[R] Extracting only some coefficients for the logistic regression model and its plot
Jim Lemon
drj|m|emon @end|ng |rom gm@||@com
Wed Jun 15 07:07:49 CEST 2022
Hi Hana,
str(model) will display the structure of the returned object. However,
you want the summary of that object, so:
As you have already constructed the estimate and confidence interval
matrix, you only have to extract rows 3 to 7 and columns 1:3:
> exp(cbind(OR = coef(model ), confint(model )))[3:7,1:3]
Waiting for profiling to be done...
OR 2.5 % 97.5 %
X3A 0.01157565 0.001429430 0.08726854
X3B 0.06627849 0.008011818 0.54419759
X3C 0.01118084 0.001339984 0.08721028
X3D 0.01254032 0.001545240 0.09539880
X3E 0.10654454 0.013141540 0.87369972
Jim
On Wed, Jun 15, 2022 at 1:38 PM anteneh asmare <hanatezera using gmail.com> wrote:
>
> sample_data = read.table("http://freakonometrics.free.fr/db.txt",header=TRUE,sep=";")
> head(sample_data)
> model = glm(Y~0+X1+X2+X3,family=binomial,data=sample_data)
> summary(model)
> exp(coef(model ))
> exp(cbind(OR = coef(model ), confint(model )))
> I have the aove sample data on logistic regression with categorical predictor
> I try the above code i get the follwing out put,
> OR 2.5 % 97.5 %
> X1 1.67639337 1.352583976 2.09856514
> X2 1.23377720 1.071959330 1.42496949
> X3A 0.01157565 0.001429430 0.08726854
> X3B 0.06627849 0.008011818 0.54419759
> X3C 0.01118084 0.001339984 0.08721028
> X3D 0.01254032 0.001545240 0.09539880
> X3E 0.10654454 0.013141540 0.87369972
> but i am wondering i want to extract OR and CI only for factors, My
> desire out put will be
> OR 2.5 % 97.5 %
> X3A 0.01157565 0.001429430 0.08726854
> X3B 0.06627849 0.008011818 0.54419759
> X3C 0.01118084 0.001339984 0.08721028
> X3D 0.01254032 0.001545240 0.09539880
> X3E 0.10654454 0.013141540 0.87369972
> Can any one help me the code to extact it?
> additionally I want to plot the above OR with confidence interval for
> the extracted one
> can you also help me the code with plot,or box plot
> Kind Regards,
> Hana
>
> ______________________________________________
> R-help using 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.
More information about the R-help
mailing list