Skip to content

Commit

Permalink
[docs] add example on se
Browse files Browse the repository at this point in the history
  • Loading branch information
giadasp committed Apr 6, 2021
1 parent 5c6b4fc commit 47eba91
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
24 changes: 24 additions & 0 deletions src/information/information.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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},
Expand Down
7 changes: 4 additions & 3 deletions src/information/item_expected_information.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 9 additions & 6 deletions src/information/item_observed_information.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

########################################################################
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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 =
Expand Down

0 comments on commit 47eba91

Please sign in to comment.