Skip to content

Commit

Permalink
adding files associated with manuscript
Browse files Browse the repository at this point in the history
  • Loading branch information
goodekat committed Dec 20, 2024
1 parent 583da3f commit 1ecdbcb
Show file tree
Hide file tree
Showing 67 changed files with 7,109 additions and 3 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ README.Rmd
README_files
.github
cran-comments.md
^inst
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.RData
.Ruserdata
*.DS_Store
*.Rproj
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: veesa
Type: Package
Title: VEESA Pipeline for Explainable Machine Learning with Functional Data
Version: 0.1.1
Version: 0.1.2
Author: Katherine Goode, J. Derek Tucker
Maintainer: Katherine Goode <[email protected]>
Description: Contains functions that are helpful when applying the VEESA pipeline in R.
Description: Contains functions for applying the VEESA pipeline in R.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# veesa 0.1.2

- Added shifted peaks data
- Added example code from manuscript

# veesa 0.1.1

- Adjusted title in plot_pc_directions
- Updated code to new version of fdasrvf

# veesa 0.1.0

Initial version of package
Initial version of package
9 changes: 9 additions & 0 deletions R/data_shifted_peaks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#' "Shifted Peaks" Simulated Dataset
#'
#' A simulated dataset generated for examples in the veesa pipeline manuscript.
#' For the code used to prepare this dataset, see
#' https://github.com/sandialabs/veesa/inst/data-shifted-peaks.md.
#'
#' @format A data.frame.

"shifted_peaks"
Binary file modified README_files/figure-gfm/unnamed-chunk-10-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-10-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-10-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-15-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-15-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-15-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-16-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-16-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-16-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-18-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-18-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-18-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-20-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-20-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-21-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-21-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-23-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-23-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-9-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/unnamed-chunk-9-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/shifted_peaks.rda
Binary file not shown.
120 changes: 120 additions & 0 deletions inst/generate-data/shifted-peaks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
Shifted Peaks Data
================

Load packages:

``` r
library(dplyr)
library(ggplot2)
library(purrr)
```

Specify parameters:

``` r
z1 = 1; z1_sd = 0.05; a1 = -3; a1_sd = 1
z2 = 1.25; z2_sd = 0.05; a2 = 3; a2_sd = 1
```

Specify the times:

``` r
times = seq(-15, 15, length.out = 150)
```

Functions:

``` r
# Function for simulating data
generate_data = function(id, group, t) {
if (group == 1) {
z = rnorm(1, z1, z1_sd)
a = rnorm(1, a1, a1_sd)
}
if (group == 2) {
z = rnorm(1, z2, z2_sd)
a = rnorm(1, a2, a2_sd)
}
y = z * exp((-((t - a)^2)) / 2)

data.frame(id, group = as.character(group), index = 1:length(t), t, y)
}

# Function for generating true means
true_mean = function(group, t) {
if (group == 1) {
z = z1
a = a1
}
if (group == 2) {
z = z2
a = a2
}
y = z * exp((-((t - a)^2)) / 2)
data.frame(group = as.character(group), index = 1:length(t), t, y)
}
```

Specify the sample sizes:

``` r
ntrain = 400
ntest = 100
n = ntrain + ntest
```

Simulate data:

``` r
set.seed(20211027)
shifted_peaks <-
map2_df(
.x = 1:n,
.y = c(rep(1:2, each = n / 2)),
.f = generate_data,
t = times
)
```

Randomly select ids from the simulated data for the training data:

``` r
train_ids = sample(unique(shifted_peaks$id), ntrain, F)
```

Add training/testing variable:

``` r
shifted_peaks <-
shifted_peaks |>
mutate(data = ifelse(id %in% train_ids, "Training", "Testing")) |>
select(data, id, group, everything()) |>
mutate(data = forcats::fct_relevel(data, "Training", "Testing")) |>
mutate(group = factor(group))
```

Plot of the data:

``` r
ggplot(shifted_peaks, aes(x = t, y = y, color = group, group = id)) +
geom_line(alpha = 0.35) +
facet_grid(. ~ data) +
theme_bw() +
scale_color_manual(values = wesanderson::wes_palettes$Royal1[2:1]) +
ylim(0, 1.4) +
guides(color = guide_legend(override.aes = list(alpha = 1))) +
labs(
color = "Group",
title = "Simulated functions",
x = "Time",
y = "y"
)
```

![](shifted-peaks_files/figure-commonmark/unnamed-chunk-9-1.png)

Save the simulated data:

``` r
save(shifted_peaks, file = "../../data/shifted_peaks.rda")
```
123 changes: 123 additions & 0 deletions inst/generate-data/shifted-peaks.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: "Shifted Peaks Data"
format: gfm
---

Load packages:

```{r}
#| message: false
library(dplyr)
library(ggplot2)
library(purrr)
```

Specify parameters:

```{r}
z1 = 1; z1_sd = 0.05; a1 = -3; a1_sd = 1
z2 = 1.25; z2_sd = 0.05; a2 = 3; a2_sd = 1
```

Specify the times:

```{r}
times = seq(-15, 15, length.out = 150)
```

Functions:

```{r}
# Function for simulating data
generate_data = function(id, group, t) {
if (group == 1) {
z = rnorm(1, z1, z1_sd)
a = rnorm(1, a1, a1_sd)
}
if (group == 2) {
z = rnorm(1, z2, z2_sd)
a = rnorm(1, a2, a2_sd)
}
y = z * exp((-((t - a)^2)) / 2)
data.frame(id, group = as.character(group), index = 1:length(t), t, y)
}
# Function for generating true means
true_mean = function(group, t) {
if (group == 1) {
z = z1
a = a1
}
if (group == 2) {
z = z2
a = a2
}
y = z * exp((-((t - a)^2)) / 2)
data.frame(group = as.character(group), index = 1:length(t), t, y)
}
```

Specify the sample sizes:

```{r}
ntrain = 400
ntest = 100
n = ntrain + ntest
```

Simulate data:

```{r}
set.seed(20211027)
shifted_peaks <-
map2_df(
.x = 1:n,
.y = c(rep(1:2, each = n / 2)),
.f = generate_data,
t = times
)
```

Randomly select ids from the simulated data for the training data:

```{r}
train_ids = sample(unique(shifted_peaks$id), ntrain, F)
```

Add training/testing variable:

```{r}
shifted_peaks <-
shifted_peaks |>
mutate(data = ifelse(id %in% train_ids, "Training", "Testing")) |>
select(data, id, group, everything()) |>
mutate(data = forcats::fct_relevel(data, "Training", "Testing")) |>
mutate(group = factor(group))
```

Plot of the data:

```{r}
#| fig-width: 16
#| fig-height: 4
ggplot(shifted_peaks, aes(x = t, y = y, color = group, group = id)) +
geom_line(alpha = 0.35) +
facet_grid(. ~ data) +
theme_bw() +
scale_color_manual(values = wesanderson::wes_palettes$Royal1[2:1]) +
ylim(0, 1.4) +
guides(color = guide_legend(override.aes = list(alpha = 1))) +
labs(
color = "Group",
title = "Simulated functions",
x = "Time",
y = "y"
)
```

Save the simulated data:

```{r}
save(shifted_peaks, file = "../../data/shifted_peaks.rda")
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1ecdbcb

Please sign in to comment.