-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_pc_directions.Rd
97 lines (82 loc) · 2.55 KB
/
plot_pc_directions.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_pc_directions.R
\name{plot_pc_directions}
\alias{plot_pc_directions}
\title{Plot principal component directions}
\usage{
plot_pc_directions(
fpcs,
fdasrvf,
fpca_method,
times = NULL,
digits = 0,
alpha = 1,
nrow = 1,
linesizes = NULL,
linetype = TRUE,
freey = FALSE
)
}
\arguments{
\item{fpcs}{Vector of numbers identifying the PCs to include in the plot}
\item{fdasrvf}{Object output from jointFPCA, horizFPCA, or vertFPCA}
\item{fpca_method}{Character string specifying the type of elastic fPCA method to use ('jfpca', 'hfpca', or 'vfpca')}
\item{times}{Optional vector of times (if not included, times will be represented on the interval from 0 to 1)}
\item{digits}{Number of digits to print in the title for the proportion of variability explained by a PC}
\item{alpha}{Vector of alpha values associated with lines in plot (length must match number of lines in plot)}
\item{nrow}{Number of rows to use when creating a grid of plots}
\item{linesizes}{Vector of line widths associated with lines in plot (length must match number of lines in plot)}
\item{linetype}{Vector of line types (e.g., "solid" or "dashed") associated with lines in plot (length must match number of lines in plot)}
\item{freey}{Indicator for whether y-axis should be freed across facets}
}
\value{
ggplot2 plot of specified principal component directions
}
\description{
Function for plotting the functional PC directions
}
\examples{
# Load packages
library(dplyr)
library(tidyr)
# Select a subset of functions from shifted peaks data
sub_ids <-
shifted_peaks$data |>
select(data, group, id) |>
distinct() |>
group_by(data, group) |>
slice(1:4) |>
ungroup()
# Create a smaller version of shifted data
shifted_peaks_sub <-
shifted_peaks$data |>
filter(id \%in\% sub_ids$id)
# Extract times
shifted_peaks_times = unique(shifted_peaks_sub$t)
# Convert training data to matrix
shifted_peaks_train_matrix <-
shifted_peaks_sub |>
filter(data == "Training") |>
select(-t) |>
mutate(index = paste0("t", index)) |>
pivot_wider(names_from = index, values_from = y) |>
select(-data, -id, -group) |>
as.matrix() |>
t()
# Obtain veesa pipeline training data
veesa_train <-
prep_training_data(
f = shifted_peaks_train_matrix,
time = shifted_peaks_times,
fpca_method = "jfpca"
)
# Plot principal directions of PC1
plot_pc_directions(
fpcs = 1,
fdasrvf = veesa_train$fpca_res,
fpca_method = "jfpca",
times = -shifted_peaks_times,
linesizes = rep(0.75,5),
alpha = 0.9
)
}