OpenBugs/R categorical variable "yes", "no" as 1,0

62 Views Asked by At

I have a simple logistical regression like


logit(p[i]) <- b0 + b1*x[i]

but data for the p[i] is given as "yes", "no". How to encode ("yes"/"no") to (1,0) ?

e.g. smt like this


logit(encode(p[i])) <- b0 + b1*x[i]

1

There are 1 best solutions below

1
On

Try the old fashion way! I am assuming that p and x are columns of data that I combine in a dataframe named 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)