[R] Correlation matrix

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Fri Jul 13 16:50:48 CEST 2007


Caskenette, Amanda wrote:
> I have a model with 5 parameters that I am optimising where the (best)
> value of the objective function is negative. I would like to use the
> Hessian matrix (from genoud and/or optim functions)  to construct  the
> covariance and correlation matrices.
>
>   This is the code that I am using:
>
>   est <- out$par                  # Parameter estimates 
>   H <- out$hessian             # Hessian 
>   V <- solve(H)                   # Covariance matrix
>   s <- sqrt(abs(diag(V)))    # Vector of standard deviations 
>   cor <- V/(s%o%s)            # Correlation coefficient matrix 
>   ci <- est+qnorm(0.975)*s%o%c(-1,1) # 95% CI's
>
> However I am getting values that are greater than 1 (1.05, 2.34, etc)
> for the correlation matrix. Might this be due to the fact that the
> out$val is negative?
>
>   

Not by itself (just add a large enough constant to the objective
function and the value becomes positive without changing the Hessian).

More likely, you have not actually found the minimum (Hessian not
positive definite), or there is a code error.

Print out and review the following items:

    H, eigen(H), V, s, s%o%s

and see if that makes you any wiser (why are you taking abs(diag(V))?
Negative elements?)

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list