Skip to content

Commit ccfcc57

Browse files
authored
Merge pull request #55 from lokeshh/missing_values
Remove deprecated missing value functions
2 parents 5e86599 + a410797 commit ccfcc57

29 files changed

Lines changed: 36 additions & 98 deletions

benchmarks/correlation_matrix_methods/correlation_matrix.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def prediction_optimized(vars,cases)
6060

6161
rs[:c_v] = rs.collect {|row| row[:cases]*row[:vars]}
6262

63-
rs.update
6463
rs.save("correlation_matrix.ds")
6564
Statsample::Excel.write(rs,"correlation_matrix.xls")
6665

examples/correlation_matrix.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@
77

88
require 'statsample'
99
Statsample::Analysis.store("Statsample::Bivariate.correlation_matrix") do
10-
# It so happens that Daru::Vector and Daru::DataFrame must update metadata
11-
# like positions of missing values every time they are created.
12-
#
13-
# Since we dont have any missing values in the data that we are creating,
14-
# we set Daru.lazy_update = true so that missing data is not updated every
15-
# time and things happen much faster.
16-
#
17-
# In case you do have missing data and lazy_update has been set to *true*,
18-
# you _SHOULD_ called `#update` on the concerned Vector or DataFrame object
19-
# everytime an assingment or deletion cycle is complete.
20-
Daru.lazy_update = true
21-
2210
# Create a Daru::DataFrame containing 4 vectors a, b, c and d.
2311
#
2412
# Notice that the `clone` option has been set to *false*. This tells Daru
@@ -36,10 +24,6 @@
3624
# Calculate correlation matrix by calling the `cor` shorthand.
3725
cm = cor(ds)
3826
summary(cm)
39-
40-
# Set lazy_update to *false* once our job is done so that this analysis does
41-
# not accidentally affect code elsewhere.
42-
Daru.lazy_update = false
4327
end
4428

4529
if __FILE__==$0

examples/dataset.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
require 'statsample'
77

88
Statsample::Analysis.store(Daru::DataFrame) do
9-
# We set lazy_update to *true* so that time is not wasted in updating
10-
# metdata every time an assignment happens.
11-
Daru.lazy_update = true
12-
139
samples = 1000
1410

1511
# The 'new_with_size' function lets you specify the size of the
@@ -26,9 +22,6 @@
2622
# order by default.
2723
ds = Daru::DataFrame.new({:a=>a,:b=>b}, order: [:b, :a])
2824
summary(ds)
29-
30-
# Reset lazy_update to *false* to prevent other code from breaking.
31-
Daru.lazy_update = false
3225
end
3326

3427
if __FILE__==$0

examples/dominance_analysis_bootstrap.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
require 'statsample'
44

55
Statsample::Analysis.store(Statsample::DominanceAnalysis::Bootstrap) do
6-
# Remember to call *update* after an assignment/deletion cycle if lazy_update
7-
# is *false*.
8-
Daru.lazy_update = true
9-
106
sample=300
117
a=rnorm(sample)
128
b=rnorm(sample)
@@ -29,8 +25,6 @@
2925
dab2=dominance_analysis_bootstrap(ds2, :y1, :debug=>true)
3026
dab2.bootstrap(100,nil)
3127
summary(dab2)
32-
33-
Daru.lazy_update = false
3428
end
3529

3630
if __FILE__==$0

examples/reliability.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
ds["v#{i}".to_sym]= a + rnorm(samples,0,0.2)
1616
end
1717

18-
ds.update
19-
2018
rel=Statsample::Reliability::ScaleAnalysis.new(ds)
2119
summary rel
2220

lib/statsample.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ def vector_cols_matrix(*vs)
206206
def only_valid(*vs)
207207
i = 1
208208
h = vs.inject({}) { |acc, v| acc["v#{i}".to_sym] = v; i += 1; acc }
209-
df = Daru::DataFrame.new(h).dup_only_valid
209+
df = Daru::DataFrame.new(h).reject_values(*Daru::MISSING_VALUES)
210210
df.map { |v| v }
211211
end
212212

213213
# Cheap version of #only_valid.
214214
# If any vectors have missing_values, return only valid.
215215
# If not, return the vectors itself
216216
def only_valid_clone(*vs)
217-
if vs.any?(&:has_missing_data?)
217+
if vs.any? { |v| v.include_values?(*Daru::MISSING_VALUES) }
218218
only_valid(*vs)
219219
else
220220
vs

lib/statsample/anova/oneway.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def report_building(builder) # :nodoc:
164164
if summary_descriptives
165165
s.table(:name=>_("Descriptives"),:header=>%w{Name N Mean SD Min Max}.map {|v| _(v)}) do |t|
166166
@vectors.each do |v|
167-
t.row [v.name, v.n_valid, "%0.4f" % v.mean, "%0.4f" % v.sd, "%0.4f" % v.min, "%0.4f" % v.max]
167+
t.row [v.name, v.reject_values(*Daru::MISSING_VALUES).size, "%0.4f" % v.mean, "%0.4f" % v.sd, "%0.4f" % v.min, "%0.4f" % v.max]
168168
end
169169
end
170170
end

lib/statsample/bivariate.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def covariance_matrix_optimized(ds)
159159

160160
def covariance_matrix(ds)
161161
vars,cases = ds.ncols, ds.nrows
162-
if !ds.has_missing_data? and Statsample.has_gsl? and prediction_optimized(vars,cases) < prediction_pairwise(vars,cases)
162+
if !ds.include_values?(*Daru::MISSING_VALUES) and Statsample.has_gsl? and prediction_optimized(vars,cases) < prediction_pairwise(vars,cases)
163163
cm=covariance_matrix_optimized(ds)
164164
else
165165
cm=covariance_matrix_pairwise(ds)
@@ -198,7 +198,7 @@ def covariance_matrix_pairwise(ds)
198198
# Order of rows and columns depends on Dataset#fields order
199199
def correlation_matrix(ds)
200200
vars, cases = ds.ncols, ds.nrows
201-
if !ds.has_missing_data? and Statsample.has_gsl? and prediction_optimized(vars,cases) < prediction_pairwise(vars,cases)
201+
if !ds.include_values?(*Daru::MISSING_VALUES) and Statsample.has_gsl? and prediction_optimized(vars,cases) < prediction_pairwise(vars,cases)
202202
cm=correlation_matrix_optimized(ds)
203203
else
204204
cm=correlation_matrix_pairwise(ds)
@@ -248,7 +248,7 @@ def n_valid_matrix(ds)
248248
m = vectors.collect do |row|
249249
vectors.collect do |col|
250250
if row==col
251-
ds[row].only_valid.size
251+
ds[row].reject_values(*Daru::MISSING_VALUES).size
252252
else
253253
rowa,rowb = Statsample.only_valid_clone(ds[row],ds[col])
254254
rowa.size
@@ -281,7 +281,7 @@ def spearman(v1,v2)
281281
# Calculate Point biserial correlation. Equal to Pearson correlation, with
282282
# one dichotomous value replaced by "0" and the other by "1"
283283
def point_biserial(dichotomous,continous)
284-
ds = Daru::DataFrame.new({:d=>dichotomous,:c=>continous}).dup_only_valid
284+
ds = Daru::DataFrame.new({:d=>dichotomous,:c=>continous}).reject_values(*Daru::MISSING_VALUES)
285285
raise(TypeError, "First vector should be dichotomous") if ds[:d].factors.size != 2
286286
raise(TypeError, "Second vector should be continous") if ds[:c].type != :numeric
287287
f0=ds[:d].factors.sort.to_a[0]

lib/statsample/converter/spss.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class << self
77
# ds=Daru::DataFrame.from_excel("my_data.xls")
88
# puts Statsample::SPSS.tetrachoric_correlation_matrix(ds)
99
def tetrachoric_correlation_matrix(ds)
10-
dsv=ds.dup_only_valid
10+
dsv=ds.reject_values(*Daru::MISSING_VALUES)
1111
# Delete all vectors doesn't have variation
1212
dsv.vectors.each { |f|
1313
if dsv[f].factors.size==1

lib/statsample/daru.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def histogram(bins=10)
1111
# ugly patch. The upper limit for a bin has the form
1212
# x < range
1313
#h=Statsample::Histogram.new(self, bins)
14-
valid = only_valid
14+
valid = reject_values(*Daru::MISSING_VALUES)
1515
min,max=Statsample::Util.nice(valid.min,valid.max)
1616
# fix last data
1717
if max == valid.max
@@ -72,7 +72,6 @@ def to_multiset_by_split_one_field(field)
7272
end
7373
#puts "Ingreso a los dataset"
7474
ms.datasets.each do |k,ds|
75-
ds.update
7675
ds.rename self[field].index_of(k)
7776
end
7877

@@ -102,7 +101,6 @@ def to_multiset_by_split_multiple_fields(*fields)
102101
each_row { |r| p1.call(r) }
103102

104103
ms.datasets.each do |k,ds|
105-
ds.update
106104
ds.rename(
107105
fields.size.times.map do |i|
108106
f = fields[i]

0 commit comments

Comments
 (0)