Linear regression

Tanuja Kadam
Tanuja Kadam used Ask the Experts™
on
How to calculate linear regression in oracle plsql.
Please see the file attached.
C--Tanuja-Lake_IL-BRDs-linear-regre.docx
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2012
Commented:
Do you have the excel file or the raw data instead of a picture of data?

In any case,  you shouldn't use PL/SQL to solve this.  Instead use the built in SQL aggregate function REGR_SLOPE.
 

SELECT REGR_SLOPE(dependent_variables, independent_variables)  FROM yourtable

if you're trying to do it "manually" then you can use the basic SUM and COUNT aggregate functions.  This does assume every (dep,indep) pair is not null for both elements, which is true for your sample data.

select  ((SUM(dep * indep) - SUM(indep) * SUM(dep) / COUNT(*)) / COUNT(*))  / ((SUM(POWER(indep, 2)) - POWER(SUM(indep), 2) / COUNT(*)) / COUNT(*)) from yourtable
Tanuja KadamProgrmmer Analyst

Author

Commented:
Thank you.
I will use this function and let you know.
Tanuja KadamProgrmmer Analyst

Author

Commented:
I also Need to calculate sales ratio. I have the details attached. Really appreciate your help and time.
C--Tanuja-Lake_IL-BRDs-sales-ratio-.docx
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2011
Top Expert 2012

Commented:
please open a new question for a new question.

in your new question please provide sample data and expected results.

Please provide the data in a form that can be imported to create a test case.
Tanuja KadamProgrmmer Analyst

Author

Commented:
I have opened a new question. Thanks
Tanuja KadamProgrmmer Analyst

Author

Commented:
Appreciate your help. The solution work perfectly.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial