Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unexpected error with -bayes:mixed-

    The following
    Code:
    sysuse bplong
    bayes: mixed bp i.when || patient: , noconstant residuals(exchangeable)
    aborts with the following error message:

    random effects level patient is empty
    an error occurred when bayes executed mixed

    r(198);


    Does anyone see what I'm doing wrong?

    (The code is excerpted; the complete do-file and SMCL log file are attached below.)

    The helpfile, help bayes_mixed, specifically mentions allowing the noconstant option in the random effects equation as does the corresponding user's manual entry (Page 593), although the latter doesn't contain a worked example that exercises that option.

    I'd rather not trouble Technical Support with this if someone can readily spot an error.
    Attached Files
    Last edited by Joseph Coveney; 25 Mar 2023, 22:13. Reason: is → are

  • #2
    I don’t have an answer for you, but the -bayes- prefix for mixed also doesn’t support the use of the -residual()- covariance matrix structures. In principle, these should be theoretically possible but you might need to work directly with -bayesmh-.

    Comment


    • #3
      Originally posted by Leonardo Guizzetti View Post
      . . . the -bayes- prefix for mixed also doesn’t support the use of the -residual()- covariance matrix structures.
      Thank you, Leonardo, I wasn't aware of that. The problem with the noconstant option seems to be separate from that, but inasmuch as the only reason I'd ever specify the option in the random effects side is exactly to use patterned residual covariance structures, I guess that my problem is moot.

      For this example, I could reshape wide and use bayes: mvreg, but there is no way to impose a constraint with mvreg to make for an exchangeable residuals covariance.

      As you suggest, I'll look into bayesmh. Thanks again.

      Comment


      • #4
        Well, it is doable with bayesmh, but it will be nicer when bayes gets brushed up a bit.
        Code:
        version 17.0
        
        clear *
        
        // seedem
        set seed 986666036
        
        quietly sysuse bplong
        
        mixed bp i.(sex agegrp when) || patient: , noconstant residual(exchangeable) ///
            reml dfmethod(satterthwaite) ///
                nolrtest nolog
        
        *
        * Begin here
        *
        quietly reshape wide bp, i(patient) j(when)
        generate byte k = 1
        
        matrix define OffDiagonal = J(2, 2, 1) - I(2)
        bayesmh ///
            (bp1 = ({common:sex} * 1.sex +  {common:agegrp2} * 2.agegrp + {common:agegrp3} * 3.agegrp + {bp1} * k)) ///
            (bp2 = ({common:sex} * 1.sex +  {common:agegrp2} * 2.agegrp + {common:agegrp3} * 3.agegrp + {bp2} * k)), ///
                likelihood(mvnormal({var} * I(2) + {covar} * OffDiagonal)) ///
                prior({common:} {bp1 bp2 var covar}, normal(0, 100)) ///
                    initial({common:sex} -5 {common:agegrp2} 5 {common:agegrp3} 10 {bp1} 150 {bp2} 150 {var} 130 {covar} -10) ///
                    nomodelsummary saving(Posterior)
        
        foreach graph in trace ac histogram {
            foreach parm in "sex" "agegrp2" "agegrp3" "bp1" "bp2" "var" "covar" {
                bayesgraph `graph' {`parm'}
                if "`graph'" == "histogram" sleep 5000
                else sleep 2500
            }
        }
        
        // Time variable
        frame create When
        cwf When
        use Posterior
        generate double when = eq0_p2 - eq0_p1
        summarize when [fweight=_frequency], detail
        histogram when [fweight=_frequency]
        
        exit
        If anyone has a suggestion for improving my model-specification syntax, I'd be glad to hear it.

        Comment

        Working...
        X