Module: Statsample::Reliability
- Defined in:
- lib/statsample/reliability.rb,
lib/statsample/reliability/icc.rb,
lib/statsample/reliability/scaleanalysis.rb,
lib/statsample/reliability/multiscaleanalysis.rb,
lib/statsample/reliability/skillscaleanalysis.rb
Defined Under Namespace
Classes: ICC, ItemCharacteristicCurve, MultiScaleAnalysis, ScaleAnalysis, SkillScaleAnalysis
Class Method Summary collapse
-
.alfa_second_derivative(n, sx, sxy) ⇒ Object
Second derivative for alfa Parameters
n
: Number of itemssx
: mean of variancessxy
: mean of covariances. -
.alpha_first_derivative(n, sx, sxy) ⇒ Object
First derivative for alfa Parameters
n
: Number of itemssx
: mean of variancessxy
: mean of covariances. -
.cronbach_alpha(ods) ⇒ Object
Calculate Chonbach’s alpha for a given dataset.
-
.cronbach_alpha_from_covariance_matrix(cov) ⇒ Object
Get Cronbach’s alpha from a covariance matrix.
-
.cronbach_alpha_from_n_s2_cov(n, s2, cov) ⇒ Object
Get Cronbach alpha from
n
cases,s2
mean variance andcov
mean covariance. -
.cronbach_alpha_standarized(ods) ⇒ Object
Calculate Chonbach’s alpha for a given dataset using standarized values for every vector.
-
.n_for_desired_alpha(alpha, s2, cov) ⇒ Object
Returns n necessary to obtain specific alpha given variance and covariance mean of items.
-
.n_for_desired_reliability(r, r_d, n = 1) ⇒ Object
Returns the number of items to obtain
r_d
desired reliability fromr
current reliability, achieved withn
items. -
.spearman_brown_prophecy(r, n) ⇒ Object
(also: sbp)
Predicted reliability of a test by replicating
n
times the number of items.
Class Method Details
.alfa_second_derivative(n, sx, sxy) ⇒ Object
Second derivative for alfa Parameters n
: Number of items sx
: mean of variances sxy
: mean of covariances
103 104 105 |
# File 'lib/statsample/reliability.rb', line 103 def alfa_second_derivative(n,sx,sxy) (2*(sxy**2)*(sxy-sx)).quo(((sxy*(n-1))+sx)**3) end |
.alpha_first_derivative(n, sx, sxy) ⇒ Object
First derivative for alfa Parameters n
: Number of items sx
: mean of variances sxy
: mean of covariances
94 95 96 |
# File 'lib/statsample/reliability.rb', line 94 def alpha_first_derivative(n,sx,sxy) (sxy*(sx-sxy)).quo(((sxy*(n-1))+sx)**2) end |
.cronbach_alpha(ods) ⇒ Object
Calculate Chonbach’s alpha for a given dataset. only uses tuples without missing data
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/statsample/reliability.rb', line 6 def cronbach_alpha(ods) ds = ods.reject_values(*Daru::MISSING_VALUES) n_items = ds.ncols return nil if n_items <= 1 s2_items = ds.to_h.values.inject(0) { |ac,v| ac + v.variance } total = ds.vector_sum (n_items.quo(n_items - 1)) * (1 - (s2_items.quo(total.variance))) end |
.cronbach_alpha_from_covariance_matrix(cov) ⇒ Object
Get Cronbach’s alpha from a covariance matrix
56 57 58 59 60 61 |
# File 'lib/statsample/reliability.rb', line 56 def cronbach_alpha_from_covariance_matrix(cov) n = cov.row_size raise "covariance matrix should have at least 2 variables" if n < 2 s2 = n.times.inject(0) { |ac,i| ac + cov[i,i] } (n.quo(n - 1)) * (1 - (s2.quo(cov.total_sum))) end |
.cronbach_alpha_from_n_s2_cov(n, s2, cov) ⇒ Object
Get Cronbach alpha from n
cases, s2
mean variance and cov
mean covariance
52 53 54 |
# File 'lib/statsample/reliability.rb', line 52 def cronbach_alpha_from_n_s2_cov(n,s2,cov) (n.quo(n-1)) * (1-(s2.quo(s2+(n-1)*cov))) end |
.cronbach_alpha_standarized(ods) ⇒ Object
Calculate Chonbach’s alpha for a given dataset using standarized values for every vector. Only uses tuples without missing data Return nil if one or more vectors has 0 variance
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/statsample/reliability.rb', line 20 def cronbach_alpha_standarized(ods) ds = ods.reject_values(*Daru::MISSING_VALUES) return nil if ds.any? { |v| v.variance==0} ds = Daru::DataFrame.new( ds.vectors.to_a.inject({}) { |a,i| a[i] = ods[i].standardize a } ) cronbach_alpha(ds) end |
.n_for_desired_alpha(alpha, s2, cov) ⇒ Object
Returns n necessary to obtain specific alpha given variance and covariance mean of items
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/statsample/reliability.rb', line 64 def n_for_desired_alpha(alpha,s2,cov) # Start with a regular test : 50 items min=2 max=1000 n=50 prev_n=0 epsilon=0.0001 dif=1000 c_a=cronbach_alpha_from_n_s2_cov(n,s2,cov) dif=c_a - alpha while(dif.abs>epsilon and n!=prev_n) prev_n=n if dif<0 min=n n=(n+(max-min).quo(2)).to_i else max=n n=(n-(max-min).quo(2)).to_i end c_a=cronbach_alpha_from_n_s2_cov(n,s2,cov) dif=c_a - alpha end n end |
.n_for_desired_reliability(r, r_d, n = 1) ⇒ Object
Returns the number of items to obtain r_d
desired reliability from r
current reliability, achieved with n
items
44 45 46 47 |
# File 'lib/statsample/reliability.rb', line 44 def n_for_desired_reliability(r,r_d,n=1) return nil if r.nil? (r_d*(1-r)).quo(r*(1-r_d))*n end |
.spearman_brown_prophecy(r, n) ⇒ Object Also known as: sbp
Predicted reliability of a test by replicating n
times the number of items
35 36 37 |
# File 'lib/statsample/reliability.rb', line 35 def spearman_brown_prophecy(r,n) (n*r).quo(1+(n-1)*r) end |