drizopoulos / GLMMadaptive

GLMMs with adaptive Gaussian quadrature
https://drizopoulos.github.io/GLMMadaptive/
59 stars 14 forks source link

"Error in eigen(Y, symmetric = TRUE): infinite or missing values in 'x'" #52

Closed moosterwegel closed 8 months ago

moosterwegel commented 8 months ago

Hi Dimitris,

Thanks for fixing the previous issue so quickly. Unfortunately, I ran into another issue on a different dataset. I have reduced the problem to the repex below:

df <- readr::read_csv(here::here("data_w_error.csv"))
#> Rows: 628 Columns: 4
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (4): id, n, y1, left_cens
#> 
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
df |> summary()
#>        id              n               y1          left_cens      
#>  Min.   :  1.0   Min.   :1.000   Min.   :11.01   Min.   :0.00000  
#>  1st Qu.:129.0   1st Qu.:1.000   1st Qu.:13.69   1st Qu.:0.00000  
#>  Median :258.5   Median :1.000   Median :14.09   Median :0.00000  
#>  Mean   :260.2   Mean   :1.172   Mean   :14.09   Mean   :0.01274  
#>  3rd Qu.:394.2   3rd Qu.:1.000   3rd Qu.:14.54   3rd Qu.:0.00000  
#>  Max.   :523.0   Max.   :3.000   Max.   :16.21   Max.   :1.00000
df |> dplyr::group_by(left_cens) |> dplyr::tally()
#> # A tibble: 2 × 2
#>   left_cens     n
#>       <dbl> <int>
#> 1         0   620
#> 2         1     8

# doesn't work:
m <- GLMMadaptive::mixed_model(fixed = GLMMadaptive::formula(cbind(y1, left_cens) ~ 1, type = 'fixed'), 
                               random =  GLMMadaptive::formula(~ 1|id, type = 'random'), 
                               data = df,
                               family = GLMMadaptive::censored.normal())
#> Error in eigen(Y, symmetric = TRUE): infinite or missing values in 'x'

# does work:
m <- GLMMadaptive::mixed_model(fixed = GLMMadaptive::formula(cbind(y1, left_cens) ~ 1, type = 'fixed'), 
                               random =  GLMMadaptive::formula(~ 1|id, type = 'random'), 
                               data = df |> dplyr::mutate(y1 = y1 - 0.76),
                               family = GLMMadaptive::censored.normal())
# doesn't work
m <- GLMMadaptive::mixed_model(fixed = GLMMadaptive::formula(cbind(y1, left_cens) ~ 1, type = 'fixed'), 
                               random =  GLMMadaptive::formula(~ 1|id, type = 'random'), 
                               data = df |> dplyr::mutate(y1 = y1 - 0.75),
                               family = GLMMadaptive::censored.normal())
#> Error in eigen(Y, symmetric = TRUE): infinite or missing values in 'x'

Created on 2024-01-16 with reprex v2.1.0

Here's the stubborn dataset that yields the error: data_w_error.csv

Any idea what's going on? I noticed that Hbetas was a matrix of NaNs after the numer_deriv_vec call.

I'm running version 0.9.2 of GLMMadaptive now on R 4.3.1.

drizopoulos commented 8 months ago

You need to choose better initial values.