[R] Correlation matrix

Caskenette, Amanda CaskenetteA at dfo-mpo.gc.ca
Fri Jul 13 17:25:18 CEST 2007


Thank you very much for the quick response,

Yes that is correct, some values for V are negative. 
I wish that looking at the H, eigen(H), V, s, s%o%s made me wiser, however I really have no idea what I am looking for. 

The genoud function does not converge if left running for a week so I have a feeling that the real minimum will not be found...however the solutions seem only to differ in the 3rd or 4th decimal place when allowed to run for a week or for a day. Does that mean that the Hessian matrix is useless to me? 

Here is the objective function:

objective= (years*age)/2*log(sigma_s^2) + 1/(2*sigma_s^2) * sum((log(result.data) - log(result.sim))^2)

Where sigma_s, the error component, is one of the parameters estimated by the model, result.data is the data I am fitting, and result.sim is the output of the model.

Amanda


-----Original Message-----
From: Peter Dalgaard [mailto:P.Dalgaard at biostat.ku.dk] 
Sent: July 13, 2007 10:51 AM
To: Caskenette, Amanda
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Correlation matrix

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