Sigh... In a linear model with qualitative predictor variables, models with and without intercepts are just different parameterizations of the *same* model. -- they produce exactly the same predicted responses. So what do you mean?
Search on "contrasts in linear models R" and similar for an explanation. Cheers, Bert On Tue, Feb 21, 2023, 13:34 varin sacha via R-help <r-help@r-project.org> wrote: > Dear R-experts, > > Here below my R code working with quite a few warnings. > x11 and x12 are dichotomous variable (0=no and 1=yes). I substract 1 to > ignore intercept. > I would like not to ignore intercept. How to modify my R code because if I > just remove -1 it does not work? > > > y= c(32,45,65,34,23,43,65,76,87,98,7,867,56,45,65,76,88,34,55,66) > x11=c(0,1,1,0,0,1,1,1,0,0,1,0,0,1,0,0,1,1,0,1) > x12=c(0,1,0,1,0,1,1,0,1,1,0,0,1,1,1,0,0,1,0,0) > > Dataset=data.frame(y,x11,x12) > > a=lm(y~x11+x12-1,Dataset)$coef > b=NULL > for(i in c(1:2)) { > f=formula(paste('y~',names(Dataset)[i],-1)) > b=c(b,lm(f,Dataset)$coef) > } > coef=data.frame(rbind(a,b)) > coef$Model=c('Multi','Single') > library(reshape2) > coef.long<-melt(coef,id.vars="Model") > > library(ggplot2) > ggplot(coef.long,aes(x=variable,y=value,fill=Model))+ > geom_bar(stat="identity",position="dodge")+ > scale_fill_discrete(name="Model", > labels=c("Multiple", "Simple"))+ > labs(title =paste('La différences des coefficients > entre la régression multiple et simple'), > x="Models",y="Coefficient")+ > coord_flip() > > > > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.