我正在尝试估计堆定律的常数。
我有以下数据集novels_colection
:
Number of novels DistinctWords WordOccurrences
1 1 13575 117795
2 1 34224 947652
3 1 40353 1146953
4 1 55392 1661664
5 1 60656 1968274
然后我构建下一个函数:
# Function for Heaps law
heaps <- function(K, n, B){
K*n^B
}
heaps(2,117795,.7) #Just to test it works
So n = Word Occurrences
, and K
and B
是应该是常量的值,以便找到我对不同单词的预测。
我尝试了这个,但它给了我一个错误:
fitHeaps <- nls(DistinctWords ~ heaps(K,WordOccurrences,B),
data = novels_collection[,2:3],
start = list(K = .1, B = .1), trace = T)
Error = Error in numericDeriv(form[[3L]], names(ind), env) :
Missing value or an infinity produced when evaluating the model
任何关于如何解决这个问题或适合函数并获取值的方法的想法K
and B
?