54 lines
1.2 KiB
R
54 lines
1.2 KiB
R
# %%
|
|
library(profoc)
|
|
library(ggplot2)
|
|
library(tidyr)
|
|
library(dplyr)
|
|
library(readr)
|
|
|
|
# Creating faceted plots for different knot values and mu values
|
|
# Create a function to generate the data for a given number of knots and mu value
|
|
generate_basis_data <- function(num_knots, mu_value) {
|
|
grid <- seq(0, 1, length.out = 20)
|
|
B <- profoc:::make_basis_matrix(grid,
|
|
profoc::make_knots(
|
|
n = num_knots,
|
|
mu = mu_value,
|
|
sig = 1,
|
|
nonc = 0,
|
|
deg = 1
|
|
),
|
|
deg = 3
|
|
)
|
|
df <- as.data.frame(as.matrix(B))
|
|
df$x <- grid
|
|
df_long <- pivot_longer(df,
|
|
cols = -x,
|
|
names_to = "b",
|
|
values_to = "y"
|
|
)
|
|
df_long$knots <- num_knots # Store knot count as numeric
|
|
df_long$mu <- mu_value # Add mu parameter information
|
|
return(df_long)
|
|
}
|
|
|
|
# Generate data for each combination of knot value and mu value
|
|
knot_values <- 5:10
|
|
mu_values <- seq(0.1, 0.9, by = 0.1)
|
|
|
|
# Create an empty list to store all combinations
|
|
all_data <- list()
|
|
counter <- 1
|
|
|
|
# Generate data for all combinations
|
|
for (k in knot_values) {
|
|
for (m in mu_values) {
|
|
all_data[[counter]] <- generate_basis_data(k, m)
|
|
counter <- counter + 1
|
|
}
|
|
}
|
|
|
|
# Combine all data frames
|
|
all_data <- bind_rows(all_data)
|
|
|
|
write_csv(all_data, "basis_functions.csv")
|