designmatrix: Initialize and Update Design Matrices

Description Usage Arguments Value Examples

View source: R/designmatrix.R

Description

Either 1) initialize a design matrix given a data frame and a list specifying the dependent variable and associated grouping variables, or 2) update a design matrix after modification of of the element summarizing the design matrix over all possible combinations of levels for the grouping variables.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
designmatrix(df = NULL, select = NULL, dm = NULL, digits = 2)

is.designmatrix(x)

## S3 method for class 'designmatrix'
print(x)

## S3 method for class 'designmatrix'
summary(x)

## S3 method for class 'designmatrix'
plot(
  x,
  intercept = T,
  exclude_effects = NULL,
  error_bars = F,
  average = T,
  ...
)

## S3 method for class 'designmatrix'
subset(x, summary = T)

subset(x, update = F) <- value

Arguments

df

A data frame with the observations for the dependent variable and associated grouping variables.

select

A list with...

  1. The column name for the dependent variable.

  2. The set of column names for the grouping variables.

If only the column name for the dependent variable is provided, the function assumes all remaining columns are the set of grouping variables.

dm

An object of class designmatrix. If provided, the function will update the object based on the specifications of the summary_matrix element.

digits

The number of digits to round to when computing the group means.

Value

An object of class designmatrix. The print method displays the combination of levels and associated rows of the design matrix. The summary method displays the combination of levels and their associated descriptive statistics (mean, standard deviation, standard error of the mean, and sample size). The method subset can be used to access the summary matrix (or the full design matrix if summary is TRUE), or to replace elements of the summary matrix.

The plot method generates a simple plot of the group means (filled circles). If elements of the design matrix are non-zero, the method fits a simple linear model to the data using the specified design matrix and shows the resulting estimates for the group means (empty circles). If the option intercept is set to TRUE (the default), the method assumes the intercept term is defined in the user-submitted design matrix. The option error_bars, if TRUE, adds approximate 95 equal to +/- 2 standard errors relative to the observed means. The option exclude_effects takes a string character with the column names for the design matrix. The method then displays what the estimated means would be were these columns excluded from from the design matrix (empty blue circles). Additional plotting options for plot, excluding xlab, ylab, xaxt, pch, and bty, can be supplied.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Example with R data set 'PlantGrowth'
dm = designmatrix( PlantGrowth, list( 'weight', 'group' ) )
# Summarize group means
summary( dm )

# Specify design matrix
# Main effect of treatment 1
subset( dm )[1:2,2] = c(-1,1)
# Main effect of treatment 2
subset( dm )[c(1,3),3] = c(-1,1)

# Update summaries and full design matrix
dm = designmatrix( dm )

# Example of methods
print( dm )
plot( dm, intercept = T, error_bars = T, exclude_effects = c( 'X2', 'X3' ) )

# Example analysis
dtba = getdata( dm )
lmf = lm( DV ~ -1 + ., data = dtba )

rettopnivek/designmatrix documentation built on Jan. 13, 2020, 7:09 p.m.