Package 'linearModel'

Title: Linear Model Functions
Description: Functions to access and test results from a linear model.
Authors: Jared Studyvin [aut, cre]
Maintainer: Jared Studyvin <[email protected]>
License: MIT + file LICENSE
Version: 1.0.2
Built: 2024-10-31 21:15:41 UTC
Source: CRAN

Help Index


ANOVA Table

Description

Produces the overall ANOVA table where the model sum of squares are not partioned into their parts.

Usage

anovaTable(object, ...)

Arguments

object

lm or aov model object

...

currently ignored

Value

Object of class anova and data.frame

Examples

data(depression)

## MLR model
modMLR <- lm(depress~trauma+control,data=depression)
anovaTable(modMLR)

## ANOVA model
depression$gender <- factor(depression$gender)
depression$history <- factor(depression$history)
modAOV  <- lm(depress~-1+gender+history+gender:history,data=depression)
anovaTable(modAOV)

Test Contrasts

Description

Contrast testing function. Designed to test contrasts of parameter estimates from a linear model.

Usage

contrastTest(
  estVec,
  n,
  dfModel,
  dfError,
  mse,
  C = NULL,
  test = c("scheffe", "bonferroni", "hsd", "lsd"),
  ...
)

Arguments

estVec

numeric vector of parameter estimates for comparison

n

numeric vector indicating the sample size for the parameter estimates, if a single value is given it is assumed to apply to all estiamtes

dfModel

numeric value for the model degrees of freedom

dfError

numeric value for the error or residual degrees of freedom

mse

numeric value for the mean squared error from the model

C

numeric matrix, each row is a contrast that should sum to zero, see details

test

character, indicating which testing method should be used, see details

...

currently ignored

Details

The test argument can be one of the following: 'scheffe','bonferroni','hsd', or 'lsd'. 'hsd' is the Tukey HSD test. 'lsd' is th Fisher LSD test. The other two are the Scheffe test and Bonferroni adjustment.

The matrix C is the contrast matrix. Each row is a separate contrast. The number of columns of C must be equal to the length(estVec). Row names for C are retained in the output, but they are not required.

Value

Object of class anova and data.frame

Examples

data(genericData)

mod <- lm(Y~A,data=genericData)
dfModel <- anovaTable(mod)['Model','df']
dfError <- anovaTable(mod)['Residual','df']
mse <- anovaTable(mod)['Residual','MS']
meanVec <- aggregate(Y~A,FUN=mean,data=genericData)$Y
n <- aggregate(Y~A,FUN=length,data=genericData)$Y

## can add names for ease of interpretation with the output
names(meanVec) <- c('group 1','group 2','group 3')
contrastTest(estVec=meanVec,n=n,dfModel=dfModel,dfError=dfError,mse=mse,test='hsd')

## each group vs the mean of the other two
C <- rbind(c(1,-0.5,-0.5),c(-0.5,1,-0.5),c(-0.5,-0.5,1))
## row names are not required but are helpful
row.names(C) <- c('1 vs 2+3','2 vs 1+3','3 vs 1+2')
contrastTest(estVec=meanVec,n=n,dfModel=dfModel,dfError=dfError,mse=mse,C=C,test='scheffe')

Self Reported Depression

Description

Self reported level of depression and other associated metrics.

Usage

data(depression)

Format

An object of class data.frame with 50 rows and 13 columns.

Details

This is a fictious dataset useful for teaching how to use and interpret linear statistical models. The variables are:

educate

Level of Education: (1) professional degree (non-college), (2) 2 years of college, (3) 2+ years of college, but not a BS degree, (4) BS degree, (5) MS degree

income

Annual Income: 1 = $10,0001 to $19,999; 2 = $20,000 to $29,999; ... 9 = $90,000 to $99,999; 10 = $100,000 or more

trauma

Experience of Trauma; Percent of Life Events Viewed as Traumatic: 0 = 0%, 1 = 10%, 2= 20%, ..., 9 = 90%, 10 = 100%

satisfac

Satisfied with your Life: 0 = No, 1 = Yes

control

Feeling of Control; How much do you feel in control: 0 = Not at all, 1 = A Little, 2 = Some, 3 = A Lot, 4 = Completely

history

Family History of Depression: 0 = No, 1 = Yes

exercise

Weekly Amount of Exercise: 0 = None, 1 = 1 Hour, 2 = 2 Hours, 3 = 3 Hours, 4 = 4 Hours, 5 = 5 or more Hours

mhpg

3-methoxy-4-hydroxyphenylethyleneglycol, Depression Related Chemical Secreted in Urine; milligrams secreted per 24 hour period, labeled as mg/24h: 0 = 0 mg/24h, 1 = 100 mg/24h,..., 9 = 900 mg/24h, 10 = 1000+ mg/24h

sleep

Amount of Sleep Problems: 0 = None, 1 = 10% of the time, ... , 9 = 90% of the time, 10 = 100% of the time

depress

Perceived Level of Depression: 0 = None, 1 = 10% of the time, ... , 9 = 90% of the time, 10 = 100% of the time

depressYes

Do I consider myself depressed: 0 = No, 1 = Yes

welbeing

Feeling of Well Being; how often do you feel good about yourself: 0 = None, 1 = 10% of the time, ... , 9 = 90% of the time, 10 = 100% of the time

gender

Your Sex: 0 = Male, 1 = Female


Generic Data Set

Description

Generic data set with four ratio predictors (X1,X2,X3,X4), two categorical predictors (A,B) and one ratio response variable (Y).

Usage

data(depression)

Format

An object of class data.frame with 60 rows and 7 columns.

Details

This is a fictious dataset useful for teaching how to use and interpret linear statistical models.