-
Notifications
You must be signed in to change notification settings - Fork 0
/
InitializationAmelia.R
75 lines (65 loc) · 1.4 KB
/
InitializationAmelia.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
setwd("~/Documents/013-14/Summer 2014/MedIX")
## Loading add-on packages
pack.names <- c("MASS","irr","rpart","rpart.plot",
"scales","e1071","phyclust")
sapply(pack.names,library,character.only=TRUE)
## Defined function
mode <- function(x)
{
tabSmpl<-tabulate(x)
ifelse((sum(tabSmpl == max(tabSmpl))>1),ceiling(mean(x)),which(tabSmpl== max(tabSmpl)))
}
rescale <- function(x)
{
value <- ifelse(x==1|x==2,1,ifelse(x==3,2,3))
return(value)
}
as.dummy <- function(x)
{
if(x==1)
{
value <- c(1,0,0)
}
else if(x==2)
{
value <- c(0,1,0)
}
else
{
value <- c(0,0,1)
}
return(value)
}
rvi <- function(x)
{
center <- ifelse(is.na(mode(x)),ceiling(mean(x)),mode(x))
value <- mean((x-center)^2)
return(value)
}
label.selector <- function(x,index)
{
x <- as.vector(t(x))
value <- x[seq(0,4*(length(index)-1),4)+index]
return(value)
}
iter.mean.calculator <- function(x,iter.index)
{
if(iter.index==4) iter.index <-0
x <- x[(x[,1] %% 4)==iter.index,]
value <- apply(x,2,mean)
return(value)
}
iter.rand.ci.calculator <- function(x,iter.index)
{
if(iter.index==4) iter.index <- 0
x <- x[(x[,1] %% 4)==iter.index,]
value <- as.vector(t.test(x[,3])$conf.int)
return(value)
}
iter.kappa.ci.calculator <- function(x,iter.index)
{
if(iter.index==4) iter.index <- 0
x <- x[(x[,1] %% 4)==iter.index,]
value <- as.vector(t.test(x[,4])$conf.int)
return(value)
}