Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Code used to illustrate effects of K factors.
########################################
# K Factor Example #
########################################
# Apply the gravity model
gravity<-function(T0,f,k){
Zones=nrow(T0)
T1<-matrix(0,Zones,Zones)
for(i in 1:Zones){
P=sum(T0[i,])
for(j in 1:Zones){
A=sum(T0[,j])*f[i,j]*k[i,j]
SA=sum(T0*f[i,]*k[i,])
T1[i,j]=P*A/SA
}
}
return(T1)
}
Zones=5
T0<-matrix(50,Zones,Zones)
ff<-matrix(1,Zones,Zones)
K<-matrix(1,Zones,Zones)
T1<-gravity(T0,ff,K)
K[1,5]<-2
K[5,1]<-2
T2<-gravity(T0,ff,K)
K[1,5]<-0.5
K[5,1]<-0.2
T3<-gravity(T0,ff,K)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment