@@ -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
@@ -186,15 +198,15 @@ power.law.fit.old <- function(x, xmin = NULL, start = 2, ...) {
186198 alpha
187199}
188200
189- power.law.fit.new <- function (data , xmin = - 1 , force.continuous = FALSE ) {
201+ power.law.fit.new <- function (data , xmin = - 1 , force.continuous = FALSE , p.value = FALSE ) {
190202 # Argument checks
191203 data <- as.numeric(data )
192204 xmin <- as.numeric(xmin )
193205 force.continuous <- as.logical(force.continuous )
194206
195207 on.exit(.Call(R_igraph_finalizer ))
196208 # Function call
197- res <- .Call(R_igraph_power_law_fit , data , xmin , force.continuous )
209+ res <- .Call(R_igraph_power_law_fit_new , data , xmin , force.continuous , p.value )
198210
199211 res
200212}
0 commit comments