I've been playing around with a King County house dataset posted on Kaggle (link: https://www.kaggle.com/harlfoxem/housesalesprediction) and tried to predict house prices with Kriging. The entire coding is shown below:
library(gstat)
library(sp)
library(ggplot2)
setwd("~/Documentos/R/Kriging")
dados = read.csv('kc_house_data.csv')
dados$price_sqft = dados$price / dados$sqft_living
ggplot(dados, aes(x = long, y = lat, size = price_sqft)) +
geom_point(alpha = 0.2) + scale_size_continuous(range = c(0.5, 5))
set.seed(1337)
treino_ind <- sample(seq_len(nrow(dados)), size = 0.80*nrow(dados))
dados_treino = dados[treino_ind,]
dados_teste = dados[-treino_ind,]
coordinates(dados_treino) = ~ long + lat
coordinates(dados_teste) = ~ long + lat
vrg = variogram(log(price_sqft)~1, (dados_treino))
vrg
vrg.fit = fit.variogram(vrg, model = vgm(1, "Sph", 1, 1))
vrg.fit
plot(vrg, vrg.fit)
vrg.krige = krige(log(price_sqft)~1, dados_treino, dados_teste,
model = vrg.fit, nmax = 1)
At first, I ran the code without the nmax = 1
bit, but saw some posts where the inclusion of some restriction on the amount of calculations was advised and finally added it. The thing with this is that if I increase the nmax parameter, kringe() function returns many NA. For instance, when nmax = 3, there was 216 NAs. With nmax = 10
, there was 766 NAs. With nmax = 50
, there was 2568 NAs (to give a little perspective, the entire test set is composed by about 4300 obs).
My question is: does that actually make sense or is it a bug?