-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bartels rank test for randomness of residuals for linear regression #99
Comments
> getAnywhere(pbartelsrank)
A single object matching ‘pbartelsrank’ was found
It was found in the following places
package:randtests
namespace:randtests
with value
function (q, n, lower.tail = TRUE, log.p = FALSE)
{
stopifnot(is.numeric(q) & n > 0)
tmp <- permut(x = 1:n, m = n, FUN = randtests.aux, method = "bartels")[,
1]
yr <- rep(0, length(q))
for (i in 1:length(q)) {
yr[i] <- ifelse(lower.tail, sum(tmp <= q[i]), sum(tmp >
q[i]))
}
r0 <- yr/factorial(n)
ifelse(log.p, return(log(r0)), return(r0))
} |
> getAnywhere(dbartelsrank)
A single object matching ‘dbartelsrank’ was found
It was found in the following places
package:randtests
namespace:randtests
with value
function (x, n, log = FALSE)
{
stopifnot(is.numeric(x) & n > 0)
tmp <- permut(x = 1:n, m = n, FUN = randtests.aux, method = "bartels")[,
1]
yr <- rep(0, length(x))
for (i in 1:length(x)) {
yr[i] <- sum(tmp == x[i])
}
r0 <- yr/factorial(n)
ifelse(log, return(log(r0)), return(r0))
}
> getAnywhere(permut)
A single object matching ‘permut’ was found
It was found in the following places
package:randtests
namespace:randtests
with value
function (x, m = length(x), FUN = NULL, ...)
{
n <- length(x)
X <- NULL
if (m == 1)
X <- matrix(x, n, 1)
else if (n == 1)
X <- matrix(x, 1, m)
else if (n == 2 & m == 2)
X <- matrix(c(x, x[2:1]), 2, 2)
else if (n == 4 & m == 4 & is.null(FUN)) {
idx <- c(1:4, c(1:2, 4:3), c(1, 3, 2, 4), c(1, 3, 4,
2), c(1, 4, 2, 3), c(1, 4, 3, 2))
X <- rbind(X, matrix(x[idx], nrow = 6, ncol = 4, byrow = T))
X <- rbind(X, matrix((x[c(2, 1, 3:4)])[idx], nrow = 6,
ncol = 4, byrow = T))
X <- rbind(X, matrix((x[c(3, 1, 2, 4)])[idx], nrow = 6,
ncol = 4, byrow = T))
X <- rbind(X, matrix((x[c(4, 1:3)])[idx], nrow = 6, ncol = 4,
byrow = T))
}
else if (n == 5 & m == 5 & is.null(FUN)) {
idx <- c(1:5, 1:3, 5, 4, 1, 2, 4, 3, 5, 1, 2, 4, 5, 3,
1, 2, 5, 3, 4, 1, 2, 5, 4, 3, 1, 3, 2, 4, 5, 1, 3,
2, 5, 4, 1, 3, 4, 2, 5, 1, 3, 4, 5, 2, 1, 3, 5, 2,
4, 1, 3, 5, 4, 2, 1, 4, 2, 3, 5, 1, 4, 2, 5, 3, 1,
4, 3, 2, 5, 1, 4, 3, 5, 2, 1, 4, 5, 2, 3, 1, 4, 5,
3, 2, 1, 5, 2, 3, 4, 1, 5, 2, 4, 3, 1, 5, 3, 2, 4,
1, 5, 3, 4, 2, 1, 5, 4, 2, 3, 1, 5, 4, 3, 2)
X <- rbind(X, matrix(x[idx], nrow = 24, ncol = 5, byrow = T))
X <- rbind(X, matrix((x[c(2, 1, 3:5)])[idx], nrow = 24,
ncol = 5, byrow = T))
X <- rbind(X, matrix((x[c(3, 1, 2, 4, 5)])[idx], nrow = 24,
ncol = 5, byrow = T))
X <- rbind(X, matrix((x[c(4, 1, 2, 3, 5)])[idx], nrow = 24,
ncol = 5, byrow = T))
X <- rbind(X, matrix((x[c(5, 1, 2, 3, 4)])[idx], nrow = 24,
ncol = 5, byrow = T))
}
else {
for (i in 1:n) {
if (is.null(FUN)) {
X <- rbind(X, cbind(x[i], Recall(x[-i], m - 1)))
}
else {
y <- apply(cbind(x[i], Recall(x[-i], m - 1)),
1, FUN, ...)
X <- rbind(X, matrix(y))
}
}
}
return(X)
} |
References
|
The Bartels rank test for randomness can be used to check the randomness assumption of residuals in Regression.
This test should be part of
HypothesisTest.jl
We should do PR in
HypothesisTest.jl
Here is the R implementtation.
The text was updated successfully, but these errors were encountered: