Announcement

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

  • Calculating partial pseudo R2 after logistic regression using Wald test and accessing matrices

    Dear Statalist,

    I very much hope you can help me with this Stata problem.

    I have a list of independent variables that I would like to test in a logistic regression and then compute a partial pseudo R2 for each variable to rank variables by their relative importance. There appears to be no prepackaged way to do this so I have resorted to manual calculations.

    The formula for the partial pseudo R2 requires the Wald test chi2 statistic (LR would be better but too cumbersome, and I have a large sample size anyway). I would like to get this automatically, probably from the matrix generated from the -test- command, and then compute the partial R2 for each variable.

    my plan:

    logit y x1 x2 x3 //run the regression

    test x1 x2 x3, mtest // calculate wald statistics

    matrix myresults = r(mtest)

    ... and here is when I would like to pull the results from the matrix 'myresults' , calculate the partial pseudo R2 using my formula, ideally store the results somewhere (in a new matrix?), and automatically rank by partial pseudo R2.


    The process needs to be automated because I will be doing it over many different subsets of the data and with different lists of independent variables that depend on the subset.

    Any help from the community would be greatly appreciated and will probably turn me into a much better Stata user!

    Pavel

  • #2
    I found some helpful code from Martin Buis to get the Wald chi2 statistics.
    Code:
     
     // create an example model sysuse auto, clear probit foreign price mpg   // square z-statistics di as txt "Chi^2 for price " ///    as result (_b[price]/_se[price])^2 di as txt "Chi^2 for mpg " ///    as result (_b[mpg]/_se[mpg])^2
    and

    Code:
     
     // use Mata to do this for all //parameters in one go mata b = st_matrix("e(b)")' V = st_matrix("e(V)") se = diagonal(cholesky(diag(V))) (b :/ se ):^2  // or equivalently (b:^2) :/ diagonal(V) end
    now the challenge is to actually store the results somehow that allows me to rank the resulting partial R2
    Last edited by Pavel Roshanov; 03 Jul 2014, 15:41.

    Comment

    Working...
    X