Announcement

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

  • [FMM] Estimating centiles/graphing density of a single observation

    Dear Statalisters,

    I want to estimate centiles for a single observation after using a finite mixture model (Mixture of 4 Gaussians/normal distributions).
    The aim is to graph those values later on.

    Below I do the same for an OLS regression and a Quantile Regression.
    First I expand the data set by 99 to calculate 99 centiles for each observation
    Id2 is the identifier for an observation and idq the quantile.

    For the OLS regression I simply take the point estimate and add the centile of the residual.
    For the Quantile regression I use the predicted value for the given quantile directly.

    My question is: How do I proceed the same way if I have estimated classprobabilities, classpostprobabilities and point estimates given a latent class for each observation. As for OLS the assumption of normality within each group holds.

    I'm stuck but somehow I should be able to
    1. estimate the parameters of the normal distributions
    2. calculate the centiles for a given observation by knowing the classprobabilities for the given observation and the parameters of the normal distributions.

    Code:
    regress $y3 $x1 $x2 $x3 $x4
    predict OLS
    predict OLSres, res
    
    gen id2 = _n
    expand 99
    gen QRden = .
    gen OLSden = .
    gen FRMden = .
    bysort id2: gen idq = _n
    
    forvalues q=1/99{
    local fq = `q'/100
    qui qreg $y3 $x1 $x2 $x3 $x4 if idq==1, q(`q')
    capture drop aux
    predict aux
    replace QRden = aux if idq==`q'
    
    qui centile OLSres, centile(`q')
    replace OLSden = OLS + r(c_1) if idq==`q'
    }
    E.g. twoway kdensity OLSden if id2==1 || kdensity QRden if id2==1 would be the predicted density of observation 1 by an OLS regression and by a Quantile regression.

    Any help is appreciated.

    Kind regards

    Steffen Plützke
Working...
X