LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-19-2017, 03:39 PM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Rep: Reputation: 255Reputation: 255Reputation: 255
Simple Multiple Regression in C?


Hello,

A multiple regression is in math pretty commonly used.
It allows to do things such as :
http://www.nature.com/nmeth/journal/...th.3665-F1.jpg
or also nice
http://www.intechopen.com/source/htm.../image20_w.png

One cool thing is to evaluate the effect of variables on another one.

Would you know, maybe, a simple C programm that would do a multiple regression?

There are few, but let's share the best ones.

thank you

This one is just for x and y.
Code:
    #include <stdio.h>
    #include <math.h>
    int main()
    {
        float xx[5],yy[5],nr=0,dr=0;
        float x[5]={60,61,62,63,65},y[5]={3.1,3.6,3.8,4.0,4.1};
        double sum_y=0,sum_xy=0,sum_x=0,sum_xx=0,sum_x2=0,slope=0,intercept=0,reg;
        int i,n=5;
        for(i=0;i<n;i++)
        {
        xx[i]=x[i]*x[i];
        yy[i]=y[i]*y[i];
        }
        for(i=0;i<n;i++)
        {
        sum_x+=x[i];
        sum_y+=y[i];
        sum_xx+= xx[i];
        sum_xy+= x[i]*y[i];
        }
        nr=(n*sum_xy)-(sum_x*sum_y);
        sum_x2=sum_x*sum_x;
        dr=(n*sum_xx)-sum_x2;
        slope=nr/dr;
        double fac = pow(10, 2);
        slope=round(slope*fac)/fac;       
        intercept=(sum_y- slope*sum_x)/n;
        reg= intercept + (slope*64);
        printf("Slope: %.2f\nIntercept: %.3f\nRegression: %.3f",slope,intercept,reg);
        return 0;
    }

Last edited by Xeratul; 03-19-2017 at 03:41 PM.
 
Old 03-19-2017, 04:54 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Although the method may be commonly used and powerful, without the context of a data set of interest, X and Y are only numbers and the graphs are just lines and dots!

Perhaps you could provide a data set of interest to yourself, and explain the relationships among the independent variables and the dependent variable of interest. That would make the problem interesting to others and allow for some context for evaluating the quaity of the code and the resultant predicted values, other than a vague "cool" factor.

Here is a brief, simple introduction to the the idea behind Multiple Regression Analysis for those who may be interested.

When posting topics such as this in the Programming forum, please try to provide a specific question or postulate of interest, and the complete context necessary to understand it, per the Site FAQ and LQ Rules. That helps to maintain a high quality of useful information accessible to future searchers. Vague or general posts with no specific question may be more appropriate for the General forum.
 
Old 03-19-2017, 07:37 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939
Also, check out the open-source "R" statistics programming language.

It is a statistics package unlike anything you ever saw ... and, today, every mainstream package has an interface to it.

Here are some links:
What makes "R" different is that it is truly a programming language, which just happens to have strong support for statistics and plotting. This is quite different from SASŪ or SPSSŪ, which consist of modules, loaded with options, that are loosely tied together using nothing more than a macro facility. "R" is much smaller, more expressive, faster ... and free.

(Note that "R" generally does things in-memory, which used to be a limitation but not so much anymore.)

Given the easy availability of an open source(!) tool that does so much already, I see little return on investment for rolling-your-own in "C."

Last edited by sundialsvcs; 03-21-2017 at 08:09 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple multiple sheets Editor ? xpucto Linux - Software 10 02-01-2014 12:26 PM
Simple way to apply multiple tweaks after installing Mint 15? Donny Bahama Linux - General 2 12-04-2013 04:37 PM
Simple way of rolling out RPM to multiple server SethWhite Linux - Newbie 1 12-16-2009 10:29 AM
Is there a simple utility that can stitch multiple images into one? davee Linux - Software 3 08-09-2004 02:28 AM
Simple question, setting up multiple game servers lexington Linux - Newbie 3 05-24-2004 04:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration