From 47eba91a21ff9b643d6d052cb11616c1016003d1 Mon Sep 17 00:00:00 2001 From: giadasp Date: Tue, 6 Apr 2021 16:09:12 +0200 Subject: [PATCH] [docs] add example on se --- src/information/information.jl | 24 ++++++++++++++++++++ src/information/item_expected_information.jl | 7 +++--- src/information/item_observed_information.jl | 15 +++++++----- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/information/information.jl b/src/information/information.jl index 9ff7bdbe..5430d47d 100644 --- a/src/information/information.jl +++ b/src/information/information.jl @@ -220,6 +220,8 @@ item_observed_information( It computes the sum of the item observed informations across the responses. Items (latents) must be of the same type. +# Example 1 + ```@example examinees = [Examinee(n) for n = 1 : 100]; #default examinee factory (1-D latent) items_2PL = [Item(i, Parameters2PL()) for i = 1 : 30]; #2PL item factory @@ -233,6 +235,28 @@ responses = answer(examinees, items) # generate responses obs_items_info_2PL = item_observed_information(items_2PL, examinees, responses) obs_items_info_3PL = item_observed_information(items_3PL, examinees, responses) ``` + +# Example 2. Compute the standard errors of item parameter estimates using the observed responses and estimated abilities. + +```@example +# The package LinearAlgebra is required to compute the inverse of the matrix. +using LinearAlgebra + +# Randomly generate examinees, items and responses. +examinees = [Examinee(n) for n = 1 : 10] +items = [Item(i) for i = 1:40]; +responses = answer(examinees, items); +responses_per_item = map(i -> get_responses_by_item_id(i.id, responses), items); + +items_obs_info = [sum([item_observed_information(items[i], examinees[r.examinee_idx], r) for r in responses_per_item[i]] for i in 1:40]; + +#Using the inverse of the matrix: +inv_items_obs_info = inv.(items_obs_info); +item_parameters_standard_errors_inv = [[sqrt(i[1,1]), sqrt(i[2,2])] for i in inv_items_obs_info] + +#Using the inverse of the diagonal: +item_parameters_standard_errors_diag = [[sqrt(1/i[1,1]), sqrt(1/i[2,2])] for i in items_obs_info] +``` """ function item_observed_information( items::Vector{<:AbstractItem}, diff --git a/src/information/item_expected_information.jl b/src/information/item_expected_information.jl index a114cdff..1700a460 100644 --- a/src/information/item_expected_information.jl +++ b/src/information/item_expected_information.jl @@ -50,9 +50,10 @@ A ``2 \times 2`` matrix of the expected informations. """ function _item_expected_information(parameters::Parameters2PL, latent::Latent1D) p = _probability(latent, parameters) - i_aa = (1 - p) * p * (latent.val - parameters.b)^2 - i_ab = -parameters.a * (1 - p) * p * (latent.val - parameters.b) - i_bb = parameters.a^2 * (1 - p) * p + p_1_p = (1 - p) * p + i_aa = p_1_p * (latent.val - parameters.b)^2 + i_ab = -parameters.a * p_1_p * (latent.val - parameters.b) + i_bb = parameters.a^2 * p_1_p return [i_aa i_ab; i_ab i_bb]::Matrix{Float64} end diff --git a/src/information/item_observed_information.jl b/src/information/item_observed_information.jl index a8e796e7..7fe16fcc 100644 --- a/src/information/item_observed_information.jl +++ b/src/information/item_observed_information.jl @@ -28,7 +28,10 @@ function _item_observed_information( latent::Latent1D, response_val::Float64 ) - return _item_expected_information(parameters, latent)::Matrix{Float64} + p = _probability(latent, parameters) + i_bb = - (- p^2) * (1 - p) * p / (p^2) # v p.49 Kim, Baker: - L_22 + return i_bb::Float64 + # return _item_expected_information(parameters, latent)::Matrix{Float64} end ######################################################################## @@ -45,7 +48,9 @@ _item_observed_information( # Description -It is equal to the item expected information. +Theoretically, it should be equal to its expected counterpart. +However, it is used to compute the standard errors of item parameter estimates which are based on the log-likelihood (which is based on the responses). +Look at the example in the documentation of the exported method. # Arguments @@ -54,7 +59,7 @@ It is equal to the item expected information. - **`response_val::Float64`** : Required. A scalar response. # Output -A ``2 \times 2`` matrix of the observed (expected) informations. +A ``2 \times 2`` matrix of the observed informations. """ function _item_observed_information( parameters::Parameters2PL, @@ -63,9 +68,7 @@ function _item_observed_information( ) #return _item_expected_information(parameters, latent)::Matrix{Float64} p = _probability(latent, parameters) - i = (1 - p) * p - h = (- p^2) * i - j = response_val * i + h = (- p^2) * (1 - p) * p den = p^2 i_aa = - h * (latent.val - parameters.b)^2 / den # v p.49 Kim, Baker: - L_11 i_ab =