Displaying 5 results from an estimated 5 matches for "dinvgamma".
2012 Oct 04
2
Help with R Fitting an inverse Gamma
...ere I go wrong with the following code:
rm(list=ls())
# Required packages
library(MCMCpack)
# Simulated data
set.seed(1)
data = rinvgamma(n=250, shape = 5, scale = 2) + 2
hist(data)
# log-likelihood
ll = function(par){
if(par[1]>0 & par[2]>0 & par[3]<min(data)) return( -sum(log(dinvgamma(data-
par[3],par[1],par[2]))) )
else return(Inf)
}
# MLE
mle = optim(c(5,2,2),ll)
params = mle$par
# Fit
hist(data,probability=T,ylim=c(0,2.5))
points(seq(2,4.5,0.001),dinvgamma(seq(2,4.5,0.001)-params[3],params[1],params[2]),type="l",col="red")
This code f...
2011 Jan 13
1
Fitting an Inverse Gamma Distribution
...meone might be
aware of such a function?
Secondly, is there a way to shift the pdf (code below) to the right (rather
than the data to the left)? I tried:
par(new=T)
shift<-1
hist(iniSal_US_forHist,breaks=seq(1.1,21,by=0.625),col="grey",freq=F,xlim=c(0-shift,21-shift),plot=F)
curve(dinvgamma(x,scale=11.835,shape=4.4242),from=0,to=20,add=T,col="purple",lwd=2)
but this failed in shifting the curve. More broadly, the data plotted in
the histogram represents a calibration target for output generated by a
finite difference solute transport model. The values that will be generat...
2009 Oct 08
3
foreach loop - rejection method
Hi Everybody,
Thanks in advance for your help.
This is my first time using the foreach statement and I cant get it to work
properly so here is what i have
test<-function(){
repeat {
cand2[l-1]<-rinvgamma(1,phi,lambda[l-1])
q2<-dinvgamma(cand2[l-1],phi,lambda[l-1])
p2<-cand2[l-1]^-1.5*exp(-y[l]^2/(2*cand2[l-1]))*exp(-((log(cand2[l-1])-mu_t_cand[l-1])^2)/2*sigmasq)
ratio<-p2/(c[l-1]*q2)
if (runif(1)< ratio) {break}
}
f2[l-1]<-min(p2,c[l-1]*q2)
}}
foreach(l=2:(n-1),.combine=c,.packages='MCMCpack',.options.nws=li
s...
2010 Jan 12
1
Strange behavior when trying to piggyback off of "fitdistr"
...invparalogistic = dinvparalogis, `inverse paralogistic` = dinvparalogis,
transgamma = dtrgamma, `transformed gamma` = dtrgamma, invexp = dinvexp,
`inverse exponential` = dinvexp, invtransgamma = dinvtrgamma,
`inverse transformed gamma` = dinvtrgamma, invgamma = dinvgamma,
`inverse gamma` = dinvgamma, invweibull = dinvweibull, `inverse weibull` = dinvweibull,
loggamma = dlgamma, genbeta = dgenbeta, `generalized beta` = dgenbeta, NULL)
if (is.null(densfun))
stop("unsupported distribution")
dis...
2007 Feb 13
0
Really need help here
...(T,1/nu,1/nu)
J <- rnorm(T,beta*G,sig*sqrt(G))
#------------------- Gibbs Sampler ---------------------------#
nu.stor <- rep(NA,n.iter)
for(i in 1:n.iter){
G <- MCslice1D(dgamma(x,1/nu,1/nu,log=TRUE)+dnorm(J, beta*x, sig*sqrt(x),log=TRUE),w=20,m=10,x0=G)
nu <- MCslice1D(log(dinvgamma(x,m,M))-T*log(x)*1/x-T*log(gamma(1/x))+(1/x-1)*sum(log(G))-sum(G)/x, w=3,m=12, x0=nu)
nu.stor[i] <- nu
}
return(list(nu=nu.stor))
}