Lecture


R content

Linear models

  • lm(Y ~ x + x1 + x2, data = data), with three independent predictors
  • lm(Y ~ x*x1, data = data), with an interaction effect
  • lm(Y ~ x + x1 + x:x1, data = data), with an interaction effect, written more verbosely
  • lm(Y ~ ., data = data), to include all other columns as predictors

Logistic regression

  • glm(Y ~ x + x1 + x2, data = data, family = 'binomial'), with three independent predictors
  • glm(Y ~ ., data = data, family = 'binomial'), to include all other columns as predictors
  • Code to extract relevant information for plotting:


model <- glm(Y ~ ., data = data, family = 'binomial')

plot.data <- tibble(x = model$linear.predictors,
                    y = model$fitted.values,
                    response = data$Y)