ill <- read.csv("/Applications/therbook/Illiteracy.csv", header =TRUE)
attach(ill)
names(ill)
head(ill)
tail(ill)
我观察到,当 illit 率超过50时,每名女性的出生均高于4岁及以上的孩子
# Observing the graph it's clearly shown how illiteracy affects birth rates in country.
# The more a woman is illiterate, the more children she bares
plot(Births,Illit)
regression_coe <- lm(Births~Illit,data=ill)
regression_coe
在我们的例子中,系数将是0.05452
plot(ill$Births,ill$Illit)
abline(regression_coe)
int_abline中的错误(a = a,b = b,h = h,v = v,untf = untf,...):plot.new尚未被调用
r <- cor(Births,Illit)
r^2
因此,在此线性回归中解释了约59%
rr <- resid(regression_coe)
plot(Births,Illit)
abline(rr)
int_abline中的错误(a = a,b = b,h = h,v = v,untf = untf,...):plot.new尚未被调用
答案 0 :(得分:0)
残差是一个长命名向量,abline不能将其作为输入。 abline
可以采用斜率和截距,值来制作垂直或水平线,系数或线性模型对象。如果您正在寻找剩余部分中的模式,您可能希望这样做:
plot(resid(regression_coe))
abline(0,0)
答案 1 :(得分:0)
问题,评论和答案点朝着abline()
的方向发展,但问题似乎与使用lm()
有关。
以下代码对我有用:
regression_coe <- lm(Illit ~ Births, data = ill)
regression_coe
#
#Call:
#lm(formula = Illit ~ Births, data = ill)
#
#Coefficients:
#(Intercept) Births
# -8.24 10.84
plot(ill$Births, ill$Illit)
abline(regression_coe)
请注意,OP有regression_coe <- lm(Births~Illit,data=ill)
。
resid(regression_coe)
regression_coe <- lm(Births ~ Illit, data = ill)
regression_coe
#
#Call:
#lm(formula = Births ~ Illit, data = ill)
#
#Coefficients:
#(Intercept) Illit
# 1.94874 0.05452
plot(ill$Illit, ill$Births)
abline(regression_coe)
ill <- structure(list(ID = 1:94, Country = structure(1:94, .Label = c("Albania",
"Algeria", "Bahrain", "Belize", "Benin", "Bolivia", "Botswana",
"Brazil", "Brunei", "Burkina Faso", "Burma", "Burundi", "Cambodia",
"Cape Verde", "Central African Republic", "Chad", "China", "Colombia",
"Comoros", "Congo, Democratic Republic of the", "Congo, Republic of the",
"Cote d'Ivoire", "Djibouti", "Dominican Republic", "Ecuador",
"Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Ethiopia",
"Fiji", "Gambia, The", "Ghana", "Guatemala", "Guinea-Bissau",
"Haiti", "Honduras", "Hong Kong", "India", "Indonesia", "Iran",
"Israel", "Jamaica", "Jordan", "Kenya", "Kuwait", "Laos", "Lebanon",
"Lesotho", "Liberia", "Libya", "Macau", "Madagascar", "Malawi",
"Malaysia", "Mali", "Malta", "Mauritania", "Mauritius", "Mexico",
"Mozambique", "Namibia", "Nicaragua", "Niger", "Nigeria", "Oman",
"Pakistan", "Panama", "Papua New Guinea", "Paraguay", "Peru",
"Portugal", "Puerto Rico", "Qatar", "Rwanda", "Saudi Arabia",
"Senegal", "Singapore", "South Africa", "Sri Lanka", "Sudan",
"Swaziland", "Syria", "Tanzania", "Thailand", "Togo", "Tunisia",
"Turkey", "United Arab Emirates", "Venezuela", "Vietnam", "Yemen",
"Zambia", "Zimbabwe"), class = "factor"), Illit = c(20.5, 39.1,
15, 5.9, 73.5, 18.5, 17.6, 11.9, 11.5, 83.4, 18.1, 54.8, 39.8,
30.9, 60.1, 60.7, 19.6, 7.5, 50.7, 44.9, 21.6, 59.1, 41.6, 15.2,
9.1, 53.1, 22.3, 21.6, 52.4, 64.8, 8.1, 66.9, 32.7, 36.8, 72.4,
48.8, 23, 9.5, 51.7, 15.9, 27.4, 6.2, 8.3, 13.4, 20.3, 18.3,
43.4, 17.8, 5.5, 59.5, 28.1, 8, 37.5, 50.3, 14.7, 82, 6.4, 68.1,
17.4, 9.8, 67.3, 16.3, 32.2, 90.2, 39, 32.8, 69.4, 8.1, 40.6,
7, 13.3, 8.8, 5.5, 15, 35.2, 29.3, 69.2, 10.4, 14.3, 10.1, 49.5,
19.2, 36.1, 29.4, 5.4, 53.1, 35.6, 21.4, 18.5, 6.9, 8.5, 69.8,
25.2, 12.9), Births = c(1.78, 2.44, 2.34, 2.97, 5.6, 3.65, 3.03,
2.29, 2.38, 5.9, 2.23, 6.8, 3.89, 3.53, 4.73, 6.3, 1.81, 2.4,
3.76, 6.7, 5.6, 4.7, 4.74, 2.73, 2.67, 3.1, 2.76, 5.89, 5.24,
5.32, 2.79, 4.4, 4.06, 4.33, 7.08, 3.75, 3.47, 0.97, 2.84, 2.27,
2.07, 2.82, 2.38, 3.29, 4.98, 2.39, 4.5, 2.25, 3.4, 6.78, 2.85,
0.88, 5.04, 5.84, 2.74, 6.72, 1.37, 5.59, 1.98, 2.11, 5.3, 3.66,
3.08, 7.67, 5.5, 3.44, 4.12, 2.62, 3.8, 3.67, 2.74, 1.4, 1.8,
2.89, 5.8, 3.83, 4.9, 1.24, 2.78, 1.91, 4.15, 3.91, 3.24, 5.2,
1.89, 5.03, 2.04, 2.19, 2.43, 2.65, 1.78, 5.87, 5.4, 3.34)), .Names = c("ID",
"Country", "Illit", "Births"), class = "data.frame", row.names = c(NA,
-94L))