R代写-STAT 5303
时间:2021-03-01
Midterm I Spring 2020 Solutions A
Barbara Kuzmak
3/3/2020
Questions 1 - 3 Donut Problem
#Donuts A
donuts <- read.csv("~/Documents/STAT 5303 Spring 2020/Data/donuts.csv")
attach(donuts)
model.1<-with(donuts,aov(amt.sugar~topping.type*sugar.type))
summary(model.1)
## Df Sum Sq Mean Sq F value Pr(>F)
## topping.type 4 4890 1222.6 795.267 < 2e-16 ***
## sugar.type 1 13 12.8 8.318 0.00578 **
## topping.type:sugar.type 4 19 4.8 3.151 0.02188 *
## Residuals 50 77 1.5
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(model.1,which=1)
10 15 20 25 30

4

2
0
2
Fitted values
R
es
id
ua
ls
aov(amt.sugar ~ topping.type * sugar.type)
Residuals vs Fitted
33
3
5
1
plot(model.1,which=2)
−2 −1 0 1 2

3

2

1
0
1
2
Theoretical Quantiles
St
an
da
rd
ize
d
re
sid
ua
ls
aov(amt.sugar ~ topping.type * sugar.type)
Normal Q−Q
33
3
5
car::outlierTest(model.1)
## rstudent unadjusted p-value Bonferroni p
## 33 -3.754959 0.0004606 0.027636
library(car)
## Loading required package: carData
boxCox(model.1)
2
−2 −1 0 1 2

17
0

15
0

13
0
λ
lo
g−
lik
e
lih
oo
d
95%
Question 1
The data does not look like it meets the constant variance assumption.
The data looks like it is normally distributed.
Observation 33 may be an outlier.
I tried two different transformations on amt.sugar since 0 and 0.5 are in the 95% CI.
model.1a<-with(donuts,aov(log(amt.sugar)~topping.type*sugar.type))
summary(model.1a)
## Df Sum Sq Mean Sq F value Pr(>F)
## topping.type 4 13.450 3.362 527.289 < 2e-16 ***
## sugar.type 1 0.068 0.068 10.669 0.00197 **
## topping.type:sugar.type 4 0.113 0.028 4.422 0.00388 **
## Residuals 50 0.319 0.006
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(model.1a,which=1)
3
2.2 2.4 2.6 2.8 3.0 3.2 3.4

0.
1
0.
0
0.
1
0.
2
Fitted values
R
es
id
ua
ls
aov(log(amt.sugar) ~ topping.type * sugar.type)
Residuals vs Fitted
12
49
54
plot(model.1a,which=2)
−2 −1 0 1 2

2

1
0
1
2
Theoretical Quantiles
St
an
da
rd
ize
d
re
sid
ua
ls
aov(log(amt.sugar) ~ topping.type * sugar.type)
Normal Q−Q
12
49
54
car::outlierTest(model.1a)
## No Studentized residuals with Bonferroni p < 0.05
## Largest |rstudent|:
4
## rstudent unadjusted p-value Bonferroni p
## 12 2.332992 0.023798 NA
model.1b<-with(donuts,aov(amt.sugar^0.5~topping.type+sugar.type + topping.type:sugar.type))
summary(model.1b)
## Df Sum Sq Mean Sq F value Pr(>F)
## topping.type 4 61.96 15.491 718.190 < 2e-16 ***
## sugar.type 1 0.23 0.227 10.546 0.00208 **
## topping.type:sugar.type 4 0.37 0.092 4.271 0.00474 **
## Residuals 50 1.08 0.022
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(model.1b,which=1)
3.0 3.5 4.0 4.5 5.0 5.5

0.
4

0.
2
0.
0
0.
2
Fitted values
R
es
id
ua
ls
aov(amt.sugar^0.5 ~ topping.type + sugar.type + topping.type:sugar.type)
Residuals vs Fitted
33
49
54
plot(model.1b,which=2)
5
−2 −1 0 1 2

2

1
0
1
2
Theoretical Quantiles
St
an
da
rd
ize
d
re
sid
ua
ls
aov(amt.sugar^0.5 ~ topping.type + sugar.type + topping.type:sugar.type)
Normal Q−Q
33
49
54
car::outlierTest(model.1b)
## No Studentized residuals with Bonferroni p < 0.05
## Largest |rstudent|:
## rstudent unadjusted p-value Bonferroni p
## 33 -2.675555 0.010115 0.60689
The square root transformation seems to stabilize the variance slightly better than the log, therefore we will
use the square root transformation.
Outliers do not seem to be an issue now.
6
Question 2
summary(model.1a)
## Df Sum Sq Mean Sq F value Pr(>F)
## topping.type 4 13.450 3.362 527.289 < 2e-16 ***
## sugar.type 1 0.068 0.068 10.669 0.00197 **
## topping.type:sugar.type 4 0.113 0.028 4.422 0.00388 **
## Residuals 50 0.319 0.006
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The results indicate that both main effects, topping.type and sugar.type, and their two-way interaction are
statistically significant. Let’s look at the interaction.
library(lattice)
library(cfcdae)
## Registered S3 method overwritten by 'DoE.base':
## method from
## factorize.factor conf.design
## Registered S3 method overwritten by 'xts':
## method from
## as.zoo.xts zoo
## Registered S3 methods overwritten by 'lme4':
## method from
## cooks.distance.influence.merMod car
## influence.merMod car
## dfbeta.influence.merMod car
## dfbetas.influence.merMod car
interactplot(topping.type,sugar.type,(amt.sugar)^0.5,
confidence=0.95,cex.axis=.5)
7
11
1 1 13.0
3.
5
4.
0
4.
5
5.
0
5.
5
6.
0
topping.type
M
ea
n
of
(a
mt
.su
ga
r)^
0.5
2
2
2 2 2
Frosted Frosted n Sprinkles Glazed Plain Powdered
sugar.type
2
1
Regular
Low Sugar
The interaction plot is parallel for the most part, except at frosted. This is where the interaction
is. The lines widen for frosted regular vs. frosted low sugar. The 95% confidence lines do not overlap at
frosted regular vs. frosted low sugar.
The lines are parallel for all other comparisons for a given topping.type for the two different sugar types and
the confidence intervals overlap.
#Examine the differences between topping.type and sugar.type
tapply((amt.sugar)^0.5,list(topping.type,sugar.type),mean)
## Low Sugar Regular
## Frosted 3.440242 3.875808
## Frosted n Sprinkles 5.705032 5.767231
## Glazed 3.062236 3.107329
## Plain 3.066201 3.088848
## Powdered 3.163003 3.213226
TukeyHSD(model.1b,"topping.type:sugar.type")
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = amt.sugar^0.5 ~ topping.type + sugar.type + topping.type:sugar.type)
##
## $`topping.type:sugar.type`
## diff
## Frosted n Sprinkles:Low Sugar-Frosted:Low Sugar 2.264789921
## Glazed:Low Sugar-Frosted:Low Sugar -0.378006294
## Plain:Low Sugar-Frosted:Low Sugar -0.374040994
## Powdered:Low Sugar-Frosted:Low Sugar -0.277238986
## Frosted:Regular-Frosted:Low Sugar 0.435565678
## Frosted n Sprinkles:Regular-Frosted:Low Sugar 2.326989566
## Glazed:Regular-Frosted:Low Sugar -0.332913012
## Plain:Regular-Frosted:Low Sugar -0.351393424
8
## Powdered:Regular-Frosted:Low Sugar -0.227016074
## Glazed:Low Sugar-Frosted n Sprinkles:Low Sugar -2.642796215
## Plain:Low Sugar-Frosted n Sprinkles:Low Sugar -2.638830914
## Powdered:Low Sugar-Frosted n Sprinkles:Low Sugar -2.542028907
## Frosted:Regular-Frosted n Sprinkles:Low Sugar -1.829224243
## Frosted n Sprinkles:Regular-Frosted n Sprinkles:Low Sugar 0.062199645
## Glazed:Regular-Frosted n Sprinkles:Low Sugar -2.597702932
## Plain:Regular-Frosted n Sprinkles:Low Sugar -2.616183345
## Powdered:Regular-Frosted n Sprinkles:Low Sugar -2.491805995
## Plain:Low Sugar-Glazed:Low Sugar 0.003965301
## Powdered:Low Sugar-Glazed:Low Sugar 0.100767308
## Frosted:Regular-Glazed:Low Sugar 0.813571972
## Frosted n Sprinkles:Regular-Glazed:Low Sugar 2.704995860
## Glazed:Regular-Glazed:Low Sugar 0.045093282
## Plain:Regular-Glazed:Low Sugar 0.026612870
## Powdered:Regular-Glazed:Low Sugar 0.150990220
## Powdered:Low Sugar-Plain:Low Sugar 0.096802007
## Frosted:Regular-Plain:Low Sugar 0.809606671
## Frosted n Sprinkles:Regular-Plain:Low Sugar 2.701030560
## Glazed:Regular-Plain:Low Sugar 0.041127982
## Plain:Regular-Plain:Low Sugar 0.022647569
## Powdered:Regular-Plain:Low Sugar 0.147024920
## Frosted:Regular-Powdered:Low Sugar 0.712804664
## Frosted n Sprinkles:Regular-Powdered:Low Sugar 2.604228552
## Glazed:Regular-Powdered:Low Sugar -0.055674025
## Plain:Regular-Powdered:Low Sugar -0.074154438
## Powdered:Regular-Powdered:Low Sugar 0.050222912
## Frosted n Sprinkles:Regular-Frosted:Regular 1.891423888
## Glazed:Regular-Frosted:Regular -0.768478689
## Plain:Regular-Frosted:Regular -0.786959102
## Powdered:Regular-Frosted:Regular -0.662581752
## Glazed:Regular-Frosted n Sprinkles:Regular -2.659902578
## Plain:Regular-Frosted n Sprinkles:Regular -2.678382990
## Powdered:Regular-Frosted n Sprinkles:Regular -2.554005640
## Plain:Regular-Glazed:Regular -0.018480413
## Powdered:Regular-Glazed:Regular 0.105896938
## Powdered:Regular-Plain:Regular 0.124377350
## lwr
## Frosted n Sprinkles:Low Sugar-Frosted:Low Sugar 1.9841037
## Glazed:Low Sugar-Frosted:Low Sugar -0.6586926
## Plain:Low Sugar-Frosted:Low Sugar -0.6547273
## Powdered:Low Sugar-Frosted:Low Sugar -0.5579253
## Frosted:Regular-Frosted:Low Sugar 0.1548794
## Frosted n Sprinkles:Regular-Frosted:Low Sugar 2.0463033
## Glazed:Regular-Frosted:Low Sugar -0.6135993
## Plain:Regular-Frosted:Low Sugar -0.6320797
## Powdered:Regular-Frosted:Low Sugar -0.5077023
## Glazed:Low Sugar-Frosted n Sprinkles:Low Sugar -2.9234825
## Plain:Low Sugar-Frosted n Sprinkles:Low Sugar -2.9195172
## Powdered:Low Sugar-Frosted n Sprinkles:Low Sugar -2.8227152
## Frosted:Regular-Frosted n Sprinkles:Low Sugar -2.1099105
## Frosted n Sprinkles:Regular-Frosted n Sprinkles:Low Sugar -0.2184866
## Glazed:Regular-Frosted n Sprinkles:Low Sugar -2.8783892
## Plain:Regular-Frosted n Sprinkles:Low Sugar -2.8968696
9
## Powdered:Regular-Frosted n Sprinkles:Low Sugar -2.7724923
## Plain:Low Sugar-Glazed:Low Sugar -0.2767210
## Powdered:Low Sugar-Glazed:Low Sugar -0.1799190
## Frosted:Regular-Glazed:Low Sugar 0.5328857
## Frosted n Sprinkles:Regular-Glazed:Low Sugar 2.4243096
## Glazed:Regular-Glazed:Low Sugar -0.2355930
## Plain:Regular-Glazed:Low Sugar -0.2540734
## Powdered:Regular-Glazed:Low Sugar -0.1296961
## Powdered:Low Sugar-Plain:Low Sugar -0.1838843
## Frosted:Regular-Plain:Low Sugar 0.5289204
## Frosted n Sprinkles:Regular-Plain:Low Sugar 2.4203443
## Glazed:Regular-Plain:Low Sugar -0.2395583
## Plain:Regular-Plain:Low Sugar -0.2580387
## Powdered:Regular-Plain:Low Sugar -0.1336614
## Frosted:Regular-Powdered:Low Sugar 0.4321184
## Frosted n Sprinkles:Regular-Powdered:Low Sugar 2.3235423
## Glazed:Regular-Powdered:Low Sugar -0.3363603
## Plain:Regular-Powdered:Low Sugar -0.3548407
## Powdered:Regular-Powdered:Low Sugar -0.2304634
## Frosted n Sprinkles:Regular-Frosted:Regular 1.6107376
## Glazed:Regular-Frosted:Regular -1.0491650
## Plain:Regular-Frosted:Regular -1.0676454
## Powdered:Regular-Frosted:Regular -0.9432680
## Glazed:Regular-Frosted n Sprinkles:Regular -2.9405888
## Plain:Regular-Frosted n Sprinkles:Regular -2.9590693
## Powdered:Regular-Frosted n Sprinkles:Regular -2.8346919
## Plain:Regular-Glazed:Regular -0.2991667
## Powdered:Regular-Glazed:Regular -0.1747893
## Powdered:Regular-Plain:Regular -0.1563089
## upr
## Frosted n Sprinkles:Low Sugar-Frosted:Low Sugar 2.545476191
## Glazed:Low Sugar-Frosted:Low Sugar -0.097320024
## Plain:Low Sugar-Frosted:Low Sugar -0.093354723
## Powdered:Low Sugar-Frosted:Low Sugar 0.003447284
## Frosted:Regular-Frosted:Low Sugar 0.716251948
## Frosted n Sprinkles:Regular-Frosted:Low Sugar 2.607675837
## Glazed:Regular-Frosted:Low Sugar -0.052226741
## Plain:Regular-Frosted:Low Sugar -0.070707154
## Powdered:Regular-Frosted:Low Sugar 0.053670197
## Glazed:Low Sugar-Frosted n Sprinkles:Low Sugar -2.362109944
## Plain:Low Sugar-Frosted n Sprinkles:Low Sugar -2.358144644
## Powdered:Low Sugar-Frosted n Sprinkles:Low Sugar -2.261342636
## Frosted:Regular-Frosted n Sprinkles:Low Sugar -1.548537973
## Frosted n Sprinkles:Regular-Frosted n Sprinkles:Low Sugar 0.342885916
## Glazed:Regular-Frosted n Sprinkles:Low Sugar -2.317016662
## Plain:Regular-Frosted n Sprinkles:Low Sugar -2.335497074
## Powdered:Regular-Frosted n Sprinkles:Low Sugar -2.211119724
## Plain:Low Sugar-Glazed:Low Sugar 0.284651571
## Powdered:Low Sugar-Glazed:Low Sugar 0.381453578
## Frosted:Regular-Glazed:Low Sugar 1.094258242
## Frosted n Sprinkles:Regular-Glazed:Low Sugar 2.985682131
## Glazed:Regular-Glazed:Low Sugar 0.325779553
## Plain:Regular-Glazed:Low Sugar 0.307299140
## Powdered:Regular-Glazed:Low Sugar 0.431676491
10
## Powdered:Low Sugar-Plain:Low Sugar 0.377488278
## Frosted:Regular-Plain:Low Sugar 1.090292942
## Frosted n Sprinkles:Regular-Plain:Low Sugar 2.981716830
## Glazed:Regular-Plain:Low Sugar 0.321814252
## Plain:Regular-Plain:Low Sugar 0.303333840
## Powdered:Regular-Plain:Low Sugar 0.427711190
## Frosted:Regular-Powdered:Low Sugar 0.993490934
## Frosted n Sprinkles:Regular-Powdered:Low Sugar 2.884914823
## Glazed:Regular-Powdered:Low Sugar 0.225012245
## Plain:Regular-Powdered:Low Sugar 0.206531833
## Powdered:Regular-Powdered:Low Sugar 0.330909183
## Frosted n Sprinkles:Regular-Frosted:Regular 2.172110159
## Glazed:Regular-Frosted:Regular -0.487792419
## Plain:Regular-Frosted:Regular -0.506272831
## Powdered:Regular-Frosted:Regular -0.381895481
## Glazed:Regular-Frosted n Sprinkles:Regular -2.379216307
## Plain:Regular-Frosted n Sprinkles:Regular -2.397696720
## Powdered:Regular-Frosted n Sprinkles:Regular -2.273319369
## Plain:Regular-Glazed:Regular 0.262205858
## Powdered:Regular-Glazed:Regular 0.386583208
## Powdered:Regular-Plain:Regular 0.405063621
## p adj
## Frosted n Sprinkles:Low Sugar-Frosted:Low Sugar 0.0000000
## Glazed:Low Sugar-Frosted:Low Sugar 0.0017645
## Plain:Low Sugar-Frosted:Low Sugar 0.0020482
## Powdered:Low Sugar-Frosted:Low Sugar 0.0554341
## Frosted:Regular-Frosted:Low Sugar 0.0001868
## Frosted n Sprinkles:Regular-Frosted:Low Sugar 0.0000000
## Glazed:Regular-Frosted:Low Sugar 0.0090945
## Plain:Regular-Frosted:Low Sugar 0.0047177
## Powdered:Regular-Frosted:Low Sugar 0.2109797
## Glazed:Low Sugar-Frosted n Sprinkles:Low Sugar 0.0000000
## Plain:Low Sugar-Frosted n Sprinkles:Low Sugar 0.0000000
## Powdered:Low Sugar-Frosted n Sprinkles:Low Sugar 0.0000000
## Frosted:Regular-Frosted n Sprinkles:Low Sugar 0.0000000
## Frosted n Sprinkles:Regular-Frosted n Sprinkles:Low Sugar 0.9991271
## Glazed:Regular-Frosted n Sprinkles:Low Sugar 0.0000000
## Plain:Regular-Frosted n Sprinkles:Low Sugar 0.0000000
## Powdered:Regular-Frosted n Sprinkles:Low Sugar 0.0000000
## Plain:Low Sugar-Glazed:Low Sugar 1.0000000
## Powdered:Low Sugar-Glazed:Low Sugar 0.9708515
## Frosted:Regular-Glazed:Low Sugar 0.0000000
## Frosted n Sprinkles:Regular-Glazed:Low Sugar 0.0000000
## Glazed:Regular-Glazed:Low Sugar 0.9999374
## Plain:Regular-Glazed:Low Sugar 0.9999993
## Powdered:Regular-Glazed:Low Sugar 0.7436526
## Powdered:Low Sugar-Plain:Low Sugar 0.9775604
## Frosted:Regular-Plain:Low Sugar 0.0000000
## Frosted n Sprinkles:Regular-Plain:Low Sugar 0.0000000
## Glazed:Regular-Plain:Low Sugar 0.9999713
## Plain:Regular-Plain:Low Sugar 0.9999998
## Powdered:Regular-Plain:Low Sugar 0.7710767
## Frosted:Regular-Powdered:Low Sugar 0.0000000
## Frosted n Sprinkles:Regular-Powdered:Low Sugar 0.0000000
11
## Glazed:Regular-Powdered:Low Sugar 0.9996415
## Plain:Regular-Powdered:Low Sugar 0.9966047
## Powdered:Regular-Powdered:Low Sugar 0.9998461
## Frosted n Sprinkles:Regular-Frosted:Regular 0.0000000
## Glazed:Regular-Frosted:Regular 0.0000000
## Plain:Regular-Frosted:Regular 0.0000000
## Powdered:Regular-Frosted:Regular 0.0000000
## Glazed:Regular-Frosted n Sprinkles:Regular 0.0000000
## Plain:Regular-Frosted n Sprinkles:Regular 0.0000000
## Powdered:Regular-Frosted n Sprinkles:Regular 0.0000000
## Plain:Regular-Glazed:Regular 1.0000000
## Powdered:Regular-Glazed:Regular 0.9601107
## Powdered:Regular-Plain:Regular 0.8985937
12
Question 3
Based on the interaction plot and Tukey’s test, any of the plain, powered or glazed toppings are low in sugar
content regardless of whether the donut was made with regular or low sugar. The low sugar version of the
donut has less sugar than the regular version, but for these three types of topping they are not statistically
different. Therefore, all six combinations of-
plain:regular powered:regular glazed:regular
plain:low sugar powered:low sugar glazed:low sugar
are statistically lower than the remaining donuts and are good choices.
Donuts made with frosted and frosted n sprinkles are the worst topppings with regard to the amount of
sugar they contain regardless of whether the donut used regular or low sugar.
13
Questions 4 - 6 Asparagus Problem
#Asparagus A
asparagus <- read.csv("~/Documents/STAT 5303 Spring 2020/Data/asparagus.csv")
attach(asparagus)
## The following object is masked from donuts:
##
## X
str(asparagus)
## 'data.frame': 24 obs. of 5 variables:
## $ X : int 1 2 3 4 5 6 7 8 9 10 ...
## $ K : int 65 54 41 33 56 52 54 48 56 50 ...
## $ cooking.method: Factor w/ 2 levels "Grilled","Steamed": 2 2 2 2 2 2 2 2 2 2 ...
## $ cooking.time : int 4 8 12 16 4 8 12 16 4 8 ...
## $ age : Factor w/ 3 levels "mature","old",..: 3 3 3 3 1 1 1 1 2 2 ...
asparagus$cooking.time.z<-cooking.time
asparagus$cooking.time<-as.factor(cooking.time)
attach(asparagus)
## The following objects are masked from asparagus (pos = 3):
##
## age, cooking.method, cooking.time, K, X
##
## The following object is masked from donuts:
##
## X
# Since there is no replication in the study,
# the three-way interaction is used as the error.
model.1<-aov(K~(cooking.method+age+cooking.time)^2,data=asparagus)
summary(model.1)
## Df Sum Sq Mean Sq F value Pr(>F)
## cooking.method 1 126.0 126.04 10.894 0.0164 *
## age 2 170.1 85.04 7.351 0.0243 *
## cooking.time 3 794.5 264.82 22.890 0.0011 **
## cooking.method:age 2 3.6 1.79 0.155 0.8598
## cooking.method:cooking.time 3 57.5 19.15 1.655 0.2741
## age:cooking.time 6 326.9 54.49 4.709 0.0406 *
## Residuals 6 69.4 11.57
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# The residual df = 6, so we pool the non significant
# two-way interactions, cooking.method:age and
# cooking.method:cooking:time.
model.1a<-with(asparagus,aov(K~cooking.method+age+
cooking.time +
age:cooking.time))
summary(model.1a)
## Df Sum Sq Mean Sq F value Pr(>F)
14
## cooking.method 1 126.0 126.04 10.628 0.0076 **
## age 2 170.1 85.04 7.171 0.0102 *
## cooking.time 3 794.5 264.82 22.329 5.55e-05 ***
## age:cooking.time 6 326.9 54.49 4.594 0.0142 *
## Residuals 11 130.5 11.86
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(model.1a,which=1)
35 40 45 50 55 60 65

6

4

2
0
2
4
6
Fitted values
R
es
id
ua
ls
aov(K ~ cooking.method + age + cooking.time + age:cooking.time)
Residuals vs Fitted
9
21
15
plot(model.1a,which=2)
15
−2 −1 0 1 2

2

1
0
1
2
Theoretical Quantiles
St
an
da
rd
ize
d
re
sid
ua
ls
aov(K ~ cooking.method + age + cooking.time + age:cooking.time)
Normal Q−Q
9
21
15
outlierTest(model.1a)
## No Studentized residuals with Bonferroni p < 0.05
## Largest |rstudent|:
## rstudent unadjusted p-value Bonferroni p
## 9 2.967808 0.014099 0.33837
boxCox(model.1a,lambda=seq(-2,5))
−2 −1 0 1 2 3 4 5

66

64

62

60

58
λ
lo
g−
lik
e
lih
oo
d
95%
Question 4.
16
The residuals are not as stabled as dersired, but a pattern isn’t obvious. The normality plot looks fine. A
BoxCox transformation will be investigated.
Since 1 is included in the 95% CI of the Box-Cox transformation, a log transformation will not help.
The potassium content will be analyzed on the original scale.
Question 5
Now let’s examine cooking.time and the cooking.time by age interaction on the quantitative scale.
model.1b<-with(asparagus,aov(K~cooking.method+age+
cooking.time.z + I(cooking.time.z^2)+I(cooking.time.z^3) +
age:cooking.time.z + age:I(cooking.time.z^2)+
age:I(cooking.time.z^3)))
summary(model.1b)
## Df Sum Sq Mean Sq F value Pr(>F)
## cooking.method 1 126.0 126.0 10.628 0.00760 **
## age 2 170.1 85.0 7.171 0.01015 *
## cooking.time.z 1 785.4 785.4 66.224 5.55e-06 ***
## I(cooking.time.z^2) 1 2.0 2.0 0.172 0.68619
## I(cooking.time.z^3) 1 7.0 7.0 0.591 0.45825
## age:cooking.time.z 2 315.2 157.6 13.289 0.00116 **
## age:I(cooking.time.z^2) 2 1.1 0.5 0.046 0.95554
## age:I(cooking.time.z^3) 2 10.6 5.3 0.448 0.65031
## Residuals 11 130.5 11.9
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
model.1c<-with(asparagus,lm(K~cooking.method+age+
cooking.time.z + I(cooking.time.z^2)+I(cooking.time.z^3) +
age:cooking.time.z + age:I(cooking.time.z^2)+
age:I(cooking.time.z^3)))
summary(model.1c)
##
## Call:
## lm(formula = K ~ cooking.method + age + cooking.time.z + I(cooking.time.z^2) +
## I(cooking.time.z^3) + age:cooking.time.z + age:I(cooking.time.z^2) +
## age:I(cooking.time.z^3))
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.292 -1.354 0.000 1.354 5.292
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 71.33333 11.67854 6.108 7.65e-05 ***
## cooking.method1 2.29167 0.70297 3.260 0.0076 **
## age1 10.66667 16.51595 0.646 0.5316
## age2 -18.83333 16.51595 -1.140 0.2784
## cooking.time.z -4.27778 4.46520 -0.958 0.3586
## I(cooking.time.z^2) 0.35937 0.49317 0.729 0.4814
## I(cooking.time.z^3) -0.01259 0.01637 -0.769 0.4582
17
## age1:cooking.time.z -4.63889 6.31474 -0.735 0.4779
## age2:cooking.time.z 4.94444 6.31474 0.783 0.4502
## age1:I(cooking.time.z^2) 0.59375 0.69745 0.851 0.4127
## age2:I(cooking.time.z^2) -0.51563 0.69745 -0.739 0.4752
## age1:I(cooking.time.z^3) -0.01997 0.02316 -0.862 0.4070
## age2:I(cooking.time.z^3) 0.01780 0.02316 0.768 0.4584
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.444 on 11 degrees of freedom
## Multiple R-squared: 0.9157, Adjusted R-squared: 0.8238
## F-statistic: 9.96 on 12 and 11 DF, p-value: 0.0002941
interaction.plot(cooking.time.z,age,K)
35
40
45
50
55
60
65
cooking.time.z
m
e
a
n
o
f
K
4 8 12 16
age
mature
old
young
The interaction plot shows that the potassium content of young asparagus declines more rapidly than mature
and old asparagus with increasing cooking time.
Mature asparagus decline the least with increasing cooking time.
Old asparagus decline is in between the rapid decline of young asparagus and slow decline of mature
asparagus.
It isn’t necessary to discuss cooking.method since the question asked about cooking.time and age. However
in a consulting situation, you would report your findings regarding the cooking.method since it is statistically
significant too.
Question 6
This question is thrown out. There is a statistically significant age by cooking.time interaction which makes
the answer to the debate vague.
18
Question 7
#
Type I error
My thumb is fine (H0 is true), but I think it is broken (reject H0). I will go to the doctor.
Type II error
My thumb is broken (Ha is true), but I think it will be fine (fail to reject H0). I will not go to the doctor.
Power
My thumb is broken (Ha is true), and I think it is broken (reject H0). I will go to the doctor.
Type II error is more risky healthwise, since I think my thumb is fine (fail to reject H0) when in reality it is
broken (Ha is true). I have a broken thumb, but will not go to the doctor.
19
Question 8
#
This is an observational study. There does not seem to be a way to construct an experiment to investiage the
relationship between car cost and whether they stop or not. You cannot randomly assign a cost to a car.
It comes with a cost already determined by the manufacturer. You cannot create homogeneous experimental
units in this study.
It seems the easiest way to conduct this study is to observe the car make and model and whether they stop
or not. Collecting the car make and model will allow the investigator to determine its cost and relate it to
whether they stop or not. This type of study is an observational study.
20


essay、essay代写