Skip to content

Instantly share code, notes, and snippets.

@farshadl123
Last active November 27, 2023 02:16
Show Gist options
  • Save farshadl123/945c3a4dbb045bfe2f6050b1a18b7b3f to your computer and use it in GitHub Desktop.
Save farshadl123/945c3a4dbb045bfe2f6050b1a18b7b3f to your computer and use it in GitHub Desktop.
rasch_model_pymc3
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)
@huni1023
Copy link

huni1023 commented Nov 27, 2023

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

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