stan-dev / stan-dev/rstanarm

stan_nlmer formula and fixed effects

Open
#463 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
R
Stars
401
Forks
136
PR merge metrics
No merged PRs in 30d

Description

Summary:

Problem in specifying fixed effects in stan_nlmer formula.

Description:

Following the documentation of stan_nlmer the formula needs to be in the same form as the nlmer one: a three-part “nonlinear mixed model” formula, of the form resp ~ Nonlin(...) ~ fixed + random (from the nlmer help page).
I can't find a way to specify the fixed effect variable. When I do it, after a long list of rejected values I get:

Chain 1: 
Chain 1: Initialization between (-2, 2) failed after 100 attempts. 
Chain 1:  Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization failed."
error occurred during calling the sampler; sampling not done
Error in check_stanfit(stanfit) : 
  Invalid stanfit object produced please report bug

Also if I try to specify my own function with the suggested deriv option (check example 3 of the nlmer help page), I'm not able to fit the model with stan_nlmer.

I suspect is a long standing problem of nlmer..

Reproducible Steps:

Here an example of the problem with the code you have in your help page

data("Orange", package = "datasets")
Orange$circumference <- Orange$circumference / 100
Orange$age <- Orange$age / 100
#define a new to use as fixed effect:
Orange$fixed.eff <- ifelse(Orange$Tree=="3"|Orange$Tree=="5",1,2)
#try to include it following the formula definition:
fit <- stan_nlmer(
  circumference ~ SSlogis(age, Asym, xmid, scal) ~ fixed.eff + (Asym|Tree), 
  data = Orange,  
  #for speed only
  chains = 1, 
  iter = 1000
)
RStanARM Version:

packageVersion("rstanarm")
[1] ‘2.21.2’
packageVersion("lme4")
[1] ‘1.1.23’
packageVersion("rstan")
[1] ‘2.21.2’

R Version:

[1] ‘4.0.2’

Operating System:

OS X 10.15.6

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducible Orange example in the issue and the stan_nlmer documentation, then compare its three-part formula handling with the nlmer help example and deriv option. The issue names no source files or tests; done means establishing whether fixed.eff and a user-supplied deriv function are supported and clearly characterizing the observed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.