# Linear regression: One target predictor and two covariates
#Re-examining the relationship between Gender and Cancer, this time
# controlling for height AND smoking

fit3 <- lm(Cancer ~ Gender + Height + Smoke, data=Wk08a)
summary(fit3) # show results
## 
## Call:
## lm(formula = Cancer ~ Gender + Height + Smoke, data = Wk08a)
##
## Residuals:
## Min 1Q Median 3Q Max
## -17.2774 -3.0953 -0.0004 3.0974 18.2488
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -12.258953 1.566757 -7.824 5.29e-15 ***
## Gender 2.252762 0.069811 32.269 < 2e-16 ***
## Height 1.102309 0.024235 45.484 < 2e-16 ***
## Smoke 0.767207 0.003942 194.633 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.624 on 26771 degrees of freedom
## Multiple R-squared: 0.6978, Adjusted R-squared: 0.6978
## F-statistic: 2.061e+04 on 3 and 26771 DF, p-value: < 2.2e-16
confint(fit3, level=0.95) # CIs for model parameters 
##                   2.5 %     97.5 %
## (Intercept) -15.3298790 -9.1880262
## Gender 2.1159277 2.3895955
## Height 1.0548071 1.1498106
## Smoke 0.7594809 0.7749332
library(QuantPsyc)
lm.beta(fit3) # To get standardized estimates
##    Gender    Height     Smoke 
## 0.1339290 0.1866270 0.6958132
library(ppcor)
pcor.test(Wk08a$Gender,Wk08a$Cancer,list(Wk08a$Height,Wk08a$Smoke)) #Partial correlations
##    estimate       p.value statistic     n gp  Method
## 1 0.1934954 3.724418e-224 32.26928 26775 2 pearson
spcor.test(Wk08a$Gender,Wk08a$Cancer,list(Wk08a$Height,Wk08a$Smoke)) #Semi-partial correlations
##    estimate       p.value statistic     n gp  Method
## 1 0.1566373 1.214199e-146 25.94906 26775 2 pearson
#Here is a sample scatterplot

library(ggplot2)

ggplot(Wk08a, aes(x=Smoke, y=Cancer)) +
# geom_point(shape=1) + # Use hollow circles
geom_jitter(pch=1, width=0.3) +
geom_smooth(method=lm,formula=y~x, # Add linear regression line
se=FALSE,col="red", size=2) + # Don't add shaded confidence region
theme_bw()