Я новичок в визуализации результатов регрессии, и мне нужна помощь с получением графика, показывающего прогнозные значения по регрессии линейной модели.
Структура данных, полученная с помощью dput
:
`> dput(head(dat,4))
structure(list(X = c(809L, 3L, 1L, 2L), cntry = structure(c(1L,
1L, 1L, 1L), .Label = c("AT", "BE", "CH", "CZ", "DE", "DK", "ES",
"FI", "GB", "GR", "HU", "IE", "IL", "NL", "NO", "PL", "PT", "SE",
"SI", "EE", "IS", "LU", "SK", "TR", "UA", "BG", "CY", "FR", "RU",
"HR", "LV", "RO", "LT", "AL", "IT", "XK"), class = "factor"),
ipshabt = c(4L, 2L, 3L, 2L), ipsuces = c(3L, 2L, 3L, 1L),
imprich = c(3L, 3L, 3L, 3L), iprspot = c(3L, 3L, 4L, 4L),
impsafe = c(3L, 3L, 2L, 4L), ipstrgv = c(2L, 2L, 2L, 3L),
ipfrule = c(3L, 2L, 1L, 6L), ipbhprp = c(3L, 2L, 4L, 4L),
ipmodst = c(3L, 3L, 2L, 5L), imptrad = c(2L, 2L, 1L, 6L),
ipeqopt = c(1L, 2L, 1L, 1L), ipudrst = c(1L, 2L, 3L, 3L),
impenv = c(3L, 2L, 2L, 1L), iphlppl = c(1L, 2L, 1L, 4L),
iplylfr = c(2L, 2L, 2L, 3L), ipcrtiv = c(2L, 2L, 2L, 1L),
impfree = c(2L, 3L, 1L, 1L), impdiff = c(2L, 3L, 3L, 1L),
ipadvnt = c(6L, 4L, 3L, 1L), ipgdtim = c(2L, 2L, 1L, 1L),
impfun = c(6L, 5L, 1L, 3L), gndr = c(2L, 2L, 1L, 1L), agea = c(69L,
63L, 54L, 50L), hincfel = c(1L, 2L, 1L, 3L), educ = c(1L,
2L, 3L, 3L), year = c(2002L, 2002L, 2002L, 2002L), Achievement = c(3.5,
2, 3, 1.5), Power = c(3, 3, 3.5, 3.5), Security = c(2.5,
2.5, 2, 3.5), Conformity = c(3, 2, 2.5, 5), Tradition = c(2.5,
2.5, 1.5, 5.5), Universalism = c(1.66666666666667, 2, 2,
1.66666666666667), Benevolence = c(1.5, 2, 1.5, 3.5), SelfDirection = c(2, 2.5, 1.5, 1), Stimulation = c(4, 3.5, 3, 1), Hedonism = c(4,
3.5, 1, 2), SelfEnh = c(3.25, 2.5, 3.25, 2.5), SelfTran = c(1.6,
2, 1.8, 2.4), Cons = c(2.66666666666667, 2.33333333333333,
2, 4.66666666666667), Open = c(3.33333333333333, 3.16666666666667,
1.83333333333333, 1.33333333333333), SelfTranNet = c(-1.65,
-0.5, -1.45, -0.1), OpenNet = c(0.666666666666667, 0.833333333333333,
-0.166666666666667, -3.33333333333333), east = c(0, 0, 0,
0), eastyear = c(0, 0, 0, 0), income = c(1L, 2L, 1L, 3L),
year2002 = c(1, 1, 1, 1), eastyear2002 = c(0, 0, 0, 0), year2004 = c(0,
0, 0, 0), eastyear2004 = c(0, 0, 0, 0), year2006 = c(0, 0,
0, 0), eastyear2006 = c(0, 0, 0, 0), year2008 = c(0, 0, 0,
0), eastyear2008 = c(0, 0, 0, 0), year2010 = c(0, 0, 0, 0
), eastyear2010 = c(0, 0, 0, 0), year2012 = c(0, 0, 0, 0),
eastyear2012 = c(0, 0, 0, 0), year2014 = c(0, 0, 0, 0), eastyear2014 = c(0,
0, 0, 0), year2016 = c(0, 0, 0, 0), eastyear2016 = c(0, 0,
0, 0)), .Names = c("X", "cntry", "ipshabt", "ipsuces", "imprich",
"iprspot", "impsafe", "ipstrgv", "ipfrule", "ipbhprp", "ipmodst",
"imptrad", "ipeqopt", "ipudrst", "impenv", "iphlppl", "iplylfr",
"ipcrtiv", "impfree", "impdiff", "ipadvnt", "ipgdtim", "impfun",
"gndr", "agea", "hincfel", "educ", "year", "Achievement", "Power",
"Security", "Conformity", "Tradition", "Universalism", "Benevolence",
"SelfDirection", "Stimulation", "Hedonism", "SelfEnh", "SelfTran",
"Cons", "Open", "SelfTranNet", "OpenNet", "east", "eastyear",
"income", "year2002", "eastyear2002", "year2004", "eastyear2004",
"year2006", "eastyear2006", "year2008", "eastyear2008", "year2010",
"eastyear2010", "year2012", "eastyear2012", "year2014", "eastyear2014",
"year2016", "eastyear2016"), row.names = c(NA, 4L), class = "data.frame")`
Моя модель линейной регрессии: > modelAchievement <- lm(Achievement~east+year+year2002+eastyear2002+year2004+eastyear2004+year2006+eastyear2006+year2008+eastyear2008+year2010+eastyear2010+year2012+eastyear2012+year2014+eastyear2014+year2016+eastyear2016+agea+gndr+income+educ, data = dat)
Теперь я хочу получить две предсказанные строки зависимой переменной,то есть «Достижение», на одном графике с осью Y «Достижение» и осью X «год».Первая строка: фиктивная переменная "восток" = 1;вторая строка: если фиктивная переменная "восток" = 0.
Я не знал, как поступить, и пытался использовать ggplot(modelAchievement, aes(y = Achievement, x = year))
, но он дает пустой график.
Любой советс благодарностью.
Ссылка на полные данные: данные