#table 16.1, p. 384--first 15 obs. print( companies[ 1:15, ]) #copying into a new data frame containing standardized #version of all the numeric variables. companies.std <- companies attach(companies.std) companies.std$pe.std <- ( pe-mean(pe) ) / stdev(pe) companies.std$ror5.std <- ( ror5 -mean(ror5 ) ) / stdev(ror5 ) companies.std$de.std <- ( de -mean(de ) ) / stdev(de ) companies.std$salesgr5.std <- ( salesgr5 -mean(salesgr5 ) ) / stdev(salesgr5 ) companies.std$eps5.std <- ( eps5 -mean(eps5 ) ) / stdev(eps5 ) companies.std$npm1.std <- ( npm1 -mean(npm1 ) ) / stdev(npm1 ) companies.std$payoutr1.std <- ( payoutr1 -mean(payoutr1 ) ) / stdev(payoutr1 ) detach(companies.std) #table 16.2, p. 386--first 15 obs. print( companies.std[1:15, cbind( 1, 2, 3, 13, 14, 15, 16, 17, 12, 11)]) #looking at the first obs to be graphed in fig. 16.3. print(companies.std[1, cbind( 13, 14, 15, 16, 17, 12, 18) ] ) #creating the transposed data in order to generate the profile diagram. var1 <- rbind( 1, 2, 3, 4, 5, 6, 7) values1 <- rbind( 0.962932, -0.007359609, 0.4290669, 0.2774933, 1.28929, -0.2373285, 0.1505715) graph <- data.frame(values, var1) #Fig. 16.3, p. 387. plot(graph$var1, graph$values, ylim=c(-3, 2.5), type="b", ylab="Standardized Values", xlab="Variables") abline(h=0) legend(1, -0.5, c("1=ror5", "2=de", "3=salesgr5", "4=eps5", "5=npm1", "6=pe", "7=payoutr1")) #Looking at values for obs 15-21 to add to the graph data set. print(companies.std[15:21, cbind(13, 14, 15, 16, 17, 12, 18)] ) graph$values15 <- rbind(0.4731518, 3.672444925, 2.9025115, 2.5342160, 0.6660147, 2.2177940, 0.1347352) graph$values16 <- rbind(0.5865269, 0.360620844, 1.3881577, 1.2327199, 1.0666919, 2.4223876, 1.9789110) graph$values17 <- rbind(0.7754852, 0.912591524, 2.7636957, 1.3640635, 0.2653374, 1.8086069, 0.8403831) graph$values18 <- rbind(0.5487352, 0.728601298, 0.6688396, 1.0416746, 0.7550541, 1.8086069, 0.8380698) graph$values19 <- rbind(-0.9251403, -0.743320516, -0.1009569, 0.3610756, 0.6214950, 0.7856392, 0.8380698) graph$values20 <- rbind(-1.7943489, -0.007359609, -0.1892942, -0.1881796, -1.2483323, -0.4419221, -1.5364365) graph$values21 <- rbind(-3.0036826, -0.927310743, -0.2271531, -0.1881796, -1.2038126, -0.2373285, -1.3708303) #Fig. 16.4, p. 388. plot(graph$var1, graph$values15, ylim=c(-4, 4), type="b", ylab="Standardized Values", xlab="Variables", pch=2) abline(h=0) legend(2.5, -1.5, c("1= -1*ror5", "2=de", "3=salesgr5", "4=eps5", "5=npm1", "6=pe", "7= -1*payoutr1")) points(graph$var1, graph$values16, type="b", pch=6) points(graph$var1, graph$values17, type="b", pch=18) points(graph$var1, graph$values18, type="b", pch=0) points(graph$var1, graph$values19, type="b", pch=15) points(graph$var1, graph$values20, type="b", pch=5, lty=4) points(graph$var1, graph$values21, type="b", pch=17, lty=4) legend(5.2, -1.5, c("obs 15", "obs 16", "obs 17", "obs 18", "obs 19", "obs 20", "obs 21"), marks=c(2, 6, 18, 0, 15, 5, 17)) #creating the subset for use in the function agnes. comp.subset <- companies.std[, cbind(12, 13, 14, 15, 16, 11, 17)] #fig. 16.9, p. 399. #Not an exact match to the figure in the book but very close. plot(agnes(comp.subset),which=2) #creating the matrix to be used in the function pam. attach(companies.std) comp.subset <- cbind(ror5, de, salesgr5, eps5, npm1, pe, payoutr1) detach(companies.std) #Table 16.4, p. 401. #Three clusters pam3 <- pam( comp.subset,3) print(pam3$clustering) #Four clusters pam4 <- pam( comp.subset,4) print(pam4$clustering)