inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
76 stars 21 forks source link

Bug report: rw2 doesn't work on devel branch #64

Closed dpsimpson closed 3 years ago

dpsimpson commented 5 years ago

There's something wrong on the devel branch when calling the rw2 model. I haven't checked but it's probably a general error. As far as I can tell, what it's doing is treating it like a spde component, so it's got internal length of length(values). But what it's not doing is correctly building an "A-matrix" so it is expecting index in the data to be the save length as values, which is almost never true.

I can't quite work out the code well enough to suggest a fix (sorry!), but I thought you should know before pushing this to main!

D

Minimal error:

library(inlabru)
n = 40
tt = 1:20
times = sample(x = tt, size=n, replace = TRUE)
yy = sin(times) + rnorm(n)
data = data.frame(yy,times)
formula = yy ~ time_trend(map=times,model="rw2",values=tt)
out = bru(formula, family="gaussian",data=data)

This gives the error message

Error in parse.input.list(list(effects[[k]]), input.ncol(A[[k]]), paste("Effect block ",  : 
  Effect block 1:
Mismatching row sizes: 40, n.A=20

Session Info

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets 
[7] methods   base     

other attached packages:
[1] inlabru_2.1.12.999 ggplot2_3.2.1      INLA_19.07.27     
[4] Matrix_1.2-17      spdep_1.1-2        sf_0.7-7          
[7] spData_0.3.0       sp_1.3-1          

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2         compiler_3.6.1     pillar_1.4.2      
 [4] LearnBayes_2.15.1  class_7.3-15       tools_3.6.1       
 [7] boot_1.3-22        tibble_2.1.3       nlme_3.1-140      
[10] gtable_0.3.0       lattice_0.20-38    pkgconfig_2.0.2   
[13] rlang_0.4.0        rstudioapi_0.10    DBI_1.0.0         
[16] rgdal_1.4-4        yaml_2.2.0         expm_0.999-4      
[19] coda_0.19-3        e1071_1.7-2        withr_2.1.2       
[22] dplyr_0.8.3        MatrixModels_0.4-1 gtools_3.8.1      
[25] tidyselect_0.2.5   classInt_0.4-1     grid_3.6.1        
[28] glue_1.3.1         R6_2.4.0           gdata_2.18.0      
[31] purrr_0.3.2        deldir_0.1-23      magrittr_1.5      
[34] scales_1.0.0       MASS_7.3-51.4      units_0.6-3       
[37] gmodels_2.18.1     splines_3.6.1      assertthat_0.2.1  
[40] colorspace_1.4-1   KernSmooth_2.23-15 lazyeval_0.2.2    
[43] munsell_0.5.0      crayon_1.3.4   
finnlindgren commented 5 years ago

Thanks for the report! Yes, indexing for rw2 (and ar1 and related models) makes incorrect assumptions that only hold for special cases.