Skip to content

Commit 162ca0a

Browse files
committed
fix resids being off when there is no constant term
1 parent 953240a commit 162ca0a

15 files changed

+120
-70
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ All formats have their own format options, which can be passed into the `format_
224224
- **coefficient_column_name** (default = `'coefficient'`): Column name storing model coefficients.
225225
- **strip_quotes** (default = `True`): If true, strip outer quotes from column names if provided; if false, always use string literals.
226226

227-
These options are only available when `method='chol'`:
227+
These options are available for `format='long'` only when `method='chol'`:
228228

229-
- **calculate_standard_error** (default = `'calculate_standard_error'`): If true, provide the standard error in the output.
229+
- **calculate_standard_error** (default = `True if not alpha else False`): If true, provide the standard error in the output.
230230
- **standard_error_column_name** (default = `'standard_error'`): Column name storing the standard error for the parameter.
231231
-- **t_statistic_column_name** (default = `'t_statistic'`): Column name storing the t-statistic for the parameter.
232232

integration_tests/tests/test_collinear_matrix_1var_without_const.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ with
22

33
expected as (
44

5-
select 'x1' as variable_name, 30.500076644845674 as coefficient
5+
select 'x1' as variable_name, 30.500076644845674 as coefficient, 0.8396121329329627 as standard_error, 36.326388636502585 as t_statistic
66

77
)
88

@@ -11,5 +11,10 @@ from {{ ref('collinear_matrix_1var_without_const') }} as base
1111
full outer join expected
1212
on base.variable_name = expected.variable_name
1313
where
14-
round(base.coefficient, 7) - round(expected.coefficient, 7)
14+
round(base.coefficient, 7) != round(expected.coefficient, 7)
15+
or round(base.standard_error, 7) != round(expected.standard_error, 7)
16+
or round(base.t_statistic, 7) != round(expected.t_statistic, 7)
1517
or base.coefficient is null
18+
or base.standard_error is null
19+
or base.t_statistic is null
20+
or expected.coefficient is null

integration_tests/tests/test_collinear_matrix_2var_without_const.sql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ with
22

33
expected as (
44

5-
select 'x1' as variable_name, 63.18154691334764 as coefficient
5+
select 'x1' as variable_name, 63.18154691334764 as coefficient, 0.4056389914380657 as standard_error, 155.75807120848344 as t_statistic
66
union all
7-
select 'x2' as variable_name, 55.39820150046505 as coefficient
7+
select 'x2' as variable_name, 55.39820150046505 as coefficient, 0.2738669097295638 as standard_error, 202.2814715190283 as t_statistic
88

99
)
1010

@@ -13,5 +13,10 @@ from {{ ref('collinear_matrix_2var_without_const') }} as base
1313
full outer join expected
1414
on base.variable_name = expected.variable_name
1515
where
16-
round(base.coefficient, 7) - round(expected.coefficient, 7)
16+
round(base.coefficient, 7) != round(expected.coefficient, 7)
17+
or round(base.standard_error, 7) != round(expected.standard_error, 7)
18+
or round(base.t_statistic, 7) != round(expected.t_statistic, 7)
1719
or base.coefficient is null
20+
or base.standard_error is null
21+
or base.t_statistic is null
22+
or expected.coefficient is null

integration_tests/tests/test_collinear_matrix_3var_without_const.sql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ with
22

33
expected as (
44

5-
select 'x1' as variable_name, 20.090207982897063 as coefficient
5+
select 'x1' as variable_name, 20.090207982897063 as coefficient, 0.5196176972417176 as standard_error, 38.6634406209445 as t_statistic
66
union all
7-
select 'x2' as variable_name, -16.533211090826203 as coefficient
7+
select 'x2' as variable_name, -16.533211090826203 as coefficient, 0.7481701784700665 as standard_error, -22.098195793682894 as t_statistic
88
union all
9-
select 'x3' as variable_name, 35.00389104686492 as coefficient
9+
select 'x3' as variable_name, 35.00389104686492 as coefficient, 0.351617515124373 as standard_error, 99.55104493154575 as t_statistic
1010

1111
)
1212

@@ -15,5 +15,10 @@ from {{ ref('collinear_matrix_3var_without_const') }} as base
1515
full outer join expected
1616
on base.variable_name = expected.variable_name
1717
where
18-
round(base.coefficient, 7) - round(expected.coefficient, 7)
18+
round(base.coefficient, 7) != round(expected.coefficient, 7)
19+
or round(base.standard_error, 7) != round(expected.standard_error, 7)
20+
or round(base.t_statistic, 7) != round(expected.t_statistic, 7)
1921
or base.coefficient is null
22+
or base.standard_error is null
23+
or base.t_statistic is null
24+
or expected.coefficient is null

integration_tests/tests/test_collinear_matrix_4var_without_const.sql

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ with
22

33
expected as (
44

5-
select 'x1' as variable_name, 20.587532776354163 as coefficient
5+
select 'x1' as variable_name, 20.587532776354163 as coefficient, 0.5176259827853541 as standard_error, 39.772989496339235 as t_statistic
66
union all
7-
select 'x2' as variable_name, -20.41001520357013 as coefficient
7+
select 'x2' as variable_name, -20.41001520357013 as coefficient, 0.8103907603637923 as standard_error, -25.185399688426696 as t_statistic
88
union all
9-
select 'x3' as variable_name, 35.084935774341524 as coefficient
9+
select 'x3' as variable_name, 35.084935774341524 as coefficient, 0.34920588221192245 as standard_error, 100.4706322588505 as t_statistic
1010
union all
11-
select 'x4' as variable_name, 1.8960558858899716 as coefficient
11+
select 'x4' as variable_name, 1.8960558858899716 as coefficient, 0.1583538085466205 as standard_error, 11.973541421529871 as t_statistic
1212

1313
)
1414

@@ -17,5 +17,10 @@ from {{ ref('collinear_matrix_4var_without_const') }} as base
1717
full outer join expected
1818
on base.variable_name = expected.variable_name
1919
where
20-
round(base.coefficient, 7) - round(expected.coefficient, 7)
20+
round(base.coefficient, 7) != round(expected.coefficient, 7)
21+
or round(base.standard_error, 7) != round(expected.standard_error, 7)
22+
or round(base.t_statistic, 7) != round(expected.t_statistic, 7)
2123
or base.coefficient is null
24+
or base.standard_error is null
25+
or base.t_statistic is null
26+
or expected.coefficient is null

integration_tests/tests/test_collinear_matrix_5var_without_const.sql

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ with
22

33
expected as (
44

5-
select 'x1' as variable_name, 11.392300499659957 as coefficient
5+
select 'x1' as variable_name, 11.392300499659957 as coefficient, 0.5240533254061608 as standard_error, 21.73881921430515 as t_statistic
66
union all
7-
select 'x2' as variable_name, 2.333060182571783 as coefficient
7+
select 'x2' as variable_name, 2.333060182571783 as coefficient, 0.9201150492406911 as standard_error, 2.5356178931070636 as t_statistic
88
union all
9-
select 'x3' as variable_name, 21.895814737788875 as coefficient
9+
select 'x3' as variable_name, 21.895814737788875 as coefficient, 0.44810399169425286 as standard_error, 48.8632441210849 as t_statistic
1010
union all
11-
select 'x4' as variable_name, 3.4480236159406785 as coefficient
11+
select 'x4' as variable_name, 3.4480236159406785 as coefficient, 0.1504072830205524 as standard_error, 22.92457882820424 as t_statistic
1212
union all
13-
select 'x5' as variable_name, 15.766951731565559 as coefficient
13+
select 'x5' as variable_name, 15.766951731565559 as coefficient, 0.37297028350495787 as standard_error, 42.274015997727524 as t_statistic
1414

1515
)
1616

@@ -19,5 +19,10 @@ from {{ ref('collinear_matrix_5var_without_const') }} as base
1919
full outer join expected
2020
on base.variable_name = expected.variable_name
2121
where
22-
round(base.coefficient, 7) - round(expected.coefficient, 7)
22+
round(base.coefficient, 7) != round(expected.coefficient, 7)
23+
or round(base.standard_error, 7) != round(expected.standard_error, 7)
24+
or round(base.t_statistic, 7) != round(expected.t_statistic, 7)
2325
or base.coefficient is null
26+
or base.standard_error is null
27+
or base.t_statistic is null
28+
or expected.coefficient is null

integration_tests/tests/test_collinear_matrix_regression_chol.sql

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@ with
22

33
expected as (
44

5-
select 'const' as variable_name, 19.757104885315176 as coefficient
5+
select 'const' as variable_name, 19.757104885315176 as coefficient, 2.992803142237603 as standard_error, 6.601538406078909 as t_statistic
66
union all
7-
select 'x1' as variable_name, 9.90708767581426 as coefficient
7+
select 'x1' as variable_name, 9.90708767581426 as coefficient, 0.5692826957191374 as standard_error, 17.402755696445837 as t_statistic
88
union all
9-
select 'x2' as variable_name, 6.187473206056227 as coefficient
9+
select 'x2' as variable_name, 6.187473206056227 as coefficient, 1.0880807259333622 as standard_error, 5.686593888287631 as t_statistic
1010
union all
11-
select 'x3' as variable_name, 19.66874583168642 as coefficient
11+
select 'x3' as variable_name, 19.66874583168642 as coefficient, 0.5601379212447676 as standard_error, 35.11411223146169 as t_statistic
1212
union all
13-
select 'x4' as variable_name, 3.7192417102253468 as coefficient
13+
select 'x4' as variable_name, 3.7192417102253468 as coefficient, 0.15560940177101745 as standard_error, 23.901137514160553 as t_statistic
1414
union all
15-
select 'x5' as variable_name, 13.444273483323244 as coefficient
15+
select 'x5' as variable_name, 13.444273483323244 as coefficient, 0.5121595119107619 as standard_error, 26.250168493728488 as t_statistic
1616

1717
)
1818

19-
select base.variable_name
19+
select base.*
2020
from {{ ref('collinear_matrix_regression_chol') }} as base
2121
full outer join expected
2222
on base.variable_name = expected.variable_name
2323
where
24-
round(base.coefficient, 7) - round(expected.coefficient, 7)
24+
round(base.coefficient, 7) != round(expected.coefficient, 7)
25+
or round(base.standard_error, 7) != round(expected.standard_error, 7)
26+
or round(base.t_statistic, 7) != round(expected.t_statistic, 7)
2527
or base.coefficient is null
28+
or base.standard_error is null
29+
or base.t_statistic is null
30+
or expected.coefficient is null

integration_tests/tests/test_collinear_matrix_regression_chol_unoptimized.sql

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@ with
22

33
expected as (
44

5-
select 'const' as variable_name, 19.757104885315176 as coefficient
5+
select 'const' as variable_name, 19.757104885315176 as coefficient, 2.992803142237603 as standard_error, 6.601538406078909 as t_statistic
66
union all
7-
select 'x1' as variable_name, 9.90708767581426 as coefficient
7+
select 'x1' as variable_name, 9.90708767581426 as coefficient, 0.5692826957191374 as standard_error, 17.402755696445837 as t_statistic
88
union all
9-
select 'x2' as variable_name, 6.187473206056227 as coefficient
9+
select 'x2' as variable_name, 6.187473206056227 as coefficient, 1.0880807259333622 as standard_error, 5.686593888287631 as t_statistic
1010
union all
11-
select 'x3' as variable_name, 19.66874583168642 as coefficient
11+
select 'x3' as variable_name, 19.66874583168642 as coefficient, 0.5601379212447676 as standard_error, 35.11411223146169 as t_statistic
1212
union all
13-
select 'x4' as variable_name, 3.7192417102253468 as coefficient
13+
select 'x4' as variable_name, 3.7192417102253468 as coefficient, 0.15560940177101745 as standard_error, 23.901137514160553 as t_statistic
1414
union all
15-
select 'x5' as variable_name, 13.444273483323244 as coefficient
15+
select 'x5' as variable_name, 13.444273483323244 as coefficient, 0.5121595119107619 as standard_error, 26.250168493728488 as t_statistic
1616

1717
)
1818

19-
select base.variable_name
19+
select base.*
2020
from {{ ref('collinear_matrix_regression_chol_unoptimized') }} as base
2121
full outer join expected
2222
on base.variable_name = expected.variable_name
2323
where
24-
round(base.coefficient, 7) - round(expected.coefficient, 7)
24+
round(base.coefficient, 7) != round(expected.coefficient, 7)
25+
or round(base.standard_error, 7) != round(expected.standard_error, 7)
26+
or round(base.t_statistic, 7) != round(expected.t_statistic, 7)
2527
or base.coefficient is null
28+
or base.standard_error is null
29+
or base.t_statistic is null
30+
or expected.coefficient is null

integration_tests/tests/test_collinear_matrix_regression_fwl.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ from {{ ref('collinear_matrix_regression_fwl') }} as base
2121
full outer join expected
2222
on base.variable_name = expected.variable_name
2323
where
24-
round(base.coefficient, 7) - round(expected.coefficient, 7)
24+
round(base.coefficient, 7) != round(expected.coefficient, 7)
2525
or base.coefficient is null
26+
or expected.coefficient is null

integration_tests/tests/test_groups_matrix_regression_chol.sql

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ with
22

33
expected as (
44

5-
select 'a' as gb_var, 'const' as variable_name, -0.06563066041472207 as coefficient
5+
select 'a' as gb_var, 'const' as variable_name, -0.06563066041472207 as coefficient, 0.053945103940799474 as standard_error, -1.2166194078844779 as t_statistic
66
union all
7-
select 'a' as gb_var, 'x1' as variable_name, 0.9905419281557593 as coefficient
7+
select 'a' as gb_var, 'x1' as variable_name, 0.9905419281557593 as coefficient, 0.015209571618398615 as standard_error, 65.12622136954383 as t_statistic
88
union all
9-
select 'a' as gb_var, 'x2' as variable_name, 4.948221700496285 as coefficient
9+
select 'a' as gb_var, 'x2' as variable_name, 4.948221700496285 as coefficient, 0.02906881854690807 as standard_error, 170.2243829590593 as t_statistic
1010
union all
11-
select 'a' as gb_var, 'x3' as variable_name, 0.031234030051974747 as coefficient
11+
select 'a' as gb_var, 'x3' as variable_name, 0.031234030051974747 as coefficient, 0.014337008978330493 as standard_error, 2.178559705108859 as t_statistic
1212
union all
13-
select 'b' as gb_var, 'const' as variable_name, 2.0117130483709955 as coefficient
13+
select 'b' as gb_var, 'const' as variable_name, 2.0117130483709955 as coefficient, 0.035587045398501334 as standard_error, 56.529364150464545 as t_statistic
1414
union all
15-
select 'b' as gb_var, 'x1' as variable_name, 2.996331112245573 as coefficient
15+
select 'b' as gb_var, 'x1' as variable_name, 2.996331112245573 as coefficient, 0.006731681784764358 as standard_error, 445.1088462064698 as t_statistic
1616
union all
17-
select 'b' as gb_var, 'x2' as variable_name, 9.019683491736044 as coefficient
17+
select 'b' as gb_var, 'x2' as variable_name, 9.019683491736044 as coefficient, 0.008744674914389008 as standard_error, 1031.4486907791759 as t_statistic
1818
union all
19-
select 'b' as gb_var, 'x3' as variable_name, 0.016151316166848173 as coefficient
19+
select 'b' as gb_var, 'x3' as variable_name, 0.016151316166848173 as coefficient, 0.0072206704541224525 as standard_error, 2.2368166875178472 as t_statistic
2020

2121
)
2222

@@ -27,5 +27,10 @@ on
2727
base.gb_var = expected.gb_var
2828
and base.variable_name = expected.variable_name
2929
where
30-
round(base.coefficient, 7) - round(expected.coefficient, 7)
30+
round(base.coefficient, 7) != round(expected.coefficient, 7)
31+
or round(base.standard_error, 7) != round(expected.standard_error, 7)
32+
or round(base.t_statistic, 7) != round(expected.t_statistic, 7)
3133
or base.coefficient is null
34+
or base.standard_error is null
35+
or base.t_statistic is null
36+
or expected.coefficient is null

0 commit comments

Comments
 (0)