Parent

Included Modules

Class/Module Index [+]

Quicksearch

Statsample::Reliability::ScaleAnalysis

Analysis of a Scale. Analoge of Scale Reliability analysis on SPSS. Returns several statistics for complete scale and each item

Usage

@x1=[1,1,1,1,2,2,2,2,3,3,3,30].to_vector(:scale)
@x2=[1,1,1,2,2,3,3,3,3,4,4,50].to_vector(:scale)
@x3=[2,2,1,1,1,2,2,2,3,4,5,40].to_vector(:scale)
@x4=[1,2,3,4,4,4,4,3,4,4,5,30].to_vector(:scale)
ds={'x1'=>@x1,'x2'=>@x2,'x3'=>@x3,'x4'=>@x4}.to_dataset
ia=Statsample::Reliability::ScaleAnalysis.new(ds)
puts ia.summary

Attributes

ds[R]
mean[R]
sd[R]
valid_n[R]
alpha[R]
alpha_standarized[R]
variances_mean[R]
covariances_mean[R]
cov_m[R]
name[RW]
summary_histogram[RW]

Public Class Methods

new(ds, opts=Hash.new) click to toggle source
# File lib/statsample/reliability/scaleanalysis.rb, line 18
def initialize(ds, opts=Hash.new)
  @dumped=ds.fields.find_all {|f|
    ds[f].variance==0
  }
  
  @ods=ds
  @ds=ds.dup_only_valid(ds.fields - @dumped)
  
  
  @k=@ds.fields.size        
  @total=@ds.vector_sum

  @o_total=@dumped.size > 0 ? @ods.vector_sum : nil
  
  @vector_mean=@ds.vector_mean
  @item_mean=@vector_mean.mean
  @item_sd=@vector_mean.sd
  
  @mean=@total.mean
  @median=@total.median
  
  @skew=@total.skew
  @kurtosis=@total.kurtosis
  @sd = @total.sd
  @variance=@total.variance
  @valid_n = @total.size
  opts_default={
    :name=>_("Reliability Analisis"),
    :summary_histogram=>true
  }
  @opts=opts_default.merge(opts)
  @opts.each{|k,v| self.send("#{k}=",v) if self.respond_to? k }
  
  @cov_m=Statsample::Bivariate.covariance_matrix(@ds)
  # Mean for covariances and variances
  @variances=@k.times.map {|i| @cov_m[i,i]}.to_scale
  @variances_mean=@variances.mean
  @covariances_mean=(@variance-@variances.sum).quo(@k**2-@k)
  #begin
    @alpha = Statsample::Reliability.cronbach_alpha(@ds)
    @alpha_standarized = Statsample::Reliability.cronbach_alpha_standarized(@ds)
  #rescue => e
  #  raise DatasetException.new(@ds,e), "Error calculating alpha"
  #end
end

Public Instance Methods

item_characteristic_curve() click to toggle source

Returns a hash with structure

# File lib/statsample/reliability/scaleanalysis.rb, line 64
def item_characteristic_curve
  i=0
  out={}
  total={}
  @ds.each do |row|
    tot=@total[i]
    @ds.fields.each do |f|
      out[f]||= {}
      total[f]||={}
      out[f][tot]||= 0
      total[f][tot]||=0
      out[f][tot]+= row[f]
      total[f][tot]+=1
    end
    i+=1
  end
  total.each do |f,var|
    var.each do |tot,v|
      out[f][tot]=out[f][tot].quo(total[f][tot])
    end
  end
  out
end
item_difficulty_analysis() click to toggle source

Returns a dataset with cases ordered by score and variables ordered by difficulty

# File lib/statsample/reliability/scaleanalysis.rb, line 112
def item_difficulty_analysis
  dif={}
  @ds.fields.each{|f| dif[f]=@ds[f].mean }
  dif_sort=dif.sort{|a,b| -(a[1]<=>b[1])}
  scores_sort={}
  scores=@ds.vector_mean
  scores.each_index{|i| scores_sort[i]=scores[i] }
  scores_sort=scores_sort.sort{|a,b| a[1]<=>b[1]}
  ds_new=Statsample::Dataset.new(['case','score'] + dif_sort.collect{|a,b| a})
  scores_sort.each do |i,score|
    row=[i, score]
    case_row=@ds.case_as_hash(i)
    dif_sort.each{|variable,dif_value| row.push(case_row[variable]) }
    ds_new.add_case_array(row)
  end
  ds_new.update_valid_data
  ds_new
end
item_statistics() click to toggle source
# File lib/statsample/reliability/scaleanalysis.rb, line 103
def item_statistics
    @is||=@ds.fields.inject({}) do |a,v|
      a[v]={:mean=>@ds[v].mean, :sds=>Math::sqrt(@cov_m.variance(v))}
      a
    end
end
item_total_correlation() click to toggle source

Adjusted R.P.B. for each item

Adjusted RPB(Point biserial-correlation) for each item

# File lib/statsample/reliability/scaleanalysis.rb, line 90
def item_total_correlation
  @itc||=@ds.fields.inject({}) do |a,v|
    vector=@ds[v].clone
    ds2=@ds.clone
    ds2.delete_vector(v)
    total=ds2.vector_sum
    a[v]=Statsample::Bivariate.pearson(vector,total)
    a
  end
end
mean_rpb() click to toggle source
# File lib/statsample/reliability/scaleanalysis.rb, line 100
def mean_rpb
  item_total_correlation.values.to_scale.mean
end
stats_if_deleted() click to toggle source
# File lib/statsample/reliability/scaleanalysis.rb, line 131
def stats_if_deleted
  @sif||=stats_if_deleted_intern
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.