Description Usage Arguments Details Value Examples
View source: R/predict_plbpsm.R
Takes a fitted plbpsm
object produced by plbpsm()
and produces predictions given a new set of values for the model covariates
or the original values used for the model fit. Predictions can be accompanied
by standard errors, based on the posterior distribution of the model
coefficients. The routine can optionally return the matrix by which the model
coefficients must be pre-multiplied in order to yield the values of the linear predictor at
the supplied covariate values.
1 2 3 4 5 6 |
object |
a fitted |
newdata |
A data frame or list containing the values of the model covariates at which predictions
are required. If this is not provided then predictions corresponding to the
original data are returned. If |
type |
the type of prediction required. The default is on the scale of the linear predictors;
the alternative |
se.fit |
when this is |
terms |
if |
exclude |
if |
block.size |
maximum number of predictions to process per call to underlying
code: larger is quicker, but more memory intensive. Set to < 1 to use total number
of predictions as this. If |
newdata.guaranteed |
Set to |
na.action |
what to do about |
unconditional |
if TRUE then the smoothing parameter uncertainty corrected covariance matrix is used to compute uncertainty bands, if available. Otherwise the bands treat the smoothing parameters as fixed. |
newB |
the given matrix of bivariate spline basis functions. |
newind00 |
the given index of the data points in the triangulation. |
backfitting |
whether SBL estimation is obtained. |
... |
other arguments. |
See examples to see usages of different types.
if se.fit
is TRUE
then a 2 item list is returned with items (both arrays) fit
and se.fit
containing predictions and associated standard error estimates, otherwise an
array of predictions is returned. The dimensions of the returned arrays depends on whether
type
is "terms"
or not: if it is then the array is 2 dimensional with each
term in the linear predictor separate, otherwise the array is 1 dimensional and contains the
linear predictor/predicted values (or corresponding s.e.s). The linear predictor returned termwise will
not include the offset or the intercept.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | library(MASS)
library(grpreg)
library(BPST)
data("eg1pop_dat")
eg1_V2 <- eg1pop_dat[['V2']]
eg1_T2 <- eg1pop_dat[['T2']]
eg1pop_rho03 <- eg1pop_dat[['rho03']]
sam <- eg1pop_rho03[sample(1:dim(eg1pop_rho03)[1],100),]
### Partial Linear Spatial Model ###
formula_d4 <- Y~z1+z2+z3+z4+z5+z6+z7+z8+b(x1,x2,d=4,r=1,V=eg1_V2,Tr=eg1_T2)
res <- plbpsm(formula=formula_d4,data=as.data.frame(sam),VS=TRUE)
# check deviance and the estimated error from predict function
newdata <- as.data.frame(sam[sample(1:dim(sam)[1],90),])
pred <- predict(res,newdata)
# exclude one covariate
pred0 <- predict(res,newdata,exclude="z2",type='terms')
# check
### Generalized Partially Linear Spatial Model ###
# Poisson family
data("eg_poi_pl")
sam <- as.data.frame(eg_poi[['sam_poi']])
sam[1,]
V <- eg_poi[['V1']]
Tr <- eg_poi[['T1']]
formula <- y~c1+c2+c3+c4+c5+c6+c7+c8+c9+c10+c11+c12+c13+c14+c15+b(loc1,loc2,V=V,Tr=Tr,d=2,r=1)
res_poi <- plbpsm(formula=formula,family=poisson(),data=as.data.frame(sam))
# with offset
res_poi2 <- plbpsm(formula=formula,family=poisson(),offset=rep(0.1,length(data$y)),
data <- as.data.frame(sam))
newdata <- as.data.frame(sam[sample(1:dim(sam)[1],90),])
# return the predicted value for each term #
predict(res_poi,newdata,type='terms',se.fit = TRUE)
predict(res_poi2,newdata)
data(eg1pop_bin_rho00)
formula <- Y~z1+z2+z3+b(x1,x2,V=eg1_V2,Tr=eg1_T2,d=2,r=1)
n <- 100
Npop <- nrow(eg1pop_bin_rho00)
# ind.pop <- (1:Npop)[!is.na(eg1pop_bin_rho00[,1])]
ind.pop <- (1:Npop)
sam.ind <- sort(sample(ind.pop,n,replace=FALSE))
sam <- eg1pop_bin_rho00[sam.ind,]
res_eg1_bin <- plbpsm(formula=formula,data=as.data.frame(sam),family=binomial())
eg1pop_bin_rho00=as.data.frame(eg1pop_bin_rho00)
newdata <- eg1pop_bin_rho00[1000:1100,]
predict(res_eg1_bin,as.data.frame(newdata),type='terms',se.fit = TRUE)
### Generalized Geoadditive Models with Model Identification ###
data(eg1pop_poi2)
formula <- Y~u(z1)+u(z2)+u(z3)+b(x1,x2,V=eg1_V2,Tr=eg1_T2,d=2,r=1)
n <- 100
Npop <- nrow(eg1pop_poi2)
# ind.pop <- (1:Npop)[!is.na(eg1pop_poi2[,1])]
ind.pop <- (1:Npop)
sam.ind <- sort(sample(ind.pop,n,replace=FALSE))
sam <- eg1pop_poi2[sam.ind,]
res_eg1_poi_add <- plbpsm(formula=formula,data=as.data.frame(sam),family='poisson')
newdata <- as.data.frame(sam[sample(1:dim(sam)[1],90),])
## backfitting = FALSE ##
pred_noBKF <- predict(res_eg1_poi_add,newdata,backfitting=FALSE)
## defualt backfitting for \code{res_eg1_poi_add}
pred_BKF <- predict(res_eg1_poi_add,newdata)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.