psychbruce/bruceR

When I want to generate results of HLM, I meet one problem:

LinJing96 opened this issue · 12 comments

Platform: Mac latest
R Version: 4.0.2 (2020-06-22)
bruceR Version: latest (installed via install_github())

First of all, thanks for developing this useful and powerful package!
Here is my code:
`

install packages

library(carData)
library(car)
library(haven)
library("lme4")
library (haven)
library(tidyverse)
library(RColorBrewer)
library(lmerTest)
library (dplyr)
library(ggplot2)
library(readxl)
library("ggpubr")
library(compareGroups)
library(lmerTest)
library(RLRsim)
library(mice)
library(dplyr)
library(lattice)
library(grid)
library(DMwR)
library(bootstrap)
library(interactions)
library(jtools)
library(devtools)
library(usethis)
library(rJava)
library(reghelper)
library(pacman)
library(interactions)
library(bbmle)
library(xlsx)
library(bruceR)

One model to illustrate this problem

lmm.fit2=lmer(trust ~(1|countrycode)+gini+gender+education+logGDP+Scarcity+social_class+age,data=gini_hlmanalysis1,REML=F)
HLM_summary(lmm.fit2)
`

Here is the studio feedback:

image

Thanks for your kindly reply!

Lin

Hi, code checks on my computer and CRAN both have not reported this bug. Please try this code: stats::anova(lmm.fit2) and see whether it goes well.

Actually, I can successfully run stats::anova(lmm.fit2) with no errors, but still can not use HLM_summary().
And I really appreciate that if you can explain how to use package"bruceR" function to report the outcome of Slope (L2) variance (τ11) and Intercept-slope (L2) covariance (τ01) in HLM.

Many thanks for your assistance!

Lin

Please also try some examples using print_table(), such as print_table(lmm.fit2), to see whether print_table() runs well on your computer. This error is related to the fail of print_table() but not HLM_summary() on your computer. If you still cannot run these functions, please update R and all R packages to their latest version! Note that the latest version of R is NOT 4.0.2 (2020-06-22) BUT 4.1.2 (2021-11-01)! Your R version is definitely out of date, which might account for these errors.

Both HLM_summary() and model_summary() in bruceR report the results of random effects of an HLM model (the variance). I suggest using model_summary() because it can report a list of multiple models and save the table to MS Word (.doc). To test the significance of the random effects, please use the function lmerTest::rand() or lmerTest::ranova().

PS: HLM_summary() does not report covariance, but both summary() (the default function in R for reporting models) and model_summary() (the bruceR function for reporting models in a tidy way) do report the variance and covariance of random effects of multilevel models (HLM).

Please read the help pages of the functions you don't know how to use.
Please also read these two articles on Zhihu:
https://zhuanlan.zhihu.com/p/281150493
https://zhuanlan.zhihu.com/p/432931518

Thank you so much for sharing!
First, I updated my R to R version 4.1.2 (2021-11-01) to ensure that the problem is not caused by the fact that R is not the latest version. At the same time, I browsed your Zhihu post link to make sure that all packages are installed and all packages are now up-to-date.
Next, I tried the print_table function, and the same problem occurred:
image

But I found that I ran the model_summary() function (which is really useful!) without any problems. I can report the parameters I need. Thank you very much for sharing the covariance part.

I suspect that my question may be a very niche question, but your patient answer makes me very warm, thank you again!

Lin

It still seems strange. Please find that even the CRAN released version 0.8.0 did not report any bug related to print_table(), see CRAN Package Check Results for Package bruceR.

By the way, I have re-checked the bug you reported yesterday, and I find that for a data frame with only one column, print_table() does not work and reports a similar error message as yours. But actually in your code, the to-be-printed data frame contained more than one column. Whatever, in the latest commit to GitHub (hours ago), I fixed the bug related to one-column data frame for print_table().

Please update to this version and check whether your problem is also fixed. I suggest doing so because many functions of bruceR rely on print_table(), which is basic and very important.

The reason why model_summary() runs well is that this function does not call print_table() to print the table. So the problem is still with print_table(), and indeed, the rep() function. If times < 0, then this error will be reported.

Let me know whether the problem will be fixed after you update to the latest bruceR GitHub version. Thanks.

This problem is also possibly relevant to another change in 0.8.0. To test this possibility, please also check whether the following code runs well on your computer:

rep("a", 3)
nchar("abc", type="width")
rep_char("a", 3)

You may copy and paste the output.

According to your suggestion, I removed the package first by using remove.packages("bruceR") and then passed devtools::install_github("psychbruce/bruceR", force=TRUE, upgrade=FALSE) to install your latest version in github.
However, unfortunately, the problems still exist, and I also copied your code and found that everything works well.
For specific error information and operating information, please see the following picture:
image

I also refer to CRAN, but it is very strange that I can't find the problem why my laptop software doesn't work.
I also realize that this statement is very important to the presented results of this package, so I also hope to use this powerful package better by solving this problem.
Thanks again!

I have just submitted a new update to GitHub where I tried best to figure it out. Please again install the latest version and see if the problem disappears. Note that in the last comment your pictures indicate that your installed version of bruceR was not the new version I updated this morning, because the output format of GLM_summary() and HLM_summary() have been improved in that update. So make sure that your installed version is exactly the latest. Below are what you would obtain with the latest bruceR:

library(bruceR)
library(lmerTest)
m=lmer(Reaction ~ Days + (Days | Subject), data=sleepstudy)
HLM_summary(m)

Hierarchical Linear Model (HLM)
(also known as) Linear Mixed Model (LMM)
(also known as) Multilevel Linear Model (MLM)

Model Information:
Formula: Reaction ~ Days + (Days | Subject)
Level-1 Observations: N = 180
Level-2 Groups/Clusters: Subject, 18

Model Fit:
AIC = 1755.628
BIC = 1774.786
R_(m)² = 0.27865  (Marginal R²: fixed effects)
R_(c)² = 0.79922  (Conditional R²: fixed + random effects)
Omega² = 0.82590  (= 1 - proportion of unexplained variance)

ANOVA Table:
───────────────────────────────────────────────────────────
          Sum Sq   Mean Sq  NumDF  DenDF      F      p     
───────────────────────────────────────────────────────────
Days    30030.94  30030.94   1.00  17.00  45.85  <.001  ***
───────────────────────────────────────────────────────────

Fixed Effects:
Unstandardized Coefficients (b or γ):
Outcome Variable: Reaction
────────────────────────────────────────────────────────────────────────────
                   b/γ     S.E.      t    df      p          [95% CI of b/γ]
────────────────────────────────────────────────────────────────────────────
(Intercept)    251.405  (6.825)  36.84  17.0  <.001  ***  [237.006, 265.804]
Days            10.467  (1.546)   6.77  17.0  <.001  ***  [  7.206,  13.729]
────────────────────────────────────────────────────────────────────────────
'df' is estimated by Satterthwaite approximation.

Standardized Coefficients (β):
Outcome Variable: Reaction
──────────────────────────────────────────────────────────────
            β     S.E.     t    df      p        [95% CI of β]
──────────────────────────────────────────────────────────────
Days    0.535  (0.079)  6.77  17.0  <.001  ***  [0.368, 0.702]
──────────────────────────────────────────────────────────────

Random Effects:
────────────────────────────────────────────────
  Cluster   K    Parameter     Variance      ICC
────────────────────────────────────────────────
  Subject    18  (Intercept)  612.10016  0.48309
                 Days          35.07171         
  Residual                    654.94001         
────────────────────────────────────────────────

Hey, please let me know whether the latest GitHub version has no error on your computer. I hope all is well.

I'm sorry, because I have some work in the laboratory, so I didn't reply to you immediately. I'm sorry about that...

I once again removed the existing bruceR package and installed it through the devtools::install_github("psychbruce/bruceR", force=TRUE, upgrade=FALSE) code, but it was unsuccessful (I don't know if it is due to network issues or GitHub is not stable at night).
So, I downloaded psychbruce-bruceR-ffa6a68.tar.gz through the link and installed it locally.

I am not quite sure that my BruceR package is the latest version?
image

At the same time, my error never appeared again, and now my model of running HLM is the result as shown in the figure below:
image
image

This problem was successfully solved! Thank you again for sharing and helping me solve this problem completely!
You are so sincere and kind, I am very grateful about your all the comments!

Lin

Thanks! It is great that this problem finally has been fixed. Yes, the web access to GitHub sometimes/usually/often fails in "some" areas. So... I will close this issue.