rms icon indicating copy to clipboard operation
rms copied to clipboard

contrast.rms collapses small p-values to zero

Open alexploner opened this issue 9 years ago • 2 comments

The function contrast.rms reports the p-values for all Wald statistics absolutely larger than ca. 9 as an exact zero.

Example adapted from the contrast.rms help page with Z=10.36:

set.seed(1)
x  = rnorm(500)
xb = 1+2*x
y  = ifelse(runif(500) <= plogis(xb), 1, 0)
f  = lrm(y ~ x)
ct = contrast(f, list(x=1))
ct
ct$P==0 ## Exact zero

The problem seems to be the line below in contrast.s where the p-value is calculated:

P <- if(length(idf)) 2 * (1 - pt(abs(Z), idf)) else 2 * (1 - pnorm(abs(Z)))

Replacing this with

P <- if(length(idf)) 2 * (1 - pt(abs(Z), idf)) else 2 *  pnorm(-abs(Z))

should do the trick.

rms 4.3-1

               _                           
platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          2.2                         
year           2015                        
month          08                          
day            14                          
svn rev        69053                       
language       R                           
version.string R version 3.2.2 (2015-08-14)
nickname       Fire Safety 

alexploner avatar Sep 30 '15 16:09 alexploner

To be consistent should that not be

|P <- if(length(idf)) 2 * pt(-abs(Z), idf)) else 2 * pnorm(-abs(Z)) |

On 09/30/2015 11:48 AM, Alexander Ploner wrote:

The function |contrast.rms| reports the p-values for all Wald statistics absolutely larger than ca. 9 as an exact zero.

Example adapted from the |contrast.rms| help page with Z=10.36:

|set.seed(1) x = rnorm(500) xb = 1+2*x y = ifelse(runif(500) <= plogis(xb), 1, 0) f = lrm(y ~ x) ct = contrast(f, list(x=1)) ct ct$P==0 ## Exact zero |

The problem seems to be the line below in |contrast.s| where the p-value is calculated:

|P <- if(length(idf)) 2 * (1 - pt(abs(Z), idf)) else 2 * (1 - pnorm(abs(Z))) |

Replacing this with

|P <- if(length(idf)) 2 * (1 - pt(abs(Z), idf)) else 2 * pnorm(-abs(Z)) |

should do the trick.

|rms 4.3-1 _ platform x86_64-w64-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 status major 3 minor 2.2 year 2015 month 08 day 14 svn rev 69053 language R version.string R version 3.2.2 (2015-08-14) nickname Fire Safety |

— Reply to this email directly or view it on GitHub https://github.com/harrelfe/rms/issues/13.


Frank E Harrell Jr Professor and Chairman School of Medicine

Department of *Biostatistics*   *Vanderbilt University*

harrelfe avatar Sep 30 '15 17:09 harrelfe

Of course! Sorry, completely blinded to dfs :) /alexander

On 2015-09-30 19:16, Frank Harrell wrote:

To be consistent should that not be

|P <- if(length(idf)) 2 * pt(-abs(Z), idf)) else 2 * pnorm(-abs(Z)) |

On 09/30/2015 11:48 AM, Alexander Ploner wrote:

The function |contrast.rms| reports the p-values for all Wald statistics absolutely larger than ca. 9 as an exact zero.

Example adapted from the |contrast.rms| help page with Z=10.36:

|set.seed(1) x = rnorm(500) xb = 1+2*x y = ifelse(runif(500) <= plogis(xb), 1, 0) f = lrm(y ~ x) ct = contrast(f, list(x=1)) ct ct$P==0 ## Exact zero |

The problem seems to be the line below in |contrast.s| where the p-value is calculated:

|P <- if(length(idf)) 2 * (1 - pt(abs(Z), idf)) else 2 * (1 - pnorm(abs(Z))) |

Replacing this with

|P <- if(length(idf)) 2 * (1 - pt(abs(Z), idf)) else 2 * pnorm(-abs(Z)) |

should do the trick.

|rms 4.3-1 _ platform x86_64-w64-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 status major 3 minor 2.2 year 2015 month 08 day 14 svn rev 69053 language R version.string R version 3.2.2 (2015-08-14) nickname Fire Safety |

— Reply to this email directly or view it on GitHub https://github.com/harrelfe/rms/issues/13.


Frank E Harrell Jr Professor and Chairman School of Medicine

Department of Biostatistics Vanderbilt University

— Reply to this email directly or view it on GitHub https://github.com/harrelfe/rms/issues/13#issuecomment-144480857.

Alexander Ploner Medical Epidemiology & Biostatistics Karolinska Institutet http://ki.se/meb

alexploner avatar Sep 30 '15 17:09 alexploner