# Some demos of functions presented in # Kozak M, Wnuk A, Krzanowski WJ (2010) 'A simple R function for inspecting multivariate data', # Communications in Biometry and Crop Science 5(1), 34-40. source("http://agrobiol.sggw.waw.pl/~cbcs/articles/5_1_6/functions_www.R") # The simplest call to symb.mv function: data(iris) symb.mv(iris[, 1:4]) # NAs: iris[20, 2] <- NA symb.mv(iris[, 1:4]) # Using the grouping.variables argument to include goruping variables: data(iris) symb.mv(iris[, 1:4], grouping.variables = data.frame(Species = iris$Species)) symb.mv(iris[, 1:4], grouping.variables = data.frame(Sp = abbreviate(iris$Species, 2))) # Ordering by sums of scaled values: symb.mv(iris[, 1:4], grouping.variables = data.frame(Species = iris$Species), ord.method = "sum") # Let's add the information on the species to row names: data(iris) rownames(iris) <- paste(substr(iris$Species, 1, 2), rownames(iris), sep = "_") iris.symb <- symb.mv(iris[, 1:4], grouping.variables = data.frame(Sp = abbreviate(iris$Species, 2))) iris.symb[1:10, ] iris.symb[rownames(iris.symb) == "vi_123", ] iris.symb[rownames(iris.symb) %in% c("se_1", "se_50", "se_123"), ] # Note: there is no 'se_123 row', so only two are printed # Utilizing the cutoff value: data(iris) symb.mv(iris[, 1:4], grouping.variables = data.frame(Sp = abbreviate(iris$Species, 2)), cutoff = 5) symb.mv(iris[, 1:4], grouping.variables = data.frame(Sp = abbreviate(iris$Species, 2)), cutoff = 10) # Notice the warning # But: iris[1, 1] <- 100 symb.mv(iris[, 1:4], grouping.variables = data.frame(Sp = abbreviate(iris$Species, 2)), cutoff = 10) # Also an error, but one case left and is printed. # Writing into text file: data(iris) setwd(tempdir()) iris.symb <- symb.mv(iris[, 1:4], grouping.variables = data.frame(Sp = abbreviate(iris$Species, 2))) write.table(iris.symb, "iris_symb.txt", quote = F, row.names = F, sep = "\t") file.show("iris_symb.txt") # Or a <- symb.mv(iris[, 1:4], grouping.variable = data.frame(species = iris$Species, row = rownames(iris))) a <- a[, c(6, 1:5)] write.table(a, "iris_symb.txt", quote = F, row.names = F, sep = "\t") file.show("iris_symb.txt") # Independently for species: symb.mv(iris[iris$Species == "versicolor", 1:4]) symb.mv(iris[iris$Species == "setosa", 1:4]) symb.mv(iris[iris$Species == "virginica", 1:4]) # Now example on producing plastic film from Krzanowski (1998, p. 381) (see also ?summary.manova) # Krzanowski, W.J. (1988) Principles of Multivariate Analysis. A User's Perspective. Oxford. tear <- c(6.5, 6.2, 5.8, 6.5, 6.5, 6.9, 7.2, 6.9, 6.1, 6.3, 6.7, 6.6, 7.2, 7.1, 6.8, 7.1, 7, 7.2, 7.5, 7.6) gloss <- c(9.5, 9.9, 9.6, 9.6, 9.2, 9.1, 10, 9.9, 9.5, 9.4, 9.1, 9.3, 8.3, 8.4, 8.5, 9.2, 8.8, 9.7, 10.1, 9.2) opacity <- c(4.4, 6.4, 3, 4.1, 0.8, 5.7, 2, 3.9, 1.9, 5.7, 2.8, 4.1, 3.8, 1.6, 3.4, 8.4, 5.2, 6.9, 2.7, 1.9) Y <- cbind(tear, gloss, opacity) rate <- factor(gl(2, 10), labels = c("Low", "High")) additive <- factor(gl(2, 5, length = 20), labels = c("Low", "High")) symb.mv(Y, grouping.variables = data.frame(rate, additive)) symb.mv(Y, grouping.variables = data.frame(rate = abbreviate(rate, 1), add = abbreviate(additive, 1))) # Now writing to a 'symb.html' html page with the symb.mv.www function: library(hwriter) setwd(tempdir()) # or any other directory symb.mv.www(iris[, 1:4], grouping.variables = data.frame(Sp = abbreviate(iris$Species, 2))) symb.mv.www(Y, grouping.variables = data.frame(rate = abbreviate(rate, 1), add = abbreviate(additive, 1))) symb.mv.www(Y, grouping.variables = data.frame(rate = abbreviate(rate, 1), add = abbreviate(additive, 1)), ord.method = "sum") symb.mv.www(Y, cols.for.order = 1, grouping.variables = data.frame(rate = abbreviate(rate, 1), add = abbreviate(additive, 1)), ord.method = "sum")