Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable Labels from Hmisc and lm function R3.5.0 #93

Open
bangecon opened this issue May 30, 2018 · 4 comments
Open

Variable Labels from Hmisc and lm function R3.5.0 #93

bangecon opened this issue May 30, 2018 · 4 comments

Comments

@bangecon
Copy link

When I updated to R 3.5.0, several lm and glm command lines started giving an error, "Error: x must be a numeric or a character vector." Running the same lines in R 3.4.4 did not give that command. I was able to determine that these commands ran fine in R 3.5.0 if I ran them before assigning variable labels using the label() command, but not after assigning the labels. My short run solution is "don't use the labels." But descriptive English labels are nice to have when you have a lot of variables.

@couthcommander
Copy link
Collaborator

Can you provide an example? The following works for me.

library(Hmisc)
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
label(group) <- "Treatment Group"
weight <- c(ctl, trt)
summary(lm(weight ~ group))

class(group) returns [1] "labelled" "factor"

@bangecon
Copy link
Author

bangecon commented May 31, 2018 via email

@couthcommander
Copy link
Collaborator

Reinstalling and restarting R is always a great place to start. My first thought was that you might have an additional package loaded interfering with behaviour. For instance, the haven package creates a labelled class that would likely cause problems if loaded after Hmisc.

@spgarbet
Copy link

Here's an example with an Hmisc dataset that was labelled showing the maven problem.

> load("data/pbc.rda")
> head(pbc)
  bili albumin stage protime    sex fu.days      age spiders hepatom ascites alk.phos   sgot chol
1 14.5    2.60     4    12.2 female     400 58.76523 present present present   1718.0 137.95  261
2  1.1    4.14     3    10.6 female    4500 56.44627 present present  absent   7394.8 113.52  302
3  1.4    3.48     4    12.0   male    1012 70.07255  absent  absent  absent    516.0  96.10  176
4  1.8    2.54     4    10.3 female    1925 54.74059 present present  absent   6121.8  60.63  244
5  3.4    3.53     3    10.9 female    1504 38.10541 present present  absent    671.0 113.15  279
6  0.8    3.98     3    11.0 female    2503 66.25873  absent present  absent    944.0  93.00  248
  trig platelet            drug status                          edema copper
1  172      190         placebo      1 edema despite diuretic therapy    156
2   88      221         placebo      0                       no edema     54
3   55      151         placebo      1     edema, no diuretic therapy    210
4   92      183         placebo      1     edema, no diuretic therapy     64
5   72      136 D-penicillamine      0                       no edema    143
6   63       NA D-penicillamine      1                       no edema     50
> library(haven)
> head(pbc)
Error: `x` and `labels` must be same type
> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3

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

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

other attached packages:
[1] haven_1.1.2

loaded via a namespace (and not attached):
 [1] compiler_3.4.4  magrittr_1.5    hms_0.4.2       tools_3.4.4     pillar_1.3.0   
 [6] rstudioapi_0.7  tibble_1.4.2    crayon_1.3.4    Rcpp_0.12.18    forcats_0.3.0  
[11] pkgconfig_2.0.2 rlang_0.2.2    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants