Predict Method for CLM fits
predict.RdObtains predictions from a cumulative link model.
Arguments
- object
a fitted object of class inheriting from
clm.- newdata
optionally, a data frame in which to look for variables with which to predict. Note that all predictor variables should be present having the same names as the variables used to fit the model. If the response variable is present in
newdatapredictions are obtained for the levels of the response as given bynewdata. If the response variable is omitted fromnewdatapredictions are obtained for all levels of the response variable for each of the rows ofnewdata.- se.fit
should standard errors of the predictions be provided? Not applicable and ignored when
type = "class".- interval
should confidence intervals for the predictions be provided? Not applicable and ignored when
type = "class".- level
the confidence level.
- type
the type of predictions.
"prob"gives probabilities,"class"gives predicted response class membership defined as highest probability prediction,"cum.prob"gives cumulative probabilities (see details) and"linear.predictor"gives predictions on the scale of the linear predictor including the boundary categories.- na.action
function determining what should be done with missing values in
newdata. The default is to predictNA.- ...
further arguments passed to or from other methods.
Details
If newdata is omitted and type = "prob" a vector of
fitted probabilities are returned identical to the result from
fitted.
If newdata is supplied and the response
variable is omitted, then predictions, standard errors and intervals
are matrices rather than vectors with the same number of rows as
newdata and with one column for each response class. If
type = "class" predictions are always a vector.
If newdata is omitted, the way 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
residuals, whereas if na.action = na.exclude
they will appear (in predictions, standard
errors or interval limits), with residual value NA. See also
napredict.
If type = "cum.prob" or type = "linear.predictor" there
will be two sets of predictions, standard errors and intervals; one
for j and one for j-1 (in the usual notation) where j = 1, ..., J index
the response classes.
If newdata is supplied and the response variable is omitted, then
predict.clm returns much the same thing as predict.polr
(matrices of predictions). Similarly, if type = "class".
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
(cf. predict.lm).
If a flexible link function is used (Aranda-Ordaz or log-gamma)
standard errors and confidence intervals of predictions do not take the
uncertainty in the link-parameter into account.
Value
A list containing the following components
- fit
predictions or fitted values if
newdatais not supplied.- se.fit
if
se.fit=TRUEstandard errors of the predictions otherwiseNULL.- upr, lwr
if
interval=TRUElower and upper confidence limits.
Examples
## simple model:
fm1 <- clm(rating ~ contact + temp, data=wine)
summary(fm1)
#> formula: rating ~ contact + temp
#> data: wine
#>
#> link threshold nobs logLik AIC niter max.grad cond.H
#> logit flexible 72 -86.49 184.98 6(0) 4.01e-12 2.7e+01
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> contactyes 1.5278 0.4766 3.205 0.00135 **
#> tempwarm 2.5031 0.5287 4.735 2.19e-06 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Threshold coefficients:
#> Estimate Std. Error z value
#> 1|2 -1.3444 0.5171 -2.600
#> 2|3 1.2508 0.4379 2.857
#> 3|4 3.4669 0.5978 5.800
#> 4|5 5.0064 0.7309 6.850
## Fitted values with standard errors and confidence intervals:
predict(fm1, se.fit=TRUE, interval=TRUE) # type="prob"
#> $fit
#> [1] 0.57064970 0.19229094 0.44305990 0.09582084 0.20049402 0.20049402
#> [7] 0.27378469 0.27378469 0.20679013 0.57064970 0.05354601 0.44305990
#> [13] 0.20141572 0.50157554 0.27378469 0.36359581 0.57064970 0.19229094
#> [19] 0.44305990 0.37764614 0.07562701 0.07562701 0.36359581 0.36359581
#> [25] 0.19229094 0.57064970 0.44305990 0.37764614 0.50157554 0.20141572
#> [31] 0.27378469 0.30420994 0.57064970 0.19229094 0.09582084 0.44305990
#> [37] 0.50157554 0.50157554 0.30420994 0.30420994 0.19229094 0.57064970
#> [43] 0.44305990 0.37764614 0.20141572 0.20049402 0.27378469 0.36359581
#> [49] 0.20679013 0.20679013 0.37764614 0.37764614 0.20141572 0.50157554
#> [55] 0.05380128 0.30420994 0.57064970 0.57064970 0.37764614 0.44305990
#> [61] 0.50157554 0.50157554 0.30420994 0.36359581 0.20679013 0.57064970
#> [67] 0.44305990 0.37764614 0.50157554 0.20141572 0.36359581 0.36359581
#>
#> $se.fit
#> [1] 0.08683884 0.06388672 0.07939754 0.04257593 0.06761012 0.06761012
#> [7] 0.09132786 0.09132786 0.08481920 0.08683884 0.02976295 0.07939754
#> [13] 0.07233205 0.07498381 0.09132786 0.08671574 0.08683884 0.06388672
#> [19] 0.07939754 0.08851418 0.03777829 0.03777829 0.08671574 0.08671574
#> [25] 0.06388672 0.08683884 0.07939754 0.08851418 0.07498381 0.07233205
#> [31] 0.09132786 0.07805942 0.08683884 0.06388672 0.04257593 0.07939754
#> [37] 0.07498381 0.07498381 0.07805942 0.07805942 0.06388672 0.08683884
#> [43] 0.07939754 0.08851418 0.07233205 0.06761012 0.09132786 0.08671574
#> [49] 0.08481920 0.08481920 0.08851418 0.08851418 0.07233205 0.07498381
#> [55] 0.02668355 0.07805942 0.08683884 0.08683884 0.08851418 0.07939754
#> [61] 0.07498381 0.07498381 0.07805942 0.08671574 0.08481920 0.08683884
#> [67] 0.07939754 0.08851418 0.07498381 0.07233205 0.08671574 0.08671574
#>
#> $lwr
#> [1] 0.39887109 0.09609419 0.29746543 0.03887676 0.09886604 0.09886604
#> [7] 0.13287400 0.13287400 0.08644108 0.39887109 0.01758030 0.29746543
#> [13] 0.09458859 0.35857236 0.13287400 0.21512673 0.39887109 0.09609419
#> [19] 0.29746543 0.22483820 0.02758599 0.02758599 0.21512673 0.21512673
#> [25] 0.09609419 0.39887109 0.29746543 0.22483820 0.35857236 0.09458859
#> [31] 0.13287400 0.17506663 0.39887109 0.09609419 0.03887676 0.29746543
#> [37] 0.35857236 0.35857236 0.17506663 0.17506663 0.09609419 0.39887109
#> [43] 0.29746543 0.22483820 0.09458859 0.09886604 0.13287400 0.21512673
#> [49] 0.08644108 0.08644108 0.22483820 0.22483820 0.09458859 0.35857236
#> [55] 0.01994752 0.17506663 0.39887109 0.39887109 0.22483820 0.29746543
#> [61] 0.35857236 0.35857236 0.17506663 0.21512673 0.08644108 0.39887109
#> [67] 0.29746543 0.22483820 0.35857236 0.09458859 0.21512673 0.21512673
#>
#> $upr
#> [1] 0.7269447 0.3477399 0.5991420 0.2173139 0.3643505 0.3643505 0.4812023
#> [8] 0.4812023 0.4180260 0.7269447 0.1517267 0.5991420 0.3784608 0.6443214
#> [15] 0.4812023 0.5435675 0.7269447 0.3477399 0.5991420 0.5593657 0.1909065
#> [22] 0.1909065 0.5435675 0.5435675 0.3477399 0.7269447 0.5991420 0.5593657
#> [29] 0.6443214 0.3784608 0.4812023 0.4738928 0.7269447 0.3477399 0.2173139
#> [36] 0.5991420 0.6443214 0.6443214 0.4738928 0.4738928 0.3477399 0.7269447
#> [43] 0.5991420 0.5593657 0.3784608 0.3643505 0.4812023 0.5435675 0.4180260
#> [50] 0.4180260 0.5593657 0.5593657 0.3784608 0.6443214 0.1370739 0.4738928
#> [57] 0.7269447 0.7269447 0.5593657 0.5991420 0.6443214 0.6443214 0.4738928
#> [64] 0.5435675 0.4180260 0.7269447 0.5991420 0.5593657 0.6443214 0.3784608
#> [71] 0.5435675 0.5435675
#>
## class predictions for the observations:
predict(fm1, type="class")
#> $fit
#> [1] 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3
#> [39] 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4 2 2 3 3 3 3 4 4
#> Levels: 1 2 3 4 5
#>
newData <- expand.grid(temp = c("cold", "warm"),
contact = c("no", "yes"))
## Predicted probabilities in all five response categories for each of
## the four cases in newData:
predict(fm1, newdata=newData, type="prob")
#> $fit
#> 1 2 3 4 5
#> 1 0.206790132 0.57064970 0.1922909 0.02361882 0.00665041
#> 2 0.020887709 0.20141572 0.5015755 0.20049402 0.07562701
#> 3 0.053546010 0.37764614 0.4430599 0.09582084 0.02992711
#> 4 0.004608274 0.05380128 0.3042099 0.36359581 0.27378469
#>
## now include standard errors and intervals:
predict(fm1, newdata=newData, se.fit=TRUE, interval=TRUE, type="prob")
#> $fit
#> 1 2 3 4 5
#> 1 0.206790132 0.57064970 0.1922909 0.02361882 0.00665041
#> 2 0.020887709 0.20141572 0.5015755 0.20049402 0.07562701
#> 3 0.053546010 0.37764614 0.4430599 0.09582084 0.02992711
#> 4 0.004608274 0.05380128 0.3042099 0.36359581 0.27378469
#>
#> $se.fit
#> 1 2 3 4 5
#> 1 0.084819201 0.08683884 0.06388672 0.01380264 0.00482850
#> 2 0.013191469 0.07233205 0.07498381 0.06761012 0.03777829
#> 3 0.029762953 0.08851418 0.07939754 0.04257593 0.01734387
#> 4 0.003522846 0.02668355 0.07805942 0.08671574 0.09132786
#>
#> $lwr
#> 1 2 3 4 5
#> 1 0.086441084 0.39887109 0.09609419 0.007429029 0.001595527
#> 2 0.005989787 0.09458859 0.35857236 0.098866040 0.027585992
#> 3 0.017580298 0.22483820 0.29746543 0.038876765 0.009475544
#> 4 0.001026538 0.01994752 0.17506663 0.215126732 0.132874005
#>
#> $upr
#> 1 2 3 4 5
#> 1 0.41802603 0.7269447 0.3477399 0.07251284 0.02728234
#> 2 0.07022233 0.3784608 0.6443214 0.36435050 0.19090648
#> 3 0.15172666 0.5593657 0.5991420 0.21731390 0.09048786
#> 4 0.02043158 0.1370739 0.4738928 0.54356745 0.48120233
#>