Question
Example. Suppose we have a list of cities with the car driver velocities on weekdays and weekends. Test if the driving behavior in each city
Example. Suppose we have a list of cities with the car driver velocities on weekdays and weekends. Test if the driving behavior in each city is different on weekdays as compared to weekends. We take 00: no difference in driving behavior and test it against 11: driving behavior is different at weekdays and weekends for a given city. You should use permutation test for the difference in means.
We will generate our own dataset by generating car velocities at weekdays and weekends for a number of cities. We will repeat the experiment two times:
In the first experiment the driving behavior will be same at weekdays and weekends.
In the second experiment with probability p=0.05 the velocities at weekdays and weekends will come from different distributions.
You should test for 00 vs. 11 for both cases once without correction and once with correction. Use the permutation test and compute the p-value. Make sure that you resample enough times to obtain good approximations for the p-value. Check the slides to learn about the permutation test and the correction.
Check how many times your test states that the driving behavior is different for both cases (1) and (2). What can you conclude from your results?
n_cities = 100 n = 100 m = 40 p = 0.05
mu_weekdays = 50 mu_weekends = 100 sigma = 5
count_different = 0 for i in range(n_cities): x = stats.norm.rvs(loc=mu_weekdays, scale=sigma, size=n) # experiment 1: same behavior y1 = stats.norm.rvs(loc=mu_weekdays, scale=sigma, size=m) # experiment 2: different behavior in 5% of the cases if np.random.rand() <= p: y2 = stats.norm.rvs(loc=mu_weekends, scale=sigma, size=m) count_different += 1 else: y2 = stats.norm.rvs(loc=mu_weekdays, scale=sigma, size=m)
# your code goes here # perform the permutation test and compare x with y1 and then x with y2 # hint: write a function called permutation_test and invoke it from this loop
Code in python please no errors
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started