【问题标题】:How can I find regression model analyses from 2 dataset?如何从 2 个数据集中找到回归模型分析?
【发布时间】:2021-01-14 21:21:07
【问题描述】:
setwd("C:/Users/sevvalayse.yurtekin/Desktop/hw3")
data = read.table('DSE501_fall2020_HW3.csv', header= T, sep=',')
attach
data
getOption("max.print")

rs<-rowSums(data[,2:76], na.rm = TRUE)
data<-cbind(data,rs)
data

p1<-ggplot()+
  geom_line(aes(y = rs, x=year), data=data)+
  scale_x_continuous(breaks = seq(2004,2019,2))
p1

model = lm(rs ~ year )
model
summary(model)
residuals(model)
predict(model)
#model.fit = lm(year~rs)
#summary(model.fit)

new.year<-data.frame(
  year = c(2021,2022,2023)
)
predict(model, newdata = new.year, interval = 'confidence')

data2 = read.table('TUIK_nufus_2019.csv', header = T, sep=",")
data2


total = data2$Total
mydata<-data[-c(1,2,3),]


model2 = lm(mydata~total)
model2

您好,关于 model.frame.default(formula = mydata ~ total, drop.unused.levels = TRUE) 中的错误:变量“mydata”的类型(列表)无效。

我该如何解决?我想从 2 个数据中进行回归分析。

【问题讨论】:

    标签: r error-handling regression linear-regression predict


    【解决方案1】:

    导致问题的行是model2 = lm(mydata~total)mydata 不是一个向量,它是你的因变量应该在 lm 函数中。当您设置 mydata 时,您不提供列名:mydata&lt;-data[-c(1,2,3), &lt;enter column name of dependent variable&gt;]

    否则,您可以使用以下语法拟合您的模型(前提是您的因变量和自变量位于同一数据框中)。这里我只是用y作为一个假变量名:lm(y ~ total, data = mydata)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-22
      • 2016-02-13
      • 2015-09-23
      • 1970-01-01
      • 2021-11-05
      • 2012-04-28
      • 2018-08-20
      • 1970-01-01
      相关资源
      最近更新 更多