42.1k views
3 votes
Write a function that computes that statistic. It should take as its argument an array of waiting times and return the variance of them. Call the function var_based_estimator.

User Henrik
by
6.7k points

1 Answer

5 votes

Answer:

Written in Python:

def var_based_estimator(waitingtimes):

isum = 0

for i in range(0,len(waitingtimes)):

isum = isum + waitingtimes[i]

mean = isum/len(waitingtimes)

varsum=0

for i in range(0,len(waitingtimes)):

varsum = varsum + (waitingtimes[i] - mean)**2

variance = varsum/len(waitingtimes)

print(round(variance,3))

Step-by-step explanation:

(1) To calculate variance, first we need to determine the mean,

(2) Then we subtract the mean from individual data

(3) Then we take the squares of (2)

(4) Sum the results in (3)

(5) Divide the result in (4) by the mean

This is implemented in python as follows:

This line defines the function

def var_based_estimator(waitingtimes):

We start by calculating the mean, here i.e. (1)

This line initializes the sum of all data to 0

isum = 0

The following iteration adds up the elements of waitingtimes list

for i in range(0,len(waitingtimes)):

isum = isum + waitingtimes[i]

The mean is calculated here;
Mean = (\sum x)/(n)

mean = isum/len(waitingtimes)

(2), (3) and (4) are implemented in the following iteration

First the sum is initialized to 0

varsum=0

This iterates through the list; subtracts each element from the mean; take the square and sum the results together

for i in range(0,len(waitingtimes)):

varsum = varsum + (waitingtimes[i] - mean)**2

This calculates the variance by dividing the (4) by the mean

variance = varsum/len(waitingtimes)

This prints the variance rounded to three decimal placed

print(round(variance,3))

User Priyank Gosalia
by
7.0k points