funsVarTk | R Documentation |
T_k
Test statisticTwo functions: VarTk
and VarTkaij
.
Both functions compute the (finite sample) variance of Cuzick and Edwards T_k
test statistic based on the
number of cases within k
NNs of the cases in the data under RL or CSR independence.
The common arguments for both functions are n1
, representing the number of cases and k
.
The number of cases are denoted as n_1
and number of controls as n_0
in this function
to match the case-control class labeling,
which is just the reverse of the labeling in \insertCitecuzick:1990;textualnnspat.
The logical argument nonzero.mat
(default=TRUE
) is for using the A
matrix if FALSE
or just the matrix of nonzero
locations in the A
matrix (if TRUE
) for computing N_s
and N_t
, which are required in the computation of the
variance. N_s
and N_t
are defined on page 78 of (\insertCitecuzick:1990;textualnnspat) as follows.
N_s=\sum_i\sum_j a_{ij} a_{ji}
(i.e., number of ordered pairs for which k
NN relation is symmetric)
and N_t= \sum \sum_{i \ne l}\sum a_{ij} a_{lj}
(i.e, number of triplets (i,j,l)
i,j
, and l
distinct so that
j
is among k
NNs of i
and j
is among k
NNs of l
).
The function VarTkaij
uses Toshiro Tango's moments formulas based on the A=(a_{ij})
matrix
(and is equivalent to the function VarTk
, see \insertCitetango:2007;textualnnspat,
where a_{ij}(k) = 1
if z_j
is among the k
NNs of z_i
and 0 otherwise.
The function varTkaij
is equivalent to varTk
(with $var
extension).
See (\insertCitecuzick:1990,tango:2007;textualnnspat).
varTk(dat, n1, k, nonzero.mat = TRUE, ...)
varTkaij(n1, k, a)
dat |
The data set in one or higher dimensions, each row corresponds to a data point, used in |
n1 |
Number of cases |
k |
Integer specifying the number of NNs (of subject |
nonzero.mat |
A logical argument (default is |
... |
are for further arguments, such as |
a |
The |
The function VarTk
returns a list
with the elements
var.Tk |
The (finite sample) variance of Cuzick and Edwards |
Ns |
The |
Nt |
The |
The function VarTkaij
returns only var.Tk
as above.
Elvan Ceyhan
asyvarTk
n<-20 #or try sample(1:20,1)
Y<-matrix(runif(3*n),ncol=3)
cls<-sample(0:1,n,replace = TRUE) #or try cls<-rep(0:1,c(10,10))
n1<-sum(cls==1)
k<-2 #try also 2,3
a<-aij.mat(Y,k)
varTk(Y,n1,k)
varTk(Y,n1,k,nonzero.mat=FALSE)
varTk(Y,n1,k,method="max")
n<-20 #or try sample(1:20,1)
Y<-matrix(runif(3*n),ncol=3)
cls<-sample(0:1,n,replace = TRUE) #or try cls<-rep(0:1,c(10,10))
n1<-sum(cls==1)
k<-1 #try also 2,3, sample(1:5,1)
a<-aij.mat(Y,k)
varTkaij(n1,k,a)
varTk(Y,n1,k)$var
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.