【问题标题】:How to deal with a quadratic model that has too many fitted values?如何处理具有太多拟合值的二次模型?
【发布时间】:2020-02-29 00:40:24
【问题描述】:

我正在尝试将二次回归模型拟合到数据集,然后在散点图上绘制曲线。该数据集是关于电视节目中角色的剧集数和放映时间。

我在 x 轴上绘制了一个散点图,在 y 轴上绘制了屏幕时间,这很好用。

然后我创建模型如下:

#ordering
gottemp <- got[order(got$episodes),]

#plotting
plot(screentime~episodes, data = gottemp, xlab ="Number of episodes", ylab = "Screentime (minutes)", col=c("blue","red")[gender], pch=c(1,2)[gender])
legend("topleft",pch = c(1,2),col=c("blue","red"),c("female","male"))
title("Plot of Screentimes vs Number of Episodes")

#creating 3model and plotting line
model <- lm(screentime~episodes+I(episodes^2), data = got)
lines(fitted(model))

这给了我一个具有正确系数的模型,但是绘制的线不是预期的。当我查看模型时,我看到有 113 个拟合值,我认为这是由于某些角色的集数相同,因此为了解决这个问题,我认为每个集数应该只有一个拟合值。

【问题讨论】:

  • 说明你正在正确解决的问题。
  • 编辑有帮助吗?

标签: r regression linear-regression


【解决方案1】:

有点像

nd <- data.frame(episodes=seq(min(episodes), max(episodes), length=51)
nd$screentime <- predict(model, newdata=nd)
with(nd, lines(episodes, screentime))

应该做你想做的。某处可能有重复...

【讨论】:

    猜你喜欢
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 2017-01-08
    • 2015-07-22
    • 1970-01-01
    相关资源
    最近更新 更多