I receive error when trying to use a simple OLS function?
Mostrar comentarios más antiguos
First I receive this error:

And then when converting my variable 'iota' into a table, I get the following error:

Can someone please provide some information on the following problem?
Getting very nervous for my exam in the beginning of the new year.
3 comentarios
dpb
el 26 de Dic. de 2019
I can't find a MATLAB function ols searching the TMW website; link or source???
You pulled error messages out of context with nowhere near enough code to have a clue as to what line N might actually be so we have really nothing to go on...
Start with the first...if we can see what you're trying to use has for instructions, that would go a long way.
LouLou
el 26 de Dic. de 2019
LouLou
el 26 de Dic. de 2019
Respuestas (1)
"...certainly nothing should be out of context here. "
Well, other than the missing function, the error says line 33 and there's only some 10-15 lines in the image and no line number so, yes, there is some lack of context here.
But, w/ the ols function, the meaning of the error regarding ctranspose is clear--the expression data(:,2), etc., returns a table of the given column, not the underlying data array and it doesn't make sense to try to transpose a table.
If you're going to use a table variable as the underlying data type, use the dot notation to return it instead; or if it is more convenient programmatically to use subscripts, dereference the table with the "curlies" {}.
We also don't have your table and you didn't show us its structure so we don't know if it has variable names or not...would make sense to create some when you read it if they aren't in the input file, but I'll just use the default VarN that readtable creates if they are not provided.
data=readtable('yourfile');
LHS=data.Var2;
RHS=[ones(height(data),1) data.Var3 data.Var4];
b=ols(LHS,RHS);
Alternatively, to illustrate the array notation RHS could be written as
RHS=[ones(height(data),1) data{:,3:4}];
NB: the {} to dereference the table.
NB2: MATLAB has the builtin \ backslash operator to solve OLS problems that uses more robust numerical methods than direct matrix solution as your ols function does. I'd strongly recommend using it instead.
See doc mldivide for details...
2 comentarios
dpb
el 26 de Dic. de 2019
"Thank you very much, the code you provided seems to work. This was a great help and much appreciated. " -- Answer moved to comment--dpb
dpb
el 26 de Dic. de 2019
No problem, glad to be of assistance. If above does solve the problem, please ACCEPT the Answer to indicate so to others if nothing else...
Categorías
Más información sobre Functions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

