briencj / asremlPlus

asremlPlus is an R package that augments the use of 'ASReml-R' and 'ASReml4-R' in fitting mixed models
Other
16 stars 3 forks source link

The argument transform.function in predictPlus seems to not backtransform the predictions #7

Closed igorkf closed 1 year ago

igorkf commented 1 year ago

I'm not sure if this is a bug or if I'm making some silly mistake, but seems the argument transform.function in predictPlus is not backtransforming the predictions.

Here is a quick example:

library(asreml)
library(asremlPlus)

# fit a model
mod <- asreml(Yield ~ Variety, data = Oats.dat)
pred <- predictPlus(mod, classify = 'Variety')$predictions

# fit a model but with a transformed target
mod_trans <- asreml(sqrt(Yield) ~ Variety, data = Oats.dat)
pred_trans <- predictPlus(mod, classify = 'Variety', transform.function = 'sqrt')$backtransforms

pred == pred_trans
 Variety predicted.value standard.error upper.Confidence.limit lower.Confidence.limit est.status
1    TRUE            TRUE             NA                   TRUE                   TRUE       TRUE
2    TRUE            TRUE             NA                   TRUE                   TRUE       TRUE
3    TRUE            TRUE             NA                   TRUE                   TRUE       TRUE

As you can see, the backtransforms object is equal to the predictions (except for the standard.error column that was set to NA).

My session info:

sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: America/Chicago
tzcode source: system (glibc)

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

other attached packages:
[1] asremlPlus_4.3.55 asreml_4.1.0.176  Matrix_1.6-0     

loaded via a namespace (and not attached):
 [1] utf8_1.2.3              generics_0.1.3          qqconf_1.3.2            robustbase_0.99-0       bitops_1.0-7            stringi_1.7.12          lattice_0.21-8          pracma_2.4.2           
 [9] magrittr_2.0.3          caTools_1.18.2          grid_4.3.1              RColorBrewer_1.1-3      iterators_1.0.14        foreach_1.5.2           doParallel_1.0.17       plyr_1.8.8             
[17] jsonlite_1.8.7          opdisDownsampling_0.8.2 httr_1.4.6              fansi_1.0.4             scales_1.2.1            codetools_0.2-19        cli_3.6.1               rlang_1.1.1            
[25] munsell_0.5.0           tools_4.3.1             parallel_4.3.1          reshape2_1.4.4          memuse_4.2-3            dplyr_1.1.2             colorspace_2.1-0        ggplot2_3.4.2          
[33] dae_3.2.15              benchmarkme_1.0.8       vctrs_0.6.3             R6_2.5.1                lifecycle_1.0.3         stringr_1.5.0           MASS_7.3-60             pkgconfig_2.0.3        
[41] pillar_1.9.0            gtable_0.3.3            data.table_1.14.8       glue_1.6.2              sticky_0.5.6.1          Rcpp_1.0.11             benchmarkmeData_1.0.4   DEoptimR_1.1-0         
[49] tibble_3.2.1            tidyselect_1.2.0        rstudioapi_0.15.0       qqplotr_0.0.6           compiler_4.3.1          twosamples_2.0.1 
igorkf commented 1 year ago

Sorry, this was my fault because I was passing the wrong model (mod) to the predictPlus function.