[R] IRT discrimination value (ltm and psych package)
shreepad khandve
@hreep@d@kh@ndve05 @end|ng |rom gm@||@com
Wed Jun 26 13:16:10 CEST 2019
Hello Sir,
I am learning R and its syntax and I have successfully converted
irt.item.diff.rasch into python code and pass the inputs as per the
function made in R.
In R :-
function (items)
{
ncases <- nrow(items)
item.mean <- colMeans(items, na.rm = TRUE)
item.mean[item.mean < (1/ncases)] <- 1/ncases
irt.item.diff.rasch <- log((1/item.mean) - 1)
}
In Python :-
def diff(items):
item_mean= items.mean()
item_diff = []
for i in item_mean:
diff = np.log((1/i)-1)
item_diff.append(diff)
return item_diff
I am getting the exact same result as R output.
But I’m still unable to understand the “item.discrim” and how to and
what to pass as a input to the function,
function (item.diff, theta, items)
{
irt.item.discrim <- function(x, diff, theta, scores) {
fit <- -1 * (log(scores/(1 + exp(x * (diff - theta))) +
(1 - scores)/(1 + exp(x * (theta - diff)))))
mean(fit, na.rm = TRUE)
}
nitems <- length(item.diff)
discrim <- matrix(NaN, nitems, 2)
for (i in 1:nitems) {
item.fit <- optimize(irt.item.discrim, c(-5, 5), diff = item.diff[i],
theta = theta, scores = items[, i])
discrim[i, 1] <- item.fit$minimum
discrim[i, 2] <- item.fit$objective
}
irt.discrim <- discrim
Could you please guide how do I convert the same in python, because
there are no proper explanation in documentation what to pass as
following arguments or the formulas to find the values of x and theta.
X= ?
Diff = I got the diff values
Theta = ?
Scores = = items[, i] as per mentioned in code
Unable to find theta and x, please help with this parameters ?
Thanks,
Shreepad
More information about the R-help
mailing list