Init simple web-app
This commit is contained in:
52
test.R
Normal file
52
test.R
Normal file
@@ -0,0 +1,52 @@
|
||||
# %%
|
||||
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) {
|
||||
B <- profoc:::make_basis_matrix(1:99 / 100,
|
||||
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 <- 1:99 / 100
|
||||
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")
|
||||
Reference in New Issue
Block a user