stan-dev / rstanarm

rstanarm R package for Bayesian applied regression modeling
https://mc-stan.org/rstanarm
GNU General Public License v3.0
389 stars 133 forks source link

Gaussian family, logit link #243

Closed dhicks closed 5 years ago

dhicks commented 6 years ago

Summary:

I'm trying to model a bounded continuous variable using a GLMM with a logit link and a Gaussian family. This works in lme4 but not rstanarm.

Description:

In my actual dataset, I have a variable $H$ that is bounded between 0 and 1. (TMI: $H_d$ is the entropy of document $d$'s topic distribution in a topic model with 2 topics.) I'm trying to fit a GLMM with $H$ as the dependent variable. It makes sense to model $H$ as having a logit-normal conditional distribution, which means I want a Gaussian family with a logit link. This combination is available in lme4; but rstanarm raises an error that 'link' must be one of identity, log, inverse.

Reproducible Steps:

## MWE dataset where the dependent variable is bounded between 0 and 1
dataf = rstanarm::radon
dataf = dataf[which(dataf$log_radon < 1 & dataf$log_radon > 0),]

library(lme4)
glmer(data = dataf, 
      log_radon ~ 1 + (1|county),
      family = gaussian(link = 'logit'))
## Works as expected

library(rstanarm)
stan_glmer(data = dataf, 
           log_radon ~ 1 + (1|county), 
           family = gaussian(link = 'logit'))
## Raises the exception

RStanARM Version:

2.15.3

R Version:

3.4.2

Operating System:

OS X 10.13.2

bgoodri commented 6 years ago

The rstanarm package enumerates the links that are valid for a particular family, and as you have seen, logit is not among them for a Gaussian family. What is supported (and is a better idea) would be to use stan_betareg with a logit link when the outcome is strictly between 0 and

  1. Or if you install the github version, you can use the betar family in the mgcv function to do something similar but with lme4-style group terms.

On Wed, Dec 20, 2017 at 12:26 PM, Dan Hicks notifications@github.com wrote:

Summary:

I'm trying to model a bounded continuous variable using a GLMM with a logit link and a Gaussian family. This works in lme4 but not rstanarm. Description:

In my actual dataset, I have a variable $H$ that is bounded between 0 and

  1. (TMI: $H_d$ is the entropy of document $d$'s topic distribution in a topic model with 2 topics.) I'm trying to fit a GLMM with $H$ as the dependent variable. It makes sense to model $H$ as having a logit-normal conditional distribution, which means I want a Gaussian family with a logit link. This combination is available in lme4; but rstanarm raises an error that 'link' must be one of identity, log, inverse. Reproducible Steps:

MWE dataset where the dependent variable is bounded between 0 and 1

dataf = rstanarm::radon dataf = dataf[which(dataf$log_radon < 1 & dataf$log_radon > 0),]

library(lme4) glmer(data = dataf, log_radon ~ 1 + (1|county), family = gaussian(link = 'logit'))

Works as expected

library(rstanarm) stan_glmer(data = dataf, log_radon ~ 1 + (1|county), family = gaussian(link = 'logit'))

Raises the exception

RStanARM Version:

2.15.3 R Version:

3.4.2 Operating System:

OS X 10.13.2

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstanarm/issues/243, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOrqspbD-i6OePyJMeOYZoxIGwdAYHbks5tCUNXgaJpZM4RIt3u .