如何更改模型系数以比较文献中的模型?

问题描述 投票:3回答:1

我想将我自己复制的统计模型中的系数与文献中的系数进行比较。我想我可以复制我的模型,然后插入文献中的系数并打印出来。但我收到此错误:

Error in if (coef.var[i] == .global.coefficient.variables[j]) { : argument is of length zero

最简单的方法是什么?

##fake data
var1<-rnorm(100)
var2<-rnorm(100)
df<-data.frame(var1, var2)
#My own model
model1<-lm(var1~var2, data=df)

#Duplicate my own model
model2<-model1
#Try to change the coefficients to match what appears in the literature
model2$coefficients<-c(5, 10)
#Try to report
library(stargazer)
stargazer(model1, model2,type="html")
r stargazer
1个回答
0
投票

此作品:

var1<-rnorm(100)
var2<-rnorm(100)
df<-data.frame(var1, var2)

model1<-lm(var1~var2, data=df)

model2<-model1

model2$coefficients[[1]] <- 5
model2$coefficients[[2]] <- 10


library(stargazer)
stargazer(model1, model2,type="html")
© www.soinside.com 2019 - 2024. All rights reserved.