1

私はジップの法則の分布を持つデータセットを持っています、そして今私はそれを標準的なzipf図と比較したいです、これは私のRコードです:

f <- read.table('/myfile.txt',sep='\t',header=T)
attach(f)
fs <- f[order(cnt), ]
detach(f)
n = 1:dim(fs)[1]
plot(fs[,2]~n)

zipf今、私はそれを同じプロットで比較したいのですが、どうすればこれを行うことができRますか?

4

1 に答える 1

6

VGAMパッケージには、Zipf分布の指数を推定するための機能があります。最適な推定密度に対して分布をプロットすることをお勧めします。

plot( cntdens <- table(f[['cnt']])/length(f[['cnt']]),
       xlim=range(f[['cnt']]), ylim=c(0, 0.8)  )

# And then plot the theoretic distribution for the VGAM fit 
# ... extending the example on ?VGAM::zipf:

require(VGAM)
zdata <- data.frame( y=1:max( f[['cnt']] ),  ofreq= table( f[['cnt']] ) )
fit = vglm(y ~ 1, zipf, zdata, trace = TRUE, weight = ofreq, crit = "coef")
proby = dzipf(1:max(f[['cnt']]), N =max(f[['cnt']]), s = Coef(fit) )
points((1:5)+0.05, proby,  col="red")

以下は、?dzipfページの例のデータを使用した手順です。 ここに画像の説明を入力してください

于 2012-10-21T20:25:19.560 に答える