——————————————————————————————————————————————————————————–

Base de dados: PENDRIVE (N:)

## [1] "N:/_IFMG/_MESTRADO/ANALISE_DE_DADOS/trabalho_01"

Apaga variáveis do ambiente R:

rm(list=ls())

Carregando bibliotecas R:

Biblioteca PWR:

#install.packages("pwr") 
library(pwr)

Biblioteca para Tabela de Distribuição de Frequências:

#install.packages("sm") # comando para instalação da biblioteca sm #
library("sm")

——————————————————————————————————————————————————————————–

Lista de Exercícios - Tema: Intervalos de Confiança e Testes de Hipóteses

Desenvolvimento:

vet_obs<-c(57,60,49,50,51,60,49,53,49,56,64,60,49,52,69,40,44,38,53,66)

summary(vet_obs)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   38.00   49.00   52.50   53.45   60.00   69.00
stem(sort(vet_obs))
## 
##   The decimal point is 1 digit(s) to the right of the |
## 
##   3 | 8
##   4 | 049999
##   5 | 0123367
##   6 | 000469
# Análise via boxplot:

boxplot(vet_obs)

# Aplicando t.test:

#Desvio padrão das observações:
sd(vet_obs)
## [1] 8.165879
# Teste com alpha=5% Opção: two.sided - mu=0
t.test(vet_obs,alternative=c("two.sided"),mu=50,conf.level=0.95)
## 
##  One Sample t-test
## 
## data:  vet_obs
## t = 1.8894, df = 19, p-value = 0.07419
## alternative hypothesis: true mean is not equal to 50
## 95 percent confidence interval:
##  49.62825 57.27175
## sample estimates:
## mean of x 
##     53.45
# Cálculo da amplitude do IC:
r95<-t.test(vet_obs,alternative=c("two.sided"),mu=50,conf.level=0.95)
r95$conf.int[2]-r95$conf.int[1]
## [1] 7.643498
# Teste de Wilcox
wilcox.test(vet_obs,mu=50,conf.int=TRUE)
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  vet_obs
## V = 139, p-value = 0.07905
## alternative hypothesis: true location is not equal to 50
## 95 percent confidence interval:
##  49.00001 58.00001
## sample estimates:
## (pseudo)median 
##       53.66572

CONCLUSÃO:

Para as 20 observações analisadas e dentro da interpretação de conformidade da indústria, observa-se que:

Conclui-se: Apesar do valor em questao encontrar-se dentro do intervalo de confiança e em conformidade com o padrão estabelecido, a amplitude superior a 7.64 mg/l, desvio padrão superior a 8 mg/l e a proximidade com o limite inferior do IC, recomenda-se a NÃO ACEITAÇÃO DE CONFORMIDADE baseando-se nas observações analisadas.

——————————————————————————————————————————————————————————–

Desenvolvimento:

Amostras<-c(50.3, 51.2, 50.5, 50.2, 49.9, 50.2, 50.3, 50.5, 49.3, 50.0, 50.4, 50.1, 51.0, 49.8, 50.7, 50.6)


summary(Amostras)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   49.30   50.08   50.30   50.31   50.52   51.20
stem(sort(Amostras))
## 
##   The decimal point is at the |
## 
##   49 | 3
##   49 | 89
##   50 | 0122334
##   50 | 5567
##   51 | 02
# Análise via boxplot:

boxplot(Amostras)

# Desvio padrão das observações (n=16):
sd(Amostras)
## [1] 0.4616998
# Cálculo do viés:
# t=1.96 (alfa=5%)
# n=16
Vies<-1.96*sd(Amostras)/sqrt(16)
Vies
## [1] 0.2262329
# Aplicando t.test para análise da hipótese:

# Teste com alpha=5% Opção: two.sided
t.test(Amostras,alternative=c("two.sided"),mu=50,conf.level=0.95)
## 
##  One Sample t-test
## 
## data:  Amostras
## t = 2.7074, df = 15, p-value = 0.01622
## alternative hypothesis: true mean is not equal to 50
## 95 percent confidence interval:
##  50.06648 50.55852
## sample estimates:
## mean of x 
##   50.3125
r95<-t.test(Amostras,alternative=c("two.sided"),mu=50,conf.level=0.95)
r95$conf.int[2]-r95$conf.int[1]
## [1] 0.4920449
# Teste com alpha=1% Opção: two.sided
t.test(Amostras,alternative=c("two.sided"),mu=0,conf.level=0.99)
## 
##  One Sample t-test
## 
## data:  Amostras
## t = 435.8893, df = 15, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 99 percent confidence interval:
##  49.97238 50.65262
## sample estimates:
## mean of x 
##   50.3125
r99<-t.test(Amostras,alternative=c("two.sided"),mu=0,conf.level=0.99)
r99$conf.int[2]-r99$conf.int[1]
## [1] 0.6802483

CONCLUSÃO:

Após a análise dos dados, conclui-se:

——————————————————————————————————————————————————————————–

Amostras<-c(64,65,75,67,65,74,75)

summary(Amostras)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   64.00   65.00   67.00   69.29   74.50   75.00
# Análise via boxplot:
boxplot(Amostras)

# Desvio padrão das observações (n=7):
sd(Amostras)
## [1] 5.122313
# Cálculo (considerando alfa=10%):
# t=1.645
# n=7
Dif<-1.645*sd(Amostras)/sqrt(7)
Dif
## [1] 3.184806
# Teste com alpha=10% Opção: two.sided
t.test(Amostras,alternative=c("two.sided"),mu=72,conf.level=0.90)
## 
##  One Sample t-test
## 
## data:  Amostras
## t = -1.402, df = 6, p-value = 0.2105
## alternative hypothesis: true mean is not equal to 72
## 90 percent confidence interval:
##  65.52362 73.04781
## sample estimates:
## mean of x 
##  69.28571
r10<-t.test(Amostras,alternative=c("two.sided"),mu=72,conf.level=0.90)
r10$conf.int[2]-r10$conf.int[1]
## [1] 7.524198
# Cálculo (considerando alfa=5%):
# t=1.96 
# n=7
Dif<-1.96*sd(Amostras)/sqrt(7)
Dif
## [1] 3.794663
# Teste com alpha=5% Opção: two.sided
t.test(Amostras,alternative=c("two.sided"),mu=72,conf.level=0.95)
## 
##  One Sample t-test
## 
## data:  Amostras
## t = -1.402, df = 6, p-value = 0.2105
## alternative hypothesis: true mean is not equal to 72
## 95 percent confidence interval:
##  64.54836 74.02306
## sample estimates:
## mean of x 
##  69.28571
r5<-t.test(Amostras,alternative=c("two.sided"),mu=72,conf.level=0.95)
r5$conf.int[2]-r5$conf.int[1]
## [1] 9.4747
# Cálculo (considerando alfa=1%):
# t=2.58 
# n=7
Dif<-2.58*sd(Amostras)/sqrt(7)
Dif
## [1] 4.995015
# Teste com alpha=1% Opção: two.sided
t.test(Amostras,alternative=c("two.sided"),mu=72,conf.level=0.99)
## 
##  One Sample t-test
## 
## data:  Amostras
## t = -1.402, df = 6, p-value = 0.2105
## alternative hypothesis: true mean is not equal to 72
## 99 percent confidence interval:
##  62.10794 76.46349
## sample estimates:
## mean of x 
##  69.28571
r1<-t.test(Amostras,alternative=c("two.sided"),mu=72,conf.level=0.99)
r1$conf.int[2]-r1$conf.int[1]
## [1] 14.35555

CONCLUSÃO:

Após a análise dos dados, conclui-se:

——————————————————————————————————————————————————————————–

AmISE<-c(0.32,0.36,0.24,0.11,0.11,0.44,2.79,2.99,3.47)
AmCOL<-c(0.36,0.37,0.21,0.09,0.11,0.42,2.77,2.91,3.52)

summary(AmISE)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.110   0.240   0.360   1.203   2.790   3.470
summary(AmCOL)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.090   0.210   0.370   1.196   2.770   3.520
# Análise via boxplot:
par(mfrow=c(1,2))
boxplot(AmISE,main="Amostra ISE")
boxplot(AmCOL,main="Amostra COLORIMETRIC")

Análise da amostra ISE:

# Desvio padrão das observações (n=9):
sd(AmISE)
## [1] 1.424798
# Cálculo (considerando alfa=5%):
# t=1.96
# n=9
Dif1<-1.96*sd(AmISE)/sqrt(9)
Dif1
## [1] 0.9308682
# Teste com alpha=5% Opção: two.sided
t.test(AmISE,alternative=c("two.sided"),mu=0,conf.level=0.95)
## 
##  One Sample t-test
## 
## data:  AmISE
## t = 2.5337, df = 8, p-value = 0.03505
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.1081365 2.2985302
## sample estimates:
## mean of x 
##  1.203333
rAmISE5<-t.test(AmISE,alternative=c("two.sided"),mu=0,conf.level=0.95)
rAmISE5$conf.int[2]-rAmISE5$conf.int[1]
## [1] 2.190394

Análise da amostra COLORIMETRIC:

# Desvio padrão das observações (n=9):
sd(AmCOL)
## [1] 1.421901
# Cálculo (considerando alfa=5%):
# t=1.96
# n=9
Dif2<-1.96*sd(AmCOL)/sqrt(9)
Dif2
## [1] 0.9289754
# Teste com alpha=5% Opção: two.sided
t.test(AmCOL,alternative=c("two.sided"),mu=0,conf.level=0.95)
## 
##  One Sample t-test
## 
## data:  AmCOL
## t = 2.5224, df = 8, p-value = 0.03567
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.1025856 2.2885255
## sample estimates:
## mean of x 
##  1.195556
rAmCOL5<-t.test(AmCOL,alternative=c("two.sided"),mu=0,conf.level=0.95)
rAmCOL5$conf.int[2]-rAmCOL5$conf.int[1]
## [1] 2.18594
#Cálculo t.test para as duas amostras:
# Teste com alpha=5% Opção: two.sided
t.test(AmCOL,AmISE,alternative=c("two.sided"),mu=0,conf.level=0.95)
## 
##  Welch Two Sample t-test
## 
## data:  AmCOL and AmISE
## t = -0.0116, df = 16, p-value = 0.9909
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.430179  1.414624
## sample estimates:
## mean of x mean of y 
##  1.195556  1.203333

CONCLUSÃO:

Após a análise das duas amostras ISE e COLORIMETRIC, conclui-se:

——————————————————————————————————————————————————————————–

AmCID<-c(0.34,0.18,0.13,0.09,0.16,0.09,0.16,0.10,0.14,0.26,0.06,0.26,0.07)
AmPAR<-c(0.26,0.06,0.16,0.19,0.32,0.16,0.08,0.05,0.10,0.13)

summary(AmCID)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0600  0.0900  0.1400  0.1569  0.1800  0.3400
summary(AmPAR)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0500  0.0850  0.1450  0.1510  0.1825  0.3200

Análise via diagrama CAULE/FOLHAS:

stem(sort(AmCID))
## 
##   The decimal point is 1 digit(s) to the left of the |
## 
##   0 | 6799
##   1 | 034668
##   2 | 66
##   3 | 4
stem(sort(AmPAR))
## 
##   The decimal point is 1 digit(s) to the left of the |
## 
##   0 | 568
##   1 | 03669
##   2 | 6
##   3 | 2

Análise via boxplot:

par(mfrow=c(1,2))
boxplot(AmCID,main="Amostra CIDADES")
boxplot(AmPAR,main="Amostra poços PARTICULARes")

Análise da amostra CIDade:

# Desvio padrão das observações (n=13):
sd(AmCID)
## [1] 0.08439832
# Cálculo (considerando alfa=5%):
# t=1.96
# n=13
Dif1<-1.96*sd(AmCID)/sqrt(13)
Dif1
## [1] 0.04587945
# Teste com alpha=5% Opção: two.sided
t.test(AmCID,alternative=c("two.sided"),mu=0,conf.level=0.95)
## 
##  One Sample t-test
## 
## data:  AmCID
## t = 6.7039, df = 12, p-value = 2.184e-05
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.1059217 0.2079245
## sample estimates:
## mean of x 
## 0.1569231
rAmCID5<-t.test(AmCID,alternative=c("two.sided"),mu=0,conf.level=0.95)
rAmCID5$conf.int[2]-rAmCID5$conf.int[1]
## [1] 0.1020028

Análise da amostra PARticular:

# Desvio padrão das observações (n=10):
sd(AmPAR)
## [1] 0.08736259
# Cálculo (considerando alfa=5%):
# t=1.96
# n=10
Dif2<-1.96*sd(AmPAR)/sqrt(10)
Dif2
## [1] 0.05414789
# Teste com alpha=5% Opção: two.sided
t.test(AmPAR,alternative=c("two.sided"),mu=0,conf.level=0.95)
## 
##  One Sample t-test
## 
## data:  AmPAR
## t = 5.4658, df = 9, p-value = 0.0003974
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.08850457 0.21349543
## sample estimates:
## mean of x 
##     0.151
rAmPAR5<-t.test(AmPAR,alternative=c("two.sided"),mu=0,conf.level=0.95)
rAmPAR5$conf.int[2]-rAmPAR5$conf.int[1]
## [1] 0.1249909
#Cálculo t.test para as duas amostras:
# Teste com alpha=5% Opção: two.sided
t.test(AmPAR,AmCID,alternative=c("two.sided"),mu=0,conf.level=0.95)
## 
##  Welch Two Sample t-test
## 
## data:  AmPAR and AmCID
## t = -0.1636, df = 19.156, p-value = 0.8718
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.08166929  0.06982314
## sample estimates:
## mean of x mean of y 
## 0.1510000 0.1569231

CONCLUSÃO:

Após a análise das duas amostras CIDade e PARticular, conclui-se:

——————————————————————————————————————————————————————————–