I'm trying to run a small data table through the lrm function from the rms library, but every time I run it I get this:
Error in fitter(X, Y, offset = offs, penalty.matrix = penalty.matrix, :
NA/NaN/Inf in foreign function call (arg 1)
Here's some reproducible code:
library(tidyverse)
library(rms)
data <- tribble(
~a, ~b, ~c,
"name", 2, 77.95535,
"name", 2, 81.36152,
"name", 2, 80.87081,
"name", 2, 80.59054,
"name", 2, 79.36807,
"name", 2, 82.42083,
"name", 2, 78.80646,
"name", 2, 78.88949
)
lmod <- lrm(b~c, data, penalty=0, x=T, y=T, tol=1e-10, maxit=1e6)
I've tried a variety of things. I tried switching b~c to c~b (I know it wouldn't yield the same data) and I got an error, but not the same error. I tried using only the first two parameters, as well as a variety of including or excluding the following ones. I've also tried debugging and following the code into the lrm function, and I narrowed it down to (shocker) the fitter function.
Here's some resources that I've been using that you might find helpful for yourselves or to help me. If there's anything I forgot to include drop a comment and I'll fill in what I can:) Thanks!
R Reference Manual
lrm Function Description
R for Data Science (book)
lrm Function Source Code
I get the same error using your supplied data. Then I changed some b
to 1, the error disappeared:
data <- tribble(
~a, ~b, ~c,
"name", 2, 77.95535,
"name", 2, 81.36152,
"name", 1, 80.87081,
"name", 1, 80.59054,
"name", 2, 79.36807,
"name", 1, 82.42083,
"name", 1, 78.80646,
"name", 2, 78.88949
)
lmod <- lrm(b~c, data = data, penalty=0, x=TRUE, y=TRUE, tol=1e-14, maxit=1e10)
lmod
Logistic Regression Model
lrm(formula = b ~ c, data = data, x = TRUE, y = TRUE, penalty = 0,
tol = 1e-14, maxit = 1e+10)
Model Likelihood Discrimination Rank Discrim.
Ratio Test Indexes Indexes
Obs 8 LR chi2 0.00 R2 0.000 C 0.500
1 4 d.f. 1 g 0.000 Dxy 0.000
2 4 Pr(> chi2) 1.0000 gr 1.000 gamma 0.000
max |deriv| 3 gp 0.000 tau-a 0.000
Brier 0.250
Coef S.E. Wald Z Pr(>|Z|)
Intercept 0.0000 39.9600 0.00 1.0000
c 0.0000 0.4992 0.00 1.0000
I know it's only a subset of your data, but maybe all rows in b
have value 2? You can check that with eg, table(data$b)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.