Why is the shape and scale estimation of a Weibull Distribution different in Python and R?

Viewed 29

I am porting some distribution fitting code from R to Python and I noticed that the shape and scale parameter estimation in R and Python are different after 3 decimal places, and I wondered why this would be the case.

R code:

library(fitdistrplus)
library(ADGofTest)

set.seed(66)
weibull_sample <- rweibull(150, shape = 0.75, scale = 1)

weibull_fit <- fitdist(weibull_sample,"weibull",method="mle")
summary(weibull_fit) # shape = 0.888309653152, scale = 1.065783323933 
gofstat(weibull_fit) #AD  0.9755906963522
plot(weibull_fit)

ad.test(weibull_sample, pweibull, shape = 0.888309653152, scale = 1.065783323933)
# AD = 0.9755906964

write.csv(weibull_sample, file = "weibull_sample.csv", row.names = FALSE, col.names = FALSE)

here is the python code

# Import libraries
import pandas as pd
import numpy as np
import math
from scipy import stats
import statistics as stat
# Read in a dataset from disk (n)
file_path = "weibull_sample.csv"

weibull_df = pd.read_csv(file_path)
weibull_df = weibull_df.sort_values(by=['Wait_Times'], ascending=True)
weibull_df = weibull_df.reset_index(drop=True)

# Find the parameters a Weibull Distribution based on the head dataset
weibull_fit = stats.weibull_min.fit(weibull_df['Wait_Times'], floc=0)

# Extract parameters to individual values
weibull_shape, wiebull_unused, weibull_scale = weibull_fit

# Print the values
print("Weibull Shape Parameter for Dataset", weibull_shape)
print("Weibull Scale Parameter for Dataset", weibull_scale)


#shape R  = 0.888309653152
#shape Py = 0.8883784856851663

#scale R  = 1.065783323933
#scale Py = 1.0659294522799554

Note I am using a flag in R to set the decimal places to 12 as follows options(digits = 12), Python appears to provide 16dp by default.

Of course, if I round to 3 decimal places I am none the wiser but I am wondering why there is a difference in the first place.

But more importantly how do I know which set of parameters is "correct"?

0 Answers
Related