predict20x: Deprecated Teaching Predictions for a Linear Model

View source: R/predict20x.R

predict20xR Documentation

Deprecated Teaching Predictions for a Linear Model

Description

Teaching helper for linear-model predictions. It wraps predict.lm and prints a compact table containing fitted values, confidence intervals for the mean response, and prediction intervals for new observations.

Usage

predict20x(object, newdata, cilevel = 0.95, digit = 3, print.out = TRUE, ...)

Arguments

object

an lm object, i.e. the output from lm.

newdata

prediction data frame.

cilevel

confidence level for the intervals.

digit

number of decimal places to print.

print.out

if TRUE, print the prediction table.

...

optional arguments that are passed to predict.lm.

Details

This is not an S3 predict() method and is not intended to be a drop-in replacement for base R prediction methods. It is a compatibility helper for older teaching material that expects confidence and prediction intervals to be printed together. The standard predict interface is preferred for new work.

Note: newdata must be a data frame with the same column order and data types as those used in fitting the model. This is stricter than the usual predict.lm() interface and is kept for compatibility with the original teaching wrapper.

Value

Invisibly returns a list with components

frame

printed data frame containing predictions, confidence intervals, and prediction intervals.

fit

prediction values.

se.fit

standard errors of predictions.

residual.scale

residual standard deviation.

df

residual degrees of freedom.

cilevel

confidence level of the interval.

Note

This function is deprecated because it is no longer used in class. Prefer the standard predict method for new work.

See Also

predict, predict.lm, as.data.frame.

Examples


# Zoo data
data(zoo.df)
zoo.df = within(zoo.df, {day.type = factor(day.type)})
zoo.fit = lm(log(attendance) ~ time + sun.yesterday + nice.day + day.type + tv.ads,
             data = zoo.df)
pred.zoo = data.frame(time = 8, sun.yesterday = 10.8, nice.day = 0,
                      day.type = factor(3), tv.ads = 1.181)
predict20x(zoo.fit, pred.zoo)

# Peruvian Indians data
data(peru.df)
peru.fit = lm(BP ~ age + years + I(years^2) + weight + height, data = peru.df)
pred.peru = data.frame(age = 21, years = 2, `I(years^2)` = 2, weight = 71, height = 1629)
predict20x(peru.fit, pred.peru)


s20x documentation built on July 1, 2026, 9:06 a.m.