The proc_glm function performs a general linear model analysis for one or more models. Unlike proc_reg, the proc_glm function accepts categorical predictors through the class parameter, and produces Type I, Type II, and Type III sums of squares. The model(s) are passed on the model parameter, and the input dataset is passed on the data parameter. The by parameter allows you to subset the data into groups and run the model on each group. The weight parameter lets you assign a weight to each observation. The output and options parameters provide additional customization of the results.

proc_glm(
  data,
  model,
  class = NULL,
  by = NULL,
  stats = NULL,
  output = NULL,
  weight = NULL,
  lsmeans = NULL,
  contrast = NULL,
  estimate = NULL,
  random = NULL,
  options = NULL,
  titles = NULL,
  where = NULL
)

Arguments

data

The input data frame for which to perform the analysis. This parameter is required.

model

A model for the analysis. The model can be specified using either R syntax (y ~ a + b + a:b) or SAS syntax ("y = a b a*b"). To pass multiple models, use a list (R syntax) or a vector of strings (SAS syntax). By default, models are named "MODEL1", "MODEL2", etc.

class

An optional vector of variable names to treat as categorical (factor) predictors. These variables will be converted to factors prior to fitting the model. Pass quoted, or unquoted using the v function.

by

An optional by group. If specified, the input data will be subset on the by variable(s) prior to performing the analysis.

stats

Optional statistics keywords. Valid values are "ss1", "ss2", "ss3", "solution", "clparm", "p", "est", and "clb". The "solution" keyword adds a parameter estimates table to the interactive report ("est" is an accepted alias). The "clparm" keyword adds confidence limits for the estimates, using the alpha value from the options parameter ("clb" is an accepted alias). The "p" keyword adds predicted values and residuals to the interactive report.

output

Whether or not to return datasets from the function. Valid values are "out", "none", and "report", plus the data shaping keywords "long", "stacked", and "wide". Default is "out".

weight

The name of a variable to use as a weight for each observation.

lsmeans

The name of one or more class variables for which to compute least-squares means. Each requested effect produces a least-squares means table on the interactive report. The effect(s) must also appear on the class parameter.

contrast

A named list of contrast specifications. Each element name is the contrast label, and each value is itself a named list mapping a model effect to a vector of coefficients over that effect's levels, in level order. For example, contrast = list("F vs M" = list(Sex = c(1, -1))) mirrors the SAS statement contrast 'F vs M' Sex 1 -1. Each contrast produces an F-test row on the interactive report.

estimate

A named list of estimate specifications, using the same structure as the contrast parameter. Each estimate produces a row on the interactive report with the estimate, standard error, t value, p value, and confidence limits.

random

The name of one or more class variables to treat as random effects. Produces a table of Type III expected mean squares on the interactive report. The effect(s) must also appear on the class parameter.

options

A vector of optional keywords. Valid values are "alpha =", "noprint", "ss1", "ss2", "ss3", and "outstat". The "outstat" option requests an output dataset of the model sums of squares. This is the default output dataset, so the option does not normally need to be passed.

titles

A vector of one or more titles to use for the report output.

where

An expression to filter the rows before statistics are calculated. Use the expression function.

Value

Normally the requested statistics are shown interactively in the viewer, and output results are returned as a data frame. If "report" datasets are requested they are returned as a list.

Details

The proc_glm function is a general-purpose linear modeling function built on top of the GLM function from the sasLM package. It produces a dataset output by default, and, when working in RStudio, also produces an interactive report. Statistical output is designed to match SAS.

See also