ezResample: Resample data from a factorial experiment

Description Usage Arguments Value Author(s) See Also Examples

View source: R/ezResample.R

Description

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

Usage

1
2
3
4
5
6
7
8
9
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

Author(s)

Michael A. Lawrence mike.lwrnc@gmail.com
Visit the ez development site at http://github.com/mike-lawrence/ez
for the bug/issue tracker and the link to the mailing list.

See Also

ezBoot

Examples

 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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'
)

ez documentation built on May 2, 2019, 3:46 a.m.