Use LINEST with OFFSET

mejohn

New Member
Joined
Jun 23, 2018
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have the following data set. It contains different products (P1,P2,P3,P4) and two variables (Var1, Var2).
I've condensed the product names in column F with the following formula: =OFFSET($B$3,(ROW(F1)*4)-4,0).
I've also calculated the slope and intercept for product P1 using: =LINEST(D3:D6,C3:C6)

I'd like to calculate R2 statistic into the same row in column i
Also, I'd like to use OFFSET with LINEST so that I can fill LINEST down the slope, intercept and R2 columns for use with the "Product name condensed" column.

Thanks so much in advance for your assistance.

A1BCDEFGHI
2Productvar1var2Product name condensedslopeinterceptR2
3P1100.39P10.03060.065
4200.65P2
5300.98P3
6401.30P4
7P2100.50
8200.75
9301.10
10401.40
11P3100.75
12201.20
13301.40
14401.80
15P4100.30
16200.70
17300.90
18401.20
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Here is one idea...I couldn't seem to get LINEST to accept arrays formed with the OFFSET function. Additionally, the R^2 correlation coefficient isn't readily accessible on the same line as slope and intercept using LINEST. Since you're using linear regression, you might instead consider using the SLOPE, INTERCEPT, and CORREL functions and forming the arrays using INDEX/MATCH constructions like this:
Book1
ABCDEFGHI
1
2Productvar1var2Product name condensedslopeinterceptR2
3P1100.39P10.03060.0650.9987
4200.65P20.03050.1750.998124
5300.98P30.03350.450.990557
6401.3P40.0290.050.991779
7P2100.5
8200.75
9301.1
10401.4
11P3100.75
12201.2
13301.4
14401.8
15P4100.3
16200.7
17300.9
18401.2
Sheet3
Cell Formulas
RangeFormula
F3:F6F3=OFFSET($B$3,(ROW(F1)*4)-4,0)
G3:G6G3=SLOPE(INDEX($D$3:$D$18,MATCH($F3,$B$3:$B$18,0)):INDEX($D$3:$D$18,MATCH($F3,$B$3:$B$18,0)+3),INDEX($C$3:$C$18,MATCH($F3,$B$3:$B$18,0)):INDEX($C$3:$C$18,MATCH($F3,$B$3:$B$18,0)+3))
H3:H6H3=INTERCEPT(INDEX($D$3:$D$18,MATCH($F3,$B$3:$B$18,0)):INDEX($D$3:$D$18,MATCH($F3,$B$3:$B$18,0)+3),INDEX($C$3:$C$18,MATCH($F3,$B$3:$B$18,0)):INDEX($C$3:$C$18,MATCH($F3,$B$3:$B$18,0)+3))
I3:I6I3=CORREL(INDEX($D$3:$D$18,MATCH($F3,$B$3:$B$18,0)):INDEX($D$3:$D$18,MATCH($F3,$B$3:$B$18,0)+3),INDEX($C$3:$C$18,MATCH($F3,$B$3:$B$18,0)):INDEX($C$3:$C$18,MATCH($F3,$B$3:$B$18,0)+3))
 
Upvote 0
Here's how you can do it with LINEST and OFFSET:

Book1
ABCDEFGHI
1
2Productvar1var2Product name condensedslopeinterceptR2
3P1100.39P10.03060.0650.99740094
4200.65P20.03050.1750.99625167
5300.98P30.03350.450.98120219
6401.3P40.0290.050.98362573
7P2100.5
8200.75
9301.1
10401.4
11P3100.75
12201.2
13301.4
14401.8
15P4100.3
16200.7
17300.9
18401.2
19
Sheet12
Cell Formulas
RangeFormula
F3:F6F3=INDEX(B:B,ROW(F1)*4-1)
G3:H6G3=LINEST(OFFSET($D$3:$D$6,ROW(D1)*4-4,0),OFFSET($C$3:$C$6,ROW(D1)*4-4,0))
I3:I6I3=INDEX(LINEST(OFFSET($D$3:$D$6,ROW(D1)*4-4,0),OFFSET($C$3:$C$6,ROW(D1)*4-4,0),,1),3,1)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Solution
Thanks, Eric. I see the problem I overlooked...I neglected to enter the LINEST/OFFSET as an array formula. I also noticed an issue with my first post...what I labeled as R2 (obtained with CORREL) is actually just R...it needs to be squared. Then my values match those you obtained with LINEST. I appreciate the tip for extracting R2 from the LINEST array output using INDEX...that's helpful.
 
Upvote 0
Thank you guys.

They both work great, although as KRice mentioned R needs to be squared.

I appreciate the help.
 
Upvote 0

Forum statistics

Threads
1,214,886
Messages
6,122,093
Members
449,064
Latest member
Danger_SF

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