Created
November 11, 2013 14:15
-
-
Save n8thangreen/7413788 to your computer and use it in GitHub Desktop.
Stochastic array of multinomial logistic regression parameter fits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| probs.logit <- function(grps.seq, cov, coeff, x){ | |
| ## | |
| ## multinomial logistic regression model fit for a given covariate | |
| ## e.g. probability sums per age =1 | |
| ## | |
| ## x: covariate value e.g. age=16 | |
| ## grps: vector of class labels for NATSAL groups e.g. het5yrs | |
| ## cov: covariate name to regress against (string) | |
| ## coeff: coefficients from the mlogit() fit | |
| ## likleihood | |
| L <- pihat <- vector() | |
| L[1] <- 0 | |
| for(i in grps.seq[-1]){ | |
| ## omit pivot group from loop | |
| intercept <- paste(i, ":(intercept)", sep="") | |
| cov_index <- paste(i, ":", cov, sep="") | |
| L[which(grps.seq==i)] <- coeff[intercept] + coeff[cov_index]*x | |
| } | |
| denom <- sum(exp(L)) | |
| for (i in 1:length(L)){ | |
| pihat[i] <- exp(L[i])/denom | |
| } | |
| names(pihat) <- grps.seq | |
| pihat | |
| } | |
| ## END FUNCTION ## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment