-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAICBIC.R
45 lines (42 loc) · 1.64 KB
/
AICBIC.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
aic.new <- function(loglike, nparam){
-2*loglike + 2*nparam
}
bic.new <- function(loglike, nparam, sample){
-2*loglike + nparam*log(sample)
}
rmse <- function(obs, pred){
sqrt(sum((obs - pred)^2) / length(obs))
## or:
# sqrt(mean((obs - pred)^2))
}
pvaf <- function(obs, pred){
1 - (sum((obs - pred)^2) / sum((obs - mean(obs))^2))
}
## Example on how to use it,
## dat.1 ist teh dataframe in which frequencies and probabilities as well as t are stored
#liste <- list(list(max.1.n, loglike.1),
# list(max.2.n, loglike.2),
# list(max.3.n, loglike.3))
#
#aic.1 <- data.frame(Model=c(1,2,3),
# AIC=unlist(
# lapply(liste,
# function(x){
# b.aic(
# x[[2]](param=x[[1]]$estimate,
# data=c(dat.1$frq_obs.m1,
# dat.1$frq_nobs.m1),
# t=dat.1$time),
# length(x[[1]]$estimate))})),
# BIC=unlist(
# lapply(liste,
# function(x){
# b.bic(
# x[[2]](param=x[[1]]$estimate,
# data=c(dat.1$frq_obs.m1,
# dat.1$frq_nobs.m1),
# t=dat.1$time),
# length(x[[1]]$estimate),
# length(dat.1$frq_obs.m1))
# })
# ))