diff options
| author | Ben Green <bgreen@g.harvard.edu> | 2015-09-18 23:38:46 -0400 |
|---|---|---|
| committer | Ben Green <bgreen@g.harvard.edu> | 2015-09-18 23:38:48 -0400 |
| commit | bb68c49552f69b90ce840dbd7346fc76eb93e3e3 (patch) | |
| tree | a5a184d2403eb16dbadf9cbf9a1f32f540d5ab00 /R Scripts/plot-power-law.R | |
| parent | a585b261dace47783fdae28130c8e4792627a230 (diff) | |
| download | criminal_cascades-bb68c49552f69b90ce840dbd7346fc76eb93e3e3.tar.gz | |
pretty plots!
Diffstat (limited to 'R Scripts/plot-power-law.R')
| -rw-r--r-- | R Scripts/plot-power-law.R | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/R Scripts/plot-power-law.R b/R Scripts/plot-power-law.R new file mode 100644 index 0000000..8cca228 --- /dev/null +++ b/R Scripts/plot-power-law.R @@ -0,0 +1,26 @@ +plot(1:max(degree(lcc)),degree.distribution(lcc)[-1], + log='xy',col='#377EB8',pch=20, + xlab='Degree', ylab='Number of Vertices', main='') + + +# plot and fit the power law distribution +# calculate degree +d = degree(graph, mode = "all") +dd = degree.distribution(graph, mode = "all", cumulative = FALSE) +degree = 1:max(d) +probability = dd[-1] +# delete blank values +nonzero.position = which(probability != 0) +probability = probability[nonzero.position] +degree = degree[nonzero.position] +reg = lm(log(probability) ~ log(degree)) +cozf = coef(reg) +power.law.fit = function(x) exp(cozf[[1]] + cozf[[2]] * log(x)) +alpha = -cozf[[2]] +print(paste("Alpha =", round(alpha, 3))) +# plot +print(d) +curve(power.law.fit, col = "red", add = T, n = length(d)) + + +# fit_power_law(lcc) |
