Last active
November 27, 2023 02:16
-
-
Save farshadl123/945c3a4dbb045bfe2f6050b1a18b7b3f to your computer and use it in GitHub Desktop.
rasch_model_pymc3
This file contains 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
with pm.Model() as model: | |
## Independent priors | |
alpha = pm.Normal('Person', mu = 0, sigma = 3, shape = (1, len(data))) | |
gamma = pm.Normal('Question', mu = 0, sigma = 3, shape = (data.shape[1], 1)) | |
## Log-Likelihood | |
def logp(d): | |
v1 = tt.transpose(d) * tt.log(tt.nnet.sigmoid(alpha - (gamma - gamma.mean(0)))) | |
v2 = tt.transpose((1-d)) * tt.log(1 - tt.nnet.sigmoid(alpha - (gamma - gamma.mean(0)))) | |
return v1 + v2 | |
ll = pm.DensityDist('ll', logp, observed = {'d': data.values}) | |
trace = pm.sample(1500, cores=-1, step = pm.NUTS()) | |
trace = trace[250:] | |
pm.traceplot(trace); | |
trace = pm.trace_to_dataframe(trace) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm studying item response theory. It's not a clear implementation, but I build a sample code of this gist on Medium.
see here