\documentclass[a4paper, oneside, 10pt]{article} \usepackage[unicode]{hyperref} \usepackage[utf8x]{inputenc} \usepackage[english]{babel} \usepackage{listings} \date{\today} \title{} \author{} \begin{document} \begin{itemize} \item Array \item Array \end{itemize} \subsection{\texorpdfstring{ANÁLISES EXPLORATÓRIAS DE DADOS}{ANALISES EXPLORATORIAS DE DADOS}} \label{sec:analises_exploratorias_de_dados} \subsubsection{\texorpdfstring{Preparação dos dados e programa}{Preparaao dos dados e programa}} \label{sec:preparaao_dos_dados_e_programa} As análises abaixo serão realizadas em ambiente R e para isso teremos que instalar alguns pacotes, abaixo estão todos os comandos necessários para a realização da atividade. 1) Crie um diretório (pasta), copie os arquivos de dados abaixo para esse diretório e faça a descompactação no mesmo diretório: \begin{itemize} \item \href{media/planeco/roteiro/univar1.csv.zip}{univar.zip} \item \href{media/planeco/roteiro/autocorr.csv.zip}{autocorr.zip} \end{itemize} 2) Abra o R no seu computador e mude o diretório de trabalho para o diretório (\emph{i.e.} a pasta) que você criou, usando o menu \textbf{\emph{Arquivo}} \textgreater \textbf{\emph{mudar dir...}}. 3) Instale os pacotes \emph{car} e \emph{lattice}. Para isso, basta copiar e colar os comandos que estão nas caixas de cor cinza:\lstset{frame=single} \begin{lstlisting} install.packages("car") \end{lstlisting} Espere finalizar todo o processo de instalação desse pacote para iniciar o próximo: \lstset{frame=single} \begin{lstlisting} install.packages("lattice") \end{lstlisting} 4) Agora carregue os pacotes:\lstset{frame=single} \begin{lstlisting} library(car) library(lattice) library (graphics) \end{lstlisting} \subsubsection{\texorpdfstring{ANALISANDO DADOS UNIVARIADOS}{ANALISANDO DADOS UNIVARIADOS}} \label{sec:analisando_dados_univariados} 1) importe o conjunto de dados para o R\lstset{frame=single} \begin{lstlisting} univar1<-read.csv("univar1.csv") \end{lstlisting} 2) Use a função \emph{head} para visualizar as 5 primeiras linhas do conjunto de dados\lstset{frame=single} \begin{lstlisting} head(univar1) \end{lstlisting} 3) Inspecione o resumo dos dados\lstset{frame=single} \begin{lstlisting} summary(univar1) \end{lstlisting} \paragraph{\texorpdfstring{Conhecendo os dados:}{Conhecendo os dados}} \label{sec:conhecendo_os_dados} 4) Se quiser, visualize o conjunto de dados como uma planilha convencional\lstset{frame=single} \begin{lstlisting} edit(univar1) \end{lstlisting} \subsubsection{\texorpdfstring{Análises gráficas}{Analises graficas}} \label{sec:analises_graficas} \lstset{frame=single} \begin{lstlisting} par(mfrow = c(2,2)) ##Aqui estamos criando um layout para colocar os quatro gráficos juntos hist(univar1$COMPRIMENTO_BICO) hist(univar1$BIOMASSA_AVE) hist(univar1$BIOMASSA_INSETOS) hist(univar1$TAMANHO_SEMENTES) par(mfrow=c(1,1)) ## voltando ao padrão de apresentar apenas 1 gráfico por página \end{lstlisting} \lstset{frame=single} \begin{lstlisting} #use o argumento breaks para determinar o número de classes par(mfrow = c(2,2)) hist(univar1$COMPRIMENTO_BICO, breaks = 20) hist(univar1$BIOMASSA_AVE, breaks = 20) hist(univar1$BIOMASSA_INSETOS, breaks = 20) hist(univar1$TAMANHO_SEMENTES, breaks = 20) par(mfrow=c(1,1)) \end{lstlisting} \lstset{frame=single} \begin{lstlisting} par(mfrow = c(2,2)) hist(univar1$COMPRIMENTO_BICO, breaks = 10) hist(univar1$BIOMASSA_AVE, breaks = 10) hist(univar1$BIOMASSA_INSETOS, breaks = 10) hist(univar1$TAMANHO_SEMENTES, breaks = 10) par(mfrow=c(1,1)) \end{lstlisting} \lstset{frame=single} \begin{lstlisting} par(mfrow = c(2,2)) plot(density(univar1$COMPRIMENTO_BICO)) plot(density(univar1$BIOMASSA_AVE)) plot(density(univar1$BIOMASSA_INSETOS)) plot(density(univar1$TAMANHO_SEMENTES)) par(mfrow=c(1,1)) \end{lstlisting} Podemos juntar esses dois gráficos em um só. Para isso, use o código abaixo:\lstset{frame=single} \begin{lstlisting} par(mfrow = c(2,2)) hist(univar1$COMPRIMENTO_BICO, prob=T ) lines(density(univar1$COMPRIMENTO_BICO)) hist(univar1$BIOMASSA_AVE, prob=T) lines(density(univar1$BIOMASSA_AVE)) hist(univar1$BIOMASSA_INSETOS, prob=T) lines(density(univar1$BIOMASSA_INSETOS)) hist(univar1$TAMANHO_SEMENTES, prob=T) lines(density(univar1$TAMANHO_SEMENTES)) par(mfrow=c(1,1)) \end{lstlisting} Podemos também mostrar, na parte inferior do gráfico de densidade, o número de observações em cada faixa do gráfico. Para isso vamos usar a função \emph{rug()}\lstset{frame=single} \begin{lstlisting} par(mfrow = c(2,2)) plot(density(univar1$COMPRIMENTO_BICO)) rug(univar1$COMPRIMENTO_BICO, side=1) plot(density(univar1$BIOMASSA_AVE)) rug(univar1$BIOMASSA_AVE, side=1) plot(density(univar1$BIOMASSA_INSETOS)) rug(univar1$BIOMASSA_INSETOS, side=1) plot(density(univar1$TAMANHO_SEMENTES)) rug(univar1$TAMANHO_SEMENTES, side=1) par(mfrow=c(1,1)) \end{lstlisting} Todas essas informações nos auxiliam para identificarmos a quais distribuições teóricas nossos dados se ajustam.\lstset{frame=single} \begin{lstlisting} (sort(univar1$COMPRIMENTO_BICO)) \end{lstlisting} Mas temos uma função que faz isso por nós:\lstset{frame=single} \begin{lstlisting} boxplot(univar1$COMPRIMENTO_BICO, range=0) \end{lstlisting} Vamos fazer um boxplot modificado com os nossos dados de COMPRIMENTO\_BICO\lstset{frame=single} \begin{lstlisting} boxplot(univar1$COMPRIMENTO_BICO) \end{lstlisting} \lstset{frame=single} \begin{lstlisting} boxplot(univar1$BIOMASSA_INSETOS ~ univar1$NIVEL_DISTURBIO) \end{lstlisting} \lstset{frame=single} \begin{lstlisting} boxplot(univar1$BIOMASSA_INSETOS ~ univar1$NIVEL_DISTURBIO, notch=TRUE) \end{lstlisting} \textbf{E agora, você está mais seguro(a) para afirmar se a biomassa de insetos difere ou não entre os dois níveis de distúrbio?} \subsubsection{\texorpdfstring{CHECANDO O AJUSTE DOS DADOS A UMA DISTRIBUIÇÃO}{CHECANDO O AJUSTE DOS DADOS A UMA DISTRIBUIAO}} \label{sec:checando_o_ajuste_dos_dados_a_uma_distribuiao} Vamos então aplicar as funções abaixo aos nossos dados:\lstset{frame=single} \begin{lstlisting} par(mfrow = c(2,2)) qqnorm(univar1$COMPRIMENTO_BICO) qqline(univar1$COMPRIMENTO_BICO) qqnorm(univar1$BIOMASSA_AVE) qqline(univar1$BIOMASSA_AVE) qqnorm(univar1$BIOMASSA_INSETOS) qqline(univar1$BIOMASSA_INSETOS) qqnorm(univar1$TAMANHO_SEMENTES) qqline(univar1$TAMANHO_SEMENTES) par(mfrow=c(1,1)) \end{lstlisting} \subsubsection{\texorpdfstring{AVALIANDO AUTOCORRELAÇÃO}{AVALIANDO AUTOCORRELAAO}} \label{sec:avaliando_autocorrelaao} Para essa parte do tutorial, importe o conjunto de dados ,,autocorr.csv" para o R e inspecione os dados:\lstset{frame=single} \begin{lstlisting} autocorr<-read.csv("autocorr.csv") head(autocorr) summary(autocorr) \end{lstlisting} \lstset{frame=single} \begin{lstlisting} lag.plot(autocorr$x1, do.lines = FALSE, diag=FALSE) lag.plot(autocorr$x2, do.lines = FALSE, diag=FALSE) \end{lstlisting} \subsubsection{\texorpdfstring{ANALISANDO DADOS BIVARIADOS}{ANALISANDO DADOS BIVARIADOS}} \label{sec:analisando_dados_bivariados} \lstset{frame=single} \begin{lstlisting} bivar<-read.csv("bivar.csv") head(bivar) summary (bivar) \end{lstlisting} \lstset{frame=single} \begin{lstlisting} plot(bivar$y.l ~ bivar$x.l) \end{lstlisting} \lstset{frame=single} \begin{lstlisting} plot(bivar$y.l ~ bivar$x.l) lines(lowess(bivar$y.l ~ bivar$x.l)) \end{lstlisting} \lstset{frame=single} \begin{lstlisting} plot(bivar$y.n ~ bivar$x.n) lines(lowess(bivar$y.n ~ bivar$x.n)) \end{lstlisting} \lstset{frame=single} \begin{lstlisting} #grafico do pacote car scatterplot (bivar$y.l ~ bivar$x.l) \end{lstlisting} \lstset{frame=single} \begin{lstlisting} scatterplot (bivar$y.n ~ bivar$x.n) \end{lstlisting} \subsubsection{\texorpdfstring{Transformando os dados}{Transformando os dados}} \label{sec:transformando_os_dados} \lstset{frame=single} \begin{lstlisting} scatterplot(univar1$COMPRIMENTO_BICO ~ univar1$BIOMASSA_AVE) \end{lstlisting} Como podemos observar pelos boxplots laterais, nesse caso, aparentemente são os dados da variável Y que parecem estar afetando a linearidade da relação. Então, vamos transformar os dados de Y pelo logaritmo natural e ver se o ajuste melhora.\lstset{frame=single} \begin{lstlisting} scatterplot (log(univar1$COMPRIMENTO_BICO) ~ univar1$BIOMASSA_AVE) \end{lstlisting} \end{document}