-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgroup_lmPerm.R
65 lines (42 loc) · 2.18 KB
/
group_lmPerm.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
58
59
60
61
62
63
64
## group lmPerm
require(lmPerm)
require(AICcmodavg)
group.lmp <- function(group.vars, # should be character string
var.table.name, # should be character string
dependent.var, #should be character string
control.var = NULL,
iter = 999999,
Ca = .01
) {
lmp.results <- data.frame(row.names = group.vars,
estimate = rep(NA, times = length(group.vars)),
var.explnd = rep(NA),
# avg.var.explnd = rep(NA),
F.stat.lmp = rep(NA),
prob.pval = rep(NA),
prob.iter = rep(NA),
adj.pval = rep(NA),
AICc.lm = rep(NA)
)
if (!is.null(control.var)) {control.var <- paste0(control.var, "+")}
for (i in 1:length(group.vars)) {
lmp.temp <- lmp(as.formula(paste0(dependent.var, " ~ ",
control.var,
var.table.name, "$", group.vars[i])),
model = TRUE, seqs = TRUE, x = TRUE, y = TRUE,
center = FALSE, maxIter = iter, Ca = Ca)
summary.lmp.temp <- lmPerm::summary.lmp(lmp.temp)
lm.temp <- lm(as.formula(paste0(dependent.var, " ~ ", var.table.name, "$",
group.vars[i])))
# add calculated values to table:
lmp.results$estimate[i] <- ifelse(length(summary.lmp.temp$coefficients[,1]) > 2, NA,
summary.lmp.temp$coefficients[2,1])
lmp.results$var.explnd[i] <- summary.lmp.temp$adj.r.squared
lmp.results$F.stat.lmp[i] <- summary.lmp.temp$fstatistic["value"]
lmp.results$prob.pval[i] <- summary.lmp.temp$coefficients[2,3]
lmp.results$prob.iter[i] <- summary.lmp.temp$coefficients[1,2]
lmp.results$AICc.lm[i] <- AICc(lm.temp)[1]
}
lmp.results$adj.pval <- p.adjust(p = lmp.results$prob.pval, method = "holm")
return(lmp.results)
}