Learn R Programming

ez (version 4.4-0)

ezResample: Resample data from a factorial experiment

Description

This function resamples data (useful when bootstrapping and used by ezBoot).

Usage

ezResample( data , wid , within = NULL , between = NULL , resample_within = FALSE , resample_between = TRUE , check_args = TRUE )

Arguments

data
Data frame containing the data to be analyzed.
wid
.() object specifying the column in data that contains the variable specifying the case/Ss identifier.
within
Optional .() object specifying one or more columns in data that contain predictor variables that are manipulated (or observed) within-Ss.
between
Optional .() object specifying one or more columns in data that contain predictor variables that are manipulated (or observed) between-Ss.
resample_within
Logical. If TRUE, and if there are multiple observations per subject within each cell of the design specified by the factorial combination of variables supplied to within and between, then these observations-within-cells are resampled with replacement.
resample_between
Logical. If TRUE (default), levels of wid are resampled.
check_args
Users should leave this as its default (TRUE) value. This argument is intended for internal use only.

Value

A data frame consisting of the resampled data

See Also

ezBoot

Examples

Run this code
library(plyr)
#Read in the ANT data (see ?ANT).
data(ANT)
head(ANT)
ezPrecis(ANT)


#Bootstrap the within-cell variances
var_boots = ldply(
    .data = 1:1e1 #1e3 or higher should be used for publication
    , .fun = function(x){
        this_resample = ezResample(
            data = ANT[ANT$error==0,]
            , wid = .(subnum)
            , within = .(cue,flank)
            , between = .(group)
        )
        cell_vars = ddply(
            .data = idata.frame(this_resample)
            , .variables = .(subnum,cue,flank,group)
            , .fun = function(x){
                to_return = data.frame(
                    value = var(x$rt)
                )
                return(to_return)
            }
        )
        mean_cell_vars = ddply(
            .data = idata.frame(cell_vars)
            , .variables = .(cue,flank,group)
            , .fun = function(x){
                to_return = data.frame(
                    value = mean(x$value)
                )
                return(to_return)
            }
        )
        mean_cell_vars$iteration = x
        return(mean_cell_vars)
    }
    , .progress = 'time'
)



Run the code above in your browser using DataLab