-
-
Save kkprakasa/fba446cc3ce958cb1e3a39c13346b4f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#sae | |
wilayah<-podes[,c(1:9)] | |
head(wilayah) | |
str_to_lower(wilayah$R103N) | |
str_replace(str_to_lower(wilayah$R103N),' ','') | |
wilayah$kec<-str_replace(str_to_lower(wilayah$R103N),' ','') | |
sek_desa<-sek_desa | |
sekdesa<-sek_desa | |
sekdesa$kec <- gsub(' ','',str_replace(str_to_lower(sekdesa$Kecamatan),'kec. ','')) | |
aggregate(R104 ~ R103N, wilayah[ !duplicated(wilayah$R103N),], FUN = function(x){ NROW(x)}) | |
ggscatter(test.2, x = "xCap", y = "Minimarket.swalayan", | |
add = "reg.line", conf.int = TRUE, | |
cor.coef = TRUE, cor.method = "pearson", | |
xlab = "Toko", ylab = "rata exp_cap") | |
####################### Aggregate menggunakan fungsi ### | |
data("mtcars") | |
library(plyr) | |
ddply(mtcars,"cyl",function(x) cor(x$hp,x$wt)) | |
################################################ | |
############################################### | |
tDesa <- read.csv('jumlah sarana ekonomi desa.xlsx - Sheet1.csv', header=T) | |
kab<-aggregate(.~Id.Prov+Provinsi+Id.Kab+Kabupaten, tDesa[,c(3:6,11:21)], sum) | |
kab <- kab[ order(kab$Id.Kab),] | |
expcap<-read.dbf('../Documents/datalab/SUSENAS/SUSENAS Maret 2018/Data kor 2018/kor18ind_revisi_diseminasi.dbf')[,c(1,2,171,172)] | |
expcap$R102 <- paste0(expcap$R101,sprintf('%02d',expcap$R102)) | |
expcap$mul <- expcap$FWT * expcap$EXP_CAP | |
exKab<-merge( | |
aggregate(mul ~ R101+R102, expcap, sum), | |
aggregate(FWT ~ R101+R102, expcap, sum), | |
by=c('R101','R102')) | |
# merge variance sample expcap dengan exKab | |
exKab<-merge( | |
exKab, | |
ddply(expcap,c('R101','R102'),function(x) var(x$EXP_CAP)), | |
by=c('R101','R102')) | |
exKab$xCap <- exKab$mul/exKab$FWT | |
exPro<-merge( | |
aggregate(mul ~ R101, expcap, sum), | |
aggregate(FWT ~ R101, expcap, sum), | |
by=c('R101')) | |
# uji dengan pengguna listrik rumahtangga | |
Dmukim <- read.csv('Indonesia_podes_2018_pemukiman.csv') | |
Dmukim$R102 <- paste0(Dmukim$R101,sprintf('%02d',Dmukim$R102)) | |
Kmukim <- aggregate( .~ R101+R101N+R102+R102N, Dmukim[,c(1:4,9:11)],sum) | |
Kmukim <- Kmukim[ order(Kmukim$R102),] | |
Kmukim$Tot <- rowSums(Kmukim[,c(5:7)]) | |
Kmukim$totA12 <- rowSums(Kmukim[,c(5,6)]) | |
Kmukim$percent <- 100*Kmukim$totA12/Kmukim$Tot | |
test.3<-merge(exKab[ exKab$R101 %in% c(11:36),], Kmukim, by.x=c('R101','R102')) | |
df <- data.frame() | |
for(i in unique(test.3$R101)){ | |
res<-cor.test(test.3[test.3$R101 == i,]$xCap,test.3[test.3$R101 == i,]$percent) | |
test <- ifelse(res$p.value < 0.05, paste0('ok'),paste0('not-ok')) | |
df<-rbind(df,data.frame(R101=i, koef.cor = as.vector(res$estimate), p.value=res$p.value, test=test)) | |
} | |
test.2<-merge(exKab[ exKab$R101 %in% c(11:36),], kab, by.x=c('R101','R102'), by.y=c('Id.Prov','Id.Kab')) | |
c("Kelompok.pertokoan","Minimarket.swalayan","Pasar.dengan.bangunan.permanen","Pasar.dengan.bangunan.semi.permanen","Pasar.tanpa.bangunan","Penginapan","Restoran.rumah.makan","Toko.warung.kelontong","Toko.warung.kelontong.yang.menjual.bahan.pangan","Warung.kedai.makanan.minuman") | |
df <- data.frame() | |
for( j in colnames(test.2[8:18]) ){ | |
for( i in c("11","12","13","14","15","16","17","18","19","21","31","32","33","34","35","36")){ | |
l <- cor(test.2[ test.2$R101 == i,]$xCap,test.2[ test.2$R101 == i,j]) | |
df<-rbind(df,data.frame(R101=i, cor.coef=l, param=j)) | |
} | |
} | |
df.1 <- data.frame() | |
for( j in colnames(test.2[8:18]) ){ | |
for( i in unique(test.2$R101)){ | |
l <- cor(test.2[ test.2$R101 == i,]$xCap,test.2[ test.2$R101 == i,j]) | |
df.1<-rbind(df,data.frame(R101=i, cor.coef=l, param=j)) | |
} | |
} | |
lm(xCap ~ 0+Hotel, data=test.2[test.2$R101,]) | |
#log | |
for( i in c("11","12","13","14","15","16","17","18","19","21","31","32","33","34","35","36")){ | |
l <- cor(log(test.2[ test.2$R101 == i,]$xCap),test.2[test.2$R101 == i,]$Minimarket.swalayan) | |
print(l) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment