Comments (3)
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]]))
The error is:
Error in paste(call.f, sep = "")[[3]] : subscript out of bounds
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?
from bmstdr.
Thank you. But the file spGPP.r is not within bmstdr package. It belongs to spTimer. Please contact the spTimer maintainer.
However, there is an easier solution which worked for me. Just do not attach the library string. I believe that is messing up some function used in the spTimer code.
Please see below the code and the output I produced without error on my Windows computer.
Restarting R session...
Restart R
rm(list=ls())
library(bmstdr)
Loading required package: Rcpp
Registered S3 method overwritten by 'GGally':
method from
+.gg ggplot2
Warning messages:
1: package ‘bmstdr’ was built under R version 4.1.3
2: package ‘Rcpp’ was built under R version 4.1.3
library(spTimer)
spTimer version: 3.3.1
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)
Output: GPP approximation models
Sampled: 400 of 2000, 20.00%.
Batch Acceptance Rate (phi): 47.62%
Checking Parameters:
phi: 0.0082, rho: 0.2140, sig2eps: 24.8181, sig2eta: 213.0410
beta[1]: -18.3156 beta[2]: 2.3864 beta[3]: 0.6344 beta[4]: -0.5185
Sampled: 800 of 2000, 40.00%.
Batch Acceptance Rate (phi): 46.18%
Checking Parameters:
phi: 0.0078, rho: 0.2410, sig2eps: 24.8995, sig2eta: 177.1832
beta[1]: -5.5031 beta[2]: 1.9212 beta[3]: 1.1077 beta[4]: -0.2455
Sampled: 1200 of 2000, 60.00%.
Batch Acceptance Rate (phi): 44.37%
Checking Parameters:
phi: 0.0088, rho: 0.3057, sig2eps: 26.5538, sig2eta: 178.2912
beta[1]: -8.7637 beta[2]: 1.9623 beta[3]: 1.2766 beta[4]: -0.8588
Sampled: 1600 of 2000, 80.00%.
Batch Acceptance Rate (phi): 44.97%
Checking Parameters:
phi: 0.0102, rho: 0.2496, sig2eps: 25.4951, sig2eta: 180.1180
beta[1]: -23.6339 beta[2]: 2.3384 beta[3]: 1.1674 beta[4]: 0.6791
Sampled: 2000 of 2000, 100.00%.
Batch Acceptance Rate (phi): 44.22%
Checking Parameters:
phi: 0.0090, rho: 0.1954, sig2eps: 26.7600, sig2eta: 194.2956
beta[1]: -19.1704 beta[2]: 2.3443 beta[3]: 0.7325 beta[4]: 0.2659
nBurn = 1000 . Iterations = 2000 .
Acceptance rate: (phi) = 44.2 %
Elapsed time: 1.42 Sec.
Model: GPP
Total time taken:: 1.46 - Sec.
Spatial prediction using spT.Gibbs output
pred.gp <- predict(mod$fit, tol.dist=0.0, newdata = DataValPred, newcoords = ~ Longitude + Latitude)
Prediction: GPP models
Sampled: 100 of 1000, 10.00%
Sampled: 200 of 1000, 20.00%
Sampled: 300 of 1000, 30.00%
Sampled: 400 of 1000, 40.00%
Sampled: 500 of 1000, 50.00%
Sampled: 600 of 1000, 60.00%
Sampled: 700 of 1000, 70.00%
Sampled: 800 of 1000, 80.00%
Sampled: 900 of 1000, 90.00%
Sampled: 1000 of 1000, 100.00%
Predicted samples and summary statistics are given.
nBurn = 1000 . Iterations = 2000 .
Elapsed time: 0.56 Sec.
from bmstdr.
I have found the solution or the error. Your tip with the string - package has helped me very well. I have taken out all times one after the other and so I could identify the package which causes the error. It was the package "formula.tools" which overwrites the base paste() function. If I take out this package and restart r then the prediction works without error.
Here again the code:
rm(list=ls())
library(bmstdr)
library(spTimer)
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)
# without error
pred.gp <- predict(mod$fit, tol.dist=0.0, newdata = DataValPred, newcoords = ~ Longitude + Latitude)
# with error if the package "formula.tools" is loaded
if(!require(formula.tools)){install.packages("formula.tools");library(formula.tools)}
pred.gp <- predict(mod$fit, tol.dist=0.0, newdata = DataValPred, newcoords = ~ Longitude + Latitude)
Great, then one error would be already done :=)
Thanks for the help. Because of the other things I write to the maintrainer.
from bmstdr.
Related Issues (8)
- Release bmstdr 0.1.0.9000
- Random Error by total time measurement in the Bsptime function in foreach loop HOT 2
- No function for the "plotit" option HOT 3
- Error in predict function HOT 4
- Random Error in Function Bsptime HOT 12
- truncated distribution with two border??? HOT 1
- Error in spTimer model with truncated GPP and validrows HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bmstdr.