-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexemple.R
executable file
·51 lines (47 loc) · 1.96 KB
/
exemple.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
temps <- c(548,519,637,619,776,818,641,678,701,846,858,855,517,493,618,876,741,849,602,719,731,628,595,687)
home <- gl(8, 3)
tractament <- gl(3, 1, length=24, labels=LETTERS[1:3])
fix.aov <- aov(temps ~ tractament + home)
(ac <- anova2cross(fix.aov, random="home"))
# Components de la variància
mm <- matrix(c(1,1,ac["tractament","Df"]+1,0), ncol=2)
solve(mm,ac[-1,"Mean Sq"])
anova2cross <- function (aovObj, random = NULL, restricted = TRUE)
{
nrandom <- length(random)
aovTab <- anova(aovObj)
if (nrandom == 0)
return(aovTab)
yName <- as.character(aovObj$call$formula[[2]])
modelNames <- names(aovObj$model)
if (!all(match(random, modelNames[-match(yName, modelNames)],
nomatch = 0)))
stop("Algun dels factors aleatoris indicats no \303\251s un factor o no forma part del model")
interacEff <- grep(":", rownames(aovTab))
if (any(interacEff)) {
msInterac <- aovTab[interacEff, 3]
dfInterac <- aovTab[interacEff, 1]
switch(nrandom, {
if (restricted) {
fixedName <- modelNames[-match(c(yName, random),
modelNames)]
iFixedName <- pmatch(fixedName, rownames(aovTab)[1:2])
fixedF <- aovTab[iFixedName, "Mean Sq"]/msInterac
aovTab[iFixedName, "F value"] <- fixedF
aovTab[iFixedName, "Pr(>F)"] <- pf(fixedF, aovTab[iFixedName,
1], dfInterac, lower.tail = FALSE)
} else {
correctF <- aovTab[1:2, "Mean Sq"]/msInterac
aovTab[1:2, "F value"] <- correctF
aovTab[1:2, "Pr(>F)"] <- pf(correctF, aovTab[1:2,
1], dfInterac, lower.tail = FALSE)
}
}, {
correctF <- aovTab[1:2, "Mean Sq"]/msInterac
aovTab[1:2, "F value"] <- correctF
aovTab[1:2, "Pr(>F)"] <- pf(correctF, aovTab[1:2,
1], dfInterac, lower.tail = FALSE)
})
}
return(aovTab)
}