Joker Chair
Joker Chair

Reputation: 15

A strange phenomenon while using the "dmvnorm" function

I want to use this function to calculate but it keeps telling me this problem.My "means" is 1*2,and "covars" is 2*2 array.And the length of "means" and ncols of "covars" is the same.I don't know why...

This is my codes .

and this is the wrong message . my inputs are

 weights<-c(1/3,1/3,1/3)
means<-matrix(1:6,nrow=3,byrow=FALSE)
covars<-array(1,dim=c(2,2,3))
EM(d,weights,means,covars,300,3,10,0.0001)

and the "d" is

the d is a 300*2 matrix.I capture a little. I'm so sorry that I don't have a good command of this website and I don't know how to put so many data on it.

Thank you so much!

Upvotes: 1

Views: 908

Answers (1)

Zheyuan Li
Zheyuan Li

Reputation: 73385

The only possible cause is your input data d. It must be a two-column matrix as you have a bivariate normal distribution. The following reproduces your error:

library(mvtnorm)

# 3 columns 
dmvnorm(matrix(runif(6), 2, 3)), c(0,0), diag(2))

But this is fine

# 2 columns
dmvnorm(matrix(runif(6), 3, 2)), c(0,0), diag(2))

I think your d has two rows but many columns.

Upvotes: 1

Related Questions