Difference between revisions of "LIST STAT STD DEV"
Jump to navigation
Jump to search
m |
m (<lsl> tag to <source>) |
||
(2 intermediate revisions by 2 users not shown) | |||
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. | ||
< | <source lang="lsl2"> | ||
integer | float sample_standard_deviation = llListStatistics( LIST_STAT_STD_DEV, numList ); | ||
</source> | |||
</ | 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: | ||
The sample standard deviation is used when the list doesn't include the ''entire'' set of numbers. The true standard deviation is therefore estimated by using the sample standard deviation, which is defined by, | <source lang="lsl2"> | ||
< | integer count = (integer)llListStatistics( LIST_STAT_NUM_COUNT, numList ); | ||
integer | float standard_deviation = llSqrt( llListStatistics( LIST_STAT_SUM_SQUARES , numList ) ) / count; | ||
1/( | </source> | ||
</ | 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, | ||
|pa | <source lang="lsl2"> | ||
|text | integer count = (integer)llListStatistics( LIST_STAT_NUM_COUNT, numList ); | ||
|pb= | float sample_standard_deviation = llSqrt( llListStatistics( LIST_STAT_SUM_SQUARES , numList ) ) / (count - 1); | ||
</source> | |||
Another way to calculate the sample standard deviation is | |||
<source lang="lsl2"> | |||
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 )); | |||
} | |||
</source> | |||
|pa | |||
|text | |||
|pb | |||
|example= | |||
<source lang="lsl2"> | |||
list numList = [1,1,1,2,1000,1000,1000]; | |||
float standard_deviation = llListStatistics( LIST_STAT_STD_DEV, numList ); | |||
llOwnerSay((string)standard_deviation); | |||
</source> | |||
|constants= | |constants= | ||
<!--{{LSL ConstRow|CHANGED_SHAPE}}--> | <!--{{LSL ConstRow|CHANGED_SHAPE}}--> |
Latest revision as of 16:00, 23 January 2015
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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.
float sample_standard_deviation = llListStatistics( LIST_STAT_STD_DEV, numList );
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:
integer count = (integer)llListStatistics( LIST_STAT_NUM_COUNT, numList );
float standard_deviation = llSqrt( llListStatistics( LIST_STAT_SUM_SQUARES , numList ) ) / count;
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,
integer count = (integer)llListStatistics( LIST_STAT_NUM_COUNT, numList );
float sample_standard_deviation = llSqrt( llListStatistics( LIST_STAT_SUM_SQUARES , numList ) ) / (count - 1);
Another way to calculate the sample standard deviation is
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 ));
}
Caveats
Related Articles
Functions
• | llListStatistics |