rmcelreath / rethinking

Statistical Rethinking course and book package
2.14k stars 601 forks source link

'There appear to be no linear models here' error on simple Gaussian model sample code #139

Open leungi opened 6 years ago

leungi commented 6 years ago

Trying to replicate the introduction sample code and ran into an 'error'.

Issue: map2stan() successfully compiled and return as a valid object, but an error message came along with it. Running WAIC(fit.stan) returns the same error message.

library(rethinking)

f <- alist(y ~ dnorm(mu, sigma), mu ~ dnorm(0, 10), sigma ~ dcauchy(0, 1))

fit <- map(f, data = list(y = c(-1, 1)), start = list(mu = 0, sigma = 1))

fit.stan <- map2stan(f, data = list(y = c(-1, 1)), start = list(mu = 0, sigma = 1))

#> SAMPLING FOR MODEL 'y ~ dnorm(mu, sigma)' NOW (CHAIN 1).
#> 
#> Gradient evaluation took 0 seconds
#> 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Adjust your expectations accordingly!
#> 
#> 
#> Iteration:    1 / 2000 [  0%]  (Warmup)
#> Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Iteration: 2000 / 2000 [100%]  (Sampling)
#> 
#>  Elapsed Time: 0.069 seconds (Warm-up)
#>                0.051 seconds (Sampling)
#>                0.12 seconds (Total)
#> 
#> 
#> SAMPLING FOR MODEL 'y ~ dnorm(mu, sigma)' NOW (CHAIN 1).
#> 
#> Gradient evaluation took 0 seconds
#> 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Adjust your expectations accordingly!
#> 
#> 
#> WARNING: No variance estimation is
#>          performed for num_warmup < 20
#> 
#> Iteration: 1 / 1 [100%]  (Sampling)
#> 
#>  Elapsed Time: 0 seconds (Warm-up)
#>                0 seconds (Sampling)
#>                0 seconds (Total)
#> Computing WAIC
#> Constructing posterior predictions
#> Error in .local(fit, data, n, ...) : 
#>  There appear to be no linear models here
Riadsala commented 6 years ago

Did you ever find out if this is something to be worried about? I have ran in to the same 'error' when messing about with some beta distributions. The message is correct, as there's no linear model, we're just fitting a distribution. But is it anything to be worried about? Am I overlooking a far similar approach to this problem?

m <- map2stan( alist( x ~ dbeta(alpha, beta), alpha ~ dcauchy(0,1), beta ~ dcauchy(0,1)), data = dat)