-
Notifications
You must be signed in to change notification settings - Fork 0
/
aux-functions
35 lines (30 loc) · 867 Bytes
/
aux-functions
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
#################
### function mode
#################
require(modeest)
mode <- function(x) {
mode = mlv(x, method = "lientz", bw = 0.2)$M
return(mode)
}
##################################
### Trace of product of matrices
##################################
tr <- function(A, B) {
S = 0
for (i in 1:dim(A)[1]) S = S + A[i,] %*% B[,i]
return(as.numeric(S))
}
#############################################
### functions for bias and mean squared error
#############################################
biasMSE = function(x, par, li, ls) {
x = x[x > li & x < ls]
bias = par - mean(x)
mse = sum(par - x)^2/length(x)
S = matrix(, 1, 3)
colnames(S) = c('bias', 'mse', 'N')
S[ ,1] = bias
S[ ,2] = mse
S[ ,3] = length(x)
return(S)
}