further update on multiple regression

This commit is contained in:
Marco Oesting
2023-10-09 16:07:42 +02:00
parent 905aea7546
commit 08951f610d
2 changed files with 339 additions and 343 deletions

View File

@@ -1,34 +1,30 @@
############################################################################
#### Execute code chunks separately in VSCODE by pressing 'Alt + Enter' ####
############################################################################
using Statistics
using Plots
using RDatasets
using GLM
##
#---
trees = dataset("datasets", "trees")
scatter(trees.Girth, trees.Volume,
legend=false, xlabel="Girth", ylabel="Volume")
##
#---
scatter(trees.Girth, trees.Volume,
legend=false, xlabel="Girth", ylabel="Volume")
plot!(x -> -37 + 5*x)
##
#---
linmod1 = lm(@formula(Volume ~ Girth), trees)
##
#---
linmod2 = lm(@formula(Volume ~ Girth + Height), trees)
##
#---
r2(linmod1)
r2(linmod2)
@@ -37,7 +33,7 @@ linmod3 = lm(@formula(Volume ~ Girth + Height + Girth*Height), trees)
r2(linmod3)
##
#---
using CSV
using HTTP
@@ -47,6 +43,6 @@ SwissLabor = DataFrame(CSV.File(http_response.body))
SwissLabor[!,"participation"] .= (SwissLabor.participation .== "yes")
##
#---
model = glm(@formula(participation ~ age), SwissLabor, Binomial(), ProbitLink())

View File

@@ -10,7 +10,7 @@ editor:
### Introductory Example: tree dataset from R
```{julia}
``` julia
using Statistics
using Plots
using RDatasets
@@ -25,7 +25,7 @@ scatter(trees.Volume, trees.Girth,
the *explanatory variable/covariate* `girth`? Can we predict the volume
of a tree given its girth?
```{julia}
``` julia
scatter(trees.Girth, trees.Volume,
legend=false, xlabel="Girth", ylabel="Volume")
plot!(x -> -37 + 5*x)
@@ -68,7 +68,7 @@ rather use Julia to solve the problem.
\[use Julia code (existing package) to perform linear regression for
`volume ~ girth`\]
```{julia}
``` julia
lm(@formula(Volume ~ Girth), trees)
```
@@ -183,7 +183,7 @@ the corresponding standard errors and the $t$-statistics. Test your
functions with the \`\`\`tree''' data set and try to reproduce the
output above.
```{julia}
``` julia
r2(linmod1)
r2(linmod2)
@@ -274,7 +274,7 @@ $$
In the Gaussian case, the maximum likelihood estimator is identical to
the least squares estimator considered above.
```{julia}
``` julia
using CSV
using HTTP