Title: | Test of Independence & Image Structural Similarity Measure PSSIM |
---|---|
Description: | Test-based Image structural similarity measure and test of independence. This package implements the key functions of two tasks: (1) computing image structural similarity measure PSSIM of Wang, Maldonado and Silwal (2011) <DOI:10.1016/j.csda.2011.04.021>; and (2) test of independence between a response and a covariate in presence of heteroscedastic treatment effects proposed by Wang, Tolos, and Wang (2010) <DOI:10.1002/cjs.10068>. |
Authors: | Luann C. Jung, Haiyan Wang, Diego Maldonado, Sharad Silwal, Siti Tolos, Suojin Wang |
Maintainer: | Haiyan Wang <[email protected]> |
License: | GPL-2 |
Version: | 0.1.0 |
Built: | 2024-12-15 07:26:55 UTC |
Source: | CRAN |
The function makepseudo performs the nearest neighbor augmentation based on the rank of covariate values according to the scheme discribed on page 410-411 of Wang, Tolos and Wang (2010)
makepseudo(N, n, k, a, alltrt)
makepseudo(N, n, k, a, alltrt)
N |
total number of covariate values. |
n |
vector of sample sizes from all treatments |
k |
number of nearest neighbors |
a |
number of treatment levels in the data |
alltrt |
a matrix of dimension 3x |
A list containing the following: psudo: a 3-d array of the dimension (k, a, N) that stores the augmented observations based on k-nearest neighbor rule in Wang, Tolos and Wang (2010). index: a 3-d array of the dimension (k, a, N) that stores the index of which observation was used for augmentation.
Haiyan Wang, Siti Tolos, and Suojin Wang (2010). A Distribution Free Nonparametric Test to Detect Dependence Between a Response Variable and Covariate in Presence of Heteroscedastic Treatment Effects. The Canadian Journal of Statistics. 38(3), 408433. Doi:10.1002/cjs.10068
a=2; n=c(7,9); N=sum(n); X=runif(N); trt=c(rep(1,n[1]), rep(2, n[2])); e=rnorm(N, 0, 0.1) Y=ifelse(trt==1, 4*(X-0.5)^2+e, 2*X+e) ranksuse=unlist(tapply(X, trt, rank) ) alltrt=rbind(Y, X, ranksuse ) aug=makepseudo(N,n, k=3, a, alltrt)
a=2; n=c(7,9); N=sum(n); X=runif(N); trt=c(rep(1,n[1]), rep(2, n[2])); e=rnorm(N, 0, 0.1) Y=ifelse(trt==1, 4*(X-0.5)^2+e, 2*X+e) ranksuse=unlist(tapply(X, trt, rank) ) alltrt=rbind(Y, X, ranksuse ) aug=makepseudo(N,n, k=3, a, alltrt)
Function mapindex() maps the 1-d index r=1,...,N to 2-d index i=1, ...a, j=1, ..., ni. Generally the covariate values from all treatments are stored together in one vector and r=1,...,N enumerates the values. For any integer between 1 and N, mapindex tells which treatment the rth value belongs to, and which observation in the identified treatment.
mapindex(r, n)
mapindex(r, n)
r |
an integer between 1 and sum(n). |
n |
a vector of the sample sizes. |
the 2-d index, where the first gives which treatment the value belongs to and the second gives which observation in that treatment.
r=5; n=c(7, 8); mapindex(r, n) r=7; n=c(7, 8); mapindex(r, n) r=9; n=c(7, 8); mapindex(r, n)
r=5; n=c(7, 8); mapindex(r, n) r=7; n=c(7, 8); mapindex(r, n) r=9; n=c(7, 8); mapindex(r, n)
The matrices are grayscale images in matrix format.
data(miniimagematrix)
data(miniimagematrix)
A list with two grayscale image matrices
A matrix for one image
A matrix for a second image
data(miniimagematrix) miniimagematrix$A
data(miniimagematrix) miniimagematrix$A
NPtest_indept performs the test of independence between the response variable and a single covariate when there is potentially heteroscedastic treatment effects present (see Wang, Tolos and Wang (2010)).
NPtest_indept(dat, k = 7)
NPtest_indept(dat, k = 7)
dat |
A data frame with three columns named X, trt, and Y, where X is the covarite, trt is the treatment level, and Y is the response variable. |
k |
An odd integer to specify the number of nearest neighbors to be used in augmentation. Generally recommend to use 3, 5, or 7. |
A list containing the following variables:
Asys_var: the asymptotic variance for the test statistics
Tstat: the test statistic
pvalue: the p-value of the test under H0: independence between X and Y.
Haiyan Wang, Siti Tolos, and Suojin Wang (2010). A Distribution Free Nonparametric Test to Detect Dependence Between a Response Variable and Covariate in Presence of Heteroscedastic Treatment Effects. The Canadian Journal of Statistics. 38(3), 408433. Doi:10.1002/cjs.10068
n=64; X=runif(n); trt=gl(2, n/2) e=rnorm(n, 0, 0.1) Y=ifelse(trt==1, 4*(X-0.5)^2+e, 2*X+e) dat=data.frame(X, Y, trt) NPtest_indept(dat, k=7)
n=64; X=runif(n); trt=gl(2, n/2) e=rnorm(n, 0, 0.1) Y=ifelse(trt==1, 4*(X-0.5)^2+e, 2*X+e) dat=data.frame(X, Y, trt) NPtest_indept(dat, k=7)
PSSIM_snow computes image structural similarity PSSIM of Wang, Maldonado and Silwal (2011) using parallel programming.
PSSIM_snow( A, A1, nprocess = min(8, parallel::detectCores()), b = 64, a = 2, vs = 32, wavecoeff = FALSE, cs = 2, dyn = FALSE )
PSSIM_snow( A, A1, nprocess = min(8, parallel::detectCores()), b = 64, a = 2, vs = 32, wavecoeff = FALSE, cs = 2, dyn = FALSE )
A |
a grayscale image stored as a matrix. |
A1 |
grayscale image stored as a matix. Same dimension as A. |
nprocess |
number of cores (workers) to use for parallel computation. Note: In personal computer, nprocess =detectCores() is good to use. On cluster machine, nprocess need to be specified to a number that is no more than its number of cores (for courtesy) |
b |
Number of columns in each block. Suggest to use default value 64. |
a |
Number of rows in each block. Suggest to use default value 2. |
vs |
Block shift size. Suggest to use default value 32. |
wavecoeff |
logical of whether the input matrices are wavelet coefficients. Currently, wavelet version is not implemented. This parameter is a placeholder for future implementation. |
cs |
dividing factor to split index. |
dyn |
logical, whether dynamic scheduling should be used. |
: Image structural similarity based on PSSIM. The value is in [0,1] with values close to 0 meaning the two images are different and values close to 1 meaning the two iamges are similar.
Haiyan Wang, Diego Maldonado, and Sharad Silwal (2011). A Nonparametric-Test-Based Structural Similarity Measure for Digital Images. Computational Statistics and Data Analysis. 55: 2925-2936. Doi:10.1016/j.csda.2011.04.021
A=miniimagematrix$A B=miniimagematrix$B # see it with image(A, axes=FALSE, col = gray((0:255)/256) ) PSSIM_snow(A, B, nprocess=2)
A=miniimagematrix$A B=miniimagematrix$B # see it with image(A, axes=FALSE, col = gray((0:255)/256) ) PSSIM_snow(A, B, nprocess=2)
Function trt_position() gives the starting and ending index of covariate values in the i1th group if all the covariate values from all treatment groups are together in a vector. E.g., covariate values in group 1 start from 1st value to the n1 th value; those in group 2 start from n1+1 and end at (n1+n2)th value. This function is for retrieving the position of an observations when the covariate values from all treatments are stored together in one vector.
trt_position(i1, n)
trt_position(i1, n)
i1 |
an integer between 1 and length(n). |
n |
the vector of sample sizes. |
i = 2; n=c(7, 8); trt_position(i, n)
i = 2; n=c(7, 8); trt_position(i, n)