Skip to content

Commit 888cefd

Browse files
Merge pull request #83 from sem-in-r/reproducibility
tolerance for floating point calcs
2 parents cdf2837 + 2c71430 commit 888cefd

File tree

7 files changed

+49
-49
lines changed

7 files changed

+49
-49
lines changed

tests/testthat/test-bootstrap.R

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ bootmatrix_control <- as.matrix(read.csv("../fixtures/boostrapmatrix1.csv", row.
3535
# Testing
3636

3737
test_that("Seminr performs the bootstrapping correctly", {
38-
expect_equal(bootmatrix[,1], bootmatrix_control[,1])
39-
expect_equal(bootmatrix[,2], bootmatrix_control[,2])
40-
expect_equal(bootmatrix[,3], bootmatrix_control[,3])
38+
expect_equal(bootmatrix[,1], bootmatrix_control[,1], tolerance = 0.00001)
39+
expect_equal(bootmatrix[,2], bootmatrix_control[,2], tolerance = 0.00001)
40+
expect_equal(bootmatrix[,3], bootmatrix_control[,3], tolerance = 0.00001)
4141
})
4242

4343
context("SEMinR correctly bootstraps the interaction model\n")
@@ -84,9 +84,9 @@ bootmatrix_control <- as.matrix(read.csv("../fixtures/boostrapmatrix2.csv", row.
8484
# Testing
8585

8686
test_that("Seminr performs the bootstrapping correctly", {
87-
expect_equal(bootmatrix[,1], bootmatrix_control[,1])
88-
expect_equal(bootmatrix[,2], bootmatrix_control[,2])
89-
expect_equal(bootmatrix[,3], bootmatrix_control[,3])
87+
expect_equal(bootmatrix[,1], bootmatrix_control[,1], tolerance = 0.00001)
88+
expect_equal(bootmatrix[,2], bootmatrix_control[,2], tolerance = 0.00001)
89+
expect_equal(bootmatrix[,3], bootmatrix_control[,3], tolerance = 0.00001)
9090
})
9191

9292
context("SEMinR correctly bootstraps the model weights - composite measurement mode\n")
@@ -126,9 +126,9 @@ bootmatrix_control <- as.matrix(read.csv("../fixtures/boot_weights.csv", row.nam
126126
# Testing
127127

128128
test_that("Seminr performs the bootstrapping correctly", {
129-
expect_equal(bootmatrix[,1], bootmatrix_control[,1])
130-
expect_equal(bootmatrix[,2], bootmatrix_control[,2])
131-
expect_equal(bootmatrix[,3], bootmatrix_control[,3])
129+
expect_equal(bootmatrix[,1], bootmatrix_control[,1], tolerance = 0.00001)
130+
expect_equal(bootmatrix[,2], bootmatrix_control[,2], tolerance = 0.00001)
131+
expect_equal(bootmatrix[,3], bootmatrix_control[,3], tolerance = 0.00001)
132132
})
133133

134134
context("SEMinR correctly bootstraps the model loadings - factor measurement mode\n")
@@ -168,9 +168,9 @@ bootmatrix_control <- as.matrix(read.csv("../fixtures/boot_loadings.csv", row.na
168168
# Testing
169169

170170
test_that("Seminr performs the bootstrapping correctly", {
171-
expect_equal(bootmatrix[,1], bootmatrix_control[,1])
172-
expect_equal(bootmatrix[,2], bootmatrix_control[,2])
173-
expect_equal(bootmatrix[,3], bootmatrix_control[,3])
171+
expect_equal(bootmatrix[,1], bootmatrix_control[,1], tolerance = 0.00001)
172+
expect_equal(bootmatrix[,2], bootmatrix_control[,2], tolerance = 0.00001)
173+
expect_equal(bootmatrix[,3], bootmatrix_control[,3], tolerance = 0.00001)
174174
})
175175

176176

@@ -190,7 +190,7 @@ bootmatrix_control <- as.matrix(read.csv("../fixtures/boot_HTMT.csv", row.names
190190
# Testing
191191

192192
test_that("Seminr performs the bootstrapping correctly", {
193-
expect_equal(bootmatrix[,1], bootmatrix_control[,1])
194-
expect_equal(bootmatrix[,2], bootmatrix_control[,2])
195-
expect_equal(bootmatrix[,3], bootmatrix_control[,3])
193+
expect_equal(bootmatrix[,1], bootmatrix_control[,1], tolerance = 0.00001)
194+
expect_equal(bootmatrix[,2], bootmatrix_control[,2], tolerance = 0.00001)
195+
expect_equal(bootmatrix[,3], bootmatrix_control[,3], tolerance = 0.00001)
196196
})

tests/testthat/test-consistent.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ rho_control <- as.matrix(read.csv("../fixtures/rho1.csv", row.names = 1))
3434
# Testing
3535

3636
test_that("Seminr estimates rhoA correctly\n", {
37-
expect_equal(rho, rho_control)
37+
expect_equal(rho, rho_control, tolerance = 0.00001)
3838
})
3939

4040
context("SEMinR correctly estimates rhoA for the interaction model\n")
@@ -80,7 +80,7 @@ rho_control <- as.matrix(read.csv("../fixtures/rho2.csv", row.names = 1))
8080
# Testing
8181

8282
test_that("Seminr estimates rho_A correctly\n", {
83-
expect_equal(rho, rho_control)
83+
expect_equal(rho, rho_control, tolerance = 0.00001)
8484
})
8585

8686
context("SEMinR correctly estimates PLSc path coefficients, rsquared and loadings for the simple model\n")
@@ -126,15 +126,15 @@ rSquared_control <- as.matrix(read.csv("../fixtures/rsquaredplsc.csv", row.names
126126
# Testing
127127

128128
test_that("Seminr estimates PLSc path coefficients correctly\n", {
129-
expect_equal(path_coef, path_coef_control)
129+
expect_equal(path_coef, path_coef_control, tolerance = 0.00001)
130130
})
131131

132132
test_that("Seminr estimates PLSc loadings correctly\n", {
133-
expect_equal(loadings, loadings_control)
133+
expect_equal(loadings, loadings_control, tolerance = 0.00001)
134134
})
135135

136136
test_that("Seminr estimates rsquared correctly\n", {
137137
# remove BIC for now
138138
#expect_equal(rSquared, rSquared_control)
139-
expect_equal(rSquared[1:2,], rSquared_control[1:2,])
139+
expect_equal(rSquared[1:2,], rSquared_control[1:2,], tolerance = 0.00001)
140140
})

tests/testthat/test-inner_weighting.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ weight_control <- as.matrix(read.csv("../fixtures/inner_weights_weights.csv", ro
4242
# Testing
4343

4444
test_that("Seminr estimates the loadings and path coefficients correctly", {
45-
expect_equal(coefficients[,4], coefficients_control[,4])
45+
expect_equal(coefficients[,4], coefficients_control[,4], tolerance = 0.00001)
4646
})
4747

4848
test_that("Seminr estimates the construct scores correctly", {
49-
expect_equal(construct_scores[,1:4], construct_scores_control[,1:4])
49+
expect_equal(construct_scores[,1:4], construct_scores_control[,1:4], tolerance = 0.00001)
5050
})
5151

5252
test_that("Seminr estimates the outer weights correctly", {
53-
expect_equal(weight, weight_control)
53+
expect_equal(weight, weight_control, tolerance = 0.00001)
5454
})
5555

5656
context("SEMinR correctly estimates the model using factorial scheme\n")
@@ -97,13 +97,13 @@ weight_control <- as.matrix(read.csv("../fixtures/factorial_weights.csv", row.na
9797
# Testing
9898

9999
test_that("Seminr estimates the loadings and path coefficients correctly", {
100-
expect_equal(coefficients[,4], coefficients_control[,4])
100+
expect_equal(coefficients[,4], coefficients_control[,4], tolerance = 0.00001)
101101
})
102102

103103
test_that("Seminr estimates the scores correctly", {
104-
expect_equal(construct_scores[,1:4], construct_scores_control[,1:4])
104+
expect_equal(construct_scores[,1:4], construct_scores_control[,1:4], tolerance = 0.00001)
105105
})
106106

107107
test_that("Seminr estimates the outer weights correctly", {
108-
expect_equal(weight, weight_control)
108+
expect_equal(weight, weight_control, tolerance = 0.00001)
109109
})

tests/testthat/test-metric.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ rsquared_control <- as.matrix(read.csv("../fixtures/rsquared1.csv", row.names =
3838

3939
test_that("Seminr estimates the Rsquared correctly", {
4040
# Remove BIC for now
41-
expect_equal(rsquared[1:2,1], rsquared_control[1:2,1])
41+
expect_equal(rsquared[1:2,1], rsquared_control[1:2,1], tolerance = 0.00001)
4242
})
4343

tests/testthat/test-output.r

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ weight_control <- as.matrix(read.csv("../fixtures/weights.csv", row.names=1, che
4848
# Testing
4949

5050
test_that("Seminr estimates the loadings and path coefficients correctly", {
51-
expect_equal(coefficients[,6], coefficients_control[,6])
51+
expect_equal(coefficients[,6], coefficients_control[,6], tolerance = 0.00001)
5252
})
5353

5454
test_that("Seminr estimates the construct scores correctly", {
55-
expect_equal(construct_scores[,1:6], construct_scores_control[,1:6])
55+
expect_equal(construct_scores[,1:6], construct_scores_control[,1:6], tolerance = 0.00001)
5656
})
5757

5858
test_that("Seminr estimates the outer weights correctly", {
59-
expect_equal(weight, weight_control)
59+
expect_equal(weight, weight_control, tolerance = 0.00001)
6060
})
6161

6262
context("SEMinR correctly estimates the model scaled product indicator\n")
@@ -109,14 +109,14 @@ weight_control <- as.matrix(read.csv("../fixtures/weights2.csv", row.names=1, ch
109109
# Testing
110110

111111
test_that("Seminr estimates the loadings and path coefficients correctly", {
112-
expect_equal(coefficients[,6], coefficients_control[,6])
112+
expect_equal(coefficients[,6], coefficients_control[,6], tolerance = 0.00001)
113113
})
114114

115115
test_that("Seminr estimates the construct scores correctly", {
116-
expect_equal(construct_scores[,1:6], construct_scores_control[,1:6])
116+
expect_equal(construct_scores[,1:6], construct_scores_control[,1:6], tolerance = 0.00001)
117117
})
118118

119119
test_that("Seminr estimates the outer weights correctly", {
120-
expect_equal(weight, weight_control)
120+
expect_equal(weight, weight_control, tolerance = 0.00001)
121121
})
122122

tests/testthat/test-summary.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ reliability_control <- as.matrix(read.csv("../fixtures/reliability.csv", row.nam
4343
#})
4444

4545
test_that("Seminr estimates the cross-loadings correctly", {
46-
expect_equal(cross_loadings, cross_loadings_control)
46+
expect_equal(cross_loadings, cross_loadings_control, tolerance = 0.00001)
4747
})
4848

4949
test_that("Seminr estimates the reliability correctly", {
50-
expect_equal(reliability, reliability_control)
50+
expect_equal(reliability, reliability_control, tolerance = 0.00001)
5151
})
5252

5353
context("SEMinR correctly returns the summary object for class boot_seminr_model\n")
@@ -87,11 +87,11 @@ p_values_control <- as.matrix(read.csv("../fixtures/pvalues.csv", row.names = 1)
8787
# Testing
8888

8989
test_that("Seminr estimates the t-values correctly", {
90-
expect_equal(t_values, t_values_control)
90+
expect_equal(t_values, t_values_control, tolerance = 0.00001)
9191
})
9292

9393
test_that("Seminr estimates the p-values correctly", {
94-
expect_equal(p_values, p_values_control)
94+
expect_equal(p_values, p_values_control, tolerance = 0.00001)
9595
})
9696

9797
context("SEMinR:::evaluate_measurement_model() correctly evaluates FACTORS for class seminr_model\n")
@@ -133,15 +133,15 @@ factor_discriminant_validity_control <- as.matrix(read.csv("../fixtures/factor_d
133133
# Testing
134134

135135
test_that("Seminr evaluates the factor reliability correctly", {
136-
expect_equal(factor_reliability,factor_reliability_control)
136+
expect_equal(factor_reliability,factor_reliability_control, tolerance = 0.00001)
137137
})
138138

139139
test_that("Seminr evaluates the factor indicator reliability correctly", {
140-
expect_equal(factor_indicator_reliability,factor_indicator_reliability_control)
140+
expect_equal(factor_indicator_reliability,factor_indicator_reliability_control, tolerance = 0.00001)
141141
})
142142

143143
test_that("Seminr evaluates the factor reliability correctly", {
144-
expect_equal(factor_discriminant_validity,factor_discriminant_validity_control)
144+
expect_equal(factor_discriminant_validity,factor_discriminant_validity_control, tolerance = 0.00001)
145145
})
146146

147147
context("SEMinR:::evaluate_measurement_model() correctly evaluates COMPOSITES for class seminr_model\n")
@@ -160,11 +160,11 @@ composite_collinearity_control <- read.csv("../fixtures/composite_collinearity.c
160160
# Testing
161161

162162
test_that("Seminr evaluates the composite indicator reliability correctly", {
163-
expect_equal(composite_indicator_reliability,composite_indicator_reliability_control)
163+
expect_equal(composite_indicator_reliability,composite_indicator_reliability_control, tolerance = 0.00001)
164164
})
165165

166166
test_that("Seminr evaluates the composite collinearity correctly", {
167-
expect_equal(unname(composite_collinearity[1:5]),composite_collinearity_control[1:5,1])
167+
expect_equal(unname(composite_collinearity[1:5]),composite_collinearity_control[1:5,1], tolerance = 0.00001)
168168
})
169169

170170
context("SEMinR:::boot_evaluate_measurement_model() correctly evaluates FACTORS for class boot_seminr_model\n")
@@ -183,11 +183,11 @@ factor_discriminant_validity_p_values_control <- as.matrix(read.csv("../fixtures
183183
# Testing
184184

185185
test_that("Seminr evaluates the factor discriminant validity t_values control correctly", {
186-
expect_equal(factor_discriminant_validity_t_values, factor_discriminant_validity_t_values_control)
186+
expect_equal(factor_discriminant_validity_t_values, factor_discriminant_validity_t_values_control, tolerance = 0.00001)
187187
})
188188

189189
test_that("Seminr evaluates the factor discriminant validity p_values correctly", {
190-
expect_equal(factor_discriminant_validity_p_values, factor_discriminant_validity_p_values_control)
190+
expect_equal(factor_discriminant_validity_p_values, factor_discriminant_validity_p_values_control, tolerance = 0.00001)
191191
})
192192

193193
context("SEMinR:::boot_evaluate_measurement_model() correctly evaluates COMPOSITES for class boot_seminr_model\n")
@@ -206,9 +206,9 @@ composite_indicator_weights_p_values_control <- as.matrix(read.csv("../fixtures/
206206
# Testing
207207

208208
test_that("Seminr evaluates the composite indicator t values correctly", {
209-
expect_equal(composite_indicator_weights_t_values, composite_indicator_weights_t_values_control)
209+
expect_equal(composite_indicator_weights_t_values, composite_indicator_weights_t_values_control, tolerance = 0.00001)
210210
})
211211

212212
test_that("Seminr evaluates the composite collinearity correctly", {
213-
expect_equal(composite_indicator_weights_p_values, composite_indicator_weights_p_values_control)
213+
expect_equal(composite_indicator_weights_p_values, composite_indicator_weights_p_values_control, tolerance = 0.00001)
214214
})

tests/testthat/test_validity.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ correct_vif_antecedents2 <- read.csv("../fixtures/vifs/flat_vif_antecedents2.csv
5252

5353
## Tests ----
5454
test_that("Seminr computes the item VIFs correctly", {
55-
expect_equal(flat_vif_items1, correct_item_vifs1)
55+
expect_equal(flat_vif_items1, correct_item_vifs1, tolerance = 0.00001)
5656
})
5757

5858
test_that("Seminr computes the antecedent VIFs correctly for single endogenous variable", {
59-
expect_equal(flat_vif_antecedents1, correct_vif_antecedents1)
59+
expect_equal(flat_vif_antecedents1, correct_vif_antecedents1, tolerance = 0.00001)
6060
})
6161

6262
test_that("Seminr computes the antecedent VIFs correctly for multiple endogenous variables", {
63-
expect_equal(flat_vif_antecedents2, correct_vif_antecedents2)
63+
expect_equal(flat_vif_antecedents2, correct_vif_antecedents2, tolerance = 0.00001)
6464
})

0 commit comments

Comments
 (0)