further update on multiple regression
This commit is contained in:
@@ -1,34 +1,30 @@
|
|||||||
############################################################################
|
|
||||||
#### Execute code chunks separately in VSCODE by pressing 'Alt + Enter' ####
|
|
||||||
############################################################################
|
|
||||||
|
|
||||||
using Statistics
|
using Statistics
|
||||||
using Plots
|
using Plots
|
||||||
using RDatasets
|
using RDatasets
|
||||||
using GLM
|
using GLM
|
||||||
|
|
||||||
##
|
#---
|
||||||
|
|
||||||
trees = dataset("datasets", "trees")
|
trees = dataset("datasets", "trees")
|
||||||
|
|
||||||
scatter(trees.Girth, trees.Volume,
|
scatter(trees.Girth, trees.Volume,
|
||||||
legend=false, xlabel="Girth", ylabel="Volume")
|
legend=false, xlabel="Girth", ylabel="Volume")
|
||||||
|
|
||||||
##
|
#---
|
||||||
|
|
||||||
scatter(trees.Girth, trees.Volume,
|
scatter(trees.Girth, trees.Volume,
|
||||||
legend=false, xlabel="Girth", ylabel="Volume")
|
legend=false, xlabel="Girth", ylabel="Volume")
|
||||||
plot!(x -> -37 + 5*x)
|
plot!(x -> -37 + 5*x)
|
||||||
|
|
||||||
##
|
#---
|
||||||
|
|
||||||
linmod1 = lm(@formula(Volume ~ Girth), trees)
|
linmod1 = lm(@formula(Volume ~ Girth), trees)
|
||||||
|
|
||||||
##
|
#---
|
||||||
|
|
||||||
linmod2 = lm(@formula(Volume ~ Girth + Height), trees)
|
linmod2 = lm(@formula(Volume ~ Girth + Height), trees)
|
||||||
|
|
||||||
##
|
#---
|
||||||
|
|
||||||
r2(linmod1)
|
r2(linmod1)
|
||||||
r2(linmod2)
|
r2(linmod2)
|
||||||
@@ -37,7 +33,7 @@ linmod3 = lm(@formula(Volume ~ Girth + Height + Girth*Height), trees)
|
|||||||
|
|
||||||
r2(linmod3)
|
r2(linmod3)
|
||||||
|
|
||||||
##
|
#---
|
||||||
|
|
||||||
using CSV
|
using CSV
|
||||||
using HTTP
|
using HTTP
|
||||||
@@ -47,6 +43,6 @@ SwissLabor = DataFrame(CSV.File(http_response.body))
|
|||||||
|
|
||||||
SwissLabor[!,"participation"] .= (SwissLabor.participation .== "yes")
|
SwissLabor[!,"participation"] .= (SwissLabor.participation .== "yes")
|
||||||
|
|
||||||
##
|
#---
|
||||||
|
|
||||||
model = glm(@formula(participation ~ age), SwissLabor, Binomial(), ProbitLink())
|
model = glm(@formula(participation ~ age), SwissLabor, Binomial(), ProbitLink())
|
||||||
@@ -10,7 +10,7 @@ editor:
|
|||||||
|
|
||||||
### Introductory Example: tree dataset from R
|
### Introductory Example: tree dataset from R
|
||||||
|
|
||||||
```{julia}
|
``` julia
|
||||||
using Statistics
|
using Statistics
|
||||||
using Plots
|
using Plots
|
||||||
using RDatasets
|
using RDatasets
|
||||||
@@ -25,7 +25,7 @@ scatter(trees.Volume, trees.Girth,
|
|||||||
the *explanatory variable/covariate* `girth`? Can we predict the volume
|
the *explanatory variable/covariate* `girth`? Can we predict the volume
|
||||||
of a tree given its girth?
|
of a tree given its girth?
|
||||||
|
|
||||||
```{julia}
|
``` julia
|
||||||
scatter(trees.Girth, trees.Volume,
|
scatter(trees.Girth, trees.Volume,
|
||||||
legend=false, xlabel="Girth", ylabel="Volume")
|
legend=false, xlabel="Girth", ylabel="Volume")
|
||||||
plot!(x -> -37 + 5*x)
|
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
|
\[use Julia code (existing package) to perform linear regression for
|
||||||
`volume ~ girth`\]
|
`volume ~ girth`\]
|
||||||
|
|
||||||
```{julia}
|
``` julia
|
||||||
lm(@formula(Volume ~ Girth), trees)
|
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
|
functions with the \`\`\`tree''' data set and try to reproduce the
|
||||||
output above.
|
output above.
|
||||||
|
|
||||||
```{julia}
|
``` julia
|
||||||
r2(linmod1)
|
r2(linmod1)
|
||||||
r2(linmod2)
|
r2(linmod2)
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ $$
|
|||||||
In the Gaussian case, the maximum likelihood estimator is identical to
|
In the Gaussian case, the maximum likelihood estimator is identical to
|
||||||
the least squares estimator considered above.
|
the least squares estimator considered above.
|
||||||
|
|
||||||
```{julia}
|
``` julia
|
||||||
using CSV
|
using CSV
|
||||||
using HTTP
|
using HTTP
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user