36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
import logging
|
|
|
|
from lib.irt.models.three_parameter_logistic import ThreeParameterLogistic
|
|
from lib.irt.models.rasch import Rasch
|
|
from lib.errors.item_generation_error import ItemGenerationError
|
|
|
|
|
|
class ItemInformationFunction():
|
|
|
|
def __init__(self, irt_model):
|
|
self.model_data = irt_model
|
|
|
|
# determines the amount of information for a given question at a given theta (ability level)
|
|
# further detailed on page 161, equation 4 here:
|
|
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5978482/pdf/10.1177_0146621615613308.pdf
|
|
def calculate(self, **kwargs):
|
|
try:
|
|
if self.model_data.model == '3PL':
|
|
p = ThreeParameterLogistic(self.model_data, kwargs).result()
|
|
q = 1 - p
|
|
return (self.model_data.a_param * q *
|
|
(p - self.model_data.c_param)**2) / (p * (
|
|
(1 - self.model_data.c_param)**2))
|
|
elif self.model_data.model == 'rasch':
|
|
p = Rasch(self.model_data, kwargs).result()
|
|
q = 1 - p
|
|
return p * q
|
|
else:
|
|
# potentially error out
|
|
raise ItemGenerationError(
|
|
"irt model not supported or provided")
|
|
except ZeroDivisionError as error:
|
|
logging.error(error)
|
|
raise ItemGenerationError("params not well formatted",
|
|
error.args[0])
|