Message Boards Message Boards

GROUPS:

Rearrange a matrix of data to Map LinearModelFit?

Posted 5 months ago
675 Views
|
5 Replies
|
1 Total Likes
|

Hello, Community

I have built the following matrix (10,10) of data

xdata = Table[RandomVariate[NormalDistribution[], n], 10];
\[Epsilon]data = Table[RandomVariate[NormalDistribution[0, RandomChoice[{1/3, 1, 3}]], n], 10];
\[Beta]data = Table[RandomChoice[{1/3, 1, 3}, n], 10];    
ydata = xdata \[Beta]data + \[Epsilon]data;

I rearranged the data according to

data = Table[Transpose[{ydata[[k]], xdata[[k]]}], {k, 10}];

But when I map LinearModelFit to estimate 10 equations like below,

lsFunc = LinearModelFit[#, x, x] & /@ data

It doesn't work {:^(

Can someone please let me know my mistake and how to fix it?

Also, how can I Map properties to the LinearModelFit results? For example, I want to extract the list of "BestFitParameters".

5 Replies

OK, it wasn't working then but it's working now...Go figure!

enter image description here

I still need help with Mapping the properties of LinearModelFit to the results. The following, for example, doesn't work:

parametersLs = Map[lsFunc["BestFitParameters"], lsFunc]

I would appreciate any help. Thanks in advance,

Thad

OK, this worked like a charm:

Table[lsFunc[[j]]["BestFitParameters"], {j, 10}]

Cheers,

Thad

You can also get the parameters with this:

Through[lsFunc["BestFitParameters"]]

It is equivalent to Table[[lsFunc[[k]]["BestFitParameters"], {k, 10}].

By the way, you can also construct data like this:

data = Transpose[{ydata, xdata}, {3, 1, 2}];

Michael, how do I apply the Through function if my LinearModelFit results have two levels, like the following, for example?

ols = LinearModelFit[#, v, v] & @@@ # & /@ data

regression results I have tried combinations of Through with Map and others without success.

Thank you

I have found the following way:

#["BestFitParameters"] & /@ # & /@ ols

But I still can't make it work with Through.

Cheers

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract