-
Notifications
You must be signed in to change notification settings - Fork 0
/
Derr.R
26 lines (24 loc) · 1.21 KB
/
Derr.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
# D-error
#
# Function to calculate d error given a design, and parameter values.
# @param par Vector containing parameter values.
# @param des A design matrix in which each row is a profile.
# @param n.alts Numeric value indicating the number of alternatives per choice
# set.
# @return D-error.
Derr <- function(par, des, n.alts) {
info.des <- InfoDes(par, des, n.alts) # Calculates Fisher-Information matrix
detinfo <- det(info.des) # Calculates the determinant of the information matrix
ifelse((detinfo <= 0), return(NA), return(detinfo^(-1 / length(par)))) # Return the d-error
}
Derr2 <- function(par, des, n.alts) {
info.des <- InfoDes_cpp(par, des, n.alts) # Calculates Fisher-Information matrix
detinfo <- det(info.des) # Calculates the determinant of the information matrix
ifelse((detinfo <= 0), return(NA), return(detinfo^(-1 / length(par)))) # Return the d-error
}
# Function using Info_des_cpp and det_cpp
Derr3 <- function(par, des, n.alts) {
info.des <- InfoDes_cpp(par, des, n.alts) # Calculates Fisher-Information matrix
detinfo <- det_cpp(info.des) # Calculates the determinant of the information matrix
ifelse((detinfo <= 0), return(NA), return(detinfo^(-1 / length(par)))) # Return the d-error
}