Skip to content

Commit a625da0

Browse files
krlmlrmaelle
authored andcommitted
feat: Support fit_power_law(implementation = "plfit.p") to compute the P-value
1 parent f04cf68 commit a625da0

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

R/fit.R

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,19 @@ power.law.fit <- function(x, xmin = NULL, start = 2, force.continuous = FALSE, i
9999
#' be used to calculate confidence intervals and log-likelihood. See
100100
#' [stats4::mle-class()] for details.
101101
#'
102-
#' If `implementation` is \sQuote{`plfit`}, then the result is a
103-
#' named list with entries: \item{continuous}{Logical scalar, whether the
102+
#' If `implementation` is \sQuote{`plfit`} or \sQuote{`plfit.p`}, then the result is a
103+
#' named list with entries:
104+
#' \item{continuous}{Logical scalar, whether the
104105
#' fitted power-law distribution was continuous or discrete.}
105-
#' \item{alpha}{Numeric scalar, the exponent of the fitted power-law
106-
#' distribution.} \item{xmin}{Numeric scalar, the minimum value from which the
106+
#' \item{alpha}{Numeric scalar, the exponent of the fitted power-law distribution.}
107+
#' \item{xmin}{Numeric scalar, the minimum value from which the
107108
#' power-law distribution was fitted. In other words, only the values larger
108-
#' than `xmin` were used from the input vector.} \item{logLik}{Numeric
109-
#' scalar, the log-likelihood of the fitted parameters.} \item{KS.stat}{Numeric
110-
#' scalar, the test statistic of a Kolmogorov-Smirnov test that compares the
111-
#' fitted distribution with the input vector. Smaller scores denote better
112-
#' fit.} \item{KS.p}{Numeric scalar, the p-value of the Kolmogorov-Smirnov
109+
#' than `xmin` were used from the input vector.}
110+
#' \item{logLik}{Numeric scalar, the log-likelihood of the fitted parameters.}
111+
#' \item{KS.stat}{Numeric scalar, the test statistic of a Kolmogorov-Smirnov test
112+
#' that compares the fitted distribution with the input vector.
113+
#' Smaller scores denote better fit.}
114+
#' \item{KS.p}{Only for `plfit.p`. Numeric scalar, the p-value of the Kolmogorov-Smirnov
113115
#' test. Small p-values (less than 0.05) indicate that the test rejected the
114116
#' hypothesis that the original data could have been drawn from the fitted
115117
#' power-law distribution.}
@@ -137,15 +139,25 @@ power.law.fit <- function(x, xmin = NULL, start = 2, force.continuous = FALSE, i
137139
#' fit1$logLik
138140
#' stats4::logLik(fit2)
139141
#'
140-
fit_power_law <- function(x, xmin = NULL, start = 2, force.continuous = FALSE,
141-
implementation = c("plfit", "R.mle"), ...) {
142+
fit_power_law <- function(
143+
x,
144+
xmin = NULL,
145+
start = 2,
146+
force.continuous = FALSE,
147+
implementation = c("plfit", "R.mle", "plfit.p"),
148+
...) {
142149
implementation <- igraph.match.arg(implementation)
143150

144151
if (implementation == "r.mle") {
145152
power.law.fit.old(x, xmin, start, ...)
146-
} else if (implementation == "plfit") {
153+
} else if (implementation %in% c("plfit", "plfit.p")) {
147154
if (is.null(xmin)) xmin <- -1
148-
power.law.fit.new(x, xmin = xmin, force.continuous = force.continuous)
155+
power.law.fit.new(
156+
x,
157+
xmin = xmin,
158+
force.continuous = force.continuous,
159+
p.value = (implementation == "plfit.p")
160+
)
149161
}
150162
}
151163

man/fit_power_law.Rd

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)