Skip to content

LSMeans, Contrasts in SAS, Stata #2167

Open

Description

@josef-pkt

marginal means when we have categorical variables
evaluating margins at predefine population distributions or survey distributions
marginal means for balanced sample if actual estimation sample is unbalance

Similar to DiscreteMargins and wald_anova with emphasis on categorical explanatory variables

SAS has LSMEANS (IIRC), in Stata large parts are in contrats, but also in margins and predict

I never worked with examples for this, but it looks pretty important based on SAS and Stata documentation.

Where do we get started ?

Activity

  1. josef-pkt commented on Jan 8, 2015

    @josef-pkt
    MemberAuthor

    @kshedden If you, or same for anyone else, have examples and use cases for this, it would be helpful to get more specific enhancement plans to get started with this.

    If nobody needs it, then it will go under "things that we will need - eventually" because Stata and SAS spend many pages of documentation on it.

  2. kshedden commented on Jan 9, 2015

    @kshedden
    Contributor

    This is a notebook I recently used for a workshop I taught, cell 21 is the
    way I get a certain type of plot that I frequently need. It would be nice
    to have a convenience method to do most of the work here.

    http://nbviewer.ipython.org/urls/umich.box.com/shared/static/20nyq9kap75rhet9eujh.ipynb

    On Thu, Jan 8, 2015 at 3:45 PM, Josef Perktold [email protected]
    wrote:

    @kshedden https://github.com/kshedden If you, or same for anyone else,
    have examples and use cases for this, it would be helpful to get more
    specific enhancement plans to get started with this.

    If nobody needs it, then it will go under "things that we will need -
    eventually" because Stata and SAS spend many pages of documentation on it.

    —
    Reply to this email directly or view it on GitHub
    #2167 (comment)
    .

  3. josef-pkt commented on Jan 9, 2015

    @josef-pkt
    MemberAuthor

    Thanks for the example:
    2 parts

    • We need to outsource from margin and predict helper functions that allow us to create the various exog_at, exog values where we want to evaluate.
      This is part that is most specific to this issue.
    • ones we have a desired exog, then predict or similar can take over. In your example, you used linear prediction, for which we could currently get the confidence intervals via t_test
      e.g. something like
    tt = result9.t_test(dexog)
    ci = tt.conf_int(alpha='0.05')
    

    but the link and the general nonlinear version are not yet available. (nonlinear links for GLM will be in #2151)

  4. josef-pkt commented on Jan 9, 2015

    @josef-pkt
    MemberAuthor

    followup, average effect versus effect at a average (or specific exog):

    in cell 21, you fix other exog variables, e.g.

    df["lwt"] = data.lwt.mean()
    df["age"] = age
    df["ht"] = 0
    df["ui"] = 0
    

    which then implies an affect at the average.

    Instead, Stata (and some econometrics books) emphasize the average effect.
    It's not relevant for the linear prediction, but for the predicted probabilities, we would have the average effect different from the effect at the average.

    in example: predict "age curve" for every lwt in the population, and then calculate the average "age curve"
    (that would be the analogous to the "overall=True" in Margins, IIUC.)
    The average effect over categories would assume some fractions/distribution of race and of the binary explanatory variables.

  5. josef-pkt commented on Sep 24, 2015

    @josef-pkt
    MemberAuthor

    I just found lsmeans in R by chance
    https://cran.r-project.org/web/packages/lsmeans/index.html

    (I didn't read it yet, first example in vignette is to construct average + categorical exog for predict)

    cross link #2294 another average effect issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions