Our model will will use the iris data
attach(iris)
irismod <- lm(Petal.Width ~ Petal.Length + Sepal.Length)
We can test the sigfigance of our predictors. The null hypothesis is that our selected variable, after accounting for the other predictor, has no linear relationship with the dependent variable. If our model is y= Beta0 + Beta1X1 + Beta2X2 then the null hypothesis is that beta1 = 0 the alternative is that beta1 does not = 0
Residuals
summary(residuals(irismod))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.60600 -0.12560 -0.02049 0.00000 0.11620 0.59400
Coeffcients
summary(irismod)
##
## Call:
## lm(formula = Petal.Width ~ Petal.Length + Sepal.Length)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.60598 -0.12560 -0.02049 0.11616 0.59404
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.008996 0.182097 -0.049 0.9607
## Petal.Length 0.449376 0.019365 23.205 <2e-16 ***
## Sepal.Length -0.082218 0.041283 -1.992 0.0483 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2044 on 147 degrees of freedom
## Multiple R-squared: 0.929, Adjusted R-squared: 0.9281
## F-statistic: 962.1 on 2 and 147 DF, p-value: < 2.2e-16
This tells us that our predictor variables are signfigant because at an alpha of .05 we would reject the null that our variable coeffcients are 0.
confint(irismod)
## 2.5 % 97.5 %
## (Intercept) -0.3688623 0.3508703167
## Petal.Length 0.4111061 0.4876461035
## Sepal.Length -0.1638030 -0.0006326179
The confidence interval at 95% is shown by the two bounds for each variable, the 2.5% is the lower while the 97.5% is the upper bound. For example we are 95% confident that for an increase of 1 unit in petal length will lead to an increase of between 0.4111061 and .4876461035.
Now we can construct a 99% CI for the mean petal width. Gven that a petal is 2 cm long and has a sepal length of 5 cm we can create this interval.
new.petal <- data.frame(Petal.Length = 2, Sepal.Length = 5)
predict(irismod, new.petal, interval = "confidence", level = .99)
## fit lwr upr
## 1 0.4786672 0.4156413 0.541693
This prediction interval gives us a point estimate of .4786672. We are 99% confident that the mean petal width for a flower with petal length of 2 and sepal lenght of 5 is between .4156413 and .541693.
predict(irismod, new.petal, interval = "prediction", level = .99)
## fit lwr upr
## 1 0.4786672 -0.05858199 1.015916
This fits a confidence interval for an indivdual petal. The negative lower bound is negative but that doesnt make sense for us to interpret so it may mean that we can’t predict things in this range of variables. It is larger than the interval for the mean because there is more variablilty with one prediction than with a mean.