Difference between revisions of "LIST STAT STD DEV"

From Second Life Wiki
Jump to: navigation, search
(making the math work, the manual calculation method is good but it will include non float/integer types and scew the results, but perfection isn't always required)
Line 3: Line 3:
 
|type=integer
 
|type=integer
 
|value=5
 
|value=5
|desc=Calculates the ''sample'' standard deviation of a list of numbers. Standard deviation is a measure of how spread out the values are, and is defined as the square root of the average of the squares of the numbers:
+
|desc=Calculates the ''sample'' standard deviation of a list of numbers.
 
<lsl>
 
<lsl>
integer n = llListStatistics( LIST_STAT_NUM_COUNT, numList );
+
float sample_standard_deviation = llListStatistics( LIST_STAT_STD_DEV, numList );
1/n * llSqrt( llListStatistics( LIST_STAT_SUM_SQUARES , numList ) );
+
</lsl>
 +
Standard deviation is a measure of how spread out the values are, and is defined as the square root of the average of the squares of the numbers:
 +
<lsl>
 +
integer count = (integer)llListStatistics( LIST_STAT_NUM_COUNT, numList );
 +
float standard_deviation = llSqrt( llListStatistics( LIST_STAT_SUM_SQUARES , numList ) ) / count;
 
</lsl>
 
</lsl>
 
The sample standard deviation is used when the list doesn't (or can't) include the ''entire'' set of numbers, like the mass of ''every'' prim in SL. The true standard deviation is therefore estimated by using the sample standard deviation, which is defined by,
 
The sample standard deviation is used when the list doesn't (or can't) include the ''entire'' set of numbers, like the mass of ''every'' prim in SL. The true standard deviation is therefore estimated by using the sample standard deviation, which is defined by,
 
<lsl>
 
<lsl>
integer n = llListStatistics( LIST_STAT_NUM_COUNT, numList );
+
integer count = (integer)llListStatistics( LIST_STAT_NUM_COUNT, numList );
1/(n-1) * llSqrt( llListStatistics( LIST_STAT_SUM_SQUARES , numList ) );
+
float sample_standard_deviation = llSqrt( llListStatistics( LIST_STAT_SUM_SQUARES , numList ) ) / (count - 1);
 
</lsl>
 
</lsl>
 
Another way to calculate the sample standard deviation is  
 
Another way to calculate the sample standard deviation is  
 
<lsl>
 
<lsl>
 
     list numList = [1,1,1,2,1000,1000,1000];
 
     list numList = [1,1,1,2,1000,1000,1000];
     integer n = llGetListLength( numList );
+
     integer count = llGetListLength( numList );
 
     float sum = 0;
 
     float sum = 0;
    integer i;
 
 
     float mean = llListStatistics( LIST_STAT_MEAN, numList );
 
     float mean = llListStatistics( LIST_STAT_MEAN, numList );
     for (i=0; i<n; i++) {
+
     integer i = 0;
 +
    for (; i<count; ++i) {
 
         float val = llList2Float( numList, i );
 
         float val = llList2Float( numList, i );
         float diff = val-mean;
+
         float diff = val - mean;
         sum += ( diff )*( diff);
+
         sum += ( diff * diff );
 
     }
 
     }
     float sample_stdev = llSqrt( sum/((float)(n-1)) );  
+
     float sample_stdev = llSqrt( sum / (count - 1) );  
     float true_stdev = llSqrt( sum/((float)n) );  
+
     float true_stdev = llSqrt( sum / count );  
 
     llOwnerSay((string)true_stdev);
 
     llOwnerSay((string)true_stdev);
 
     llOwnerSay((string)sample_stdev);
 
     llOwnerSay((string)sample_stdev);
Line 32: Line 36:
 
}
 
}
 
</lsl>
 
</lsl>
|pa=
+
|pa
|text=
+
|text
|pb=
+
|pb
|examples
+
|example=
 +
<lsl>
 +
list numList = [1,1,1,2,1000,1000,1000];
 +
float standard_deviation = llListStatistics( LIST_STAT_STD_DEV, numList );
 +
llOwnerSay((string)standard_deviation);
 +
</lsl>
 
|constants=
 
|constants=
 
<!--{{LSL ConstRow|CHANGED_SHAPE}}-->
 
<!--{{LSL ConstRow|CHANGED_SHAPE}}-->

Revision as of 14:32, 10 April 2008

Description

Constant: integer LIST_STAT_STD_DEV = 5;

The integer constant LIST_STAT_STD_DEV has the value 5

Calculates the sample standard deviation of a list of numbers. <lsl> float sample_standard_deviation = llListStatistics( LIST_STAT_STD_DEV, numList ); </lsl> Standard deviation is a measure of how spread out the values are, and is defined as the square root of the average of the squares of the numbers: <lsl> integer count = (integer)llListStatistics( LIST_STAT_NUM_COUNT, numList ); float standard_deviation = llSqrt( llListStatistics( LIST_STAT_SUM_SQUARES , numList ) ) / count; </lsl> The sample standard deviation is used when the list doesn't (or can't) include the entire set of numbers, like the mass of every prim in SL. The true standard deviation is therefore estimated by using the sample standard deviation, which is defined by, <lsl> integer count = (integer)llListStatistics( LIST_STAT_NUM_COUNT, numList ); float sample_standard_deviation = llSqrt( llListStatistics( LIST_STAT_SUM_SQUARES , numList ) ) / (count - 1); </lsl> Another way to calculate the sample standard deviation is <lsl>

   list numList = [1,1,1,2,1000,1000,1000];
   integer count = llGetListLength( numList );
   float sum = 0;
   float mean = llListStatistics( LIST_STAT_MEAN, numList );
   integer i = 0;
   for (; i<count; ++i) {
       float val = llList2Float( numList, i );
       float diff = val - mean;
       sum += ( diff * diff );
   }
   float sample_stdev = llSqrt( sum / (count - 1) ); 
   float true_stdev = llSqrt( sum / count ); 
   llOwnerSay((string)true_stdev);
   llOwnerSay((string)sample_stdev);
   llOwnerSay((string)llListStatistics( LIST_STAT_STD_DEV, numList ));

} </lsl>

Related Articles

Functions

•  llListStatistics

Deep Notes

Search JIRA for related Issues

Signature

integer LIST_STAT_STD_DEV = 5;