predict.lm.rrpp: predict for lm.rrpp model fits

View source: R/predict.lm.rrpp.r

predict.lm.rrppR Documentation

predict for lm.rrpp model fits

Description

Computes predicted values from an lm.rrpp model fit, using bootstrapped residuals to generate confidence intervals. (Residuals are the residuals of the lm.rppp fit, not its null model. The bootstrap procedure resamples residual vectors with replacement.) The bootstrap permutations use the same number of iterations and seed as used in the lm.rrpp model fit. A predict.lm.rrpp object can be plotted using various options. See plot.predict.lm.rrpp.

Note that if data offsets are used (if the offset argument is used when fitting a lm.rrpp model), they are ignored for estimating coefficients over iterations. Offsets are subtracted from data in lm and added to predicted values in predict.lm, effectively adjusting the intercept and then un-adjusting it for predictions. This causes problems if the newdata have a different number of observations than the original model fit.

Usage

## S3 method for class 'lm.rrpp'
predict(object, newdata = NULL, block = NULL, confidence = 0.95, ...)

Arguments

object

Object from lm.rrpp.

newdata

Data frame of either class data.frame or rrpp.data.frame. If null, the data frame from the lm.rrpp fit will be used, effectively calculating all fitted values and their confidence intervals. If a numeric variable is missing from newdata, an attempt to average the values will be made in prediction; i.e., least squares means for factor levels can be found. All factors used in the lm.rrpp fit should be represented in the newdata data frame, with appropriate factor levels.

block

An optional factor for blocks within which to restrict resampling permutations.

confidence

The desired confidence interval level for prediction.

...

Other arguments (currently none)

Author(s)

Michael Collyer

Examples

## Not run: 
# See examples for lm.rrpp to see how predict.lm.rrpp works in conjunction
# with other functions

data(Pupfish)

# CS is centroid (fish) size
fit <- lm.rrpp(coords ~ log(CS)  + Sex*Pop, 
SS.type = "I", data = Pupfish, iter = 999) 

# Predictions (holding alternative effects constant)

shapeDF <- expand.grid(Sex = levels(Pupfish$Sex), Pop = levels(Pupfish$Pop))
rownames(shapeDF) <- paste(shapeDF$Sex, shapeDF$Pop, sep = ".")
shapeDF

shapePreds <- predict(fit, shapeDF)
summary(shapePreds)
summary(shapePreds, PC = TRUE)

shapePreds99 <- predict(fit, shapeDF, confidence = 0.99)
summary(shapePreds99, PC = TRUE)

# Plot prediction

plot(shapePreds, PC = TRUE)
plot(shapePreds, PC = TRUE, ellipse = TRUE)
plot(shapePreds99, PC = TRUE)
plot(shapePreds99, PC = TRUE, ellipse = TRUE)

## End(Not run)


RRPP documentation built on June 22, 2024, 6:45 p.m.