Você está na página 1de 9

ANEXO: CÓDIGOS

# LISTA 2 - ME714
library(coin)
library(data.table)
library(vcd)

## QUESTÃO 1
placebo <- c(7,11,7,4,1)
droga <- c(1,5,7,7,10)
### TESTE NÃO ORDINAL - TESTE T DE STUDENT

var.test(placebo, droga)

t.test (placebo,droga, var.equal = TRUE)

###TESTE ORDINAL - ORDINAL CHI-SQUARED TEST


Input =(
"Tempo 0 1 2 3 4
Tratamento
Placebo 7 11 7 4 1
Droga 1 5 7 7 10
")

tabela = as.table(read.ftable(textConnection(Input)))
sum (tabela)
prop.table(tabela,
margin = NULL) ### proportion in the table
spineplot(tabela)
chisq_test(tabela, scores = list("Tempo" = c(-2, -1, 0, 1, 2)))

##QUESTAO 2
###(A)
df <- data.frame(Resposta=rep(c('Ruim','Razoavel','Muito Bom'), each=6),
Centro=rep(rep(c(c('1','2','3')), each=2), times=3),
Tratamento=rep(c('A', 'B'), times=9),
Contagem = c(6,2,4,2,11,6,6,7,7,4,19,12,3,6,6,11,6,17))
df$Resposta = factor(df$Resposta,
levels=unique(df$Resposta))
df$Tratamento = factor(df$Tratamento,
levels=unique(df$Tratamento))
df$Centro = factor(df$Centro,
levels=unique(df$Centro))
summary(df)
tabela = xtabs(Contagem ~ Centro + Tratamento + Resposta,
data=df)
ftable(tabela)
#primeiro fazemos um teste de woolf: se significativo, o teste C-M-H não é apropriado
woolf_test(tabela)
#ok, assim sendo, vamos fazer o teste de Cochran–Mantel–Haenszel
mantelhaen.test(tabela) #não rejeita H0, então não há diferença entre os tratamentos

###(B)
df <- data.frame(Resposta=rep(c('Ruim','Razoavel','Muito Bom'), each=6),
Tratamento=rep(c('A', 'B'), times=9),
Centro=rep(rep(c(c('1','2','3')), each=2), times=3),
Contagem = c(6,2,4,2,11,6,6,7,7,4,19,12,3,6,6,11,6,17))
df$Resposta = factor(df$Resposta,
levels=unique(df$Resposta))
df$Tratamento = factor(df$Tratamento,
levels=unique(df$Tratamento))
df$Centro = factor(df$Centro,
levels=unique(df$Centro))
tabela = xtabs(Contagem ~ Tratamento + Centro + Resposta,
data=df)
ftable(tabela)
woolf_test(tabela) #não significativo, então C-M-H é apropriado
mantelhaen.test(tabela) #não rejeita H0, então não há diferença entre os centros

Você também pode gostar