Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个简单的逻辑回归,比如
logit(p[i]) <- b0 + b1*x[i]
但是 p[i] 的数据以“是”、“否”的形式给出。如何将 ("yes"/"no") 编码为 (1,0) ?
例如像这样的smt
logit(encode(p[i])) <- b0 + b1*x[i]
尝试旧时尚方式!我假设 p 和 x 是我在名为 df 的数据框中组合的数据列。
library(tidyverse) library(stats) # for glm df <- as.dataframe(cbind(p,x)) df %>% mutate(p=ifelse(p=="yes",1,0) logit.model <- glm(p~x, data=df, family=binomial(link="logit")) summary(logit.model)