F distribution
moments_f = {
if (nu2>4){
return tex`
\begin{aligned}
&E( X) =\frac{\nu_2}{\nu_2-2} = ${(nu2/(nu2-2)).toPrecision(3)} \\[1em]
&Var( X) = 2\Big(\frac{\nu_2}{\nu_2-2}\Big)^2\frac{\nu_1+\nu_2-2}{\nu_1(\nu_2-4)} =
${(2*(nu2/(nu2-2))**2 * ((nu1+nu2-2)/(nu1*(nu2-4)))).toPrecision(3)} \\[1em]
&P( X\leq ${quantile}) =${fcdf.toPrecision(4)}
\end{aligned}
`
}
else{
if (nu2>2 && nu2<=4){
return tex`
\begin{aligned}
&E( X) =\frac{\nu_2}{\nu_2-2} = ${(nu2/(nu2-2)).toPrecision(3)} ( \nu_2>2 \text{ is needed} )\\[1em]
&Var( X) = \text{ does not exist} ( \nu_2>4 \text{ is needed} ) \\[1em]
&P( X\leq ${quantile}) =${fcdf.toPrecision(4)}
\end{aligned}
`
}
else{
return tex`
\begin{aligned}
&E( X) =\text{ does not exist} ( \nu_2>2 \text{ is needed} )\\[1em]
&Var( X) = \text{ does not exist} ( \nu_2>4 \text{ is needed} ) \\[1em]
&P( X\leq ${quantile}) =${fcdf.toPrecision(4)}
\end{aligned}
`
}
}
}plt_pdf_f = Plot.plot({
width: 800, // or a dynamic value based on `width` variable
height: 600,
style: {fontSize: "15px"},
color: {
legend: true
},
x: {
label: "x",
axis: true
},
y: {
label: "f(x)",
//axis: false,
//domain: [0,jstat.chisquare.pdf(mode, nu1, nu2)]
},
marks: [
Plot.ruleY([0]),
Plot.ruleX([0]),
Plot.line(fpdf, {x: "x", y: "pdf", stroke : "purple", strokeWidth: 2}),
Plot.areaY(fpdf, {filter: d => d.x <= quantile, x: "x", y: "pdf", fill: "purple", opacity: 0.2})
]
})