R, Julia, SQL, Octave and others: Personal notes on data analysis, computation, data access most especially for querying voter history, Census, PDC, and other election data. Reader is advised to just paste the code text into Notepad++.
Sunday, November 29, 2015
Voting Analysis Code for 2015
Political piece here.
# 10:11 AM 11/27/2015 -RMF
# Loads the latest (final) matchback and (final) vote results.
# Compares election results with aggregated voting returns and good ballots
# among other....
# You need matchbacks and final returns plus some created text lists.
library(reshape2)
library(dplyr)
setwd("C:/Politics")
x <- read.delim("MB.11.24.15.FINAL.txt", header = TRUE, strip.white = TRUE, sep = "\t", quote = "", stringsAsFactors = FALSE)
print(paste0("Total Registered (Active) Voters: ",nrow(x)))
print(count(x, AVReturnStatus))
print(count(x, AVReturnChallenge))
print(as.data.frame(count(x, AVReturnedDate)))
Good <- subset(x, AVReturnStatus == "Good")
Challenged <- subset(x, AVReturnStatus == "Challenged")
Undeliverable <- subset(x, AVReturnStatus == "Undeliverable")
Void <- subset(x, AVReturnStatus == "Void")
t1 <- arrange(data.frame(with(x,(table(PrecinctID)))),desc(PrecinctID))
t2 <- arrange(data.frame(with(Good,(table(PrecinctID)))),desc(PrecinctID))
t3 <- arrange(data.frame(with(Challenged,(table(PrecinctID)))),desc(PrecinctID))
t4 <- arrange(data.frame(with(Undeliverable,(table(PrecinctID)))),desc(PrecinctID))
t5 <- arrange(data.frame(with(Void,(table(PrecinctID)))),desc(PrecinctID))
m1 <- merge(t1,t2,by="PrecinctID"); m1 <- with(m1,cbind(m1,scales::percent(Freq.y/Freq.x)));colnames(m1) <- c("PrecinctID","Total_Registered", "Good", "PCT")
m1$PrecinctID <- as.numeric(as.character(m1$PrecinctID))
m2 <- merge(t1,t2,by="PrecinctID"); m2 <- with(m2,cbind(m2,(Freq.y/Freq.x)));colnames(m2) <- c("PrecinctID","Total_Registered", "Good", "PCT")
m2$PrecinctID <- as.numeric(as.character(m2$PrecinctID))
# setwd("C:/Politics/WC2015/11.23")
download.file("http://results.vote.wa.gov/results/current/export/20151103_WhatcomPrecincts.csv","20151103_WhatcomPrecincts.csv")
header <- c("Prop_DESC","Prop_NAME","Precinct1","Precinct2","Votes")
WCGEN2015 <- read.csv("C:/Politics/WC2015/11.23/20151103_WhatcomPrecincts.csv",fill=FALSE,header=FALSE,col.names=header,stringsAsFactors = FALSE)
#names(WCEN2015)
# need the precint filesin list1 downloaded
#[1] "Prop_DESC" "Prop_NAME" "Precinct1" "Precinct2" "Votes"
data=filter(WCGEN2015,Precinct1 != "Total")
list1 <- read.delim("list1.txt",strip.white = TRUE,header=TRUE)
for(i in list1$list1)
{
q1 <- t(dcast(filter(data,Prop_DESC == i),Prop_NAME ~ Precinct2))
q1 <- as.data.frame(q1,stringsAsFactors = FALSE)[-1,]; colnames(q1) <- c("V1","V2")
q1$V1 <- (as.numeric(as.character(q1$V1)))
q1$V2 <- (as.numeric(as.character(q1$V2)))
q1 <- arrange(with(q1,cbind("PID" = as.integer(as.character(row.names(q1))),q1,"V1_V2" = as.numeric(as.character(V1 - V2)))))
q2 <- noquote(gsub(" ","",substring(i,1,50)))
print("Writing q2")
write.csv(q1,paste0(noquote(gsub(" ","",substring(i,1,50))),".csv"),row.names=FALSE)
}
Ad10 <- read.csv("AdvisoryVoteNo.10EngrossedSubstituteHouseBi.csv", stringsAsFactors = FALSE)
Ad11 <- read.csv("AdvisoryVoteNo.11SecondSubstituteSenateBill.csv", stringsAsFactors = FALSE)
Ad12 <- read.csv("AdvisoryVoteNo.12SecondEngrossedSubstituteS.csv", stringsAsFactors = FALSE)
Ad13 <- read.csv("AdvisoryVoteNo.13EngrossedSubstituteSenateB.csv", stringsAsFactors = FALSE)
I1366 <- read.csv("InitiativeMeasureNo.1366concernsstatetaxesa.csv", stringsAsFactors = FALSE)
I1401 <- read.csv("InitiativeMeasureNo.1401concernstraffickingo.csv", stringsAsFactors = FALSE)
POB3 <- read.csv("PortofBellinghamAllCommissionerDistrict3.csv", stringsAsFactors = FALSE)
WCC1B <- read.csv("WhatcomCountyCouncilDistrict1PositionB.csv", stringsAsFactors = FALSE)
WCC2B <- read.csv("WhatcomCountyCouncilDistrict2PositionB.csv", stringsAsFactors = FALSE)
WCEX <- read.csv("WhatcomCountyExecutive.csv", stringsAsFactors = FALSE)
WC1 <- read.csv("WhatcomCountyPropositionNo.1MethodofElecti.csv", stringsAsFactors = FALSE)
WC_1 <- read.csv("WhatcomCountyPropositionNo.2015-1JailFacilit.csv", stringsAsFactors = FALSE)
WC2 <- read.csv("WhatcomCountyPropositionNo.2LimitingPowerof.csv", stringsAsFactors = FALSE)
WC3 <- read.csv("WhatcomCountyPropositionNo.3LimitingPowerof.csv",stringsAsFactors = FALSE)
WC4 <- read.csv("WhatcomCountyPropositionNo.4WordLimitforBa.csv", stringsAsFactors = FALSE)
WC5 <- read.csv("WhatcomCountyPropositionNo.5LoweringThreshol.csv" ,stringsAsFactors = FALSE)
WC6 <- read.csv("WhatcomCountyPropositionNo.6LoweringtheNumb.csv", stringsAsFactors = FALSE)
WC7 <- read.csv("WhatcomCountyPropositionNo.7TermLimitsforC.csv", stringsAsFactors = FALSE)
WC8 <- read.csv("WhatcomCountyPropositionNo.8AlteringComposit.csv", stringsAsFactors = FALSE)
WC9 <- read.csv("WhatcomCountyPropositionNo.9NumberofCouncil.csv", stringsAsFactors = FALSE)
WC10 <- read.csv("WhatcomCountyPropositionNo.10Amendmentsbyth.csv", stringsAsFactors = FALSE)
AllPWC2015 <- cbind(Ad10,Ad11,Ad12,Ad13,I1366,I1401,WC_1,WC1,WC2,WC3,WC4,WC5,WC6,WC7,WC8,WC9,WC10)
propN <- read.csv("list2.csv",fill=FALSE,header=TRUE,stringsAsFactors = FALSE)
# propNt <- (as.character(melt(t(propN))$value))
colnames(AllPWC2015) <- (as.character(melt(t(propN))$value))
PID <-AllPWC2015$PID
AllPWC2015 <- AllPWC2015[,-(which(colnames(AllPWC2015) == "PID"))]
AllPWC2015 <- (cbind(PID,AllPWC2015))
colSums(AllPWC2015[,2:ncol(AllPWC2015)])
CandWC2015 <- merge(merge(merge(POB3,WCC1B, by="PID"),WCC2B,by="PID"),WCEX,by="PID")
colnames(CandWC2015) <- c("PID","Jensen","Briscoe","diff18","Ayers","Donovan","diff19","Kershner","Sidhu","diff20","Louws","Gilfilen","diff21")
colSums(CandWC2015[,2:13])
AllWC2015 <- merge(AllPWC2015,CandWC2015,by="PID")
colSums(AllWC2015[,2:64])
write.csv(AllWC2015, "AllWC2015.csv",row.names=FALSE)
# rowSums and plots
difflist <- c("diff1","diff2","diff3","diff4","diff5","diff6","diff7","diff8","diff9","diff10","diff11","diff12","diff13","diff14","diff15","diff16","diff17","diff18","diff19","diff20","diff21")
for(i in difflist) {AllPWC2015 <- AllPWC2015[,which(colnames(AllPWC2015) != i)]}
rowSums(AllPWC2015[1:177,])
plot(rowSums(AllPWC2015[1:177,]));lines(lowess(rowSums(AllPWC2015[1:177,])));mtext(ncol(AllPWC2015))
for(i in difflist) {CandWC2015 <- CandWC2015[,which(colnames(CandWC2015) != i)]}
rowSums(CandWC2015[1:177,])
plot(rowSums(CandWC2015[1:177,]));lines(lowess(rowSums(CandWC2015[1:177,])));mtext(ncol(CandWC2015))
for(i in difflist) {AllWC2015 <- AllWC2015[,which(colnames(AllWC2015) != i)]}
rowSums(AllWC2015[1:177,])
plot(rowSums(AllWC2015[1:177,]));lines(lowess(rowSums(AllWC2015[1:177,])));mtext(ncol(AllWC2015))
par(mfrow=c(3,1))
plot(lowess(rowSums(AllPWC2015[1:177,])),type="l",col="red");mtext(ncol(AllPWC2015))
plot(lowess(rowSums(CandWC2015[1:177,])),col="blue");mtext(ncol(CandWC2015))
plot(lowess(rowSums(AllWC2015[1:177,])));mtext(ncol(AllWC2015))
par(mfrow=c(1,1))
# Some analysis on the vote
# rowSums
# rowSums(AllPWC2015[1:177,])
# rowSums(AllWC2015[1:177,])
# cbind(PID,rowSums(AllWC2015[1:177,]))
# cbind(PID,"AGGR43"=rowSums(AllWC2015[1:177,]))
# AGGR43 <- cbind(PID,"AGGR43"=rowSums(AllWC2015[1:177,]))
AGGR43 <- as.data.frame(cbind(PID,"AGGR43"=rowSums(AllWC2015[1:177,])))
#arrange(AGGR43,desc(AGGR43))
colnames(m2) <- c("PID","Total_Registered","Good","PCT")
merge(AGGR43,m2,by="PID")
arrange(merge(AGGR43,m2,by="PID"),desc(AGGR43))
a1 <- arrange(merge(AGGR43,m2,by="PID"),desc(AGGR43))
#a1
par(mfrow=c(4,1))
with(a1,barplot(AGGR43,names.arg=PID,las=2,cex.names=.75,col="red"))
with(a1,barplot(Good,names.arg=PID,las=2,cex.names=.75,col="blue"))
with(a1,barplot(Total_Registered,names.arg=PID,las=2,cex.names=.75,col="brown"))
with(a1,barplot(PCT,names.arg=PID,las=2,cex.names=.75,col="green"))
par(mfrow=c(1,1))
# Graphs
with(LG2,plot(diff1 ~ diff2),cex=1.5);with(LG2,lines(lowess(diff1 ~ diff2),cex=1.5,col="red"));
abline(h=0,col="blue");
abline(v=0,col="red")
mtext("By Precinct: Vertical = Louws - Gilfilen ~ Horizontal = Jail_Yes - Jail_No",cex=1.5)
# Eventually this gets us:
# "diff1" = Louws - Gilfilen
# "diff2" = WC_1y - WC_1n
# "diff3"= diff1 - diff2
# "diff4"= (Louws + Gilfilen) - (WC_1y + WC_1n)
# "PCT1"= Gilfilen/(Louws + Gilfilen)
# "PCT2"= WC_1y/(WC_1y + WC_1n)
# LG1 <- subset(AllWC2015,select=c(PID,Louws,Gilfilen,WC_1y,WC_1n))
# a1_LG1 <- merge(a1,LG1,by="PID")
# LG2 <- as.data.frame(with(LG1,cbind(PID,"diff1" = Louws - Gilfilen,"diff2" = WC_1y - WC_1n)))
# a1_LG1_LG2 <- merge(a1_LG1,LG2,by="PID")
# a1_LG1_LG2 <- with(a1_LG1_LG2,cbind(a1_LG1_LG2, "diff3"= diff1 - diff2))
# a1_LG1_LG2 <- with(a1_LG1_LG2,cbind(a1_LG1_LG2, "diff4"= (Louws + Gilfilen) - (WC_1y + WC_1n)))
# a1_LG1_LG2 <- with(a1_LG1_LG2,cbind(a1_LG1_LG2, "PCT1"= Gilfilen/(Louws + Gilfilen), "PCT2"= WC_1y/(WC_1y + WC_1n))))
cat('
PID AGGR43 Total_Registered Good PCT Louws Gilfilen WC_1y WC_1n diff1 diff2 diff3 diff4 PCT1 PCT2
1 133 6036 1069 315 0.2947 218 77 115 170 141 -55 196 10 0.26102 0.4035
2 137 6747 1064 357 0.3355 227 100 136 181 127 -45 172 10 0.30581 0.4290
')
LG1 <- subset(AllWC2015,select=c(PID,Louws,Gilfilen,WC_1y,WC_1n))
head(LG1,10)
with(LG1,cor(Louws,WC_1n))
with(LG1,cor(Louws,WC_1y))
with(LG1,cor(Gilfilen,WC_1n))
with(LG1,cor(Gilfilen,WC_1y))
LG2 <- as.data.frame(with(LG1,cbind(PID,"diff1" = Louws - Gilfilen,"diff2" = WC_1y - WC_1n)))
a1_LG1 <- merge(a1,LG1,by="PID")
a1_LG1_LG2 <- merge(a1_LG1,LG2,by="PID")
with(a1_LG1,cor(Louws,Total_Registered))
with(a1_LG1,cor(Louws,AGGR43))
with(a1_LG1,cor(Louws,Good))
with(a1_LG1,cor(Gilfilen,Total_Registered))
with(a1_LG1,cor(Gilfilen,AGGR43))
with(a1_LG1,cor(Gilfilen,Good))
cat('
head(a1_LG1_LG2,20)
PID AGGR43 Total_Registered Good PCT Louws Gilfilen WC_1y WC_1n diff1 diff2
1 101 7151 919 373 0.4059 168 145 180 169 23 11
2 102 6116 627 306 0.4880 189 78 178 119 111 59
3 103 8219 709 416 0.5867 269 98 239 161 171 78
4 104 4982 439 251 0.5718 174 48 136 107 126 29
5 105 3582 403 180 0.4467 102 54 94 77 48 17
6 106 5337 788 269 0.3414 155 79 156 105 76 51
7 107 8338 960 417 0.4344 262 95 229 174 167 55
8 108 8047 1056 401 0.3797 234 123 220 169 111 51
9 110 6471 719 328 0.4562 226 67 185 117 159 68
10 111 7337 820 362 0.4415 218 99 170 178 119 -8
11 112 3750 396 187 0.4722 121 43 98 83 78 15
12 113 7011 671 347 0.5171 253 63 188 152 190 36
13 114 4137 467 205 0.4390 122 58 90 107 64 -17
14 115 8430 854 418 0.4895 276 91 228 176 185 52
15 116 5396 499 262 0.5251 212 32 151 98 180 53
16 117 6533 560 322 0.5750 269 33 189 127 236 62
17 118 8965 929 448 0.4822 338 83 232 206 255 26
18 119 4423 443 219 0.4944 143 57 109 98 86 11
19 120 7399 736 362 0.4918 242 80 191 161 162 30
20 121 5909 553 292 0.5280 192 72 155 130 120 25
')
with(a1_LG1_LG2,cor(AGGR43,diff1))
with(a1_LG1_LG2,cor(Total_Registered,diff1))
with(a1_LG1_LG2,cor(Good,diff1))
with(a1_LG1_LG2,cor(AGGR43,diff2))
with(a1_LG1_LG2,cor(Total_Registered,diff2))
with(a1_LG1_LG2,cor(Good,diff2))
a1_LG1_LG2 <- with(a1_LG1_LG2,cbind(a1_LG1_LG2, "diff3"= diff1 - diff2))
a1_LG1_LG2 <- with(a1_LG1_LG2,cbind(a1_LG1_LG2, "diff4"= (Louws + Gilfilen) - (WC_1y + WC_1n)))
a1_LG1_LG2 <- with(a1_LG1_LG2,cbind(a1_LG1_LG2, "PCT1"= Gilfilen/(Louws + Gilfilen), "PCT2"= WC_1y/(WC_1y + WC_1n))))
with(a1_LG1_LG2,cor(AGGR43,diff3))
with(a1_LG1_LG2,cor(Total_Registered,diff3))
with(a1_LG1_LG2,cor(Good,diff3))
with(a1_LG1_LG2,cor(AGGR43,diff3))
with(a1_LG1_LG2,cor(Total_Registered,diff3))
with(a1_LG1_LG2,cor(Good,diff3))
cat(')
arrange(a1_LG1_LG2,desc(diff3))
PID AGGR43 Total_Registered Good PCT Louws Gilfilen WC_1y WC_1n diff1 diff2 diff3
1 250 12601 961 632 0.6576 365 164 213 381 201 -168 369
2 144 10815 865 535 0.6185 471 29 346 175 442 171 271
3 145 10084 908 510 0.5617 401 73 278 212 328 66 262
4 215 8818 801 442 0.5518 222 144 122 306 78 -184 262
5 222 11299 964 571 0.5923 269 191 180 360 78 -180 258
6 180 8342 625 417 0.6672 266 101 154 243 165 -89 254
7 140 11611 1147 568 0.4952 464 67 350 203 397 147 250
8 210 10561 877 534 0.6089 253 182 158 337 71 -179 250
9 266 8855 750 439 0.5853 263 108 162 252 155 -90 245
10 251 8691 686 440 0.6414 252 118 150 259 134 -109 243
11 240 9041 860 447 0.5198 278 110 176 250 168 -74 242
12 138 9082 724 462 0.6381 267 141 161 274 126 -113 239
13 146 10195 1019 504 0.4946 380 91 271 219 289 52 237
14 169 11490 1095 584 0.5333 322 171 235 319 151 -84 235
15 171 8870 867 447 0.5156 282 92 191 235 190 -44 234
16 118 8965 929 448 0.4822 338 83 232 206 255 26 229
17 239 8965 966 446 0.4617 273 112 180 246 161 -66 227
18 141 9932 933 491 0.5263 358 93 257 215 265 42 223
19 261 7709 577 387 0.6707 225 112 126 232 113 -106 219
20 258 8653 892 440 0.4933 173 170 96 311 3 -215 218
21 209 9162 793 470 0.5927 246 137 167 275 109 -108 217
22 232 8300 808 422 0.5223 258 86 178 222 172 -44 216
23 213 10121 994 519 0.5221 264 146 195 292 118 -97 215
24 249 8938 901 442 0.4906 268 108 185 240 160 -55 215
25 501 8441 765 421 0.5503 271 98 181 220 173 -39 212
....
152 230 4585 810 220 0.2716 100 87 84 129 13 -45 58
153 224 3095 343 148 0.4315 59 60 41 97 -1 -56 55
154 401 4767 568 227 0.3996 158 49 131 76 109 55 54
155 102 6116 627 306 0.4880 189 78 178 119 111 59 52
156 504 4507 449 212 0.4722 116 63 103 101 53 2 51
157 167 1870 134 90 0.6716 50 20 33 53 30 -20 50
158 236 3998 357 193 0.5406 114 55 96 86 59 10 49
159 202 5554 607 277 0.4563 163 79 151 105 84 46 38
160 301 7955 974 386 0.3963 240 108 237 140 132 97 35
161 302 9107 1098 454 0.4135 242 145 248 186 97 62 35
162 304 2755 315 126 0.4000 76 35 63 57 41 6 35
163 179 2453 193 113 0.5855 69 33 57 55 36 2 34
164 105 3582 403 180 0.4467 102 54 94 77 48 17 31
165 218 4827 746 249 0.3338 126 71 129 104 55 25 30
166 106 5337 788 269 0.3414 155 79 156 105 76 51 25
167 204 3851 598 182 0.3043 99 65 95 83 34 12 22
168 182 3533 1186 395 0.3331 0 0 178 199 0 -21 21
169 159 2533 268 122 0.4552 76 32 72 48 44 24 20
170 253 5436 1251 275 0.2198 99 111 113 141 -12 -28 16
171 303 9783 790 480 0.6076 299 100 330 144 199 186 13
172 101 7151 919 373 0.4059 168 145 180 169 23 11 12
173 267 1079 99 41 0.4141 15 18 14 25 -3 -11 8
174 268 605 54 18 0.3333 6 10 5 12 -4 -7 3
175 183 228 32 5 0.1562 0 0 2 3 0 -1 1
176 252 1678 541 75 0.1386 17 37 29 37 -20 -8 -12
177 245 3750 1400 190 0.1357 40 93 75 93 -53 -18 -35
')
a2 <- arrange(a1_LG1_LG2,desc(PCT2))
write.csv(a2,"a2.csv",row.names=FALSE)
cat('
arrange(a1_LG1_LG2,desc(PCT2))
PID AGGR43 Total_Registered Good PCT Louws Gilfilen WC_1y WC_1n diff1 diff2 diff3 diff4 PCT1 PCT2
1 605 5472 479 250 0.5219 209 21 173 70 188 103 85 -13 0.09130 0.7119
2 608 8116 751 386 0.5140 313 51 257 111 262 146 116 -4 0.14011 0.6984
3 602 9346 858 455 0.5303 374 46 305 133 328 172 156 -18 0.10952 0.6963
4 303 9783 790 480 0.6076 299 100 330 144 199 186 13 -75 0.25063 0.6962
5 606 8974 827 430 0.5200 340 59 285 127 281 158 123 -13 0.14787 0.6917
6 610 10874 881 524 0.5948 430 63 344 157 367 187 180 -8 0.12779 0.6866
7 601 13368 1058 661 0.6248 511 82 423 202 429 221 208 -32 0.13828 0.6768
8 611 6576 605 308 0.5091 242 37 197 95 205 102 103 -13 0.13262 0.6747
9 604 8602 858 402 0.4685 321 58 265 128 263 137 126 -14 0.15303 0.6743
10 609 9323 927 449 0.4844 368 54 286 141 314 145 169 -5 0.12796 0.6698
...
167 225 8360 1104 418 0.3786 174 157 126 276 17 -150 167 -71 0.47432 0.3134
168 227 7574 890 377 0.4236 162 143 108 247 19 -139 158 -50 0.46885 0.3042
169 246 6357 801 321 0.4007 129 119 90 206 10 -116 126 -48 0.47984 0.3041
170 224 3095 343 148 0.4315 59 60 41 97 -1 -56 55 -19 0.50420 0.2971
171 268 605 54 18 0.3333 6 10 5 12 -4 -7 3 -1 0.62500 0.2941
172 215 8818 801 442 0.5518 222 144 122 306 78 -184 262 -62 0.39344 0.2850
173 247 4869 905 241 0.2663 88 96 64 165 -8 -101 93 -45 0.52174 0.2795
174 226 4284 667 213 0.3193 111 61 55 142 50 -87 137 -25 0.35465 0.2792
175 257 4829 680 244 0.3588 103 82 62 161 21 -99 120 -38 0.44324 0.2780
176 258 8653 892 440 0.4933 173 170 96 311 3 -215 218 -64 0.49563 0.2359
177 228 6454 832 327 0.3930 138 115 59 242 23 -183 206 -48 0.45455 0.1960
')
with(a1_LG1_LG2,cor(PCT2,PCT1,use="na.or.complete"))
with(a1_LG1_LG2,cor(PCT1,(1 - PCT2),use="na.or.complete"))
with(a1_LG1_LG2,cor(PCT1,PCT2,use="na.or.complete"))
with(a1_LG1_LG2,cor(PCT1,(1 - PCT2),use="na.or.complete"))
# Graphs
with(LG2,plot(diff1 ~ diff2),cex=1.5);with(LG2,lines(lowess(diff1 ~ diff2),cex=1.5,col="red"));
abline(h=0,col="blue");
abline(v=0,col="red")
mtext("By Precinct: Vertical = Louws - Gilfilen ~ Horizontal = Jail_Yes - Jail_No",cex=1.5)
# Working with a1
# AGGR43 <- cbind(PID,"AGGR43"=rowSums(AllWC2015[1:177,]))
AGGR43 <- as.data.frame(cbind(PID,"AGGR43"=rowSums(AllWC2015[1:177,])))
#arrange(AGGR43,desc(AGGR43))
colnames(m2) <- c("PID","Total_Registered","Good","PCT")
merge(AGGR43,m2,by="PID")
arrange(merge(AGGR43,m2,by="PID"),desc(AGGR43))
a1 <- arrange(merge(AGGR43,m2,by="PID"),desc(AGGR43))
with(a1,cor(AGGR43,PCT))
names(m2)
names(m2) <- c("PID","Total_Registered","Good","PCT")
a1 <- arrange(merge(AGGR43,m2,by="PID"),desc(AGGR43))
with(a1,cor(AGGR43,PCT))
a1
with(a1,cov(AGGR43,PCT))
with(a1,var(AGGR43,PCT))
with(a1[1:30,],cor(AGGR43,PCT))
with(a1[,1:30],cor(AGGR43,PCT))
with(a1[1:60,],cor(AGGR43,PCT))
with(a1[1:100,],cor(AGGR43,PCT))
with(a1[1:150,],cor(AGGR43,PCT))
a1
with(a1[1:150,],cor(AGGR43,Total_Registered))
with(a1[1:30,],cor(AGGR43,Total_Registered))
with(a1,cor(AGGR43,Total_Registered))
with(a1,cbind(a1,"TR_AG"=Total_Registered/AGGR43))
arrange(with(a1,cbind(a1,"TR_AG"=Total_Registered/AGGR43)),desc(TR_AG))
arrange(with(a1,cbind(a1,"Good_AG"=Good/AGGR43)),desc(Good_AG))
a1 <- arrange(with(a1,cbind(a1,"Good_AG"=Good/AGGR43)),desc(PID))
with(a1,plot(PID,AGGR43))
with(a1,plot(PID ~ Good_AG))
with(a1,plot(PID,Good_AG))
with(a1,plot(PID,TR_AG))
names(a1)
a1 <- arrange(with(a1,cbind(a1,"TR_AG"=Total_Registered/AGGR43)),desc(PID))
with(a1,plot(PID,TR_AG))
arrange(a1,desc(AGGR43)))
a1 <- arrange(a1,desc(AGGR43))
with(a1,cor(AGGR43,PCT))
with(a1[1:15,],cor(AGGR43,PCT))
with(a1,plot(PID,AGGR43));with(a1,lines(lowess(AGGR43 ~ PID),col="red"))
mtext("'Power' of Precincts with Trend Line",cex=1.25)
with(a1,plot(PID,Good_AG));with(a1,lines(lowess((Good/AGGR43) ~ PID),col="red"))
mtext("Good / AGGR43 with Trend Line",cex=1.25)
with(a1,plot(PID,Good_AG));with(a1,lines(lowess((Good/AGGR43) ~ PID),col="red"))
mtext("Good / AGGR43 with Trend Line",cex=1.25)
with(a1,cor(Total_Registered,PCT))
with(a1,cor(Good,PCT))
with(a1,cor(Good,AGGR43))
with(a1,cor(Total_Registered,AGGR43))
with(a1,cor(Total_Registered,PCT))
with(a1,cor(Good,PCT))
with(a1[1:30,],cor(Good,AGGR43))
with(a1[1:30,],cor(Total_Registered,AGGR43))
No comments:
Post a Comment