Skip to content

Commit

Permalink
good practice
Browse files Browse the repository at this point in the history
-additional indentation
- build vignette
- change .Rbuildignore
  • Loading branch information
giovsaraceno committed Mar 8, 2024
1 parent 5828c70 commit a0edc7f
Show file tree
Hide file tree
Showing 27 changed files with 38 additions and 1,942 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
^LICENSE\.md$
^doc$
^Meta$
^codemeta.json$
^codemeta\.json$
^\.github$
^CONTRIBUTING\.md$
^codecov\.yml$
2 changes: 1 addition & 1 deletion .Rproj.user/F4975BFA/pcs/files-pane.pper
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"ascending": true
}
],
"path": "~/GitHub/QuadratiK-package/vignettes"
"path": "~/GitHub/QuadratiK-package"
}
2 changes: 1 addition & 1 deletion .Rproj.user/F4975BFA/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab": 23
"activeTab": 3
}
2 changes: 1 addition & 1 deletion .Rproj.user/F4975BFA/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"windowheight": 619
},
"right": {
"splitterpos": 319,
"splitterpos": 358,
"topwindowstate": "NORMAL",
"panelheight": 581,
"windowheight": 619
Expand Down
7 changes: 7 additions & 0 deletions .Rproj.user/shared/notebooks/paths
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
C:/Users/sarac/Documents/GitHub/QuadratiK-package/.Rbuildignore="C485D008"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/DESCRIPTION="81DC6CFF"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/R/QuadratiK-package.R="3289712E"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/R/RcppExports.R="1C52515A"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/R/classes.R="577DA69C"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/R/critical_value.R="A50610C8"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/R/h_selection.R="CC326A5C"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/R/kb.test.R="0E2DB6A5"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/R/pk.test.R="3CC5D390"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/R/pkbd_functions.R="1BEA4C49"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/R/wireless.R="5FF8D491"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/codecov.yml="C78935A5"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/codemeta.json="35775251"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/man/QuadratiK-package.Rd="71173F69"
Expand All @@ -15,8 +19,11 @@ C:/Users/sarac/Documents/GitHub/QuadratiK-package/tests/testthat/test-pkbc.R="32
C:/Users/sarac/Documents/GitHub/QuadratiK-package/tests/testthat/test-rpkb.R="251BDAC0"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/tests/testthat/test-sample_hypersphere.R="599F043F"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/tests/testthat/test.dpkb.R="449F69A9"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/vignettes/TwoSample_test.R="76EE7DD8"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/vignettes/TwoSample_test.Rmd="77787FE7"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/vignettes/kSample_test.R="81A6DE0C"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/vignettes/kSample_test.Rmd="61D887F6"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/vignettes/uniformity.R="0370929A"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/vignettes/uniformity.Rmd="89CAEE2E"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/vignettes/wireless_clustering.R="2C6FE7FD"
C:/Users/sarac/Documents/GitHub/QuadratiK-package/vignettes/wireless_clustering.Rmd="FC40ACF9"
Binary file modified Meta/vignette.rds
Binary file not shown.
4 changes: 2 additions & 2 deletions R/clustering_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ setMethod("pkbc", signature(dat = "ANY"),
memb_best <- apply(normprobMat_best, 1, which.max)

# Calculate the within-cluster sum of squares
wcss <- vapply(1:numClust, function(cl) {
wcss <- sapply(1:numClust, function(cl) {
idx <- which(memb_best==cl)

if(length(idx)>0){
Expand All @@ -306,7 +306,7 @@ setMethod("pkbc", signature(dat = "ANY"),

# Calculate the within-cluster sum of squares using cosine
# similarity
wcss_cos <- vapply(1:numClust, function(cl) {
wcss_cos <- sapply(1:numClust, function(cl) {
idx <- which(memb_best==cl)
if(length(idx)>0){
dat_memb <- matrix(t(dat[idx,]),ncol=numVar, byrow=TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/pkbd_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ rpkb <- function(n, mu, rho, method = 'rejvmf') {

} else if (method == 'rejpsaw') {

retvals <- vapply(1:n, function(x){
retvals <- sapply(1:n, function(x){
lambda <- (2*rho)/(1+rho^2)
# pSaw: log-density and derivatives
lpdf <- function(t) {-p*log(1-lambda*t) + (p-3)*(log(1+t) + log(1-t))}
Expand Down
2 changes: 1 addition & 1 deletion doc/TwoSample_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ x_2 <- rmvnorm(n, mean = rep(0,d))
y_2 <- rmsn(n=n, xi=0, Omega = diag(d), alpha=rep(skewness_y,d))

## -----------------------------------------------------------------------------
h = 2
h <- 2
set.seed(2468)
two_test <- kb.test(x=x_2, y=y_2, h=h)

Expand Down
2 changes: 1 addition & 1 deletion doc/TwoSample_test.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ y_2 <- rmsn(n=n, xi=0, Omega = diag(d), alpha=rep(skewness_y,d))
```

```{r}
h = 2
h <- 2
set.seed(2468)
two_test <- kb.test(x=x_2, y=y_2, h=h)
```
Expand Down
2 changes: 1 addition & 1 deletion doc/TwoSample_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ <h3>Non-parametric two-sample test</h3>
<span id="cb1-7"><a href="#cb1-7" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">2468</span>)</span>
<span id="cb1-8"><a href="#cb1-8" tabindex="-1"></a>x_2 <span class="ot">&lt;-</span> <span class="fu">rmvnorm</span>(n, <span class="at">mean =</span> <span class="fu">rep</span>(<span class="dv">0</span>,d))</span>
<span id="cb1-9"><a href="#cb1-9" tabindex="-1"></a>y_2 <span class="ot">&lt;-</span> <span class="fu">rmsn</span>(<span class="at">n=</span>n, <span class="at">xi=</span><span class="dv">0</span>, <span class="at">Omega =</span> <span class="fu">diag</span>(d), <span class="at">alpha=</span><span class="fu">rep</span>(skewness_y,d))</span></code></pre></div>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a>h <span class="ot">=</span> <span class="dv">2</span></span>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a>h <span class="ot">&lt;-</span> <span class="dv">2</span></span>
<span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">2468</span>)</span>
<span id="cb2-3"><a href="#cb2-3" tabindex="-1"></a>two_test <span class="ot">&lt;-</span> <span class="fu">kb.test</span>(<span class="at">x=</span>x_2, <span class="at">y=</span>y_2, <span class="at">h=</span>h)</span></code></pre></div>
<p>For the two-sample case, the <code>summary</code> function provides
Expand Down
4 changes: 2 additions & 2 deletions doc/kSample_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
library(mvtnorm)
library(QuadratiK)
sizes <- rep(200,3)
eps = 1
eps <- 1
set.seed(2468)
x1 <- rmvnorm(sizes[1], mean = c(0,sqrt(3)*eps/3))
x2 <- rmvnorm(sizes[2], mean = c(-eps/2,-sqrt(3)*eps/6))
Expand All @@ -11,7 +11,7 @@ x <- rbind(x1, x2, x3)
y <- as.factor(rep(c(1,2,3), times=sizes))

## -----------------------------------------------------------------------------
h=1.5
h <- 1.5
set.seed(2468)
k_test <- kb.test(x=x, y=y, h=h)
k_test
Expand Down
4 changes: 2 additions & 2 deletions doc/kSample_test.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ We generated three samples, with $n=200$ observations each, from a 2-dimensional
library(mvtnorm)
library(QuadratiK)
sizes <- rep(200,3)
eps = 1
eps <- 1
set.seed(2468)
x1 <- rmvnorm(sizes[1], mean = c(0,sqrt(3)*eps/3))
x2 <- rmvnorm(sizes[2], mean = c(-eps/2,-sqrt(3)*eps/6))
Expand All @@ -25,7 +25,7 @@ y <- as.factor(rep(c(1,2,3), times=sizes))
```
Recall that the computed test statistics correspond to the omnibus tests.
```{r}
h=1.5
h <- 1.5
set.seed(2468)
k_test <- kb.test(x=x, y=y, h=h)
k_test
Expand Down
4 changes: 2 additions & 2 deletions doc/kSample_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ <h3><span class="math inline">\(k\)</span>-sample test</h3>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="fu">library</span>(mvtnorm)</span>
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a><span class="fu">library</span>(QuadratiK)</span>
<span id="cb1-3"><a href="#cb1-3" tabindex="-1"></a>sizes <span class="ot">&lt;-</span> <span class="fu">rep</span>(<span class="dv">200</span>,<span class="dv">3</span>)</span>
<span id="cb1-4"><a href="#cb1-4" tabindex="-1"></a>eps <span class="ot">=</span> <span class="dv">1</span></span>
<span id="cb1-4"><a href="#cb1-4" tabindex="-1"></a>eps <span class="ot">&lt;-</span> <span class="dv">1</span></span>
<span id="cb1-5"><a href="#cb1-5" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">2468</span>)</span>
<span id="cb1-6"><a href="#cb1-6" tabindex="-1"></a>x1 <span class="ot">&lt;-</span> <span class="fu">rmvnorm</span>(sizes[<span class="dv">1</span>], <span class="at">mean =</span> <span class="fu">c</span>(<span class="dv">0</span>,<span class="fu">sqrt</span>(<span class="dv">3</span>)<span class="sc">*</span>eps<span class="sc">/</span><span class="dv">3</span>))</span>
<span id="cb1-7"><a href="#cb1-7" tabindex="-1"></a>x2 <span class="ot">&lt;-</span> <span class="fu">rmvnorm</span>(sizes[<span class="dv">2</span>], <span class="at">mean =</span> <span class="fu">c</span>(<span class="sc">-</span>eps<span class="sc">/</span><span class="dv">2</span>,<span class="sc">-</span><span class="fu">sqrt</span>(<span class="dv">3</span>)<span class="sc">*</span>eps<span class="sc">/</span><span class="dv">6</span>))</span>
Expand All @@ -363,7 +363,7 @@ <h3><span class="math inline">\(k\)</span>-sample test</h3>
<span id="cb1-10"><a href="#cb1-10" tabindex="-1"></a>y <span class="ot">&lt;-</span> <span class="fu">as.factor</span>(<span class="fu">rep</span>(<span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>), <span class="at">times=</span>sizes))</span></code></pre></div>
<p>Recall that the computed test statistics correspond to the omnibus
tests.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a>h<span class="ot">=</span><span class="fl">1.5</span></span>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a>h <span class="ot">&lt;-</span> <span class="fl">1.5</span></span>
<span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">2468</span>)</span>
<span id="cb2-3"><a href="#cb2-3" tabindex="-1"></a>k_test <span class="ot">&lt;-</span> <span class="fu">kb.test</span>(<span class="at">x=</span>x, <span class="at">y=</span>y, <span class="at">h=</span>h)</span>
<span id="cb2-4"><a href="#cb2-4" tabindex="-1"></a>k_test</span></code></pre></div>
Expand Down
2 changes: 1 addition & 1 deletion doc/uniformity.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ z <- matrix(rnorm(n * d), n, d)
dat_sphere <- z/sqrt(rowSums(z^2))

## -----------------------------------------------------------------------------
rho = 0.7
rho <- 0.7
set.seed(2468)
res_unif <- pk.test(x=dat_sphere, rho=rho)

Expand Down
2 changes: 1 addition & 1 deletion doc/uniformity.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dat_sphere <- z/sqrt(rowSums(z^2))

The ``pk.test`` is used for testing uniformity of the generated sample.
```{r}
rho = 0.7
rho <- 0.7
set.seed(2468)
res_unif <- pk.test(x=dat_sphere, rho=rho)
Expand Down
8 changes: 5 additions & 3 deletions doc/uniformity.html
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,14 @@ <h3>Uniformity test on the Sphere</h3>
<span id="cb1-6"><a href="#cb1-6" tabindex="-1"></a>dat_sphere <span class="ot">&lt;-</span> z<span class="sc">/</span><span class="fu">sqrt</span>(<span class="fu">rowSums</span>(z<span class="sc">^</span><span class="dv">2</span>))</span></code></pre></div>
<p>The <code>pk.test</code> is used for testing uniformity of the
generated sample.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a>rho <span class="ot">=</span> <span class="fl">0.7</span></span>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a>rho <span class="ot">&lt;-</span> <span class="fl">0.7</span></span>
<span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a><span class="fu">set.seed</span>(<span class="dv">2468</span>)</span>
<span id="cb2-3"><a href="#cb2-3" tabindex="-1"></a>res_unif <span class="ot">&lt;-</span> <span class="fu">pk.test</span>(<span class="at">x=</span>dat_sphere, <span class="at">rho=</span>rho)</span>
<span id="cb2-4"><a href="#cb2-4" tabindex="-1"></a></span>
<span id="cb2-5"><a href="#cb2-5" tabindex="-1"></a>res_unif</span></code></pre></div>
<pre><code>##
## Poisson Kernel-based quadratic distance test of Uniformity on the Sphere
## Poisson Kernel-based quadratic distance test of
## Uniformity on the Sphere
## Selected consentration parameter rho: 0.7
##
## U-statistic:
Expand All @@ -381,7 +382,8 @@ <h3>Uniformity test on the Sphere</h3>
variable with a table of standard descriptive statistics.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a>summary_unif <span class="ot">&lt;-</span> <span class="fu">summary</span>(res_unif)</span></code></pre></div>
<pre><code>##
## Poisson Kernel-based quadratic distance test of Uniformity on the Sphere
## Poisson Kernel-based quadratic distance test of
## Uniformity on the Sphere
## Test_Statistics Critical_Value Reject_H0
## 1 -0.9756673 0.02660107 FALSE
## 2 14.8959834 23.22948694 FALSE</code></pre>
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-kb.test.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ test_that("Error on invalid method input", {
expect_error(kb.test(x = matrix(rnorm(100), ncol = 2), h=0.5,
method = "invalid_method"),
"method must be one of 'bootstrap', 'permutation' or
'subsampling'", fixed=TRUE)
'subsampling'", fixed=TRUE)
})

# Test 2: Verify Error on Invalid b Input
test_that("Error on invalid b input", {
expect_error(kb.test(x = matrix(rnorm(100), ncol = 2), h=0.5, b = 10),
"b indicates the proportion used for the subsamples in the
subsampling algoritm. It must be in (0,1]", fixed=TRUE)
subsampling algoritm. It must be in (0,1].", fixed=TRUE)
})

# Test 3: Error on Invalid alternative Input
Expand All @@ -24,9 +24,9 @@ test_that("Error on invalid alternative input", {
expect_error(kb.test(x = matrix(rnorm(100), ncol= 2),
y = matrix(rnorm(100), ncol= 2), h=0.5,
alternative = "invalid"),
"The algorithm for selecting the value of h can be performed
with respect to the following families of alternatives:
'location', 'scale' or 'skewness'", fixed=TRUE)
"The algorithm for selecting the value of h can be performed
with respect to the following families of alternatives:
'location', 'scale' or 'skewness'", fixed=TRUE)
})

# Test 4: Error on Invalid centeringType Input
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-pkbc.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ dat<-rbind(data1$x,data2$x, data3$x)

# Test 1: Verify Error on Invalid nClust
test_that("Error is thrown for invalid nClust", {
expect_error(pkbc(dat, nClust = 0), "nClust must be greater than 0")
dat <- matrix(rnorm(100),ncol=2)
expect_error(pkbc(dat, nClust = 0), "Values in the input parameter nClust must be
greater than 0")
})

# Test 2: Test for valid input
Expand Down
32 changes: 0 additions & 32 deletions vignettes/TwoSample_test.R

This file was deleted.

Loading

0 comments on commit a0edc7f

Please sign in to comment.