Learn R Programming

GWlasso (version 1.0.1)

predict.gwlfit: Predict method for gwlfit objects

Description

Predict method for gwlfit objects

Usage

# S3 method for gwlfit
predict(object, newdata, newcoords, type = "response", verbose = FALSE, ...)

Value

a vector of predicted values

Arguments

object

Object of class inheriting from "gwlfit"

newdata

a data.frame or matrix with the same columns as the training dataset

newcoords

a dataframe or matrix of coordinates of the new data

type

the type of response. see glmnet::predict.glmnet()

verbose

TRUE to print info about the execution of the function (useful for very large predictions)

...

ellipsis for S3 compatibility. Not used in this function.

Examples

Run this code

predictors <- matrix(data = rnorm(2500), 50,50)
y_value <- sample(1:1000, 50)
coords <- data.frame("Lat" = rnorm(50), "Long" = rnorm(50))
distance_matrix <- compute_distance_matrix(coords)

my.gwl.fit <- gwl_fit(bw = 20,
                      x.var = predictors, 
                      y.var = y_value,
                      kernel = "bisquare",
                      dist.mat = distance_matrix, 
                      alpha = 1, 
                      adaptive = TRUE, 
                      progress = TRUE,
                      nfolds = 5)
                      
my.gwl.fit

new_predictors <- matrix(data = rnorm(500), 10,50)
new_coords <- data.frame("Lat" = rnorm(10), "Long" = rnorm(10))

predicted_values <- predict(my.gwl.fit,
                             newdata = new_predictors, 
                             newcoords = new_coords)

Run the code above in your browser using DataLab