r - 如何使用 jtools 包中的 coef_plot 在系数图中更好地标记分类变量
问题描述
我正在尝试创建包含分类和线性变量的线性模型的系数图。我希望系数图显示分类变量的系数是与基线类别的比较 - 这里“国家”将其他国家与“英格兰”进行比较。
有没有办法做到这一点,而不是将每个变量单独标记为“国家变量 - 与英格兰 - 威尔士的比较”或类似的东西?下面的示例代码
## Create example dataframe
DV <- c(0.1, 0.6, 0.8, 1, 1, 0, 0.4, 0.8, 0.9 , 0.3)
country <- c('England', 'Wales', 'Scotland', 'England', 'Wales', 'Scotland', 'England', 'Wales', 'Scotland', 'Scotland')
politics <- c(0.8, 1, 0.1, 0.6,0, 1, 0.9 , 0.3, 0.4, 0.8)
df <- data.frame(DV, country, politics)
## Run linear model
mod1 <- lm(DV ~ country + politics, data = df)
## Coefficient plot of the model
plot_coefs(mod1)
## Rename the variables in the coefficient plot
plot_coefs(mod1,
coefs = c('Scotland' = 'countryScotland',
'Wales' = 'countryWales',
'Political alignment' = 'politics'))
以上并没有达到我想要的 - 分类变量不同级别的系数显然不是分类变量的级别。谢谢
我想更改标签,使其显示类似
国家(以英格兰为基准)
- 苏格兰
- 威尔士
系数显示在级别标签的右侧,但标题显示它是具有多个级别的分类变量
解决方案
推荐阅读
- python - Kafka生产者和消费者脚本自动运行
- javascript - 我的 HTML 表单发送电子邮件但不从数据发送。可能是什么问题呢?
- linux - 无法打开流或文件 .../logs/laravel.log:无法打开流:权限被拒绝。不同的用户需要写日志
- ios - iOS 通知服务扩展导致程序以退出代码结束:0
- javascript - 如何在 nuxt.js 中挑选 bootstrap-vue.js 模块?
- c# - 单个正则表达式去除除锚点之外的所有 HTML
- python - 正在尝试运行算法,加载数据集时出现错误可以解决吗?如何在python中解决?
- sql - 如何使用 Distinct(id) 将 Sql 转换为 Linq
- go - golang中的模拟内部函数
- arrays - 如何获得具有通用大小的数组的所有组合?