4

パッケージpowerlawを使用して、いくつかの powerlaw フィットをプロットしてみました。単一の曲線で機能しているようです。しかし、同じグラフに複数のプロットをプロットできませんでした。 参照:このパッケージ内に方法はありますか? 【PS初心者です】

set.seed(1)
x1 <- ceiling(rlnorm(1000, 4))

x2 <- ceiling(rlnorm(1000, 2))

library(poweRlaw)

pl_d = pl_data$new(x1)
plot(pl_d)

#Now fit the powerlaw
m = displ$new(pl_d)
#Estimate the cut-off
#estimate_xmin(m)
aaa <- estimate_xmin(m)
aaa <- as.data.frame(aaa)
aaa <- aaa[2,1]
x_min <- min(table(x))
m$setXmin(aaa); m$mle()
#Plot the data and the PL line
#plot(m)
lines(m, col=2)

# next POWER LAW graph

#Plot the data
pl_d = pl_data$new(x2)
points(pl_d)

#Now fit the powerlaw
m = displ$new(pl_d)
#Estimate the cut-off
#estimate_xmin(m)
aaa <- estimate_xmin(m)
aaa <- as.data.frame(aaa)
aaa <- aaa[2,1]
x_min <- min(table(x))
m$setXmin(aaa); m$mle()
#Plot the data and the PL line
#points(m)
lines(m, col=3)
4

1 に答える 1

3

コマンドを使用して、lines最適なべき乗則を複数追加できます。したがって、データを使用して:

set.seed(1)
x1 = ceiling(rlnorm(1000, 4))

パッケージをロードして、離散べき乗則オブジェクトを作成します。

m = displ$new(x1)

次に、データをプロットします

plot(m)

次に、各べき乗則に対してxminとを設定し、 を使用してグラフに追加します。alphalines

m$setXmin(100)
p_100 = estimate_pars(m)
m$setPars(p_100)
lines(m, col=2, lwd=2)

##Line 2    
m$setXmin(202)
p_200 = estimate_pars(m)
m$setPars(p_200)
lines(m, col=3, lwd=2)

ここに画像の説明を入力


同じプロットに複数のデータ セットが必要な場合、最も簡単な方法は 1 つのデータ セットをプロットし、データをデータ フレームとして保存することです。たとえば、いくつかのデータ セットを生成します。

set.seed(1)
x1 = ceiling(rlnorm(1000, 4))
x2 = ceiling(rlnorm(1000, 5))

ベキ乗則を当てはめる

m1 = displ$new(x1)
m1$setXmin(estimate_xmin(m1))

m2 = displ$new(x2)
m2$setXmin(estimate_xmin(m2))

データ セット 2 をプロットしますが、データを次のように保存します。pts2

pts2 = plot(m2)

通常どおりに行をプロットして追加します。

plot(m1)
points(pts2$x, pts2$y, col=3)
lines(m1, col=2)
lines(m2, col=4)

取得するため:

ここに画像の説明を入力

于 2013-02-24T20:05:05.083 に答える