upstrap: Upstrap Resampling

Description Usage Arguments Value Examples

View source: R/upstrap.R

Description

This function samples with replacement either more or fewer samples than the original sample size

Usage

1
upstrap(data, statistic, R, new_sample_size, ...)

Arguments

data

The data as a vector, matrix, or data frame. If it is a matrix or data frame then each row is considered as one multivariate observation.

statistic

A function which when applied to data returns a value containing the statistic of interest.

R

The number of upstrap replicates for each value in new_sample_size vector. This should be a single positive integer.

new_sample_size

A vector of one or more new sample sizes, to be drawn from the orignal data set. The new sample sizes can be less than, equal to, or larger than the original data set.

...

additional arguments to pass to statistic.

Value

matrix of R replicates of the statistic applied to the upstrap data. One column for each value in new_sample_size

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
# read in the data
fname = system.file("extdata", "shhs1.txt",
package = "upstrap")
data = read.table(file = fname,
                 header = TRUE, na.strings="NA")
# define the moderate to severe sleep apnea variable
# from rdi4p - Respiratory Disturbance Index (RDI)
data$MtS_SA = data$rdi4p>=15

#define statistic function
statistic = function(data) {
fit<-glm(MtS_SA ~ gender + age_s1 + bmi_s1 +
 HTNDerv_s1 + age_s1*HTNDerv_s1,
 family="binomial",
 data=data)

smod = coef(summary(fit))
pval = smod["HTNDerv_s1", "Pr(>|z|)"]
pval < 0.05
}

# do upstrap for the same sample size, 1.5 the original size
# and twice the original size
res = upstrap(data,
  statistic = statistic,
  R = 50,
  new_sample_size = c(nrow(data), nrow(data)\*1.5, nrow(data)\*2))

# display results
power_res = colMeans(res)

ccrainic/upstrap documentation built on Oct. 24, 2020, 2:21 p.m.