2 way repeated measures

I have started analyzing my data using R software in 2 way repeated measures according to, "NormalWithR (toronto.edu)". it uses lme4 and car libraries. It worked fine, but when I proceed for # Two-way table of means by command, "Anokhi = meantable[1:4, 4]; Desi Karela = meantable[5:8, 4]" as mentioned in above said pdf, it displayed error message, "Error: object 'meantable' not found".
kindly help me to resolve this issue.

From the console

> ls()

if meantable does not appear, it means that it hasn't been created (is "not in the namespace") and any references to it will produce the error.

1 Like

Looking at the pdf, it looks like they forgot to assign this variable. Judging by the context, on page 2 it should be:

meantable = aggregate(rtime,by=list(ear,handed),FUN=mean) # First changes fastest
1 Like

I am a PhD student in Food Technology and harvested 10 fruit varieties at 4 maturity stages. I need mixed nodel ANOVA in repeated measures 2 way with simple effects, mean effects, interaction effects and interaction graphs.
Meantable is formed but when proceed for two way mean table then error displayed is, " length of 'dimnames' [2] not equal to array extent" and no two way table is produced. also when I used command "# Want a table of means in a similar format., "> meantable # Again" it shows one way mean table as in middle and now two way table. Your help in this regard will be highly appreciated.
the commands which I used along with their outcome are as under.

library(lme4)
> library(car)
> data <-read.csv(file.choose())
> head(data)
> str(data)
'data.frame':	120 obs. of  4 variables:
 $ sub      : int  1 1 1 1 1 1 1 1 1 1 ...
 $ varieties: chr  "Anokhi" "Anokhi" "Anokhi" "Desikarela" ...
 $ stages   : chr  "S1" "S1" "S1" "S1" ...
 $ vitc     : num  137 135 139 146 141 ...
> attach(dichotic) # Make variable names available
Error in attach(dichotic) : object 'dichotic' not found
> attach(data) # Make variable names available
**The following objects are masked from data (pos = 3):**

**    stages, sub, varieties, vitc**

**The following objects are masked from data (pos = 4):**

**    stages, sub, varieties, vitc**

> # Sample sizes
> table(varieties, stages)
             stages
varieties     S1 S2 S3 S4
  Anokhi       3  3  3  3
  Desikarela   3  3  3  3
  Dilbahar     3  3  3  3
  Gurh         3  3  3  3
  Khobani      3  3  3  3
  Mahmoodwali  3  3  3  3
  Munirwali    3  3  3  3
  Pakwhite     3  3  3  3
  Suffon       3  3  3  3
  Umran        3  3  3  3
> # Treatment means
> meantable=aggregate(vitc, by=list(stages, varieties), FUN=mean)
> # Two-way table of means
> Anokhi = meantable[1:4, 4]; Desikarela = meantable[5:8, 4]; Dilbahar = meantable[9:12, 4]; Gurh = meantable[13:16, 4]; Khobani = meantable[17:20, 4]; Mahmoodwali = meantable[21:24, 4]; Munirwali = meantable[25:28, 4]; Pakwhite = meantable[29:32, 4]; Suffon = meantable[33:36, 4]; Umran = meantable[37:40, 4]
> aggregate(vitc, by=list(stages, varieties), FUN=mean)
> # Two-way table of means
> Anokhi = meantable[1:4, 4]; Desikarela = meantable[5:8, 4]; Dilbahar = meantable[9:12, 4]; Gurh = meantable[13:16, 4]; Khobani = meantable[17:20, 4]; Mahmoodwali = meantable[21:24, 4]; Munirwali = meantable[25:28, 4]; Pakwhite = meantable[29:32, 4]; Suffon = meantable[33:36, 4]; Umran = meantable[37:40, 4]
> TwoWay = rbind(varieties,stages)
> colnames(TwoWay) = c("S1","S2","S3","S4")
Error in dimnames(x) <- dn : 
  length of 'dimnames' [2] not equal to array extent
> 
> TwoWay
          [,1]     [,2]     [,3]     [,4]         [,5]         [,6]        
varieties "Anokhi" "Anokhi" "Anokhi" "Desikarela" "Desikarela" "Desikarela"
stages    "S1"     "S1"     "S1"     "S1"         "S1"         "S1"        
          [,7]       [,8]       [,9]       [,10]  [,11]  [,12]  [,13]     [,14]    
varieties "Dilbahar" "Dilbahar" "Dilbahar" "Gurh" "Gurh" "Gurh" "Khobani" "Khobani"
stages    "S1"       "S1"       "S1"       "S1"   "S1"   "S1"   "S1"      "S1"     
          [,15]     [,16]         [,17]         [,18]         [,19]      
varieties "Khobani" "Mahmoodwali" "Mahmoodwali" "Mahmoodwali" "Munirwali"
stages    "S1"      "S1"          "S1"          "S1"          "S1"       
          [,20]       [,21]       [,22]      [,23]      [,24]      [,25]   
varieties "Munirwali" "Munirwali" "Pakwhite" "Pakwhite" "Pakwhite" "Suffon"
stages    "S1"        "S1"        "S1"       "S1"       "S1"       "S1"    
          [,26]    [,27]    [,28]   [,29]   [,30]   [,31]    [,32]    [,33]   
varieties "Suffon" "Suffon" "Umran" "Umran" "Umran" "Anokhi" "Anokhi" "Anokhi"
stages    "S1"     "S1"     "S1"    "S1"    "S1"    "S2"     "S2"     "S2"    
          [,34]        [,35]        [,36]        [,37]      [,38]      [,39]     
varieties "Desikarela" "Desikarela" "Desikarela" "Dilbahar" "Dilbahar" "Dilbahar"
stages    "S2"         "S2"         "S2"         "S2"       "S2"       "S2"      
          [,40]  [,41]  [,42]  [,43]     [,44]     [,45]     [,46]        
varieties "Gurh" "Gurh" "Gurh" "Khobani" "Khobani" "Khobani" "Mahmoodwali"
stages    "S2"   "S2"   "S2"   "S2"      "S2"      "S2"      "S2"         
          [,47]         [,48]         [,49]       [,50]       [,51]      
varieties "Mahmoodwali" "Mahmoodwali" "Munirwali" "Munirwali" "Munirwali"
stages    "S2"          "S2"          "S2"        "S2"        "S2"       
          [,52]      [,53]      [,54]      [,55]    [,56]    [,57]    [,58]  
varieties "Pakwhite" "Pakwhite" "Pakwhite" "Suffon" "Suffon" "Suffon" "Umran"
stages    "S2"       "S2"       "S2"       "S2"     "S2"     "S2"     "S2"   
          [,59]   [,60]   [,61]    [,62]    [,63]    [,64]        [,65]       
varieties "Umran" "Umran" "Anokhi" "Anokhi" "Anokhi" "Desikarela" "Desikarela"
stages    "S2"    "S2"    "S3"     "S3"     "S3"     "S3"         "S3"        
          [,66]        [,67]      [,68]      [,69]      [,70]  [,71]  [,72] 
varieties "Desikarela" "Dilbahar" "Dilbahar" "Dilbahar" "Gurh" "Gurh" "Gurh"
stages    "S3"         "S3"       "S3"       "S3"       "S3"   "S3"   "S3"  
          [,73]     [,74]     [,75]     [,76]         [,77]         [,78]        
varieties "Khobani" "Khobani" "Khobani" "Mahmoodwali" "Mahmoodwali" "Mahmoodwali"
stages    "S3"      "S3"      "S3"      "S3"          "S3"          "S3"         
          [,79]       [,80]       [,81]       [,82]      [,83]      [,84]     
varieties "Munirwali" "Munirwali" "Munirwali" "Pakwhite" "Pakwhite" "Pakwhite"
stages    "S3"        "S3"        "S3"        "S3"       "S3"       "S3"      
          [,85]    [,86]    [,87]    [,88]   [,89]   [,90]   [,91]    [,92]   
varieties "Suffon" "Suffon" "Suffon" "Umran" "Umran" "Umran" "Anokhi" "Anokhi"
stages    "S3"     "S3"     "S3"     "S3"    "S3"    "S3"    "S4"     "S4"    
          [,93]    [,94]        [,95]        [,96]        [,97]      [,98]     
varieties "Anokhi" "Desikarela" "Desikarela" "Desikarela" "Dilbahar" "Dilbahar"
stages    "S4"     "S4"         "S4"         "S4"         "S4"       "S4"      
          [,99]      [,100] [,101] [,102] [,103]    [,104]    [,105]   
varieties "Dilbahar" "Gurh" "Gurh" "Gurh" "Khobani" "Khobani" "Khobani"
stages    "S4"       "S4"   "S4"   "S4"   "S4"      "S4"      "S4"     
          [,106]        [,107]        [,108]        [,109]      [,110]     
varieties "Mahmoodwali" "Mahmoodwali" "Mahmoodwali" "Munirwali" "Munirwali"
stages    "S4"          "S4"          "S4"          "S4"        "S4"       
          [,111]      [,112]     [,113]     [,114]     [,115]   [,116]   [,117]  
varieties "Munirwali" "Pakwhite" "Pakwhite" "Pakwhite" "Suffon" "Suffon" "Suffon"
stages    "S4"        "S4"       "S4"       "S4"       "S4"     "S4"     "S4"    
          [,118]  [,119]  [,120] 
varieties "Umran" "Umran" "Umran"
stages    "S4"    "S4"    "S4"   
> TwoWay(meantable)
Error in TwoWay(meantable) : could not find function "TwoWay"
> # Marginal means
> 
> aggregate(rtime,by=list(varieties),FUN=mean)
Error in aggregate(rtime, by = list(varieties), FUN = mean) : 
  object 'rtime' not found
> aggregate(vitc,by=list(varieties),FUN=mean)
> # Repeated measures with a mixed model
> dichotic = lmer(vitc ~ varieties*stages + (1 | subject))
Error in eval(predvars, data, env) : object 'subject' not found
> dichotic = lmer(rtime ~ handed*ear + (1 | sub))
Error in eval(predvars, data, env) : object 'rtime' not found
> dichotic = lmer(vitc ~ varieties*stages + (1 | sub))
> Anova(dichotic, test="F") # F tests (from car package)
Analysis of Deviance Table (Type II Wald F tests with Kenward-Roger df)

> 
> # Multiple comparisons: Which marginal means are different?
> 
> # The combination variable varietiesstages will have 40 values
> n = length(vitc); n
[1] 120
> varietiesstages = character(n) # A character-valued variable of length n
> for(j in 1:n) varietiesstages[j] = paste(varieties[j],stages[j],sep='')
> 
> varietiesstages = factor(varietiesstages) # Maybe would be interpreted as a factor anyway
> head(data.frame(varieties,stages,varietiesstages))
   varieties stages varietiesstages
1     Anokhi     S1        AnokhiS1
2     Anokhi     S1        AnokhiS1
3     Anokhi     S1        AnokhiS1
4 Desikarela     S1    DesikarelaS1
5 Desikarela     S1    DesikarelaS1
6 Desikarela     S1    DesikarelaS1
> 
> table(varietiesstages) # Sample sizes
varietiesstages
     AnokhiS1      AnokhiS2      AnokhiS3      AnokhiS4  DesikarelaS1  DesikarelaS2 
            3             3             3             3             3             3 
 DesikarelaS3  DesikarelaS4    DilbaharS1    DilbaharS2    DilbaharS3    DilbaharS4 
            3             3             3             3             3             3 
       GurhS1        GurhS2        GurhS3        GurhS4     KhobaniS1     KhobaniS2 
            3             3             3             3             3             3 
    KhobaniS3     KhobaniS4 MahmoodwaliS1 MahmoodwaliS2 MahmoodwaliS3 MahmoodwaliS4 
            3             3             3             3             3             3 
  MunirwaliS1   MunirwaliS2   MunirwaliS3   MunirwaliS4    PakwhiteS1    PakwhiteS2 
            3             3             3             3             3             3 
   PakwhiteS3    PakwhiteS4      SuffonS1      SuffonS2      SuffonS3      SuffonS4 
            3             3             3             3             3             3 
      UmranS1       UmranS2       UmranS3       UmranS4 
            3             3             3             3 
> # Want a table of means in a similar format.
> meantable # Again

I am a PhD student in Food Technology and harvested 10 fruit varieties at 4 maturity stages. I need mixed nodel ANOVA in repeated measures 2 way with simple effects, mean effects, interaction effects and interaction graphs.
Meantable is formed by command, "aggregate(vitc, by=list(stages, varieties), FUN=mean)" however, command specified by you, "meantable=aggregate(vitc, by=list(stages, varieties), FUN=mean)" produce no results and when proceed for two way mean table by Commands,, "> TwoWay = rbind(varieties,stages)

colnames(TwoWay) = c("S1","S2","S3","S4")
then Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent" is displayed" and no two way table is produced. also when I used command "# Want a table of means in a similar format., "> meantable # Again" it shows one way mean table as in middle and now two way table. Your help in this regard will be highly appreciated.
the commands which I used along with their outcome are as under.

library(lme4)
> library(car)
> data <-read.csv(file.choose())
> head(data)
 > str(data)
'data.frame':	120 obs. of  4 variables:
 $ sub      : int  1 1 1 1 1 1 1 1 1 1 ...
 $ varieties: chr  "Anokhi" "Anokhi" "Anokhi" "Desikarela" ...
 $ stages   : chr  "S1" "S1" "S1" "S1" ...
 $ vitc     : num  137 135 139 146 141 ...
> attach(dichotic) # Make variable names available
Error in attach(dichotic) : object 'dichotic' not found
> attach(data) # Make variable names available
The following objects are masked from data (pos = 3):

    stages, sub, varieties, vitc

The following objects are masked from data (pos = 4):

    stages, sub, varieties, vitc

> # Sample sizes
> table(handed,ear)
Error in table(handed, ear) : object 'handed' not found
> table(varieties, stages)
             stages
varieties     S1 S2 S3 S4
  Anokhi       3  3  3  3
  Desikarela   3  3  3  3
  Dilbahar     3  3  3  3
  Gurh         3  3  3  3
  Khobani      3  3  3  3
  Mahmoodwali  3  3  3  3
  Munirwali    3  3  3  3
  Pakwhite     3  3  3  3
  Suffon       3  3  3  3
  Umran        3  3  3  3
> # Treatment means
> meantable=aggregate(vitc, by=list(stages, varieties), FUN=mean)
> # Two-way table of means
> Anokhi = meantable[1:4, 4]; Desikarela = meantable[5:8, 4]; Dilbahar = meantable[9:12, 4]; Gurh = meantable[13:16, 4]; Khobani = meantable[17:20, 4]; Mahmoodwali = meantable[21:24, 4]; Munirwali = meantable[25:28, 4]; Pakwhite = meantable[29:32, 4]; Suffon = meantable[33:36, 4]; Umran = meantable[37:40, 4]
> aggregate(vitc, by=list(stages, varieties), FUN=mean)
 > # Two-way table of means
> Anokhi = meantable[1:4, 4]; Desikarela = meantable[5:8, 4]; Dilbahar = meantable[9:12, 4]; Gurh = meantable[13:16, 4]; Khobani = meantable[17:20, 4]; Mahmoodwali = meantable[21:24, 4]; Munirwali = meantable[25:28, 4]; Pakwhite = meantable[29:32, 4]; Suffon = meantable[33:36, 4]; Umran = meantable[37:40, 4]
> TwoWay = rbind(varieties,stages)
> colnames(TwoWay) = c("S1","S2","S3","S4")
Error in dimnames(x) <- dn : 
  length of 'dimnames' [2] not equal to array extent
> 
> TwoWay
          [,1]     [,2]     [,3]     [,4]         [,5]         [,6]        
varieties "Anokhi" "Anokhi" "Anokhi" "Desikarela" "Desikarela" "Desikarela"
stages    "S1"     "S1"     "S1"     "S1"         "S1"         "S1"        
          [,7]       [,8]       [,9]       [,10]  [,11]  [,12]  [,13]     [,14]    
varieties "Dilbahar" "Dilbahar" "Dilbahar" "Gurh" "Gurh" "Gurh" "Khobani" "Khobani"
stages    "S1"       "S1"       "S1"       "S1"   "S1"   "S1"   "S1"      "S1"     
          [,15]     [,16]         [,17]         [,18]         [,19]      
varieties "Khobani" "Mahmoodwali" "Mahmoodwali" "Mahmoodwali" "Munirwali"
stages    "S1"      "S1"          "S1"          "S1"          "S1"       
          [,20]       [,21]       [,22]      [,23]      [,24]      [,25]   
varieties "Munirwali" "Munirwali" "Pakwhite" "Pakwhite" "Pakwhite" "Suffon"
stages    "S1"        "S1"        "S1"       "S1"       "S1"       "S1"    
          [,26]    [,27]    [,28]   [,29]   [,30]   [,31]    [,32]    [,33]   
varieties "Suffon" "Suffon" "Umran" "Umran" "Umran" "Anokhi" "Anokhi" "Anokhi"
stages    "S1"     "S1"     "S1"    "S1"    "S1"    "S2"     "S2"     "S2"    
          [,34]        [,35]        [,36]        [,37]      [,38]      [,39]     
varieties "Desikarela" "Desikarela" "Desikarela" "Dilbahar" "Dilbahar" "Dilbahar"
stages    "S2"         "S2"         "S2"         "S2"       "S2"       "S2"      
          [,40]  [,41]  [,42]  [,43]     [,44]     [,45]     [,46]        
varieties "Gurh" "Gurh" "Gurh" "Khobani" "Khobani" "Khobani" "Mahmoodwali"
stages    "S2"   "S2"   "S2"   "S2"      "S2"      "S2"      "S2"         
          [,47]         [,48]         [,49]       [,50]       [,51]      
varieties "Mahmoodwali" "Mahmoodwali" "Munirwali" "Munirwali" "Munirwali"
stages    "S2"          "S2"          "S2"        "S2"        "S2"       
          [,52]      [,53]      [,54]      [,55]    [,56]    [,57]    [,58]  
varieties "Pakwhite" "Pakwhite" "Pakwhite" "Suffon" "Suffon" "Suffon" "Umran"
stages    "S2"       "S2"       "S2"       "S2"     "S2"     "S2"     "S2"   
          [,59]   [,60]   [,61]    [,62]    [,63]    [,64]        [,65]       
varieties "Umran" "Umran" "Anokhi" "Anokhi" "Anokhi" "Desikarela" "Desikarela"
stages    "S2"    "S2"    "S3"     "S3"     "S3"     "S3"         "S3"        
          [,66]        [,67]      [,68]      [,69]      [,70]  [,71]  [,72] 
varieties "Desikarela" "Dilbahar" "Dilbahar" "Dilbahar" "Gurh" "Gurh" "Gurh"
stages    "S3"         "S3"       "S3"       "S3"       "S3"   "S3"   "S3"  
          [,73]     [,74]     [,75]     [,76]         [,77]         [,78]        
varieties "Khobani" "Khobani" "Khobani" "Mahmoodwali" "Mahmoodwali" "Mahmoodwali"
stages    "S3"      "S3"      "S3"      "S3"          "S3"          "S3"         
          [,79]       [,80]       [,81]       [,82]      [,83]      [,84]     
varieties "Munirwali" "Munirwali" "Munirwali" "Pakwhite" "Pakwhite" "Pakwhite"
stages    "S3"        "S3"        "S3"        "S3"       "S3"       "S3"      
          [,85]    [,86]    [,87]    [,88]   [,89]   [,90]   [,91]    [,92]   
varieties "Suffon" "Suffon" "Suffon" "Umran" "Umran" "Umran" "Anokhi" "Anokhi"
stages    "S3"     "S3"     "S3"     "S3"    "S3"    "S3"    "S4"     "S4"    
          [,93]    [,94]        [,95]        [,96]        [,97]      [,98]     
varieties "Anokhi" "Desikarela" "Desikarela" "Desikarela" "Dilbahar" "Dilbahar"
stages    "S4"     "S4"         "S4"         "S4"         "S4"       "S4"      
          [,99]      [,100] [,101] [,102] [,103]    [,104]    [,105]   
varieties "Dilbahar" "Gurh" "Gurh" "Gurh" "Khobani" "Khobani" "Khobani"
stages    "S4"       "S4"   "S4"   "S4"   "S4"      "S4"      "S4"     
          [,106]        [,107]        [,108]        [,109]      [,110]     
varieties "Mahmoodwali" "Mahmoodwali" "Mahmoodwali" "Munirwali" "Munirwali"
stages    "S4"          "S4"          "S4"          "S4"        "S4"       
          [,111]      [,112]     [,113]     [,114]     [,115]   [,116]   [,117]  
varieties "Munirwali" "Pakwhite" "Pakwhite" "Pakwhite" "Suffon" "Suffon" "Suffon"
stages    "S4"        "S4"       "S4"       "S4"       "S4"     "S4"     "S4"    
          [,118]  [,119]  [,120] 
varieties "Umran" "Umran" "Umran"
stages    "S4"    "S4"    "S4"   
> TwoWay(meantable)
Error in TwoWay(meantable) : could not find function "TwoWay"
> # Marginal means
> 
> aggregate(rtime,by=list(varieties),FUN=mean)
Error in aggregate(rtime, by = list(varieties), FUN = mean) : 
  object 'rtime' not found
> aggregate(vitc,by=list(varieties),FUN=mean)
 > aggregate(vitc,by=list(stages),FUN=mean)
 > # Naive fixed effects analysis
> 
> anova(lm(vitc ~ varieties*stages)) 
Analysis of Variance Table

> # Repeated measures with a mixed model
> dichotic = lmer(vitc ~ varieties*stages + (1 | subject))
Error in eval(predvars, data, env) : object 'subject' not found
> dichotic = lmer(rtime ~ handed*ear + (1 | sub))
Error in eval(predvars, data, env) : object 'rtime' not found
> dichotic = lmer(vitc ~ varieties*stages + (1 | sub))
> Anova(dichotic, test="F") # F tests (from car package)
Analysis of Deviance Table (Type II Wald F tests with Kenward-Roger df)

> # Multiple comparisons: Which marginal means are different?
> 
> # The combination variable varietiesstages will have 40 values
> n = length(vitc); n
[1] 120
> varietiesstages = character(n) # A character-valued variable of length n
> for(j in 1:n) varietiesstages[j] = paste(varieties[j],stages[j],sep='')
> 
> varietiesstages = factor(varietiesstages) # Maybe would be interpreted as a factor anyway
> head(data.frame(varieties,stages,varietiesstages))
   varieties stages varietiesstages
1     Anokhi     S1        AnokhiS1
2     Anokhi     S1        AnokhiS1
3     Anokhi     S1        AnokhiS1
4 Desikarela     S1    DesikarelaS1
5 Desikarela     S1    DesikarelaS1
6 Desikarela     S1    DesikarelaS1
> 
> table(varietiesstages) # Sample sizes
varietiesstages
     AnokhiS1      AnokhiS2      AnokhiS3      AnokhiS4  DesikarelaS1  DesikarelaS2 
            3             3             3             3             3             3 
 DesikarelaS3  DesikarelaS4    DilbaharS1    DilbaharS2    DilbaharS3    DilbaharS4 
            3             3             3             3             3             3 
       GurhS1        GurhS2        GurhS3        GurhS4     KhobaniS1     KhobaniS2 
            3             3             3             3             3             3 
    KhobaniS3     KhobaniS4 MahmoodwaliS1 MahmoodwaliS2 MahmoodwaliS3 MahmoodwaliS4 
            3             3             3             3             3             3 
  MunirwaliS1   MunirwaliS2   MunirwaliS3   MunirwaliS4    PakwhiteS1    PakwhiteS2 
            3             3             3             3             3             3 
   PakwhiteS3    PakwhiteS4      SuffonS1      SuffonS2      SuffonS3      SuffonS4 
            3             3             3             3             3             3 
      UmranS1       UmranS2       UmranS3       UmranS4 
            3             3             3             3 
> # Want a table of means in a similar format.
> meantable # Again
 

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.