|
1 | | -"""example function to analyze reaction times |
2 | | -- given a data frame with RT and accuracy, |
3 | | -compute mean RT for correct trials and mean accuracy |
| 1 | +"""Example class to analyze reaction times. |
| 2 | +
|
| 3 | +Given a data frame with RT and accuracy, compute mean RT for correct trials and |
| 4 | +mean accuracy. |
4 | 5 | """ |
5 | 6 | # %% |
6 | 7 | import pandas as pd |
7 | 8 |
|
8 | 9 |
|
9 | 10 | # %% |
10 | 11 | class RTAnalysis: |
11 | | - """[summary]""" |
| 12 | + """Response time (RT) analysis.""" |
12 | 13 |
|
13 | 14 | def __init__(self, outlier_cutoff_sd=None): |
14 | | - """ |
15 | | - RT analysis |
| 15 | + """Initialize a new RTAnalysis instance. |
16 | 16 |
|
17 | | - Parameters: |
18 | | - ----------- |
19 | | - outlier_cutoff_sd: standard deviation cutoff for long RT outliers (default: no cutoff) |
| 17 | + Parameters |
| 18 | + ---------- |
| 19 | + outlier_cutoff_sd : float, optional |
| 20 | + Standard deviation cutoff for long RT outliers, by default None |
20 | 21 | """ |
21 | 22 | self.outlier_cutoff_sd = outlier_cutoff_sd |
22 | 23 | self.meanrt_ = None |
23 | 24 | self.meanacc_ = None |
24 | 25 |
|
25 | 26 | def fit(self, rt, accuracy, verbose=True): |
26 | | - """[summary] |
27 | | -
|
28 | | - Args: |
29 | | - rt (Series of floats): response times for each trial |
30 | | - accuracy (Series of booleans): accuracy for each trial |
| 27 | + """Fit response time to accuracy. |
| 28 | +
|
| 29 | + Parameters |
| 30 | + ---------- |
| 31 | + rt : pd.Series |
| 32 | + Response time per trial |
| 33 | + accuracy : pd.Series |
| 34 | + Accuracy per trial |
| 35 | + verbose : bool, optional |
| 36 | + Whether to print verbose output or not, by default True |
| 37 | +
|
| 38 | + Raises |
| 39 | + ------ |
| 40 | + ValueError |
| 41 | + RT/accuracy length mismatch |
| 42 | + ValueError |
| 43 | + Accuracy is 0 |
31 | 44 | """ |
32 | | - |
33 | 45 | rt = self._ensure_series_type(rt) |
34 | 46 | accuracy = self._ensure_series_type(accuracy) |
35 | 47 |
|
@@ -62,16 +74,18 @@ def fit(self, rt, accuracy, verbose=True): |
62 | 74 |
|
63 | 75 | @staticmethod |
64 | 76 | def _ensure_series_type(var): |
65 | | - """return variable as a pandas Series or raise exception if |
66 | | - not possible |
| 77 | + """Return variable as a pandas Series. |
67 | 78 |
|
68 | | - Args: |
69 | | - var (array-like): variable to convert |
| 79 | + Parameters |
| 80 | + ---------- |
| 81 | + var : Iterable |
| 82 | + Variable to be converted |
70 | 83 |
|
71 | | - Returns: |
72 | | - series (pandas Series): converted variable |
| 84 | + Returns |
| 85 | + ------- |
| 86 | + pd.Series |
| 87 | + Variable values as a pandas Series |
73 | 88 | """ |
74 | | - |
75 | 89 | if type(var) is not pd.core.series.Series: |
76 | 90 | var = pd.Series(var) |
77 | 91 | return var |
0 commit comments