Update DGP + app
This commit is contained in:
33
app.qmd
33
app.qmd
@@ -10,8 +10,6 @@ execute:
|
|||||||
highlight-style: github
|
highlight-style: github
|
||||||
---
|
---
|
||||||
|
|
||||||
## B-spline Basis Functions
|
|
||||||
|
|
||||||
```{ojs}
|
```{ojs}
|
||||||
d3 = require("d3@7")
|
d3 = require("d3@7")
|
||||||
```
|
```
|
||||||
@@ -43,36 +41,36 @@ chart = {
|
|||||||
.style("gap", "20px");
|
.style("gap", "20px");
|
||||||
// μ slider control
|
// μ slider control
|
||||||
const muControl = controlsContainer.append("div").style("display","flex").style("align-items","center").style("gap","10px");
|
const muControl = controlsContainer.append("div").style("display","flex").style("align-items","center").style("gap","10px");
|
||||||
muControl.append("label").text("μ:").style("font-size","16px");
|
muControl.append("label").text("Mu:").style("font-size","20px");
|
||||||
muControl.append("input")
|
muControl.append("input")
|
||||||
.attr("type","range").attr("min",minMu).attr("max",maxMu).attr("step",0.2)
|
.attr("type","range").attr("min",minMu).attr("max",maxMu).attr("step",0.2)
|
||||||
.property("value",selectedMu)
|
.property("value",selectedMu)
|
||||||
.on("input", function() { selectedMu = +this.value; muControl.select("span").text(selectedMu); updateChart(filteredData()); });
|
.on("input", function() { selectedMu = +this.value; muControl.select("span").text(selectedMu); updateChart(filteredData()); });
|
||||||
muControl.append("span").text(selectedMu).style("font-size","16px");
|
muControl.append("span").text(selectedMu).style("font-size","20px");
|
||||||
// sigma control
|
// sigma control
|
||||||
const sigControl = controlsContainer.append("div").style("display","flex").style("align-items","center").style("gap","10px");
|
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("label").text("Sigma:").style("font-size","20px");
|
||||||
sigControl.append("input")
|
sigControl.append("input")
|
||||||
.attr("type","range").attr("min", -2).attr("max", 2).attr("step", 1)
|
.attr("type","range").attr("min", -2).attr("max", 2).attr("step", 1)
|
||||||
.property("value", Math.log2(selectedSig))
|
.property("value", Math.log2(selectedSig))
|
||||||
.on("input", function() { selectedSig = 2 ** (+this.value); sigControl.select("span").text(selectedSig); updateChart(filteredData()); });
|
.on("input", function() { selectedSig = 2 ** (+this.value); sigControl.select("span").text(selectedSig); updateChart(filteredData()); });
|
||||||
sigControl.append("span").text(selectedSig).style("font-size","16px");
|
sigControl.append("span").text(selectedSig).style("font-size","20px");
|
||||||
// nonc control
|
// nonc control
|
||||||
const noncControl = controlsContainer.append("div").style("display","flex").style("align-items","center").style("gap","10px");
|
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("label").text("Noncentrality:").style("font-size","20px");
|
||||||
noncControl.append("input")
|
noncControl.append("input")
|
||||||
.attr("type","range").attr("min", -4).attr("max", 4).attr("step", 2)
|
.attr("type","range").attr("min", -4).attr("max", 4).attr("step", 2)
|
||||||
.property("value", selectedNonc)
|
.property("value", selectedNonc)
|
||||||
.on("input", function() { selectedNonc = +this.value; noncControl.select("span").text(selectedNonc); updateChart(filteredData()); });
|
.on("input", function() { selectedNonc = +this.value; noncControl.select("span").text(selectedNonc); updateChart(filteredData()); });
|
||||||
noncControl.append("span").text(selectedNonc).style("font-size","16px");
|
noncControl.append("span").text(selectedNonc).style("font-size","20px");
|
||||||
// tail weight control
|
// tail weight control
|
||||||
const tailwControl = controlsContainer.append("div").style("display","flex").style("align-items","center").style("gap","10px");
|
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("label").text("Tailweight:").style("font-size","20px");
|
||||||
tailwControl.append("input")
|
tailwControl.append("input")
|
||||||
.attr("type","range").attr("min", -2).attr("max", 2).attr("step", 1)
|
.attr("type","range").attr("min", -2).attr("max", 2).attr("step", 1)
|
||||||
.property("value", Math.log2(selectedTailw))
|
.property("value", Math.log2(selectedTailw))
|
||||||
.on("input", function() { selectedTailw = 2 ** (+this.value); tailwControl.select("span").text(selectedTailw); updateChart(filteredData()); });
|
.on("input", function() { selectedTailw = 2 ** (+this.value); tailwControl.select("span").text(selectedTailw); updateChart(filteredData()); });
|
||||||
tailwControl.append("span").text(selectedTailw).style("font-size","16px");
|
tailwControl.append("span").text(selectedTailw).style("font-size","20px");
|
||||||
// Build SVG
|
// Build SVG
|
||||||
const width = 800;
|
const width = 800;
|
||||||
const height = 400;
|
const height = 400;
|
||||||
@@ -80,9 +78,9 @@ chart = {
|
|||||||
const innerWidth = width - margin.left - margin.right;
|
const innerWidth = width - margin.left - margin.right;
|
||||||
const innerHeight = height - margin.top - margin.bottom;
|
const innerHeight = height - margin.top - margin.bottom;
|
||||||
// Set container width to match SVG plot width
|
// Set container width to match SVG plot width
|
||||||
container.style("max-width", `${width}px`).style("width", "100%");
|
container.style("max-width", "none").style("width", "100%");
|
||||||
// Set controls container width to match SVG plot width
|
// Set controls container width to match SVG plot width
|
||||||
controlsContainer.style("max-width", `${width}px`).style("width", "100%");
|
controlsContainer.style("max-width", "none").style("width", "100%");
|
||||||
// Distribute each control evenly and make sliders full-width
|
// Distribute each control evenly and make sliders full-width
|
||||||
controlsContainer.selectAll("div").style("flex", "1").style("min-width", "0px");
|
controlsContainer.selectAll("div").style("flex", "1").style("min-width", "0px");
|
||||||
controlsContainer.selectAll("input").style("width", "100%").style("box-sizing", "border-box");
|
controlsContainer.selectAll("input").style("width", "100%").style("box-sizing", "border-box");
|
||||||
@@ -101,9 +99,10 @@ chart = {
|
|||||||
|
|
||||||
// Create SVG
|
// Create SVG
|
||||||
const svg = d3.create("svg")
|
const svg = d3.create("svg")
|
||||||
.attr("width", width)
|
.attr("width", "100%")
|
||||||
.attr("height", height)
|
.attr("height", "auto")
|
||||||
.attr("viewBox", [0, 0, width, height])
|
.attr("viewBox", [0, 0, width, height])
|
||||||
|
.attr("preserveAspectRatio", "xMidYMid meet")
|
||||||
.attr("style", "max-width: 100%; height: auto;");
|
.attr("style", "max-width: 100%; height: auto;");
|
||||||
|
|
||||||
// Add chart title
|
// Add chart title
|
||||||
@@ -112,7 +111,7 @@ chart = {
|
|||||||
// .attr("x", width / 2)
|
// .attr("x", width / 2)
|
||||||
// .attr("y", 20)
|
// .attr("y", 20)
|
||||||
// .attr("text-anchor", "middle")
|
// .attr("text-anchor", "middle")
|
||||||
// .attr("font-size", "16px")
|
// .attr("font-size", "20px")
|
||||||
// .attr("font-weight", "bold");
|
// .attr("font-weight", "bold");
|
||||||
|
|
||||||
// Create the chart group
|
// Create the chart group
|
||||||
@@ -124,12 +123,12 @@ chart = {
|
|||||||
.attr("transform", `translate(0,${innerHeight})`)
|
.attr("transform", `translate(0,${innerHeight})`)
|
||||||
.attr("class", "x-axis")
|
.attr("class", "x-axis")
|
||||||
.call(d3.axisBottom(x).ticks(10))
|
.call(d3.axisBottom(x).ticks(10))
|
||||||
.style("font-size", "16px");
|
.style("font-size", "20px");
|
||||||
|
|
||||||
const yAxis = g.append("g")
|
const yAxis = g.append("g")
|
||||||
.attr("class", "y-axis")
|
.attr("class", "y-axis")
|
||||||
.call(d3.axisLeft(y).ticks(5))
|
.call(d3.axisLeft(y).ticks(5))
|
||||||
.style("font-size", "16px");
|
.style("font-size", "20px");
|
||||||
|
|
||||||
// Add axis labels
|
// Add axis labels
|
||||||
// g.append("text")
|
// g.append("text")
|
||||||
|
|||||||
2
test.R
2
test.R
@@ -23,7 +23,7 @@ generate_basis_data <- function(num_knots, mu_value, sig_value, nonc_value, tail
|
|||||||
)
|
)
|
||||||
B_mat <- round(as.matrix(B),2)
|
B_mat <- round(as.matrix(B),2)
|
||||||
df <- as.data.frame(B_mat)
|
df <- as.data.frame(B_mat)
|
||||||
df$x <- grid
|
df$x <- round(grid,2)
|
||||||
df_long <- pivot_longer(df,
|
df_long <- pivot_longer(df,
|
||||||
cols = -x,
|
cols = -x,
|
||||||
names_to = "b",
|
names_to = "b",
|
||||||
|
|||||||
Reference in New Issue
Block a user