sampleSize_ordinal: Sample size for an ordinal exposure

View source: R/sampleSize_common.R

sampleSize_ordinalR Documentation

Sample size for an ordinal exposure

Description

Calculates the required sample size of as case-control study with an ordinal exposure variable

Usage

sampleSize_ordinal(prev, logOR, probX=NULL, distF=NULL, data=NULL, 
      size.2sided=0.05, power=0.9, cc.ratio=0.5, interval=c(-100, 100), tol=0.0001,
      n.samples=10000) 

Arguments

prev

Number between 0 and 1 giving the prevalence of disease. No default.

logOR

Vector of ordered log-odds ratios per category increase for the confounders and exposure. The last log-odds ratio in the vector is for the exposure. If the exposures are coded 0, 1, ..., k (k+1 categories), then the logOR corresponds to a one category increase. If the option data (below) is specified, then the order must match the order of data. No default.

probX

NULL or a vector that sums to 1 giving the probability that the exposure variable is equal to i, i = 0, 1, ..., k. If set to NULL, the the data option must be specified so that probX can be estimated. The default is NULL.

distF

NULL, a function or a character string giving the function to generate random vectors from the distribution of the confounders and exposure. The order of the returned vector must match the order of logOR. The default depends on other options (see details).

data

NULL, matrix, data frame or a list of type file.list that gives a sample from the distribution of the confounders and exposure. If a matrix or data frame, then the last column consists of random values for the exposure, while the other columns are for the confounders. The order of the columns must match the order of the vector logOR. The default is NULL.

size.2sided

Number between 0 and 1 giving the size of the 2-sided hypothesis test. The default is 0.05.

power

Number between 0 and 1 for the desired power of the test. The default is 0.9.

cc.ratio

Number between 0 and 1 for the proportion of cases in the case-control sample. The default is 0.5.

interval

Two element vector giving the interval to search for the estimated intercept parameter. The default is c(-100, 100).

tol

Positive value giving the stopping tolerance for the root finding method to estimate the intercept parameter. The default is 0.0001.

n.samples

Integer giving the number of random vectors to generate when the option distF is specified and is a random vector generation function. The default is 10000.

Details

If there are no confounders (length(logOR) = 1), then either probX or data must be specified, where probX takes precedance. If there are confounders (length(logOR) > 1), then either data or distF must be specified, where data takes precedance.

Value

A list containing four sample sizes, where two of them are for a Wald test and two for a score test. The two sample sizes for each test correspond to the equations for n_{1} and n_{2}.

See Also

sampleSize_continuous, sampleSize_binary, sampleSize_data

Examples

  prev  <- 0.01
  logOR <- 0.3

  # No confounders, Prob(X=1)=0.2
  sampleSize_ordinal(prev, logOR, probX=c(0.8, 0.2)) 

  # Generate data for a N(0,1) confounder and ordinal exposure with 3 levels
  data <- cbind(rnorm(1000), rbinom(1000, 2, 0.5))
  beta <- c(0.1, 0.2)
  sampleSize_ordinal(prev, beta, data=data) 

  # Define a function to generate random vectors for two confounders and an ordinal
  #   exposure with 5 levels
  f <- function(n) {cbind(rnorm(n), rbinom(n, 1, 0.5), rbinom(n, 4, 0.5))}
  beta <- c(0.2, 0.3, 0.25)
  sampleSize_ordinal(prev, beta, distF=f) 


samplesizelogisticcasecontrol documentation built on Aug. 21, 2023, 5:07 p.m.