tbates / umx

Making Structural Equation Modeling (SEM) in R quick & powerful
https://tbates.github.io/
44 stars 17 forks source link

umx functions not detecting tibble input #141

Closed lf-araujo closed 3 years ago

lf-araujo commented 3 years ago

Hi Tim,

If this is not the place for support, please close.

First time working with twin data, and looking into using umx, as it is pretty well designed. In my attempt of analysing a GxE model, where parenting style influences one personality aspect, I get stuck in making umxGxE detect factors for the selDVs. Below is the minimal example:

dt <- ZA6701_en_person_wid1_v4.0.0 %>%
  filter(per0404t == "0: self-confident" | per0404t == 1,
         per0404u == "0: self-confident" | per0404u == 1) %>% 
  transmute(per0404_1 = factor(per0404t,ordered = T),
         per0404_2 = factor(per0404u, ordered = T),
         zyg0102 = zyg0102,
         par0104_1 = par0104t,
         par0104_2 = par0104u)

mzData  <- subset(dt, zyg0102 == "1: monozygotic")
dzData  <- subset(dt, zyg0102 == "2: dizygotic")

umxGxE( selDVs = 'per0404',
       selDefs = 'par0104',
       sep = '_',
       mzData = mzData,
       dzData = dzData)

This errs with:

Error in xmu_twin_check(selDVs = selDVs, dzData = dzData, mzData = mzData,  : 
  variables must be integer, numeric or (usually ordered) factor. The following are not: 'per0404_1' and 'per0404_2'

Clear and informative, however:

image

So, the variable is an ordered factor for one personality trait subtest. I should be doing something wrong, but I can't figure it out?

Thanks

My sessioninfo:

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-solus-linux-gnu (64-bit)
Running under: Solus 4.1 Fortitude

Matrix products: default
BLAS/LAPACK: /usr/lib64/haswell/libopenblas_haswellp-r0.3.9.so

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

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

other attached packages:
 [1] forcats_0.5.0         stringr_1.4.0         dplyr_1.0.2           purrr_0.3.4          
 [5] readr_1.4.0           tidyr_1.1.2           tibble_3.0.4          tidyverse_1.3.0      
 [9] ggplot2_3.3.2         naniar_0.6.0          visdat_0.5.3          here_0.1             
[13] summarytools_0.9.6    ProjectTemplate_0.9.2 umx_4.0.0             OpenMx_2.18.1        

loaded via a namespace (and not attached):
 [1] httr_1.4.2         jsonlite_1.7.1     modelr_0.1.8       assertthat_0.2.1   highr_0.8         
 [6] stats4_3.6.3       pander_0.6.3       cellranger_1.1.0   yaml_2.2.1         pillar_1.4.6      
[11] backports_1.2.0    lattice_0.20-38    glue_1.4.2         digest_0.6.27      RColorBrewer_1.1-2
[16] pryr_0.1.4         checkmate_2.0.0    rvest_0.3.6        colorspace_1.4-1   MuMIn_1.43.17     
[21] cowplot_1.1.0      htmltools_0.5.0    Matrix_1.2-18      plyr_1.8.6         pkgconfig_2.0.3   
[26] broom_0.7.2        haven_2.3.1        magick_2.5.2       DiagrammeR_1.0.6.1 xtable_1.8-4      
[31] scales_1.1.1       generics_0.1.0     ellipsis_0.3.1     withr_2.3.0        cli_2.1.0         
[36] magrittr_1.5       crayon_1.3.4       readxl_1.3.1       evaluate_0.14      fansi_0.4.1       
[41] fs_1.5.0           nlme_3.1-144       MASS_7.3-51.5      xml2_1.3.2         rapportools_1.0   
[46] tools_3.6.3        hms_0.5.3          lifecycle_0.2.0    matrixStats_0.57.0 munsell_0.5.0     
[51] reprex_0.3.0       compiler_3.6.3     rlang_0.4.8        grid_3.6.3         polycor_0.7-10    
[56] rstudioapi_0.11    htmlwidgets_1.5.2  visNetwork_2.0.9   rmarkdown_2.5      tcltk_3.6.3       
[61] base64enc_0.1-3    gtable_0.3.0       codetools_0.2-16   DBI_1.1.0          R6_2.5.0          
[66] lubridate_1.7.9    knitr_1.30         rprojroot_1.3-2    stringi_1.5.3      parallel_3.6.3    
[71] Rcpp_1.0.5         vctrs_0.3.4        dbplyr_2.0.0       tidyselect_1.1.0   xfun_0.19    
lf-araujo commented 3 years ago

Hi Tim!

Was pulling my hair as I couldn't identify a problem with my dataset! Turns out, umx does not support tibbles. A simple as.data.frame solved the issue.

tbates commented 3 years ago

Hi I guessed that was the answer but didn't have time to have a look this week. Glad you've found the sanity of R's perfectly good data frame!

I had this problem last year with another colleague who moved to the **** tidy verse. I guess I'll code around it

Cheers T

tbates commented 3 years ago

hi @lf-araujo, Thanks for the report again.

I think I have fixed (one possible cause) of this with the different signature and drop=FALSE default of tibbles. If you update with devtools::install_github("tbates/umx") you could test?

lf-araujo commented 3 years ago

Thanks for this Tim,

I think it is not there yet, working code still fails:

[cid:83d2a1a3-a9b8-4b2a-8663-83cb3ee633e2]


From: Tim Bates notifications@github.com Sent: Monday, 30 November 2020 8:36 PM To: tbates/umx umx@noreply.github.com Cc: lf_araujo luis.nando@gmail.com; Mention mention@noreply.github.com Subject: Re: [tbates/umx] umx functions not detecting tibble input (#141)

hi @lf-araujohttps://github.com/lf-araujo, Thanks for the report again.

I think I have fixed (one possible cause) of this with the different signature and drop=FALSE default of tibbles. If you update with devtools::install_github("tbates/umx") you could test?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/tbates/umx/issues/141#issuecomment-736119538, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACNLSLXL4MLUGLNIBP5PGGLSSQT6DANCNFSM4UCW5O5Q.

tbates commented 3 years ago

hmm.. fixed a typo in the proposed fix which would have lead to a run-time error...

lf-araujo commented 3 years ago

Hi Tim,

Happy to help debug, it's still not there yet. Reinstalled the packaged, restarted session and now for (working) code:


dt$perextr1  <-  dt$perextr2  <-  as.numeric(dt$perextr)
dt$parcontt1  <-  dt$parcontt2  <-  as.numeric(dt$parcontt)

G2 <- umxGxE(data = dt,
             zyg = "zyg0102",
              mzData = "1: monozygotic",
             dzData = "2: dizygotic",
             selDVs = "perextr",
             selDefs = "parcontt",
             sep = "")

I get:

image

For code:

mzData  <- subset(dt, zyg0102 == "1: monozygotic")
dzData  <- subset(dt, zyg0102 == "2: dizygotic")

umxGxE( selDVs = "perextr",
       selDefs = "parcontt",
       sep = '',
       mzData = mzData,
       dzData = dzData)

I get:

image

When I add tryHard:

image

tbates commented 3 years ago

Fixed now, I believe

lf-araujo commented 3 years ago

Yay! Working as expected! Thanks for this!