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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Wrong standard deviation?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
newuser_ca Posted - 04/30/2015 : 2:40:43 PM
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?

4   L A T E S T    R E P L I E S    (Newest First)
newuser_ca Posted - 05/04/2015 : 11:23:27 AM
Thanks a lot!
cdrozdowski111 Posted - 05/01/2015 : 3:48:23 PM
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);
}

newuser_ca Posted - 05/01/2015 : 09:15:52 AM
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).



cdrozdowski111 Posted - 04/30/2015 : 5:27:54 PM
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).


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000