Online course evaluations
• Open from tomorrow through noon, December 2.
• Find link in MyASU → My Classes → Course
Evaluations
Copyright By PowCoder代写 加微信 powcoder
• Please complete the evaluation! Student input is important in evaluating teaching, curriculum development, and hiring and promotion.
• Responses are anonymous and will not be seen by instructors until after grades are submitted.
Analysis of covariance: Linear models with both categorical and numerical predictors
Mole rat example:
The full model has caste, mass, and their interaction as predictors of energy expenditure
𝑌!” = 𝛼! + 𝛽!𝑋!” + 𝜀!”
Energy expenditure of jth mole rat in caste i
Linear equation predicting energy expenditure from body mass, for caste i
Normally distributed random term
Graphic display of the ANCOVA fit
𝑦! = − 0 . 3 + 1 . 0 𝑥
𝑦! = 1 . 3 + 0 . 6 𝑥
Working Lazy
3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4
ln(body mass)
ln(daily energy expenditure)
3.5 4.0 4.5 5.0
Now that we have fit the model, we can use it to answer these questions
• Does energy expenditure change with body mass?
• Is energy expenditure different for the two castes?
• Is the effect of body mass different for the two castes?
𝑦! = − 0 . 3 + 1 . 0 𝑥
𝑦! = 1 . 3 + 0 . 6 𝑥
3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4
ln(body mass)
ln(daily energy expenditure)
3.5 4.0 4.5 5.0
Using Analysis of variance to test the model
# ANOVA of full model
anova(full.model)
Analysis of Variance Table
Response: lnEnergy
Df Sum Sq Mean Sq F value
lnMass 1 1.31061 1.31061 14.9100 caste 1 0.63747 0.63747 7.2521 lnMass:caste 1 0.08956 0.08956 1.0188 Residuals 31 2.72494 0.08790
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01
0.0005362 ***
0.0113217 *
‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
The null hypothesis that body mass has no effect is rejected
# ANOVA of full model
anova(full.model)
Analysis of Variance Table
Response: lnEnergy
Df Sum Sq Mean Sq F value Pr(>F)
lnMass 1 1.31061 1.31061 14.9100 0.0005362 *** caste 1 0.63747 0.63747 7.2521 0.0113217 * lnMass:caste 1 0.08956 0.08956 1.0188 0.3206094 Residuals 31 2.72494 0.08790
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
The null hypothesis that caste has no effect is rejected
# ANOVA of full model
anova(full.model)
Analysis of Variance Table
Response: lnEnergy
Df Sum Sq Mean Sq F value Pr(>F)
lnMass 1 1.31061 1.31061 14.9100 0.0005362 *** caste 1 0.63747 0.63747 7.2521 0.0113217 * lnMass:caste 1 0.08956 0.08956 1.0188 0.3206094 Residuals 31 2.72494 0.08790
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
The null hypothesis that there is no interaction between caste and body mass is not rejected
# ANOVA of full model
anova(full.model)
Analysis of Variance Table
Response: lnEnergy
Df Sum Sq Mean Sq F value Pr(>F)
lnMass 1 1.31061 1.31061 14.9100 0.0005362 *** caste 1 0.63747 0.63747 7.2521 0.0113217 * lnMass:caste 1 0.08956 0.08956 1.0188 0.3206094 Residuals 31 2.72494 0.08790
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Question 1
What does it mean that there is no interaction between caste and body mass?
A) The slopes of the lines for lazy and working mole rats are the same.
B) The slopes of the lines for lazy and working mole rats are different.
C) The intercepts of the lines for lazy and working mole rats are the same.
D) The intercepts of the lines for lazy and working mole rats are different.
ANOVA suggests that the interaction is not significant
• That is, the slopes may actually be equal
• Perhaps a simpler model, with no interaction,
would be better
• A simpler model makes it easier to focus on main question: Is energy expenditure different between castes?
With the full model, it is difficult to compare energy expenditure between castes
Working Lazy
3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4
ln(body mass)
ln(daily energy expenditure)
3.5 4.0 4.5 5.0
In fact, the full model coefficient for caste is misleading: it suggests lower energy consumption by workers
(Intercept)
casteworker lnMass:casteworker 0.4186
Fitting a simpler model without interaction
# Fit model with two main effects only
simple.model <- lm(lnEnergy ~ lnMass + caste, data = molerat)
# Summarize model results
summary(simple.model)
Summary of simple model fit
lm(formula = lnEnergy ~ lnMass + caste, data = molerat)
Residuals:
Min 1Q Median 3Q Max
-0.73388 -0.19371 0.01317 0.17578 0.47673
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.09687 0.94230 -0.103 0.9188
lnMass 0.89282 0.19303 4.625 5.89e-05 *** casteworker 0.39334 0.14611 2.692 0.0112 *
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.2966 on 32 degrees of freedom Multiple R-squared: 0.409, Adjusted R-squared: 0.3721 F-statistic: 11.07 on 2 and 32 DF, p-value: 0.0002213
Plot of simple model illustrates higher energy consumption by workers
Working Lazy
3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4
ln(body mass)
ln(daily energy expenditure)
3.5 4.0 4.5 5.0
ANOVA of simple model shows significant effects of both body mass and caste
# ANOVA of simple model
anova(simple.model)
Analysis of Variance Table
Response: lnEnergy
Df Sum Sq Mean Sq F value Pr(>F)
lnMass 1 1.31061 1.31061 14.9013 0.0005178 *** caste 1 0.63747 0.63747 7.2478 0.0111984 * Residuals 32 2.81450 0.08795
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
The full model accounts for a weight effect, caste differences, and it allows weight effect to be
The simpler model accounts for a weight effect and caste differences, but it assumes that the weight effect is the same for the two castes
Which model is better?
different for the two castes
3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4
ln(body mass)
3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4
ln(body mass)
ln(daily energy expenditure)
3.5 4.0 4.5 5.0
ln(daily energy expenditure)
3.5 4.0 4.5 5.0
Compare the goodness of fit of each model
Full model
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.2965 on 31 degrees of freedom Multiple R-squared: 0.4278, Adjusted R-squared: 0.3725 F-statistic: 7.727 on 3 and 31 DF, p-value: 0.0005391
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.09687 0.94230 -0.103 0.9188
lnMass 0.89282 0.19303 4.625 5.89e-05 ***
casteworker 0.39334 0.14611 2.692 0.0112 *
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.2966 on 32 degrees of freedom Multiple R-squared: 0.409, Adjusted R-squared: 0.3721 F-statistic: 11.07 on 2 and 32 DF, p-value: 0.0002213
Simple model
Estimate Std. Error t value Pr(>|t|)
1.2939 1.6691 0.775 0.4441
0.6069 0.3428 1.771 0.0865 .
(Intercept)
casteworker
lnMass:casteworker 0.4186 0.4147 1.009 0.3206
-1.5713 1.9518 -0.805 0.4269
Full model
• Four parameters: two intercepts and two slopes
• Adjusted R2 = 0.3725
• Comparison of castes is difficult because the difference depends on body mass
Simple model
• Three parameters: two intercepts and one slope
• Adjusted R2 = 0.3721
• Comparison of castes is easy because the difference is the same for all body masses
Comparing the models
The simple model is a more useful tool for answering our main biological question
ANCOVA lessons
• General linear models can be arbitrarily complex
• Hypotheses about different predictors can be separately tested in a full model
• It is sometimes valuable to find the simplest useful model for the specific goals of the modeler
Fixed Effects vs. Random Effects in
One-factor ANOVA
• Question 1: Is there a difference in sugar content of peaches fertilized with bone meal vs. those fertilized with chicken manure?
– Randomly select 10 peaches from bone meal- fertilized trees and 10 from manure-fertilized trees. Measure their sugar content.
– Perform ANOVA.
– Response variable: sugar content.
– Explanatory variable: fertilizer type.
• Fertilizer types are of specific interest (chosen by
experimenter).
• If experiment were repeated, it would use the same fertilizer types.
• Inference will be drawn only about these fertilizers.23
• Question 2: What is the variance in sugar content among the trees in a population of peach trees?
– Randomly select 10 peaches each from 5 randomly selected trees. Measure sugar content.
– Perform ANOVA.
– Response variable: sugar content.
– Explanatory variable: Tree.
• Trees are of interest only as representatives of a
population of trees (sampled randomly).
• If experiment were repeated, it would use a different random sample of trees.
• Inference will be drawn about the whole population of trees.
• Fixed effects (also known as Model I)
– Factor levels are specified by the investigator as
being of particular interest.
– Main question: Are the means of the levels different?
• Random effects (also known as Model II) – Factor levels are randomly sampled from some
population.
– Main question: What is the population variance due to this factor?
Fixed effect of fertilizer on sugar amount 14
13 12 11 10 9 8 7
𝜎) !”#$%&'(
Sugar percentage of peaches given fertilizer i
Bone meal Fertilizer
Goal of fixed-effects ANOVA: Test for differences among group means
Sugar percentage
Major assumption of random-effects ANOVA
The levels of the grouping factor are randomly sampled from a large, normally distributed population
Mean sugar percentages of trees from population
Random effect of trees on sugar amount 14
13 12 11 10 9 8 7
𝜎) !”#$%&'(
Sugar percentage of peaches from tree i
Mean sugar percentages of trees from population
ABCDE Tree
Goal of random-effects ANOVA: Estimate both residual and group variances
Sugar percentage
Carrying out random effects ANOVA
Calculations are the same, and produce the familiar ANOVA table:
The F test is not of much interest in random- effects ANOVA
Instead of F tests, estimate the variance components: 𝝈𝟐 and 𝝈𝟐
Variance estimators in one-factor ANOVA
estimates 𝜎) + 𝑛𝜎) !”#$%&'( *+””#
estimates 𝜎) !”#$%&'(
Trees Residual
𝑹𝒆𝒔𝒊𝒅𝒖𝒂𝒍 𝑻𝒓𝒆𝒆𝒔
n is the sample size of each group
Estimating the variance components
𝑠) = 𝑀𝑆!”#$%&'( !”#$%&'(
𝑀𝑆*+””# − 𝑠) !”#$%&'(
(for a balanced design)
𝑠) = *+””#
Intraclass correlation coefficient
(aka, repeatability) 𝑠)
*+””# !”#$%&'(
Measures the similarity of measurements from the same group.
Peach example
)0.2.3.45 53
𝑠) = 𝑀𝑆!”#$%&'( = 𝟎. 𝟖𝟏 !”#$%&'(
2.51 2.51 + 0.81
/ !”#$%&'(
Differences between random and fixed effects
• Selection of levels
• Scope of inference
• Significance tests vs. variance components
Examples of fixed vs. random effects • Fixed effect
– Is there a difference in sugar content of peaches depending on the fertilizer used?
– Fertilizer is a fixed effect. • Random effect
– Is there significant variation among trees in sugar content of peaches?
– Tree is a random effect.
Examples of fixed vs. random effects • Fixed effect
– Are lizards from islands with predators different in size from those without predators?
– Predators are a fixed effect. • Random effect
– Is there significant variation among islands in the size of lizards?
– Island is a random effect.
Examples of fixed vs. random effects • Fixed effect
– Are treehoppers bearing allele a1 different in size from those with alleles a2 or a3?
– Allele is a fixed affect. • Random effect
– Is there significant genetic variation in the sizes of treehoppers?
– Genotype is a random effect.
Question 2
• Question: Does expression of PLP1 gene contribute to mental illness?
• Take three random samples:
1. 15peoplewithschizophrenia.
2. 15 people with bipolar illness.
3. 15 people with no known mental illness.
• Measure PLP1 gene expression in each person.
• You can use these data to compare the means of the
groups or to estimate variance components.
• Should you treat the factor as fixed or random? A) Fixed B) Random
Question 3
• Question: Which of three commonly grown strains of tomato should I plant to get the biggest tomatoes?
• Take 10 plants from each of the three strains.
• Measure average fruit size for each plant.
• You can use these data to compare the means of the groups or to estimate variance components.
• Is this a fixed effect or a random effect? A) Fixed B) Random
Question 4
• Question: Is there a genetic component to fruit size in tomatoes?
• Take 10 plants from each of three randomly chosen tomato strains.
• Measure average fruit size for each plant.
• You can use these data to compare the means of the
groups or to estimate variance components.
• Is this a fixed effect or a random effect?
A) Fixed B) Random
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com