11.4: Worked Example
- Page ID
- 33193
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)For the example dataset in Repeated Measures Example Data, which we introduced in the 11.2: Correlated Residuals section, we can plot the data:
We can obtain the results for the split-plot in time approach using the following:
/* Split-Plot in Time */ proc mixed data=rmanova method=type3; class trt time subject; model resp=trt time trt*time / ddfm=kr; random subject(trt); title 'Split-Plot in Time'; run;
Next, we run the analysis as a repeated-measures ANOVA, which allows us to evaluate which covariance structure fits best.
Next, we run the analysis as a repeated-measures ANOVA, which allows us to evaluate which covariance structure fits best.
/* Repeated Measures Approach */ /* Fitting Covariance structures: */ /* Note: the code begining with "ods output ..." for each run of the Mixed procedure generates an output that is tabulated at the end to enable comparison of the candidate covariance structure */ proc mixed data=rmanova; class trt time subject; model resp=trt time trt*time / ddfm=kr; repeated time/subject=subject(trt) type=cs rcorr; ods output FitStatistics=FitCS (rename=(value=CS)) FitStatistics=FitCSp; title 'Compound Symmetry'; run; title ' '; run; proc mixed data=rmanova; class trt time subject; model resp=trt time trt*time / ddfm=kr; repeated time/subject=subject(trt) type=ar(1) rcorr; ods output FitStatistics=FitAR1 (rename=(value=AR1)) FitStatistics=FitAR1p; title 'Autoregressive Lag 1'; run; title ' '; run; proc mixed data=rmanova; class trt time subject; model resp=trt time trt*time / ddfm=kr; repeated time/subject=subject(trt) type=un rcorr; ods output FitStatistics=FitUN (rename=(value=UN)) FitStatistics=FitUNp; title 'Unstructured'; run; title ' '; run; data fits; merge FitCS FitAR1 FitUN; by descr; run; ods listing; proc print data=fits; run;
We get the following Summary Table:
Obs | Descr | CS | AR1 | UN |
---|---|---|---|---|
1 | -2 Res Log Likelihood | 70.9 | 71.9 | 63.0 |
2 | AIC (smaller is better) | 74.9 | 75.9 | 75.0 |
3 | AICC (smaller is better) | 75.7 | 76.7 | 82.6 |
4 | BIC (smaller is better) | 75.3 | 76.3 | 76.2 |
Using the AICC as our criteria, we would choose the compound symmetry (CS) covariance structure.
The output from this would be:
Type 3 Test of Fixed Effect | ||||
---|---|---|---|---|
Effect | Num DF | Den DF | F Value | Pr > F |
trt | 2 | 6 | 7.14 | F">0.0259 |
time | 2 | 12 | 605.62 | F">< .0001 |
trt*time | 4 | 12 | 9.66 | F">0.0010 |
Note that for this case, the \(p\)-values obtained here are identical to the split-plot in time approach.
- Steps in R
-
1. Obtain the results for the split-plot in time approach by using the following commands:
library(lmerTest) library(lme4) model<-lmer(resp ~ trt + factor(time) + trt:factor(time) + (1 | factor(subject) : (trt)) , repeated_measures_example_data) anova(model) #Type III Analysis of Variance Table with Satterthwaite s method # Sum Sq Mean Sq NumDF DenDF F value Pr(>F) #trt 15 8 2 6 7.14 0.02590 * #(time) 1301 650 2 12 605.62 8.9e-13 *** #trt:factor(time) 41 10 4 12 9.66 0.00099 *** #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
2. Run the analysis as a repeated-measures ANOVA by using different covariance structures. We can use the following commands:
library(nlme) model_cs<-gls(resp ~ trt + factor(time) + trt*factor(time),repeated_measures_example_data,correlation=corCompSymm(form=~1|subject),method="ML") model_AR<-gls(resp ~ trt + factor(time) + trt*factor(time),repeated_measures_example_data,correlation=corAR1(form=~1|subject),method="ML") model_UN<-gls(resp ~ trt + factor(time) + trt*factor(time),repeated_measures_example_data,correlation=corSymm(form=~1|subject),method="ML") Model_Selection <- data.frame( c ("","-2LogLik","AIC", "BIC"), c("CS", round(-2*summary(model_cs)$logLik,2),round(summary(model_cs)$AIC,2),round(summary(model_cs)$BIC,2)), c("AR1", round(-2*summary(model_AR)$logLik,2),round(summary(model_AR)$AIC,2),round(summary(model_AR)$BIC,2)), c("UN", round(-2*summary(model_UN)$logLik,2),round(summary(model_UN)$AIC,2),round(summary(model_UN)$BIC,2)), stringsAsFactors = FALSE) names(Model_Selection) <- c(" ", " ","","") print(Model_Selection) #1 CS AR1 UN #2 -2LogLik 80.54 82.03 69.95 #3 AIC 102.54 104.03 95.95 #4 BIC 116.79 118.29 112.79 detach(repeated_measures_example_data)