Exercise 1: The file boston6k.csv contains information on house prices in Boston by census tract, as well as various socio-economic and environmental factors. Use this to cluster the tracts by these factors (NOT by price), then examine the characteristics of the clusters, whether they show a difference in house price and if there is any spatial structure to the clusters. Use only the following variables in the cluster analysis: CRIM, ZN, INDUS, CHAS, NOX, RM, AGE, DIS, RAD, TAX, PTRATIO, B, LSTAT (see the file description for explanations of these). You will need to scale the data as the variables are in a wide range of units.
r setwd ("C:/doug/classes/geog6000") b6k <- read.csv("boston6k.csv", na.strings="") mycol <- heat.colors(5) summary(b6k)
## ID TOWN TOWNNO TRACT ## Min. : 1.0 Cambridge : 30 Min. : 0.00 Min. : 1 ## 1st Qu.:127.2 Boston Savin Hill: 23 1st Qu.:26.25 1st Qu.:1303 ## Median :253.5 Lynn : 22 Median :42.00 Median :3394 ## Mean :253.5 Boston Roxbury : 19 Mean :47.53 Mean :2700 ## 3rd Qu.:379.8 Newton : 18 3rd Qu.:78.00 3rd Qu.:3740 ## Max. :506.0 Somerville : 15 Max. :91.00 Max. :5082 ## (Other) :379 ## LON LAT MEDV CMEDV ## Min. :-71.49 Min. :42.05 Min. : 5.00 Min. : 5.00 ## 1st Qu.:-71.16 1st Qu.:42.30 1st Qu.:17.02 1st Qu.:17.02 ## Median :-71.09 Median :42.36 Median :21.20 Median :21.20 ## Mean :-71.09 Mean :42.36 Mean :22.53 Mean :22.53 ## 3rd Qu.:-71.03 3rd Qu.:42.42 3rd Qu.:25.00 3rd Qu.:25.00 ## Max. :-70.68 Max. :42.64 Max. :50.00 Max. :50.00 ## ## CRIM ZN INDUS CHAS ## Min. : 0.00632 Min. : 0.00 Min. : 0.46 Min. :0.00000 ## 1st Qu.: 0.08204 1st Qu.: 0.00 1st Qu.: 5.19 1st Qu.:0.00000 ## Median : 0.25651 Median : 0.00 Median : 9.69 Median :0.00000 ## Mean : 3.61352 Mean : 11.36 Mean :11.14 Mean :0.06917 ## 3rd Qu.: 3.67708 3rd Qu.: 12.50 3rd Qu.:18.10 3rd Qu.:0.00000 ## Max. :88.97620 Max. :100.00 Max. :27.74 Max. :1.00000 ## ## NOX RM AGE DIS ## Min. :0.3850 Min. :3.561 Min. : 2.90 Min. : 1.130 ## 1st Qu.:0.4490 1st Qu.:5.886 1st Qu.: 45.02 1st Qu.: 2.100 ## Median :0.5380 Median :6.208 Median : 77.50 Median : 3.207 ## Mean :0.5547 Mean :6.285 Mean : 68.57 Mean : 3.795 ## 3rd Qu.:0.6240 3rd Qu.:6.623 3rd Qu.: 94.08 3rd Qu.: 5.188 ## Max. :0.8710 Max. :8.780 Max. :100.00 Max. :12.127 ## ## RAD TAX PTRATIO B ## Min. : 1.000 Min. :187.0 Min. :12.60 Min. : 0.32 ## 1st Qu.: 4.000 1st Qu.:279.0 1st Qu.:17.40 1st Qu.:375.38 ## Median : 5.000 Median :330.0 Median :19.05 Median :391.44 ## Mean : 9.549 Mean :408.2 Mean :18.46 Mean :356.67 ## 3rd Qu.:24.000 3rd Qu.:666.0 3rd Qu.:20.20 3rd Qu.:396.23 ## Max. :24.000 Max. :711.0 Max. :22.00 Max. :396.90 ## ## LSTAT ## Min. : 1.73 ## 1st Qu.: 6.95 ## Median :11.36 ## Mean :12.65 ## 3rd Qu.:16.95 ## Max. :37.97 ##
r b6k.use = b6k[,c("CRIM", "ZN", "INDUS", "CHAS", "NOX", "RM", "AGE", "DIS", "RAD", "TAX", "PTRATIO", "B", "LSTAT")] b6ks.use = scale(b6k.use) summary(b6ks.use)
## CRIM ZN INDUS ## Min. :-0.419367 Min. :-0.48724 Min. :-1.5563 ## 1st Qu.:-0.410563 1st Qu.:-0.48724 1st Qu.:-0.8668 ## Median :-0.390280 Median :-0.48724 Median :-0.2109 ## Mean : 0.000000 Mean : 0.00000 Mean : 0.0000 ## 3rd Qu.: 0.007389 3rd Qu.: 0.04872 3rd Qu.: 1.0150 ## Max. : 9.924110 Max. : 3.80047 Max. : 2.4202 ## CHAS NOX RM AGE ## Min. :-0.2723 Min. :-1.4644 Min. :-3.8764 Min. :-2.3331 ## 1st Qu.:-0.2723 1st Qu.:-0.9121 1st Qu.:-0.5681 1st Qu.:-0.8366 ## Median :-0.2723 Median :-0.1441 Median :-0.1084 Median : 0.3171 ## Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 ## 3rd Qu.:-0.2723 3rd Qu.: 0.5981 3rd Qu.: 0.4823 3rd Qu.: 0.9059 ## Max. : 3.6648 Max. : 2.7296 Max. : 3.5515 Max. : 1.1164 ## DIS RAD TAX PTRATIO ## Min. :-1.2658 Min. :-0.9819 Min. :-1.3127 Min. :-2.7047 ## 1st Qu.:-0.8049 1st Qu.:-0.6373 1st Qu.:-0.7668 1st Qu.:-0.4876 ## Median :-0.2790 Median :-0.5225 Median :-0.4642 Median : 0.2746 ## Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 ## 3rd Qu.: 0.6617 3rd Qu.: 1.6596 3rd Qu.: 1.5294 3rd Qu.: 0.8058 ## Max. : 3.9566 Max. : 1.6596 Max. : 1.7964 Max. : 1.6372 ## B LSTAT ## Min. :-3.9033 Min. :-1.5296 ## 1st Qu.: 0.2049 1st Qu.:-0.7986 ## Median : 0.3808 Median :-0.1811 ## Mean : 0.0000 Mean : 0.0000 ## 3rd Qu.: 0.4332 3rd Qu.: 0.6024 ## Max. : 0.4406 Max. : 3.5453 • Start by running k-means cluster analysis on the data from 2 to 20 clusters, using the approach outlined above. You should calculate either the silhouette index or the Calinski-Harabasz index for each set of clusters. Provide a plot of the index values, and identify the number of clusters (k) that gives the best solution
set.seed(42)
ngrp <- 7
b6k.kmeans <- kmeans(b6ks.use, ngrp, nstart=50, iter.max=20)
table(b6k.kmeans$cluster)
##
## 1 2 3 4 5 6 7
## 99 91 58 34 38 34 152
#mycol <- rainbow(ngrp)
library(cluster)
sil.out <- silhouette(b6k.kmeans$cluster, dist(b6ks.use))
sil.out[1:4,]
## cluster neighbor sil_width
## [1,] 6 2 0.02928840
## [2,] 6 2 0.10091549
## [3,] 6 2 0.09835926
## [4,] 2 1 0.46328707
tapply(sil.out[,3], sil.out[,1], mean)
## 1 2 3 4 5 6 7
## 0.2406632 0.4081228 0.3160620 0.1886433 0.2694492 0.1928969 0.2214812
pdf("Boston silhouette.pdf")
plot(sil.out, col=mycol, main="Boston Housing Silhouette Plot")
# Close the pdf file
dev.off()
## png
## 2
sil.out <- rep(NA,20) ## Silhouette index
for (i in 2:20) {
b6k.kmeans <- kmeans(b6ks.use, centers=i, nstart=50)
tmp <- silhouette(b6k.kmeans$cluster, dist(b6ks.use))
sil.out[i] <- mean(tmp[,3])
}
# the average silhouette index:
plot(1:20,sil.out, type='b', lwd=2,
xlab="N Groups", ylab="C", main="Average silhouette index")
# note higher is better
• In your opinion, is this the best solution, or would more or less clusters be useful?
• Re-run kmeans() using your chosen number for k
ngrp <- 12
b6k.kmeans <- kmeans(b6ks.use, ngrp, nstart=50, iter.max=20)
table(b6k.kmeans$cluster)
##
## 1 2 3 4 5 6 7 8 9 10 11 12
## 5 27 94 26 38 22 62 34 50 31 40 77
• Using the aggregate() function, provide a table showing the median “OF” the variables used in clustering. In 1-2 sentences, describe the characteristics of the clusters
b6k.centers <- aggregate(b6ks.use, list(b6k.kmeans$cluster), median)
b6k.centers
## Group.1 CRIM ZN INDUS CHAS NOX
## 1 1 7.4762471 -0.4872402 1.0149946 -0.2723291 1.07272553
## 2 2 -0.3862822 -0.4872402 1.5674443 -0.2723291 0.59808708
## 3 3 -0.3941470 -0.4872402 -0.3756044 -0.2723291 -0.14407485
## 4 4 1.5957280 -0.4872402 1.0149946 -0.2723291 1.22374685
## 5 5 -0.3786202 -0.4872402 -1.0446662 -0.2723291 -0.43748771
## 6 6 -0.1560352 -0.4872402 1.2307270 -0.2723291 2.72964520
## 7 7 0.3383690 -0.4872402 1.0149946 -0.2723291 1.19354259
## 8 8 -0.3638042 -0.4872402 0.4013236 3.6647712 -0.04051738
## 9 9 -0.4105307 0.7990739 -0.8901552 -0.2723291 -1.05020280
## 10 10 0.8394627 -0.4872402 1.0149946 -0.2723291 1.07272553
## 11 11 -0.4163181 2.9429307 -1.2968398 -0.2723291 -1.27457734
## 12 12 -0.4091990 -0.4872402 -0.6161168 -0.2723291 -0.83445805
## RM AGE DIS RAD TAX PTRATIO
## 1 -0.75095575 1.1163897 -1.1253414 1.6596029 1.52941294 0.8057784
## 2 -0.48765447 1.0098134 -0.8681835 -0.6373311 0.17066179 1.2676838
## 3 -0.36454332 0.4858136 -0.2357602 -0.6373311 -0.60068166 0.3438730
## 4 -1.30246521 1.0453389 -1.0629633 1.6596029 1.52941294 0.8057784
## 5 1.61306285 0.3206204 -0.4227518 -0.5224844 -0.85581834 -0.4875567
## 6 -0.59795636 0.9991558 -0.9726850 -0.5224844 -0.03107419 -1.7347012
## 7 -0.06993053 0.8659355 -0.7201811 1.6596029 1.52941294 0.8057784
## 8 -0.07633515 0.7096237 -0.3924532 -0.5224844 -0.60068166 -0.3951756
## 9 0.41682105 -1.2282877 1.3514003 -0.4650610 -0.64221553 -0.7416046
## 10 0.09018512 0.7895559 -0.8536040 1.6596029 1.52941294 0.8057784
## 11 0.68225721 -1.4485453 1.6687754 -0.6947544 -0.55914778 -1.0187478
## 12 -0.23289268 -0.9618471 0.6819824 -0.6373311 -0.71934988 0.1129203
## B LSTAT
## 1 -2.93996857 1.11565161
## 2 0.35572613 0.65213509
## 3 0.40304533 0.01567509
## 4 0.44061589 1.77031618
## 5 0.36706302 -1.04579175
## 6 -0.07321367 0.14520765
## 7 0.33737898 0.38956908
## 8 0.37138966 -0.23288740
## 9 0.40567417 -0.82033508
## 10 -3.52291483 0.98541887
## 11 0.39937590 -1.08710214
## 12 0.41575141 -0.54096485
• Report the mean corrected house value per cluster # I have no idea which variable is the housing value. I can find no file description! And what would I correct for? I can convert the variables back to original units (destandardize) but then what? I could calc the houseing price if I had any idea what that was per observation to begin with. #
• Use anova() to test whether the values are significantly different between clusters. You will need the vector of house prices/values and the vector of clusters from kmeans(). Give the F-statistic and the p-value
#well, the problem of not knowing housing prices bites me again.#
The file wnaclim2.csv contains a set of climatic variables for sites distributed across western North America. Use principal component analysis to explore the spatial distribution of climate. This will require you to install the add-on package fields for plotting.
wna <- read.csv("wnaclim2.csv", na.strings="")
library(fields)
## Warning: package 'fields' was built under R version 3.5.3
## Loading required package: spam
## Warning: package 'spam' was built under R version 3.5.3
## Loading required package: dotCall64
## Warning: package 'dotCall64' was built under R version 3.5.3
## Loading required package: grid
## Spam version 2.3-0 (2019-09-13) is loaded.
## Type 'help( Spam)' or 'demo( spam)' for a short introduction
## and overview of this package.
## Help for individual functions is also obtained by adding the
## suffix '.spam' to the function name, e.g. 'help( chol.spam)'.
##
## Attaching package: 'spam'
## The following objects are masked from 'package:base':
##
## backsolve, forwardsolve
## Loading required package: maps
## Warning: package 'maps' was built under R version 3.5.3
##
## Attaching package: 'maps'
## The following object is masked from 'package:cluster':
##
## votes.repub
## See https://github.com/NCAR/Fields for
## an extensive vignette, other supplements and source code
• Read in the file and perform principal component analysis using the monthly temperature and precipitation variables (these are the same as you used in the cluster analysis in the lab). . Use the SVD approach with the function prcomp(). Note that you will have to use to scale the data in the PCA to avoid any bias from the difference in magnitude of the variables in the dataset (use the scale=TRUE parameter). Make a biplot of this ordination (biplot()) and a scree-plot showing the variance explained by the components (screeplot()).
wna2<- wna[,seq(3,26)]
summary(wna2)
## tjan tfeb tmar tapr
## Min. :-33.60 Min. :-34.800 Min. :-32.700 Min. :-24.9000
## 1st Qu.:-22.30 1st Qu.:-18.900 1st Qu.:-12.800 1st Qu.: -3.9000
## Median : -6.90 Median : -4.400 Median : -1.600 Median : 3.2000
## Mean :-10.27 Mean : -8.347 Mean : -4.998 Mean : 0.8068
## 3rd Qu.: -1.40 3rd Qu.: 1.200 3rd Qu.: 3.200 3rd Qu.: 6.7000
## Max. : 15.10 Max. : 17.300 Max. : 19.400 Max. : 22.8000
## tmay tjun tjul taug
## Min. :-11.600 Min. :-1.5 Min. : 2.90 Min. : 1.40
## 1st Qu.: 3.900 1st Qu.: 9.5 1st Qu.:12.30 1st Qu.:11.00
## Median : 8.200 Median :12.8 Median :15.70 Median :15.00
## Mean : 7.471 Mean :13.0 Mean :16.13 Mean :14.97
## 3rd Qu.: 11.500 3rd Qu.:16.1 3rd Qu.:19.80 3rd Qu.:18.80
## Max. : 27.100 Max. :32.7 Max. :35.20 Max. :34.20
## tsep toct tnov tdec
## Min. :-5.80 Min. :-16.400 Min. :-26.00 Min. :-30.800
## 1st Qu.: 5.60 1st Qu.: -3.700 1st Qu.:-14.50 1st Qu.:-20.500
## Median :10.60 Median : 5.500 Median : -1.40 Median : -6.000
## Mean :10.29 Mean : 3.542 Mean : -4.44 Mean : -9.113
## 3rd Qu.:14.40 3rd Qu.: 9.000 3rd Qu.: 3.00 3rd Qu.: -0.800
## Max. :31.80 Max. : 26.500 Max. : 19.90 Max. : 15.500
## pjan pfeb pmar papr
## Min. : 3.00 Min. : 1.00 Min. : 1.00 Min. : 2.00
## 1st Qu.: 15.00 1st Qu.: 13.00 1st Qu.: 15.00 1st Qu.: 11.00
## Median : 26.00 Median : 22.00 Median : 25.00 Median : 22.00
## Mean : 60.17 Mean : 47.78 Mean : 47.56 Mean : 35.65
## 3rd Qu.: 54.00 3rd Qu.: 47.00 3rd Qu.: 48.00 3rd Qu.: 43.00
## Max. :492.00 Max. :389.00 Max. :337.00 Max. :300.00
## pmay pjun pjul paug
## Min. : 1.00 Min. : 0.00 Min. : 0.0 Min. : 0.00
## 1st Qu.: 11.00 1st Qu.: 16.00 1st Qu.: 22.0 1st Qu.: 27.00
## Median : 29.00 Median : 31.00 Median : 40.0 Median : 42.00
## Mean : 34.29 Mean : 37.96 Mean : 43.7 Mean : 46.27
## 3rd Qu.: 48.00 3rd Qu.: 55.00 3rd Qu.: 61.0 3rd Qu.: 61.00
## Max. :225.00 Max. :194.00 Max. :176.0 Max. :268.00
## psep poct pnov pdec
## Min. : 4.00 Min. : 0.00 Min. : 3.00 Min. : 3.00
## 1st Qu.: 21.00 1st Qu.: 18.00 1st Qu.: 15.00 1st Qu.: 15.00
## Median : 32.00 Median : 26.00 Median : 25.00 Median : 27.00
## Mean : 39.66 Mean : 45.22 Mean : 56.62 Mean : 62.21
## 3rd Qu.: 45.00 3rd Qu.: 38.00 3rd Qu.: 49.00 3rd Qu.: 55.00
## Max. :422.00 Max. :618.00 Max. :531.00 Max. :520.00
wna2.pca <- prcomp(wna2, scale=TRUE)
summary(wna2.pca)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6
## Standard deviation 3.4612 2.8065 1.5846 0.84733 0.63986 0.51316
## Proportion of Variance 0.4992 0.3282 0.1046 0.02992 0.01706 0.01097
## Cumulative Proportion 0.4992 0.8274 0.9320 0.96190 0.97896 0.98993
## PC7 PC8 PC9 PC10 PC11 PC12
## Standard deviation 0.29261 0.20707 0.17437 0.15014 0.13534 0.10798
## Proportion of Variance 0.00357 0.00179 0.00127 0.00094 0.00076 0.00049
## Cumulative Proportion 0.99350 0.99528 0.99655 0.99749 0.99825 0.99874
## PC13 PC14 PC15 PC16 PC17 PC18
## Standard deviation 0.09353 0.08322 0.06116 0.05676 0.04584 0.04161
## Proportion of Variance 0.00036 0.00029 0.00016 0.00013 0.00009 0.00007
## Cumulative Proportion 0.99910 0.99939 0.99955 0.99968 0.99977 0.99984
## PC19 PC20 PC21 PC22 PC23 PC24
## Standard deviation 0.03439 0.02946 0.02562 0.02411 0.01802 0.01392
## Proportion of Variance 0.00005 0.00004 0.00003 0.00002 0.00001 0.00001
## Cumulative Proportion 0.99989 0.99993 0.99995 0.99998 0.99999 1.00000
wna2.pca$rotation
## PC1 PC2 PC3 PC4 PC5
## tjan 0.27154635 -0.07007925 0.080386417 -0.1634473814 0.29901716
## tfeb 0.27524689 -0.07830351 0.051384208 -0.0792929685 0.26587174
## tmar 0.27484658 -0.09367701 -0.001067899 0.0006366441 0.19086484
## tapr 0.26473010 -0.12257641 -0.076298000 0.1052955242 0.03981628
## tmay 0.23877755 -0.16889072 -0.127271902 0.1251598792 -0.21848109
## tjun 0.20220435 -0.21701738 -0.139841033 0.0811805985 -0.44268300
## tjul 0.20390908 -0.22851811 -0.090041235 0.0981226254 -0.35337585
## taug 0.22863878 -0.20271341 -0.057726655 0.1081761983 -0.22777782
## tsep 0.25186014 -0.16881584 -0.031188367 -0.0252319485 -0.11100418
## toct 0.26714245 -0.12423680 -0.014213457 0.0039586317 0.12864795
## tnov 0.27214789 -0.09552584 0.029032040 -0.0776651476 0.26276447
## tdec 0.27301687 -0.07380880 0.068758839 -0.1472904833 0.28523902
## pjan 0.16803736 0.25995212 0.198293078 -0.0491302786 -0.14878411
## pfeb 0.17102216 0.26393484 0.174815508 -0.0779200398 -0.13546314
## pmar 0.17796187 0.25650454 0.169544577 -0.0684787805 -0.08941670
## papr 0.17074339 0.27824680 0.066073520 0.0873621609 -0.01709438
## pmay 0.14748106 0.25905950 -0.096201569 0.4454588155 0.21475276
## pjun 0.05730680 0.23790590 -0.271290553 0.6551603362 0.14238968
## pjul 0.01369406 0.10097126 -0.573535723 -0.1391139500 0.07054361
## paug 0.03206302 0.14782502 -0.519764989 -0.4064516753 0.01206271
## psep 0.10354548 0.26528778 -0.300542026 -0.1481576621 -0.04780745
## poct 0.13939969 0.28759576 -0.081905529 -0.1479311802 -0.16441200
## pnov 0.16303542 0.27829605 0.141217106 -0.0566592085 -0.16857230
## pdec 0.16860662 0.26639834 0.170927455 -0.0622112513 -0.15532094
## PC6 PC7 PC8 PC9 PC10
## tjan -0.0284108206 0.006685677 0.150748941 -0.03370819 0.295282973
## tfeb 0.0003503783 0.136618117 0.096325727 0.05374427 0.146770345
## tmar 0.0472553831 0.299836795 0.107879864 0.12796171 -0.002868388
## tapr 0.1142053327 0.361840941 0.005051047 0.18027931 -0.245606706
## tmay 0.1162681105 0.391610249 0.152998679 0.14131428 -0.153895952
## tjun 0.0336846593 0.059413350 0.153361302 0.08729649 0.185251391
## tjul -0.0968873526 -0.282122219 0.078633470 -0.02281332 0.111072241
## taug -0.1100855056 -0.269202717 -0.078353138 -0.16060487 0.002348289
## tsep -0.0494334800 -0.197844681 -0.135371606 -0.17154105 0.019210005
## toct -0.0108001461 -0.228312237 -0.393469988 -0.13609013 -0.315583081
## tnov -0.0341735253 -0.123895015 -0.174524477 -0.10198795 -0.168381612
## tdec -0.0376637342 -0.070659399 0.019616400 -0.04699441 0.196876851
## pjan 0.2458067285 0.032089376 -0.048645619 -0.21338581 0.001100698
## pfeb 0.1820140769 -0.040185881 -0.011301000 0.07554311 -0.126403221
## pmar 0.2288319443 -0.177170757 0.160725487 0.13544683 -0.309717304
## papr -0.0925172437 -0.305189314 0.271689204 0.39781282 -0.204745692
## pmay -0.1948655497 -0.258064679 0.241986147 0.13372542 0.183453709
## pjun 0.1213474134 0.141181422 -0.086059500 -0.36227611 0.043038183
## pjul 0.4811346946 -0.176731790 -0.383344278 0.38567024 0.178533100
## paug 0.0604580646 -0.072069255 0.509760728 -0.38851386 -0.032443473
## psep -0.4843787725 0.196824537 -0.149665107 -0.09624515 -0.407497122
## poct -0.4759093700 0.159625862 -0.266370371 0.26037169 0.346421923
## pnov 0.0644439203 0.128788161 -0.117454901 -0.17604085 0.237115136
## pdec 0.1871590345 0.094644125 -0.105030745 -0.21895144 0.170211499
## PC11 PC12 PC13 PC14 PC15
## tjan -0.3177818979 0.084717452 -0.198073796 0.0306128664 -0.12524773
## tfeb -0.0850920746 0.207170982 0.215049963 -0.0248132032 0.07177408
## tmar 0.0837891432 0.151198192 0.338194830 -0.1213396869 -0.04343164
## tapr 0.2429592526 -0.018873516 0.244346289 0.0007484506 0.04381860
## tmay 0.0431667637 -0.232783794 -0.291244671 0.0480458427 -0.18616504
## tjun -0.0987876247 -0.033840012 -0.422444222 -0.0105642695 0.31526141
## tjul -0.0486904501 0.283065952 0.298939526 -0.0044454340 0.14450174
## taug -0.0152404625 0.136111286 0.291708371 -0.0496293283 -0.21486141
## tsep -0.0444107836 -0.120942065 -0.094460420 0.0209592856 -0.41993874
## toct 0.2093561076 -0.231921667 -0.011130377 0.0997939913 0.27607606
## tnov 0.1006998972 -0.233238733 -0.174605090 -0.0378639293 0.02149880
## tdec -0.1909224250 0.002929791 -0.196357064 0.0633928569 0.15143733
## pjan -0.0005762763 0.039714713 0.006401917 -0.3431345819 0.49814932
## pfeb -0.1595286785 0.149113176 0.045518203 0.2980140260 0.07726715
## pmar -0.0295711250 0.194223506 -0.064458463 0.5326818242 -0.13153712
## papr -0.3048488853 -0.403344025 0.133363364 -0.4467304855 -0.08102153
## pmay 0.5520813847 0.203821338 -0.246609418 0.0048849326 0.02882245
## pjun -0.4115111702 -0.123357939 0.112057802 0.1724675213 0.02767334
## pjul -0.0309151580 0.137303662 -0.039627958 -0.1174288399 -0.07339510
## paug 0.1609697226 -0.224188960 0.158706743 0.0989438683 0.06477934
## psep -0.1703085895 0.441341096 -0.234474281 -0.2164132305 -0.05426607
## poct 0.0248821147 -0.304950065 0.205141127 0.3425036906 0.16345751
## pnov 0.1821268769 -0.095799139 0.015392954 -0.1184016248 -0.41165840
## pdec 0.1898709898 0.053178843 -0.055907092 -0.2039300913 -0.10002376
## PC16 PC17 PC18 PC19 PC20
## tjan 0.148674822 -0.107041343 0.160823567 -0.0269825468 0.4272858093
## tfeb -0.017002651 0.234367308 -0.030332072 0.0627361960 0.0203446585
## tmar -0.035352024 -0.000212998 -0.023742455 -0.0452842790 -0.2687836322
## tapr 0.022030975 0.145866305 0.006613803 -0.0184863673 -0.0467386911
## tmay 0.142255714 -0.298105316 0.126282045 0.0006562435 0.3387549738
## tjun -0.160935797 0.249990410 -0.191135211 0.0289864553 -0.2723565962
## tjul -0.238251861 -0.162051895 -0.033972474 0.1319965479 0.2737881475
## taug 0.106065552 -0.250950490 0.035001101 -0.1434759326 -0.0549829727
## tsep 0.390707549 0.327566676 0.244781447 -0.0916673160 -0.3538791803
## toct 0.018144251 0.349455508 -0.075056635 0.0788151267 0.4142142645
## tnov -0.264971834 -0.588989556 -0.143864858 0.0332551632 -0.3245451022
## tdec -0.157870134 0.092966911 -0.097722453 0.0092514596 -0.1416159968
## pjan 0.206879187 -0.141990574 0.530872235 0.0890666735 -0.0947536147
## pfeb 0.530999363 -0.151466383 -0.533289719 0.2207678709 -0.0675137256
## pmar -0.380592388 0.074655676 0.335006369 -0.1362476881 -0.0616168429
## papr -0.056901612 0.106755938 -0.084786785 -0.0375141498 0.0485745440
## pmay 0.177758906 -0.022014450 0.025024070 0.0376327473 -0.0093294644
## pjun -0.094904165 0.013377094 -0.016298342 -0.0261197497 -0.0346808089
## pjul -0.005543386 -0.049203713 0.044870954 0.0112968029 0.0096717843
## paug 0.047348123 0.015708070 -0.052098593 0.0046396787 0.0009636633
## psep -0.040657537 0.041970363 -0.011347466 0.0246969815 0.0132694536
## poct 0.027120678 -0.090538295 0.148875670 -0.1375823255 -0.0299283689
## pnov -0.283906262 0.105283956 -0.052183791 0.6219718414 0.0532889852
## pdec -0.122022282 0.048156966 -0.325075890 -0.6730608587 0.1687923951
## PC21 PC22 PC23 PC24
## tjan 0.110569448 -0.174362955 0.466461484 0.1410538810
## tfeb 0.411083337 0.195963582 -0.553989382 0.3303973610
## tmar 0.190517645 -0.117562888 0.219088103 -0.6511559490
## tapr -0.404433770 -0.108135234 0.270516403 0.5155541679
## tmay -0.037106821 0.143632598 -0.348991274 -0.1986853412
## tjun 0.254278010 0.063546212 0.239743583 0.0692545700
## tjul -0.179763796 -0.459394939 -0.200353045 -0.0523957985
## taug 0.026308260 0.644090923 0.223105697 0.0795298706
## tsep -0.041652632 -0.338752088 -0.179241161 -0.0007117746
## toct 0.159245830 0.068434255 0.090617300 -0.2078886850
## tnov 0.183602516 -0.198760485 -0.051768256 0.1951652783
## tdec -0.671182075 0.274168418 -0.167825018 -0.2131251230
## pjan -0.025665936 0.023245016 -0.023533194 -0.0018978335
## pfeb -0.017169890 -0.043847725 0.001437087 -0.0140109546
## pmar 0.073977731 0.042827913 0.030519916 -0.0138651710
## papr -0.008348023 0.008701196 -0.001837501 0.0129567032
## pmay -0.007890496 0.009175983 -0.014398707 -0.0095682867
## pjun 0.019589810 -0.050004246 -0.001155038 -0.0001735104
## pjul -0.003853114 0.023997896 -0.014147625 -0.0044508995
## paug 0.004197034 0.012388955 0.011866533 0.0056221737
## psep -0.017989679 -0.007676584 -0.001546521 -0.0008137329
## poct 0.026887105 -0.009846198 -0.006560772 0.0004372792
## pnov -0.015092274 0.074152159 0.081791929 0.0084156928
## pdec -0.018484850 -0.087548286 -0.071983057 0.0171497426
screeplot(wna2.pca)
biplot(wna2.pca)
• Give the total variance from the second PCA. Calculate the total percentage of variance explained by axes 1 and 2 (use summary())
summary(wna2.pca)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6
## Standard deviation 3.4612 2.8065 1.5846 0.84733 0.63986 0.51316
## Proportion of Variance 0.4992 0.3282 0.1046 0.02992 0.01706 0.01097
## Cumulative Proportion 0.4992 0.8274 0.9320 0.96190 0.97896 0.98993
## PC7 PC8 PC9 PC10 PC11 PC12
## Standard deviation 0.29261 0.20707 0.17437 0.15014 0.13534 0.10798
## Proportion of Variance 0.00357 0.00179 0.00127 0.00094 0.00076 0.00049
## Cumulative Proportion 0.99350 0.99528 0.99655 0.99749 0.99825 0.99874
## PC13 PC14 PC15 PC16 PC17 PC18
## Standard deviation 0.09353 0.08322 0.06116 0.05676 0.04584 0.04161
## Proportion of Variance 0.00036 0.00029 0.00016 0.00013 0.00009 0.00007
## Cumulative Proportion 0.99910 0.99939 0.99955 0.99968 0.99977 0.99984
## PC19 PC20 PC21 PC22 PC23 PC24
## Standard deviation 0.03439 0.02946 0.02562 0.02411 0.01802 0.01392
## Proportion of Variance 0.00005 0.00004 0.00003 0.00002 0.00001 0.00001
## Cumulative Proportion 0.99989 0.99993 0.99995 0.99998 0.99999 1.00000
• Examine the ‘loadings’ of the variables on the first two axes (wnaclim.pca$rotation). Name two variables that are highly associated (high positive or negative values) with axis 1 and two that are highly associated with axis 2, and give their scores. #tjul and tjun with axis 1 and papr and pfeb with axis2? # • Produce a map of the sites scores on axis 1, using the quilt.plot() function from the fields package (code to do this is given with the file description below). With reference to the association between the variables and axis 1 (previous question), give a short description of the map (e.g. where do you find negative or positive values and what variables are these associated with?). Does this make sense in terms of what you know about the geography and climate of North America?
wnaclim.pca.score = wna2.pca$x[,1]
quilt.plot(wna$Longitude,wna$Latitude,wnaclim.pca.score)
world(add=TRUE)
# well, the weather grouping more-or-less makes sense, other than categorizing the Sonoran desert areas with the British Columbian coast. #
• Finally, produce a map of the sites scores on the second axis and give a short description of the spatial pattern in terms of the associated variables
wnaclim2.pca.score = wna2.pca$x[,2]
quilt.plot(wna$Longitude,wna$Latitude,wnaclim2.pca.score)
world(add=TRUE)
#the summer temps (june and july) are negatively associated with the warmer areas of the N.American continent and spring precipitation postively with the PNW coastal? #