Learn R Programming

ciTools (version 0.6.1)

add_probs.lm: Response Level Probabilities for Linear Models

Description

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

Usage

# S3 method for lm
add_probs(
  df,
  fit,
  q,
  name = NULL,
  yhatName = "pred",
  comparison = "

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 \beta + \epsilon\).

...

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

Run this code
# NOT RUN {
# 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 = ">")

# }

Run the code above in your browser using DataLab