Skip to content

Commit

Permalink
Add Results.standard_parameters_estimate
Browse files Browse the repository at this point in the history
  • Loading branch information
pberkes committed Nov 28, 2024
1 parent cc13b60 commit f672d1b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
22 changes: 22 additions & 0 deletions psignifit/_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,25 @@ def slope_at_proportion_correct(self, proportion_correct: np.ndarray, unscaled:
"""
stimulus_levels = self.threshold(proportion_correct, unscaled, return_ci=False, estimate_type=estimate_type)
return self.slope(stimulus_levels)

def standard_parameters_estimate(self, estimate_type: Optional[EstimateType]=None):
""" Get the parameters of the psychometric function in the standard format.
`psignifit` uses the same intuitive parametrization, threshold and width, for all
sigmoid types. However, each different type of sigmoid has its own standard parametrization.
The interpretation of the standard parameters, location and scale, depends on the sigmoid class used.
For instance, for a Gaussian sigmoid, the location corresponds to the mean and the scale to the standard
deviation of the distribution.
For negative slope sigmoids, we return the same parameters as for the positive ones.
Args:
proportion_correct: proportion correct at the threshold you want to calculate
Returns:
Standard parameters (loc, scale) for the sigmoid subclass.
"""
sigmoid = self.configuration.make_sigmoid()
estimate = self.get_parameters_estimate(estimate_type)
loc, scale = sigmoid.standard_parameters(estimate['threshold'], estimate['width'])
return loc, scale
29 changes: 29 additions & 0 deletions psignifit/tests/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,32 @@ def test_estimate_type_default(result):
result.estimate_type = 'mean'
estimate = result.get_parameters_estimate()
assert _close_numpy_dict(estimate, result.parameters_estimate_mean)


def test_standard_parameters_estimate():
width = 2.1
threshold = 0.87
parameter_estimate = {
'threshold': threshold,
'width': width,
'lambda': 0.0,
'gamma': 0.0,
'eta': 0.0,
}
confidence_intervals = {
'threshold': [[threshold, threshold]],
'width': [[width, width]],
'lambda': [[0.05, 0.2]],
'gamma': [[0.1, 0.3]],
'eta': [[0.0, 0.0]]
}
result = _build_result(parameter_estimate, parameter_estimate, confidence_intervals)

# For a Gaussian sigmoid with alpha=0.05, PC=0.5
expected_loc = threshold
# 1.644853626951472 is the normal PPF at alpha=0.95
expected_scale = width / (2 * 1.644853626951472)

loc, scale = result.standard_parameters_estimate()
np.testing.assert_allclose(loc, expected_loc)
np.testing.assert_allclose(scale, expected_scale)

0 comments on commit f672d1b

Please sign in to comment.