Linear regression

How to calculate linear regression in oracle plsql.
Please see the file attached.
Tanuja KadamProgrmmer AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tanuja KadamProgrmmer AnalystAuthor Commented:
Thank you.
I will use this function and let you know.
Tanuja KadamProgrmmer AnalystAuthor Commented:
I also Need to calculate sales ratio. I have the details attached. Really appreciate your help and time.
Ensure Business Longevity with As-A-Service

Using the as-a-service approach for your business model allows you to grow your revenue stream with new practice areas, without forcing you to part ways with existing clients just because they don’t fit the mold of your new service offerings.

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 AnalystAuthor Commented:
I have opened a new question. Thanks
Tanuja KadamProgrmmer AnalystAuthor Commented:
Appreciate your help. The solution work perfectly.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Statistical Packages

From novice to tech pro — start learning today.