Learn R Programming

mosaic (version 0.5-1)

mm: Construct a model based on groupwise means

Description

Calculate groupwise means, presenting the result as a model in the style of lm.

Usage

mm(formula, data = parent.frame(), fun = mean,
    drop = TRUE, ...)

## S3 method for class 'groupwiseModel': confint(object, parm, level = 0.95, ..., pooled = TRUE, margin = FALSE)

## S3 method for class 'groupwiseModel': coef(object, ...)

## S3 method for class 'groupwiseModel': print(x, ...)

## S3 method for class 'groupwiseModel': residuals(object, ...)

## S3 method for class 'groupwiseModel': fitted(object, ...)

## S3 method for class 'groupwiseModel': summary(object, ...)

## S3 method for class 'summary.groupwiseModel': print(x, ...)

Arguments

formula
A formula. The left-hand side specifies the variable over which the mean will be taken. The right-hand side gives the grouping variables, separated by &.
data
A data frame to which the formula variables refer. If not specified, variables will be taken from the current environment.
fun
The function used to calculate the means. Default: mean.
drop
Logical flag indicating whether to drop unoccupied groups. Default TRUE. NOT YET IMPLEMENTED.
...
Additional arguments to be passed to the fun doing the calculation.
parm
Not used
level
The confidence level (e.g., 0.95)
pooled
Whether to use a pooled variance of residuals to compute the standard error. (This is what lm does.)
margin
Whether to present the margin of error rather than the lower and upper bounds
x
Object to be printed
object
groupwiseMean object from which to extract the residuals

Value

  • mm returns an object of class groupwiseModel. The functions fitted.values, residuals, coefficients, and summary are useful for extracting various features of the value returned by mm

Details

mm is a sort of training function for lm, meant to provide a basis for discussing inference and introducing resampling in a simple, intuitive setting of groupwise means. lm provides a better, more general facility. When using lm to recreate the results of mm, include all the interaction terms, that is, use * instead of &. See the examples.

See Also

lm, do

Examples

Run this code
mm( wage ~ sex, data=CPS85 )
mm( wage ~ sex & married, data=CPS85 )
lm( wage ~ sex*married-1, data=CPS85)
do(5) * mm( wage ~ sex & married, data=resample(CPS85))
mod <- mm( width ~ domhand, data=KidsFeet)
summary(mod)
resid(mod)
fitted(mod)

Run the code above in your browser using DataLab