10.07.2015 Views

Multiple Linear Regression

Multiple Linear Regression

Multiple Linear Regression

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

How to do it with RThe important thing is to double check that the qualitative variable in question is stored as a factor.The way to check is with the class command. For example,> class(trees$Tall)[1] "factor"If the qualitative variable is not yet stored as a factor then we may convert it to one with thefactor command. Other than this we perform MLR as we normally would.> treesdummy.lm summary(treesdummy.lm)Call:lm(formula = Volume ~ Girth + Tall, data = trees)Residuals:Min 1Q Median 3Q Max-5.7788 -3.1710 0.4888 2.6737 10.0619Coefficients:Estimate Std. Error t value Pr(>|t|)(Intercept) -34.1652 3.2438 -10.53 3.02e-11 ***Girth 4.6988 0.2652 17.72 < 2e-16 ***Tallyes 4.3072 1.6380 2.63 0.0137 *---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Residual standard error: 3.875 on 28 degrees of freedom<strong>Multiple</strong> R-squared: 0.9481, Adjusted R-squared: 0.9444F-statistic: 255.9 on 2 and 28 DF,p-value: < 2.2e-16From the output we see that all parameter estimates are statistically significant and we concludethat the mean response differs for trees with Tall = yes and trees with Tall = no.We were somewhat disingenuous when we defined the dummy variable Tallyes because,in truth, R defines Tallyes automatically without input from the user 3 . Indeed, I fit the model3 That is, R by default handles contrasts according to its internal settings which may be customized by the user forfine control. Given that we will not investigate contrasts further in this book it does not serve the discussion to delveinto those settings, either. The interested reader should check ?contrasts for details.22

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!