1

I have a logistic regression output and odds ratio with the format odds ratio:

  variables   oddsratio    2.5%      97.5%      p-value
      height  0.9810833  0.9724681  0.9898     2.197e-05 ***
      weight  0.9889900  0.9794387  0.9986     0.025356 *  
        BMI   1.0097044  1.0029179  1.0165     0.005005 ** 

but I want the output of p-value in the decimal format like

pvalue
0.001
0.025
0.005

1 Answers1

1

For just console output read @EliBerkow's link in the comment to your question. For table outputs or to use in a function you may use formatC().

Example

(output <- summary(glm(I(Sepal.Length > 5.7) ~ Sepal.Width + Species, iris, 
                       family=binomial()))$coefficients)
#                     Estimate Std. Error   z value     Pr(>|z|)
# (Intercept)       -15.846295   3.893382 -4.070059 4.700128e-05
# Sepal.Width         3.274112   0.970872  3.372342 7.453193e-04
# Speciesversicolor   7.149531   1.533740  4.661501 3.139108e-06
# Speciesvirginica    9.283911   1.630188  5.694992 1.233776e-08

All with four digits:

as.data.frame(apply(output, 2, formatC, format="f", digits=4))
#                   Estimate Std. Error z value Pr(>|z|)
# (Intercept)       -15.8463     3.8934 -4.0701   0.0000
# Sepal.Width         3.2741     0.9709  3.3723   0.0007
# Speciesversicolor   7.1495     1.5337  4.6615   0.0000
# Speciesvirginica    9.2839     1.6302  5.6950   0.0000

Different number of digits:

setNames(data.frame(output[,-4], formatC(output[,4], format="f", digits=4)), colnames(output))
#                     Estimate Std. Error   z value Pr(>|z|)
# (Intercept)       -15.846295   3.893382 -4.070059   0.0000
# Sepal.Width         3.274112   0.970872  3.372342   0.0007
# Speciesversicolor   7.149531   1.533740  4.661501   0.0000
# Speciesvirginica    9.283911   1.630188  5.694992   0.0000
Community
  • 1
  • 1
jay.sf
  • 60,139
  • 8
  • 53
  • 110