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


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.


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



a formula object


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


a data frame


an optional subsetting criterion


an optional NA-handling function


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


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


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

harrelfe/Hmisc documentation built on May 19, 2024, 4:13 a.m.