F-distribution

Hello,

if F-distribution included in Stan? If not do you guys have any idea whether there is an easy way to expressed it in terms of other distributions (e.g., beta)

Thanks

A first attempt

stan(
	model_code="
functions{
	real f_lpdf(real x, real d1, real d2){
		return (	0.5 * (-d1 * log(d1 * x + d2) -
						d2 * log(d1 * x + d2) + d1 * log(x) + d1 * log(d1) +
						d2 * log(d2) - 2 * log(x)) - lbeta(d1/2, d2/2)			);
	}
}
	data {
	int<lower=1> G;
	vector[G] y; 
	}
	parameters { real<lower=0> h[2]; }
	model { for(g in 1:G) y[g] ~ f(h[1], h[2]); }
	", 
data = list(G=(1000), y=rf(1000, 20, 20), refresh = 0)
)

from https://en.wikipedia.org/wiki/F-distribution
using https://www.wolframalpha.com/input/?i=log((1%2F(B(d1%2F2,+d2%2F2)))++(d1%2Fd2)%5E(d1%2F2)++(x%5E(d1%2F2-1))++(1%2Bd1%2Fd2x)%5E(-((d1%2Bd2)%2F2)))

1 Like