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.

Two extensions of the linear model 333> opened = c(rep(1:0,c(20,1250–20)), rep(1:0,c(15,1250–15)),+ rep(1:0,c(17,1250–17)), rep(1:0,c(8,1250–8)))> xtabs(opened ~ first.name+offer)offerfirst.name 0 10 8 171 15 20This matches Table 12.1, but the default ordering is different, as a or, “no,” is first.We remark that the value of opened could have been defined a bit more quickly usinga function and sapply() to repeat the typing. (See below <strong>for</strong> furthur savings in work.)> f = function(x) rep(1:0,c(x,1250-x))> opened = c(sapply(c(20,15,17,8),f))Now to fit the logistic regression model. We use factor() around each predictor; otherwisethey are treated as numeric values.> res.glm = glm(opened ~ factor(first.name) +factor(offer),+ family = binomial)> summary(res.glm)Call:glm(<strong>for</strong>mula = opened ~factor(first.name)+factor(offer),family = binomial)Deviance Residuals:Min 1Q Median 3Q Max−0.187 −0.158 −0.147 −0.124 3.121Coefficients:Estimate Std. Error z value Pr(>|z|)(Intercept) −4.864 0.259 −18.81

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

Saved successfully!

Ooh no, something went wrong!