lib/statsample/reliability.rb in statsample-0.15.0 vs lib/statsample/reliability.rb in statsample-0.15.1
- old
+ new
@@ -4,13 +4,15 @@
# Calculate Chonbach's alpha for a given dataset.
# only uses tuples without missing data
def cronbach_alpha(ods)
ds=ods.dup_only_valid
n_items=ds.fields.size
+ return nil if n_items<=1
s2_items=ds.vectors.inject(0) {|ac,v|
ac+v[1].variance }
total=ds.vector_sum
+
(n_items.quo(n_items-1)) * (1-(s2_items.quo(total.variance)))
end
# Calculate Chonbach's alpha for a given dataset
# using standarized values for every vector.
# Only uses tuples without missing data
@@ -31,9 +33,10 @@
# Returns the number of items
# to obtain +r_d+ desired reliability
# from +r+ current reliability, achieved with
# +n+ items
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
# Get Cronbach alpha from <tt>n</tt> cases,
# <tt>s2</tt> mean variance and <tt>cov</tt>
\ No newline at end of file