Este material está disponível em: http://rpubs.com/leonardoreffatti.
setwd("C:/R/Curso do R/MODULO_4.2")
dados<-read.table("peixes.txt", h=T)
dados
## Predador Densidade
## 1 Peixe 10.4993
## 2 Peixe 17.6714
## 3 Peixe 11.1032
## 4 Peixe 4.6647
## 5 Peixe 18.9767
## 6 Peixe 14.2042
## 7 Peixe 14.8269
## 8 Libélula 11.8394
## 9 Libélula 20.9545
## 10 Libélula 7.3108
## 11 Libélula 20.2219
## 12 Libélula 21.4057
## 13 Libélula 19.6589
## 14 Libélula 9.9067
## 15 Libélula 14.5693
## 16 Nenhum 11.0370
## 17 Nenhum 11.1047
## 18 Nenhum 4.9696
## 19 Nenhum 7.7347
## 20 Nenhum 16.9973
## 21 Nenhum 7.6902
## 22 Nenhum 10.1636
## 23 Nenhum 1.9043
## 24 Nenhum 1.7670
## 25 Nenhum 12.1435
attach(dados)
summary(dados)
## Predador Densidade
## Libélula: 8 Min. : 1.767
## Nenhum :10 1st Qu.: 7.735
## Peixe : 7 Median :11.105
## Mean :12.133
## 3rd Qu.:16.997
## Max. :21.406
library(car)
## Loading required package: carData
library(carData)
library(sciplot)
resultado<-aov(Densidade~Predador)
ls(resultado) #lista as partes do objeto
## [1] "assign" "call" "coefficients" "contrasts"
## [5] "df.residual" "effects" "fitted.values" "model"
## [9] "qr" "rank" "residuals" "terms"
## [13] "xlevels"
resultado$residuals
## 1 2 3 4 5 6 7 8
## -2.63590 4.53620 -2.03200 -8.47050 5.84150 1.06900 1.69170 -3.89400
## 9 10 11 12 13 14 15 16
## 5.22110 -8.42260 4.48850 5.67230 3.92550 -5.82670 -1.16410 2.48581
## 17 18 19 20 21 22 23 24
## 2.55351 -3.58159 -0.81649 8.44611 -0.86099 1.61241 -6.64689 -6.78419
## 25
## 3.59231
qqnorm(resultado$residuals, pch=16)
qqline(resultado$residuals, lty=2, col="red")
shapiro.test(resultado$residuals)
##
## Shapiro-Wilk normality test
##
## data: resultado$residuals
## W = 0.95663, p-value = 0.3515
leveneTest(Densidade~Predador)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 2 0.467 0.6329
## 22
summary(resultado)
## Df Sum Sq Mean Sq F value Pr(>F)
## Predador 2 239.0 119.51 4.679 0.0203 *
## Residuals 22 561.9 25.54
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
lineplot.CI(Predador, Densidade, type="p", xlab="Classes de Predadores",
ylab="Densidade",
main="Densidade para cada classe de predadores")
#A densidade de girinos nas poças estuadadas variou conforme a presença de diferentes tipos de predadores (F22,2=4.679 , p=0.0203)
#Podemos afirmar que a presença de libélulas nas poças resulta em uma maior densidade de girinos do que naquelas poças sem a presença de predadores conforme a figura acima.
TukeyHSD(resultado, ordered = TRUE)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
## factor levels have been ordered
##
## Fit: aov(formula = Densidade ~ Predador)
##
## $Predador
## diff lwr upr p adj
## Peixe-Nenhum 4.58401 -1.672465 10.840485 0.1799912
## Libélula-Nenhum 7.18221 1.160144 13.204276 0.0175643
## Libélula-Peixe 2.59820 -3.972413 9.168813 0.5886784
#Libélula-Nenhum apresenta diferença estatística.
#Peixe-Nenhum não apresenta diferença estatística.
#Libélula-Peixe não apresenta diferença estatística.
setwd("C:/R/Curso do R/MODULO_4.2")
dados<-read.table("atividade.txt", h=T)
dados
## Especie Sexo atividade
## 1 sp1 m 0.700204355
## 2 sp1 m 0.976500000
## 3 sp1 m 0.419710309
## 4 sp1 m 0.876000000
## 5 sp1 m 0.791317977
## 6 sp1 f 0.968614165
## 7 sp1 f 0.584332970
## 8 sp1 f 0.844385153
## 9 sp1 f 0.273194567
## 10 sp1 f 0.552834079
## 11 sp2 m 0.759966269
## 12 sp2 m 0.879139758
## 13 sp2 m 0.366845600
## 14 sp2 m 0.428552031
## 15 sp2 m 0.381704877
## 16 sp2 m 0.356849963
## 17 sp2 m 0.859750929
## 18 sp2 m 0.658150571
## 19 sp2 m 0.373728868
## 20 sp2 f 0.037800000
## 21 sp2 f 0.644248833
## 22 sp2 f 0.001000000
## 23 sp2 f 0.214757933
## 24 sp2 f 0.002000000
## 25 sp2 f 0.023304461
## 26 sp3 m 0.230000000
## 27 sp3 m 0.165233769
## 28 sp3 m 0.025207032
## 29 sp3 m 0.609113337
## 30 sp3 m 0.120000000
## 31 sp3 m 0.019000000
## 32 sp3 m 0.020000000
## 33 sp3 m 0.004640789
## 34 sp3 m 0.030065240
## 35 sp3 m 0.010000000
## 36 sp3 m 0.504449523
## 37 sp3 f 0.982337565
## 38 sp3 f 0.396336979
## 39 sp3 f 0.645594529
## 40 sp3 f 0.926249366
## 41 sp3 f 0.911964377
## 42 sp3 f 0.900000000
## 43 sp3 f 0.790000000
## 44 sp3 f 0.890000000
## 45 sp3 f 0.815452440
## 46 sp3 f 0.990000000
## 47 sp3 f 0.402555210
## 48 sp3 f 0.990636424
## 49 sp3 f 0.890000000
## 50 sp3 f 0.542021462
## 51 sp3 f 0.485094367
attach(dados)
summary(dados)
## Especie Sexo atividade
## sp1:10 f:26 Min. :0.0010
## sp2:15 m:25 1st Qu.:0.2224
## sp3:26 Median :0.5420
## Mean :0.5151
## 3rd Qu.:0.8521
## Max. :0.9906
library(car)
library(carData)
library(sciplot)
library(ExpDes)
##
## Attaching package: 'ExpDes'
## The following object is masked from 'package:stats':
##
## ccf
resultado <- aov(atividade~Especie*Sexo)
ls(resultado) #lista as partes do objeto
## [1] "assign" "call" "coefficients" "contrasts"
## [5] "df.residual" "effects" "fitted.values" "model"
## [9] "qr" "rank" "residuals" "terms"
## [13] "xlevels"
resultado$residuals
## 1 2 3 4 5
## -0.052542173 0.223753472 -0.333036219 0.123253472 0.038571449
## 6 7 8 9 10
## 0.323941978 -0.060339217 0.199712966 -0.371477620 -0.091838108
## 11 12 13 14 15
## 0.197223062 0.316396551 -0.195897607 -0.134191176 -0.181038330
## 16 17 18 19 20
## -0.205893244 0.297007722 0.095407364 -0.189014339 -0.116051871
## 21 22 23 24 25
## 0.490396962 -0.152851871 0.060906062 -0.151851871 -0.130547410
## 26 27 28 29 30
## 0.072026392 0.007260161 -0.132766576 0.451139729 -0.037973608
## 31 32 33 34 35
## -0.138973608 -0.137973608 -0.153332819 -0.127908368 -0.147973608
## 36 37 38 39 40
## 0.346475915 0.211788050 -0.374212536 -0.124954986 0.155699851
## 41 42 43 44 45
## 0.141414862 0.129450485 0.019450485 0.119450485 0.044902925
## 46 47 48 49 50
## 0.219450485 -0.367994305 0.220086909 0.119450485 -0.228528053
## 51
## -0.285455148
qqnorm(resultado$residuals, pch=16)
qqline(resultado$residuals, lty=2, col="red")
shapiro.test(resultado$residuals)
##
## Shapiro-Wilk normality test
##
## data: resultado$residuals
## W = 0.96878, p-value = 0.1968
leveneTest(atividade~Especie)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 2 2.7039 0.07714 .
## 48
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
leveneTest(atividade~Sexo)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 1 0.0807 0.7775
## 49
summary(resultado)
## Df Sum Sq Mean Sq F value Pr(>F)
## Especie 2 0.5390 0.2695 5.259 0.00886 **
## Sexo 1 0.3698 0.3698 7.215 0.01009 *
## Especie:Sexo 2 2.6427 1.3214 25.783 3.46e-08 ***
## Residuals 45 2.3062 0.0512
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
lineplot.CI(Especie, atividade, Sexo, type=, xlab="Atividade",
ylab="Especie", main="atividade para especies e sexos")
TukeyHSD(resultado, ordered = TRUE)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
## factor levels have been ordered
##
## Fit: aov(formula = atividade ~ Especie * Sexo)
##
## $Especie
## diff lwr upr p adj
## sp3-sp2 0.1121961 -0.06569951 0.2900917 0.2874089
## sp1-sp2 0.2995227 0.07553198 0.5235134 0.0062351
## sp1-sp3 0.1873266 -0.01683321 0.3914864 0.0779859
##
## $Sexo
## diff lwr upr p adj
## f-m 0.168324 0.04060594 0.2960421 0.0109426
##
## $`Especie:Sexo`
## diff lwr upr p adj
## sp3:m-sp2:f 0.004121737 -0.33779827 0.3460417 1.0000000
## sp2:m-sp2:f 0.408891336 0.05381578 0.7639669 0.0155759
## sp1:f-sp2:f 0.490820316 0.08286956 0.8987711 0.0101879
## sp1:m-sp2:f 0.598894657 0.19094390 1.0068454 0.0009724
## sp3:f-sp2:f 0.616697643 0.29126552 0.9421298 0.0000153
## sp2:m-sp3:m 0.404769599 0.10196015 0.7075791 0.0032156
## sp1:f-sp3:m 0.486698579 0.12332724 0.8500699 0.0031398
## sp1:m-sp3:m 0.594772920 0.23140158 0.9581443 0.0001955
## sp3:f-sp3:m 0.612575906 0.34514184 0.8800100 0.0000003
## sp1:f-sp2:m 0.081928979 -0.29384767 0.4577056 0.9864594
## sp1:m-sp2:m 0.190003321 -0.18577333 0.5657800 0.6630503
## sp3:f-sp2:m 0.207806307 -0.07625414 0.4918668 0.2684637
## sp1:m-sp1:f 0.108074341 -0.31801633 0.5341650 0.9735560
## sp3:f-sp1:f 0.125877328 -0.22202425 0.4737789 0.8880109
## sp3:f-sp1:m 0.017802986 -0.33009859 0.3657046 0.9999877
fat2.crd(Especie,Sexo,atividade,quali=c(TRUE,TRUE),mcomp="tukey",fac.names=c("Especie","Sexo"),sigT=0.05,sigF=0.05)
## ------------------------------------------------------------------------
## Legend:
## FACTOR 1: Especie
## FACTOR 2: Sexo
## ------------------------------------------------------------------------
##
##
## Analysis of Variance Table
## ------------------------------------------------------------------------
## DF SS MS Fc Pr>Fc
## Especie 2 0.5390 0.26951 5.2589 0.0088628
## Sexo 1 0.3698 0.36978 7.2154 0.0100889
## Especie*Sexo 2 2.6427 1.32135 25.7830 0.0000000
## Residuals 45 2.3062 0.05125
## Total 50 5.8577
## ------------------------------------------------------------------------
## CV = 43.95 %
##
## ------------------------------------------------------------------------
## Shapiro-Wilk normality test
## p-value: 0.1967811
## According to Shapiro-Wilk normality test at 5% of significance, residuals can be considered normal.
## ------------------------------------------------------------------------
##
##
##
## Significant interaction: analyzing the interaction
## ------------------------------------------------------------------------
##
## Analyzing Especie inside of each level of Sexo
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
## DF SS MS Fc Pr.Fc
## Sexo 1 0.36978 0.36978 7.2154 0.0101
## Especie:Sexo f 2 1.64015 0.82008 16.0018 0
## Especie:Sexo m 2 1.49204 0.74602 14.5568 0
## Residuals 45 2.30620 0.05125
## Total 50 5.85770
## ------------------------------------------------------------------------
##
##
##
## Especie inside of the level f of Sexo
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a 3 0.7705495
## a 1 0.6446722
## b 2 0.1538519
## ------------------------------------------------------------------------
##
##
## Especie inside of the level m of Sexo
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a 1 0.7527465
## a 2 0.5627432
## b 3 0.1579736
## ------------------------------------------------------------------------
##
##
##
## Analyzing Sexo inside of each level of Especie
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
## DF SS MS Fc Pr.Fc
## Especie 2 0.53902 0.26951 5.2589 0.0089
## Sexo:Especie sp1 1 0.02920 0.0292 0.5698 0.4543
## Sexo:Especie sp2 1 0.60189 0.60189 11.7445 0.0013
## Sexo:Especie sp3 1 2.38139 2.38139 46.4671 0
## Residuals 45 2.30620 0.05125
## Total 50 5.85770
## ------------------------------------------------------------------------
##
##
##
## Sexo inside of the level sp1 of Especie
##
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
## Levels Means
## 1 1 0.6446722
## 2 2 0.7527465
## ------------------------------------------------------------------------
##
##
## Sexo inside of the level sp2 of Especie
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a 2 0.5627432
## b 1 0.1538519
## ------------------------------------------------------------------------
##
##
## Sexo inside of the level sp3 of Especie
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a 1 0.7705495
## b 2 0.1579736
## ------------------------------------------------------------------------