Learn R Programming

mgwrsar (version 0.1-1)

predict_mgwrsar: mgwrsar Model Predictions

Description

predict_mgwrsar is a function for computing predictions of a mgwrsar models. It uses Best Linear Unbiased Predictor for mgwrsar models with spatial autocorrelation.

Usage

predict_mgwrsar(model, newdata, newdata_coord, W = NULL,
type = "BPN", h_w = 100,kernel_w = "knn", k_extra = 12,
kernel_extra = "sheppard")

Arguments

model

a model of mgwrsar class.

newdata

a matrix or data.frame of new data.

newdata_coord

a matrix of new coordinates.

W

the spatial weight matrix for models with spatial autocorrelation.

type

Type for BLUP estimator, default "BPN". If NULL use predictions without spatial bias correction.

h_w

bandwidth for constructing W, if W is NULL.

kernel_w

kernel for constructing W, if W is NULL.

k_extra

number of neighboors for local parameter extrapolation, default 12.

kernel_extra

kernel for local parameter extrapolation, default sheppard kernel.

Value

A vector of predictions.

See Also

MGWRSAR, bandwidths_mgwrsar, summary_mgwrsar, plot_mgwrsar, kernelW_C

Examples

Run this code
# NOT RUN {
library(mgwrsar)
data(mydata)
coord=as.matrix(mydata[,c("x_lat","y_lon")])
W=KNN(coord,2)
model_GWR_insample<-MGWRSAR(formula = 'Y_gwr~X1+X2+X3', data = mydata[1:800,],
coord=coord[1:800,],fixed_vars=NULL,kernels=c('gauss_adapt'),H=50,
 Model = 'GWR',control=list())
Y_pred=predict_mgwrsar(model_GWR_insample, newdata=mydata[801:1000,],
newdata_coord=coord[801:1000,],k_extra = 8, kernel_extra = "sheppard")
head(Y_pred)
head(mydata$Y_gwr[801:1000])
sqrt(mean((mydata$Y_gwr[801:1000]-Y_pred)^2))

## predict with spatial autocorrelation
model_MGWRSAR_1_0_kv_insample<-MGWRSAR(formula = 'Y_mgwrsar_1_0_kv~X1+X2+X3',data = mydata[1:800,],
coord=coord[1:800 ,], fixed_vars=NULL,kernels=c('gauss_adapt'),H=50,
Model = 'MGWRSAR_1_0_kv',control=list(W=W[1:800,1:800],Lambdacor=TRUE,SE=TRUE))
summary_mgwrsar(model_MGWRSAR_1_0_kv_insample)

## with BLUP
Y_pred=predict_mgwrsar(model_MGWRSAR_1_0_kv_insample, newdata=mydata[801:1000,],
newdata_coord=coord[801:1000,], k_extra = 12,  W = W,
 type = "BPN",kernel_extra = "sheppard")
head(Y_pred)
head(mydata$Y_gwr[801:1000])
sqrt(mean((mydata$Y_gwr[801:1000]-Y_pred)^2))

## without BLUP
Y_pred=predict_mgwrsar(model_MGWRSAR_1_0_kv_insample, newdata=mydata[801:1000,],
newdata_coord=coord[801:1000,], k_extra = 12,  W = W,
type = "TC",kernel_extra = "sheppard")
head(Y_pred)
head(mydata$Y_mgwrsar_1_0_kv[801:1000])
sqrt(mean((mydata$Y_mgwrsar_1_0_kv[801:1000]-Y_pred)^2))
# }

Run the code above in your browser using DataLab