-
Notifications
You must be signed in to change notification settings - Fork 0
/
peer_table.R
58 lines (47 loc) · 1.94 KB
/
peer_table.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
52
53
54
55
56
57
#!/usr/bin/R
## Function to create anova table of results for peer reviewed literature.
# Author: Adri'a Masip
peer.table <- function(x) {
## Function to create anova table of results for peer reviewed literature, after Tallent-Halsell et al. 2002
# Check class
if (inherits(x, 'mresp')) {
# create a list of aov objects based on 'UserDataFrame' and 'ChosenModelResponse'
mresp=TRUE
a <- list()
for (var in colnames(x[['ChosenModelResponse']])) {
a[[var]] <- summary(aov())[[1L]]
}
} else if (inherits(x, c('aov', 'lm'))) {
## access list first element and check
a <- summary(x)[[1L]]
} else if (inherits(x, 'summary.aov')) {
a <- x[[1L]]
} else {stop('[!] Wrong object')}
if(!mresp) {a <- list(Response=a)}
var <- c();name <- c();df <- c();SS <- c()
MS <- c();Fval <- c();Pperm <- c()
for (l in names(a)) {
if (inherits(a, c('summary', 'data.frame'))) {} else {stop('[!] Not an aov data.frame')}
var <- c(var, c(l, "", "")) # Needs more abstraction
name <- c(name, row.names(tb)[1 : 3]) # Needs more abstraction
df <- c(df, tb[1 : 3, 'Df'])
SS <- c(SS, tb[1 : 3, 'Sum Sq'])
MS <- c(MS, tb[1 : 3, 'Mean Sq'])
Fval <- c(Fval, tb[1 : 3, 'F value'])
Pperm <- c(Pperm, tb[1 : 3, 'Prob(perm)'])
}
sig <- factor(levels = c("**", "*", ""))
for (i in 1 : length(Pperm)) {
if (Pperm[i] < 0.01) {sig[i] <- "**";next}
if (Pperm[i] < 0.05) {sig[i] <- "*"} else {sig[i] <- ""}
}
out <- data.frame(var, name, df, SS, MS, Fval, Pperm, sig)
colnames(out) <- c('Response Variable', 'Main Factor', 'df', 'SS', 'MS', 'F', 'P perm', 'sig')
if (is.null(export) == FALSE) {
cat('[?] Writting csv file.\n')
write.csv(out, paste(as.character(export), '.csv', sep = ""))
}
et <- Sys.time()
# cat('[?] Total time spend:',et-st)
return(out)
}