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 334−4.864+0.341+0.481. Let o 0 be the odds ratio when neither a name nor an offer isincluded:If we include the first name, the odds ratio goes up to e −4.864+0.341 =o 0 .e 0.341 , which is anadditional factor of e 0.341 =1.406. So, if the original odds were 2 to 100, they go up to2(1.406) to 100.Avoiding replication In the previous example the data was replicated to producevariables first .name, offer, and opened with 5,000 values, so that all the recorded datawas present. The interface <strong>for</strong> glm () conveniently allows <strong>for</strong> tabulated data when thebinomial family is used. Not only is tabulated data easier to type in, we can save memoryas we don’t store large vectors of data.A two-column matrix is used, with its first column recording the number of successesand its second column the number of failures. In our example, we can construct thismatrix using cbind as follows:> opened=c(8,15,17,20)> not.opened=1250—opened> opened.mat=cbind(opened=opened,not.opened=not.opened)> opened.matopened not.opened[1,] 8 1242[2,] 15 1235[3,] 17 1233[4,] 20 1230The predictor variables match the levels <strong>for</strong> the rows. For example, <strong>for</strong> the values of 8and 15 <strong>for</strong> opened, offer was a and first. name was a then 1. Continuing gives thesevalues:> offer = c(0,0,1,1)> first.name = c(0,1,0,1)Finally, the model is fit as be<strong>for</strong>e, using opened. mat in place of opened.> glm(opened.mat ~ first.name+offer, family=binomial)Call: glm(<strong>for</strong>mula=opened.mat ~ first.name+offer,family=binomial)Coefficients:(Intercept) first.name offer−4.864 0.341 0.481Degrees of Freedom: 3 Total (i.e. Null); 1 ResidualNull Deviance: 5.77Residual Deviance: 0.736 AIC: 24.7

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

Saved successfully!

Ooh no, something went wrong!