@@ -601,16 +601,25 @@ lav_options_est_iv <- function(opt) {
601601 # sample.icov not needed
602602 opt $ sample.icov <- FALSE
603603
604+ # no loglik
605+ opt $ loglik <- FALSE
606+
607+ # no rescale of vcov
608+ opt $ sample.cov.rescale <- FALSE
609+
604610 # estimator options
605611 if (is.null(opt $ estimator.args )) {
606612 # create default list
607613 opt $ estimator.args <- list (iv.method = " 2SLS" ,
608614 iv.samplestats = FALSE ,
609615 iv.varcov.method = " RLS" ,
610- iv.varcov.se = TRUE ,
611- iv.varcov.modelbased = TRUE ,
612- iv.varcov.jaca.numerical = FALSE ,
613- iv.varcov.jacb.numerical = FALSE )
616+ iv.sargan = TRUE ,
617+ iv.vcov.stage1 <- " lm.vcov.dfres" ,
618+ iv.vcov.stage2 <- " delta" ,
619+ iv.vcov.gamma.modelbased = TRUE ,
620+ iv.vcov.jack.numerical = FALSE ,
621+ iv.vcov.jaca.numerical = FALSE ,
622+ iv.vcov.jacb.numerical = FALSE )
614623 } else {
615624 if (is.null(opt $ estimator.args $ iv.method )) {
616625 opt $ estimator.args $ iv.method <- " 2SLS"
@@ -620,30 +629,79 @@ lav_options_est_iv <- function(opt) {
620629 if (is.null(opt $ estimator.args $ iv.samplestats )) {
621630 opt $ estimator.args $ iv.samplestats <- FALSE
622631 }
632+ if (is.null(opt $ estimator.args $ iv.sargan )) {
633+ opt $ estimator.args $ iv.sargan <- TRUE
634+ }
635+ if (is.null(opt $ estimator.args $ iv.vcov.stage1 )) {
636+ if (opt $ .categorical ) {
637+ opt $ estimator.args $ iv.vcov.stage1 <- " lm.vcov.dfres"
638+ } else {
639+ opt $ estimator.args $ iv.vcov.stage1 <- " lm.vcov.dfres"
640+ }
641+ if (tolower(opt $ se [1 ]) == " none" ) {
642+ opt $ estimator.args $ iv.vcov.stage1 <- " none"
643+ }
644+ } else if (! tolower(opt $ estimator.args $ iv.vcov.stage1 ) %in%
645+ c(" lm.vcov" , " lm.vcov.dfres" , " gamma" , " none" )) {
646+ lav_msg_stop(gettext(" iv.vcov.stage1 should be lm.vcov, lm.vcov.dfres,
647+ gamma or none." ))
648+ } else if (tolower(opt $ estimator.args $ iv.vcov.stage1 ) == " gamma" &&
649+ ! opt $ estimator.args $ iv.samplestats ) {
650+ lav_msg_stop(gettext(" iv.vcov.stage1 cannot be gamma if
651+ iv.samplestats is FALSE" ))
652+ }
653+ if (opt $ .categorical ) {
654+ opt $ estimator.args $ iv.samplestats <- TRUE
655+ }
656+ if (is.null(opt $ estimator.args $ iv.vcov.stage2 )) {
657+ if (opt $ .categorical ||
658+ tolower(opt $ estimator.args $ iv.vcov.stage1 ) == " gamma" ) {
659+ opt $ estimator.args $ iv.vcov.stage2 <- " h2"
660+ } else {
661+ opt $ estimator.args $ iv.vcov.stage2 <- " delta"
662+ }
663+ if (tolower(opt $ se [1 ]) == " none" ) {
664+ opt $ estimator.args $ iv.vcov.stage2 <- " none"
665+ }
666+ } else if (! tolower(opt $ estimator.args $ iv.vcov.stage2 ) %in%
667+ c(" h2" , " delta" , " none" )) {
668+ lav_msg_stop(gettext(" iv.vcov.stage2 should be h2, delta, or none." ))
669+ } else if (tolower(opt $ estimator.args $ iv.vcov.stage1 ) %in%
670+ c(" lm.vcov" , " lm.vcov.dfres" ) &&
671+ tolower(opt $ estimator.args $ iv.vcov.stage2 ) == " h2" ) {
672+ lav_msg_stop(gettext(" iv.vcov.stage2 should be delta (or none) if
673+ iv.vcov.stage1 is either lm.vcov or lm.vcov.dfres." ))
674+ }
623675 if (opt $ .categorical ) {
624676 opt $ estimator.args $ iv.samplestats <- TRUE
625677 }
626678 if (is.null(opt $ estimator.args $ iv.varcov.method )) {
627679 opt $ estimator.args $ iv.varcov.method <- " RLS"
628680 } else if (! toupper(opt $ estimator.args $ iv.varcov.method ) %in%
629681 c(" ULS" , " GLS" , " 2RLS" , " RLS" , " NONE" )) {
630- lav_msg_stop(gettext(" iv.varcov.method should ULS, GLS, 2RLS, RLS
682+ lav_msg_stop(gettext(" iv.varcov.method should be ULS, GLS, 2RLS, RLS
631683 or NONE." ))
632684 }
633- if (is.null(opt $ estimator.args $ iv.varcov.se )) {
634- opt $ estimator.args $ iv.varcov.se <- TRUE
685+ if (is.null(opt $ estimator.args $ iv.vcov.gamma.modelbased )) {
686+ opt $ estimator.args $ iv.vcov.gamma.modelbased <- TRUE
635687 }
636- if (is.null(opt $ estimator.args $ iv.varcov.modelbased )) {
637- opt $ estimator.args $ iv.varcov.modelbased <- TRUE
688+ if (is.null(opt $ estimator.args $ iv.vcov.jack.numerical )) {
689+ opt $ estimator.args $ iv.vcov.jack.numerical <- FALSE
638690 }
639- if (is.null(opt $ estimator.args $ iv.varcov .jaca.numerical )) {
640- opt $ estimator.args $ iv.varcov .jaca.numerical <- FALSE
691+ if (is.null(opt $ estimator.args $ iv.vcov .jaca.numerical )) {
692+ opt $ estimator.args $ iv.vcov .jaca.numerical <- FALSE
641693 }
642- if (is.null(opt $ estimator.args $ iv.varcov .jacb.numerical )) {
643- opt $ estimator.args $ iv.varcov .jacb.numerical <- FALSE
694+ if (is.null(opt $ estimator.args $ iv.vcov .jacb.numerical )) {
695+ opt $ estimator.args $ iv.vcov .jacb.numerical <- FALSE
644696 }
645697 }
646698
699+ # override test if iv.varcov.method is "none"
700+ if (toupper(opt $ estimator.args $ iv.varcov.method ) == " NONE" ) {
701+ opt $ test <- " none"
702+ opt $ standard.test <- " none"
703+ }
704+
647705 opt
648706}
649707
0 commit comments