我想用化系数的名字来画一个coefplot.glm()。
考虑以下代码:
coefplot::coefplot.glm(lm(rbinom(1000,1,.5) ~ rnorm(1000,50,2) + rbinom(1000,1,prob=0.63) + rpois(1000, 2)))这很好,但给出了原始变量名;我想在coefplot.glm()调用中更改它们为c("x1", "x2", "x3", "Intercept")。实际上,我正在处理分解数据,并将其重命名并不容易--重命名将是另一个导入的向量。
我试过了
coefplot::coefplot.glm(lm(rbinom(1000,1,.5) ~ rnorm(1000,50,2) + rbinom(1000,1,prob=0.63) + rpois(1000, 2)),
newNames = c("1", "2", "3", "Interc"))但这会产生
映射值中的
错误(x,from = same (替换),to =替换,warn_missing = warn_missing):
from和to向量的长度不一样。
发布于 2019-11-28 11:33:17
您需要一个命名的向量,如果您想在coefplot.glm中使用它,它就不那么简单了,您可以尝试如下:
# create a function first for your lm
f = function(){
lm(rbinom(1000,1,.5) ~ rnorm(1000,50,2) + rbinom(1000,1,prob=0.63) + rpois(1000, 2))
}使用该函数,您可以调用它两次,第一次用于绘图,第二次用于获取名称。
coefplot::coefplot.glm(f(),
newNames = setNames(c("Interc", "3", "2", "1"),names(coefficients(f())))
)或者你就这么做:
library(ggplot2)
coefplot::coefplot.glm(fit) + scale_y_discrete(labels=c("Interc", "3", "2", "1"))发布于 2019-11-25 17:07:03
关于
data <- data.frame(y=rbinom(1000,1,.5) ,x1=rnorm(1000,50,2),x2=rbinom(1000,1,prob=0.63),x3=rpois(1000, 2))
model<-lm(y~ x1 +x2 +x3 ,data=data)
coefplot::coefplot.glm(model)https://stackoverflow.com/questions/59036723
复制相似问题