Estatística II - Exemplos

`"

Capítulo 5

Exemplo 5.2

P([`x]B £ 167|m = 171) = P(Z £ -2.31) =
> pnorm(-2.31)
 
[1] 0.01044408
 
b = P(Não Rejeitar H0 - H0 é Falsa)=
> 1 - dnorm(-0.4618802)
 
[1] 0.6414206
 

Exemplo 5.3

> dados <- c(498.8, 503.1, 497.6, 491.6, 499.3, 491.3, 499.8, 492.1, 
+     498.1, 493.2, 487.2, 489.8, 495.8, 498.2, 498.8, 485.7)
> t.test(dados, mu = 500, conf = 0.99, alternative = "less")
 
	One Sample t-test

data:  dados 
t = -3.9825, df = 15, p-value = 0.0006007
alternative hypothesis: true mean is less than 500 
99 percent confidence interval:
     -Inf 498.2761 
sample estimates:
mean of x 
  495.025 
 

Exemplo 5.4

> xa <- c(3.4, 2.99, 3.21, 3.07, 3.01, 3.27, 3.23, 3.02)
> xa
 
[1] 3.40 2.99 3.21 3.07 3.01 3.27 3.23 3.02
 
> xb <- c(2.82, 3.16, 2.98, 3.04, 3.15, 3.2, 3, 3.01, 3.08, 3.06)
> xb
 
 [1] 2.82 3.16 2.98 3.04 3.15 3.20 3.00 3.01 3.08 3.06
 
Teste para as variâncias.
> var.test(xa, xb, conf.level = 0.95, alternative = "greater")
 
	F test to compare two variances

data:  xa and xb 
F = 1.8569, num df = 7, denom df = 9, p-value = 0.1905
alternative hypothesis: true ratio of variances is greater than 1 
95 percent confidence interval:
 0.5639297       Inf 
sample estimates:
ratio of variances 
          1.856877 
 
Teste para as médias.
> t.test(xa, xb, conf = 0.95, var.equal = T, alternative = "two.sided")
 
	Two Sample t-test

data:  xa and xb 
t = 1.6443, df = 16, p-value = 0.1196
alternative hypothesis: true difference in means is not equal to 0 
95 percent confidence interval:
 -0.02892157  0.22892157 
sample estimates:
mean of x mean of y 
     3.15      3.05 
 

Exemplo 5.5

Resistência de dois tipos de concreto.
> conc1 <- c(101.2, 102, 100.8, 102.3, 101.6)
> conc1
 
[1] 101.2 102.0 100.8 102.3 101.6
 
> conc2 <- c(100, 102.8, 101.5, 99, 102)
> conc2
 
[1] 100.0 102.8 101.5  99.0 102.0
 
Teste para as variâncias.
> var.test(conc2, conc1)
 
	F test to compare two variances

data:  conc2 and conc1 
F = 6.5414, num df = 4, denom df = 4, p-value = 0.09617
alternative hypothesis: true ratio of variances is not equal to 1 
95 percent confidence interval:
  0.6810783 62.8274220 
sample estimates:
ratio of variances 
          6.541436 
 
Teste das médias.
> t.test(conc1, conc2, alternative = "greater")
 
	Welch Two Sample t-test

data:  conc1 and conc2 
t = 0.7037, df = 5.195, p-value = 0.2559
alternative hypothesis: true difference in means is greater than 0 
95 percent confidence interval:
 -0.9566956        Inf 
sample estimates:
mean of x mean of y 
   101.58    101.06 
 

Exemplo 5.6

> antes <- c(179, 200, 161, 170, 181, 190, 202, 220, 195, 165)
> depois <- c(160, 180, 161, 180, 165, 170, 196, 216, 170, 160)
> d <- mean(depois - antes)
> d
 
[1] -10.5
 
> t.test(antes, depois, paired = TRUE, conf = 0.99)
 
	Paired t-test

data:  antes and depois 
t = 2.9811, df = 9, p-value = 0.01542
alternative hypothesis: true difference in means is not equal to 0 
99 percent confidence interval:
 -0.9464151 21.9464151 
sample estimates:
mean of the differences 
                   10.5 
 

Exemplo 5.7

> require(corpora)
> prop.cint(98, 200, method = "z.score", correct = FALSE, conf.level = 0.95, 
+     alternative = "less")
 
  lower    upper
1     0 0.547887
 
> z.score(98, 200, p = 0.57, correct = FALSE)
 
[1] -2.285248
 
> z.score.pval(98, 200, p = 0.57, correct = FALSE, alternative = "less")
 
[1] 0.01114915
 

Exemplo 5.8

2.
> ztab <- qnorm(0.99)
> ztab
 
[1] 2.326348
 
> kr <- 171
> nr <- 180
> kc <- 171
> nc <- 190
> pr <- kr/nr
> pc <- kc/nc
> pr
 
[1] 0.95
 
> pc
 
[1] 0.9
 
> p <- (kr + kc)/(nr + nc)
> p
 
[1] 0.9243243
 
3.
> zcalc <- ((pr - pc) - (0))/sqrt((p * (1 - p)) * ((1/nr) + (1/nc)))
> zcalc
 
[1] 1.817573
 
> p.valor <- 1 - pnorm(zcalc)
> p.valor
 
[1] 0.03456471
 
A função prop.test obtém o mesmo p-valor mas, considerando a distribuição c2
> prop.test(c(171, 171), c(180, 190), corre = FALSE, conf = 0.99, 
+     alt = "g")
 
	2-sample test for equality of proportions without continuity
	correction

data:  c(171, 171) out of c(180, 190) 
X-squared = 3.3036, df = 1, p-value = 0.03456
alternative hypothesis: greater 
99 percent confidence interval:
 -0.01317965  1.00000000 
sample estimates:
prop 1 prop 2 
  0.95   0.90 
 
Observe que a estatística de teste é baseada no teste de c2.

Exemplo 5.9

2.
> xq <- qchisq(0.975, 6)
> xq
 
[1] 14.44938
 
3.
> dados <- matrix(c(30, 18, 26, 13, 7, 8, 17), nrow = 1)
> chisq.test(dados)
 
	Chi-squared test for given probabilities

data:  dados 
X-squared = 26.3529, df = 6, p-value = 0.0001913
 

Exemplo 5.10

Renda e número de filhos por família em uma cidade.
> zero <- c(15, 8, 25)
> um <- c(27, 13, 30)
> dois <- c(50, 9, 12)
> mais <- c(43, 10, 8)
> tab5.13 <- data.frame(zero, um, dois, mais)
> # O próximo passo Ã© apenas para que a tabela fique mais apresentável. Mas pode-se rodar o teste mesmo sem alterar o nome das linhas.
> dimnames(tab5.13)[[1]] <- c("< 2000", "2000 a 5000", "> 5000")
> tab5.13
 
            zero um dois mais
< 2000        15 27   50   43
2000 a 5000    8 13    9   10
> 5000        25 30   12    8
 
> chisq.test(tab5.13)
 
	Pearson's Chi-squared test

data:  tab5.13 
X-squared = 36.6212, df = 6, p-value = 2.087e-06
 
P( c26 ³ 36,62) =
> p.valor <- round(1 - pchisq(36.6212, 6), 8)
> p.valor
 
[1] 2.09e-06
 



File translated from TEX by TTH, version 3.67.
On 26 May 2009, 15:57.