# ML fit of t distribution
nlogL <- function(x, data) # negative log likelihood
{ mu <- x[1]
sig <- x[2]
df <- x[3]
-sum(log( dt((data-mu)/sig, df=df)/sig )) }
y <- rt(n=100, df=10) # generate t data
# this is Splus code.....so remove the #'s for it to work in R
# fit <- nlminb(c(1,1,4), nlogL, upper=c(Inf,Inf,Inf), lower=c(-Inf,0,0),
# data=y)
# fit$parameters # maximum likelihood estimates
# J <- ihess(nlogL, fit$parameters, data=y)
# sqrt(diag(J)) # standard errors based on observed information
#
# In this example the standard error can be a bad measure of
# uncertainty for the df.
Run the code above in your browser using DataLab