nobsY: Compute Number of Observations for Left Hand Side of Formula

View source: R/nobsY.s

nobsYR Documentation

Compute Number of Observations for Left Hand Side of Formula

Description

After removing any artificial observations added by addMarginal, computes the number of non-missing observations for all left-hand-side variables in formula. If formula contains a term id(variable) variable is assumed to be a subject ID variable, and only unique subject IDs are counted. If group is given and its value is the name of a variable in the right-hand-side of the model, an additional object nobsg is returned that is a matrix with as many columns as there are left-hand variables, and as many rows as there are levels to the group variable. This matrix has the further breakdown of unique non-missing observations by group. The concatenation of all ID variables, is returned in a list element id.

Usage

nobsY(formula, group=NULL, data = NULL, subset = NULL,
      na.action = na.retain, matrixna=c('all', 'any'))

Arguments

formula

a formula object

group

character string containing optional name of a stratification variable for computing sample sizes

data

a data frame

subset

an optional subsetting criterion

na.action

an optional NA-handling function

matrixna

set to "all" if an observation is to be considered NA if all the columns of the variable are NA, otherwise use matrixna="any" to consider the row missing if any of the columns are missing

Value

an integer, with an attribute "formula" containing the original formula but with an id variable (if present) removed

Examples

d <- expand.grid(sex=c('female', 'male', NA),
                 country=c('US', 'Romania'),
                 reps=1:2)
d$subject.id <- c(0, 0, 3:12)
dm <- addMarginal(d, sex, country)
dim(dm)
nobsY(sex + country ~ 1, data=d)
nobsY(sex + country ~ id(subject.id), data=d)
nobsY(sex + country ~ id(subject.id) + reps, group='reps', data=d)
nobsY(sex ~ 1, data=d)
nobsY(sex ~ 1, data=dm)
nobsY(sex ~ id(subject.id), data=dm)

Hmisc documentation built on June 22, 2024, 12:19 p.m.