-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.R
More file actions
executable file
·72 lines (54 loc) · 1.44 KB
/
Functions.R
File metadata and controls
executable file
·72 lines (54 loc) · 1.44 KB
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
library(CompQuadForm)
library(smcure)
library(survival)
Compute.V.sqrt = function(V)
{
d = dim(V)[1]
n = d/2
V.sqrt = matrix(0,nrow=d,ncol=d)
for (i in 1:n)
{
A = V[i,i]
B = V[i,(i+n)]
C = B
D = V[(i+n),(i+n)]
del = A*D-B*C
s = sqrt(del)
tau = A+D
t = sqrt(tau+(2*s))
V.sqrt[i,i]=(A+s)/t
V.sqrt[i,(i+n)]=B/t
V.sqrt[(i+n),i]=C/t
V.sqrt[(i+n),(i+n)]=(D+s)/t
}
return(V.sqrt)
}
#######################################################################
## Return a B by n matrix of permuted indices ##
## The bth line of the returned matrix is a permutation of {1,...,n} ##
#######################################################################
create.indices.i = function(i,n) {sample(n,n)}
create.indices = function(n,B) {t(sapply(1:B,create.indices.i,n=n))}
#########################################################
## Compute the ith element of the diagonal of t(A)%*%B ##
#########################################################
mult=function(i,A,B) {return(t(A[i,])%*%B[i,])}
Compute.Grid=function()
{
rho.vect=seq(-0.9,0.9,0.1)
phi.vect=seq(0.1,0.9,0.1)
l.rho=length(rho.vect)
l.phi=length(phi.vect)
Mat=NULL
for(i in 1:l.rho)
{
for(j in 1:l.phi)
{
v=c(phi.vect[j],1-phi.vect[j],2*rho.vect[i]*sqrt(phi.vect[j]*(1-phi.vect[j])))
Mat=rbind(Mat,v)
}
}
return(Mat)
}
rank.mat=function(i,M) {rank(M[,i])}
rank.vect.mat = function(i,vect,matr) {mean(vect[i]<matr[,i])}