[R-sig-ME] Using mixed-effects modelling to estimate between- and within-Ss variance in an effect
Mike Lawrence
Mike.Lawrence at dal.ca
Wed Jul 7 20:51:51 CEST 2010
To illustrate the measures I'm seeking, here's how I'd obtain them
normally (code alternatively downloadable at http://drop.io/qumwtvp):
library(ez)
data(ANT)
#simplify the data to a 2x2x2 for demonstration purposes
ANT = ANT[
ANT$cue %in% c('No Cue','Center Cue')
& ANT$flanker %in% c('Congruent Flanker','Incongruent Flanker')
& ANT$group %in% c('Control','Treatment')
,
]
#use bootstrap resampling to generate distributions of effects from
which the within- and between-Ss variance will be estimated
bootstrap_iterations = 10 #obviously for publication, use a much larger number!
boot = ldply(
.data = 1:bootstrap_iterations
, .fun = function(x){
resampled_ANT = ddply(
.data = ANT
, .variables = .(sid,group,cue,flanker)
, .fun = function(x){
to_return = x[ sample( 1:nrow(x) , nrow(x) , replace=T ) , ]
return(to_return)
}
)
resampled_ANT_scores = ddply(
.data = resampled_ANT
, .variables = .(sid,group)
, .fun = function(x){
cue_eff = mean(x$acc[x$cue=='No Cue']) - mean(x$acc[x$cue=='Center Cue'])
flank_eff = mean(x$acc[x$flanker=='Incongruent Flanker']) -
mean(x$acc[x$flanker=='Congruent Flanker'])
to_return = data.frame(
eff = c('cue','flank')
, value = c(cue_eff,flank_eff)
)
return(to_return)
}
)
resampled_ANT_scores$iteration = x
return(resampled_ANT_scores)
}
, .progress = 'text'
)
within_variance = ddply(
.data = boot
, .variables = .(sid,group,eff)
, .fun = function(x){
to_return = data.frame(
value = var(x$value)
)
return(to_return)
}
)
within_variance_stats = ddply(
.data = within_variance
, .variables = .(group,eff)
, .fun = function(x){
to_return = data.frame(
Mean = mean(x$value)
, SD = sd(x$value)
)
return(to_return)
}
)
print(within_variance_stats)
between_variance_per_iteration = ddply(
.data = boot
, .variables = .(iteration,group,eff)
, .fun = function(x){
to_return = data.frame(
value = var(x$value)
)
return(to_return)
}
)
between_variance_stats = ddply(
.data = between_variance_per_iteration
, .variables = .(group,eff)
, .fun = function(x){
to_return = data.frame(
Mean = mean(x$value)
, SD = sd(x$value)
)
return(to_return)
}
)
print(between_variance_stats)
More information about the R-sig-mixed-models
mailing list