MrR*_*bot 3 python statistics r scipy
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:
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
Run Code Online (Sandbox Code Playgroud)
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 ]
Run Code Online (Sandbox Code Playgroud)
I saw here that these two functions are equivalent.
SciPystats.uniform由loc和参数化scale,而 R 函数由min和参数化max。等效的 SciPy 将是
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])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
164 次 |
| 最近记录: |