I've applied Wright's rank and sign test using Rstudio. I got R1,R2 but R3 resulted in NaN.. what is the reason of such a result? and how to get the sign result?

I am using the "vrtest" package.

Thank you.

I've applied Wright's rank and sign test using Rstudio. I got R1,R2 but R3 resulted in NaN.. what is the reason of such a result? and how to get the sign result?

I am using the "vrtest" package.

Thank you.

Hello @ShahadMH

the documentation of the function does not mention R3 (however it mentions S1).

The example uses `data(exrates)`

but executing that gives me an error:

probably the data belongs to a package that is not installed on my computer.

So no further help from me, I am afraid.

EDIT: forgot to do `library(vrtest)`

The data is in the vrtest package itself.

The documentation mentions S1 but the output indicates R3 ??

```
Wright {vrtest} R Documentation
Wright's Rank and Sign Tests
Description
The function returns R1, R2 and S1 tests statistics detailed in Wright (2000)
```

```
> data(exrates)
> y <- exrates$ca
> nob <- length(y)
> r <- log(y[2:nob])-log(y[1:(nob-1)])
> kvec <- c(2,5,10)
> Wright(r,kvec)
$Stats
R1 R2 R3
k=2 2.483482 2.511358 2.015755
k=5 2.847969 2.106418 3.431291
k=10 2.188621 1.105754 3.606674
```

Viewed the code, but it did not help me much.

Maybe depending on the function argument for `Wright`

that you specify.

`vrtest`

functions below:

```
> Wright
function (y, kvec)
{
y <- as.matrix(y)
n <- nrow(y)
W_mat <- matrix(NA, nrow = length(kvec), ncol = 3)
for (i in 1:length(kvec)) {
k <- kvec[i]
W <- Wright_stat(y, k)
W_mat[i, ] <- cbind(W$WR1, W$WR2, W$WS1)
}
VR <- W_mat
rownames(VR) <- paste("k=", kvec, sep = "")
colnames(VR) <- c("R1", "R2", "R3")
return(list(Stats = VR))
}
<bytecode: 0x0000024df212f038>
<environment: namespace:vrtest>
> vrtest:::Wright_stat
function (y, k)
{
y <- as.matrix(y)
n <- nrow(y)
ranking <- as.matrix(rank(y))
r1 <- (ranking - 0.5 * (n + 1))/sqrt((n - 1) * (n + 1)/12)
r2 <- qnorm(ranking/(n + 1))
s <- sign(y)
s[s == 0] <- -1
R1 <- stat(r1, k)
R2 <- stat(r2, k)
S1 <- stat(s, k)
return(list(WR1 = R1, WR2 = R2, WS1 = S1))
}
<bytecode: 0x0000024df2127498>
<environment: namespace:vrtest>
> vrtest:::stat
function (x, k)
{
x <- as.matrix(x)
n <- nrow(x)
index <- 1:k
summ <- 0
for (i in k:n) {
summ <- summ + sum(x[index])^2
index <- index + 1
}
vr1 <- sum(x^2)/n
vr2 <- summ/(n * k)
vr <- vr2/vr1
tem1 <- 2 * (2 * k - 1) * (k - 1)
tem2 <- 3 * k * n
vrstat <- (vr - 1)/sqrt(tem1/tem2)
}
<bytecode: 0x0000024df211b770>
<environment: namespace:vrtest>
>
```

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.