# [R] FW: IRT discrimination value (ltm and psych package)

shr@@k m@iii@g oii outiook@com shr@@k m@iii@g oii outiook@com
Tue Jun 25 07:28:05 CEST 2019

```

________________________________
From: shraak using outlook.com
Sent: Tuesday, June 25, 2019 10:57:30 AM
To: Eric Berger
Subject: IRT discrimination value (ltm and psych package)

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