Write scripts containing simple for-loops
summation i to N [ (Xi - mean of X)/ SDx * (Yi - mean of Y) / SDy ]
r = ------------------------------------------------------------------------
( N - 1 )
As you will recall:
SD = sqrt( summation i to N (Yi - mean)2 / (N - 1) )
So calculating r requires several steps:
X = ( 3, 5, 6, 7, 10, 12 )
mean of X = 7.17
Y = ( 5, 6, 7, 9, 10, 13 )
mean of Y = 8.33
SDx = [ (3-7.17)2+(5-7.17)2+(6-7.17)2+(7-7.17)2+(10-7.17)2+(12-7.17)2 ] / 5 SD = 1.48 SDx = [ (5-8.33)2+(6-8.33)2+(7-8.33)2+(9-8.33)2+(10-8.33)2+(13-8.33)2 ] / 5 SD = 1.32
r = [((3-7.17)/1.48*(5-8.33)/1.32)/5+((5-7.17)/1.48*(6-8.33)/1.32)/5+((6-7.17)/1.48*(7-8.33)/1.32)/5+((7-7.17)/1.48*(9-8.33)/1.32)/5+((10-7.17)/1.48*(10-8.33)/1.32)/5+((12-7.17)/1.48*(13-8.33)/1.32)/5 ] / 5 r = 0.978
Nonparametric Methods
Statistical methods that do not make assumptions about the distribution of the population are called nonparametric tests. Most nonparametric ideas are based on a simple idea. List the values in order from low to high, and assign each value a rank. Base all further analyses on the ranks. By analyzing ranks rather than values, you don't need to care about the distribution of the population.
PERL: For Loops
You've seen this construct many times:
The first part: $i = 0; This is the initializer. The variable which is being used to keep track of the count is initialized. Commonly this variable is initialized to zero, but it can be initialized to any integer value. The middle part: $i < 10; This is the exit condition. The loop will continue as long as this condition evaluates to true. Once this condition becomes false the loop ends. The end: $i++ This is the increment amount. In this case the value stored in the counter variable is increased by one on every iteration of the loop. The counter can be increased by any integer amount on each loop or it can even be decreased in value!Now consider what we can do when we utilize the comma operator:
Now consider this useful trick using a foreach loop:
ASSIGNMENT: