add_probs.lm: Response Level Probabilities for Linear Models

Description Usage Arguments Value See Also Examples

View source: R/add_probs_lm.R

Description

This is the method add_probs uses if the model is of class lm. Probabilities are calculated parametrically, using a pivotal quantity.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## S3 method for class 'lm'
add_probs(
  df,
  fit,
  q,
  name = NULL,
  yhatName = "pred",
  comparison = "<",
  log_response = FALSE,
  ...
)

Arguments

df

A data frame of new data.

fit

An object of class lm. Predictions are made with this object.

q

A real number. A quantile of the response distribution.

name

NULL or a string. If NULL, probabilities automatically will be named by add_probs, otherwise, the probabilities will be named name in the returned data frame.

yhatName

A character vector of length one. Names of the

comparison

"<", or ">". If comparison = "<", then Pr(Y|x < q) is calculated for each observation in df. Otherwise, Pr(Y|x > q) is calculated.

log_response

A logical. Default is FALSE. Set to TRUE if the model is log-linear: \log(Y) = X β + ε.

...

Additional arguments.

Value

A dataframe, df, with predicted values and probabilities attached.

See Also

add_ci.lm for confidence intervals for lm objects, add_pi.lm for prediction intervals of lm objects, and add_quantile.lm for response quantiles of lm objects.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Fit a linear model
fit <- lm(dist ~ speed, data = cars)

# Calculate the probability that a new dist will be less than 20,
# given the model.
add_probs(cars, fit, q = 20)

# Calculate the probability that a new dist will be greater than
# 30, given the model.
add_probs(cars, fit, q = 30, comparison = ">")

ciTools documentation built on Jan. 13, 2021, 7 a.m.