Schwierig zu sagen ohne klare Daten Details, aber ist das, was Sie wollen?
set.seed(100)
dat<- data.frame(
color=rep(c("red", "orange", "blue"),each=10)
,
var=rnorm(3*10,20,1)
)
levels(dat$color)
dat$is_red=ifelse(dat$color=="red",1,0)
dat$is_blue=ifelse(dat$color=="blue",1,0)
lm(var~is_blue+is_red,dat)
lm(var~factor(color),dat) #base blue
lm(var ~ C(color,contr.treatment(3, base=2)), data=dat)
> lm(var~is_blue+is_red,dat)
Call:
lm(formula = var ~ is_blue + is_red, data = dat)
Coefficients:
(Intercept) is_blue is_red
20.2337 -0.3628 -0.2516
> lm(var~factor(color),dat) #base blue
Call:
lm(formula = var ~ factor(color), data = dat)
Coefficients:
(Intercept) factor(color)orange factor(color)red
19.8709 0.3628 0.1112
> lm(var ~ C(color,contr.treatment(3, base=2)), data=dat)
Call:
lm(formula = var ~ C(color, contr.treatment(3, base = 2)), data = dat)
Coefficients:
(Intercept) C(color, contr.treatment(3, base = 2))1
20.2337 -0.3628
C(color, contr.treatment(3, base = 2))3
-0.2516
Was meinen Sie mit "meine kategorischen Variablen zweimal verwenden"? – Tor
Bitte ein kleines reproduzierbares Beispiel zeigen – akrun