nobsY.RdAfter 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'),
reps=1:2)
d$subject.id <- c(0, 0, 3:12)
dm <- addMarginal(d, sex, country)
dim(dm)
#> [1] 48 5
nobsY(sex + country ~ 1, data=d)
#> $nobs
#> sex country
#> 8 12
#>
#> $nobsg
#> NULL
#>
#> $id
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12
#>
#> $formula
#> sex + country ~ 1
#> <environment: 0x58f68dc407e8>
#>
nobsY(sex + country ~ id(subject.id), data=d)
#> $nobs
#> sex country
#> 7 11
#>
#> $nobsg
#> NULL
#>
#> $id
#> [1] 0 0 3 4 5 6 7 8 9 10 11 12
#>
#> $formula
#> sex + country ~ 1
#> <environment: 0x58f68d8446b0>
#>
nobsY(sex + country ~ id(subject.id) + reps, group='reps', data=d)
#> $nobs
#> sex country
#> 7 11
#>
#> $nobsg
#> sex country
#> 1 3 5
#> 2 4 6
#>
#> $id
#> [1] 0 0 3 4 5 6 7 8 9 10 11 12
#>
#> $formula
#> sex + country ~ id(subject.id) + reps
#> <environment: 0x58f68d6c4330>
#>
nobsY(sex ~ 1, data=d)
#> $nobs
#> sex
#> 8
#>
#> $nobsg
#> NULL
#>
#> $id
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12
#>
#> $formula
#> sex ~ 1
#> <environment: 0x58f68dc407e8>
#>
nobsY(sex ~ 1, data=dm)
#> $nobs
#> sex
#> 8
#>
#> $nobsg
#> NULL
#>
#> $id
#> [1] 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] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#>
#> $formula
#> sex ~ 1
#> <environment: 0x58f68dc407e8>
#>
nobsY(sex ~ id(subject.id), data=dm)
#> $nobs
#> sex
#> 7
#>
#> $nobsg
#> NULL
#>
#> $id
#> [1] 0 0 3 4 5 6 7 8 9 10 11 12 0 0 3 4 5 6 7 8 9 10 11 12 0
#> [26] 0 3 4 5 6 7 8 9 10 11 12 0 0 3 4 5 6 7 8 9 10 11 12
#>
#> $formula
#> sex ~ id(subject.id)
#> <environment: 0x58f68d312198>
#>