Skip to content

Error fitting binomial model when data is a tibble #17

@amorrill-ecgc

Description

@amorrill-ecgc

Thank you for your excellent package.

I ran into an error when running a binomial response model when my data was stored as a tibble rather than a dataframe. It seems the dimensions of what is provided to Stan as binomialN somehow gets adjusted from the single dimension that is expected:

Error : Exception: mismatch in number dimensions declared and found in context; processing stage=data initialization; variable name=binomialN; dims declared=(200); dims found=(200,1) (in 'string', line 8, column 2 to column 34) failed to create the sampler; sampling not done

However, the model fits fine when I use as.data.frame() on my data prior to fitting the model.

Here is a reproducible (silly) example based off of the package vignette; this could be run after defining d as it is there:

# Converting vignette gamma response to binomial
d$y <- round(d$y / max(d$y))

# Fitting binomial glmmfields model
m_spatial <- glmmfields(y ~ temperature,
                        data = d, family = binomial(link = "logit"),
                        lat = "lat", lon = "lon", nknots = 12, 
                        iter = 500, chains = 1,
                        prior_intercept = student_t(3, 0, 10),
                        prior_beta = student_t(3, 0, 3),
                        prior_sigma = half_t(3, 0, 3),
                        prior_gp_theta = half_t(3, 0, 10),
                        prior_gp_sigma = half_t(3, 0, 3),
                        seed = 123
)
# ^This works

# Converting d to a tibble
d_tibble <- tibble::as_tibble(d)

# Fitting binomial glmmfields model with data stored as a tibble
m_spatial <- glmmfields(y ~ temperature,
                        data = d_tibble, family = binomial(link = "logit"),
                        lat = "lat", lon = "lon", nknots = 12, 
                        iter = 500, chains = 1,
                        prior_intercept = student_t(3, 0, 10),
                        prior_beta = student_t(3, 0, 3),
                        prior_sigma = half_t(3, 0, 3),
                        prior_gp_theta = half_t(3, 0, 10),
                        prior_gp_sigma = half_t(3, 0, 3),
                        seed = 123
)
# ^This does not work 

I am using glmmfields version 0.1.8 and R version 4.2.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions