Skip to content

Bootstrapping a repeated measures ANOVA

3 messages · Charles C. Berry, Fischer, Felix

#
On Fri, 16 Apr 2010, Fischer, Felix wrote:

            
"PLEASE ... provide commented, minimal, self-contained, reproducible 
code." Which means something a correspondent could actually run.

But before that, a careful reading of

 	?boot

should get you started. Note these bits:

Arguments:

     data: The data as a vector, ...

    statistic: A function which when applied to data returns a vector
           containing the statistic(s) of interest.  When
           sim="parametric",	[snip]
 		  In all other cases
           statistic must take at least two arguments.  The first
           argument passed will always be the original data. The second
           will be a vector of indices, frequencies or weights which
           define the bootstrap sample. ...



HTH,

Chuck
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901
#
Thank you for your answer. Sorry for the missing example.

In fact, i think, i solved the issue by some data-manipulations in the function. I splitted the data (one set for each measuring time), selected the cases at random, and then combined the two measuring times again. Results look promising to me, but if someone is aware of problems, please let me know.

This code should run:

library(boot)
anova.daten=data.frame(subject=sort(rep(1:10,2)), mz=rep(1:2,10), ort=sort(rep(1:2,10)),PHQ_Sum_score=rnorm(20,10,2))  #generate data

summary(aov(PHQ_Sum_score~mz*ort+Error(subject/mz),data=anova.daten))



 F_values <- function(formula, data1, indices) {
    data2=subset(data1, data1$mz==2)  #subsetting data for each measuring time
    data3=subset(data1, data1$mz==1)
    data4 <- data3[indices,] # allows boot to select sample
    subjekte=na.omit(data4$subject)
    data5=rbind(data3[subjekte,], data2[subjekte,]) #combine data
    data5$subject=factor(rep(1:length(subjekte),2)) #convert repeated subjects to unique subjects
    fit=aov(formula,data=data5)                #fit model
    return(c(summary(fit)[1][[1]][[1]]$`F value`, summary(fit)[2][[1]][[1]]$`F value`))     #return F-values
    }
  

  results <- boot(data=anova.daten, statistic=F_values,           
     R=10, formula=PHQ_Sum_score~mz*ort+Error(subject/mz))      #bootstrap



Thanks a lot,

Felix Fischer