1

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!

  • 1
    Please post the code and error texts, don't use images for that. Also, if possible, provide the inputs, in other words [make a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – digEmAll Apr 02 '17 at 09:08
  • @李哲源ZheyuanLi I use`as.matrix ` to change input in to a matrix,but it still makes mistakes.Is it possible that you can tell me how to correct it? – Joker Chair Apr 02 '17 at 09:37

1 Answers1

1

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.

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248