Model Predictions for Multivariate Linear Models
predict.manylm.Rd
predict.manylm
is a function for predictions from the
result of the model fitting function manylm
.
Usage
<!-- % predict.manylm -->
# S3 method for manylm
predict(object, newdata=NULL, se.fit = FALSE,
type = c("response", "terms"), terms = NULL, na.action = na.pass, ...)
Arguments
- object
object of class inheriting from
manylm
.- 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.
- type
type of prediction (response or model term), Possible values: "response", "terms".
- terms
if type="terms", which terms (default is all terms).
- na.action
function determining what should be done with missing values in newdata. The default is to predict
NA
.- ...
further arguments passed to or from other methods.
Details
predict.manylm
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 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
.
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.
Value
predict.manylm
produces a matrix of predictions or if interval
is set an array of predictions and bounds, where the first dimension has the names:
fit
, lwr
, and upr
.
If se.fit
is TRUE
, a list with the following components is returned:
- fit
vector or matrix as above
- se.fit
a matrix with the standard errors of the predicted means
- residual.scale
vector or matrix as a vector of residual standard deviations
- df
numeric, the 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.
Offsets specified by offset
in the fit by lm
will not be included in predictions, whereas those specified by an
offset term in the formula will be.
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.
Examples
data(spider)
spiddat <- mvabund(spider$abund[1:20, ])
dat = spider$x[1:20,]
manylm.fit <- manylm(spiddat~soil.dry+bare.sand, data=dat)
predict(manylm.fit)
#> Alopacce Alopcune Alopfabr Arctlute Arctperi Auloalbi Pardlugu
#> 1 10.73802292 4.445159 0.557050063 -0.1561324 0 3.967983 6.7573172
#> 2 2.45155179 7.630415 0.133819671 1.5799018 0 7.317694 6.0322943
#> 3 8.13723562 5.444881 0.424215204 0.3887383 0 5.019322 6.5297619
#> 4 6.78658242 5.964062 0.355230774 0.6717032 0 5.565308 6.4115868
#> 5 2.84207427 7.480301 0.153765554 1.4980865 0 7.159829 6.0664629
#> 6 -3.59675539 12.745220 0.293956334 3.2953890 0 8.397899 0.8918346
#> 7 0.96340695 8.202447 0.057812875 1.8916715 0 7.919259 5.9020894
#> 8 7.35734605 5.744665 0.384382449 0.5521270 0 5.334583 6.4615256
#> 9 8.97258400 5.123780 0.466880509 0.2137310 0 4.681642 6.6028505
#> 10 8.66331511 9.817187 1.220183900 1.0136815 0 2.568895 -0.9852286
#> 11 12.04246044 3.943743 0.623674033 -0.4294150 0 3.440680 6.8714486
#> 12 11.19555813 4.269285 0.580418612 -0.2519871 0 3.783030 6.7973491
#> 13 -4.61377531 12.430976 0.123452979 3.3951299 0 9.153976 1.9684070
#> 14 2.02174598 7.795629 0.111867398 1.6699471 0 7.491438 5.9946885
#> 15 -0.09377669 8.608820 0.003817363 2.1131538 0 8.346613 5.8095913
#> 16 2.67338705 7.545143 0.145149877 1.5334268 0 7.228019 6.0517037
#> 17 -0.81705206 8.886842 -0.033123828 2.2646816 0 8.638989 5.7463085
#> 18 1.60696027 7.955070 0.090682274 1.7568456 0 7.659110 5.9583969
#> 19 3.90850105 7.070375 0.208233158 1.2746677 0 6.728739 6.1597697
#> 20 1.76062740 7.896001 0.098530801 1.7246520 0 7.596992 5.9718420
#> Pardmont Pardnigr Pardpull Trocterr Zoraspin
#> 1 46.6067705 6.260688 19.707832 26.28410 0.61767677
#> 2 13.0619409 24.487334 33.308592 54.39475 10.25044629
#> 3 36.0784086 11.981293 23.976559 35.10689 3.64101255
#> 4 30.6107698 14.952145 26.193415 39.68879 5.21110563
#> 5 14.6428322 23.628353 32.667619 53.06996 9.79647584
#> 6 -5.4436224 33.353427 34.550084 62.90769 20.67061905
#> 7 7.0377160 27.760607 35.751116 59.44307 11.98036921
#> 8 32.9213032 13.696712 25.256608 37.75256 4.54761035
#> 9 39.4600193 10.143889 22.605484 32.27310 2.66994557
#> 10 48.0114933 3.547945 8.871248 13.63772 8.58668141
#> 11 51.8873217 3.391491 17.566831 21.85899 -0.89869199
#> 12 48.4589391 5.254309 18.956870 24.73198 0.08580606
#> 13 -11.0718983 36.712081 38.414768 69.39221 20.99620973
#> 14 11.3220250 25.432720 34.014041 55.85280 10.75008241
#> 15 2.7580842 30.085953 37.486293 63.02941 13.20931289
#> 16 13.9599620 23.999392 32.944489 53.64221 9.99256959
#> 17 -0.1698387 31.676846 38.673421 65.48301 14.05009841
#> 18 9.6429126 26.345069 34.694838 57.25990 11.23225813
#> 19 18.9598815 21.282677 30.917270 49.45226 8.55678729
#> 20 10.2649793 26.007068 34.442621 56.73861 11.05362479
predict(manylm.fit, se.fit = TRUE)
#> $fit
#> Alopacce Alopcune Alopfabr Arctlute Arctperi Auloalbi Pardlugu
#> 1 10.73802292 4.445159 0.557050063 -0.1561324 0 3.967983 6.7573172
#> 2 2.45155179 7.630415 0.133819671 1.5799018 0 7.317694 6.0322943
#> 3 8.13723562 5.444881 0.424215204 0.3887383 0 5.019322 6.5297619
#> 4 6.78658242 5.964062 0.355230774 0.6717032 0 5.565308 6.4115868
#> 5 2.84207427 7.480301 0.153765554 1.4980865 0 7.159829 6.0664629
#> 6 -3.59675539 12.745220 0.293956334 3.2953890 0 8.397899 0.8918346
#> 7 0.96340695 8.202447 0.057812875 1.8916715 0 7.919259 5.9020894
#> 8 7.35734605 5.744665 0.384382449 0.5521270 0 5.334583 6.4615256
#> 9 8.97258400 5.123780 0.466880509 0.2137310 0 4.681642 6.6028505
#> 10 8.66331511 9.817187 1.220183900 1.0136815 0 2.568895 -0.9852286
#> 11 12.04246044 3.943743 0.623674033 -0.4294150 0 3.440680 6.8714486
#> 12 11.19555813 4.269285 0.580418612 -0.2519871 0 3.783030 6.7973491
#> 13 -4.61377531 12.430976 0.123452979 3.3951299 0 9.153976 1.9684070
#> 14 2.02174598 7.795629 0.111867398 1.6699471 0 7.491438 5.9946885
#> 15 -0.09377669 8.608820 0.003817363 2.1131538 0 8.346613 5.8095913
#> 16 2.67338705 7.545143 0.145149877 1.5334268 0 7.228019 6.0517037
#> 17 -0.81705206 8.886842 -0.033123828 2.2646816 0 8.638989 5.7463085
#> 18 1.60696027 7.955070 0.090682274 1.7568456 0 7.659110 5.9583969
#> 19 3.90850105 7.070375 0.208233158 1.2746677 0 6.728739 6.1597697
#> 20 1.76062740 7.896001 0.098530801 1.7246520 0 7.596992 5.9718420
#> Pardmont Pardnigr Pardpull Trocterr Zoraspin
#> 1 46.6067705 6.260688 19.707832 26.28410 0.61767677
#> 2 13.0619409 24.487334 33.308592 54.39475 10.25044629
#> 3 36.0784086 11.981293 23.976559 35.10689 3.64101255
#> 4 30.6107698 14.952145 26.193415 39.68879 5.21110563
#> 5 14.6428322 23.628353 32.667619 53.06996 9.79647584
#> 6 -5.4436224 33.353427 34.550084 62.90769 20.67061905
#> 7 7.0377160 27.760607 35.751116 59.44307 11.98036921
#> 8 32.9213032 13.696712 25.256608 37.75256 4.54761035
#> 9 39.4600193 10.143889 22.605484 32.27310 2.66994557
#> 10 48.0114933 3.547945 8.871248 13.63772 8.58668141
#> 11 51.8873217 3.391491 17.566831 21.85899 -0.89869199
#> 12 48.4589391 5.254309 18.956870 24.73198 0.08580606
#> 13 -11.0718983 36.712081 38.414768 69.39221 20.99620973
#> 14 11.3220250 25.432720 34.014041 55.85280 10.75008241
#> 15 2.7580842 30.085953 37.486293 63.02941 13.20931289
#> 16 13.9599620 23.999392 32.944489 53.64221 9.99256959
#> 17 -0.1698387 31.676846 38.673421 65.48301 14.05009841
#> 18 9.6429126 26.345069 34.694838 57.25990 11.23225813
#> 19 18.9598815 21.282677 30.917270 49.45226 8.55678729
#> 20 10.2649793 26.007068 34.442621 56.73861 11.05362479
#>
#> $se.fit
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 2.231756 4.147225 0.2395863 1.1013029 0 3.555452 4.935183 9.269407
#> [2,] 1.500202 2.787795 0.1610516 0.7403038 0 2.390000 3.317466 6.230963
#> [3,] 1.725850 3.207111 0.1852756 0.8516540 0 2.749484 3.816450 7.168171
#> [4,] 1.533669 2.849985 0.1646444 0.7568187 0 2.443317 3.391472 6.369965
#> [5,] 1.463026 2.718711 0.1570606 0.7219585 0 2.330774 3.235256 6.076555
#> [6,] 3.305977 6.143429 0.3549075 1.6313983 0 5.266814 7.310658 13.731096
#> [7,] 1.699096 3.157395 0.1824035 0.8384519 0 2.706862 3.757289 7.057052
#> [8,] 1.606978 2.986214 0.1725143 0.7929943 0 2.560107 3.553584 6.674446
#> [9,] 1.872810 3.480203 0.2010522 0.9241740 0 2.983608 4.141429 7.778555
#> [10,] 5.047673 9.379984 0.5418841 2.4908715 0 8.041542 11.162148 20.965079
#> [11,] 2.525764 4.693574 0.2711490 1.2463869 0 4.023841 5.585336 10.490545
#> [12,] 2.332667 4.334747 0.2504195 1.1510997 0 3.716216 5.158333 9.688535
#> [13,] 3.047262 5.662662 0.3271335 1.5037300 0 4.854649 6.738548 12.656542
#> [14,] 1.548922 2.878329 0.1662818 0.7643453 0 2.467616 3.425201 6.433314
#> [15,] 1.883451 3.499977 0.2021946 0.9294251 0 3.000561 4.164960 7.822752
#> [16,] 1.478219 2.746944 0.1586917 0.7294558 0 2.354979 3.268853 6.139658
#> [17,] 2.024594 3.762261 0.2173468 0.9990750 0 3.225418 4.477077 8.408979
#> [18,] 1.603013 2.978846 0.1720887 0.7910378 0 2.553790 3.544816 6.657979
#> [19,] 1.399985 2.601564 0.1502930 0.6908498 0 2.230343 3.095851 5.814721
#> [20,] 1.582207 2.940183 0.1698551 0.7807708 0 2.520644 3.498807 6.571564
#> [,9] [,10] [,11] [,12]
#> [1,] 13.671329 14.463382 13.142942 3.877386
#> [2,] 9.189967 9.722391 8.834781 2.606407
#> [3,] 10.572243 11.184749 10.163633 2.998441
#> [4,] 9.394979 9.939280 9.031869 2.664551
#> [5,] 8.962233 9.481462 8.615849 2.541818
#> [6,] 20.251816 21.425111 19.469097 5.743707
#> [7,] 10.408355 11.011366 10.006080 2.951960
#> [8,] 9.844055 10.414373 9.463589 2.791916
#> [9,] 11.472490 12.137153 11.029087 3.253764
#> [10,] 30.921125 32.712549 29.726045 8.769677
#> [11,] 15.472369 16.368766 14.874373 4.388187
#> [12,] 14.289496 15.117362 13.737217 4.052707
#> [13,] 18.666970 19.748447 17.945505 5.294222
#> [14,] 9.488412 10.038126 9.121692 2.691050
#> [15,] 11.537677 12.206115 11.091754 3.272251
#> [16,] 9.055302 9.579924 8.705321 2.568214
#> [17,] 12.402294 13.120825 11.922954 3.517469
#> [18,] 9.819767 10.388678 9.440240 2.785027
#> [19,] 8.576056 9.072913 8.244598 2.432293
#> [20,] 9.692315 10.253842 9.317713 2.748880
#>
new <- spider$x[21:28,]
predict(manylm.fit, new, se.fit = TRUE)
#> $fit
#> Alopacce Alopcune Alopfabr Arctlute Arctperi Auloalbi Pardlugu
#> 21 3.304231 7.302652 0.1773701 1.40126361 0 6.9730079 6.10689925
#> 22 20.197395 4.599745 1.6775031 -1.52870076 0 -1.7101903 1.31949705
#> 23 21.075306 4.013766 1.6805600 -1.75256350 0 -1.9435064 1.80707164
#> 24 15.623198 6.358031 1.4438766 -0.57039631 0 0.1388759 0.91927874
#> 25 13.291321 7.632980 1.3884277 -0.02102029 0 0.8963107 0.08949352
#> 26 22.037939 5.349847 2.0165687 -1.68005345 0 -3.1672339 -0.92865300
#> 27 24.427277 1.972995 1.7252800 -2.57570837 0 -2.9304924 3.34379098
#> 28 23.469828 3.546501 1.8790499 -2.18139347 0 -3.1331463 1.26755462
#> Pardmont Pardnigr Pardpull Trocterr Zoraspin
#> 21 16.51371 22.611809 31.9090716 51.5021594 9.2592327
#> 22 93.02333 -20.575281 -7.6195916 -22.1170967 -5.7735444
#> 23 96.04465 -22.111017 -8.2868195 -24.0258962 -7.0959923
#> 24 74.50632 -10.514031 -0.1118659 -6.5997988 -0.4561804
#> 25 65.87789 -5.987097 2.5368234 -0.3183557 2.7144775
#> 26 103.59781 -26.942116 -15.1784328 -34.6330076 -6.1424085
#> 27 108.00170 -28.287298 -11.4463511 -32.1597702 -11.9064619
#> 28 106.70919 -28.098737 -13.6278537 -34.0989925 -9.3290302
#>
#> $se.fit
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 1.428495 2.654543 0.1533536 0.7049186 0 2.275762 3.158896 5.933133
#> [2,] 6.360094 11.818829 0.6827768 3.1385109 0 10.132384 14.064364 26.416107
#> [3,] 6.375193 11.846888 0.6843978 3.1459622 0 10.156440 14.097755 26.478823
#> [4,] 5.396198 10.027641 0.5792994 2.6628580 0 8.596784 11.932857 22.412648
#> [5,] 5.306006 9.860039 0.5696170 2.6183508 0 8.453097 11.733411 22.038043
#> [6,] 7.929273 14.734801 0.8512333 3.9128526 0 12.632272 17.534361 32.933559
#> [7,] 6.700405 12.451222 0.7193103 3.3064439 0 10.674540 14.816909 27.829560
#> [8,] 7.255852 13.483398 0.7789394 3.5805402 0 11.559433 16.045195 30.136563
#> [,9] [,10] [,11] [,12]
#> [1,] 8.750702 9.257677 8.412494 2.481825
#> [2,] 38.960777 41.217981 37.454970 11.049838
#> [3,] 39.053275 41.315838 37.543893 11.076072
#> [4,] 33.056127 34.971243 31.778530 9.375194
#> [5,] 32.503625 34.386733 31.247383 9.218497
#> [6,] 48.573283 51.387390 46.695959 13.776083
#> [7,] 41.045460 43.423441 39.459081 11.641084
#> [8,] 44.448029 47.023139 42.730144 12.606102
#>