--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/B1x42n0ecQw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
Here is the most simple example of an extremes model, fitting a univariate stationary GEV distribution.
functions {
real gev_log (real y, real mu, real sigma, real xi){
real z;
z <- 1 + (y - mu) * xi / sigma;
return -log(sigma) - (1 + 1/xi)*log(z) - pow(z,-1/xi);
}
}
data {
int<lower=0> N;
real y[N];
}
transformed data {
real min_y;
real max_y;
min_y <- min(y);
max_y <- max(y);
}
parameters {
real xi;
real<lower=0> sigma;
// location has upper/lower bounds depending on the value of xi
real<lower=if_else( xi < 0, min_y + sigma / xi, negative_infinity() ),
upper=if_else( xi > 0, positive_infinity(), max_y + sigma / xi )> mu;
}
model {
# priors on component parameters
sigma ~ gamma(.0001,.0001);
#mu ~ uniform
xi ~ uniform(-.5,.5);
for(i in 1:N) {
y[i] ~ gev(mu, sigma, xi);
}
}
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
Bob,
Thanks a ton for the feedback. I am actually using my GEV function in far more complex models so your vector implementation should help a lot. Feel free to use as you please in the manual. A built in GEV and GPD function would be fantastic.
I made some changes to the model and get an error that I am not sure how to fix:
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model 'gev' with error message:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
no matches for function name="size"
arg 0 type=vector
available function signatures for size:
0. size(int[1]) : int
1. size(real[1]) : int
2. size(vector[1]) : int
3. size(row vector[1]) : int
4. size(matrix[1]) : int
5. size(int[2]) : int
6. size(real[2]) : int
...
functions {
real gev_log (vector y, real mu, real sigma, real xi) {
vector[size(y)] z;
vector[size(y) + 1] lp;
real inv_xi;
real inv_xi_p1;
real neg_inv_xi;
z <- ((1 + y) - mu) * (xi / sigma);
inv_xi <- inv(xi);
inv_xi_p1 <- 1 + inv_xi;
neg_inv_xi <- -inv_xi;
for (n in 1:size(y))
lp[n] <- inv_xi_p1 * log(z[n]) + pow(z[n],neg_inv_xi);
lp[size(y) + 1] <- size(y) * log(sigma);
return -sum(lp);
}
}
data {
int<lower=0> N;
real y[N];
}
transformed data {
real min_y;
real max_y;
real sd_y;
min_y <- min(y);
max_y <- max(y);
sd_y <- sd(y);
}
parameters {
real<lower=-0.5,upper=0.5> xi;
real<lower=0> sigma;
// location has upper/lower bounds depending on the value of xi
real<lower=if_else( xi < 0, min_y + sigma / xi, negative_infinity() ),
upper=if_else( xi > 0, positive_infinity(), max_y + sigma / xi )> mu;
}
model {
# priors
sigma ~ normal(sd_y,100);
#mu ~ uniform
#xi ~ uniform(-.5,.5);
y ~ gev(mu, sigma, xi);
}
Thanks,
Cameron
> Tymoteusz Wołodźko
> Zespół Analiz Osiągnięć Uczniów Instytut Badań Edukacyjnych | ul. Górczewska 8 | 01-180 Warszawa
> tel. +48 695 370 391 | www.ibe.edu.pl
>
>
>
>
I made some changes to the model and get an error that I am not sure how to fix:Error in stanc(file = file, model_code = model_code, model_name = model_name, : failed to parse Stan model 'gev' with error message: SYNTAX ERROR, MESSAGE(S) FROM PARSER: no matches for function name="size" arg 0 type=vector available function signatures for size: 0. size(int[1]) : int 1. size(real[1]) : int 2. size(vector[1]) : int 3. size(row vector[1]) : int 4. size(matrix[1]) : int 5. size(int[2]) : int 6. size(real[2]) : int
rows(y)