[R] dmvnorm returns NaN
David Winsemius
dwinsemius at comcast.net
Fri Oct 18 20:16:15 CEST 2013
On Oct 18, 2013, at 10:31 AM, David Winsemius wrote:
>
> On Oct 18, 2013, at 1:12 AM, peter dalgaard wrote:
>
>>
>> On Oct 18, 2013, at 08:37 , David Winsemius wrote:
>>
>>>
>>> On Oct 17, 2013, at 9:11 PM, Steven LeBlanc wrote:
>>>
>>>> Greets,
>>>>
>>>> I'm using nlminb() to estimate the parameters of a multivariate normal random sample with missing values and ran into an unexpected result from my call to dmvnorm()
>>>
>>> There are at least 5 different version of dmvnorm. None of them are in the default packages.
>>>
>>>> within the likelihood function. Particular details are provided below.
>>>
>>> Complete? Except for the name of the package that has `dmvnorm`.
>>>
>>
>> More importantly, it gives no clue as to the connection between sigma and the data set. It is not the covariance matrix:
>>
>>> s <- scan(what=list("",0,0))
>> 1: [1,] 0.84761637 3.994261
>> 2: [2,] 0.91487059 4.952595
>> 3: [3,] 0.84527267 4.521837
>> ....
>> 40: [40,] 0.65938218 5.209301
>> 41:
>> Read 40 records
>>> cor(s[[2]],s[[3]])
>> [1] 0.8812403
>>> colMeans(cbind(s[[2]],s[[3]]))
>> [1] 1.252108 5.540686
>>> var(cbind(s[[2]],s[[3]]))
>> [,1] [,2]
>> [1,] 1.284475 2.536627
>> [2,] 2.536627 6.450582
>>
>> These are not the u and sigma stated.
>>
>> Furthermore the matrix given as sigma is not a covariance matrix. Try working out the correlation coefficient:
>>
>>> 2.2289513/sqrt(0.6464647*5.697834)
>> [1] 1.161377
>>
So the covariances need to be less than the sqrt of the product of the variances. I finally get it.
--
David.
>> That should be enough to make any version of dmvnorm complain...
>
> I understood the question differently, but you are my superior in both R and statistics, so I beg some education if I'm totally confused. I thought that what was being requested was the passage of the "complete" matrix (a series of 40 points in 2-space) to some unspecified version of dmvnorm with the hope of getting 40 density estimates from a theoretical MVN distribution with mean = c(1.267198, 5.475045) and the variance-covariance matrix, sigma= matrix( c( 0.6461647, 2.2289513, 2.228951, 5.697834), 2)
>
>
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list