Skip to content

Add observation-level sample weights to poLCA#29

Open
tingjhenjiang wants to merge 1 commit into
dlinzer:masterfrom
tingjhenjiang:sample-weights
Open

Add observation-level sample weights to poLCA#29
tingjhenjiang wants to merge 1 commit into
dlinzer:masterfrom
tingjhenjiang:sample-weights

Conversation

@tingjhenjiang

Copy link
Copy Markdown

Adds a weights argument to poLCA() (numeric vector or column name of data) implementing weighted pseudo-maximum-likelihood estimation:

  • weighted log-likelihood sum_i w_i log f(y_i)
  • weighted M-step response probabilities via row-scaled posteriors passed to the existing probhat C routine
  • weighted mixing proportions (no-covariate case) and a weighted pure-R Newton step poLCA.dLL2dBeta.w for latent class regression, matching the C layout of d2lldbeta2 exactly at unit weights
  • pseudo-ML sandwich standard errors in poLCA.se (A^-1 B A^-1 with A = sum w s s', B = sum w^2 s s'), reducing to the original ginv(t(s) s) at unit weights
  • weighted cell frequencies in poLCA.compress for Chisq/Gsq

weights=NULL or all-1 weights reproduce the original estimator exactly; integer weights match row-replicated data to fp accumulation error.

Adds a weights argument to poLCA() (numeric vector or column name of
data) implementing weighted pseudo-maximum-likelihood estimation:
- weighted log-likelihood sum_i w_i log f(y_i)
- weighted M-step response probabilities via row-scaled posteriors
  passed to the existing probhat C routine
- weighted mixing proportions (no-covariate case) and a weighted pure-R
  Newton step poLCA.dLL2dBeta.w for latent class regression, matching
  the C layout of d2lldbeta2 exactly at unit weights
- pseudo-ML sandwich standard errors in poLCA.se (A^-1 B A^-1 with
  A = sum w s s', B = sum w^2 s s'), reducing to the original
  ginv(t(s) s) at unit weights
- weighted cell frequencies in poLCA.compress for Chisq/Gsq

weights=NULL or all-1 weights reproduce the original estimator exactly;
integer weights match row-replicated data to fp accumulation error.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread R/poLCA.R
# weighted estimator of the response probabilities
vp$vecprobs <- poLCA.probHat.C(w*rgivy,y,vp)
} else {
vp$vecprobs <- poLCA.probHat.C(rgivy,y,vp) # update probs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the majority of the code, you've re-used w well in both the unweighted and weighted versions. Why do you need an if statement here?

@shermanlo77

Copy link
Copy Markdown

Have you written this commit yourself?

@shermanlo77

Copy link
Copy Markdown

weighted pure-R Newton step poLCA.dLL2dBeta.w

Is there a chance you could instead modify the C code?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants