Este relatório aplica técnicas de Análise Multivariada a dados agrometeorológicos, incluindo estatística descritiva, correlação, Análise de Componentes Principais (PCA), clusterização e visualização tridimensional.
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(FactoMineR)
library(factoextra)
library(cluster)
library(corrplot)
library(plotly)
library(htmlwidgets)
dados <- read.csv("https://raw.githubusercontent.com/leocbc/ANALISE-MULTIVARIADA/main/agro_meteoro.csv")
head(dados)
summary(dados)
## Data Precipitacao_mm Temp_Max_C Temp_Min_C
## Length:48 Min. :12.10 Min. :26.50 Min. :17.90
## Class :character 1st Qu.:17.52 1st Qu.:28.85 1st Qu.:19.38
## Mode :character Median :22.70 Median :30.85 Median :20.50
## Mean :23.14 Mean :31.49 Mean :20.69
## 3rd Qu.:28.52 3rd Qu.:34.15 3rd Qu.:21.73
## Max. :35.20 Max. :37.50 Max. :24.10
## Umidade_Relativa_. Veloc_Vento_km_h Insolacao_h Evapotranspiracao_mm
## Min. :60.00 Min. : 6.50 Min. : 5.400 Min. :2.700
## 1st Qu.:70.75 1st Qu.:10.03 1st Qu.: 6.800 1st Qu.:3.375
## Median :77.50 Median :12.60 Median : 7.650 Median :3.750
## Mean :76.27 Mean :13.21 Mean : 7.685 Mean :3.808
## 3rd Qu.:83.00 3rd Qu.:16.27 3rd Qu.: 8.525 3rd Qu.:4.225
## Max. :90.00 Max. :21.70 Max. :10.100 Max. :5.200
## Produtividade_soja_sc_ha Produtividade_milho_sc_ha
## Min. :56.10 Min. :110.3
## 1st Qu.:61.88 1st Qu.:116.8
## Median :66.00 Median :121.0
## Mean :65.57 Mean :121.0
## 3rd Qu.:69.28 3rd Qu.:124.9
## Max. :74.20 Max. :132.7
dados_num <- dados %>% select(where(is.numeric))
cor_mat <- cor(dados_num, use = "pairwise.complete.obs")
corrplot(cor_mat, method = "color", type = "upper", tl.col = "black", tl.srt = 45)
dados_scaled <- scale(dados_num)
pca <- prcomp(dados_scaled, center = TRUE, scale. = TRUE)
summary(pca)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 2.9611 0.35189 0.19276 0.17547 0.14217 0.09893 0.07277
## Proportion of Variance 0.9742 0.01376 0.00413 0.00342 0.00225 0.00109 0.00059
## Cumulative Proportion 0.9742 0.98797 0.99210 0.99552 0.99777 0.99886 0.99945
## PC8 PC9
## Standard deviation 0.06129 0.03515
## Proportion of Variance 0.00042 0.00014
## Cumulative Proportion 0.99986 1.00000
fviz_pca_biplot(pca, label = "var", repel = TRUE)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## ℹ The deprecated feature was likely used in the ggpubr package.
## Please report the issue at <https://github.com/kassambara/ggpubr/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
pca_3d <- plot_ly(
x = pca$x[,1],
y = pca$x[,2],
z = pca$x[,3],
type = "scatter3d",
mode = "markers"
)
pca_3d
saveWidget(pca_3d, "PCA_3D.html", selfcontained = TRUE)
Observação: o gráfico interativo 3D é salvo automaticamente no arquivo PCA_3D.html, que deve ser aberto no navegador.
dist_eucl <- dist(dados_scaled)
hc_ward <- hclust(dist_eucl, method = "ward.D2")
plot(hc_ward)
rect.hclust(hc_ward, k = 3, border = 2:4)
set.seed(123)
k3 <- kmeans(dados_scaled, centers = 3, nstart = 25)
k3
## K-means clustering with 3 clusters of sizes 18, 17, 13
##
## Cluster means:
## Precipitacao_mm Temp_Max_C Temp_Min_C Umidade_Relativa_. Veloc_Vento_km_h
## 1 -0.2090586 0.01769498 0.005498036 -0.02556993 0.02639127
## 2 1.1121828 -1.03775882 -1.008528840 1.03681952 -1.03666350
## 3 -1.1649270 1.33256848 1.311232741 -1.32043638 1.31909512
## Insolacao_h Evapotranspiracao_mm Produtividade_soja_sc_ha
## 1 0.09621403 0.0317782 -0.07649904
## 2 -1.06452849 -1.0230443 1.05447539
## 3 1.25885629 1.2938266 -1.27300761
## Produtividade_milho_sc_ha
## 1 -0.1609129
## 2 1.0850327
## 3 -1.1960865
##
## Clustering vector:
## [1] 1 1 2 3 2 3 2 1 2 1 1 3 2 1 2 3 2 1 1 3 2 1 1 3 2 3 2 1 1 3 2 1 1 3 2 1 2 3
## [39] 2 1 3 2 1 2 3 2 1 3
##
## Within cluster sum of squares by cluster:
## [1] 20.37487 23.35935 18.15434
## (between_SS / total_SS = 85.4 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
fviz_cluster(k3, data = dados_scaled)
A PCA evidenciou padrões multivariados relevantes entre as variáveis agrometeorológicas. O gráfico 3D permite melhor visualização da separação entre observações no espaço multivariado, complementando a análise 2D.
As técnicas multivariadas aplicadas demonstram forte potencial para análise integrada de dados climáticos e agrícolas, auxiliando o planejamento e a tomada de decisão no setor agroambiental.