glm_bw {psfmi}R Documentation

Function for backward selection of Linear and Logistic regression models.

Description

glm_bw Backward selection of Linear and Logistic regression models in single dataset using as selection method the likelihood-ratio test.

Usage

glm_bw(
  data,
  formula = NULL,
  Outcome = NULL,
  predictors = NULL,
  p.crit = 1,
  cat.predictors = NULL,
  spline.predictors = NULL,
  int.predictors = NULL,
  keep.predictors = NULL,
  nknots = NULL,
  model_type = "binomial"
)

Arguments

data

A data frame.

formula

A formula object to specify the model as normally used by glm. See under "Details" and "Examples" how these can be specified.

Outcome

Character vector containing the name of the outcome variable.

predictors

Character vector with the names of the predictor variables. At least one predictor variable has to be defined. Give predictors unique names and do not use predictor name combinations with numbers as, age2, gnder10, etc.

p.crit

A numerical scalar. P-value selection criterium. A value of 1 provides the pooled model without selection.

cat.predictors

A single string or a vector of strings to define the categorical variables. Default is NULL categorical predictors.

spline.predictors

A single string or a vector of strings to define the (restricted cubic) spline variables. Default is NULL spline predictors. See details.

int.predictors

A single string or a vector of strings with the names of the variables that form an interaction pair, separated by a “:” symbol.

keep.predictors

A single string or a vector of strings including the variables that are forced in the model during predictor selection. All type of variables are allowed.

nknots

A numerical vector that defines the number of knots for each spline predictor separately.

model_type

A character vector. If "binomial" a logistic regression model is used (default) and for "linear" a linear regression model is used.

Details

A typical formula object has the form Outcome ~ terms. Categorical variables has to be defined as Outcome ~ factor(variable), restricted cubic spline variables as Outcome ~ rcs(variable, 3). Interaction terms can be defined as Outcome ~ variable1*variable2 or Outcome ~ variable1 + variable2 + variable1:variable2. All variables in the terms part have to be separated by a "+".

Value

An object of class smods (single models) from which the following objects can be extracted: original dataset as data, model at each selection step RR_model, final selected model as RR_model_final, p-values at final step multiparm_final, and at each step as multiparm, formula object at final step as formula_final, and at each step as formula_step and for start model as formula_initial, predictors included at each selection step as predictors_in, predictors excluded at each step as predictors_out, and Outcome, p.crit, call, model_type, predictors_final for names of predictors in final selection step and predictors_initial for names of predictors in start model and keep.predictors for variables that are forced in the model during selection.

Author(s)

Martijn Heymans, 2021

References

http://missingdatasolutions.rbind.io/

See Also

psfmi_perform

Examples


data1 <- subset(psfmi::lbpmilr, Impnr==1) # extract first imputed dataset
res_single <- glm_bw(data=data1, p.crit = 0.05, formula=Chronic ~
       Tampascale + Smoking + factor(Satisfaction), model_type="binomial")
         
res_single$RR_model_final

res_single <- glm_bw(data=data1, p.crit = 0.05, formula=Pain ~
         Tampascale  + Smoking + factor(Satisfaction), model_type="linear")
         
res_single$RR_model_final


[Package psfmi version 1.4.0 Index]