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

fix scaled.test= issue reported by Njal #365

Merged
merged 3 commits into from
Jun 28, 2024
Merged

Conversation

TDJorgensen
Copy link
Contributor

No description provided.

@TDJorgensen
Copy link
Contributor Author

TDJorgensen commented Jun 28, 2024

The third commit is an unrelated issue, revealed by a reprex from @ambhangale. Below is a condensed reprex I made by dump()ing a list that can be run as a call to lavaan(). If you debug(lav_test_satorra_bentler), which is commented out below, you'll see the trace.UGamma2 is slightly negative (-1.718735e-30). Division on Line 353 yields NaN, which causes an error when subsequently checking whether scaling.factor < 0. So I wrapped that check in isTRUE() in the third commit of this PR (also added a similar check for a).

library(lavaan)

lavCall <-
list(quote(lavaan::lavaan), model = c("V1_ij ~~ var1*V1_ij", 
"V1_ji ~~ var1*V1_ji", "V1_ij ~~ V1_ji", "V1_ij ~~ inter12*V2_ji", 
"V2_ij ~~ inter12*V1_ji", "V1_ij ~~ intra12*V2_ij", "V1_ji ~~ intra12*V2_ji", 
"V1_ij ~~ inter13*V3_ji", "V3_ij ~~ inter13*V1_ji", "V1_ij ~~ intra13*V3_ij", 
"V1_ji ~~ intra13*V3_ji", "V2_ij ~~ var2*V2_ij", "V2_ji ~~ var2*V2_ji", 
"V2_ij ~~ V2_ji", "V2_ij ~~ inter23*V3_ji", "V3_ij ~~ inter23*V2_ji", 
"V2_ij ~~ intra23*V3_ij", "V2_ji ~~ intra23*V3_ji", "V3_ij ~~ var3*V3_ij", 
"V3_ji ~~ var3*V3_ji", "V3_ij ~~ V3_ji"), data = structure(list(
    sample.cov = list(dyad = structure(c(0.83942920987165004, 
    0.082310916654182303, 0.53078002700026194, 0.17111845289629099, 
    0.84295103557800699, 0.15547370175171801, 0.082310916654182303, 
    0.83942920987165004, 0.17111845289629099, 0.53078002700026194, 
    0.15547370175171801, 0.84295103557800699, 0.53078002700026194, 
    0.17111845289629099, 0.91646420978250898, 0.24196418031814601, 
    0.72854008417879601, 0.259005958961882, 0.17111845289629099, 
    0.53078002700026194, 0.24196418031814601, 0.91646420978250898, 
    0.259005958961882, 0.72854008417879601, 0.84295103557800699, 
    0.15547370175171801, 0.72854008417879601, 0.259005958961882, 
    1.5743455449616499, 0.131636780532398, 0.15547370175171801, 
    0.84295103557800699, 0.259005958961882, 0.72854008417879601, 
    0.131636780532398, 1.5743455449616499), dim = c(6L, 6L), dimnames = list(
        c("V1_ij", "V1_ji", "V2_ij", "V2_ji", "V3_ij", "V3_ji"
        ), c("V1_ij", "V1_ji", "V2_ij", "V2_ji", "V3_ij", "V3_ji"
        )))), sample.mean = NULL, sample.nobs = c(dyad = 150L), 
    NACOV = list(dyad = structure(c(0.7519987098077161, 0.070639743859327184, 
    0.3686387448604122, 0.08456664292769181, 0.6291298752360398, 
    0.082160543734003999, 0.7519987098077161, 0.08456664292769181, 
    0.3686387448604122, 0.082160543734003999, 0.6291298752360398, 
    0.18184042013485971, 0.049313540677085058, 0.28054918018006386, 
    0.081488221607049299, 0.18184042013485971, 0.081488221607049299, 
    0.28054918018006386, 0.50004076564884603, 0.08501249686043845, 
    0.50004076564884603, 0.070639743859327184, 0.43862607706859663, 
    0.055339932823256478, 0.17951927189370645, 0.0895211236385937, 
    0.30433045524533192, 0.070639743859327184, 0.17951927189370645, 
    0.055339932823256478, 0.30433045524533192, 0.0895211236385937, 
    0.04939275518401489, 0.061808322116878089, 0.071903603735502045, 
    0.09625062270646445, 0.04939275518401489, 0.09625062270646445, 
    0.071903603735502045, 0.079274593232901175, 0.1550602224337346, 
    0.079274593232901175, 0.3686387448604122, 0.055339932823256478, 
    0.44991509921052808, 0.1023339598426367, 0.37953496591919467, 
    0.066935968922631012, 0.3686387448604122, 0.1023339598426367, 
    0.44991509921052808, 0.066935968922631012, 0.37953496591919467, 
    0.40293060644210316, 0.13520768361925051, 0.41020607930214908, 
    0.12982880809936412, 0.40293060644210316, 0.12982880809936412, 
    0.41020607930214908, 0.37261738700895697, 0.081192489287687367, 
    0.37261738700895697, 0.08456664292769181, 0.17951927189370645, 
    0.1023339598426367, 0.27723858519170896, 0.10547127914304549, 
    0.17019643143944993, 0.08456664292769181, 0.27723858519170896, 
    0.1023339598426367, 0.17019643143944993, 0.10547127914304549, 
    0.13459352354070914, 0.20413600328515225, 0.12569186586505759, 
    0.21768117217038549, 0.13459352354070914, 0.21768117217038549, 
    0.12569186586505759, 0.12322564164927195, 0.12429149450933809, 
    0.12322564164927195, 0.6291298752360398, 0.0895211236385937, 
    0.37953496591919467, 0.10547127914304549, 0.89216297594404648, 
    0.08818290571782815, 0.6291298752360398, 0.10547127914304549, 
    0.37953496591919467, 0.08818290571782815, 0.89216297594404648, 
    0.24623751962418183, 0.087754354501343584, 0.50678335594127677, 
    0.13658430873734989, 0.24623751962418183, 0.13658430873734989, 
    0.50678335594127677, 1.0621425645235005, 0.14452900352790468, 
    1.0621425645235005, 0.082160543734003999, 0.30433045524533192, 
    0.066935968922631012, 0.17019643143944993, 0.08818290571782815, 
    0.46534778309655367, 0.082160543734003999, 0.17019643143944993, 
    0.066935968922631012, 0.46534778309655367, 0.08818290571782815, 
    0.070586013462458408, 0.071876100522523231, 0.10135860282119952, 
    0.21775218356743589, 0.070586013462458408, 0.21775218356743589, 
    0.10135860282119952, 0.12707099045735143, 0.48454537842500878, 
    0.12707099045735143, 0.7519987098077161, 0.070639743859327184, 
    0.3686387448604122, 0.08456664292769181, 0.6291298752360398, 
    0.082160543734003999, 0.7519987098077161, 0.08456664292769181, 
    0.3686387448604122, 0.082160543734003999, 0.6291298752360398, 
    0.18184042013485971, 0.049313540677085058, 0.28054918018006386, 
    0.081488221607049299, 0.18184042013485971, 0.081488221607049299, 
    0.28054918018006386, 0.50004076564884603, 0.08501249686043845, 
    0.50004076564884603, 0.08456664292769181, 0.17951927189370645, 
    0.1023339598426367, 0.27723858519170896, 0.10547127914304549, 
    0.17019643143944993, 0.08456664292769181, 0.27723858519170896, 
    0.1023339598426367, 0.17019643143944993, 0.10547127914304549, 
    0.13459352354070914, 0.20413600328515225, 0.12569186586505759, 
    0.21768117217038549, 0.13459352354070914, 0.21768117217038549, 
    0.12569186586505759, 0.12322564164927195, 0.12429149450933809, 
    0.12322564164927195, 0.3686387448604122, 0.055339932823256478, 
    0.44991509921052808, 0.1023339598426367, 0.37953496591919467, 
    0.066935968922631012, 0.3686387448604122, 0.1023339598426367, 
    0.44991509921052808, 0.066935968922631012, 0.37953496591919467, 
    0.40293060644210316, 0.13520768361925051, 0.41020607930214908, 
    0.12982880809936412, 0.40293060644210316, 0.12982880809936412, 
    0.41020607930214908, 0.37261738700895697, 0.081192489287687367, 
    0.37261738700895697, 0.082160543734003999, 0.30433045524533192, 
    0.066935968922631012, 0.17019643143944993, 0.08818290571782815, 
    0.46534778309655367, 0.082160543734003999, 0.17019643143944993, 
    0.066935968922631012, 0.46534778309655367, 0.08818290571782815, 
    0.070586013462458408, 0.071876100522523231, 0.10135860282119952, 
    0.21775218356743589, 0.070586013462458408, 0.21775218356743589, 
    0.10135860282119952, 0.12707099045735143, 0.48454537842500878, 
    0.12707099045735143, 0.6291298752360398, 0.0895211236385937, 
    0.37953496591919467, 0.10547127914304549, 0.89216297594404648, 
    0.08818290571782815, 0.6291298752360398, 0.10547127914304549, 
    0.37953496591919467, 0.08818290571782815, 0.89216297594404648, 
    0.24623751962418183, 0.087754354501343584, 0.50678335594127677, 
    0.13658430873734989, 0.24623751962418183, 0.13658430873734989, 
    0.50678335594127677, 1.0621425645235005, 0.14452900352790468, 
    1.0621425645235005, 0.18184042013485971, 0.04939275518401489, 
    0.40293060644210316, 0.13459352354070914, 0.24623751962418183, 
    0.070586013462458408, 0.18184042013485971, 0.13459352354070914, 
    0.40293060644210316, 0.070586013462458408, 0.24623751962418183, 
    0.83441832690910833, 0.26387932133116193, 0.53346771385066483, 
    0.21469795186997137, 0.83441832690910833, 0.21469795186997137, 
    0.53346771385066483, 0.35411968522330683, 0.10265733856742666, 
    0.35411968522330683, 0.049313540677085058, 0.061808322116878089, 
    0.13520768361925051, 0.20413600328515225, 0.087754354501343584, 
    0.071876100522523231, 0.049313540677085058, 0.20413600328515225, 
    0.13520768361925051, 0.071876100522523231, 0.087754354501343584, 
    0.26387932133116193, 0.53474510334027081, 0.20059122237529506, 
    0.28568347434494212, 0.26387932133116193, 0.28568347434494212, 
    0.20059122237529506, 0.13841917528234035, 0.092973467519897879, 
    0.13841917528234035, 0.28054918018006386, 0.071903603735502045, 
    0.41020607930214908, 0.12569186586505759, 0.50678335594127677, 
    0.10135860282119952, 0.28054918018006386, 0.12569186586505759, 
    0.41020607930214908, 0.10135860282119952, 0.50678335594127677, 
    0.53346771385066483, 0.20059122237529506, 0.79693690902985548, 
    0.19076776670758322, 0.53346771385066483, 0.19076776670758322, 
    0.79693690902985548, 0.83476202682149436, 0.18284378821229735, 
    0.83476202682149436, 0.081488221607049299, 0.09625062270646445, 
    0.12982880809936412, 0.21768117217038549, 0.13658430873734989, 
    0.21775218356743589, 0.081488221607049299, 0.21768117217038549, 
    0.12982880809936412, 0.21775218356743589, 0.13658430873734989, 
    0.21469795186997137, 0.28568347434494212, 0.19076776670758322, 
    0.50514863632110496, 0.21469795186997137, 0.50514863632110496, 
    0.19076776670758322, 0.23322808966665029, 0.39374347115400748, 
    0.23322808966665029, 0.18184042013485971, 0.04939275518401489, 
    0.40293060644210316, 0.13459352354070914, 0.24623751962418183, 
    0.070586013462458408, 0.18184042013485971, 0.13459352354070914, 
    0.40293060644210316, 0.070586013462458408, 0.24623751962418183, 
    0.83441832690910833, 0.26387932133116193, 0.53346771385066483, 
    0.21469795186997137, 0.83441832690910833, 0.21469795186997137, 
    0.53346771385066483, 0.35411968522330683, 0.10265733856742666, 
    0.35411968522330683, 0.081488221607049299, 0.09625062270646445, 
    0.12982880809936412, 0.21768117217038549, 0.13658430873734989, 
    0.21775218356743589, 0.081488221607049299, 0.21768117217038549, 
    0.12982880809936412, 0.21775218356743589, 0.13658430873734989, 
    0.21469795186997137, 0.28568347434494212, 0.19076776670758322, 
    0.50514863632110496, 0.21469795186997137, 0.50514863632110496, 
    0.19076776670758322, 0.23322808966665029, 0.39374347115400748, 
    0.23322808966665029, 0.28054918018006386, 0.071903603735502045, 
    0.41020607930214908, 0.12569186586505759, 0.50678335594127677, 
    0.10135860282119952, 0.28054918018006386, 0.12569186586505759, 
    0.41020607930214908, 0.10135860282119952, 0.50678335594127677, 
    0.53346771385066483, 0.20059122237529506, 0.79693690902985548, 
    0.19076776670758322, 0.53346771385066483, 0.19076776670758322, 
    0.79693690902985548, 0.83476202682149436, 0.18284378821229735, 
    0.83476202682149436, 0.50004076564884603, 0.079274593232901175, 
    0.37261738700895697, 0.12322564164927195, 1.0621425645235005, 
    0.12707099045735143, 0.50004076564884603, 0.12322564164927195, 
    0.37261738700895697, 0.12707099045735143, 1.0621425645235005, 
    0.35411968522330683, 0.13841917528234035, 0.83476202682149436, 
    0.23322808966665029, 0.35411968522330683, 0.23322808966665029, 
    0.83476202682149436, 2.142781402732032, 0.13760969309950921, 
    2.142781402732032, 0.08501249686043845, 0.1550602224337346, 
    0.081192489287687367, 0.12429149450933809, 0.14452900352790468, 
    0.48454537842500878, 0.08501249686043845, 0.12429149450933809, 
    0.081192489287687367, 0.48454537842500878, 0.14452900352790468, 
    0.10265733856742666, 0.092973467519897879, 0.18284378821229735, 
    0.39374347115400748, 0.10265733856742666, 0.39374347115400748, 
    0.18284378821229735, 0.13760969309950921, 1.2155801330689715, 
    0.13760969309950921, 0.50004076564884603, 0.079274593232901175, 
    0.37261738700895697, 0.12322564164927195, 1.0621425645235005, 
    0.12707099045735143, 0.50004076564884603, 0.12322564164927195, 
    0.37261738700895697, 0.12707099045735143, 1.0621425645235005, 
    0.35411968522330683, 0.13841917528234035, 0.83476202682149436, 
    0.23322808966665029, 0.35411968522330683, 0.23322808966665029, 
    0.83476202682149436, 2.142781402732032, 0.13760969309950921, 
    2.142781402732032), dim = c(21L, 21L), dimnames = list(c("V1_ij~~V1_ij", 
    "V1_ji~~V1_ij", "V2_ij~~V1_ij", "V2_ji~~V1_ij", "V3_ij~~V1_ij", 
    "V3_ji~~V1_ij", "V1_ji~~V1_ji", "V2_ij~~V1_ji", "V2_ji~~V1_ji", 
    "V3_ij~~V1_ji", "V3_ji~~V1_ji", "V2_ij~~V2_ij", "V2_ji~~V2_ij", 
    "V3_ij~~V2_ij", "V3_ji~~V2_ij", "V2_ji~~V2_ji", "V3_ij~~V2_ji", 
    "V3_ji~~V2_ji", "V3_ij~~V3_ij", "V3_ji~~V3_ij", "V3_ji~~V3_ji"
    ), c("V1_ij~~V1_ij", "V1_ji~~V1_ij", "V2_ij~~V1_ij", "V2_ji~~V1_ij", 
    "V3_ij~~V1_ij", "V3_ji~~V1_ij", "V1_ji~~V1_ji", "V2_ij~~V1_ji", 
    "V2_ji~~V1_ji", "V3_ij~~V1_ji", "V3_ji~~V1_ji", "V2_ij~~V2_ij", 
    "V2_ji~~V2_ij", "V3_ij~~V2_ij", "V3_ji~~V2_ij", "V2_ji~~V2_ji", 
    "V3_ij~~V2_ji", "V3_ji~~V2_ji", "V3_ij~~V3_ij", "V3_ji~~V3_ij", 
    "V3_ji~~V3_ji")), class = c("lavaan.matrix.symmetric", "matrix", 
    "array"))), ov.order = "data", lavOptions = list(sample.cov.rescale = FALSE, 
        fixed.x = FALSE, conditional.x = FALSE, estimator = "ML", 
        se = "robust.sem", test = "Browne.residual.adf")), class = c("lavMoments", 
"list")), test = "scaled.shifted", h1 = FALSE, baseline = FALSE)

# debug(lavaan:::lav_test_satorra_bentler)
eval(as.call(lavCall))

@yrosseel yrosseel merged commit 73ecb27 into yrosseel:master Jun 28, 2024
5 checks passed
@yrosseel
Copy link
Owner

Great, thanks!

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

Successfully merging this pull request may close these issues.

2 participants