How to extract coefficients from elrm summary output

你离开我真会死。 提交于 2019-12-23 12:04:21

问题


I ran exact logistic regression on my data set using the package elrm

I am comparing it to ordinary logistic regression.

I was able to run a bootstrap on the ordinary logistic regression, the statistics of interest I pulled were the estimated coefficient and p-value.

However, I cannot run my elrm bootstrap because I can't pull the coefficients I need from the output.

With my data the summary gives a print out:

Results:
   estimate p-value p-value_se mc_size
M  0.15116 0.06594    0.00443   49000

95% Confidence Intervals for Parameters

     lower     upper
M 0.00156155 0.3647232

I want to extract the M estimate and p-value so I can pull these stats when I do the bootstrap. I have tried a bunch of different combinations to try and pull the values and they aren't working.

summary(model)$coefficient 
summary(model)$Results
summary(model)$estimate

All of these just spit out the summary again.

Does anyone know if it is possible to extract from the elrm summary?

Any help would be appreciated.


回答1:


library(elrm)
data(drugDat)
drug.elrm <- elrm(formula=recovered/n~sex+treatment,interest=~sex+treatment,r=4, 
    iter=100000,burnIn=1000,dataset=drugDat)

> summary.elrm(drug.elrm)

Call:
[[1]]
elrm(formula = recovered/n ~ sex + treatment, interest = ~sex + 
    treatment, r = 4, iter = 1e+05, dataset = drugDat, burnIn = 1000)


Results:
          estimate p-value p-value_se mc_size
joint           NA 0.14886    0.00173   99000
sex        0.27092 0.69385    0.01204    2649
treatment  0.76739 0.07226    0.00314   13160

95% Confidence Intervals for Parameters

               lower    upper
sex       -0.6217756 1.212499
treatment -0.1216884 1.852346

# If you look at the summary function, it simply outputs formatted results to
# the screen. So instead, we can just work with the original drug.elrm object

names(drug.elrm)
# shows you everything in this object

# to see the p-values
drug.elrm$p.values.se
      joint         sex   treatment 
0.001734482 0.012039701 0.003143006 

# to get the p-value for joint
drug.elrm$p.values.se[[1]]

# now for the CI
drug.elrm$coeffs.ci
               lower    upper
sex       -0.6217756 1.212499
treatment -0.1216884 1.852346

> drug.elrm$coeffs.ci[[1]]
[1] -0.6217756 -0.1216884
> drug.elrm$coeffs.ci[[1]][1]
[1] -0.6217756
> 



回答2:


It looks like the p-values and confidence intervals are stored as part of the model object itself. The summary.elrm function just extracts and formats some of that information for you. I show the steps below that I used to figure this out, but the summary version is to index into your model object itself for object$p.values and object$coeffs.ci respectively.

#Example from help page
data(utiDat) 
uti.elrm <- elrm(uti/n~age+current+dia+oc+pastyr+vi+vic+vicl+vis,
                 interest=~dia,r=4,iter=5000,burnIn=1000,dataset=utiDat)
#Look at summary
summary(uti.elrm)
#Let's examine the structure of the summary object to see what's in there, i.e.
#what can we extract?
str(summary(uti.elrm))
#Hmm, doesn't look like anything of interest. Let's look at the source code itself
summary.elrm
#Looks like the p.values are stored in the actual model object iself and the summary function
#just formats them for us. The relevant part of the summary code for the p-value is:
#-----
  #inferences = as.data.frame(cbind(round(as.numeric(object$coeffs),5), 
  #                                 round(as.numeric(object$p.values), 5), 
  #                                 round(as.numeric(object$p.values.se),5),
  #                                 object$mc.size)
  #                           )
  #results = data.frame(row.names = names(object$coeffs), inferences)
  #names(results) = c("estimate", "p-value", "p-value_se", "mc_size")
#So, it looks like we can grab the p.values directly from "object"
> uti.elrm$p.values
dia 
0.02225
#And the confidence intervals are also in the object, located here in the summary code:
#-----
  #cat(object$ci.level, "% Confidence Intervals for Parameters\n", 
  #    sep = "")
  #cat("\n")
  #print(object$coeffs.ci)
#So we can extract them thusly:
> uti.elrm$coeffs.ci
lower upper
dia 0.1256211   Inf


来源:https://stackoverflow.com/questions/11267376/how-to-extract-coefficients-from-elrm-summary-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!