Update app.qmd (add inputs)
This commit is contained in:
48
app.qmd
48
app.qmd
@@ -19,10 +19,6 @@ d3 = require("d3@7")
|
||||
```{ojs}
|
||||
bsplineData = FileAttachment("basis_functions.csv").csv({ typed: true })
|
||||
|
||||
knotValues = Array.from(new Set(bsplineData.map(d => d.knots))).sort((a, b) => a - b)
|
||||
minKnots = Math.min(...knotValues)
|
||||
maxKnots = Math.max(...knotValues)
|
||||
|
||||
muValues = Array.from(new Set(bsplineData.map(d => d.mu))).sort((a, b) => a - b)
|
||||
minMu = Math.min(...muValues)
|
||||
maxMu = Math.max(...muValues)
|
||||
@@ -31,31 +27,20 @@ maxMu = Math.max(...muValues)
|
||||
```{ojs}
|
||||
chart = {
|
||||
// State variables for selected parameters
|
||||
let selectedKnots = minKnots;
|
||||
let selectedMu = 0.5;
|
||||
const filteredData = () => bsplineData.filter(d => selectedKnots == d.knots && Math.abs(selectedMu - d.mu) < 0.001);
|
||||
let selectedSig = 1;
|
||||
let selectedNonc = 0;
|
||||
let selectedTailw = 1;
|
||||
const filteredData = () => bsplineData.filter(d =>
|
||||
Math.abs(selectedMu - d.mu) < 0.001 &&
|
||||
d.sig === selectedSig &&
|
||||
d.nonc === selectedNonc &&
|
||||
d.tailw === selectedTailw
|
||||
);
|
||||
const container = d3.create("div").style("margin-bottom", "20px");
|
||||
const controlsContainer = container.append("div")
|
||||
.style("display", "flex")
|
||||
.style("gap", "20px");
|
||||
// Knots slider control
|
||||
const knotsControl = controlsContainer.append("div")
|
||||
.style("display","flex")
|
||||
.style("align-items","center")
|
||||
.style("gap","10px");
|
||||
knotsControl
|
||||
.append("label")
|
||||
.text("Knots:")
|
||||
.style("font-size","16px");
|
||||
knotsControl
|
||||
.append("input")
|
||||
.attr("type","range")
|
||||
.attr("min",minKnots)
|
||||
.attr("max",maxKnots)
|
||||
.attr("step",1)
|
||||
.property("value",selectedKnots)
|
||||
.on("input", function() { selectedKnots = +this.value; knotsControl.select("span").text(selectedKnots); updateChart(filteredData()); });
|
||||
knotsControl.append("span").text(selectedKnots).style("font-size","16px");;
|
||||
// μ slider control
|
||||
const muControl = controlsContainer.append("div").style("display","flex").style("align-items","center").style("gap","10px");
|
||||
muControl.append("label").text("μ:").style("font-size","16px");
|
||||
@@ -64,6 +49,21 @@ chart = {
|
||||
.property("value",selectedMu)
|
||||
.on("input", function() { selectedMu = +this.value; muControl.select("span").text(selectedMu); updateChart(filteredData()); });
|
||||
muControl.append("span").text(selectedMu).style("font-size","16px");
|
||||
// sigma control
|
||||
const sigControl = controlsContainer.append("div").style("display","flex").style("align-items","center").style("gap","10px");
|
||||
sigControl.append("label").text("Sigma:").style("font-size","16px");
|
||||
sigControl.append("select").selectAll("option").data([0.25,0.5,1,2,4]).enter().append("option").attr("value", d => d).property("selected", d => d === selectedSig).text(d => d);
|
||||
sigControl.select("select").on("change", function() { selectedSig = +this.value; updateChart(filteredData()); });
|
||||
// nonc control
|
||||
const noncControl = controlsContainer.append("div").style("display","flex").style("align-items","center").style("gap","10px");
|
||||
noncControl.append("label").text("Non-centrality:").style("font-size","16px");
|
||||
noncControl.append("select").selectAll("option").data([-4,0,2,4]).enter().append("option").attr("value", d => d).property("selected", d => d === selectedNonc).text(d => d);
|
||||
noncControl.select("select").on("change", function() { selectedNonc = +this.value; updateChart(filteredData()); });
|
||||
// tail weight control
|
||||
const tailwControl = controlsContainer.append("div").style("display","flex").style("align-items","center").style("gap","10px");
|
||||
tailwControl.append("label").text("Tail weight:").style("font-size","16px");
|
||||
tailwControl.append("select").selectAll("option").data([0.25,0.5,1,2,4]).enter().append("option").attr("value", d => d).property("selected", d => d === selectedTailw).text(d => d);
|
||||
tailwControl.select("select").on("change", function() { selectedTailw = +this.value; updateChart(filteredData()); });
|
||||
// Build SVG
|
||||
const width = 800;
|
||||
const height = 400;
|
||||
|
||||
48
test.R
48
test.R
@@ -7,43 +7,61 @@ 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)
|
||||
generate_basis_data <- function(num_knots, mu_value, sig_value, nonc_value, tailw_value, deg_value) {
|
||||
grid <- seq(from = 0.01, to = 0.99, length.out = 50)
|
||||
# Use provided degree
|
||||
B <- profoc:::make_basis_matrix(grid,
|
||||
profoc::make_knots(
|
||||
n = num_knots,
|
||||
mu = mu_value,
|
||||
sig = 1,
|
||||
nonc = 0,
|
||||
deg = 1
|
||||
sig = sig_value,
|
||||
nonc = nonc_value,
|
||||
tailw = tailw_value,
|
||||
deg = deg_value
|
||||
),
|
||||
deg = 3
|
||||
deg = deg_value
|
||||
)
|
||||
df <- as.data.frame(as.matrix(B))
|
||||
B_mat <- round(as.matrix(B),2)
|
||||
df <- as.data.frame(B_mat)
|
||||
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
|
||||
df_long$knots <- num_knots
|
||||
df_long$mu <- mu_value
|
||||
df_long$sig <- sig_value
|
||||
df_long$nonc <- nonc_value
|
||||
df_long$tailw <- tailw_value
|
||||
df_long$deg <- deg_value
|
||||
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)
|
||||
# Generate data for each combination of knot, mu, sig, nonc, tailw, and deg
|
||||
knot_values <- c(10)
|
||||
mu_values <- seq(0.1, 0.9, by = 0.2)
|
||||
sig_values <- 2^(-2:2)
|
||||
nonc_values <- c(-4,2,0,2,4)
|
||||
tailw_values <- 2^(-2:2)
|
||||
|
||||
# Create an empty list to store all combinations
|
||||
all_data <- list()
|
||||
counter <- 1
|
||||
|
||||
# Generate data for all combinations
|
||||
# Nested loops to cover all parameter combinations
|
||||
for (k in knot_values) {
|
||||
print(paste("Processing knots:", k))
|
||||
for (m in mu_values) {
|
||||
all_data[[counter]] <- generate_basis_data(k, m)
|
||||
counter <- counter + 1
|
||||
print(paste("Processing mu:", m))
|
||||
for (s in sig_values) {
|
||||
for (nc in nonc_values) {
|
||||
for (tw in tailw_values) {
|
||||
all_data[[counter]] <- generate_basis_data(5, m, s, nc, tw, 2)
|
||||
counter <- counter + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user