function graph_from_type(s) {
if (s == "A perfect linear relationship") {
let a = jstat.uniform.sample(1 / 3, 2 / 3);
let b = jstat.uniform.sample(-6, 6);
return make_perturbed_graph(
(x) => a * x + b,
(x) => 0,
-10,
10,
100
);
} else if (s == "A close to linear relationship") {
let a = jstat.uniform.sample(1 / 3, 2 / 3);
let b = jstat.uniform.sample(-6, 6);
return make_perturbed_graph(
(x) => a * x + b,
(x) => jstat.randn(),
-10,
10,
100
);
} else if (s == "A close to linear, but negative, relationship") {
let a = jstat.uniform.sample(1 / 3, 2 / 3);
let b = jstat.uniform.sample(-6, 6);
return make_perturbed_graph(
(x) => -a * x + b,
(x) => jstat.randn(),
-10,
10,
100
);
} else if (s == "A weaker relationship") {
let a = jstat.uniform.sample(-2 / 3, 2 / 3);
let b = jstat.uniform.sample(-6, 6);
return make_perturbed_graph(
(x) => a * x + b,
(x) => 4 * jstat.randn(),
-10,
10,
100
);
} else if (s == "A nonlinear relationship") {
let a = jstat.uniform.sample(-3, 1);
let b = jstat.uniform.sample(1, 3);
return make_perturbed_graph(
(x) => (x - a) * (x - b),
(x) => 0.6 * jstat.randn(),
-10,
10,
100
);
} else if (s == "No relationship") {
let a = jstat.uniform.sample(-3, 1);
let b = jstat.uniform.sample(1, 3);
return make_perturbed_graph(
(x) => 0,
(x) => jstat.uniform.sample(-10, 10),
-10,
10,
100
);
}
}