Convergence of PageRank
In this exercise, you will visually inspect how the PageRanks converge by plotting the differences of every two subsequent iterations.
This exercise is part of the course
Predictive Analytics using Networked Data in R
Exercise instructions
- Create an empty vector called
value
. - Write a
for
loop with 15 steps. For each step in the loop, compute the PageRank value ofnetwork
withi
iterations. Add thevector
attribute as a column tovalue
usingcbind()
. - Compute the absolute difference between each subsequent pair of PageRank vectors in
value
and assign todifference
. - Plot the
difference
vector to inspect the convergence of the PageRank values.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create an empty vector
___ <- c()
# Write a loop to compute PageRank
for(i in 1:___){
value <- cbind(value, page.rank(___, algo = 'power',options = list(niter = ___))$vector)
}
# Compute the differences
difference <- colSums(abs(___[,1:14] - ___[,2:15]))
# Plot the differences
___(1:14, difference)