-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.R
More file actions
23 lines (21 loc) · 897 Bytes
/
Functions.R
File metadata and controls
23 lines (21 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
### ASTER function
# newdata= empty dataframe with variables in model
# FitnessVar = (in quotations) highest level fitness variable
# Model = model to use for predict
ASTER_predict <- function(newdata, FitnessVar, Model) {
for (v in vars)
newdata[[v]] <- 1
newdata$root <- 1 #add the root
#now reshape this dataset
renewdata <- reshape(newdata, varying = list(vars), direction = "long", timevar = "varb", times = as.factor(vars), v.names = "resp")
fit <- grepl(FitnessVar, as.character(renewdata$varb))
fit <- as.numeric(fit)
renewdata$fit <- fit
nind <-nrow (newdata) #num rows of df
nnode <- length (vars)
amat <-array(0, c(nind, nnode, nind)) #this makes an empty array
for (i in 1:nind)
amat[i, grep(FitnessVar, vars), i] <- 1
predictions <- predict(Model, varvar=varb, idvar=id, root=root, newdata=renewdata, se.fit=TRUE, amat=amat)
return(predictions)
}