Announcement

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

  • Estimate of mean squared error

    Hello,

    Is there a Stata written command that allows one to determine the mean squared error from a mixed-effects linear regression model? I want to estimate this quantity for a simulation analysis that I am doing.

    All best,
    Jack

  • #2
    You can square the root MSE that is returned.
    Code:
    sysuse bplong
    
    anova bp sex / patient|sex when sex#when, repeated(when)
    
    display in smcl as text "MSE = " as result e(rmse)^2

    Comment


    • #3
      Thanks Joseph.

      Would this work for a mixed-effects model?

      I have adjusted my simulation code, have I done it correctly?

      capture program drop swcrt
      program define swcrt, rclass
      /*Code omitted*/
      /*Fit multi-level model to simulated dataset*/
      mixed y intrv i.time ||cluster: ||individual:, covariance(unstructured) reml dfmethod(kroger)
      /*Return estimated effect size, bias, p-value, and significance dichotomy*/
      tempname M
      matrix `M' = r(table)
      return scalar bias = _b[intrv] - `intrvcoeff'
      return scalar mse = e(rmse)^2
      return scalar p = `M'[r(p)]
      return scalar p_= (`M'[`r(p)'] < `alpha')
      exit
      end swcrt
      *Postfile to store results
      tempfile powerresults
      capture postutil clear
      postfile step int num_clus intrvcoeff p p_ bias mse using `powerresults' /*Maybe add ICC*/
      *Loop over number of clusters, ICC
      foreach c of local num_clus{
      [INDENT=2]display as text "Number of clusters" as result "`c'"[/INDENT]/*
      foreach i of local ICC{
      [INDENT=2]display as text "Intra-class correlation" as result `ICC' */[/INDENT]
      forvalue i = 1/`nrep'{
      [INDENT=2]display as text "Iterations" as result `nrep'
      quietly swcrt `c' `intrvcoeff' `sigma_u3' `sigma_u2' `sigma_error' /*Maybe add ICC*/
      post step (`c') /*(`ICC')*/ (`r(p)') (`r(p_)') (`r(bias)') (`r(mse)')[/INDENT][INDENT=2]}[/INDENT]
      }
      }
      postclose step

      *Open results, calculate power
      use `powerresults', clear
      levelsof num_clus, local(num_clus)
      /*levelsof ICC, local(ICC)*/ /*Maybe remove or add ICC*/
      matrix drop _all
      *Loop over combinations of clusters and ICC
      *Add power results to matrix
      foreach c of local num_clus {
      /*foreach i of local ICC { */
      quietly ci proportions sig if clus_num == `c' & /*float(ICC)*/ == float(`i')
      local power `r(proportion)'
      local power_lb `r(lb)'
      local power_ub `r(ub)'
      quietly ci mean bias if clus_num == `c' & /*float(ICC)*/ == float(`i')
      local bias `r(mean)'
      local bias_lb `r(lb)'
      local bias_ub `r(ub)'
      quietly ci mean mse if clus_num == `c' & /*float(ICC)*/ == float(`i')
      local mse `r(mean)' /*Would this be correct?*/

      matrix M = nullmat(M) \ (`c', `i', `power', `power_lb', `power_ub', `r(mean)', `r(lb)', `r(ub)', ) /*May need to remove extra comma and space; why isn't rmean, rlb, and rub bias, biaslb, and biasub*/
      }
      }
      Last edited by CEdward; 30 Oct 2019, 18:36.

      Comment


      • #4
        I reviewed the stored results section of the mixed command and it appears that the mean squared error is not generated for a multi-level model, but an anova. Does anyone know if this is possible in Stata?

        Comment

        Working...
        X