6-R语言最小二乘法实战
6-R语言最小二乘法实战
6.1-准备与获得数据
my_packages<- c("ggplot2", "tidyverse",
"RColorBrewer", "paletteer", "ivreg")
tmp <- sapply(my_packages, function(x) library(x, character.only = T)); rm(tmp, my_packages)
data("SchoolingReturns", package = "ivreg")
my_data <- SchoolingReturns[, 1:8]
glimpse(my_data)
Rows: 3,010
Columns: 8
$ wage <dbl> 548, 481, 721, 250, 729, 500, 565, 608…
$ education <dbl> 7, 12, 12, 11, 12, 12, 18, 14, 12, 12,…
$ experience <dbl> 16, 9, 16, 10, 16, 8, 9, 9, 10, 11, 13…
$ ethnicity <fct> afam, other, other, other, other, othe…
$ smsa <fct> yes, yes, yes, yes, yes, yes, yes, yes…
$ south <fct> no, no, no, no, no, no, no, no, no, no…
$ age <dbl> 29, 27, 34, 27, 34, 26, 33, 29, 28, 29…
$ nearcollege <fct> no, no, no, yes, yes, yes, yes, yes, y…6.2-两次回归找拟合值
6.3-ivreg包实现
Last updated