An archive the questions from Mark's Fall 2018 Stat 225.

Computation of basic measures

Mark

Compute the mean, median, and standard deviation of the sample

S = \{-1,2,3,8\}.
megan

mean = 3
median = 2.5
standard deviation = 3.74

joshua

A. For the mean I got 3

-1+2+3+8=12/4=3

B. For the median I got 2.5

(2+3)/2=2.5

C. For the standard deviation I got about 3.74

sqrt(((-1-3)^2+(2-3)^2+(3-3)^2+(8-3)^2)/(4-1)) = 3.74
john

Program:
import math

s = [-1, 2, 3, 8] # the provided sample as a list structure

# we need the mean, median, and standard deviation of the sample. keyword... sample...

# computing the mean is simply means to add up s_0 through s_3 then divided by n
mean = 0
for sn in s:
    mean += sn
mean = mean / len(s)
print("Calculated Mean: {0}".format(mean))

# median is the middle most value. Since there is an even amount of elements in the sample, it'll be the value in between the two middle most values.
leftMiddle = (len(s)/2)-0.5
rightMiddle = (len(s)/2)+0.5
median = s[int(leftMiddle)] + s[int(rightMiddle)]
median = median / 2
print("Calculated Median: {0}".format(median))

# standard deviation is calculated by square rooting the sample variance formula. The formula basically states to for each element in the sample subract the mean from it, square it, then sum them all together. Then divide by n-1.
sampleVariance = 0
for sn in s:
    sampleVariance += (sn - mean)**2
sampleVariance /= len(s)-1
standardDev = math.sqrt(sampleVariance)
print("Calculated Standard Deviation: {0}".format(standardDev))

Output:

Calculated Mean: 3.0
Calculated Median: 2.5
Calculated Standard Deviation: 3.7416573867739413
Mark

@megan, @joshua, @john

I see some answers and some code - but I don’t see any solutions in terms of simple formulae that you could write down on a quiz.

mac

To find the mean, add all the numbers together and divide by the number of numbers:

(-1+2+3+8)/4 = 12/4 = 3

The mean for the data set is 3

To find the median, arrange the numbers in numerical order and calculate the middle number:

-1,2,3,8

The median is between 2 and 3, or the average of 2 and 3 = (2+3)/2 = 2.5
The median is 2.5

To find the standard deviation of the sample, take the square root of each of the numbers minus the average squared added together, divided by the number of numbers minus one:

sqrt((((-1-3)^2)+((2-3)^2)+((3-3)^2)+((8-3)^2))/(4-1)) = sqrt[(4^2+1+0+5^2)/3] =
sqrt[(16+1+25)/3] = sqrt[42/3] = sqrt[14] = 3.74

the standerd diviation of the sample is about 3.7417, or the square root of 14

Mark

@mac Looks good! I edited your post so that the math was typeset, rather than code. Literally, all I did was wrap your code in percent symbols. Have a look at this post to learn more.

dennis

mean (mu) = (sum_(i=1)^n(x_i)) /n = 3
median (middle) = -1, 2,| 3, 8 = 2.5

std. dev. =

sigma = sqrt( (sum_(i=1)^n(x_i-mu)^2)/n) =

= sqrt((((-1-3)^2)+((2-3)^2)+((3-3)^2)+((8-3)^2))/(4-1)) = sqrt[(4^2+1+0+5^2)/3] =

sqrt(14) = 3.741657