Search code examples
rlm

Regression results: default display format


I am running regressions in R using lm() function and I can't manage to display results in simple format. I need to print a vector of p-values:

> summary(lm)$coef[,4]
  (Intercept)           lun          d1un 
 1.433706e-01 4.673723e-158  6.629044e-04 

How can I override scientific notation and get reasonable precision? I tried options(scipen=1000), but it displays endless lines of digits, somehow options(digits=7) does not work here.

I know I can use things like format and sprints, but I would like to set the default display rule for all numeric output, e.g. not more then 6 decimals.


Solution

  • I don't think this will be possible, for general display throughout R. ?options says this about digits:

     ‘digits’: controls the number of digits to print when printing
          numeric values.  It is a suggestion only.  Valid values are
          1...22 with default 7.  See the note in ‘print.default’ about
          values greater than 15.
    

    The key phrase is "It is a suggestion only".

    Next, note that what is printed is at first governed by the print() method applied (this is hidden during interactive use, because R auto-print()s). For details see ?print and ?print.default for the basic methods. From ?print.default we note

    digits: a non-null value for ‘digits’ specifies the minimum number of
            significant digits to be printed in values.  The default,
            ‘NULL’, uses ‘getOption(digits)’.  (For the interpretation
            for complex numbers see ‘signif’.)  Non-integer values will
            be rounded down, and only values greater than or equal to 1
            and no greater than 22 are accepted.
    

    and in the Details section we have:

       The same number of decimal places is used throughout a vector.
       This means that ‘digits’ specifies the minimum number of
       significant digits to be used, and that at least one entry will be
       encoded with that minimum number.  However, if all the encoded
       elements then have trailing zeroes, the number of decimal places
       is reduced until at least one element has a non-zero final digit.
       Decimal points are only included if at least one decimal place is
       selected.
    

    The default for digits is NULL which indicates that getOption("digits") is used, but as we already noted, that is a guide only.

    There doesn't appear to be a way to configure R to do what you want nor do it globally. You would need to rewrite print.default() or all the print() methods you needed to use and make those version be used instead of the standard versions --- not easy now with NAMESPACES.