Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>using the nlme library...</p> <p>Answering your stated question, you can create a random intecept mixed effect model using the following code:</p> <pre><code>&gt; library(nlme) &gt; m1 &lt;- lme(Score ~ Condition + Time + Condition*Time, + data = myDat, random = ~ 1 | Subject) &gt; summary(m1) Linear mixed-effects model fit by REML Data: myDat AIC BIC logLik 31.69207 37.66646 -9.846036 Random effects: Formula: ~1 | Subject (Intercept) Residual StdDev: 5.214638e-06 0.3151035 Fixed effects: Score ~ Condition + Time + Condition * Time Value Std.Error DF t-value p-value (Intercept) 0.6208333 0.2406643 14 2.579666 0.0218 Condition 0.7841667 0.3403507 6 2.303996 0.0608 Time 0.9900000 0.1114059 14 8.886423 0.0000 Condition:Time 0.0637500 0.1575517 14 0.404629 0.6919 Correlation: (Intr) Condtn Time Condition -0.707 Time -0.926 0.655 Condition:Time 0.655 -0.926 -0.707 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -1.5748794 -0.6704147 0.2069426 0.7467785 1.5153752 Number of Observations: 24 Number of Groups: 8 </code></pre> <p>The intercept variance is basically 0, indicating no within subject effect, so this model is not capturing the between time relationship well. A random intercept model is rarely the type of model you want for a repeated measures design. A random intercept model assumes that the correlations between all time points are equal. i.e. the correlation between time 1 and time 2 is the same as between time 1 and time 3. Under normal circumstances (perhaps not those generating your fake data) we would expect the later to be less than the former. An auto regressive structure is usually a better way to go. </p> <pre><code>&gt; m2&lt;-gls(Score ~ Condition + Time + Condition*Time, + data = myDat, correlation = corAR1(form = ~ Time | Subject)) &gt; summary(m2) Generalized least squares fit by REML Model: Score ~ Condition + Time + Condition * Time Data: myDat AIC BIC logLik 25.45446 31.42886 -6.727232 Correlation Structure: AR(1) Formula: ~Time | Subject Parameter estimate(s): Phi -0.5957973 Coefficients: Value Std.Error t-value p-value (Intercept) 0.6045402 0.1762743 3.429543 0.0027 Condition 0.8058448 0.2492895 3.232566 0.0042 Time 0.9900000 0.0845312 11.711652 0.0000 Condition:Time 0.0637500 0.1195452 0.533271 0.5997 Correlation: (Intr) Condtn Time Condition -0.707 Time -0.959 0.678 Condition:Time 0.678 -0.959 -0.707 Standardized residuals: Min Q1 Med Q3 Max -1.6850557 -0.6730898 0.2373639 0.8269703 1.5858942 Residual standard error: 0.2976964 Degrees of freedom: 24 total; 20 residual </code></pre> <p>Your data is showing a -.596 between time point correlation, which seems odd. normally there should, at a minimum be a positive correlation between time points. How was this data generated?</p> <p>addendum:</p> <p>With your new data we know that the data generating process is equivalent to a random intercept model (though that is not the most realistic for a longitudinal study. The visualization shows that the effect of time seems to be fairly linear, so we should feel comfortable treating it as a numeric variable.</p> <pre><code>&gt; library(nlme) &gt; m1 &lt;- lme(Score ~ Condition + as.numeric(Time) + Condition*as.numeric(Time), + data = myDat, random = ~ 1 | Subject) &gt; summary(m1) Linear mixed-effects model fit by REML Data: myDat AIC BIC logLik 38.15055 44.12494 -13.07527 Random effects: Formula: ~1 | Subject (Intercept) Residual StdDev: 0.2457355 0.3173421 Fixed effects: Score ~ Condition + as.numeric(Time) + Condition * as.numeric(Time) Value Std.Error DF t-value p-value (Intercept) 1.142500 0.2717382 14 4.204415 0.0009 ConditionYes 1.748333 0.3842958 6 4.549447 0.0039 as.numeric(Time) 0.575000 0.1121974 14 5.124898 0.0002 ConditionYes:as.numeric(Time) -0.197500 0.1586710 14 -1.244714 0.2337 Correlation: (Intr) CndtnY as.(T) ConditionYes -0.707 as.numeric(Time) -0.826 0.584 ConditionYes:as.numeric(Time) 0.584 -0.826 -0.707 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -1.44560367 -0.65018585 0.01864079 0.52930925 1.40824838 Number of Observations: 24 Number of Groups: 8 </code></pre> <p>We see a significant Condition effect, indicating that the 'yes' condition tends to have higher scores (by about 1.7), and a significant time effect, indicating that both groups go up over time. Supporting the plot, we find no differential effect of time between the two groups (the interaction). i.e. the slopes are the same.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload