Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R's qunif vs Python's stats.uniform.ppf (different results)

I have an array (distribution) and I want to make this distribution in some range a and b, this is done in R by using the function qunif, I want to do it in Python and it gives different results:

R

a <- c(0.012701112, 0.131852757, 0.230918602, 0.382584686, 0.422162992,
       0.553339539, 0.64807742, 0.735555988, 0.813598841, 0.975585224)
b <- qunif(a, -4, 4)

b
# -3.8983911 -2.9451779 -2.1526512 -0.9393225 -0.6226961 
# 0.4267163  1.1846194  1.8844479  2.5087907  3.8046818

Python

import scipy.stats as stats

a = [0.012701112, 0.131852757, 0.230918602, 0.382584686, 0.422162992,
     0.553339539, 0.64807742, 0.735555988, 0.813598841, 0.975585224]
b = stats.uniform.ppf(a, -4, 4)

b
# [-3.94919555 -3.47258897 -3.07632559 -2.46966126 -2.31134803 
#  -1.78664184 -1.40769032 -1.05777605 -0.74560464 -0.0976591 ]

I saw here that these two functions are equivalent.

like image 795
jAdex Avatar asked Dec 06 '25 03:12

jAdex


1 Answers

The SciPy stats.uniform is parameterized by loc and scale, whereas the R function is parameterized by min and max. The equivalent SciPy would be

b = stats.uniform.ppf(a, loc=-4, scale=8)
b
# array([-3.8983911 , -2.94517794, -2.15265118, -0.93932251, -0.62269606,
#        0.42671631,  1.18461936,  1.8844479 ,  2.50879073,  3.80468179])
like image 70
merv Avatar answered Dec 07 '25 16:12

merv