Scripts R: ACP y Visualizaciones
Scripts R: ACP y Visualizaciones
Scripts R: ACP y Visualizaciones
#Matriz covarianza
var (x)
cor (x)
#Matriz de correlación
mc <- cor(databody[, c(“chest”, “waist”, “hips”)]); mc
round(mc,4) #Redondeando a cuatro decimales
#Distancias
x <- databody [, c(“chest”, “waist”, “hips”)]; x
escalado <- scale (x, center = F, scale = T; escalado
escalado1 <- scale (x, center = F); escalado1
sqrt (sum(databody$chest^2)/(length(databody$chest)-1))
sqrt (sum(databody$waist^2)/(length(databody$waist)-1))
sqrt (sum(databody$hips^2)/(length(databody$hipst)-1))
#Boxplot bivariado
library("MVA")
outcity <- match(lab <- c("Chicago", "Detroit", "Cleveland", "Philadelphia"), rownames(polucion))
x <- polucion[, c("manu", "popul")]
titulo <- "Boxplot Bivariado"
bvbox (x, main=titulo, xlab = mlab, ylab = plab)
text(x$manu[outcity], x$popul[outcity], labels = lab, cex = 0.7, pos = c(2, 2, 4, 2))
#Envolvente convexa
> (hull <- with(polucion, chull(manu, popul)))
[1] 9 15 41 6 2 18 16 14 7
> rownames(polucion)
#Diagrama burbuja
ylim <- with(polucion, range(wind)) * c(0.95, 1)
plot(wind ~ temp, data = polucion, xlab = "Temperatura promedio/anual (Fahrenheit)",
ylab = "Velocidad viento promedio/anual (m.p.h.)", pch = 10, ylim = ylim,
main="Grafico de Burbuja de temperatura, viento y SO2")
with(polucion, symbols(temp, wind, circles = SO2,inches = 0.5, add = TRUE))
#Diagrama de estrella
stars(polucion, key.loc=c(-2,13),cex = 0.6)
#Matriz de dispersión
pairs(polucion, pch = ".", cex = 1.5)