Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kolmogorov-Smirnov goodness of fit test for Weibull distribution (deleted)
**URL**: https://stats.stackexchange.com/questions/127257/kolmogorov-smirnov-goodness-of-fit-test-for-weibull-distribution/127259
**Linked from**: https://stats.stackexchange.com/a/129279/31372 (as "my earlier answer")
**Question**: How do I perform Kolmogorov-Smirnov goodness of fit test for Weibull distribution?
**My Answer**:
If you know the parameters of _Weibull distribution_ in question, then performing _Kolmogorov-Smirnov (K-S) test_ is just a matter of a single line of code:
```
ks.test(weiDistKnown, "pweibull", shape = 2, scale = 1),
```
where `weiDistKnown` refers to a vector of data values, representing Weibull distribution with **known** parameters.
In a `different scenario`, where you hypothesize that data represents/fits a Weibull distribution, but _don't know the distribution's parameters_, the solution is two-fold. First, you **fit** the to the distribution by using one of several `R` packages, providing this functionality. For example, as follows:
```
library(MASS)
fitdistr(weiDistUnknown, densfun = dweibull, start = list(scale = 1, shape = 2)),
```
where `weiDistUnknown` refers to a vector of data values, representing Weibull distribution with **unknown** parameters, correspondingly.
For Weibull and several other distributions, you can omit `start` values - `fitdistr()` will attempt to determine reasonable values, however they might not be optimal for best fit. If there are any particular difficulties in determining parameters of the distribution, consider performing **alternative GoF tests**, such as `Anderson-Darling (A-D)` and `Lilliefors` tests. A-D test is available for a range of distributions, which includes Weibull.
The output from `fitdistr()` will provide you with distribution parameters, which then can be used for performing **K-S test**, as described above.
**NOTE:** As you probably noticed, I've used `R` in answering your question. If you don't use R - you haven't specified that - or prefer an alternative environment, similar functionality exists in all major statistical software packages, such as _Stata_, _SPSS_, _Mplus_, _STATISTICA_ and others.
@ablekh

This comment has been minimized.

Copy link
Owner Author

@ablekh ablekh commented Mar 17, 2020

The formatted version follows.

URL: https://stats.stackexchange.com/questions/127257/kolmogorov-smirnov-goodness-of-fit-test-for-weibull-distribution/127259
Linked from: https://stats.stackexchange.com/a/129279/31372 (as "my earlier answer")

Question: How do I perform Kolmogorov-Smirnov goodness of fit test for Weibull distribution?

My Answer:

If you know the parameters of Weibull distribution in question, then performing Kolmogorov-Smirnov (K-S) test is just a matter of a single line of code:

ks.test(weiDistKnown, "pweibull", shape = 2, scale = 1),

where weiDistKnown refers to a vector of data values, representing Weibull distribution with known parameters.

In a different scenario, where you hypothesize that data represents/fits a Weibull distribution, but don't know the distribution's parameters, the solution is two-fold. First, you fit the to the distribution by using one of several R packages, providing this functionality. For example, as follows:

library(MASS)
fitdistr(weiDistUnknown, densfun = dweibull, start = list(scale = 1, shape = 2)),

where weiDistUnknown refers to a vector of data values, representing Weibull distribution with unknown parameters, correspondingly.

For Weibull and several other distributions, you can omit start values - fitdistr() will attempt to determine reasonable values, however they might not be optimal for best fit. If there are any particular difficulties in determining parameters of the distribution, consider performing alternative GoF tests, such as Anderson-Darling (A-D) and Lilliefors tests. A-D test is available for a range of distributions, which includes Weibull.

The output from fitdistr() will provide you with distribution parameters, which then can be used for performing K-S test, as described above.

NOTE: As you probably noticed, I've used R in answering your question. If you don't use R - you haven't specified that - or prefer an alternative environment, similar functionality exists in all major statistical software packages, such as Stata, SPSS, Mplus, STATISTICA and others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment