bundles / scipy 1.17.1 / scipy / stats / _censored_data / CensoredData
class
scipy.stats._censored_data:CensoredData
Signature
class CensoredData ( uncensored = None , * , left = None , right = None , interval = None ) Members
-
__init__ -
__len__ -
__repr__ -
__str__ -
__sub__ -
__truediv__ -
_supported -
_uncensor -
interval_censored -
left_censored -
num_censored -
right_censored
Summary
Instances of this class represent censored data.
Extended Summary
Instances may be passed to the fit method of continuous univariate SciPy distributions for maximum likelihood estimation. The only method of the univariate continuous distributions that understands CensoredData is the fit method. An instance of CensoredData can not be passed to methods such as pdf and cdf.
An observation is said to be censored when the precise value is unknown, but it has a known upper and/or lower bound. The conventional terminology is:
left-censored: an observation is below a certain value but it is unknown by how much.
right-censored: an observation is above a certain value but it is unknown by how much.
interval-censored: an observation lies somewhere on an interval between two values.
Left-, right-, and interval-censored data can be represented by CensoredData.
For convenience, the class methods left_censored and right_censored are provided to create a CensoredData instance from a single one-dimensional array of measurements and a corresponding boolean array to indicate which measurements are censored. The class method interval_censored accepts two one-dimensional arrays that hold the lower and upper bounds of the intervals.
Parameters
uncensored: array_like, 1DUncensored observations.
left: array_like, 1DLeft-censored observations.
right: array_like, 1DRight-censored observations.
interval: array_like, 2D, with shape (m, 2)Interval-censored observations. Each row
interval[k, :]represents the interval for the kth interval-censored observation.
Notes
In the input array interval, the lower bound of the interval may be -inf, and the upper bound may be inf, but at least one must be finite. When the lower bound is -inf, the row represents a left- censored observation, and when the upper bound is inf, the row represents a right-censored observation. If the length of an interval is 0 (i.e. interval[k, 0] == interval[k, 1], the observation is treated as uncensored. So one can represent all the types of censored and uncensored data in interval, but it is generally more convenient to use uncensored, left and right for uncensored, left-censored and right-censored observations, respectively.
Examples
In the most general case, a censored data set may contain values that are left-censored, right-censored, interval-censored, and uncensored. For example, here we create a data set with five observations. Two are uncensored (values 1 and 1.5), one is a left-censored observation of 0, one is a right-censored observation of 10 and one is interval-censored in the interval [2, 3].import numpy as np from scipy.stats import CensoredData data = CensoredData(uncensored=[1, 1.5], left=[0], right=[10], interval=[[2, 3]])✓
print(data)
✗data = CensoredData(interval=[[1, 1], [1.5, 1.5], [-np.inf, 0], [10, np.inf], [2, 3]])✓
print(data)
✗data = CensoredData(uncensored=[13, 22, 17, 15], right=[20, 18]) print(data)✓
ttf = [13, 22, 17, 15, 20, 18] censored = [False, False, False, False, True, True]✓
data = CensoredData.right_censored(ttf, censored) print(data)✓
a = [10, 0.5, 2, 12.5] # Low ends of the intervals b = [11, 1.0, 3, 13.5] # High ends of the intervals data = CensoredData.interval_censored(low=a, high=b) print(data)✓
from scipy.stats import weibull_min rng = np.random.default_rng()✓
x = weibull_min.rvs(2.5, loc=0, scale=30, size=250, random_state=rng) x[x > 40] = 40 # Right-censor values greater or equal to 40.✓
data = CensoredData.right_censored(x, x == 40)
✓print(data)
✗weibull_min.fit(data, floc=0)
✗Aliases
-
scipy.stats.CensoredData