0

I am trying to work out on how to conduct a repeated measures ANOVA. My data is structured as followed

    means <- structure(list(col = c("c", "v1", "b1", "v2", "b2"), 
                `1` = c(8.55,9.73, 8.93, 9.52, 9.91), 
                `2` = c(8.4, 9.97, 9.08, 9.66, 9.97),
                `3` = c(8.48, 10.04, 9.13, 9.73, 10.04),
                `4` = c(8.42, 9.63,8.9, 9.34, 9.82), 
                `5` = c(8.42, 9.59, 8.87, 9.39, 9.69),
                `6` = c(8.52, 9.74, 9.02, 9.58, 9.84), 
                `7` = c(8.37, 9.67,8.98, 9.47, 9.74), 
                `8` = c(8.42, 9.67, 9.02, 9.52, 9.77), 
                `9` = c(8.56, 9.79, 9.36, 9.6, 9.78), 
                `10` = c(8.44, 9.63,9.15, 9.52, 9.67), 
                `11` = c(8.3, 9.58, 9.05, 9.49, 9.63),
                `12` = c(8.03, 9.33, 8.82, 9.23, 9.38),
                `13` = c(7.95, 9.08, 8.7, 9.04, 9.19), 
                `14` = c(8, 8.34, 8.37, 8.43, 8.54), 
                `15` = c(8.04,8.26, 8.4, 8.45, 8.61), 
                `16` = c(8.08, 8.09, 8.18, 8.16,8.28), 
                `17` = c(7.99, 8.06, 8.09, 8.15, 8.26), 
                `18` = c(8.06, 8.06, 8.09, 8.1, 8.22), 
                `19` = c(7.96, 7.96, 7.99, 8.03, 8.1),
                `20` = c(7.96, 7.98, 7.99, 7.99, 8.11), 
                `21` = c(8.16, 8.22, 8.22, 8.26, 8.33), 
                `22` = c(8.08, 8.16, 8.13, 8.2, 8.2), 
                `23` = c(7.94, 7.97, 7.94, 7.98, 8.07), 
                `24` = c(8.02,8.03, 8, 8.08, 8.1), 
                `25` = c(8.03, 8.08, 8.09, 8.12, 8.15), 
                `26` = c(7.92, 7.95, 7.95, 7.96, 7.98)), 
                        .Names = c("col","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
                                 "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23","24", "25", "26"), 
                                        class = c("data.table", "data.frame"))

where "col" represent different substrates (treatments) and the numbers in the header are measurements over time. This is only part of the data.

To conduct the repeated measurements ANOVA (which is hopefully the right statistical test), I tried to follow several examples I found in the net, e.g. http://rtutorialseries.blogspot.de/2011/02/r-tutorial-series-one-way-repeated.html

    # step 1 Define the levels:
    levels <- c(1:26)
    # define factor
    factor <- as.factor(levels)
    #define the frame
    frame <- data.frame(factor)
    # bind the colums
    bind <- cbind (means$`1`,means$`2`,means$`3`,means$`4`,means$`5`,means$`6`,means$`7`,means$`8`,means$`9`,means$`10`,means$`11`,means$`12`,means$`13`,means$`14`,means$`15`,means$`16`,means$`17`,means$`18`,means$`19`,means$`20`,means$`21`,means$`22`,means$`23`,means$`24`,means$`25`,means$`26`)


# define the model
model <- lm(ph_bind ~ 1)
# ANOVA
analysis <- Anova(model, idata=frame, idesign= ~factor)

This results in:

> analysis <- Anova(model, idata = factor, idesign = ~factor)
Warning message:
In Anova.lm(model, idata = factor, idesign = ~factor) :
  the model contains only an intercept: Type III test substituted
> summary (analysis)
     Sum Sq              Df         F value          Pr(>F) 
 Min.   :  61.59   Min.   :  1   Min.   :20519   Min.   :0  
 1st Qu.:2495.43   1st Qu.: 33   1st Qu.:20519   1st Qu.:0  
 Median :4929.27   Median : 65   Median :20519   Median :0  
 Mean   :4929.27   Mean   : 65   Mean   :20519   Mean   :0  
 3rd Qu.:7363.10   3rd Qu.: 97   3rd Qu.:20519   3rd Qu.:0  
 Max.   :9796.94   Max.   :129   Max.   :20519   Max.   :0  
                                 NA's   :1       NA's   :1

This is not the expected output I was hoping for. What am I doing wrong?

Grateful for any help:)

rhavan
  • 3
  • 4
  • 1
    Asking if ANOVA is the right test for you is off topic for Stack Overflow. You should ask questions about statistical methods on [stats.se] instead. Also when asking for help here, be sure to share your data in a [reproducible format](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – MrFlick Mar 12 '18 at 18:40
  • Thank you for reproducible format link, helped a lot! I also posted the question in Cross Validated. Didn't know about that, I'll delete the question here shortly – rhavan Mar 13 '18 at 12:34
  • My post in cross validated was marked off topic, b/c it was marked with R... Anyway, I edited the data input, maybe someone here can help?:) – rhavan Mar 14 '18 at 14:29

0 Answers0