我是靠谱客的博主 默默草莓,最近开发中收集的这篇文章主要介绍R notes (2) : predict.lm functionReferencePredict method for Linear Model FitsUsageArgumentsDetailsExample 1Example 2Example 3,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

R notes : predict.lm function

  • Reference
  • Predict method for Linear Model Fits
  • Usage
  • Arguments
  • Details
  • Example 1
    • data
    • Codes
  • Example 2
  • Example 3

Reference

https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/predict.lm

Predict method for Linear Model Fits

Predicted values based on linear model object.

Usage

# S3 method for lm
predict(object, newdata, se.fit = FALSE, scale = NULL, df = Inf,
        interval = c("none", "confidence", "prediction"),
        level = 0.95, type = c("response", "terms"),
        terms = NULL, na.action = na.pass,
        pred.var = res.var/weights, weights = 1,)

Arguments

Arguments Instrument
object Object of class inheriting from “lm”
newdata An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used.
se.fit A switch indicating if standard errors are required.
scale Scale parameter for std.err. calculation.
df Degrees of freedom for scale.
interval Type of interval calculation. Can be abbreviated.
level Tolerance/confidence level.
type Type of prediction (response or model term). Can be abbreviated.
terms If type = “terms”, which terms (default is all terms), a character vector.
na.action function determining what should be done with missing values in newdata. The default is to predict NA.
pred.var the variance(s) for future observations to be assumed for prediction intervals. See ‘Details’.
weights variance weights for prediction. This can be a numeric vector or a one-sided model formula. In the latter case, it is interpreted as an expression evaluated in newdata.

Details

predict.lm produces predicted values, obtained by evaluating the regression function in the frame newdata (which defaults to model.frame(object)). If the logical se.fit is TRUE, standard errors of the predictions are calculated. If the numeric argument scale is set (with optional df), it is used as the residual standard deviation in the computation of the standard errors, otherwise this is extracted from the model fit. Setting intervals specifies computation of confidence or prediction (tolerance) intervals at the specified level, sometimes referred to as narrow vs. wide intervals.

If the fit is rank-deficient, some of the columns of the design matrix will have been dropped. Prediction from such a fit only makes sense if newdata is contained in the same subspace as the original data. That cannot be checked accurately, so a warning is issued.

If newdata is omitted the predictions are based on the data used for the fit. In that case how cases with missing values in the original fit are handled is determined by the na.action argument of that fit. If na.action = na.omit omitted cases will not appear in the predictions, whereas if na.action = na.exclude they will appear (in predictions, standard errors or interval limits), with value NA. See also napredict.

The prediction intervals are for a single observation at each case in newdata (or by default, the data used for the fit) with error variance(s) pred.var. This can be a multiple of res.var, the estimated value of σ2: the default is to assume that future observations have the same error variance as those used for fitting. If weights is supplied, the inverse of this is used as a scale factor. For a weighted fit, if the prediction is for the original data frame, weights defaults to the weights used for the model fit, with a warning since it might not be the intended result. If the fit was weighted and newdata is given, the default is to assume constant prediction variance, with a warning.

Example 1

data

在这里插入图片描述
在这里插入图片描述

Codes

> xy = read.table(file = 'C:/Users/DELL/Desktop/Data Mining/Lecture/sp2001A/data01A.dat', header = T)
> xy
      x1    x2    x3    x4    x5     y
1   1.29  0.40 -0.02  0.23  0.37  1.12
2  -0.54 -1.43  0.74 -0.27  0.45 -0.95
3   0.50 -0.85 -0.02 -0.39  1.55 -

最后

以上就是默默草莓为你收集整理的R notes (2) : predict.lm functionReferencePredict method for Linear Model FitsUsageArgumentsDetailsExample 1Example 2Example 3的全部内容,希望文章能够帮你解决R notes (2) : predict.lm functionReferencePredict method for Linear Model FitsUsageArgumentsDetailsExample 1Example 2Example 3所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(32)

评论列表共有 0 条评论

立即
投稿
返回
顶部