Skip to content

Commit

Permalink
docs: update OLS now intercept (aka constant) returned first
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Feb 25, 2025
1 parent 2a245bb commit a8c95bb
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions lib/PDL/Stats/GLM.pd
Original file line number Diff line number Diff line change
Expand Up @@ -418,67 +418,57 @@ Usage:
pdl> p "$_\t@{[$m{$_} =~ /^\n*(.*?)\n*\z/s]}\n" for sort keys %m

# 2 persons' ratings, each fitted with 3 "different" models

F
[
F [
[ 38.314159 25.087209]
[ 38.314159 25.087209]
[ 38.314159 25.087209]
]

# df is the same across dv and iv models

F_df [2 7]
F_p
[
F_p [
[0.00016967051 0.00064215074]
[0.00016967051 0.00064215074]
[0.00016967051 0.00064215074]
]

R2
[
R2 [
[ 0.9162963 0.87756762]
[ 0.9162963 0.87756762]
[ 0.9162963 0.87756762]
]

b
[ # linear quadratic constant
b [ # constant linear quadratic
[
[ 0.99015152 -0.056818182 0.66363636] # person 1
[ 0.18939394 0.022727273 1.4] # person 2
[ 0.66363636 0.99015152 -0.056818182] # person 1
[ 1.4 0.18939394 0.022727273] # person 2
]
[
[ 0.49507576 -0.028409091 0.66363636]
[ 0.09469697 0.011363636 1.4]
[ 0.66363636 0.49507576 -0.028409091]
[ 1.4 0.09469697 0.011363636]
]
[
[ 0.33005051 -0.018939394 0.66363636]
[ 0.063131313 0.0075757576 1.4]
[ 0.66363636 0.33005051 -0.018939394]
[ 1.4 0.063131313 0.0075757576]
]
]

# our novice modeler realizes at this point that
# the 3 models only differ in the scaling of the IV coefficients

ss_model
[
ss_model [
[ 20.616667 13.075758]
[ 20.616667 13.075758]
[ 20.616667 13.075758]
]

ss_residual
[
ss_residual [
[ 1.8833333 1.8242424]
[ 1.8833333 1.8242424]
[ 1.8833333 1.8242424]
]

ss_total [22.5 14.9]
y_pred
[
ss_total [22.5 14.9]
y_pred [
[
[0.66363636 1.5969697 2.4166667 3.1227273 ... 4.9727273]
...
Expand Down Expand Up @@ -1446,8 +1436,7 @@ Usage:
# suppose this is a person's ratings for top 10 box office movies
# ascending sorted by box office

pdl> p $y = qsort ceil( random(10) * 5 )
[1 1 2 2 2 2 4 4 5 5]
pdl> $y = pdl '[1 1 2 2 2 2 4 4 5 5]'

# construct IV with linear and quadratic component

Expand All @@ -1459,19 +1448,18 @@ Usage:

pdl> %m = $y->ols( $x )

pdl> p "$_\t$m{$_}\n" for sort keys %m
pdl> p "$_\t@{[$m{$_} =~ /^\n*(.*?)\n*\z/s]}\n" for sort keys %m

F 40.4225352112676
F_df [2 7]
F_p 0.000142834216344756
R2 0.920314253647587

# coeff linear quadratic constant

b [0.21212121 0.03030303 0.98181818]
b_p [0.32800118 0.20303404 0.039910509]
b_se [0.20174693 0.021579989 0.38987581]
b_t [ 1.0514223 1.404219 2.5182844]
# coeff constant linear quadratic
b [0.981818 0.212121 0.030303]
b_p [0.039910 0.328001 0.203034]
b_se [0.389875 0.201746 0.021579]
b_t [2.518284 1.051422 1.404218]
ss_model 19.8787878787879
ss_residual 1.72121212121212
ss_total 21.6
Expand Down

0 comments on commit a8c95bb

Please sign in to comment.