通过 sjPlot 直观地表示具有交互作用的 plm 模型?

问题描述

这是我正在使用的变量。

str(house_split_1)
grouped_df [140 x 12] (S3: grouped_df/tbl_df/tbl/data.frame)

$ categorystate : chr [1:140] "AK" "AZ" "AZ" "AZ" ...

$ district      : chr [1:140] "1" "1" "1" "2" ...

$ airdate       : num [1:140] 2016 2012 2016 2012 2016 ...

$ est_cost      : num [1:140] 668330 9017940 3932850 2792690 3309190 ...

$ tone_pos      : num [1:140] 420 1289 1824 2615 5955 ...

$ tone_neg      : num [1:140] 1620 7647 3290 4110 2330 ...

$ estimate      : num [1:140] 524513 522005 522005 561858 561858 ...

$ moe           : num [1:140] 16069 23913 23913 23348 23348 ...

$ competitive   : Factor w/ 2 levels "Not Competitive",..: 1 2 2 1 1 1 1 1 1 1 ...

$ candidateVotes: num [1:140] 308198 251595 280710 292279 315679 ...

$ turnout       : num [1:140] 0.588 0.482 0.538 0.52 0.562 ...

$ ST_dis        : chr [1:140] "AK_1" "AZ_1" "AZ_1" "AZ_2" ...

我不断收到以下错误,指出我只能将对比应用于因素。为了澄清起见,我试图将具有竞争力的交互 PLM 表示为虚拟变量。每当我使用 lm 函数而不是 plm 时,它都能完美运行!我尝试将竞争变量更改为数字和字符,但没有运气。

library(plm)
model_house3 <- plm(turnout ~competitive*tone_neg + factor(airdate) +  est_cost + tone_pos,data 
=house_split_1,index = c("ST_dis"),model = "within")

library(sjplot)
plot_model(model_house3,type = "pred",terms = c("tone_neg","competitive"))

Error in `contrasts<-`(`*tmP*`,value = contr.funs[1 + isOF[nn]]) : 
contrasts can be applied only to factors with 2 or more levels

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)