yonicd / lmmen

R package that solves the linear mixed model elastic net
2 stars 4 forks source link

cv.lmmlasso "penalized" argument #3

Open RachelHorn opened 5 years ago

RachelHorn commented 5 years ago

(post to follow up on email) when inputting a matrix into cv.lmmlasso(), the error below appears Error in .checkinput(match.call(), parent.frame()) : missing values in "penalized" argument

but "penalized" is not an argument in cv.lmmlasso or lmmlasso, so it is not clear what this is referring to or how to fix it. Thank you.

yonicd commented 5 years ago

can you please paste in a comment the output from sessioninfo::session_info()

RachelHorn commented 5 years ago
```r - Session info -------------------------------------------------------------------------- setting value version R version 3.5.3 (2019-03-11) os Windows >= 8 x64 system x86_64, mingw32 ui RStudio language (EN) collate English_United States.1252 ctype English_United States.1252 tz America/New_York date 2019-03-28 - Packages ------------------------------------------------------------------------------ package * version date lib source assertthat 0.2.0 2017-04-11 [1] CRAN (R 3.5.1) beanplot * 1.2 2014-09-19 [1] CRAN (R 3.5.1) boot 1.3-20 2017-08-06 [2] CRAN (R 3.5.3) cli 1.0.1 2018-09-25 [1] CRAN (R 3.5.1) cmprsk 2.2-7 2014-06-17 [1] CRAN (R 3.5.3) codetools 0.2-16 2018-12-24 [2] CRAN (R 3.5.3) colorspace 1.4-0 2019-01-13 [1] CRAN (R 3.5.2) corpcor * 1.6.9 2017-04-01 [1] CRAN (R 3.5.0) crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.1) crosstalk 1.0.0 2016-12-21 [1] CRAN (R 3.5.1) data.table 1.12.0 2019-01-13 [1] CRAN (R 3.5.2) digest 0.6.18 2018-10-10 [1] CRAN (R 3.5.2) doParallel 1.0.14 2018-09-24 [1] CRAN (R 3.5.1) dplyr 0.8.0.1 2019-02-15 [1] CRAN (R 3.5.2) emulator * 1.2-19 2019-01-15 [1] CRAN (R 3.5.3) Epi * 2.35 2019-03-01 [1] CRAN (R 3.5.3) etm 1.0.4 2018-07-11 [1] CRAN (R 3.5.3) fdrtool * 1.2.15 2015-07-08 [1] CRAN (R 3.5.2) foreach * 1.4.4 2017-12-12 [1] CRAN (R 3.5.1) foreign * 0.8-71 2018-07-20 [1] CRAN (R 3.5.1) GeneNet * 1.2.13 2015-08-02 [1] CRAN (R 3.5.2) GGally 1.4.0 2018-05-17 [1] CRAN (R 3.5.1) ggplot2 * 3.1.0 2018-10-25 [1] CRAN (R 3.5.2) glmmLasso * 1.5.1 2017-05-06 [1] CRAN (R 3.5.3) glmnet * 2.0-16 2018-04-02 [1] CRAN (R 3.5.3) glue 1.3.0 2018-07-17 [1] CRAN (R 3.5.3) gridExtra 2.3 2017-09-09 [1] CRAN (R 3.5.2) gtable 0.2.0 2016-02-26 [1] CRAN (R 3.5.1) htmltools 0.3.6 2017-04-28 [1] CRAN (R 3.5.1) htmlwidgets 1.3 2018-09-30 [1] CRAN (R 3.5.1) httpuv 1.4.5.1 2018-12-18 [1] CRAN (R 3.5.2) iterators 1.0.10 2018-07-13 [1] CRAN (R 3.5.1) jsonlite 1.6 2018-12-07 [1] CRAN (R 3.5.2) KernSmooth 2.23-15 2015-06-29 [2] CRAN (R 3.5.3) knitr 1.22 2019-03-08 [1] CRAN (R 3.5.3) lars * 1.2 2013-04-24 [1] CRAN (R 3.5.2) later 0.8.0 2019-02-11 [1] CRAN (R 3.5.2) lattice 0.20-38 2018-11-04 [2] CRAN (R 3.5.3) lazyeval 0.2.1 2017-10-29 [1] CRAN (R 3.5.1) lme4 * 1.1-21 2019-03-05 [1] CRAN (R 3.5.3) lmerTest * 3.1-0 2019-02-11 [1] CRAN (R 3.5.2) lmmen * 1.0 2017-08-14 [1] CRAN (R 3.5.3) lmmlasso * 0.1-2 2011-04-15 [1] CRAN (R 3.5.3) longitudinal * 1.1.12 2015-07-08 [1] CRAN (R 3.5.2) magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.1) manipulateWidget 0.10.0 2018-06-11 [1] CRAN (R 3.5.1) MASS * 7.3-51.1 2018-11-01 [2] CRAN (R 3.5.3) Matrix * 1.2-15 2018-11-01 [2] CRAN (R 3.5.3) matrixStats 0.54.0 2018-07-23 [1] CRAN (R 3.5.3) mgcv * 1.8-27 2019-02-06 [2] CRAN (R 3.5.3) mgcViz * 0.1.3 2019-01-23 [1] CRAN (R 3.5.3) mime 0.6 2018-10-05 [1] CRAN (R 3.5.1) miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 3.5.1) minqa 1.2.4 2014-10-09 [1] CRAN (R 3.5.1) miscTools * 0.6-22 2016-11-25 [1] CRAN (R 3.5.1) munsell 0.5.0 2018-06-12 [1] CRAN (R 3.5.1) mvtnorm * 1.0-10 2019-03-05 [1] CRAN (R 3.5.2) nlme * 3.1-137 2018-04-07 [1] CRAN (R 3.5.1) nloptr 1.2.1 2018-10-03 [1] CRAN (R 3.5.1) numDeriv 2016.8-1 2016-08-27 [1] CRAN (R 3.5.0) parcor * 0.2-6 2014-09-04 [1] CRAN (R 3.5.3) penalized * 0.9-51 2018-07-12 [1] CRAN (R 3.5.3) pillar 1.3.1 2018-12-15 [1] CRAN (R 3.5.2) pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.5.1) plyr 1.8.4 2016-06-08 [1] CRAN (R 3.5.1) ppls * 1.6-1.1 2018-07-20 [1] CRAN (R 3.5.3) promises 1.0.1 2018-04-13 [1] CRAN (R 3.5.1) purrr 0.3.1 2019-03-03 [1] CRAN (R 3.5.3) qgam * 1.2.3 2019-01-24 [1] CRAN (R 3.5.3) quadprog 1.5-5 2013-04-17 [1] CRAN (R 3.5.2) R6 2.4.0 2019-02-14 [1] CRAN (R 3.5.2) RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.5.0) Rcpp 1.0.0 2018-11-07 [1] CRAN (R 3.5.2) reshape 0.8.8 2018-10-23 [1] CRAN (R 3.5.2) rgl * 0.100.18 2019-03-08 [1] CRAN (R 3.5.3) rlang 0.3.1 2019-01-08 [1] CRAN (R 3.5.2) rstudioapi 0.9.0 2019-01-09 [1] CRAN (R 3.5.2) scales 1.0.0 2018-08-09 [1] CRAN (R 3.5.1) sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.5.2) shiny 1.2.0 2018-11-02 [1] CRAN (R 3.5.2) survival * 2.43-3 2018-11-26 [2] CRAN (R 3.5.3) tibble 2.0.1 2019-01-12 [1] CRAN (R 3.5.2) tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.5.2) viridis 0.5.1 2018-03-29 [1] CRAN (R 3.5.2) viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.5.1) webshot 0.5.1 2018-09-28 [1] CRAN (R 3.5.1) withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.1) xfun 0.5 2019-02-20 [1] CRAN (R 3.5.2) xtable 1.8-3 2018-08-29 [1] CRAN (R 3.5.1) yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.1) zoo 1.8-4 2018-09-19 [1] CRAN (R 3.5.1) ```

yonicd commented 5 years ago

it looks like the error is coming from penalized:::.checkinput()

is your data a single object or a few objects that is being input into lmmlasso::lmmlasso?

for example

lmmlasso::lmmlasso(x = X, y = y, z = Z, grp = grp, lambda = lambda, pdMat = pdMat)

if it is a set of objects please put them in a list say l and do

file.create('mydata.txt')
dput(l,file='mydata.txt')

then drag and drop that data into a comment, this way I can reproduce the problem on my computer.

RachelHorn commented 5 years ago

I appreciate the help, but this is human subjects research so the data cannot be shared publicly. I will contact my supervisor to ask about sharing it with you directly, but I cannot post it here. That said, the data is all in one matrix for cv.lmmlasso per the help page.

yonicd commented 5 years ago

that is ok. can you reproduce the same issue with a generic matrix?

RachelHorn commented 5 years ago

I made up the code below - it follows a similar structure to my dataset but the content is relative nonsense. I've been trying to replicate the problem, but the error I'm now getting says that y needs to be numeric (error copied at bottom). The problem is that my original elements are numeric and R will not let me reconfigure it. If I can get it to recognize that the outcome is numeric, I suspect the original problem will be replicated. I'm sorry to spring this new issue on you! Apologies for not creating a file as above, but this runs fine when copied and pasted.

ClientID <- c(rep("1",5), rep("2",5), rep("3",5), rep("4",5), rep("5",5), rep("6",5))
Age <- as.matrix(c(rep(9,5), rep(11,5), rep(10,5), rep(13,5), rep(15,5), rep(12,5)), ncol = 1)
Gender <- as.matrix(factor(c(rep(1,5),rep(2,5),rep(1,5),rep(2,5),rep(1,5), rep(2,5)), labels = c("Boy", "Girl")), ncol = 1)
Medication <- as.matrix(factor(c(rep(2,5),rep(2,5),rep(1,5),rep(1,5),rep(1,5), rep(2,5)), labels = c("no", "yes")), ncol = 1)
Treatment <- as.matrix(factor(c(rep(1,5),rep(2,5),rep(2,5),rep(2,5),rep(1,5), rep(1,5)), labels = c("usual care", "CBT")), ncol = 1)
Treatment_site <- as.matrix(c(rep(1,5),rep(3,5),rep(2,5), rep(2,5), rep(1,5), rep(3,5)), ncol = 1)
Day <- as.matrix(c(0, 20, 40, 60, 80, 0, 25, 50, 75, 100, 0, 22, 40, 65, 80, 0, 33, 50, 79, 95, 0, 16, 41, 69, 88, 0, 30, 60, 90, 120), ncol = 1)
Symptoms <-c(8, 7, 6, 5, 4, 14, 12, 11, 8, 6, 9, 7, 9, 7, 5, 6, 4, 5, 3, 3, 8, 6, 3, 3, 2, 11, 14, 13, 11, 10)
Data <-as.matrix(cbind(Age, Gender, Medication, Treatment, Day))
Test_Matrix <- cbind(Symptoms, Data, Treatment_site)
colnames(Test_Matrix) <-  c( "y", "X1", "X2", "X3", "X4", "X5", "Z")
rownames(Test_Matrix) <- ClientID
cv.lmmlasso(Test_Matrix)

Error in lmmlasso.default(x = X, y = y, z = Z, grp = grp, lambda = lambda[i], : y has to be of type 'numeric'

yonicd commented 5 years ago

that is ok.

i'll try to reproduce using this example.

RachelHorn commented 5 years ago

Thank you. I am concerned that the problem may relate to the data's complexity - my input includes a model.matrix() output that contains 3-way interactions. Since the example does not contain interaction elements, I am wondering if that may not have been incorporated into the function.

yonicd commented 5 years ago

that may be a limitation of lmmlasso, since cv.lmmlasso is only a wrapper around it.

RachelHorn commented 5 years ago

That's not the case - if I run lmmlasso() using my data (not with everything in a singular matrix, as in cv.lmmlasso, but with x, y, z, and grp specified) and input a random value for lambda, the function works.

yonicd commented 5 years ago

good to know, that narrows it down for me. i'll get back to you with a solution for that test data.

RachelHorn commented 5 years ago

Thank you so much. If the error doesn't appear with the data as I sent it, would you mind using model.matrix( ~.^3, data) to generate those 3-way interactions and to see if the problem occurs in that context?

yonicd commented 5 years ago

it looks like there is a problem in lmmlasso::lmlasso(). this error comes from the package penalized which lmmlasso is built on, which has apparently been classified on CRAN as ORPHANED.

ClientID              <- rep(1:6,each=5)
Age                   <- rep(c(9,11,10,13,15,12),each=5)  
Gender                <- rep(c(0,1),each=5,time=3)
Medication            <- rep(c(1,1,0,0,0,1),each=5)
Treatment             <- rep(c(0,1,1,1,0,0),each=5)
Treatment_site        <- rep(c(1,3,2,2,1,3),each=5)
Day                   <- c(0, 20, 40, 60, 80, 0, 25, 50, 75, 100, 0, 22, 40, 65, 80, 0, 33, 50, 79, 95, 0, 16, 41, 69, 88, 0, 30, 60, 90, 120)
Symptoms              <- c(8, 7, 6, 5, 4, 14, 12, 11, 8, 6, 9, 7, 9, 7, 5, 6, 4, 5, 3, 3, 8, 6, 3, 3, 2, 11, 14, 13, 11, 10)
Data                  <- as.matrix(cbind(Age, Gender, Medication, Treatment, Day))
Test_Matrix           <- cbind(Symptoms, Data, Treatment_site)
colnames(Test_Matrix) <- c("y", sprintf("X%s",1:5), "Z")
rownames(Test_Matrix) <- ClientID
lmmen::cv.lmmlasso(Test_Matrix)
#> Error in optL1(y, x[, -1], model = "linear", fold = 10, trace = FALSE): could not find function "optL1"

data <-  as.matrix(Test_Matrix)
y <-  matrix(data[ , grepl('^y' , colnames(data))] , ncol = 1)
X <-  cbind(rep(1 , nrow(data)) , data[ , grepl('^X' , colnames(data))])
Z <-  cbind(rep(1 , nrow(data)) , data[ , grepl('^Z' , colnames(data))])
grp <-  factor(row.names(data))
pdMat <-  "pdSym"

lmmlasso::lmmlasso(x = X,
                   y = y,
                   z = Z,
                   grp = grp,
                   lambda = 0,
                   pdMat = pdMat)
#> Error in optL1(y, x[, -1], model = "linear", fold = 10, trace = FALSE): could not find function "optL1"

Created on 2019-03-31 by the reprex package (v0.2.1)

Session info ``` r devtools::session_info() #> ─ Session info ────────────────────────────────────────────────────────── #> setting value #> version R version 3.5.1 (2018-07-02) #> os macOS 10.14.3 #> system x86_64, darwin15.6.0 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/New_York #> date 2019-03-31 #> #> ─ Packages ────────────────────────────────────────────────────────────── #> package * version date lib #> assertthat 0.2.1 2019-03-21 [1] #> backports 1.1.3 2018-12-14 [1] #> base64enc 0.1-3 2015-07-28 [1] #> callr 3.0.0 2018-08-24 [1] #> cli 1.1.0 2019-03-19 [1] #> codetools 0.2-15 2016-10-05 [2] #> crayon 1.3.4 2017-09-16 [1] #> debugme 1.1.0 2017-10-22 [1] #> desc 1.2.0 2019-03-29 [1] #> devtools 2.0.1 2018-10-26 [1] #> digest 0.6.18 2018-10-10 [1] #> evaluate 0.13 2019-02-12 [1] #> foreach 1.4.4 2017-12-12 [1] #> fs 1.2.7 2019-03-19 [1] #> glmmLasso 1.5.1 2017-05-06 [1] #> glmnet 2.0-16 2018-04-02 [1] #> glue 1.3.1 2019-03-13 [1] #> highr 0.8 2019-03-20 [1] #> htmltools 0.3.6 2017-04-28 [1] #> iterators 1.0.10 2018-07-13 [1] #> knitr 1.22 2019-03-08 [1] #> lattice 0.20-35 2017-03-25 [2] #> lme4 1.1-18-1 2018-08-17 [1] #> lmmen 1.0 2018-12-21 [1] #> lmmlasso 0.1-2 2011-04-15 [1] #> magrittr 1.5 2014-11-22 [1] #> MASS 7.3-50 2018-04-30 [2] #> Matrix 1.2-14 2018-04-13 [2] #> memoise 1.1.0 2017-04-21 [1] #> minqa 1.2.4 2014-10-09 [1] #> mvtnorm 1.0-8 2018-05-31 [1] #> nlme 3.1-137 2018-04-07 [1] #> nloptr 1.2.1 2018-10-03 [1] #> pkgbuild 1.0.2 2018-10-16 [1] #> pkgload 1.0.2 2018-10-29 [1] #> prettyunits 1.0.2 2015-07-13 [1] #> processx 3.2.0.9000 2018-11-02 [1] #> ps 1.2.1 2018-11-06 [1] #> quadprog 1.5-5 2013-04-17 [1] #> R6 2.4.0 2019-02-14 [1] #> Rcpp 1.0.1 2019-03-17 [1] #> remotes 2.0.2 2018-10-30 [1] #> rlang 0.3.3 2019-03-29 [1] #> rmarkdown 1.11.6 2019-02-21 [1] #> rprojroot 1.3-2 2018-01-03 [1] #> sessioninfo 1.1.1 2018-11-05 [1] #> stringi 1.4.3 2019-03-12 [1] #> stringr 1.4.0 2019-02-10 [1] #> testthat 2.0.1 2018-10-13 [1] #> usethis 1.4.0.9000 2019-03-31 [1] #> withr 2.1.2 2018-03-15 [1] #> xfun 0.5 2019-02-20 [1] #> yaml 2.2.0 2018-07-25 [1] #> source #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> Github (r-lib/desc@c860e7b) #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> CRAN (R 3.5.2) #> CRAN (R 3.5.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> Github (tidyverse/glue@f356a12) #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.2) #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> local #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> Github (r-pkgs/processx@8374340) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.2) #> CRAN (R 3.5.2) #> CRAN (R 3.5.0) #> CRAN (R 3.5.1) #> Github (rstudio/rmarkdown@bbd0786) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.2) #> CRAN (R 3.5.0) #> Github (r-lib/usethis@c5f9b3e) #> CRAN (R 3.5.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> #> [1] /Users/yonis/Library/R/3.5/library #> [2] /Library/Frameworks/R.framework/Versions/3.5/Resources/library ```
verburgniels commented 4 years ago

Dear Jonathan Sidi,

I am having the same error with cv.lmmlasso as in this thread (https://github.com/yonicd/lmmen/issues/3):

cv.lmmlasso(dat.cv,lambda = seq(0, 500, 5)) Error in .checkinput(match.call(), parent.frame()) : missing values in "penalized" argument

Below the two configurations I tried:

R version 3.3.2 (2016-10-31) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: macOS 10.15.4

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

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

other attached packages: [1] devtools_2.2.2 usethis_1.5.1 lmmen_1.0 lmmlasso_0.1-2 penalized_0.9-51 survival_2.39-5 miscTools_0.6-26 emulator_1.2-20 [9] mvtnorm_1.0-7 lme4_1.1-15 glmnet_2.0-13 foreach_1.5.0 Matrix_1.2-7.1

loaded via a namespace (and not attached): [1] Rcpp_0.12.16 nloptr_1.2.2.1 remotes_2.1.1 prettyunits_1.1.1 iterators_1.0.12 tools_3.3.2 testthat_2.3.2
[8] digest_0.6.25 pkgbuild_1.0.6 pkgload_1.0.2 memoise_1.1.0 nlme_3.1-128 lattice_0.20-34 rlang_0.4.5
[15] cli_2.0.2 rstudioapi_0.11 glmmLasso_1.5.1 withr_2.1.2 desc_1.2.0 fs_1.4.1 rprojroot_1.3-2
[22] grid_3.3.2 glue_1.4.0 R6_2.4.1 processx_3.4.2 fansi_0.4.1 sessioninfo_1.1.1 minqa_1.2.4
[29] magrittr_1.5 callr_3.4.3 backports_1.1.6 codetools_0.2-15 ps_1.3.2 ellipsis_0.3.0 MASS_7.3-45
[36] splines_3.3.2 assertthat_0.2.1 quadprog_1.5-5 crayon_1.3.4

———————

R version 3.6.3 (2020-02-29) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Catalina 10.15.4

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_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages: [1] lmmen_1.0 lmmlasso_0.1-2 penalized_0.9-51 survival_3.1-8 miscTools_0.6-26 emulator_1.2-20 mvtnorm_1.1-0

loaded via a namespace (and not attached): [1] Rcpp_1.0.4.6 splines_3.6.3 MASS_7.3-51.5 statmod_1.4.34 lattice_0.20-38 quadprog_1.5-8 foreach_1.5.0 minqa_1.2.4
[9] tools_3.6.3 grid_3.6.3 glmnet_3.0-2 nlme_3.1-144 iterators_1.0.12 lme4_1.1-23 digest_0.6.25 Matrix_1.2-18
[17] nloptr_1.2.2.1 codetools_0.2-16 shape_1.4.4 glmmLasso_1.5.1 compiler_3.6.3 boot_1.3-24

Could you help me?

Kind regards,

Niels Verburg

yonicd commented 4 years ago

lmmlasso is not a well maintained package. It's DESCRIPTION file is not written well at all and the user needs to manually load a lot of other packages to get it to somewhat work, eg penalized and emulator.

I still cannot run the simple reproducible example from above when directly calling lmmlasso.

cv.lmmlasso is just a wrapper on that package.

I would suggest you open an issue for that package.

Thanks