# Re: [R] Trouble with mixreg

From: Rolf Turner <rolf_at_math.unb.ca>
Date: Thu 10 Mar 2005 - 05:43:39 EST

y <- as.matrix(LRINTER)

The y argument has to be a ***vector***, not a matrix. Deep in the bowels of mixreg, yhat is formed as a matrix of fitted values for all of the models in the mixture. (The first column of yhat consists of the fitted values from model 1, the second of the fitted values from model 2, und so weiter.)

If y is a vector then y - yhat is the matrix whose columns are y - (the respective columns of yhat). This is standard R syntax. If y is a matrix, R won't touch the subtraction with a sterilized barge-pole, and rightly so.

Remember that in R there is a big difference between a vector and 1-dimensional array, much as the two may seem to resemble each other.

cheers,

```					Rolf Turner
rolf@math.unb.ca

```

P. S. The usual protocol for asking questions about ***contributed*** packages is to attempt firstly to contact the author of the package. (In this case me.) Only if the author is a recalcitrant guttersnipe, and fails to respond, should you bug the r-help list about the problem.

R. T.

===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===

Massimiliano Marinucci wrote:

> I am trying to estimate a mixture of regression and get the
> following error using the mixreg package:
>
> Error in y - yhat : non-conformable arrays
>
> The instruction I used were:
> x <- as.matrix(LRHUN)
> y <- as.matrix(LRINTER)
>
> TS <- list(list(beta=c(3.0,1.0),sigsq=1,lambda=0.4),
> list(beta=c(0.0,1.0),sigsq=1,lambda=0.6))
>
> prova <- mixreg(x,y, ncomp=2, theta.start=TS)
>
> The data set has about 1200 observations.
> I checked out that x and y have the same number of obs.
> Also examples work fine.
>
> Any hints on what is going on? Thanks
> best regards
> M
>
> **********************************************
> Massimiliano Marinucci
> http://personales.ya.com/max_mar/
> Ph.D Candidate in Economics
> Fundamentos del Analisis Económico II
> (Economía Cuantitativa)