sujit-sahu / bmstdr

This is the repository for the R package bmstdr.

Home Page:https://www.sujitsahu.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in predict function

Hallo951 opened this issue · comments

The predict function has error with bmstdr. The error is:

"Error in paste(call.f, sep = "")[[3]] : subscript out of bounds"

Here a Example:

library(bmstdr)
library(spTimer)
library(string) 

set.seed(11)
s <- sort(sample(unique(nysptime$s.index), size = floor((length(unique(nysptime$s.index))/100)*20)))
DataFit <- spT.subset(data = nysptime, var.name = "s.index", s = s, reverse = T) 
DataValPred <- spT.subset(data = nysptime, var.name = "s.index", s = s, reverse = F) 

mod <- Bsptime(package = "spTimer", 
                 model = "GPP", 
                 formula = as.formula(y8hrmax ~ xmaxtemp + xwdsp + xrh), 
                 data = DataFit, 
                 n.report = 5, 
                 coordtype = "utm", 
                 coords = 4:5, 
                 scale.transform = "NONE", 
                 g_size = 4,
                 N = 2000, 
                 mchoice = F,
                 plotit = F)

# Spatial prediction using spT.Gibbs output
pred.gp <- predict(mod$fit, tol.dist=0.0, newdata = DataValPred, newcoords = ~ Longitude + Latitude)

# result: Error in paste(call.f, sep = "")[[3]] : subscript out of bounds

A temporary fix is:
mod$fit$call <- c(mod$fit$call,"", str_split_fixed(mod$fit$call, " ", n = 3)[3])

The error is that the predict function cannot divide the regression formula by dependent and independent variables. I do this manually with the fix. The error line (line number 674) is in the data spGPP.r from the package spTimer in github with the Web Adress https://github.com/cran/spTimer/blob/master/R/spGPP.r in the function "spGPP.prediction". The line is call.f<-as.formula(paste("tmp~",paste(call.f,sep="")[[3]])).

It is very important that you fix this in the program code, because this error occurs in all models. My temporary fix is only a stopgap.

My system:
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 17763)

Version bmstdr: 0.2.2

Dear Hallo951,
Thank you very much. I am away attending ISBA in Montreal this week. I will reply once I am able to investigate the issues - possibly next week after my return. Please can you wait.
Best wishes, Sujit

Hello Mr. Sujit,

thank you very much for the answer. Yes until next week is not a problem...I will then do other work left this week....

best regard
Frank (alias Hallo951)

Thanks for this. But sorry, I have not been able to reproduce the error. I checked both on my linux and Windows machines. I will ask some of my students to double check this. Please can you give me code which results in error.

That's very strange.

I have tried their package on different computers and the error occurs on all of them. The incorrect line for me is the following:

call.f<-as.formula(paste("tmp~",paste(call.f,sep="")[[3]]))

Where call.f is the model formula. Does the following work for them:

call.f <- as.formula(y8hrmax ~ xmaxtemp + xwdsp + xrh)

call.f<-as.formula(paste("tmp~",paste(call.f,sep="")[[3]]))

After all, this line does nothing but replace "y8hrmax" with "tmp". And just this causes me the error no matter which computer I test it on...

Do you have an additional package installed or something?