Subject: Multiple regression From: Shariful Date: 7 Aug, 2012 10:42:14 Message: 1 of 14 Dear Matlab Community, 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? Thanks in advance for your help! Shariful
 Subject: Multiple regression From: Torsten Date: 7 Aug, 2012 11:23:53 Message: 2 of 14 On 7 Aug., 12:42, "Shariful " wrote: > Dear Matlab Community, > 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? > > Thanks in advance for your help! > Shariful 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. Best wishes Torsten.
 Subject: Multiple regression From: Shariful Date: 7 Aug, 2012 12:18:09 Message: 3 of 14 Thanks for your reply. I know that X should be defined as X=[x1 x2 x3]. 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. Torsten wrote in message <322a4998-56bb-43f7-9805-2bf00e34d6e8@j11g2000vbc.googlegroups.com>... > On 7 Aug., 12:42, "Shariful " wrote: > > Dear Matlab Community, > > 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? > > > > Thanks in advance for your help! > > Shariful > > 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. > > Best wishes > Torsten.
 Subject: Multiple regression From: Torsten Date: 7 Aug, 2012 13:04:49 Message: 4 of 14 On 7 Aug., 14:18, "Shariful " wrote: > Thanks for your reply. I know that X should be defined as X=[x1 x2 x3]. 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. > > > > Torsten wrote in message <322a4998-56bb-43f7-9805-2bf00e34d...@j11g2000vbc.googlegroups.com>... > > On 7 Aug., 12:42, "Shariful " wrote: > > > Dear Matlab Community, > > > 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? > > > > Thanks in advance for your help! > > > Shariful > > > 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. > > > Best wishes > > Torsten.- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - For i=1:I,   For j=1:J,     For k=1:K,        X((i-1)*J*K+(j-1)*K+k,1:3)=[x1(i) x2(j) x3(k)];     end   end end Best wishes Torsten.
 Subject: Multiple regression From: Steven_Lord Date: 7 Aug, 2012 13:25:22 Message: 5 of 14 "Shariful " wrote in message news:jvr121\$e8b\$1@newscl01ah.mathworks.com... > Thanks for your reply. I know that X should be defined as X=[x1 x2 x3]. > 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]; Do you have 5*6 = 30 data points, one for each combination of values where one comes from x1 and one from x2? If so, look at MESHGRID. If that's not your situation, you will need to say more about how you intend to do a regression for a function y = f(X) where the function sometimes accepts one input and sometimes two. -- Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com
 Subject: Multiple regression From: dpb Date: 7 Aug, 2012 13:28:11 Message: 6 of 14 On 8/7/2012 7:18 AM, Shariful wrote: ...[top posting repaired--don't do that: hard conversation follow makes]... > Torsten wrote in message > <322a4998-56bb-43f7-9805-2bf00e34d6e8@j11g2000vbc.googlegroups.com>... >> On 7 Aug., 12:42, "Shariful " 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... --
 Subject: Multiple regression From: Shariful Date: 7 Aug, 2012 13:47:13 Message: 7 of 14 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 wrote in message ... > On 8/7/2012 7:18 AM, Shariful wrote: > > ...[top posting repaired--don't do that: hard conversation follow makes]... > > > Torsten wrote in message > > <322a4998-56bb-43f7-9805-2bf00e34d6e8@j11g2000vbc.googlegroups.com>... > >> On 7 Aug., 12:42, "Shariful " 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... > > --
 Subject: Multiple regression From: Shariful Date: 7 Aug, 2012 14:44:15 Message: 10 of 14 Hi, Thanks for your reply. We have a response variable y which is strongly correlated to three other varibale, say, x1 (of length 20), x2 (of length 30) and x3 (of length 40). Now I would like to obtain the multiple regression line by using x1, x2 and x3 as my predictor variables. "Steven_Lord" wrote in message ... > > > "Shariful " wrote in message > news:jvr121\$e8b\$1@newscl01ah.mathworks.com... > > Thanks for your reply. I know that X should be defined as X=[x1 x2 x3]. > > 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]; > > Do you have 5*6 = 30 data points, one for each combination of values where > one comes from x1 and one from x2? If so, look at MESHGRID. > > If that's not your situation, you will need to say more about how you intend > to do a regression for a function y = f(X) where the function sometimes > accepts one input and sometimes two. > > -- > Steve Lord > slord@mathworks.com > To contact Technical Support use the Contact Us link on > http://www.mathworks.com
 Subject: Multiple regression From: Shariful Date: 7 Aug, 2012 14:46:17 Message: 11 of 14 Hi Torsten, I wonder why should I bulid my X in the following way? --- For i=1:I,   For j=1:J,     For k=1:K,        X((i-1)*J*K+(j-1)*K+k,1:3)=[x1(i) x2(j) x3(k)];     end   end end --- Could you please explain or refer me to the relevant literature? Thanks Torsten wrote in message <25d48a59-edc2-4c67-adf4-dda5eb3e8f1d@q3g2000vbc.googlegroups.com>... > On 7 Aug., 14:18, "Shariful " wrote: > > Thanks for your reply. I know that X should be defined as X=[x1 x2 x3]. 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. > > > > > > > > Torsten wrote in message <322a4998-56bb-43f7-9805-2bf00e34d...@j11g2000vbc.googlegroups.com>... > > > On 7 Aug., 12:42, "Shariful " wrote: > > > > Dear Matlab Community, > > > > 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? > > > > > > Thanks in advance for your help! > > > > Shariful > > > > > 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. > > > > > Best wishes > > > Torsten.- Zitierten Text ausblenden - > > > > - Zitierten Text anzeigen - > > For i=1:I, > For j=1:J, > For k=1:K, > X((i-1)*J*K+(j-1)*K+k,1:3)=[x1(i) x2(j) x3(k)]; > end > end > end > > Best wishes > Torsten.
 Subject: Multiple regression From: dpb Date: 7 Aug, 2012 16:54:47 Message: 12 of 14 On 8/7/2012 8:47 AM, Shariful wrote: DO _NOT_ TOP POST!!! Thank you... > 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. ... Well that's not the question you demonstrated as being a problem... The regression depends on what you have for responses -- if you have the right number of responses then the meshgrid() response works. --
 Subject: Multiple regression From: Bruno Luong Date: 7 Aug, 2012 18:14:14 Message: 14 of 14 "Shariful" wrote in message ... > Hi, > Thanks for your reply. We have a response variable y which is strongly correlated to three > other varibale, say, x1 (of length 20), x2 (of length 30) and x3 (of length 40). Now I would like > to obtain the multiple regression line by using x1, x2 and x3 as my predictor variables. How many elements of y do you have? You must somehow a relationship between x1, x2, x3 and y, so they must always group by quadruplets, i.e., they must have the same length. If missing values occur, then you must fill by NaN where it occurs. But after filling vectors MUST have the same length. Bruno

### Everyone's Tags:

Separated by commas
Ex.: root locus, bode

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.