Os dados foram obtidos a partir do mapa interativo do Censo agropecuário 2017.
Foi extraído o shapefile do estado do Paraná, com a delimitação municipal. Com o auxílio do QGis, extrai a tabela de atributos. E feito o download da tabela de dados da webpage Censo Agropecuário 2017
A tabela de atributos tem dados do Rendimento médio(kg/ha) dos produtos: arroz, cana, mandioca, milho, soja, trigo, cacau, café, laranja e uva. Para o feijão, extraído pela ferramenta do site e calculado o rendimento (produção_kg/area colhida_ha).
Rendimento médio = quociente entre produção e área colhida.
Redução da dimensionalidade dos dados
Reduzir o número de variáveis, tentar representar as 11 variáveis em uma ou duas.
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidyr)library(vegan)
Warning: package 'vegan' was built under R version 4.3.1
Carregando pacotes exigidos: permute
Warning: package 'permute' was built under R version 4.3.1
Carregando pacotes exigidos: lattice
This is vegan 2.6-4
library(ggplot2)cultivos_num<-readr::read_delim("pr_limpo_delim_num.csv") #separado por ";" e nao fica com caracteres especiais
Rows: 399 Columns: 11
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
dbl (11): municipio, arroz, cana, mandioca, milho, soja, trigo, cacau, café,...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#log transformacao cbind(log(cultivos_num[-1]+1))->cultivos.log#padronizaçaodecostand(cultivos.log, method ="stand")->cultivos.std#sd de todas as variaveis = 1sd(cultivos.std$arroz)
#standard deviation: variacao do componente#proportion of variance: quanto o eixo sumarizou a variacao#cumulative proportion: quanto das variaveis podem ser interpretadas pelos componentessummary(pca.std)
#componentes 1,2,3... sao interpretados pq superam o valor esperado pelo modelo nulo(?)biplot(pca.std)
#correlacao de pearson, deve dar proximo de zero (baixa correlacao entre as variaveis)cor(pca.std$scores[,1],pca.std$scores[,2])
[1] 1.823879e-17
#pca.std$scores
Nova tentativa: sem cacau e acrescentando o feijão
cultivos_new<-readr::read_delim("cultivos por mun PR_edit2.csv")
Rows: 399 Columns: 11
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
chr (1): municipio
dbl (10): arroz, cana, mandioca, milho, soja, trigo, café, laranja, uva, feijao
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `municipio = .Primitive("as.double")(municipio)`.
Caused by warning:
! NAs introduzidos por coerção
#log transformacao cbind(log(dados.num[-1]+1))->cultivos.log#padronizaçaodecostand(cultivos.log, method ="stand")->cultivos.std#sd de todas as variaveis = 1sd(cultivos.std$arroz)
#standard deviation: variacao do componente#proportion of variance: quanto o eixo sumarizou a variacao#cumulative proportion: quanto das variaveis podem ser interpretadas pelos componentessummary(pca.std)
#componentes 1,2,3... sao interpretados pq superam o valor esperado pelo modelo nulo(?)biplot(pca.std)
#correlacao de pearson, deve dar proximo de zero (baixa correlacao entre as variaveis) pq estao padronizados e logaritmizadoscor(pca.std$scores[,1],pca.std$scores[,2])
[1] 8.96492e-17
#pca.std$scores
Voltando uma etapa: checar alguma possível correlação entre as variáveis
cultivos_num<-readr::read_delim("cultivos por mun PR_edit3.csv")
Rows: 399 Columns: 11
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
dbl (11): municipio, arroz, cana, mandioca, milho, soja, trigo, café, laranj...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Warning: package 'corrplot' was built under R version 4.3.1
corrplot 0.92 loaded
corrplot(cor2, method="circle")
O milho, a soja e o trigo apresentam correlação.
PCA sem trigo e soja
correlação do milho com trigo e soja foi moderada (cor=<0.55)
retirei os dados de trigo e soja
cultivos_sts<-readr::read_delim("cultivos por mun PR_edit4.csv")
Rows: 399 Columns: 9
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
dbl (9): municipio, arroz, cana, mandioca, milho, café, laranja, uva, feijao
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#log transformacao cbind(log(cultivos_sts[-1]+1))->cultivos.log_sts#padronizaçaodecostand(cultivos.log_sts, method ="stand")->cultivos.std_sts#sd de todas as variaveis = 1sd(cultivos.std_sts$arroz)
#standard deviation: variacao do componente#proportion of variance: quanto o eixo sumarizou a variacao#cumulative proportion: quanto das variaveis podem ser interpretadas pelos componentessummary(pca.std_sts)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 1.3944369 1.1809533 1.0260774 0.9779766 0.8971533
Proportion of Variance 0.2436675 0.1747694 0.1319350 0.1198552 0.1008633
Cumulative Proportion 0.2436675 0.4184368 0.5503719 0.6702270 0.7710903
Comp.6 Comp.7 Comp.8
Standard deviation 0.83571019 0.75606183 0.74608758
Proportion of Variance 0.08752079 0.07163322 0.06975566
Cumulative Proportion 0.85861112 0.93024434 1.00000000
#loadings: importancia da variavel para o componenteloadings(pca.std_sts)
#correlacao de pearson, deve dar proximo de zero (baixa correlacao entre as variaveis)cor(pca.std_sts$scores[,1],pca.std_sts$scores[,2])
[1] -1.561922e-16
#pca.std_sts$scores
Feijão também teve correlação (mais fraca) com milho (cor = 0.32)
PCA sem trigo, soja e feijão
cultivos_sf<-readr::read_delim("cultivos por mun PR_edit5.csv")
Rows: 399 Columns: 8
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
dbl (8): municipio, arroz, cana, mandioca, milho, café, laranja, uva
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 1.3312714 1.1292297 1.0198270 0.9672906 0.8710623
Proportion of Variance 0.2538195 0.1826234 0.1489515 0.1340003 0.1086651
Cumulative Proportion 0.2538195 0.4364429 0.5853943 0.7193946 0.8280597
Comp.6 Comp.7
Standard deviation 0.80243178 0.74610225
Proportion of Variance 0.09221637 0.07972389
Cumulative Proportion 0.92027611 1.00000000
Cana teve correlação (correlação foi fraca) com milho (cor = 0.31)
PCA sem trigo, soja, feijão e mandioca
cultivos_sm<-readr::read_delim("cultivos por mun PR_edit6.csv")
Rows: 399 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
dbl (7): municipio, arroz, cana, milho, café, laranja, uva
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 1.2949127 1.1190960 0.9683417 0.9048732 0.8215723
Proportion of Variance 0.2801687 0.2092537 0.1566736 0.1368088 0.1127795
Cumulative Proportion 0.2801687 0.4894224 0.6460960 0.7829048 0.8956843
Comp.6
Standard deviation 0.7901426
Proportion of Variance 0.1043157
Cumulative Proportion 1.0000000
biplot(pca.std_sm)
Mandioca teve correlação (bem fraca) com cana (cor = -0.23)
PCA sem trigo, soja, feijão, mandioca e cana
cultivos_sc<-readr::read_delim("cultivos por mun PR_edit7.csv")
Rows: 399 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ";"
dbl (6): municipio, arroz, milho, café, laranja, uva
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.