forked from inuyasha2012/pypsy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
782b8d3
commit 55bef09
Showing
6 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from __future__ import print_function | ||
from psy.ctt import Ctt | ||
import numpy as np | ||
|
||
f = file('lsat.csv') | ||
score = np.loadtxt(f, delimiter=",") | ||
ctt = Ctt(score) | ||
print(ctt.get_reliability()) | ||
print(ctt.get_cr()) | ||
print(ctt.get_discrimination()) | ||
print(ctt.get_difficulty()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import division | ||
import numpy as np | ||
|
||
from psy.ctt import Ctt | ||
|
||
r_list = [0.5, 0.5, 0.5, 0.5, 0.5] | ||
t_list = np.zeros((500, 5)) | ||
x_list = np.zeros((500, 5)) | ||
for i, r in enumerate(r_list): | ||
t = np.random.randint(0, 2, 500) | ||
# t.sort() | ||
# t = np.round(t, 0) | ||
# t[t > 1] = 1 | ||
# t[t < 0] = 0 | ||
var_t = np.var(t) | ||
var_x = var_t / r | ||
var_e = var_x - var_t | ||
std_e = var_e ** 0.5 | ||
e = np.random.normal(0, std_e, 500) | ||
x = np.round(t + e, 0) | ||
x[x < 0] = 0 | ||
x[x > 1] = 1 | ||
t_list[:, i] = t | ||
x_list[:, i] = x | ||
|
||
var_tt = np.var(np.sum(t_list, axis=1)) | ||
var_tx = np.var(np.sum(x_list, axis=1)) | ||
np.savetxt('ctt.csv', x_list, delimiter=',') | ||
print var_tt / var_tx | ||
ctt = Ctt(scores=x_list) | ||
print ctt.get_reliability() | ||
print ctt.get_cr() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ctt import Ctt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# coding=utf-8 | ||
from __future__ import division, print_function | ||
import numpy as np | ||
|
||
from psy import Factor | ||
|
||
|
||
class BaseCtt(object): | ||
|
||
def __init__(self, scores): | ||
self._scores = scores | ||
self.sum_scores = np.sum(scores, axis=1) | ||
self.sum_scores.shape = self.sum_scores.shape[0], 1 | ||
self.item_size = scores.shape[1] | ||
|
||
def get_composite_reliability(self): | ||
# 组合信度 | ||
f = Factor(self._scores.transpose(), 1) | ||
loadings = f.loadings | ||
lambda_sum_square = np.sum(loadings) ** 2 | ||
lambda_square_sum = np.sum(loadings ** 2) | ||
return lambda_sum_square / (lambda_sum_square - lambda_square_sum + self.item_size) | ||
|
||
def get_alpha_reliability(self): | ||
scores = self._scores | ||
item_size = self.item_size | ||
# 每道试题的方差 | ||
items_var = np.var(scores, axis=0) | ||
# 所有试题方差的和 | ||
sum_items_var = np.sum(items_var) | ||
# 计算总分方差 | ||
sum_scores_var = np.var(self.sum_scores) | ||
return item_size / (item_size - 1) * (1 - sum_items_var / sum_scores_var) | ||
|
||
|
||
class Ctt(BaseCtt): | ||
|
||
def get_discrimination(self): | ||
scores = self._scores | ||
scores_mean = np.mean(scores, axis=0) | ||
sum_scores_mean = np.mean(self.sum_scores) | ||
center = (scores - scores_mean) * (self.sum_scores - sum_scores_mean) | ||
cov = np.mean(center, axis=0) | ||
std = np.std(scores, axis=0) * np.std(self.sum_scores) | ||
return cov / std | ||
|
||
def get_difficulty(self): | ||
return np.mean(self._scores, axis=0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters