[英]Change cornerpoint in generalized linear model
fit <- glm(formula=y~x1+x2+x3, family = binomial)
x3
是分类变量(是/否)。 此变量的拐角点(是Intercept的一部分)自动变为“ no”。 我想将拐角点更改为“是”。 我怎么做?
编辑具有相同问题的以后的读者:更改x3的级别
一些代码
> attach(dat)
> levels(x9)
[1] "ja" "nej"
> x9 <-factor(x9, levels = c("nej","ja"))
> levels(x9)
[1] "nej" "ja" ###Changing the level was succesfull
> summary(glm(y~.,family = binomial, data=dat))
Call:
glm(formula = y ~ ., family = binomial, data = dat)
Deviance Residuals:
Min 1Q Median 3Q Max
-3.2508 0.2410 0.4698 0.6234 1.5827
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 4.79255 1.42304 3.368 0.000758 ***
x1 -3.19187 2.31703 -1.378 0.168336
x2 1.55657 2.70719 0.575 0.565308
x3 -3.27159 1.08943 -3.003 0.002673 **
x4nej 0.51869 0.41696 1.244 0.213505
x5nej -1.51137 0.75315 -2.007 0.044776 *
x6nej 0.18231 0.30013 0.607 0.543565
x7 0.08706 0.08027 1.085 0.278120
x8b -0.71031 0.30084 -2.361 0.018220 *
x9nej 0.92448 0.38464 2.403 0.016240 * ###OPS: I want: x9ja here
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 396.49 on 425 degrees of freedom
Residual deviance: 342.66 on 416 degrees of freedom
AIC: 362.66
Number of Fisher Scoring iterations: 6
您只需要重新排列因子水平
x3 = factor(x3, levels = c("yes","no"))
glm
使用此顺序。
如果且仅当x3
只是一堆1和0时,您可以切换值。
x3 <- c(1,1,0,0) # old x3
x3_no <- 1 - x3
然后只需在多元回归中使用x3_no
。
dat$x3_no <- 1 - dat$x3
glm(y ~ your_linear_predictor, family = binomial)
您可能还需要更新此功能,以减少错误。
attach <- function(...){
cat("Don't attach your data")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.