|
On 7 Aug., 15:55, Torsten <Torsten.Hen...@umsicht.fraunhofer.de>
wrote:
> On 7 Aug., 15:47, "Shariful " <endrom...@gmail.com> wrote:
>
>
>
>
>
> > Thanks for your reply. Yes, I mean
> > x1=[1 2 3 4 5]'; x2=[10 20 30 40 50 60]';
>
> > >>If indeed you have column vectors you need to concatenate in that
> > >>direction instead of horizontally...
>
> > >> x1=[1 2 3 4 5]'; x2=[10 20 30 40 50 60]';
> > >> X=[x1; x2];
> > >> whos x*
>
> > --- NO, I do not want that. If I do this, then the 2 predictor (x1 & x2) will be a reduced to single predictor!
> > My question was: If I have 3 predictor vectors x1, x2, x3 (each of them are of different lengths). How can I do multiple regression? If I want to use the function "regress" which requires
> > that X = [ones(size(x1)) x1 x2 x3]. But as my x1, x2 and x3 are of different length, I can not for X! What can I do now? Thanks.
>
> > dpb <n...@non.net> wrote in message <jvr55g$ep...@speranza.aioe.org>...
> > > On 8/7/2012 7:18 AM, Shariful wrote:
>
> > > ...[top posting repaired--don't do that: hard conversation follow makes]...
>
> > > > Torsten <Torsten.Hen...@umsicht.fraunhofer.de> wrote in message
> > > > <322a4998-56bb-43f7-9805-2bf00e34d...@j11g2000vbc.googlegroups.com>...
> > > >> On 7 Aug., 12:42, "Shariful " <endrom...@gmail.com> wrote:
> > > ...
> > > >> > I would like to use Matlab multiple regression function "regress (y,
> > > >> > X)". But I have a little problem. I have 3 predictor vectors x1,
> > > >> > x2, x3 of different length. >> How can I use them to build
> > > >> > X?
> > > ...
> > > >> Row j of the matrix X consist of the three predictor values [x1_i1
> > > >> x2_i2 x3_i3] (taken from your three
> > > >> predictor vectors x1, x2 and x3, respectively) that are associated
> > > >> with observation j in the y-vector.
> > > ...
>
> > > ...
> > > > My question is what should I do if x1, x2 and x3 are of different
> > > > length? For example,
> > > > suppose I have
>
> > > > x1=[1 2 3 4 5];
> > > > x2=[10 20 30 40 50 60];
> > > > If I try
> > > >>> X=[x1 x2]
> > > > I get an error which is expected: ??? Error using ==> horzcat
> > > > CAT arguments dimensions are not consistent.
>
> > > ????
>
> > > >> x1=[1 2 3 4 5]; x2=[10 20 30 40 50 60];
> > > >> X=[x1 x2];
>
> > > You mean you have
>
> > > x1=[1 2 3 4 5]'; x2=[10 20 30 40 50 60]';
>
> > > instead, I presume?
>
> > > If indeed you have column vectors you need to concatenate in that
> > > direction instead of horizontally...
>
> > > >> x1=[1 2 3 4 5]'; x2=[10 20 30 40 50 60]';
> > > >> X=[x1; x2];
> > > >> whos x*
> > > Name Size Bytes Class
>
> > > x1 5x1 40 double array
> > > x2 6x1 48 double array
> > > X 11x1 88 double array
>
> > > Read "Getting Started" section on arrays and matrices...
>
> > > --- Zitierten Text ausblenden -
>
> > - Zitierten Text anzeigen -
>
> Steven and me already answered your question.
>
> The matrix X must be given as follows:
> [x1(1) x2(1);
> x1(1) x2(2);
> ...
> x1(1) x2(M);
> x1(2) x2(1);
> x1(2) x2(2);
> ...
> x1(2) x2(M);
> ...
> x1(M) x2(1);
> x1(M) x2(2);
> ...
> x1(M) x2(N)]
>
Sorry, should read (for two predictors)
[x1(1) x2(1);
x1(1) x2(2);
...
x1(1) x2(N);
x1(2) x2(1);
x1(2) x2(2);
...
x1(2) x2(N);
...
x1(M) x2(1);
x1(M) x2(2);
...
x1(M) x2(N)]
if
x1=[x1(1) x1(2) ... x1(M)] and x2=[x2(1) x2(2) ... x2(N)].
> This is either accomplished by my 3-fold loop or the MESHGRID-
> facility.
>
> If you want to add a constant term in your regression model, the loop
> must be
> For i=1:I,
> For j=1:J,
> For k=1:K,
> X((i-1)*J*K+(j-1)*K+k,1:4)=[ 1 x1(i) x2(j) x3(k)];
> end
> end
> end
>
> Best wishes
> Torsten.- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
|