[R-sig-Geo] power index
az14
abidi.zineb at gmail.com
Mon Aug 4 14:31:54 CEST 2014
Dear list,
I'm trying to calculate Banzhaf power index for a set of 1260
municipalities.
My data is as below, where the insee variable is the municipalities, the
variable "nbrseat" is the number of seat in the CM of each municipalities
and the "numeroc" is the groupes ( numeroc takes the value of 1 for the
group 1 ans 2 for the group 2....group 119)
The program i used is :
data<-read.csv("bzh.csv",header=TRUE,sep=";",dec=',')
attach(data)
data<-as.matrix(data)
summary(data)
for (numeroc in 1 :119) {nbseat<-Delegreel
#Banzhaf power index
#Length of the group : 2^m
subsets<-length(numeroc)-1
subs<-matrix(FALSE,2^subsets,subsets)
for (i in 1:subsets) {
subs[,i] <- rep(c(rep(FALSE, 2 ^ (i - 1)),
+
rep(TRUE, 2 ^ (i - 1))),
+ 2 ^
(subsets - i))
}
q<-sum(nbseat)/2
banzhaf <- function(i) {
other <- nbseat[-i]
part.sum <- apply(subs, 1, function(x)
{sum(other[x]) } )
sum((part.sum < q) & ((part.sum + nbseat[i]) >q))
}}
BZH <- prop.table(sapply(1:length(Delegreel), banzhaf))
but it did not work.
i will be very grateful for any help.
Thank you.
Sincerely.
Zineb
data:
insee nbrseat numeroc
22001 5 1
22300 3 1
22384 8 1
22047 6 2
22074 4 2
22244 2 2
22313 2 2
22316 2 2
22033 2 3
22158 9 3
22285 2 3
22295 2 3
22298 3 3
29007 4 4
29012 1 4
29081 8 4
29129 1 4
29275 4 4
22097 3 5
22104 2 5
22180 8 5
22315 1 5
22317 1 5
22318 1 5
22342 2 5
22078 1 6
22101 5 6
22247 6 6
22253 1 6
22264 5 6
22383 1 6
29013 1 7
29016 5 7
29018 2 7
29054 3 7
29139 3 7
29141 1 7
29211 3 7
29261 1 7
56009 4 8
56114 3 8
56152 11 8
56241 4 8
35098 5 9
35124 10 9
35249 4 9
35316 3 9
56056 1 10
56080 6 10
56129 7 10
56134 4 10
56227 2 10
56257 3 10
56025 1 11
56043 4 11
56127 12 11
56145 5 11
56208 1 11
56225 1 11
56256 1 11
22005 4 12
22037 1 12
22072 1 12
22129 1 12
22135 9 12
22216 3 12
22354 4 12
22018 1 13
22204 5 13
22212 4 13
22250 4 13
22256 4 13
22269 1 13
22283 3 13
22032 10 14
22036 1 14
22069 1 14
22071 2 14
22239 4 14
22240 4 14
22305 2 14
22312 1 14
22013 10 15
22040 2 15
22088 1 15
22092 1 15
22139 1 15
22156 2 15
22189 2 15
22249 2 15
22271 1 15
22335 1 15
22035 4 16
22056 6 16
22208 5 16
22263 1 16
22274 1 16
22306 2 16
22308 2 16
22352 1 16
22006 1 17
22030 3 17
22034 5 17
22041 1 17
22245 4 17
22254 4 17
22257 1 17
22340 4 17
22023 2 18
22024 1 18
22025 9 18
22031 3 18
22052 1 18
22132 1 18
22138 1 18
22231 1 18
22243 2 18
22320 1 18
22328 1 18
22046 3 19
22066 4 19
22102 2 19
22191 7 19
22292 1 19
22297 2 19
22303 3 19
56046 11 20
56116 6 20
56233 5 20
29033 2 21
29062 4 21
29115 1 21
29123 3 21
29142 1 21
29162 11 21
29053 5 22
29240 3 22
29263 3 22
29302 11 22
22062 2 23
22083 2 23
22122 2 23
22133 2 23
22147 9 23
22148 1 23
22309 1 23
22333 2 23
22371 3 23
35035 1 24
35046 1 24
35048 1 24
35057 3 24
35084 2 24
35160 1 24
35168 10 24
35175 3 24
35311 1 24
22119 1 25
22131 3 25
22207 7 25
22217 1 25
22227 2 25
22228 4 25
22359 1 25
22387 3 25
22009 1 26
22080 2 26
22171 11 26
22203 9 26
22051 1 27
22084 5 27
22175 3 27
22185 7 27
22193 4 27
22341 2 27
56034 11 28
56168 6 28
56258 5 28
22103 2 29
22190 10 29
22213 9 29
22368 1 29
35034 3 30
35044 1 30
35222 6 30
35247 3 30
35248 1 30
35259 3 30
35270 1 30
35291 1 30
35329 2 30
35339 1 30
35354 1 30
35008 2 31
35102 1 31
35125 12 31
35198 2 31
35199 1 31
35200 2 31
35325 1 31
35359 3 31
22085 1 32
22111 1 32
22127 4 32
22195 7 32
22196 3 32
22199 3 32
22347 3 32
56126 5 33
56147 10 33
56195 2 33
56212 5 33
--
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/power-index-tp7586862.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list