Discrete Random Variables
Only a countable number of values can be assigned to discrete random variables. L is an additional integer parameter that can be added to any discrete distribution. The general distribution p and the standard distribution p0 have the following relationship:
scipy.stats.circmean
Compute the circular mean for samples in a range. We will use the following function to calculate the circular mean:
Syntax:
scipy.stats.circmean(array, high=2*pi, low=0, axis=None, nan_policy=’propagate’)
where,
- Array – input array or samples.
- high (float or int ) – high boundary for sample. default high = 2 * pi.
- low ( float or int ) – low boundary for sample. default low = 0.
- axis ( int ) – Axis along which means are computed.
- nan_policy ( ‘propagate’, ‘raise’, ‘omit’ ) – Defines how to handle when input contains nan. ‘propagate’ returns nan, ‘raise’ throws an error, and ‘omit’ performs the calculations ignoring nan values. The default is ‘propagate’.
Python3
# importing the required package from scipy.stats import circmean # calculating the circular mean print (circmean([ 0.4 , 2.4 , 3.6 ], high = 4 , low = 2 )) # | | | # ------------- ------------ ------------ # sample array higher bound lower bound |
Output:
2.254068341376122
scipy.stats.contingency.crosstab
Given the lists a and p, create a contingency table that counts the frequencies of the corresponding pairs.
Python3
# importing the required package from scipy.stats.contingency import crosstab # list p a = [ 'A' , 'B' , 'A' , 'A' , 'B' , 'B' , 'A' , 'A' , 'B' , 'B' ] # list q p = [ 'P' , 'P' , 'P' , 'Q' , 'R' , 'R' , 'Q' , 'Q' , 'R' , 'R' ] # result ndarray print (crosstab(a, p)) # using the crosstab function and extracting # the informations like - a's unique values, # b's unique values and the final count of the pairs. (auv, puv), cnt = crosstab(a, p) # printing list a's unique values print (auv) # printing list p's unique values print (puv) # printing the count object which tells us # the pairs count for each unique values of a and p. print (cnt) |
Output:
((array(['A', 'B'], dtype='<U1'), array(['P', 'Q', 'R'], dtype='<U1')), array([[2, 3, 0], [1, 0, 4]])) ['A' 'B'] ['P' 'Q' 'R'] [[2 3 0] [1 0 4]]
Note – In the above output, we have a ndarray, which consists of the different other arrays. The first value (array([‘A’, ‘B’]), dtype='<U1′) is basically the array of unique values in the list a, the second value (array([‘P’, ‘Q’, ‘R’]),dtype='<U1′) is basically the array of unique values in the list p, and the third value is the frequency of each pair of list a and list p.
list a =
A B A A B B A A B B list b =
P P P Q R R Q Q R R
SciPy – Stats
The scipy.stats is the SciPy sub-package. It is mainly used for probabilistic distributions and statistical operations. There is a wide range of probability functions.
There are three classes:
Class | Description |
rv_continuous | For continuous random variables, we can create specialized distribution subclasses and instances. |
rv_discrete | For discrete random variables, we can create specialized distribution subclasses and instances. |
rv_histogram | generate specific distribution histograms. |
Contact Us