[R] problem in metro_hasting function
hms Dreams
cute_loomaa at hotmail.com
Thu Dec 10 22:22:22 CET 2015
No, it is not a homework..
The 3 paramters I want to estimate it are : alpha,gam and delta, the range of them >0
here my code:
library("MHadaptive")
baysianlog5=function
(param,data)
{
alpha=param[1]
gam=param[2]
delta=param[3]
x=data n =length(x)
logl=n*log(alpha)+n*log(gam)+n*log(1/delta)+(alpha-1)*sum(log(x))-(gam+1)*sum(log(1+(1/delta)*x^alpha))
p=prior5(param)
return(logl+p) #return log(p(x|theta)p(theta))
}
#non
informative prior using uniform
prior5=function(param)
{ alpha=param[1]
gam=param[2]
delta=param[3]
prior_alpha=dunif(alpha,0, 1,log=TRUE)
prior_gam=dunif(gam,0,.5,log=TRUE)
prior_delta=dunif(delta,0,.8,log=TRUE)
return(prior_alpha+
prior_gam +prior_delta)
}
alphaB5=c(); gamB5=c();deltaB5=c()
n=5 ; m=5
alpha=2;gam=3;delta=4 #initial values
v= runif(n,0,1)
x =delta^(1/alpha)*((1-v)^(-1/gam)-1)^(1/alpha)# quantile
mc5 =Metro_Hastings(li_func=baysianlog5, pars=c(.8,.2,.2),par_names=c('alpha','gamma','delta'),data=x )
#the output is
Error in optim(pars, li_func, control = list(fnscale = -1), hessian = TRUE, :
non-finite finite-difference value [1]
Can you help me
Sara
> Date: Thu, 10 Dec 2015 11:23:56 -0800
> Subject: Re: [R] problem in metro_hasting functionþ
> From: bgunter.4567 at gmail.com
> To: cute_loomaa at hotmail.com
> CC: r-help at r-project.org
>
> Heh, heh ...
>
> Uniform distributions are not necessarily "non-informative" priors
> (itself, a non-definition). See, e.g.
> http://www.stats.org.uk/priors/noninformative/YangBerger1998.pdf .
> For a basic argument, see:
> http://www.amstat.org/publications/jse/v12n2/zhu.pdf
>
> Further discussion is off-topic here (it's a statistical, not an R,
> question). I suggest you consult a local statistician for details.
>
> And your question itself is noninformative: how can one tell without
> knowing what you are trying to optimize, your data, your starting
> values, etc. (unless I have missed something obvious)?
>
> Finally, if this is homework, post elsewhere: this list has a no
> homework policy.
>
> Cheers,
> Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, Dec 10, 2015 at 9:26 AM, hms Dreams <cute_loomaa at hotmail.com> wrote:
> > Hello,
> > I estimated three paramters using non informative prior(all paramters following uniform distribution)
> >
> > the output is:
> > Error in optim(pars, li_func, control = list(fnscale = -1), hessian = TRUE, :
> > non-finite finite-difference value [1]
> >
> > How can I solve it using uniform distribution for all paramters??
> >
> > (the same code is working when I use informative prior When I sugessted other distriutions like gamma and exp.)
> >
> > Thank you
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help
mailing list