R and Regression: How to determine distribution of residuals? I have residuals from a linear regression model on my data set. I want to find an appropriate distribution of my residuals.  


*

*Say, I assume my residuals are Skew-T Distributed, how can I find the (best)
distribution parameters by Fitting?  

*If the sample distribution of my residuals indicate bimodality, how can I determine an appropriate distribution?  

*How can I model kurtotic behaviour and long (but not heavy) tails of my residuals ?

*How can I do this in R?

*How can I model Heteroscedasticity of data?

 A: You could model the residuals and get estimates using maximum likelihood.  Here's a simple example:
N <- 500
df <- data.frame(x=runif(N, 0, 50))
df$y <- 10 + 2 * df$x + 4 * rt(N, 4)  # True params
plot(df$x, df$y)

ll <- function(params) {
    ## Log likelihood for y ~ x + student's t errors
    params <- as.list(params)
    return(sum(dt((df$y - params$const - params$beta*df$x) / params$scale,
                      df=params$degrees.freedom, log=TRUE) - log(params$scale)))
}

optim_result <- optim(par=c(const=5, beta=1, scale=3, degrees.freedom=5),
                      lower=c(-Inf, -Inf, 0.1, 0.1),
                      fn=ll, method="L-BFGS-B", control=list(fnscale=-1), hessian=TRUE)
fit <- data.frame(coefficient=optim_result$par, se=sqrt(diag(solve(-optim_result$hessian))))

That's a linear regression with student's-t errors.
If your residuals are bimodal, you could try a mixture of two normals.
Edit:  for mixtures of regressions in R, see ftp://www.r-project.org/pub/R/web/packages/mixtools/vignettes/mixtools.pdf.
