10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Using</strong> R <strong>for</strong> introductory statistics 31611.3 ANCOVAAn analysis of covariance (ANCOVA) is the term given to models where bothcategorical and numeric variables are used as predictors. Per<strong>for</strong>ming an ANCOVA in R isalso done using lm().■ Example 11.8: Birth weight by mother’s weight and smoking historyIn Example 11.6 we per<strong>for</strong>med an analysis of variance of a baby’s birth weightmodeled by whether the mother smoked. In this example, we also regress on the numericmeasurement of the mother’s weight. First we make a plot, marking the points withdifferent characters depending on the value of smoke. As smoke is stored as a numericvariable, the different plot symbols <strong>for</strong> those numbers are used.> plot(wt ~ wt1, data=babies, pch=smoke, subset=wt1 res=lm(wt ~ wt1+factor(smoke), data=babies,+ subset=wt1 < 800)> summary(res)Call:lm(<strong>for</strong>mula=wt ~ wt1+factor(smoke), data=babies,subset=wt1

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

Saved successfully!

Ooh no, something went wrong!