0

I used the package "logistf" to perform a logistic regression in R.

df <- read.csv("data.csv",header=T,row.names=1)
df <- as.data.frame(sapply(df, as.numeric))


df_split <- initial_split(df, prop = 0.9)

df_train <- 
  training(df_split) %>% 
  verify(expr = nrow(.) == 14355L)

df_test <- 
  testing(df_split) %>% 
  verify(expr = nrow(.) == 1596L)


x_train <- as.matrix(df_train[,1:259]) # Removes class
y_train <- as.double(as.matrix(df_train[, 260]))


mle <- logistf(y_train ~ x_train, firth=TRUE, family = binomial)

When I run the above code, I get the following error:

Error in logistf.fit(x = x, y = y, weight = weight, offset = offset, firth,  : 
  In iteration 0: Determinant of Fisher information matrix was numerically 0

How can I fix this error?

NakataKoo
  • 11
  • 2
  • Hard to say without having access to your data unfortunately. Maybe the suggestion in the answer here might help: https://stackoverflow.com/questions/39314362/cannot-comprehend-this-error-message-in-spatstat-in-r-while-using-kppm-function. Do you have any regressors with a large scale? It might be practical to re-scale x_train using the scale function before modelling https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/scale – Jonny Phelps Nov 25 '22 at 13:26

0 Answers0