Laporan 1 Praktikum Analisis Statistik Spatial - Tugas Satria June Adwendi
Link Rpubs : klik disini
Praktikum Pertemuan 1 - Pengenalan Struktur R untuk Data Spasial
Instaling R and R studio
If you do not have R and RStudio on your computer, proceed as follows: 1. Download base R for your operating system from https://cran.r-project.org. 2. Install it on your system. 3. Download RStudio desktop version for your operating system from https://www.rstudio.com/products/RStudio/. 4. Install it on your system.
Installing Packages
Jalankan R Jika terhubung ke internet: >install.packages(“namapackage”)
Contoh:
#install.packages(c("sp", "gstat"))
Jika sudah download binary (*.zip):
install.packages(“drive:/namafile.zip”,repos=NULL)
Contoh:
install.packages(“C:/Program Files/R/nama file.zip”,repos=NULL)
atau melalui menu: Packages > Install packages(s) from local files…
Loading Interacton With R
Task 1: Compute the number of radians in one circular degree.
In this document, input and output are shown as follows
2 * pi/360
## [1] 0.01745329
Task 2: Load the sp and gstat packages into the workspace.
You can load these in RStudio by checking the small checkbox next to the packages name in the Packages tab; see Figure 3.
You can also load these this from the R console with the library function. This loads a packages into the R workspace:
library(sp)
## Warning: package 'sp' was built under R version 4.1.1
library(gstat)
## Warning: package 'gstat' was built under R version 4.1.1
Loading Meuse Dataset
Task 3: Load the meuse dataset into the workspace.
The data function loads a dataset. We show the contents of the workspace before and after with the ls() function:
ls()
## character(0)
data(meuse)
ls()
## [1] "meuse"
Task 4: Examine the structure of the meuse dataset
The str() function shows the structure of an R object:
str(meuse)
## 'data.frame': 155 obs. of 14 variables:
## $ x : num 181072 181025 181165 181298 181307 ...
## $ y : num 333611 333558 333537 333484 333330 ...
## $ cadmium: num 11.7 8.6 6.5 2.6 2.8 3 3.2 2.8 2.4 1.6 ...
## $ copper : num 85 81 68 81 48 61 31 29 37 24 ...
## $ lead : num 299 277 199 116 117 137 132 150 133 80 ...
## $ zinc : num 1022 1141 640 257 269 ...
## $ elev : num 7.91 6.98 7.8 7.66 7.48 ...
## $ dist : num 0.00136 0.01222 0.10303 0.19009 0.27709 ...
## $ om : num 13.6 14 13 8 8.7 7.8 9.2 9.5 10.6 6.3 ...
## $ ffreq : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
## $ soil : Factor w/ 3 levels "1","2","3": 1 1 1 2 2 2 2 1 1 2 ...
## $ lime : Factor w/ 2 levels "0","1": 2 2 2 1 1 1 1 1 1 1 ...
## $ landuse: Factor w/ 15 levels "Aa","Ab","Ag",..: 4 4 4 11 4 11 4 2 2 15 ...
## $ dist.m : num 50 30 150 270 380 470 240 120 240 420 ...
Description of meuse dataset
help(meuse)
## starting httpd help server ... done
Description This data set gives locations and topsoil heavy metal concentrations, along with a number of soil and landscape variables at the observation locations, collected in a flood plain of the river Meuse, near the village of Stein (NL). Heavy metal concentrations are from composite samples of an area of approximately 15 m x 15 m.
Usage data(meuse) Format This data frame contains the following columns:
x a numeric vector; Easting (m) in Rijksdriehoek (RDH) (Netherlands topographical) map coordinates
y a numeric vector; Northing (m) in RDH coordinates
Introduction to Spatial Data Type
Types of spatial Data
Plot the data
Poin
coordinates(meuse) <- c("x", "y")
plot(meuse)
title("points")
Polygons
data(meuse.riv)
.1st <- list(Polygons(list(Polygon(meuse.riv)),"meuse.riv"))
meuse<- SpatialPolygons(meuse.1st)
meuse.sr plot(meuse.sr, col = "grey")
title("polygons")
Grid
data(meuse.grid)
coordinates(meuse.grid) <- c("x", "y")
<- as(meuse.grid, "SpatialPixels")
meuse.grid image(meuse.grid, col = "grey")
title("grid")
image(meuse.grid, col = "lightgrey")
plot(meuse.sr, col = "grey", add = TRUE)
plot(meuse,add = TRUE)
Raster
<- system.file("external/test.grd", package="raster")
f library(raster)
## Warning: package 'raster' was built under R version 4.1.1
<- raster(f)
r plot(r)
image(meuse.grid, col = "lightblue")
plot(r, add=TRUE)
plot(meuse.sr, col = "blue", add = TRUE)
plot(meuse,add = TRUE)
External Data Input
Selain menggunakan data yang berada di dalam package R, bisa memasukkan data dari luar package.
data pertumbuhan penduduk.
<- read.csv('http://bit.ly/Popgrowth2000', header=T, sep=',')
datapop datapop
## City Country Latitude Longitude
## 1 Abidjan Cote d'Ivoire 5.309660 -4.012660
## 2 Adana Turkey 37.001670 35.328890
## 3 Addis Ababa Ethiopia 9.024970 38.746890
## 4 Adelaide Australia -34.928660 138.598630
## 5 Ahmadabad India 23.039568 72.566004
## 6 Aleppo Syria 36.216700 37.166700
## 7 Alexandria Egypt 31.200092 29.918739
## 8 Algiers Algeria 36.752500 3.041970
## 9 Almaty Kazakhstan 43.255058 76.912628
## 10 Amman Jordan 31.955220 35.945030
## 11 Ankara Turkey 39.919870 32.854270
## 12 Anshan China 41.116700 122.983300
## 13 Baghdad Iraq 33.340580 44.400880
## 14 Baku Azerbaijan 40.377670 49.892010
## 15 Bandung Indonesia -6.914744 107.609814
## 16 Bangalore India 12.971940 77.593690
## 17 Bangkok Thailand 13.753980 100.501440
## 18 Baotou China 40.657440 109.840540
## 19 Barcelona Spain 41.388790 2.158990
## 20 Barranquilla Columbia 10.968540 -74.781320
## 21 Bauru Brazil -22.314700 -49.060600
## 22 Beijing China 39.907500 116.397230
## 23 Belem Brazil -1.455800 -48.503900
## 24 Belgrade Serbia 44.804010 20.465130
## 25 Belo Horizonte Brazil -19.920830 -43.937780
## 26 Berlin Germany 52.524370 13.410530
## 27 Bhopal India 23.250000 77.416700
## 28 Birmingham United Kindgom 52.481420 -1.899830
## 29 Bogor Indonesia -6.600000 106.800000
## 30 Bogota Columbia 4.598056 -74.075833
## 31 Brasilia Brazil -15.779720 -47.929720
## 32 Brisbane Australia -27.467940 153.028090
## 33 Brussel Belgium 50.850450 4.348780
## 34 Bucharest Romania 44.432250 26.106260
## 35 Budapest Hungary 47.498010 19.039910
## 36 Buenos Aires Argentina -34.613150 -58.377230
## 37 Bursa Turkey 40.192660 29.084030
## 38 Busan Republic of Korea 35.179550 129.075600
## 39 Cairo Egypt 30.062630 31.249670
## 40 Calcutta India 22.562630 88.363040
## 41 Cali Columbia 3.437220 -76.522500
## 42 Caloocan City Philippines 14.650000 120.970000
## 43 Caracas Venezuela 10.488010 -66.879190
## 44 Casablanca Morocco 33.588310 -7.611380
## 45 Changchun China 43.900000 125.200000
## 46 Changde China 29.033300 111.683300
## 47 Changsha China 28.196111 112.972222
## 48 Changshu China 31.665000 120.822000
## 49 Changzhou China 31.773580 119.954010
## 50 Chelyabinsk Russian Federation 55.154020 61.429150
## 51 Chengdu China 30.666670 104.066670
## 52 Chicago United States of America 41.850030 -87.650100
## 53 Chittagong Bangladesh 22.338400 91.831680
## 54 Chongqing China 29.563010 106.551557
## 55 Cirebon Indonesia -6.716700 108.566700
## 56 Cordoba Argentina -31.413500 -64.181050
## 57 Curitiba Brazil -25.427800 -49.273100
## 58 Daegu Republic of Korea 35.871440 128.601400
## 59 Daejeon Republic of Korea 36.350410 127.384500
## 60 Dakar Senegal 14.693700 -17.444060
## 61 Dalian China 38.920800 121.639200
## 62 Dallas United States of America 32.780140 -96.800500
## 63 Damascus Syria 33.510200 36.291280
## 64 Danzhou China 19.500000 109.583300
## 65 Daqing China 46.583300 125.000000
## 66 Dar-es-Salaam Tanzania -6.822921 39.269661
## 67 Datong China 40.083333 113.300000
## 68 Davao Philippines 7.066700 125.600000
## 69 Delhi India 28.653810 77.228970
## 70 Dhaka Bangladesh 23.709921 90.407143
## 71 Dingzhou China 38.516700 114.983300
## 72 Dnipropetrovsk Ukraine 48.464717 35.046183
## 73 Donetsk Ukraine 48.015883 37.802850
## 74 Dongguan China 23.033300 113.716700
## 75 Dongtai China 32.795000 120.519000
## 76 Ecatepec Mexico 19.609722 -99.060000
## 77 Esfahan Iran 32.651389 51.679192
## 78 Faisalabad Pakistan 31.416670 73.083330
## 79 Fangchenggang China 21.600000 108.300000
## 80 Fortaleza Brazil -3.717220 -38.543060
## 81 Fukuoka Japan 33.591389 130.414722
## 82 Fushun China 41.855830 123.923330
## 83 Fuzhou China 26.076111 119.306389
## 84 Giza Egypt 30.016700 31.216700
## 85 Goiania Brazil -16.678610 -49.253890
## 86 Guangzhou China 23.116670 113.250000
## 87 Guarulhos Brazil -23.466700 -46.533300
## 88 Guatemala City Guatemala 14.640720 -90.513270
## 89 Guayaquil Ecuador -2.181940 -79.891670
## 90 Guiyang China 26.650000 106.633300
## 91 Gujranwala Pakistan 32.150000 74.183300
## 92 Gwangju Republic of Korea 35.166667 126.916667
## 93 Haicheng China 40.883300 122.683300
## 94 Hamburg Germany 53.575320 10.015340
## 95 Handan China 36.600000 114.483300
## 96 Hangzhou China 30.250000 120.166700
## 97 Hanoi Vietnam 21.033333 105.850000
## 98 Harare Zimbabwe -17.863900 31.029700
## 99 Harbin China 45.750000 126.650000
## 100 Havana Cuba 23.133020 -82.383040
## 101 Hefei China 31.866667 117.283333
## 102 Heze China 35.233300 115.433300
## 103 Hiroshima Japan 34.396775 132.460017
## 104 Hong Kong China 22.285520 114.157690
## 105 Houston United States of America 29.760190 -95.369400
## 106 Huadian China 42.950000 126.733300
## 107 Huainan China 32.626390 116.996940
## 108 Huzhou China 30.866700 120.100000
## 109 Hyderabad India 17.384050 78.456360
## 110 Hyderabad Pakistan 25.379167 68.368333
## 111 Incheon Republic of Korea 37.456256 126.705206
## 112 Indore India 22.717920 75.833300
## 113 Istanbul Turkey 41.005275 28.976944
## 114 Jaipur India 26.919620 75.787810
## 115 Jakarta Indonesia -6.214620 106.845130
## 116 Jeddah Saudi Arabia 21.543333 39.172778
## 117 Jiangyin China 31.839000 120.295000
## 118 Jilin China 43.896536 125.325990
## 119 Jimo China 36.383300 120.466700
## 120 Jinan China 36.650997 117.120497
## 121 Jingmen China 31.043600 112.200800
## 122 Kabul Afghanistan 34.533300 69.166700
## 123 Kanpur India 26.447800 80.346270
## 124 Kaohsiung Taiwan 22.616260 120.313330
## 125 Karachi Pakistan 24.905600 67.082200
## 126 Kawasaki Japan 35.516700 139.700000
## 127 Kazan Russian Federation 55.790278 49.134722
## 128 Kediri Indonesia -7.816600 112.011900
## 129 Kharkov Ukraine 49.993500 36.230384
## 130 Kiev Ukraine 50.454660 30.523800
## 131 Kinshasa Congo -4.325000 15.322200
## 132 Kitakyushu Japan 33.833330 130.833330
## 133 Kobe Japan 34.691269 135.183072
## 134 Kuala Lumpur Malaysia 3.141200 101.686530
## 135 Kunming China 25.038890 102.718330
## 136 Kyoto Japan 35.021070 135.753850
## 137 La Matanza Partido Argentina -34.716700 -58.633300
## 138 Lagos Nigeria 6.524379 3.379206
## 139 Lahore Pakistan 31.549720 74.343610
## 140 Laiwu China 36.183300 117.666700
## 141 Lanzhou China 36.061089 103.834304
## 142 Leiyang China 26.400000 112.929000
## 143 Leshan China 29.552106 103.765568
## 144 Lianyuan China 27.692000 111.664000
## 145 Lima Peru -12.043180 -77.028240
## 146 Linyi China 35.050000 118.350000
## 147 London United Kingdom 51.511210 -0.119830
## 148 Los Angeles United States of America 34.052230 -118.244000
## 149 Lucknow India 26.839280 80.923130
## 150 Ludhiana India 30.900150 75.852290
## 151 Luoyang China 34.669700 112.442200
## 152 Lusaka Zambia -15.406690 28.287130
## 153 Macheng China 31.316700 115.100000
## 154 Madras India 13.087840 80.278470
## 155 Madrid Spain 40.416780 -3.703790
## 156 Magelang Indonesia -7.466700 110.216700
## 157 Manado Indonesia 1.493100 124.841300
## 158 Manaus Brazil -3.101940 -60.025000
## 159 Manila Philippines 14.580000 121.000000
## 160 Maputo Mozambique -25.966700 32.583300
## 161 Maracaibo Venezuela 10.631670 -71.640560
## 162 Mashhad Iran 36.300000 59.600000
## 163 Medan Indonesia 3.583300 98.666700
## 164 Medellin Columbia 6.251840 -75.563590
## 165 Melbourne Australia -37.814000 144.963320
## 166 Mexico City Mexico 19.428470 -99.127700
## 167 Milan Italy 45.465450 9.198786
## 168 Minsk Belarus 53.900000 27.566670
## 169 Monterrey Mexico 25.666700 -100.300000
## 170 Montevideo Uruguay -34.817311 -56.158866
## 171 Montreal Canada 45.508840 -73.587800
## 172 Moscow Russian Federation 55.752220 37.615560
## 173 Multan Pakistan 30.195560 71.475280
## 174 Mumbai India 19.072830 72.882610
## 175 Munich Germany 48.136740 11.576760
## 176 Nagoya Japan 35.181447 136.906397
## 177 Nagpur India 21.150000 79.100000
## 178 Nairobi Kenya -1.283330 36.816670
## 179 Nanchang China 28.683330 115.883330
## 180 Nanjing China 32.050000 118.766700
## 181 Nanning China 22.816670 108.316670
## 182 Naples Italy 40.851780 14.268120
## 183 Neijiang China 29.583300 105.066700
## 184 New York United States of America 40.714350 -74.006000
## 185 Nezahualcoyotl Mexico 19.400000 -98.988889
## 186 Ningbo China 29.866700 121.550000
## 187 Nizhniy Novgorod Russian Federation 56.326900 44.007500
## 188 Novosibirsk Russian Federation 55.041500 82.934600
## 189 Odessa Ukraine 46.477470 30.732620
## 190 Omdurman Sudan 15.644530 32.477730
## 191 Omsk Russian Federation 54.992440 73.368590
## 192 Oran Algeria 35.691110 -0.641670
## 193 Osaka Japan 34.693216 135.502082
## 194 Padang Indonesia -0.949240 100.354270
## 195 Palembang Indonesia -2.916730 104.745800
## 196 Paris France 48.856610 2.352222
## 197 Pekalongan Indonesia -6.888600 109.675300
## 198 Perm Russian Federation 58.013889 56.248889
## 199 Perth Australia -31.952240 115.861400
## 200 Philadelphia United States of America 39.950000 -75.166700
## 201 Phoenix United States of America 33.448380 -112.074143
## 202 Pingdu China 36.783300 119.955600
## 203 Pingxiang China 27.633300 113.850000
## 204 Porto Alegre Brazil -30.033100 -51.230000
## 205 Prague Czech Republic 50.088040 14.420760
## 206 Probolinggo Indonesia -7.750000 113.216700
## 207 Puebla Mexico 19.033333 -98.183333
## 208 Pune India 18.520430 73.856744
## 209 Pyongyang Dem. People's Republic of Korea 39.033850 125.754300
## 210 Qidong China 31.870000 121.703000
## 211 Qingdao China 36.067082 120.382640
## 212 Qinzhou China 21.950000 108.616700
## 213 Qiqihar China 47.350000 123.916700
## 214 Queimados Brazil -22.715800 -43.555000
## 215 Quezon City Philippines 14.633300 121.033300
## 216 Quito Ecuador -0.229850 -78.524950
## 217 Rabat Morocco 34.013250 -6.832550
## 218 Rawalpindi Pakistan 33.600700 73.067900
## 219 Recife Brazil -8.053890 -34.881100
## 220 Rio de Janeiro Brazil -22.902780 -43.207500
## 221 Riyadh Saudi Arabia 24.633300 46.716700
## 222 Rizhao China 35.415800 119.527100
## 223 Rome Italy 41.894740 12.483900
## 224 Rostov-on-Don Russian Federation 47.233300 39.413940
## 225 Ruian China 27.783300 120.625000
## 226 Saint Petersburg Russian Federation 59.894440 30.264170
## 227 Salvador Brazil -12.971110 -38.510830
## 228 Samara Russian Federation 53.202800 50.140800
## 229 San Antonio United States of America 29.424120 -98.493600
## 230 San Diego United States of America 32.715330 -117.157000
## 231 Santiago Chile -33.450000 -70.666667
## 232 Santo Domingo Dominican Republic 18.466700 -69.950000
## 233 Sao Paolo Brazil -23.547500 -46.636110
## 234 Sapporo Japan 43.064170 141.346940
## 235 Semarang Indonesia -6.993200 110.420300
## 236 Sendai Japan 38.266667 140.866667
## 237 Seoul Republic of Korea 37.568260 126.977830
## 238 Setif Algeria 36.183300 5.400000
## 239 Shanghai China 31.222220 121.458060
## 240 Shenyang China 41.792220 123.432780
## 241 Shijiazhuang China 38.042308 114.514861
## 242 Shiraz Iran 29.610310 52.531140
## 243 Singapore Singapore 1.289670 103.850070
## 244 Suining China 30.532847 105.592898
## 245 Suizhou China 31.683300 113.383300
## 246 Sukabumi Indonesia -6.919600 106.927200
## 247 Suqian China 33.933300 118.283300
## 248 Surabaya Indonesia -7.249170 112.750830
## 249 Surat India 21.195940 72.830230
## 250 Sydney Australia -33.867850 151.207320
## 251 Tabriz Iran 38.080000 46.291900
## 252 Taian China 36.200000 117.083300
## 253 Taipei Taiwan 25.047760 121.531850
## 254 Taiyuan China 37.870590 112.548879
## 255 Tangshan China 39.633330 118.183330
## 256 Tashkent Uzbekistan 41.264650 69.216270
## 257 Tbilisi Georgia 41.709975 44.792989
## 258 Tegal Indonesia -6.866700 109.133300
## 259 Tehran Iran 35.694390 51.421510
## 260 Tianjin China 39.142220 117.176670
## 261 Tianmen China 30.663337 113.166078
## 262 Tianshui China 34.579520 105.742380
## 263 Tokyo Japan 35.689500 139.691710
## 264 Tripoli Libya 32.876175 13.187508
## 265 Ufa Russian Federation 54.785170 56.045620
## 266 Urumqi China 43.825000 87.600000
## 267 Vadodara India 22.307310 73.181098
## 268 Valencia Spain 39.469908 -0.376289
## 269 Vienna Austria 48.208490 16.372080
## 270 Visakhapatnam India 17.688300 83.218600
## 271 Wafangdian China 39.631000 121.974000
## 272 Warsaw Poland 52.229770 21.011780
## 273 Weifang China 36.716700 119.100000
## 274 Wuhan China 30.583330 114.266670
## 275 Wuxi China 31.491170 120.311910
## 276 Xian China 34.341485 108.940404
## 277 Xiantao China 30.366700 113.450000
## 278 Xiaogan China 30.916700 113.900000
## 279 Xinghua China 32.930000 119.830000
## 280 Xingtai China 37.063100 114.494000
## 281 Yangcheng China 34.455278 113.025278
## 282 Yangon Myanmar 16.805280 96.156110
## 283 Yekaterinburg Russian Federation 56.833333 60.600000
## 284 Yerevan Aremenia 40.183300 44.516700
## 285 Yixing China 31.030000 119.300000
## 286 Yokohama Japan 35.443708 139.638026
## 287 Yulin China 22.633300 110.150000
## 288 Yuzhou China 34.163400 113.460800
## 289 Zaozhuang China 34.866700 117.550000
## 290 Zhanjiang China 21.200000 110.400000
## 291 Zhongshan China 22.517646 113.392782
## 292 Zhucheng China 36.010000 119.416700
## 293 Zibo China 36.790560 118.063330
## PopGrowth_2000
## 1 1929000
## 2 1041000
## 3 2424000
## 4 1092000
## 5 2954000
## 6 1582000
## 7 3339000
## 8 2562000
## 9 1135000
## 10 1147000
## 11 2984000
## 12 1442000
## 13 3841000
## 14 1792000
## 15 5919000
## 16 3302000
## 17 7506000
## 18 1248000
## 19 1454000
## 20 1549000
## 21 3014000
## 22 7362000
## 23 1200000
## 24 1594000
## 25 2154000
## 26 3387000
## 27 1062000
## 28 1020000
## 29 5000000
## 30 6288000
## 31 2017000
## 32 1598000
## 33 1122000
## 34 2016000
## 35 1825000
## 36 2965000
## 37 1066000
## 38 3814000
## 39 6801000
## 40 4400000
## 41 2128000
## 42 1023000
## 43 1975000
## 44 2943000
## 45 2192000
## 46 1232000
## 47 1376000
## 48 1036000
## 49 1293000
## 50 1064000
## 51 2954000
## 52 2896000
## 53 1364000
## 54 3127000
## 55 2080000
## 56 1115000
## 57 1612000
## 58 2449000
## 59 1272000
## 60 1097000
## 61 2484000
## 62 1189000
## 63 1394000
## 64 1391000
## 65 1026000
## 66 1361000
## 67 1277000
## 68 1006000
## 69 7207000
## 70 3397000
## 71 1025000
## 72 1109000
## 73 1050000
## 74 1742000
## 75 1163000
## 76 2218000
## 77 1266000
## 78 2009000
## 79 1090000
## 80 2139000
## 81 1341000
## 82 1388000
## 83 1403000
## 84 2222000
## 85 1073000
## 86 3935000
## 87 1135000
## 88 1007000
## 89 2118000
## 90 1665000
## 91 1133000
## 92 1258000
## 93 1036000
## 94 1704000
## 95 1152000
## 96 1276000
## 97 1073000
## 98 1189000
## 99 2991000
## 100 2192000
## 101 1111000
## 102 1154000
## 103 1126000
## 104 6843000
## 105 1954000
## 106 1133000
## 107 1240000
## 108 1028000
## 109 3146000
## 110 1167000
## 111 2308000
## 112 1092000
## 113 8260000
## 114 1458000
## 115 9373000
## 116 1450000
## 117 1108000
## 118 1320000
## 119 1019000
## 120 2404000
## 121 1043000
## 122 1424000
## 123 1879000
## 124 1969000
## 125 9339000
## 126 1250000
## 127 1091000
## 128 1663000
## 129 1494000
## 130 2589000
## 131 2664000
## 132 1011000
## 133 1494000
## 134 1145000
## 135 1612000
## 136 1468000
## 137 1120000
## 138 1061000
## 139 5143000
## 140 1105000
## 141 1618000
## 142 1112000
## 143 1070000
## 144 1007000
## 145 7201000
## 146 1590000
## 147 7074000
## 148 3695000
## 149 1619000
## 150 1043000
## 151 1202000
## 152 1270000
## 153 1063000
## 154 3841000
## 155 2823000
## 156 1174000
## 157 3173000
## 158 1286000
## 159 1654000
## 160 1015000
## 161 1706000
## 162 1887000
## 163 1988000
## 164 1885000
## 165 3414000
## 166 8235000
## 167 1306000
## 168 1677000
## 169 1069000
## 170 13303000
## 171 1016000
## 172 8297000
## 173 1197000
## 174 9926000
## 175 1195000
## 176 2171000
## 177 1625000
## 178 1346000
## 179 1369000
## 180 1200000
## 181 1164000
## 182 1046000
## 183 1289000
## 184 8008000
## 185 1255000
## 186 1142000
## 187 1357000
## 188 1400000
## 189 1002000
## 190 1271000
## 191 1253000
## 192 1214000
## 193 2599000
## 194 1153000
## 195 1415000
## 196 2152000
## 197 1093000
## 198 1014000
## 199 1362000
## 200 1518000
## 201 1321000
## 202 1296000
## 203 1388000
## 204 1322000
## 205 1193000
## 206 1174000
## 207 1007000
## 208 1567000
## 209 2741000
## 210 1136000
## 211 2102000
## 212 1006000
## 213 1425000
## 214 1388000
## 215 1989000
## 216 1615000
## 217 1220000
## 218 1409000
## 219 1400000
## 220 5613000
## 221 1800000
## 222 1028000
## 223 2648000
## 224 1003000
## 225 1046000
## 226 4678000
## 227 2332000
## 228 1165000
## 229 1145000
## 230 1223000
## 231 4788000
## 232 2677000
## 233 10009000
## 234 1822000
## 235 2221000
## 236 1009000
## 237 10231000
## 238 1311000
## 239 8214000
## 240 4670000
## 241 1390000
## 242 1053000
## 243 3894000
## 244 1260000
## 245 1440000
## 246 2138000
## 247 1077000
## 248 2801000
## 249 1506000
## 250 4032000
## 251 1191000
## 252 1413000
## 253 2640000
## 254 2052000
## 255 1518000
## 256 2142000
## 257 1268000
## 258 1633000
## 259 6758000
## 260 5855000
## 261 1507000
## 262 1040000
## 263 8130000
## 264 1500000
## 265 1087000
## 266 1131000
## 267 1062000
## 268 1363000
## 269 1560000
## 270 1504000
## 271 1001000
## 272 1615000
## 273 1151000
## 274 4040000
## 275 1013000
## 276 2873000
## 277 1371000
## 278 1302000
## 279 1497000
## 280 1306000
## 281 1367000
## 282 2513000
## 283 1267000
## 284 1249000
## 285 1075000
## 286 3427000
## 287 1323000
## 288 1073000
## 289 1793000
## 290 1399000
## 291 1237000
## 292 1039000
## 293 2484000
dimensi data
dim(datapop)
## [1] 293 5
Struktur Data
str(datapop)
## 'data.frame': 293 obs. of 5 variables:
## $ City : chr "Abidjan" "Adana" "Addis Ababa" "Adelaide" ...
## $ Country : chr "Cote d'Ivoire" "Turkey" "Ethiopia" "Australia" ...
## $ Latitude : num 5.31 37 9.02 -34.93 23.04 ...
## $ Longitude : num -4.01 35.33 38.75 138.6 72.57 ...
## $ PopGrowth_2000: int 1929000 1041000 2424000 1092000 2954000 1582000 3339000 2562000 1135000 1147000 ...
Tabel data
View(datapop)
Plot the Data Point
coordinates(datapop) <- c("Longitude", "Latitude")
plot(datapop)
<-datapop$PopGrowth_2000/sum(datapop$PopGrowth_2000)
sizeplot(datapop,pch=20, col="steelblue", cex=size*100)
Menambahkan Peta Dunia
library(rworldmap)
## Warning: package 'rworldmap' was built under R version 4.1.1
## ### Welcome to rworldmap ###
## For a short introduction type : vignette('rworldmap')
data(package="rworldmap")
data(countriesCoarse,envir=environment(),package="rworldmap")
#str(countriesCoarse)
Menampilkan peta dunia dalam bentuk dasar berupa garis-garis wilayah.
plot(countriesCoarse)
## Warning in wkt(obj): CRS object has no comment
Menggabungkan peta dunia + data pertumbuhan penduduk:
plot(countriesCoarse)
## Warning in wkt(obj): CRS object has no comment
plot(countriesCoarse)
## Warning in wkt(obj): CRS object has no comment
plot(datapop,add=TRUE, pch=20)
Coba tampilkan data pertumbuhan penduduk dengan ukuran titik sesuai dengan besarnya pertumbuhan, pada peta dunia.!
plot(countriesCoarse)
## Warning in wkt(obj): CRS object has no comment
plot(datapop,add=TRUE, pch=20, col="green", cex=size*150)
#### Rasterize
library(raster)
<- raster(datapop)
r res(r)<-c(5,5)
<- rasterize(coordinates(datapop), r, fun=mean, background=NA)
nc plot(nc)
plot(countriesCoarse, add=TRUE)
Tugas Mandiri: Peta Pulau Jawa
Load package untuk mengimpor data polygon (shape file):
library(rgdal)
## rgdal: version: 1.5-23, (SVN revision 1121)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: C:/Users/ADWENDI/OneDrive/Documents/R/win-library/4.1/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/ADWENDI/OneDrive/Documents/R/win-library/4.1/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Overwritten PROJ_LIB was C:/Users/ADWENDI/OneDrive/Documents/R/win-library/4.1/rgdal/proj
Menggunakan fungsi readOGR:
readOGR(dsn=‘folder (direktori) tempat shape file disimpan’, layer=‘nama shape file (tanpa .shp extension)’)
<- readOGR(dsn='D:\\S2 Bismillah\\03_SEMESTER 2\\_STA553 Analisis Statistik Spasial\\PRAKTIKUM\\Map of Jawa (original)', layer='jawa') jawa
## Warning in OGRSpatialRef(dsn, layer, morphFromESRI = morphFromESRI, dumpSRS
## = dumpSRS, : Discarded datum D_unknown in Proj4 definition: +proj=longlat
## +ellps=GRS80 +no_defs
## OGR data source with driver: ESRI Shapefile
## Source: "D:\S2 Bismillah\03_SEMESTER 2\_STA553 Analisis Statistik Spasial\PRAKTIKUM\Map of Jawa (original)", layer: "jawa"
## with 116 features
## It has 5 fields
Pratinjau data:
head(jawa@data)
## MISKIN KODE_KAB NAMA_KAB KODE_PROP NAMA_PROP
## 0 0 3501 Pacitan 35 Jawa Timur
## 1 0 3502 Ponorogo 35 Jawa Timur
## 2 0 3503 Trenggalek 35 Jawa Timur
## 3 0 3504 Tulungagung 35 Jawa Timur
## 4 0 3508 Lumajang 35 Jawa Timur
## 5 0 3511 Bondowoso 35 Jawa Timur
Menampilkan peta Pulau Jawa
Menampilkan nama kota/kabupaten
plot(jawa)
text(jawa,'NAMA_KAB',cex=0.5)
Memberi warna yang berbeda utk setiap Propinsi
plot(jawa,col=jawa$KODE_PROP-30)
Mengganti referensi warna:
palette(rainbow(6))
plot(jawa, col=jawa$KODE_PROP-30)
palette(terrain.colors(6))
plot(jawa, col=jawa$KODE_PROP-30)
Praktikum 2 - Konfigurasi Titik Ruang dalam Ruang
Review
Titik adalah objek dalam dimensi nol dan menggambarkan sifat dari titik menduduki ruang. Pola keseluruhan titik dalam ruang mencerminkan sifat keseluruhan titik tersebut. Pembahasan bukan membicarakan sebuah titik tapi keseluruhan titik dalam ruang.
Ada tiga pola titik:
Acak : setiap titik mempunyai peluang yang sama untuk menduduki suatu ruang dan tidak dipengaruhi oleh titik yang lain
Uniform : setiap titik adalah sejauh mungkin dari titik-titik tetangganya.
Cluster : Banyak titik terkonsentrasi menduduki pada ruang yang sama, dan ruang yang lain sangat sedikit ditempati oleh titik.
First Approach: Quadrant Method
Metode Kuadran
Bagilah Daerah Studi menjadi beberapa sel yang berukuran sama. Ukuran Sel Ditentukan oleh skala yang diinginkan
Tentukan Rata-rata Banyaknya Titik per sel
Tentukan Variance banyaknya titik per sel
Hitung perbandingan Ragam dengan Rata-rata (VMR)
\(\overline{x} = \frac{N}{m}\) \(S^2 = \frac{\sum_{i = 1}^{m}(x_i - \overline{x})^2}{m - 1}\) \(VMR = \frac{S^2}{\overline{x}}\)
\(N = \text{banyaknya titik}\\\) \(m = \text{banyaknya sel}\\\) $x_i = \ $ \(\overline{x} = \text{rata-rata banyaknya titik persel}\\\) \(S^2 = \text{ragam banyaknya titik persel}\\\) \(VMR = \text{perbandingan ragam dengan rata-rata}\\\)
- VMR = 0 titik menyebar Uniform (sistematik)
- VMR = 1 titik menyebar acak
- VMR > 1 titik menyebar lebih mengelompok
Hipotesis
H0: Titik menyebar acak
H1: Titik tidak menyebar acak
Jika m < 30 maka didekati dengan sebaran Khi Kuadrat \(\chi^2 = (m - 1)VMR = \frac{(m - 1)S^2}{\overline{x}}\)
Jika m >= 30 maka didekati dengan sebaran Z \(Z = \frac{(m - 1)(VMR-(m-1))}{\sqrt{2(m-1)}} = \sqrt{\frac{m-1}{2}}(VMR - 1)\)
Bila alpha 5%, Z > 1.96 menolak H0 dan menerima H1 dengan kesimpulan Kluster
Bila alpha 5%, Z < -1.96 menolak H0 dan menerima H1 dengan kesimpulan Uniform
Aplikasi pada R
library(spatstat)
## Warning: package 'spatstat' was built under R version 4.1.1
## Loading required package: spatstat.data
## Warning: package 'spatstat.data' was built under R version 4.1.1
## Loading required package: spatstat.geom
## Warning: package 'spatstat.geom' was built under R version 4.1.1
## spatstat.geom 2.2-2
##
## Attaching package: 'spatstat.geom'
## The following objects are masked from 'package:raster':
##
## area, rotate, shift
## Loading required package: spatstat.core
## Warning: package 'spatstat.core' was built under R version 4.1.1
## Loading required package: nlme
##
## Attaching package: 'nlme'
## The following object is masked from 'package:raster':
##
## getData
## Loading required package: rpart
## spatstat.core 2.3-0
##
## Attaching package: 'spatstat.core'
## The following object is masked from 'package:gstat':
##
## idw
## Loading required package: spatstat.linnet
## Warning: package 'spatstat.linnet' was built under R version 4.1.1
## spatstat.linnet 2.3-0
##
## spatstat 2.2-0 (nickname: 'That's not important right now')
## For an introduction to spatstat, type 'beginner'
data(swedishpines)
help(swedishpines)
Swedish Pines Point Pattern
Description > The data give the locations of pine saplings in a Swedish forest.
Usage > data(swedishpines)
Format An object of class “ppp” representing the point pattern of tree locations in a rectangular plot 9.6 by 10 metres.
Cartesian coordinates are given in decimetres (multiples of 0.1 metre) rounded to the nearest decimetre. Type rescale(swedishpines) to get an equivalent dataset where the coordinates are expressed in metres.
See ppp.object for details of the format of a point pattern object.
<- swedishpines
X plot(X)
summary(X)
## Planar point pattern: 71 points
## Average intensity 0.007395833 points per square unit (one unit = 0.1 metres)
##
## Coordinates are integers
## i.e. rounded to the nearest unit (one unit = 0.1 metres)
##
## Window: rectangle = [0, 96] x [0, 100] units
## Window area = 9600 square units
## Unit of length: 0.1 metres
Plot Contour seperti memprediksi ketinggian kepekatan menjadi dua dimensi.
contour(density(X,10),axes = F)
nx dan ny default nya 5 x 5
<- quadratcount(X, nx = 4, ny = 3)
q q
## x
## y [0,24) [24,48) [48,72) [72,96]
## [66.7,100] 7 3 6 5
## [33.3,66.7) 5 9 7 7
## [0,33.3) 4 3 6 9
plot(q)
<- mean(q)
mu <- sd(q)^2
sigma <- sigma/mu
VMR VMR
## [1] 0.6901408
quadrat.test(q)#H1 tidak sama dengan
##
## Chi-squared test of CSR using quadrat counts
##
## data:
## X2 = 7.5915, df = 11, p-value = 0.5013
## alternative hypothesis: two.sided
##
## Quadrats: 4 by 3 grid of tiles
p-value = 0.5013 > alpha = 0.05 sehingga tidak tolak Ho berarti pada taraf alpha 5%, tidak ada bukti untuk menyatakan bahwa titik tidak menyebar acak.
quadrat.test(q, alt = "regular")
##
## Chi-squared test of CSR using quadrat counts
##
## data:
## X2 = 7.5915, df = 11, p-value = 0.2506
## alternative hypothesis: regular
##
## Quadrats: 4 by 3 grid of tiles
p-value = 0.2506 > alpha = 0.05 sehingga tidak tolak Ho berarti pada taraf alpha 5%, tidak ada bukti untuk menyatakan bahwa titik tidak menyebar acak atau regular.
Second Approach: Empirical K-Function
<- nndist(swedishpines)
nn hist(nn)
The Empirical K-Function
\(\hat{K}(r) = \frac{|W|}{n(n-1)}\sum_{i=1}^{n}\sum_{j=1\text{ },\text{ } j\neq{i}}^{n}1\{d_{ij}\le{r}\}e_{ij}(r)\\\) \(\text{ }\\\) \(d_{ij} = \text{observed pairwise distance}\\\) \(r = \text{distance value}(r\ge{0})\\\) \(e_{ij} = \text{edge correction weight}\\\) \(n = \text{number of points}\\\) \(|W| = \text{the area of observation window}\)
In summary, the empirical K-function \(\hat{K}(r)\) is the cumulative average number of data points lying within a distance r of a typical data point, corrected for edge effects, and standardised by dividing by the intensity.
Possible pattern for \(\hat{K}(r)\)
Theoritical K-Function \(K_{pois}(r) = \pi r^2\)
This is the K function for a homogeneous Poisson process
Use of empirical K-Function
Aplikasi pada R
<- Kest(swedishpines, correction="Ripley")
Kplot(K)
<-envelope(swedishpines,Kest, nsim=99) E
## Generating 99 simulations of CSR ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
## 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
## 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99.
##
## Done.
plot(E)
graphical test
mad.test(swedishpines, Kest, nsim=99, alternative="two.sided")
## Generating 99 simulations of CSR ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
## 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
## 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99.
##
## Done.
##
## Maximum absolute deviation test of CSR
## Monte Carlo test based on 99 simulations
## Summary function: K(r)
## Reference function: theoretical
## Alternative: two.sided
## Interval of distance values: [0, 24] units (one unit = 0.1 metres)
## Test statistic: Maximum absolute deviation
## Deviation = observed minus theoretical
##
## data: swedishpines
## mad = 150.69, rank = 20, p-value = 0.2
Menggunakan data external
Jenis data yang diperlukan
Import Data
Data dapat diunduh di: city.rds crime.rds
library(raster)
library(spatstat)
<- readRDS('city.rds')
city <- readRDS('crime.rds') crime
Konversi data menjadi titik point pattern
<-city
border<-city@polygons[[1]]@Polygons[[1]]@coords
coord.city<-owin(poly=data.frame(x=rev(coord.city[,1]),
windowy=rev(coord.city[,2])))
plot(window)
Menghitung titik di dalam kuadran
<- remove.duplicates(crime) crime2
## Warning in wkt(obj): CRS object has no comment
## Warning in wkt(obj): CRS object has no comment
<- crime2[crime,] crime2
## Warning in wkt(obj): CRS object has no comment
## Warning in wkt(obj): CRS object has no comment
<-ppp(x=crime2@coords[,1],y=crime2@coords[,2],
crime2.pppwindow=window)
## Warning: 5 points were rejected as lying outside the specified window
<-quadratcount(crime2.ppp)
quadplot(quad, col="red")
plot(crime2.ppp, add=T, pch=20, cex = 0.5)
## Warning in plot.ppp(crime2.ppp, add = T, pch = 20, cex = 0.5): 5 illegal points
## also plotted
quadrat.test(crime2.ppp,alt="cluster")
## Warning: Some expected counts are small; chi^2 approximation may be inaccurate
##
## Chi-squared test of CSR using quadrat counts
##
## data: crime2.ppp
## X2 = 480.83, df = 22, p-value < 2.2e-16
## alternative hypothesis: clustered
##
## Quadrats: 23 tiles (irregular windows)
Using K-funtion
<- Kest(crime2.ppp,
Kcorrection="Ripley")
plot(K)
mad.test(crime2.ppp, Kest, nsim = 20, alternative = "greater")
## Generating 20 simulations of CSR ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
##
## Done.
##
## Maximum signed deviation test of CSR
## Monte Carlo test based on 20 simulations
## Summary function: K(r)
## Reference function: theoretical
## Alternative: greater
## Interval of distance values: [0, 3697.26712973043]
## Test statistic: Maximum signed deviation
## Deviation = observed minus theoretical
##
## data: crime2.ppp
## mad = 16518845, rank = 1, p-value = 0.04762
Simulasi Data
Poisson process
To create a Poisson process with uniform intensity of 50 over [0; 1] [0; 1]
<- rpoispp(50)
pp0 plot(pp0)
### Matern Clustering
<- rMatClust(12, 0.1, 4)
pp3 plot(pp3)
Apakah data yang dibangkitkan selalu sesuai dengan yg diinginkan? > Belum Tentu
Other generator function
- rThomas
- rCauchy
- rVarGamma
- rNeymanScott
- rGaussPoisson
Other point pattern data
- amacrine (rabbit amacrine cells, locations and 2 types)
- anemones (sea anemones data, locations and sizes)
- ants (ant nests data, location and 2 types)
- bei (tropical rainforest trees, locations)
- betacells (cat retinal ganglia data, locations, 2 types and sizes)
- bramblecanes (Bramble Canes data, locations and 3 types)
- cells (biological cells data, locations)
- chorley (cancer data, locations and 2 types)
- finpines (Finnish Pines data, locations and 2 size measures)
- hamster (hamster tumour data, locations and 2 types)
- japanesepines (Japanese Pines data, locations)
- lansing (Lansing Woods data, locations and 6 types)
- longleaf (Longleaf Pines data, locations and sizes)
- nztrees (trees data, locations)
- ponderosa (ponderosa pine trees data, locations)
- redwood (redwood samplings data, locations)
- spruces (Spruce trees in Saxonia, locations and sizes)
Referensi
- Anisa, R. 2021. Pengenalan Struktur R untuk Data Spasial.Retrieved from newlms.ipb.ac.id
- Anisa, R. 2021. Konfigurasi Titik Ruang. Retrieved from newlms.ipb.ac.id
Demikian, Terima Kasih
Satria June Adwendi, IPB University, sjadwendi@apps.ipb.ac.id↩︎