-
Notifications
You must be signed in to change notification settings - Fork 0
/
PCM20230424_ISLR2_2.1.1_What_Is_Statistical_Learning.jl
2364 lines (1989 loc) · 90.8 KB
/
PCM20230424_ISLR2_2.1.1_What_Is_Statistical_Learning.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### A Pluto.jl notebook ###
# v0.19.25
using Markdown
using InteractiveUtils
# ╔═╡ 849dbc25-8dd1-416b-b706-672e826eec6a
using CSV, Plots, GLM, LsqFit, Statistics,StatsPlots, HypothesisTests
# ╔═╡ faef2569-8983-4704-9e1a-7080fb16dd06
md"
=====================================================================================
#### ISLR2_2.1.1 What Is Statistical Learning ?
##### file: PCM20230424\_ISLR2\_2.1.1\_What\_Is\_Statistical\_Learning.jl
##### Julia/Pluto (1.9.0/0.19.25) by PCM *** 2023/05/15 ***
=====================================================================================
"
# ╔═╡ abc89755-f470-4958-916a-fec048e28189
md"
*Statistical learning* to me means describing data using *adaptive, parsimonious* mathematical expressions, *inductively* determining the *generative* or *causal* mechanisms that produces s*sample* of data from well-defined *populations*. Of lesser importance to me are *deep learning* methods that analyze *large* data sets that define populations by themselves.
"
# ╔═╡ 622d27ff-e36f-4b69-949d-1fa78a8413ce
md"
---
#### 1. The *Advertising* Data Set
##### 1.1 Dataframe
"
# ╔═╡ 7b047630-b637-47ee-9aee-6d685dd3e773
advertisingDataFrame = CSV.File("C:/Users/claus/Nextcloud/PCM_Book/PCM2023_ISLR_Data/AdvertisingData/AdvertisingData.csv")
# ╔═╡ f698b886-e349-436f-932d-657bf7ff1eb5
md"
---
##### 1.2 ISLR2, Fig.2.2
###### 1.2.1 2D-Plot $Sales \times TV\text{-}Advertising$
"
# ╔═╡ de0c31cf-a954-41fb-afca-a03cf28364dc
let
#-------------------------------------------------------------------------------
plot(title="Sales X TV-Advertising (ISLR2e, Fig. 2.1 - left)", xlims=(-10,320), ylims=(0,32))
plot!(advertisingDataFrame.TV, advertisingDataFrame.Sales, seriestype=:scatter, label="(TV, Sales)", xlabel="advertisingDataFrame.TV", ylabel="advertisingDataFrame.Sales")
#-------------------------------------------------------------------------------
end # let
# ╔═╡ b852829d-0da2-44db-b7ed-9bf390858882
md"
---
###### 1.2.2 Linear Univariate OLS-Regression Model $f(X)=\beta_0 + \beta_1X_1$
where $Y=Sales$ and $X_1=TV\text{-}Advertising$
"
# ╔═╡ 009a4323-0593-4900-b0d9-e2c4fc7a8756
let
ols_lin = lm(@formula(Sales ~ TV), advertisingDataFrame)
yHat = predict(ols_lin)
rxy = round(cor(advertisingDataFrame.TV, advertisingDataFrame.Sales), digits=3)
ryyHat = round(cor(advertisingDataFrame.Sales, yHat), digits=3)
ryyHatsQ = round(ryyHat^2, digits=3)
#--------------------------------------------------------------------------------
plot(title="Sales -> TV-Advertising (ISLR2e, Fig. 2.1 - left)", xlims=(-10,320), ylims=(0,32))
plot!(advertisingDataFrame.TV, advertisingDataFrame.Sales, seriestype=:scatter, label="(TV, Sales)", xlabel="advertisingDataFrame.TV", ylabel="advertisingDataFrame.Sales")
plot!(advertisingDataFrame.TV, yHat, seriestype=:line, width=2, label="(TV, Sales^)")
#--------------------------------------------------------------------------------
annotate!(72, 22.5, "r(Sales, TV) = $rxy", 10)
annotate!(62, 21, "r(Sales, Sales^) = $ryyHat", 10)
annotate!(56, 19.5, "r^2(Sales, Sales^) = $ryyHatsQ", 10)
end # let
# ╔═╡ e08f52e5-6dfc-4efd-8363-cb0e02b98796
md"
---
###### 1.2.3 Linear Univariate OLS-Regression Model $f(X)=\beta_0 + \beta_1X_1$
where $Y=Sales$ and $X_1=Radio\text{-}Advertising$
"
# ╔═╡ 4d9fc2b5-3ee4-4acf-be66-d2881f9f994a
let
ols_lin = lm(@formula(Sales ~ Radio), advertisingDataFrame)
yHat = predict(ols_lin)
rxy = round(cor(advertisingDataFrame.Sales, advertisingDataFrame.Radio), digits=3)
rxyHat = round(cor(advertisingDataFrame.Sales, yHat), digits=3)
rxyHatsQ = round(rxyHat^2, digits=3)
#--------------------------------------------------------------------------------
plot(title="Sales -> Radio-Advertising (ISLR2e, Fig. 2.1 - middle)", xlims=(-3,55), ylims=(0,32))
plot!(advertisingDataFrame.Radio, advertisingDataFrame.Sales, seriestype=:scatter, label="(x,y)", xlabel="advertisingDataFrame.Radio", ylabel="advertisingDataFrame.Sales")
plot!(advertisingDataFrame.Radio, yHat, seriestype=:line, width=2, label="(x, y^)")
#--------------------------------------------------------------------------------
annotate!(11, 22.5, "r(Sales, Radio) = $rxy", 10)
annotate!(10.4, 21, "r(Sales, Sales^) = $rxyHat", 10)
annotate!(09.3, 19.5, "r^2(Sales, Sales^) = $rxyHatsQ", 10)
end # let
# ╔═╡ fddf7996-2a6c-48db-8ebb-15e6807c216c
md"
---
###### 1.2.4 Linear Univariate OLS-Regression Model $f(X)=\beta_0 + \beta_1X_1$
where $Y=Sales$ and $X_1=Newspaper\text{-}Advertising$
"
# ╔═╡ da5a6876-ef9f-4d73-bd3b-1369c70bc103
let
ols_lin = lm(@formula(Sales ~ Newspaper), advertisingDataFrame)
yHat = predict(ols_lin)
rxy = round(cor(advertisingDataFrame.Sales, advertisingDataFrame.Newspaper), digits=3)
ryyHat = round(cor(yHat, advertisingDataFrame.Sales), digits=3)
ryyHatsQ = round(ryyHat^2, digits=3)
#--------------------------------------------------------------------------------
plot(title="Sales -> Newsp-Advertising (ISLR2e, Fig. 2.1 - right)", xlims=(-5,125), ylims=(-2,30))
plot!(advertisingDataFrame.Newspaper, advertisingDataFrame.Sales, seriestype=:scatter, label="(x, y)", xlabel="advertisingDataFrame.Newspaper", ylabel="advertisingDataFrame.Sales")
plot!(advertisingDataFrame.Newspaper, yHat, seriestype=:line, width=2, label="(x, y^)")
#--------------------------------------------------------------------------------
annotate!(103.2, 29, "r(Sales, Newsp) = $rxy", 10)
annotate!(102.8, 27.5, "r(Sales, Sales^) = $ryyHat", 10)
annotate!(100.4, 26, "r^2(Sales, Sales^) = $ryyHatsQ", 10)
end # let
# ╔═╡ 24576004-b1d2-43e1-a861-eba45d1fda0e
md"
---
#### 2. The *Income1* Data Set
Both *Income* data sets are generated from numerical simulations. The *true* model function $f(Education, Seniority)$ is depicted in Figure 2.3 (ISLR2, 2021, p.18) as a *blue* surface. Its mathematical form is *not* published by the authors. So we have to estimate $f$ by various approaches.
"
# ╔═╡ 1feee341-401b-4afd-8970-7c2804fc3f89
md"
---
##### 2.1 Dataframe
"
# ╔═╡ 8f6de19f-c4ff-46dd-a120-269ebf647578
income1DataFrame = CSV.File("C:/Users/claus/Nextcloud/PCM_Book/PCM2023_ISLR_Data/IncomeData/Income1Data.csv")
# ╔═╡ d800b01d-477b-4776-bd2c-848fff8a5da9
md"
---
##### 2.2 ISLR2, Fig.2.2
###### 2.2.1 2D-Plot $Income \times Education$
"
# ╔═╡ 7ad28ec0-74ad-4f15-8235-259f091622a6
let
xdata = income1DataFrame.Education
ydata = income1DataFrame.Income
plot(title="Income X Education (ISLR2e, Fig. 2.2 - left)", xlims=(9,23), ylims=(5,95))
plot!(xdata, ydata, seriestype=:scatter, label="(x, y)", xlabel="income1DataFrame.Education", ylabel="income1DataFrame.Income")
end # let
# ╔═╡ 55a0b4d7-890f-4d32-a10f-002631906bda
md"
---
###### 2.2.2 Linear Univariate OLS-Regression Model $f(X)=\beta_0 + \beta_1X_1$
where: $Y=Income$, $X_1=Education$, and #parms$=2$
"
# ╔═╡ bfcdfaf5-50c1-452a-946b-941e5c4c1041
let
xdata = income1DataFrame.Education
ydata = income1DataFrame.Income
#--------------------------------------------------------------------------------
ols_lin = lm(@formula(Income ~ 1 + Education), income1DataFrame)
yHat = predict(ols_lin)
e = residuals(ols_lin)
sse = round(e'e, digits=2)
rxy = round(cor(ydata, xdata), digits=3)
ryyHat = round(cor(ydata, yHat), digits=3)
ryyHatsQ = round(ryyHat^2, digits=3)
#--------------------------------------------------------------------------------
plot(title="Income -> Education (ISLR2e, Fig. 2.2 - left)", xlims=(9,23), ylims=(5,95))
plot!(xdata, ydata, seriestype=:scatter, label="(x, y)", xlabel="income1DataFrame.Education", ylabel="income1DataFrame.Income")
plot!(xdata, yHat, seriestype=:line, width=2, label="(x, y^)")
plot!(map(((x, y, yh) -> ([x, x],[y, yh])), xdata, ydata, yHat), label="")
#--------------------------------------------------------------------------------
annotate!((21.6,28,"r(y, x) = $rxy", 10))
annotate!((21.4,22,"r(y, y^) = $ryyHat", 10))
annotate!((21.15,16,"r^2(y, y^) = $ryyHatsQ", 10))
annotate!((19.2,10,"SSE = $sse (= error sum of squares)", 10))
end # let
# ╔═╡ 5479bd68-aafa-47c6-bce5-d5a8817c131a
md"
---
###### 2.2.3 Nonlinear Univariate OLS-Regression with the [Generalized Logistic Function](https://en.wikipedia.org/wiki/Generalised_logistic_function)
$f(x) = L + (U-L) \cdot \frac{1}{1+e^{-k\left(x - x_{k_{max}}\right)}}$
$\;$
where:
- #parms $= 4$
- **$U$** = Upper (right) asymptote of $X$
- **$L$** = Lower (left) asymptote of $X$
- **$x_{k_{max}}$** = $\underset{X}{\operatorname{argmax}\;k} \;\; \text{(= }x\text{ is the inflection point of } k)$
- **$k_{max}$** = $max(k)$ = max. growth rate *k* of $X$ in the simple *standard* logistic function
The above function $f(X)$ is a solution of *differential equation* describing a [*(logistic) growth process*](https://en.wikipedia.org/wiki/Logistic_function). We derive the differential equation for the simple logistic function $(0 < f_{simple}(X) < 1)$ in the appendix:
$f_{simple}(x) = \frac{1}{1+e^{-x}} = \frac{e^x}{e^x+1}.$
"
# ╔═╡ 92ea0bb5-d318-4758-83c9-ac5960918e12
let
#--------------------------------------------------------------------------------
xdata = income1DataFrame.Education
ydata = income1DataFrame.Income
#--------------------------------------------------------------------------------
myModel(x, p) = p[1] .+ (p[2]-p[1]) .* (1 ./ ((1 .+ exp.(-p[3] .* (x .- p[4])))))
parms0 = [18.0, 78.0, 0.5, 16.0] # initial estimates of parms
myModel(xdata, parms0)
fit = curve_fit(myModel, xdata, ydata, parms0)
e = fit.resid
sse = round(e'e, digits=2)
parms_hat = coef(fit)
L = round(parms_hat[1], digits=2) # greatest Lower bound (gLb)
U = round(parms_hat[2], digits=2) # least Upper bound (lUb)
k = round(parms_hat[3], digits=2) # max. growth rate k
x_k_max = round(parms_hat[4], digits=2) # point x of k_max
yHat = myModel(xdata, parms_hat)
rxy = round(cor(ydata, xdata), digits=3)
ryyHat = round(cor(ydata, yHat), digits=3)
ryyHatsQ = round(ryyHat^2, digits=3)
#--------------------------------------------------------------------------------
Plots.plot(title="Income -> Education (ISLR2e, Fig. 2.2 - right)", xlims=(9,23), ylims=(5,95))
Plots.plot!(xdata, ydata, seriestype=:scatter, xlabel="income1DataFrame.Education", ylabel="income1DataFrame.Income", label="(x, y)")
Plots.plot!(xdata, yHat, seriestype=:line, label="(x, y^)", w=2)
Plots.plot!(map(((x, y, yh) -> ([x, x],[y, yh])), xdata, ydata, yHat), label="")
#--------------------------------------------------------------------------------
annotate!((21.7,52.2,"r(y, x) = $rxy", 10))
annotate!((21.7,46,"r(y,y^) = $ryyHat ", 10))
annotate!((21.3,40,"r^2(y,y^) = $ryyHatsQ", 10))
annotate!((21.4,34,"x_k_max = $x_k_max", 10))
annotate!((19.4,28,"U=$U (= Upper (right) asymptote)", 10))
annotate!((19.6,22,"L=$L (= Lower (left) asymptote)", 10))
annotate!((19.2,16,"SSE = $sse ( = error sum of squares)", 10))
annotate!((17.45,10,"k=$k (= max. growth rate of standard logistic function)", 10))
#--------------------------------------------------------------------------------
end # let
# ╔═╡ e5a0b52d-f482-43fa-9efc-84ecd0711794
md"""
The derivative $f'(x)$ is the description of the logistic growth process and is called [*logistic differential equation*](https://en.wikipedia.org/wiki/Logistic_function) with boundary condition $f(0)= \frac{1}{2}$.
This can be simplified to the product of two terms:
$$f'(x) = \frac{e^x}{(e^x+1)^2} = \frac{e^x}{(e^x+1)(e^x+1)} = \frac{e^x}{(e^x+1)} \cdot \frac{1}{(e^x+1)} = f(x)(1-f(x)).$$
"""
# ╔═╡ 5adf8b34-2d41-4b15-8c13-0cbf84ed0cce
md"
---
#### 3. The *Income2* Data Set
##### 3.1 Dataframe
"
# ╔═╡ ec30ce62-3699-40f8-88c3-8e394d6d826e
income2DataFrame = CSV.File("C:/Users/claus/Nextcloud/PCM_Book/PCM2023_ISLR_Data/IncomeData/Income2Data.csv")
# ╔═╡ c54e5513-f30a-4bc1-afe0-102ba43a6f87
md"
---
##### 3.2 ISLR2, Figs. 2.3 - 2.6 $Income \rightarrow Education$
###### 3.2.1 2D-Plot $Income \times Education$
"
# ╔═╡ a559d47a-bdf9-4229-b363-d33ff4994de6
let
xdata = income2DataFrame.Education
ydata = income2DataFrame.Income
plot(title="Income X Education (ISLR2e, cf. Fig. 2.3)", xlims=(9,23), ylims=(5,120))
plot!(xdata, ydata, seriestype=:scatter, label="(x, y)", xlabel="income2DataFrame.Education", ylabel="income2DataFrame.Income")
end # let
# ╔═╡ a0e54499-eb79-4381-81eb-acfd8826511e
md"
---
###### 3.2.2 Linear Univariate Regression Model $f(X)=\beta_0 + \beta_1X_1$
where $Y=Income$, $X_1=Education$, and #parms$=2$
"
# ╔═╡ 7be41329-e7b8-4647-8eb3-a791f8669f50
let
xdata = income2DataFrame.Education
ydata = income2DataFrame.Income
#--------------------------------------------------------------------------------
ols_linX = lm(@formula(Income ~ 1 + Education), income2DataFrame)
yHat = predict(ols_linX)
eX = residuals(ols_linX)
sseX = round(eX'eX, digits=2)
rxy = round(cor(ydata, xdata), digits=3)
rxyHat = round(cor(ydata, yHat), digits=3)
rxyHatsQ = round(rxyHat^2, digits=3)
#--------------------------------------------------------------------------------
plot(title="Linear OLS: Income -> Education (ISLR2e, cf. Fig.2.3)", xlims=(9,23), ylims=(5,120))
plot!(xdata, ydata, seriestype=:scatter, label="(x, y)", xlabel="income2DataFrame.Education", ylabel="income2DataFrame.Income")
plot!(xdata, yHat, seriestype=:line, width=2, label="(x, y^)")
plot!(map(((x, y, yh) -> ([x, x],[y, yh])), xdata, ydata, yHat), label="")
#--------------------------------------------------------------------------------
annotate!((21,28,"r(y, x) = $rxy", 10))
annotate!((20.9,22,"r(x,y^) = $rxyHat", 10))
annotate!((20.6,16,"r^2(x,y^) = $rxyHatsQ", 10))
annotate!((18.4,10,"SSE = $sseX ( = error sum of squares)", 10))
#--------------------------------------------------------------------------------
end # let
# ╔═╡ d1982304-7008-4486-a16d-5d4064935ebc
md"
---
###### 3.2.3 Nonlinear Univariate OLS-Regressions using the [Generalized Logistic Function](https://en.wikipedia.org/wiki/Generalised_logistic_function)
$f(x) = L + (U-L) \cdot \frac{1}{1+e^{-k\left(x - x_{k_{max}}\right)}}$
$\;$
where:
- #parms $= 4$
- **$U$** = Upper (right) asymptote of $X$
- **$L$** = Lower (left) asymptote of $X$
- **$x_{k_{max}}$** = $\underset{X}{\operatorname{argmax}\;k} \;\; \text{(= }x\text{ is the inflection point of rate } k)$
- **$k_{max}$** = $max(k)$ = max. growth rate *k* of $X$ in the simple *standard* logistic function
$\;$
The above function $f(X)$ is a solution of *differential equation* describing a [*(logistic) growth process*](https://en.wikipedia.org/wiki/Logistic_function). We derive the differential equation for the *simple* logistic function $(0 < f_{simple}(x) < 1)$ in the appendix:
$f_{simple}(x) = \frac{1}{1+e^{-x}} = \frac{e^x}{e^x+1}.$
$\;$
$\;$
"
# ╔═╡ 8ad1be9a-ffdd-4c43-b6ff-edd49550b6d2
let
xdata = income2DataFrame.Education
ydata = income2DataFrame.Income
#--------------------------------------------------------------------------------
myModel(x, p) = p[1] .+ (p[2]-p[1]) .* (1 ./ ((1 .+ exp.(-p[3] .* (x .- p[4])))))
parms0 = [28.0, 88.0, 0.9, 16.0] # initial estimates of parms
myModel(xdata, parms0)
fit = curve_fit(myModel, xdata, ydata, parms0)
parmsHat = coef(fit)
yHat = myModel(xdata, parmsHat)
e = fit.resid
sse = round(e'e, digits=2)
rxy = round(cor(ydata, xdata), digits=3)
ryyHat = round(cor(ydata, yHat), digits=3)
ryyHatsQ = round(ryyHat^2, digits=3)
#--------------------------------------------------------------------------------
L = round(parmsHat[1], digits=2) # greatest Lower bound (gLb)
U = round(parmsHat[2], digits=2) # least Upper bound (lUb)
k = round(parmsHat[3], digits=2) # max. growth rate k
x_k_max = round(parmsHat[4], digits=2) # point x of k_max
#--------------------------------------------------------------------------------
plot(title="Logistic OLS: Income -> Education (ISLR2e, cf.Fig.2.3)", xlims=(9,22), ylims=(5,120))
plot!(xdata, ydata, seriestype=:scatter, label="(x, y)", xlabel="income2DataFrame.Education", ylabel="income2DataFrame.Income")
plot!(xdata, yHat, seriestype=:line, label="(x, yHat)", w=2)
plot!(map(((x, y, yh) -> ([x, x],[y, yh])), xdata, ydata, yHat), label="")
#--------------------------------------------------------------------------------
annotate!((20.85,58,"r(y, x) = $rxy", 10))
annotate!((20.9,52,"r(y,y^) = $ryyHat ", 10))
annotate!((20.45,46,"r^2(y,y^) = $ryyHatsQ", 10))
annotate!((20.55,40,"x_k_max = $x_k_max", 10))
annotate!((19.5,34,"k=$k (= max. growth rate)", 10))
annotate!((18.7,28,"U=$U (= Upper (right) asymptote)", 10))
annotate!((19.0,22,"L=$L (= Lower (left) asymptote)", 10))
annotate!((18.4,16,"SSE = $sse ( = error sum of squares)", 10))
annotate!((16.9,10,"k=$k (= max. growth rate of standard logistic function)", 10))
#--------------------------------------------------------------------------------
end # let
# ╔═╡ df58736c-ebd1-4020-915c-b32291985f3f
md"
---
##### 3.3 ISLR2, Fig.2.3 $Income \rightarrow Seniority$
###### 3.3.1 2D-Plot $Income \times Seniority$
"
# ╔═╡ 8e78b3e0-e97e-4b8d-9342-a180b26bbf03
let
xdata = income2DataFrame.Seniority
ydata = income2DataFrame.Income
#--------------------------------------------------------------------------------
plot(title="Income X Seniority (ISLR2e, cf. Fig. 2.3)", xlims=(9,200), ylims=(5,120))
plot!(xdata, ydata, seriestype=:scatter, label="(y,z)",
xlabel="income2DataFrame.Seniority", ylabel="income2DataFrame.Income")
#--------------------------------------------------------------------------------
end # let
# ╔═╡ 2771a9f1-353f-4bfa-b4d9-a0deda6e031a
md"
---
###### 3.3.2 Linear Univariate OLS-Regression Model $f(X)=\beta_0 + \beta_2X_2$
where: $Y=Income$, $X_2=Seniority$, and #parms$= 2$
"
# ╔═╡ 84c06bd1-4dbf-411f-96c4-97554146ca21
let
xdata = income2DataFrame.Seniority
ydata = income2DataFrame.Income
#--------------------------------------------------------------------------------
ols_lin = lm(@formula(Income ~ 1 + Seniority), income2DataFrame)
yHat = predict(ols_lin)
e = residuals(ols_lin)
sse = round(e'e, digits=2)
rxy = round(cor(ydata, xdata), digits=3)
ryyHat = round(cor(ydata, yHat), digits=3)
ryyHatsQ = round(ryyHat^2, digits=3)
#--------------------------------------------------------------------------------
plot(title="Linear OLS: Income -> Seniority (ISLR2e, cf. Fig.2.3)", xlims=(9,200), ylims=(5,120))
plot!(xdata, ydata, seriestype=:scatter, label="(x, y)", xlabel="income2DataFrame.Seniority", ylabel="income2DataFrame.Income")
plot!(xdata, yHat, seriestype=:line, width=2, label="(x, y^)")
plot!(map(((x, y, yh) -> ([x, x],[y, yh])), xdata, ydata, yHat), label="")
#--------------------------------------------------------------------------------
annotate!((178,28,"r(y,x) = $rxy", 10))
annotate!((175.8,22,"r(y,y^) = $ryyHat", 10))
annotate!((172,16,"r^2(y,y^) = $ryyHatsQ", 10))
annotate!((140,10,"SSE = $sse ( = error sum of squares)", 10))
end # let
# ╔═╡ baa67da7-d394-4a1d-9eee-3a982c0f74c2
md"
---
###### 3.3.3 Nonlinear Univariate Regression using the [Generalized Logistic Function](https://en.wikipedia.org/wiki/Generalised_logistic_function)
$f(x) = L + \frac{U-L}{1+e^{-k\left(x - x_{k_{max}}\right)}}$
where:
- #parms $= 4$
- **$U$** = Upper (right) asymptote of $X$
- **$L$** = Lower (left) asymptote of $X$
- **$x_{k_{max}}$** = $\underset{X}{\operatorname{argmax}\;k} \;\; \text{(= }x\text{ is the inflection point of rate } k)$
- **$k_{max}$** = $max(k)$ = max. growth rate *k* of $X$ in the simple *standard* logistic function
$\;$
The above function $f(x)$ is a solution of *differential equation* describing a [*(logistic) growth process*](https://en.wikipedia.org/wiki/Logistic_function). We derive the differential equation for the *simple* logistic function $f_{simple}(x)$ in the appendix:
$f_{simple}(x) = \frac{1}{1+e^{-x}} = \frac{e^x}{e^x+1}.$
$\;$
$\;$
"
# ╔═╡ f3025a7a-0256-46c7-b296-4cc3a36c5372
let
xdata = income2DataFrame.Seniority
ydata = income2DataFrame.Income
#------------------------------------------------------------------------------
myModel(x, p) = p[1] .+ (p[2] .-p[1]) ./((1 .+ exp.(-p[3] .*(x .- p[4]))))
parms0 = [40.0, 78.0, 4.0, 70.0] # initial estimates of parms
myModel(xdata, parms0)
fit = curve_fit(myModel, xdata, ydata, parms0)
e = fit.resid
sse = round(e'e, digits=2)
parms_hat = coef(fit)
yHat = myModel(xdata, parms_hat)
rxy = round(cor(xdata, ydata), digits=3)
ryyHat = round(cor(ydata, yHat), digits=3)
ryyHatsQ = round(ryyHat^2, digits=3)
#--------------------------------------------------------------------------------
L = round(parms_hat[1], digits=2) # greatest Lower bound (gLb)
U = round(parms_hat[2], digits=2) # least Upper bound (lUb)
k = round(parms_hat[3], digits=2) # max. growth rate k
y_k_max = round(parms_hat[4], digits=2) # point x of k_max
#------------------------------------------------------------------------------
plot(title="Logistic OLS: Income -> Seniority (ISLR2e, cf. Fig.2.3)", xlims=(9,200), ylims=(5,125))
plot!(xdata, ydata, seriestype=:scatter, label="(x, y)", xlabel="income2DataFrame.Seniority", ylabel="income2DataFrame.Income")
plot!(xdata, yHat, seriestype=:line, label="(x, y^)", w=2)
plot!(map(((x, y, yh) -> ([x, x],[y, yh])), xdata, ydata, yHat), label="")
#------------------------------------------------------------------------------
annotate!((40.7,102,"r(y, x) = $rxy", 10))
annotate!((38.5, 96,"r(y, y^) = $ryyHat", 10))
annotate!((36.14,90,"r^(y, y^) = $ryyHatsQ", 10))
annotate!((155.0,30,"Ly=$L (= Lower (left) asymptote)", 10))
annotate!((152.4,24,"Uy=$U (= Upper (right) asymptote)", 10))
annotate!((147.9,18,"sseY=$sse ( = error sum of squares)", 10))
annotate!((127.2,12,"ky=$k (= max. growth rate of standard logistic function)", 10))
#------------------------------------------------------------------------------
end # let
# ╔═╡ e31097bf-1cbf-4146-91b3-841b91aa11b3
md"
---
##### 3.4 ISLR2, Fig.2.3 $Education \times Seniority$
###### 3.4.1 2D-Plot $Education \times Seniority$
"
# ╔═╡ f98e88e4-6abf-41c6-86c4-60f61523e1bb
let
#-------------------------------------------------------------------------------
xs = income2DataFrame.Education
ys = income2DataFrame.Seniority
rxy = round(cor(xs, ys), digits=3)
#-------------------------------------------------------------------------------
plot(title="Income2 Data: Split at Inflection Points of Rate k", xlabel="Education", ylabel="Seniority")
plot!(xs, ys, seriestype=:scatter, label="(x,y)")
plot!([(16.0, 0), (16, 220)], legend=:none) # vertical line at x_k_max = 16
plot!([( 9.5, 70), (22, 70)], legend=:none) # horizontal line at y_k_max = 70
#-------------------------------------------------------------------------------
annotate!(20.7, 60, "y_k_max=70", 10)
annotate!(14.7, 210, "x_k_max=16", 10)
annotate!(12.4, 165, "r(Education, Seniority) = $rxy", 10)
#-------------------------------------------------------------------------------
end # let
# ╔═╡ 1e5f39c1-b6e0-4088-b0dd-5e6162602bed
md"
---
###### 3.4.2 Group-based Frequencies and Means
"
# ╔═╡ 4da9634c-41ab-469f-a25b-dc618e65eacb
let
xs = income2DataFrame.Education
ys = income2DataFrame.Seniority
zs = income2DataFrame.Income
#-------------------------------------------------------------------
lx_ly =
filter(z -> z !== 0,
(map((x, y, z) ->
x <= 16.0 && y <= 70.0 ? z : 0, xs, ys, zs)))
mean_lx_ly = mean(lx_ly)
length_lx_ly = length(lx_ly)
#---------------------------------------------------------
lx_hy =
filter(z -> z !== 0,
(map((x, y, z) ->
x <= 16.0 && y > 70.0 ? z : 0, xs, ys, zs)))
mean_lx_hy = mean(lx_hy)
length_lx_hy = length(lx_hy)
#---------------------------------------------------------
hx_ly =
filter(z -> z !== 0,
(map((x, y, z) ->
x > 16.0 && y <= 70.0 ? z : 0, xs, ys, zs)))
mean_hx_ly = mean(hx_ly)
length_hx_ly = length(hx_ly)
#---------------------------------------------------------
hx_hy =
filter(z -> z !== 0,
(map((x, y, z) ->
x > 16.0 && y > 70.0 ? z : 0, xs, ys, zs)))
mean_hx_hy = mean(hx_hy)
length_hx_hy = length(hx_hy)
#-------------------------------------------------------------------
plot(title="Income2 Data: Split at Inflection Points of Rate k", seriestype=:scatter, legend=:none, xlabel="Education", ylabel="Seniority")
plot!([(16.0, 0), (16, 220)]) # vertical line at x_k_max = 16
plot!([( 9.5, 70), (22, 70)]) # horizontal line at y_k_max = 70
#-------------------------------------------------------------------------------
annotate!(20.7, 60, "y_k_max=70", 10)
annotate!(14.7, 210, "x_k_max=16", 10)
#-------------------------------------------------------------------------------
annotate!(11.5, 40, "N=7", 10)
annotate!(11.5, 25, "mean(Income)=24.1", 10)
annotate!(11.5, 10, "group=lxly", 10)
#----------------------------------------
annotate!(11.5, 140, "N=4", 10)
annotate!(11.5, 125, "mean(Income)=43.8", 10)
annotate!(11.5, 110, "group=lxhy", 10)
#----------------------------------------
annotate!(19.0, 40, "N=4", 10)
annotate!(19.0, 25, "mean(Income)=69.0", 10)
annotate!(19.0, 10, "group=hxly", 10)
#----------------------------------------
annotate!(19.0, 140, "N=15", 10)
annotate!(19.0, 125, "mean(Income)=84.1", 10)
annotate!(19.0, 110, "group=hxhy", 10)
#-------------------------------------------------------------------
# (N_lx_ly=length_lx_ly, N_lx_hy=length_lx_hy, N_hx_ly=length_hx_ly, N_hx_hy=length_hx_hy, mean_lx_ly=mean_lx_ly, mean_lx_hy=mean_lx_hy, mean_hx_ly=mean_hx_ly, mean_hx_hy=mean_hx_hy)
#-------------------------------------------------------------------------------
end # let
# ╔═╡ f76d77bf-eb40-4f9b-8fca-4b12994d8aef
md"
---
##### 3.5 ISLR2, Fig.2.3 $Income \rightarrow (Education \times Seniority)$
###### 3.5.1 2D-Group-Histogram
"
# ╔═╡ cedc8274-24c4-4fab-bae8-70c5f9276e49
let
#-------------------------------------------------------------------------------
xs = income2DataFrame.Education
ys = income2DataFrame.Seniority
zs = income2DataFrame.Income
#-------------------------------------------------------------------------------
lx_ly =
filter(z -> z !== 0,
(map((x, y, z) ->
x <= 16.0 && y <= 70.0 ? (z, :lxly) : 0, xs, ys, zs)))
#---------------------------------------------------------
lx_hy =
filter(z -> z !== 0,
(map((x, y, z) ->
x <= 16.0 && y > 70.0 ? (z, :lxhy) : 0, xs, ys, zs)))
#---------------------------------------------------------
hx_ly =
filter(z -> z !== 0,
(map((x, y, z) ->
x > 16.0 && y <= 70.0 ? (z, :hxly) : 0, xs, ys, zs)))
#---------------------------------------------------------
hx_hy =
filter(z -> z !== 0,
(map((x, y, z) ->
x > 16.0 && y > 70.0 ? (z, :hxhy) : 0, xs, ys, zs)))
#-------------------------------------------------------------------------------
gs = cat(lx_ly, lx_hy, hx_ly, hx_hy; dims=1)
gzs = [gsi[1] for gsi in gs]
ggs = [gsi[2] for gsi in gs]
groupedhist(gzs, group = ggs, title="Income2 Data: Split at Inflection Points of Rate k", xlabel="Income", bins=10)
#-------------------------------------------------------------------------------
end # let
# ╔═╡ 467c6c7c-3acc-4919-99d9-4f197a067174
md"""
---
###### 3.5.2 Frequency Table and Subgroup Means
The results of the 'Test for nonzero correlation' shows that we can stick to the *Nullhypothesis* $H_0: \rho=0$. This means that we can assume that the *population* correlation coeffizient $\rho = 0$. So we can assume that the *variables* $Education$ and $Seniority$ are *stochastic linear independent*.
"""
# ╔═╡ b6dedd81-c882-469d-8bf7-c6abbd8ce724
let
xs = income2DataFrame.Education
ys = income2DataFrame.Seniority
zs = income2DataFrame.Income
rXY = cor(xs, ys)
CorrelationTest(xs, ys)
end # let
# ╔═╡ 4ea401b0-4604-4ab1-a5c4-cbdf4dc3195e
md"
---
###### 3.5.3 Model-free Data Analysis and Modelling Consequences
From cross-tables and histograms we can see that the rank order in $Income$ is from groups $lxly$ over $lxhy$ and $hxly$ to $hxhy$. So we see that a low value in $Education$ *cannot* be compensated by $Seniority$ though a higher $Education$ or $Seniority$ *alone* are favorable influences on $Income$ (at least in this *simulated* data set).
So it is a good idea to model the univariate influences by a *monotonic ascending* function. We used linear and nonlinear (*sigmoid* or *logistic*) functions. In case of the logistic functions we have the advantage that these are solutions of simple *growth processes* formalizable as linear differential equations.
Despite the fact that the frequencies of the two extreme groups $lxly$ and $hxhy$ are higher than in the two other groups the variables $Education$ and $Seniority$ are correlationally *independent*. The corresponding *product-moment correlation* coefficient is $r = 0.19$ (as can be seen above). This gives us the opportunity to construct a nonlinear 3D-regression surface for the multivariate regression model $Income \rightarrow Education \times Seniority$ by *multiplying* the marginal regression functions of the two marginal nonlinear regression models $Income \rightarrow Education$ and $Income \rightarrow Seniority$.
"
# ╔═╡ 2db54260-2d77-40a1-834f-d6d0e4164e44
md"
---
##### 3.6 ISLR2, Fig.2.3 $Income \rightarrow Education \times Seniority$
###### 3.6.1 3D Plot $Income \times Education \times Seniority$
"
# ╔═╡ 8beec881-7371-40dc-948d-deb61ad2d99f
let
#--------------------------------------------------------------------------------
xs = income2DataFrame.Education
ys = income2DataFrame.Seniority
zs = income2DataFrame.Income
#--------------------------------------------------------------------------------
plot(title="Income X Education X Seniority (ISLR2e, Fig. 2.3 - (new))", xlims=(10,20), ylims=(25,180), zlims=(0,100), windowsize=(600*2, 400*2))
plot!(xs, ys, zs, seriestype=:scatter, label="(x,y,z)", xlabel = "Education", ylabel="Seniority", zlabel="Income", markersize=8, grid=true, gridstyle=:solid, gridlinewidth=5, camera=(10,10)) # camera(horizontal, vertical)
#--------------------------------------------------------------------------------
end # let
# ╔═╡ 01cc3ff4-e7a8-4610-b990-088eedbfcd9a
md"
---
###### 3.6.2 Linear Multiple Regression $f(X)=\beta_0 + \beta_1X_1 + \beta_2 X_2 + \beta_3(X_1 \cdot X_2)$
where $Y=Income, X_1=Education$, and $X_2=Seniority$
This model has $4$ parameters $\beta_0, \beta_1, \beta_2, \beta_3$.
"
# ╔═╡ 347ae10c-0991-4cd7-b0d2-d87de4b43f17
let
#--------------------------------------------------------------------------------
xs = income2DataFrame.Education
ys = income2DataFrame.Seniority
zs = income2DataFrame.Income
#--------------------------------------------------------------------------------
ols_lin = lm(@formula(Income ~ 1 + Education * Seniority), income2DataFrame)
zhat = predict(ols_lin)
multipleR = round(cor(zs, zhat), digits=3)
multipleRsQ = round(multipleR^2, digits=3)
#--------------------------------------------------------------------------------
plot(title="Linear Multiple Regression: Income -> f(Education, Seniority, Education * Seniority) (ISLR2e, cf.Fig.2.3)", xlims=(10,20), ylims=(25,180), zlims=(0,100), windowsize=(600*2, 400*2))
plot!(map((x, y, z, zh) -> ([x, x], [y, y], [z, zh]), xs, ys, zs, zhat), label="", linewidth=3)
plot!(xs, ys, zs, seriestype=:scatter, label="(x,y,z)", xlabel = "Education", ylabel="Seniority", zlabel="Income", markersize=8, grid=true, gridstyle=:solid, gridlinewidth=5, camera=(10,10))
plot!(xs, ys, zhat, seriestype=:surface, color=:viridis, legend=:none, colorbar=false, alpha=0.5)
#--------------------------------------------------------------------------------
annotate!(22,160,40, "multiple R = $multipleR")
annotate!(21.6,160,34, "multiple R^2 = $multipleRsQ")
#--------------------------------------------------------------------------------
end # let
# ╔═╡ 55f36e93-0c4e-4eaf-962e-e6ff7cf3e321
md"
---
###### 3.6.3 Linear Multiple OLS-Regression $f(X)=\beta_0 + \beta_1X_1 + \beta_2X_2$
where $Y=Income, X_1=Education$, and $X_2=Seniority$
This model has $3$ parameters $\beta_0, \beta_1, \beta_2$.
"
# ╔═╡ fcbbb2c6-55ca-4302-bd7c-638ba47ac9de
let
#--------------------------------------------------------------------------------
xs = income2DataFrame.Education
ys = income2DataFrame.Seniority
zs = income2DataFrame.Income
#--------------------------------------------------------------------------------
ols_lin = lm(@formula(Income ~ 1 + Education + Seniority), income2DataFrame)
zhat = predict(ols_lin)
multipleR = round(cor(zs, zhat), digits=3)
multipleRsQ = round(multipleR^2, digits=3)
#--------------------------------------------------------------------------------
plot(title="Linear Regression: Income -> Education + Seniority (ISLR2e, cf. Fig. 2.3)", xlims=(10,20), ylims=(25,180), zlims=(0,100), windowsize=(600*2, 400*2))
plot!(map((x, y, z, zh) -> ([x, x], [y, y], [z, zh]), xs, ys, zs, zhat), label="", linewidth=3)
plot!(xs, ys, zs, seriestype=:scatter, label="(x,y,z)", xlabel = "Education", ylabel="Seniority", zlabel="Income", markersize=8, grid=true, gridstyle=:solid, gridlinewidth=5, camera=(10,10)) # camera(horizontal, vertical)
plot!(xs, ys, zhat, seriestype=:surface, color=:viridis, legend=:none, colorbar=false, alpha=0.5)
#--------------------------------------------------------------------------------
annotate!(12,160,90, "multiple R = $multipleR")
annotate!(11.6,160,84, "multiple R^2 = $multipleRsQ")
#--------------------------------------------------------------------------------
end # let
# ╔═╡ cf103b63-ee7e-4970-9f85-b6b9ae72e025
md"
---
###### 3.6.4 Linear Univariate Regression $f(X)=\beta_0 + \beta_1(X_1 \cdot X_2)$
where $Y=Income, X_1=Education$, and $X_2=Seniority$
This model has $2$ parameters $\beta_0, \beta_1$.
"
# ╔═╡ b276aaa9-ee61-444c-a4fa-c09f62f792b8
let
#--------------------------------------------------------------------------------
xs = income2DataFrame.Education
ys = income2DataFrame.Seniority
zs = income2DataFrame.Income
#--------------------------------------------------------------------------------
ols_lin = lm(@formula(Income ~ 1 + Education & Seniority), income2DataFrame)
zhat = predict(ols_lin)
multipleR = round(cor(zs, zhat), digits=3)
multipleRsQ = round(multipleR^2, digits=3)
#--------------------------------------------------------------------------------
plot(title="Linear Regression: Income -> (Education & Seniority) (ISLR2e, cf. Fig. 2.3)", xlims=(10,20), ylims=(25,180), zlims=(0,100), windowsize=(600*2, 400*2))
plot!(map((x, y, z, zh) -> ([x, x], [y, y], [z, zh]), xs, ys, zs, zhat), label="", linewidth=3)
plot!(xs, ys, zs, seriestype=:scatter, label="(x,y,z)", xlabel = "Education", ylabel="Seniority", zlabel="Income", markersize=8, grid=true, gridstyle=:solid, gridlinewidth=5, camera=(10,10)) # camera(horizontal, vertical)
plot!(xs, ys, zhat, seriestype=:surface, color=:viridis, legend=:none, colorbar=false, alpha=0.5)
#--------------------------------------------------------------------------------
annotate!(22,160,40, "multiple R = $multipleR")
annotate!(21.6,160,34, "multiple R^2 = $multipleRsQ")
#--------------------------------------------------------------------------------
end # let
# ╔═╡ c94b50d3-2e18-4f61-921c-ad8d34b28185
md"
---
###### 3.6.5 Comparison of Regression Models 3.6.2-3.6.4 and Interpretation
The *full model* is the the 4-parameter model with interaction term. The other two models are *nested* special cases obtained by *restrictions* on the parameters of the full model. There is a statistical test (*F-test*) to evaluate the increase of the SSE (= sum of error squares) going from the *full* to the *restricted* models.
"
# ╔═╡ b0ea196b-fd17-46b1-a480-9eb0c8dc605b
md"
---
###### 3.6.5.1 Full Model 3.6.2 vs Restricted Model 3.6.3: Significance of Interaction ?
The result of the F-Test full model 3.6.2 versus restricted model 3.6.3 demonstrates that we *may* drop the *interaction* term without loss of accounted variance.
"
# ╔═╡ 2e43b039-725d-4e31-b169-a7029d96b19e
let
#--------------------------------------------------------------------------------
xs = income2DataFrame.Education
ys = income2DataFrame.Seniority
zs = income2DataFrame.Income
#--------------------------------------------------------------------------------
ols_lin_3_6_2 = lm(@formula(Income ~ 1 + Education * Seniority), income2DataFrame)
ols_lin_3_6_3 = lm(@formula(Income ~ 1 + Education + Seniority), income2DataFrame) # no interaction term
#--------------------------------------------------------------------------------
ftest(ols_lin_3_6_2.model, ols_lin_3_6_3.model)
#--------------------------------------------------------------------------------
end # let
# ╔═╡ 7260981e-2c46-4691-a07a-1aa8cc27d3dd
md"
---
###### 3.6.5.2 Full Model 3.6.2 vs Restricted Model 3.6.4: Significance of Main Effects ?
The result of the F-Test full model 3.6.2 versus restricted model 3.6.4 demonstrates that we may *not* drop the *main effects* without loss of accounted variance.
"
# ╔═╡ bd1fe6b8-262b-4202-89c9-4476a672ea34
let
#--------------------------------------------------------------------------------
xs = income2DataFrame.Education
ys = income2DataFrame.Seniority
zs = income2DataFrame.Income
#--------------------------------------------------------------------------------
ols_lin_3_6_2 = lm(@formula(Income ~ 1 + Education * Seniority), income2DataFrame)
ols_lin_3_6_4 = lm(@formula(Income ~ 1 + Education & Seniority), income2DataFrame) # no interaction term
#--------------------------------------------------------------------------------
ftest(ols_lin_3_6_2.model, ols_lin_3_6_4.model)
#--------------------------------------------------------------------------------
end # let
# ╔═╡ 3a4ce2bc-6387-4581-acd2-517b834d8301
md"
---
##### 3.7 Summary
The highest accounted variance with a *linear* parameter-parsimoneous model is $93.4\% = R^2*100$. This achieved with the $3$ parameter model 3.6.3. This has *no* interaction term.
"
# ╔═╡ e13cda08-84ec-48c3-ade8-fd61a3c5ac17
md"
---
##### References
- **James, G., Witten, D., Hastie, T. & Tibshirani, R.**; *An Introduction to Statistical Learning, Heidelberg: Springer, 2021, 2/e,
- **Wikipedia**; *Logistic Function*; [https://en.wikipedia.org/wiki/Logistic_function](https://en.wikipedia.org/wiki/Logistic_function); last visit 2023/05/07
- **Wikipedia**; *The Generalized Logistic Function*, [https://en.wikipedia.org/wiki/Generalised_logistic_function](https://en.wikipedia.org/wiki/Generalised_logistic_function); last visit 2023/05/04
"
# ╔═╡ 75c6cefe-7be7-4086-a5c6-0e8312b8b6ee
md"
---
##### end of ch. 2.1.1
"
# ╔═╡ 6566d57d-d090-4bed-87e8-be8b516e86e1
md"
====================================================================================
This is a **draft** under the Attribution-NonCommercial-ShareAlike 4.0 International **(CC BY-NC-SA 4.0)** license. Comments, suggestions for improvement and bug reports are welcome: **claus.moebus(@)uol.de**
====================================================================================
"
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a"
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
LsqFit = "2fda8390-95c7-5789-9bda-21331edee243"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
[compat]
CSV = "~0.10.9"
GLM = "~1.8.3"
HypothesisTests = "~0.10.13"
LsqFit = "~0.13.0"
Plots = "~1.38.11"
StatsPlots = "~0.15.5"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
julia_version = "1.9.0"
manifest_format = "2.0"
project_hash = "a1636ede352b79f841eaced756821acc3456eda0"
[[deps.AbstractFFTs]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "16b6dbc4cf7caee4e1e75c49485ec67b667098a0"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "1.3.1"
weakdeps = ["ChainRulesCore"]
[deps.AbstractFFTs.extensions]
AbstractFFTsChainRulesCoreExt = "ChainRulesCore"
[[deps.Adapt]]
deps = ["LinearAlgebra", "Requires"]
git-tree-sha1 = "76289dc51920fdc6e0013c872ba9551d54961c24"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.6.2"
weakdeps = ["StaticArrays"]
[deps.Adapt.extensions]
AdaptStaticArraysExt = "StaticArrays"
[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"
[[deps.Arpack]]
deps = ["Arpack_jll", "Libdl", "LinearAlgebra", "Logging"]
git-tree-sha1 = "9b9b347613394885fd1c8c7729bfc60528faa436"
uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"
version = "0.5.4"
[[deps.Arpack_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "OpenBLAS_jll", "Pkg"]
git-tree-sha1 = "5ba6c757e8feccf03a1554dfaf3e26b3cfc7fd5e"
uuid = "68821587-b530-5797-8361-c406ea357684"
version = "3.5.1+1"
[[deps.ArrayInterface]]
deps = ["Adapt", "LinearAlgebra", "Requires", "SnoopPrecompile", "SparseArrays", "SuiteSparse"]
git-tree-sha1 = "38911c7737e123b28182d89027f4216cfc8a9da7"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "7.4.3"
[deps.ArrayInterface.extensions]
ArrayInterfaceBandedMatricesExt = "BandedMatrices"
ArrayInterfaceBlockBandedMatricesExt = "BlockBandedMatrices"
ArrayInterfaceCUDAExt = "CUDA"
ArrayInterfaceGPUArraysCoreExt = "GPUArraysCore"
ArrayInterfaceStaticArraysCoreExt = "StaticArraysCore"
ArrayInterfaceTrackerExt = "Tracker"
[deps.ArrayInterface.weakdeps]
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[deps.AxisAlgorithms]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"]
git-tree-sha1 = "66771c8d21c8ff5e3a93379480a2307ac36863f7"
uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950"
version = "1.0.1"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[deps.BitFlags]]
git-tree-sha1 = "43b1a4a8f797c1cddadf60499a8a077d4af2cd2d"
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.7"
[[deps.Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "19a35467a82e236ff51bc17a3a44b69ef35185a2"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+0"
[[deps.CSV]]
deps = ["CodecZlib", "Dates", "FilePathsBase", "InlineStrings", "Mmap", "Parsers", "PooledArrays", "PrecompileTools", "SentinelArrays", "Tables", "Unicode", "WeakRefStrings", "WorkerUtilities"]
git-tree-sha1 = "ed28c86cbde3dc3f53cf76643c2e9bc11d56acc7"
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
version = "0.10.10"
[[deps.Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "CompilerSupportLibraries_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "4b859a208b2397a7a623a03449e4636bdb17bcf2"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.16.1+1"
[[deps.Calculus]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "f641eb0a4f00c343bbc32346e1217b86f3ce9dad"
uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
version = "0.5.1"
[[deps.ChainRulesCore]]
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "e30f2f4e20f7f186dc36529910beaedc60cfa644"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.16.0"
[[deps.Clustering]]
deps = ["Distances", "LinearAlgebra", "NearestNeighbors", "Printf", "Random", "SparseArrays", "Statistics", "StatsBase"]
git-tree-sha1 = "a6e6ce44a1e0a781772fc795fb7343b1925e9898"
uuid = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
version = "0.15.2"
[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "9c209fb7536406834aa938fb149964b985de6c83"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.1"