[R] parameters in fitdistr
    Carsten Steinhoff 
    carsten.steinhoff at gmx.de
       
    Tue Jun  6 16:09:17 CEST 2006
    
    
  
Hello,
today I've updated from Version 2.1.1 to 2.3.1.
The function you can find below for MLE with double tuncated Lognormal
Distr. is working very well with 2.1.1 but now with the same function I get
the error: object "u_right" not found ... although I've declared
standard-values. I also tryed it with the call:
my.lnvfit(rlnorm(1000,5,2),u_left=100,u_right=10000)!
Is it due to changes in the environment or in the function "fitdistr" (MASS)
? 
For both I could not find anything regarding this problem in the
documentation.
Who can help?
Thanks a lot,
Carsten
============
lognormal_tr=function (loss, u_left=0, u_right=Inf, mu=NA, sigma=NA, ...)
{
library(MASS)
verluste=which(loss>=u_left & loss <=u_right)
loss=loss[verluste]
if (is.na(mu))
mu = mean(log(loss))
if (is.na(sigma)) 
sigma = sd (log(loss))
# Function to optimize
lnv2=function(x,mu,sigma,left,right)
{
return(dlnorm(x,mu,sigma)/(plnorm(right,mu,sigma)-plnorm(left,mu,sigma)))
}
pars=fitdistr(loss,lnv2,list(mu=mu,sigma=sigma),left=u_left,right=u_right,
...)
return(mu=as.vector(pars$estimate[1]), sigma=as.vector(pars$estimate[2]))
}
    
    
More information about the R-help
mailing list