-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStepAICSelection.R
42 lines (28 loc) · 1.36 KB
/
StepAICSelection.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
source('autoload.R')
aic <- function(scopes, data, starting='~.',
direction='both', steps=100,k=2) {
features <- list()
starting <- as.formula(starting)
fit <- glm(starting, data=data, control=glm.control(maxit=10000), family=gaussian)
for(scope in scopes) {
step <- stepAIC(fit, scope, direction=direction, steps = steps, trace=T, k=k)
features <- append(features, list(step$formula))
}
names(features) <- names(scopes)
return(features)
}
allFm <- as.formula(paste('DEXAyagyuz ~ ', paste(inputCols, collapse='+')))
fmFromBeginning <- aic(c(allFm), genderDb$`1`, starting='DEXAyagyuz ~ 1' , direction='both')
fmFromEnd <- aic(c(allFm), genderDb$`1`, starting=paste(format(allFm), collapse='') , direction='both')
first <- strsplit(gsub('DEXAyagyuz ~ ', '', paste(fmFromBeginning)), ' + ', T)[[1]]
second <- strsplit(gsub('DEXAyagyuz ~ ', '', paste(fmFromEnd), fixed=T), ' + ', T)[[1]]
intersect(second, first)
setdiff(second, first)
aic_groups <- lapply(genderDb, function(gdb) {
names(train(allFm, gdb, method='glmStepAIC',
trControl = trainControl(method = 'repeatedcv',
number=5,
seeds=get('getTrControlSeeds')(),
repeats=10))$finalModel$coefficients)[-1]
})
save(aic_groups, file='glmstepAIC.RData')