1- import pandas as pd
1+ """Utility module for handling the generation of test data."""
22import numpy as np
3+ import pandas as pd
34import scipy .stats
45
56
6- def generate_test_df (meanRT , sdRT , meanAcc , n = 100 ):
7- """
8- generate simulated RT data for testing
7+ def generate_test_df (mean_rt , sd_rt , mean_accuracy , n = 100 ):
8+ """Generate simulated RT data for testing.
99
10- Args:
11- meanRT (float): mean RT (for correct trials)
12- sdRT (float): std deviation of RT (for correct trials)
13- meanAcc (float): mean accuracy (proportion, 0 <= meanAcc <= 1)
14- sdcutoff ([type]): outlier cutoff (default None for no cutoff)
15- """
10+ Parameters
11+ ----------
12+ mean_rt : float
13+ Mean response time for correct trials
14+ sd_rt : float
15+ Standard deviation of the response time in correct trials
16+ mean_accuracy : float
17+ Mean accuracy across trials (between 0 and 1)
18+ n : int, optional
19+ Number of observations to generate, by default 100
1620
21+ Returns
22+ -------
23+ pd.DataFrame
24+ Generated mock data
25+ """
1726 rt = pd .Series (scipy .stats .weibull_min .rvs (2 , loc = 1 , size = n ))
1827
1928 # get random accuracy values and threshold for intended proportion
2029 accuracy_continuous = np .random .rand (n )
2130 accuracy = pd .Series (
2231 accuracy_continuous
23- < scipy .stats .scoreatpercentile (accuracy_continuous , 100 * meanAcc )
32+ < scipy .stats .scoreatpercentile (accuracy_continuous , 100 * mean_accuracy )
2433 )
2534
2635 # scale the correct RTs only
2736 rt_correct = rt .mask (~ accuracy )
28- rt_scaled = scale_values (rt_correct , meanRT , sdRT )
37+ rt_scaled = scale_values (rt_correct , mean_rt , sd_rt )
2938
3039 # NB: .where() replaces values where the condition is False
3140 rt_scaled_with_inaccurate_rts = rt_scaled .where (accuracy , rt )
@@ -34,14 +43,22 @@ def generate_test_df(meanRT, sdRT, meanAcc, n=100):
3443
3544
3645def scale_values (values , mean , sd ):
37- """scale values by given mean/sd
46+ """Scale values by given mean/SD.
47+
48+ Parameters
49+ ----------
50+ values : array-like
51+ Values to be scaled
52+ mean : float
53+ Target mean
54+ sd : float
55+ Target standard deviation
3856
39- Args:
40- values (array-like): values to be scaled
41- mean (float): intended mean
42- sd (float): intended standard deviation
57+ Returns
58+ -------
59+ array-like
60+ Scaled values
4361 """
4462 values = values * (sd / np .std (values ))
4563 values = (values - np .mean (values )) + mean
46-
4764 return values
0 commit comments