r語言predict函數_R語言:predict.lm()函數中文幫助文檔(中英文對照)

在predict函數中,

predict (object, …)result1<-predict(result,newdata,interval=」confidence」)這裡面的newdata有什麼要求呢,必須是解釋變數裡面的值嗎,隨便帶入值不可以預測嗎?

解答:

可以。但newdata似乎要求是數據框,並且數據框里每個變數的名字要與原先模型里的一致。

要和原始數據一樣的數據類型,以data.frame()的形式帶入predict()

如果你的模型是y~x,(x是自變數),首先估計模型

Model=lm(y~x,data=…)估計出來後,進行預測,例如預測x=2時候的y值,則應當輸入命令predict(Model,newdata=data.frame(x=2),interval=」confidence」)R語言:predict.lm()函數中文幫助文檔(中英文對照)

predict.lm(stats)

predict.lm()所屬R語言包:stats

Predict method for Linear Model Fits

對於線性模型擬合預測方法

譯者:生物統計家園網 機器人LoveR

描述———-Description———-

Predicted values based on linear model object.

預測值基於線性模型對象。

用法———-Usage———-

## S3 method for class 『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———-

參數:object

Object of class inheriting from 「lm」 繼承類的對象從」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

尺度參數std.err。計算

參數:df

Degrees of freedom for scale 度規模的自由

參數:interval

Type of interval calculation. 區間計算的類型。

參數:level

Tolerance/confidence level

寬容/置信水平

參數:type

Type of prediction (response or model term). 預測型(反應或模型長期)。

參數:terms

If type=」terms」, which terms (default is all terms) 如果type=」terms」,哪些條款(默認是所有條款)

參數:na.action

function determining what should be done with missing values in newdata. The default is to predict NA. 功能確定應做與newdata缺失值。默認預測NA。

參數:pred.var

the variance(s) for future observations to be assumed for prediction intervals. See 「Details」. 要承擔未來的觀測方差(S)的預測區間。見「詳細資料」。

參數: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 預測方差權。這可以是一個數值向量或片面的模型公式。在後一種情況下,它被解釋為表達newdata評價

參數:…

further arguments passed to or from other methods. 通過進一步的論據或其他方法。

Details

詳情———-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.

predict.lm生產預測值,取得通過評估的回歸函數框架newdata(默認為model.frame(object)。如果邏輯se.fit是TRUE,標準誤差預測計算,如果數字參數scale設置(可選df),它被用於殘留在計算標準誤差的標準偏差,否則這是從模型中提取適合設置intervals指定的信心,或在指定level,有時簡稱為窄與寬間隔的預測(耐)間隔的計算。

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.

如果缺乏合適的是排名,一些設計矩陣的列將被丟棄。從這樣一個合適的預測才有意義newdata如果包含在原始數據相同的子空間。不能準確地檢查,所以會發出一個警告。

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 is determined by the na.action argument of that fit. If na.action = na.omit omitted cases will not appear in the residuals, whereas if na.action = na.exclude they will appear (in predictions, standard errors or interval limits), with residual value NA. See also napredict.

newdata如果省略的預測是基於適合使用的數據。在這種情況下,如何在原來的擬合遺漏值的情況下確定na.action合身的說法。如果na.action = na.omit省略的情況下將不會出現在殘差,而剩餘價值na.action = na.exclude如果NA「他們會出現預測,標準錯誤或間隔限制,。還可以看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 &sigma;^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.

預測區間在每一種情況下的單一觀察newdata(或默認情況下,使用的數據為合適)與誤差方差()pred.var的。這可以是1res.var,估計價值&sigma;^2多:默認是假設未來的觀測裝修使用的相同的誤差方差。如果weights提供,這反被用來作為一個尺度因子。加權擬合,如果預測是原始的數據框,weights默認用於模型擬合的權重警告,因為它可能無法預期的結果。如果合適的加權和newdata,默認是假設恆定的預測方差,一個警告。

值———-Value———-

predict.lm produces a vector of predictions or a matrix of predictions and bounds with column names fit, lwr, and upr if interval is set. If se.fit is TRUE, a list with the following components is returned:

predict.lm生產fit,lwr,upr如果interval設置的預測向量或矩陣的列名的預測與邊界。如果se.fitTRUE,以下組件的列表,則返回:

參數:fit

vector or matrix as above 上述的向量或矩陣

參數:se.fit

standard error of predicted means 預測方法的標準誤差

參數:residual.scale

residual standard deviations

剩餘標準偏差

參數:df

degrees of freedom for residual 剩餘的自由度

注意———-Note———-

Variables are first looked for in newdata and then searched for in the usual way (which will include the environment of the formula used in the fit). A warning will be given if the variables found are not of the same length as those in newdata if it was supplied.變數在newdata先看著,然後在通常的方法(其中包括環境適合使用的公式)搜查。一個將給予警告,如果發現的變數是相同長度不為那些在newdata如果它提供的。

Notice that prediction variances and prediction intervals always refer to future observations, possibly corresponding to the same predictors as used for the fit. The variance of the residuals will be smaller.

請注意,預測方差和預測區間總是指未來的觀測,可能適合使用相同的預測相應。殘差的方差較小。

Strictly speaking, the formula used for prediction limits assumes that the degrees of freedom for the fit are the same as those for the residual variance. This may not be the case if res.var is not obtained from the fit.

嚴格地說,用於預測限制的公式假設,自由的契合度是相同的殘差。這可能不是res.var如果不適合獲得的情況下。數據分析培訓

參見———-See Also———-

The model fitting function lm, predict.該模型的擬合函數lm,predict。

SafePrediction for prediction from polynomial and spline fits.

SafePrediction多項式樣條擬合預測。

舉例———-Examples———-

require(graphics)

## Predictions[#預測]

x <- rnorm(15)y <- x + rnorm(15)predict(lm(y ~ x))new <- data.frame(x = seq(-3, 3, 0.5))predict(lm(y ~ x), new, se.fit = TRUE)pred.w.plim <- predict(lm(y ~ x), new, interval=」prediction」)pred.w.clim <- predict(lm(y ~ x), new, interval=」confidence」)matplot(new$x,cbind(pred.w.clim, pred.w.plim[,-1]), lty=c(1,2,2,3,3), type=」l」, ylab=」predicted y」)

## Prediction intervals, special cases[預測區間,特殊情況下]

## The first three of these throw warnings[#這些罰球警告前三]w <- 1 + x^2fit <- lm(y ~ x)wfit <- lm(y ~ x, weights = w)predict(fit, interval = 「prediction」)predict(wfit, interval = 「prediction」)predict(wfit, new, interval = 「prediction」)predict(wfit, new, interval = 「prediction」, weights = (new$x)^2)predict(wfit, new, interval = 「prediction」, weights = ~x^2)
推薦閱讀:
相关文章