source('_format.R')
Chapter 15 in the text and the associated supplemental material covers several important methods and design concerns. This includes repeated measures, normality-inducing transformations, unbalanced data problems, and analysis of covariance.
Using the data from Example3.5
we can find the Box-Cox transform of the response to make our data look more normally distributed:
library(MASS) model <- lm(Observation ~ EstimationMethod, data=Example3.5) vals <- boxcox(model)
\noindent The plot indicates that the 95% confidence interval doesn't contain 0 (so no log transform), and that the best is somewhere between around 1/2 to 3/4. By assigning the value returned by boxcox
to a variable we can find the peak:
best.lambda <- vals$x[which.max(vals$y)] print(best.lambda)
\noindent This suggests 0.5 is an appropriate value for $\lambda$.
Recall the coupon redemption data from Table 15.1, where the number of coupons redeemed is out of 1000 customers. To fit a binomial GLM (logistic regression) we use the glm
function and indicate the family is binomial
. Note that the response won't be a number, but will be two columns: the first column is the number of successes and the second is the number of failures:
model <- glm(cbind(Coupons, I(1000 - Coupons)) ~ (A + B + C)^2, data=Table15.1, family='binomial') print(summary(model))
The grill defects experiment described in problem 8.51 is analyzed in the text using Poisson regression. First we retrieve the number of defects.
df <- Problem8.51[,c('A','B','C','D','E','F','G','H','J')] df[,'Defects'] <- round(Problem8.51[,'Sqrt']^2)
\noindent Next, we fit a poisson model:
model <- glm(Defects ~ D + F + B:G, data=df, family='poisson') summary(model)
\noindent Next, we generate approximate 95% confidence intervals around each observation:
response <- predict(model, type='response', se.fit=TRUE) 2 * qnorm(0.975) * response$se.fit
Here we fit a Gamma GLM to the data. Note that Gamma
is capitalized in the family argument, and that we pass 'log'
as the link function:
model <- glm(CyclesToFailure ~ x1 + x2 + x3, data=Table15.4, family=Gamma(link='log')) summary(model)
\noindent Next, we generate approximate 95% confidence intervals around each observation:
response <- predict(model, type='response', se.fit=TRUE) 2 * qnorm(0.975) * response$se.fit
Note that by placing I(x - mean(x))
before Machine
we cause machine to be adjusted by the covariate:
model <- aov(y ~ I(x - mean(x)) + Machine, data=Table15.10) print(summary(model))
We reproduce the analysis from JMP given in Table 15.17 for the data set in Table 15.16. First, we'll fit the ugly full model as a regression model:
op <- options(contrast=c('contr.sum', 'contr.poly')) model <- lm(y ~ I(x - mean(x)) * (A + B + C)^2, data=Table15.16) options(op) print(summary(model))
\noindent Next, we'll fit the reduced model as an ANOVA model:
xx <- (Table15.16$x - mean(Table15.16$x)) op <- options(contrast=c('contr.sum', 'contr.poly')) model <- aov(y ~ xx + A + B + C + A:B + A:xx + B:xx + A:B:xx, data=Table15.16) options(op) print(summary(model))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.