Obtains predictions from a fitted generalized linear model with random effects.

# S3 method for glmmPQL
predict(object, newdata = NULL, type = c("link", "response"),
       level, na.action = na.pass, ...)

Arguments

object

a fitted object of class inheriting from "glmmPQL".

newdata

optionally, a data frame in which to look for variables with which to predict.

type

the type of prediction required. The default is on the scale of the linear predictors; the alternative "response" is on the scale of the response variable. Thus for a default binomial model the default predictions are of log-odds (probabilities on logit scale) and type = "response" gives the predicted probabilities.

level

an optional integer vector giving the level(s) of grouping to be used in obtaining the predictions. Level values increase from outermost to innermost grouping, with level zero corresponding to the population predictions. Defaults to the highest or innermost level of grouping.

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.

Value

If level is a single integer, a vector otherwise a data frame.

See also

Examples

fit <- glmmPQL(y ~ trt + I(week > 2), random = ~1 | ID, family = binomial, data = bacteria)
#> iteration 1
#> iteration 2
#> iteration 3
#> iteration 4
#> iteration 5
#> iteration 6
predict(fit, bacteria, level = 0, type="response")
#> [1] 0.9680779 0.9680779 0.8587270 0.8587270 0.9344832 0.9344832 0.7408574 #> [8] 0.7408574 0.8970307 0.8970307 0.6358511 0.6358511 0.6358511 0.9680779 #> [15] 0.9680779 0.8587270 0.8587270 0.8587270 0.9680779 0.9680779 0.8587270 #> [22] 0.8587270 0.8587270 0.8970307 0.8970307 0.6358511 0.6358511 0.9344832 #> [29] 0.9344832 0.7408574 0.7408574 0.7408574 0.9680779 0.9680779 0.8587270 #> [36] 0.8587270 0.8587270 0.9680779 0.9680779 0.8587270 0.8587270 0.8587270 #> [43] 0.9344832 0.7408574 0.9680779 0.9680779 0.8587270 0.8587270 0.8587270 #> [50] 0.8970307 0.8970307 0.6358511 0.6358511 0.6358511 0.9680779 0.9680779 #> [57] 0.8587270 0.8587270 0.8587270 0.9680779 0.9680779 0.8587270 0.8970307 #> [64] 0.8970307 0.6358511 0.6358511 0.6358511 0.9344832 0.9344832 0.7408574 #> [71] 0.7408574 0.7408574 0.9680779 0.9680779 0.8587270 0.8587270 0.8587270 #> [78] 0.8970307 0.8970307 0.6358511 0.6358511 0.6358511 0.9680779 0.9680779 #> [85] 0.8587270 0.8587270 0.8587270 0.9344832 0.9344832 0.7408574 0.7408574 #> [92] 0.9680779 0.9680779 0.8587270 0.8587270 0.8587270 0.9680779 0.9680779 #> [99] 0.8587270 0.8587270 0.8587270 0.9680779 0.9680779 0.8587270 0.8587270 #> [106] 0.8587270 0.9344832 0.9344832 0.7408574 0.7408574 0.7408574 0.8970307 #> [113] 0.8970307 0.6358511 0.6358511 0.9680779 0.9680779 0.8587270 0.9680779 #> [120] 0.9680779 0.8587270 0.8587270 0.8970307 0.8970307 0.6358511 0.6358511 #> [127] 0.6358511 0.9344832 0.7408574 0.7408574 0.7408574 0.9680779 0.8587270 #> [134] 0.8587270 0.8587270 0.8970307 0.8970307 0.6358511 0.6358511 0.6358511 #> [141] 0.9680779 0.9680779 0.8587270 0.8587270 0.8587270 0.9344832 0.7408574 #> [148] 0.8970307 0.8970307 0.6358511 0.6358511 0.9680779 0.9680779 0.8587270 #> [155] 0.8970307 0.8970307 0.6358511 0.9680779 0.9680779 0.8587270 0.8587270 #> [162] 0.8587270 0.9344832 0.9344832 0.7408574 0.7408574 0.7408574 0.9680779 #> [169] 0.9680779 0.8587270 0.8587270 0.8587270 0.9344832 0.7408574 0.8970307 #> [176] 0.8970307 0.6358511 0.6358511 0.6358511 0.9344832 0.9344832 0.7408574 #> [183] 0.7408574 0.9680779 0.9680779 0.8587270 0.8587270 0.8587270 0.8970307 #> [190] 0.8970307 0.6358511 0.6358511 0.6358511 0.9344832 0.9344832 0.7408574 #> [197] 0.7408574 0.7408574 0.8970307 0.6358511 0.6358511 0.9344832 0.9344832 #> [204] 0.7408574 0.7408574 0.7408574 0.8970307 0.8970307 0.6358511 0.6358511 #> [211] 0.9344832 0.9344832 0.7408574 0.7408574 0.7408574 0.9344832 0.9344832 #> [218] 0.7408574 0.7408574 0.7408574 #> attr(,"label") #> [1] "Predicted values"
predict(fit, bacteria, level = 1, type="response")
#> X01 X01 X01 X01 X02 X02 X02 X02 #> 0.9828449 0.9828449 0.9198935 0.9198935 0.9050782 0.9050782 0.6564944 0.6564944 #> X03 X03 X03 X03 X03 X04 X04 X04 #> 0.9724022 0.9724022 0.8759665 0.8759665 0.8759665 0.9851548 0.9851548 0.9300763 #> X04 X04 X05 X05 X05 X05 X05 X06 #> 0.9300763 0.9300763 0.9851548 0.9851548 0.9300763 0.9300763 0.9300763 0.9662755 #> X06 X06 X06 X07 X07 X07 X07 X07 #> 0.9662755 0.8516962 0.8516962 0.7291679 0.7291679 0.3504978 0.3504978 0.3504978 #> X08 X08 X08 X08 X08 X09 X09 X09 #> 0.9426815 0.9426815 0.7672499 0.7672499 0.7672499 0.9851548 0.9851548 0.9300763 #> X09 X09 X10 X10 X11 X11 X11 X11 #> 0.9300763 0.9300763 0.9640326 0.8430706 0.9851548 0.9851548 0.9300763 0.9300763 #> X11 X12 X12 X12 X12 X12 X13 X13 #> 0.9300763 0.8334870 0.8334870 0.5008219 0.5008219 0.5008219 0.9851548 0.9851548 #> X13 X13 X13 X14 X14 X14 X15 X15 #> 0.9300763 0.9300763 0.9300763 0.8907227 0.8907227 0.6203155 0.9724022 0.9724022 #> X15 X15 X15 X16 X16 X16 X16 X16 #> 0.8759665 0.8759665 0.8759665 0.9287777 0.9287777 0.7232833 0.7232833 0.7232833 #> X17 X17 X17 X17 X17 X18 X18 X18 #> 0.9426815 0.9426815 0.7672499 0.7672499 0.7672499 0.7070916 0.7070916 0.3260827 #> X18 X18 X19 X19 X19 X19 X19 X20 #> 0.3260827 0.3260827 0.8702991 0.8702991 0.5735499 0.5735499 0.5735499 0.9736293 #> X20 X20 X20 X21 X21 X21 X21 X21 #> 0.9736293 0.8809564 0.8809564 0.9851548 0.9851548 0.9300763 0.9300763 0.9300763 #> Y01 Y01 Y01 Y01 Y01 Y02 Y02 Y02 #> 0.9851548 0.9851548 0.9300763 0.9300763 0.9300763 0.7607971 0.7607971 0.3893126 #> Y02 Y02 Y03 Y03 Y03 Y03 Y03 Y04 #> 0.3893126 0.3893126 0.8487181 0.8487181 0.5292976 0.5292976 0.5292976 0.5734482 #> Y04 Y04 Y04 Y05 Y05 Y05 Y06 Y06 #> 0.5734482 0.2122655 0.2122655 0.7144523 0.7144523 0.3339997 0.9828449 0.9828449 #> Y06 Y06 Y07 Y07 Y07 Y07 Y07 Y08 #> 0.9198935 0.9198935 0.8334870 0.8334870 0.5008219 0.5008219 0.5008219 0.9238389 #> Y08 Y08 Y08 Y09 Y09 Y09 Y09 Y10 #> 0.7085660 0.7085660 0.7085660 0.9847299 0.9281899 0.9281899 0.9281899 0.9188296 #> Y10 Y10 Y10 Y10 Y11 Y11 Y11 Y11 #> 0.9188296 0.6940862 0.6940862 0.6940862 0.9851548 0.9851548 0.9300763 0.9300763 #> Y11 Y12 Y12 Y13 Y13 Y13 Y13 Y14 #> 0.9300763 0.9640326 0.8430706 0.5734482 0.5734482 0.2122655 0.2122655 0.9793383 #> Y14 Y14 Z01 Z01 Z01 Z02 Z02 Z02 #> 0.9793383 0.9047659 0.9556329 0.9556329 0.8119328 0.9851548 0.9851548 0.9300763 #> Z02 Z02 Z03 Z03 Z03 Z03 Z03 Z05 #> 0.9300763 0.9300763 0.9779690 0.9779690 0.8989642 0.8989642 0.8989642 0.8702991 #> Z05 Z05 Z05 Z05 Z06 Z06 Z07 Z07 #> 0.8702991 0.5735499 0.5735499 0.5735499 0.8306525 0.4957505 0.8334870 0.8334870 #> Z07 Z07 Z07 Z09 Z09 Z09 Z09 Z10 #> 0.5008219 0.5008219 0.5008219 0.9736293 0.9736293 0.8809564 0.8809564 0.9851548 #> Z10 Z10 Z10 Z10 Z11 Z11 Z11 Z11 #> 0.9851548 0.9300763 0.9300763 0.9300763 0.9724022 0.9724022 0.8759665 0.8759665 #> Z11 Z14 Z14 Z14 Z14 Z14 Z15 Z15 #> 0.8759665 0.9287777 0.9287777 0.7232833 0.7232833 0.7232833 0.9643851 0.8444172 #> Z15 Z19 Z19 Z19 Z19 Z19 Z20 Z20 #> 0.8444172 0.9779690 0.9779690 0.8989642 0.8989642 0.8989642 0.7620490 0.7620490 #> Z20 Z20 Z24 Z24 Z24 Z24 Z24 Z26 #> 0.3909523 0.3909523 0.8487181 0.8487181 0.5292976 0.5292976 0.5292976 0.9287777 #> Z26 Z26 Z26 Z26 #> 0.9287777 0.7232833 0.7232833 0.7232833 #> attr(,"label") #> [1] "Predicted values"