simsem / semTools

Useful tools for structural equation modeling
75 stars 36 forks source link

Error in `reliability()`: "$ operator not defined for this S4 class" #63

Closed DaniMori closed 5 years ago

DaniMori commented 5 years ago

I was preparing a psychometrics session on a masterclass I was giving today, and when calling reliability() on a lavaan object I was getting:

reliability(object)
Error: $ operator not defined for this S4 class

Since I tracked down the solution and there seemed to be a problem with the dependencies, I tried updating to the development version in Github with devtools::install_github(). It seemed to be working for me, but during the session, most of the students couldn't run the function because they got that same error, though they installed the development version following my indications (funny though, it worked for some of them). This happened both in R 3.6.3, R3.6.1, and older versions, in Windows and Mac laptops.

The problem seems to be in function getThresholds(), which should be calling lavaan::fitted(), but apparently is calling stats::fitted() instead. Would it be possible to make a quick fix for this or something? It would be much appreciated, since now we are stuck with this problem and there doesn't seem to be a straightforward solution.

Thanks!

leomartinsjf commented 5 years ago

Dear DaniMori

I had the same problem here.

The problem was solved upgrading semTools and lavaan to the most recent development version

Em sex, 8 de nov de 2019 às 18:26, DaniMori notifications@github.com escreveu:

I was preparing a psychometrics session on a masterclass I was giving today, and when calling reliability() on a lavaan object I was getting:

reliability(object) Error: $ operator not defined for this S4 class

Since I tracked down the solution and there seemed to be a problem with the dependencies, I tried updating to the development version in Github with devtools::install:github(). It seemed to be working for me, but during the session, most of the students couldn't run the function because they got that same error, though they installed the development version following my indications (funny though, it worked for some of them). This happened both in R 3.6.3, R3.6.1, and older version, in Windows and Mac laptops.

The problem seems to be in function getThresholds(), which should be calling lavaan::fitted(), but apparently is calling stats::fitted() instead. Would it be possible to make a quick fix for this or something? It would be much appreciated, since now we are stuck with this problem and there doesn't seem to be a straightforward solution.

Thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/simsem/semTools/issues/63?email_source=notifications&email_token=ABFZ2J5RZ3ZET6WA7THSXEDQSXKQPA5CNFSM4JK65BVKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HYCIDPQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFZ2J4Q3QT4LJ3ED4PJNTTQSXKQPANCNFSM4JK65BVA .

-- Sent from Gmail Mobile

TDJorgensen commented 5 years ago

I expect @leomartinsjf is right, because getThresholds() was updated precisely to address the fitted() issue: https://github.com/simsem/semTools/commit/b5a9a759fc132139235c7ac2dc28ae920202fd9b (see line 882 for the solution)

After you install the development versions of lavaan and semTools:

install.packages("lavaan", repos = "http://www.da.ugent.be", type = "source")
devtools::install_github("simsem/semTools/semTools")

Restart R, load semTools, and check sessionInfo() to make sure lavaan 0.6-6.1496 and semTools 0.5-2.910 were successfully installed. If you are still getting that error, please (privately, if you prefer) send me enough of your data along with a short R script to reproduce the error, so that I can track down the problem.

DaniMori commented 5 years ago

I'm sorry but I haven't been able to reproduce the error, as it is corrected once I install the development version from Github. I'll suggest the students installing the development version from Github as well; let's see if that sorts it out. Thanks!

TDJorgensen commented 5 years ago

I'll suggest the students installing the development version from Github as well; let's see if that sorts it out.

Make sure they install the development version of lavaan first, otherwise semTools might not install. That might be why some students are getting errors that you do not.

DaniMori commented 5 years ago

Alright, thanks a lot! For me it worked after installing the dev version of semTools, both before and after installing the lavaan version. If there are more cases that do not get solved with this I'll provide a reprex...