The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Wrong standard deviation?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

newuser_ca

70 Posts

Posted - 04/30/2015 :  2:40:43 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:
Origin 8.6 in Win7

I am using function ocmath_basic_summary_stats to get an array's standard deviation. But I didn't get it right. Here is the example:
vector vData={3, 3, 3, 7, 4};
int nSize = vData.GetSize();
int nN;
double dMean, dSD;
int nRet = ocmath_basic_summary_stats(nSize, vData, &nN, &dMean, &dSD);
if(0 == nRet)
{
out_double("Mean = ",dMean);
out_double("SD = ",dSD);
}


The got the origin output SD = 1.73205. But I calculate by hand and the SD should be 1.54919.
Here is how I calculate the SD:
The mean = 4
(3-4)^2 + (3-4)^2 + (3-4)^2 + (7-4)^2 + (4-4)^2 = 1+1+1+9+0=12
Variance = 12/5 = 2.4
SD = sqrt(variance) = sqrt(2.4) = 1.54919.

what is wrong?

cdrozdowski111

USA
247 Posts

Posted - 04/30/2015 :  5:27:54 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Offhand, your manual calculation is for population standard deviation while ocmath_basic_summary_stats() is returning the sample standard deviation (based on the numbers you provide in the post).


Edited by - cdrozdowski111 on 04/30/2015 5:29:28 PM
Go to Top of Page

newuser_ca

70 Posts

Posted - 05/01/2015 :  09:15:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks.
Is there any function in Origin to calculate the "polulation standard deviation"?

quote:
Originally posted by cdrozdowski111

Offhand, your manual calculation is for population standard deviation while ocmath_basic_summary_stats() is returning the sample standard deviation (based on the numbers you provide in the post).



Go to Top of Page

cdrozdowski111

USA
247 Posts

Posted - 05/01/2015 :  3:48:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can modify your Origin C code as below to either calculate population or sample standard deviation by switching which MomentDenFlag declaration you wish to use:


vector vData = {3, 3, 3, 7, 4};
int nSize = vData.GetSize();
int nN = 0;
double dMean = NANUM;
double dSD = NANUM;

int MomentDenFlag = DS_SAS2_N; // For Population Standard Deviation
//int MomentDenFlag = DS_SAS1_DOF; // For Sample Standard Deviation

int nRet = ocmath_basic_summary_stats(nSize, vData, &nN, &dMean, &dSD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, MomentDenFlag);

if (0 == nRet)
{
	out_double("Mean = ", dMean);
	out_double("SD = ", dSD);
}

Go to Top of Page

newuser_ca

70 Posts

Posted - 05/04/2015 :  11:23:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000