R中ggplot的多变量回归

时间:2017-03-03 02:07:34

标签: r ggplot2 regression

我的代码是这样的,但输出是什么

model <- lm(data = df, df$premarriage ~ df$year + df$age + df$educ + df$sex + df$race)

df$model <- stats::predict(model, newdata=df)
err <- stats::predict(model, newdata=df, se = TRUE)
df$ucl <- err$fit + 1.96 * err$se.fit
df$lcl <- err$fit - 1.96 * err$se.fit
attach(df)
g <- ggplot(df)
g <- g + geom_point(aes(x=premarriage, y = model), size = 2, colour = "blue")
g <- g + geom_smooth(data=df, aes(x=premarriage, y=model, ymin=lcl, ymax=ucl), size = 1.5, 
            colour = "red", se = TRUE, stat = "smooth")

0 个答案:

没有答案