Learn R Programming

psycho (version 0.4.91)

get_predicted.lm: Compute predicted values of lm models.

Description

Compute predicted from a lm model.

Usage

# S3 method for lm
get_predicted(fit, newdata = "model", prob = 0.95, ...)

Arguments

fit

An lm model.

newdata

A data frame in which to look for variables with which to predict. If omitted, the model matrix is used. If "model", the model's data is used.

prob

Probability of confidence intervals (0.95 (default) will compute 2.5-97.5% CI). Can also be a list of probs (e.g., c(0.90, 0.95)).

...

Arguments passed to or from other methods.

Value

dataframe with predicted values.

Examples

Run this code
# NOT RUN {
library(psycho)
library(ggplot2)

fit <- lm(Tolerating ~ Adjusting, data = affective)

refgrid <- psycho::refdata(affective, "Adjusting")
predicted <- get_predicted(fit, newdata = refgrid)

ggplot(predicted, aes(x = Adjusting, y = Tolerating_Predicted)) +
  geom_line() +
  geom_ribbon(aes(
    ymin = Tolerating_CI_2.5,
    ymax = Tolerating_CI_97.5
  ),
  alpha = 0.1
  )
# }

Run the code above in your browser using DataLab