I’ve never used Squiggle, but I imagine its main benefit is the ease of use and transparency. Consider the line > transfer_efficiency = 0.75 to 0.9 in the Squiggle doc. In Numpy, you’d most likely have to select number samples, initiate an rng object (at least if you do as Numpy recommend), transform the quantiles (0.05,0.95)-quantiles 0.75 and 0.9 into mean and sigma, call the log-normal random generator and store them in an array, then call the appropriate plot function. Most of these steps are minor nuisances, except for the transformation of quantiles, which might be beyond the analyst’s skill level to do efficiently.
Here’s my replication in Python, which was kind of a chore to make… All of this can be done in one line in Squiggle.
import numpy as np import scipy.stats as st import matplotlib.pyplot as plt
rng = np.random.default_rng(313) n = 10000
# Translate quantiles a = np.log(0.75) b = np.log(0.9)
x = np.linspace(0.7, 1, 100) plt.plot(x, st.lognorm.pdf(x/np.exp(mean), sigma)) # Scipy’s parameterization of the log-normal is stupid. Cost me another 5 minutes to figure out how to do this one.
### It’s prudent to check if I’ve done the calculations correctly too.. np.quantile(transfer_efficiency, [0.05, 0.95]) # array([0.75052923, 0.90200089])
1- If one had e.g. the 10th and 90th percentiles instead of the 5th and 95th, would Guesstimate and Squiggle be able to model the distribution in one line? I think one of the major upsides of Python is its flexibility...
2- I agree that converting the quantiles to distribution parameters is the main hurdle. With that in mind, I posted this roughly 1 week ago.
3- Using this spreadsheet to determine the distribution parameters mu and sigma (as explained in the post linked just above), it is also possible to calculate the distribution with one line: transfer_efficiency = np.random.lognormal(mu, sigma, N_samples)
I’ve never used Squiggle, but I imagine its main benefit is the ease of use and transparency. Consider the line
> transfer_efficiency = 0.75 to 0.9
in the Squiggle doc. In Numpy, you’d most likely have to select number samples, initiate an rng object (at least if you do as Numpy recommend), transform the quantiles (0.05,0.95)-quantiles 0.75 and 0.9 into mean and sigma, call the log-normal random generator and store them in an array, then call the appropriate plot function. Most of these steps are minor nuisances, except for the transformation of quantiles, which might be beyond the analyst’s skill level to do efficiently.
Here’s my replication in Python, which was kind of a chore to make… All of this can be done in one line in Squiggle.
import numpy as np
import scipy.stats as st
import matplotlib.pyplot as plt
rng = np.random.default_rng(313)
n = 10000
# Translate quantiles
a = np.log(0.75)
b = np.log(0.9)
k1 = st.norm.ppf(0.05)
k2 = st.norm.ppf(0.95)
sigma = (b—a) / (k2 - k1)
mean = b—sigma * k2
transfer_efficiency = np.random.lognormal(
mean=mean,
sigma=sigma,
size=n)
x = np.linspace(0.7, 1, 100)
plt.plot(x, st.lognorm.pdf(x/np.exp(mean), sigma)) # Scipy’s parameterization of the log-normal is stupid. Cost me another 5 minutes to figure out how to do this one.
### It’s prudent to check if I’ve done the calculations correctly too..
np.quantile(transfer_efficiency, [0.05, 0.95]) # array([0.75052923, 0.90200089])
Thanks for the reply!
0- Thanks for sharing the post about minor nuisances!
1- If one had e.g. the 10th and 90th percentiles instead of the 5th and 95th, would Guesstimate and Squiggle be able to model the distribution in one line? I think one of the major upsides of Python is its flexibility...
2- I agree that converting the quantiles to distribution parameters is the main hurdle. With that in mind, I posted this roughly 1 week ago.
3- Using this spreadsheet to determine the distribution parameters mu and sigma (as explained in the post linked just above), it is also possible to calculate the distribution with one line:
transfer_efficiency = np.random.lognormal(mu, sigma, N_samples)