Public
Edited
Dec 2, 2022
1 fork
Insert cell
Insert cell
minb = -1
Insert cell
maxb = 1
Insert cell
startb = 0.5
Insert cell
viewof b = Inputs.range([minb, maxb], {value: startb, step: 0.1, label: "Choose a coefficient"})
Insert cell
plot = Plot.plot({
marks: [
Plot.line(z,{x: "x", y: "y", stroke: lineColour})
// Plot.line(z,{x: "Covariate value, e.g. Distance to Protected Area (km)", y: "Parameter prediction, e.g occupancy probability", stroke: lineColour})
],
xaxis: {
title: {
text: 'Covariate value, e.g. Distance to Protected Area (km)',
},
},
yaxis: {
title: {
text: 'Parameter prediction, e.g occupancy probability',
}
}
})
Insert cell
b
Insert cell
x = d3.range(-10, 10, 0.1)
Insert cell
function logistic(inputArray) {
return Math.exp(b *inputArray) / (1 + Math.exp(b * inputArray))
}

// function myFunctionWithParameters(firstName, lastName) {
// return `My first name is ${firstName}, and my last name is ${lastName}.`
// }
Insert cell
// pass a function to map
y = x.map(x => logistic(x))
Insert cell
z = x.map((x, i) => ({
x: x,
y: y[i]
}))

Insert cell
lineRGB = d3.scaleLinear()
.domain([minb, 0, maxb])
.range(["red", "purple", "blue"]);
Insert cell
lineRGB(-0.5); // "rgb(255, 128, 128)"
Insert cell
lineColourx = d3.color(lineRGB(b))
Insert cell
lineColourx
Insert cell
lineColour = d3.color(lineRGB(b)).formatHex()
Insert cell
// color = d3.scale.linear()
// .domain([100, 0])
// .range(colorbrewer.Reds[3])
Insert cell
// Plot.line(z,{x: "x", y: "y", stroke: "green"})
Insert cell
// {
// let trace = {
// x: numHoursStudied,
// y: predictedOutcomes,
// mode: 'markers',
// type: 'scatter'
// };

// let data = [trace];

// let layout = {
// title: 'Predicted probability of passing according to the logistic model',
// xaxis: {
// title: {
// text: 'Number of hours studied',
// },
// },
// yaxis: {
// title: {
// text: 'Probability of passing the exam',
// },
// range: [0, 1]
// },
// };

// const div = htl.html`<div/>`;
// Plotly.newPlot(div, data, layout);

// return div;
// }
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more