Using LINEST with Conditional Arrays

JTWood

New Member
Joined
Mar 3, 2008
Messages
35
Summary Question
I am trying to use LINEST to calculate the linear regression output for selected data points in a table. The selection of the data points is being determined by a conditional array. Here's an example of the formula:

LINEST(IF(D2:D10000=2,E2:E10000),IF(D2:D10000=2,E2:E10000))
It returns a #VALUE response.

This method works great for other functions, like STDEV.S(IF(D2:D10000=2,E2:E10000)) or AVERAGE(IF(D2:D10000=2,E2:E10000)), but not for LINEST.
Is this simply not possible for LINEST? Or do I need to consider other steps to make it work?

Additional Detail
The data set is hourly sums of metrics for an extended period of time. I need to compare the exact hour of the day for the entire time frame for one metric to the exact hour of the day for the entire time frame for another metric. Here's a screenshot of what the data basically looks like:

vU7LuAt.png


In this particular case, I highlighted just to show the potential values that should be included in the LINEST.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Never mind. I'm reading now that you cannot use conditional arrays in LINEST. It doesn't like the 'FALSE' responses.
 
Upvote 0
I'm not a statistician, but I think that in your example Column E is the "Known y" and Column F is the "Known x", correct? If so, try the following formula that needs to be confirmed with CONTROL+SHIFT+ENTER...

=LINEST(N(OFFSET(E2:E10000,SMALL(IF(D2:D10000=2,ROW(D2:D10000)-ROW(D2)),ROW(INDIRECT("1:"&COUNTIF(D2:D10000,2)))),0,1)),N(OFFSET(F2:F10000,SMALL(IF(D2:D10000=2,ROW(D2:D10000)-ROW(D2)),ROW(INDIRECT("1:"&COUNTIF(D2:D10000,2)))),0,1)))

Also, can you use the SLOPE and INTERCEPT functions to return the same results as LINEST? If so, try the following formulas instead...

=SLOPE(IF(D2:D10000=2,E2:E10000),IF(D2:D10000=2,F2:F10000))

=INTERCEPT(IF(D2:D10000=2,E2:E10000),IF(D2:D10000=2,F2:F10000))

Note that both these formulas need to be confirmed with CONTROL+SHIFT+ENTER.

Hope this helps!
 
Upvote 0
I'm not a statistician, but I think that in your example Column E is the "Known y" and Column F is the "Known x", correct? If so, try the following formula that needs to be confirmed with CONTROL+SHIFT+ENTER...

=LINEST(N(OFFSET(E2:E10000,SMALL(IF(D2:D10000=2,ROW(D2:D10000)-ROW(D2)),ROW(INDIRECT("1:"&COUNTIF(D2:D10000,2)))),0,1)),N(OFFSET(F2:F10000,SMALL(IF(D2:D10000=2,ROW(D2:D10000)-ROW(D2)),ROW(INDIRECT("1:"&COUNTIF(D2:D10000,2)))),0,1)))

Also, can you use the SLOPE and INTERCEPT functions to return the same results as LINEST? If so, try the following formulas instead...

=SLOPE(IF(D2:D10000=2,E2:E10000),IF(D2:D10000=2,F2:F10000))

=INTERCEPT(IF(D2:D10000=2,E2:E10000),IF(D2:D10000=2,F2:F10000))

Note that both these formulas need to be confirmed with CONTROL+SHIFT+ENTER.

Hope this helps!
Hey, thanks. All those options worked great. I had found a "How to work around not using LINEST" page and bookmarked it for later.

Pretty sure you just saved me a good bit of reading!
 
Upvote 0
Just a point, but I prefer the non-volatile and shorter:

=LINEST(INDEX(E:E,N(IF(1,MODE.MULT(IF(D2:D10000=2,{1,1}*ROW(D2:D10000)))))),INDEX(F:F,N(IF(1,MODE.MULT(IF(D2:D10000=2,{1,1}*ROW(D2:D10000)))))))

for the LINEST construction.

Regards
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,484
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top