LOading dataset from Desktop

LungCapData <- read.delim(file.choose(),header = T)
attach(LungCapData)
names(LungCapData)
## [1] "LungCap"   "Age"       "Height"    "Smoke"     "Gender"    "Caesarean"





Creating a Scatterplot

plot(Age, LungCap, main = "Age~LungCap")





Significance of the relation

cor(Age,LungCap)
## [1] 0.8196749





Linear Regression Model

lmod <- lm(LungCap~Age)
summary(lmod)
## 
## Call:
## lm(formula = LungCap ~ Age)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.7799 -1.0203 -0.0005  0.9789  4.2650 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.14686    0.18353   6.249 7.06e-10 ***
## Age          0.54485    0.01416  38.476  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.526 on 723 degrees of freedom
## Multiple R-squared:  0.6719, Adjusted R-squared:  0.6714 
## F-statistic:  1480 on 1 and 723 DF,  p-value: < 2.2e-16





Coefficients of the explanatory variables and intercepts

lmod$coef
## (Intercept)         Age 
##   1.1468578   0.5448484
coef(lmod)
## (Intercept)         Age 
##   1.1468578   0.5448484





Regression Line

plot(Age, LungCap, main = "Age~LungCap")
abline(lmod)





Customize The Regression Line

plot(Age, LungCap, main = "Age~LungCap")
abline(lmod, col= "Green", lwd = 6)





Confidence level

confint(lmod)
##                 2.5 %    97.5 %
## (Intercept) 0.7865454 1.5071702
## Age         0.5170471 0.5726497





Change the Confidence level

confint(lmod, level = 0.99)
##                 0.5 %    99.5 %
## (Intercept) 0.6728686 1.6208470
## Age         0.5082759 0.5814209





ANOVA table

anova(lmod)
## Analysis of Variance Table
## 
## Response: LungCap
##            Df Sum Sq Mean Sq F value    Pr(>F)    
## Age         1 3447.0  3447.0  1480.4 < 2.2e-16 ***
## Residuals 723 1683.5     2.3                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1