PageSourceSearch

https://www.stats4stem.org/_next/static/chunks/22635.44b2c87720bd5015.js

js stats4stem.org collected 2026-10-07 18:01:54 UTC 12,733 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[22635],{22635:(e,t,s)=>{s.r(t),s.d(t,{default:()=>h});var r=s(95155),l=s(12115);function a(e){let t=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23];if(e<.5)return Math.log(Math.PI/Math.sin(Math.PI*e))-a(1-e);let s=t[0],r=(e-=1)+7+.5;for(let r=1;r<9;r++)s+=t[r]/(e+r);return .5*Math.log(2*Math.PI)+(e+.5)*Math.log(r)-r+Math.log(s)}function n(e,t){if(e<=0)return 0;let s=t/2;return Math.exp((s-1)*Math.log(e)-e/2-s*Math.log(2)-a(s))}function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;return e.toFixed(t)}let d={left:50,right:50,top:20,bottom:40},i=700-d.left-d.right,c=280-d.top-d.bottom,x=[{name:"Brown",observed:61,expectedProp:.13},{name:"Yellow",observed:64,expectedProp:.14},{name:"Red",observed:54,expectedProp:.13},{name:"Blue",observed:61,expectedProp:.24},{name:"Orange",observed:96,expectedProp:.2},{name:"Green",observed:64,expectedProp:.16}];function h(){let[e,t]=(0,l.useState)(x),[s,h]=(0,l.useState)(.05),[p,m]=(0,l.useState)("state"),b=e.reduce((e,t)=>e+t.observed,0),u=e.reduce((e,t)=>e+t.expectedProp,0),j=e.map(e=>e.expectedProp*b),f=e.map((e,t)=>{let s=j[t];return s>0?(e.observed-s)**2/s:0}),g=f.reduce((e,t)=>e+t,0),N=e.length-1,v=1-(g<=0?0:function(e,t){if(t<=0)return 0;let s=0,r=1/e;for(let l=0;l<200&&(s+=r,!(1e-14>Math.abs(r*=t/(e+l+1))));l++);return s*Math.exp(-t+e*Math.log(t)-a(e))}(N/2,g/2)),y=v<s,w=j.every(e=>e>=5),M=Math.max(1.5*g,N+4*Math.sqrt(2*N),15),C=N>=2?1.3*n(Math.max(.01,N-2),N):1.3*Math.min(n(.1,N),2),k=e=>d.left+(e-0)/(M-0)*i,P=e=>d.top+(1-e/C)*c,S=[];for(let e=0;e<=300;e++){let t=0+e/300*(M-0),s=n(t,N),r=0===e?"M":"L";S.push("".concat(r).concat(k(t).toFixed(2),",").concat(P(s).toFixed(2)))}let F=S.join(" "),E=function(e,t){let s=[],r=Math.max(e,.001),l=Math.min(t,M);s.push("M".concat(k(r).toFixed(2),",").concat(P(0).toFixed(2)));for(let e=0;e<=100;e++){let t=r+e/100*(l-r),a=n(t,N);s.push("L".concat(k(t).toFixed(2),",").concat(P(a).toFixed(2)))}return s.push("L".concat(k(l).toFixed(2),",").concat(P(0).toFixed(2)," Z")),s.join(" ")}(g,M),T=Math.max(1,Math.round(M/8)),O=[];for(let e=0;e<=M;e+=T)O.push(e);let W=(e,s,r)=>{t(t=>t.map((t,l)=>l!==e?t:"name"===s?{...t,name:r}:"observed"===s?{...t,observed:Math.max(0,Number(r)||0)}:{...t,expectedProp:Math.max(0,Number(r)||0)}))},q=s=>{e.length>2&&t(e=>e.filter((e,t)=>t!==s))},A=e=>m(p===e?null:e);return(0,r.jsxs)("div",{className:"mx-auto max-w-6xl rounded-xl border border-slate-200 bg-white p-6 shadow-sm",children:[(0,r.jsx)("h2",{className:"mb-4 text-xl font-bold text-slate-800",children:"Chi-Square Goodness of Fit Test"}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 xl:grid-cols-[1fr_340px]",children:[(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)("div",{className:"overflow-x-auto",children:[(0,r.jsxs)("table",{className:"w-full text-sm border-collapse",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"bg-slate-100",children:[(0,r.jsx)("th",{className:"border border-slate-300 px-3 py-2 text-left",children:"Category"}),(0,r.jsx)("th",{className:"border border-slate-300 px-3 py-2 text-right",children:"Observed (O)"}),(0,r.jsx)("th",{className:"border border-slate-300 px-3 py-2 text-right",children:"Expected Prop"}),(0,r.jsx)("th",{className:"border border-slate-300 px-3 py-2 text-right",children:"Expected (E)"}),(0,r.jsx)("th",{className:"border border-slate-300 px-3 py-2 text-right",children:"(O-E)\xb2/E"}),(0,r.jsx)("th",{className:"border border-slate-300 px-3 py-2 w-8"})]})}),(0,r.jsxs)("tbody",{children:[e.map((e,t)=>(0,r.jsxs)("tr",{className:"hover:bg-slate-50",children:[(0,r.jsx)("td",{className:"border border-slate-300 px-1 py-1",children:(0,r.jsx)("input",{type:"text",value:e.name,onChange:e=>W(t,"name",e.target.value),className:"w-full rounded border-0 bg-transparent px-2 py-1 text-sm focus:outline-none focus:ring-1 focus:ring-blue-400"})}),(0,r.jsx)("td",{className:"border border-slate-300 px-1 py-1",children:(0,r.jsx)("input",{type:"number",min:0,value:e.observed,onChange:e=>W(t,"observed",e.target.value),className:"w-full rounded border-0 bg-transparent px-2 py-1 text-right text-sm focus:outline-none focus:ring-1 focus:ring-blue-400"})}),(0,r.jsx)("td",{className:"border border-slate-300 px-1 py-1",children:(0,r.jsx)("input",{type:"number",min:0,step:.
101,value:e.expectedProp,onChange:e=>W(t,"expectedProp",e.target.value),className:"w-full rounded border-0 bg-transparent px-2 py-1 text-right text-sm focus:outline-none focus:ring-1 focus:ring-blue-400"})}),(0,r.jsx)("td",{className:"border border-slate-300 px-3 py-2 text-right font-mono text-slate-600",children:o(j[t],2)}),(0,r.jsx)("td",{className:"border border-slate-300 px-3 py-2 text-right font-mono text-slate-600",children:o(f[t],4)}),(0,r.jsx)("td",{className:"border border-slate-300 px-1 py-1 text-center",children:(0,r.jsx)("button",{onClick:()=>q(t),className:"text-red-400 hover:text-red-600 text-xs font-bold",title:"Remove row",children:"\xd7"})})]},t)),(0,r.jsxs)("tr",{className:"bg-slate-50 font-semibold",children:[(0,r.jsx)("td",{className:"border border-slate-300 px-3 py-2",children:"Total"}),(0,r.jsx)("td",{className:"border border-slate-300 px-3 py-2 text-right",children:b}),(0,r.jsx)("td",{className:"border border-slate-300 px-3 py-2 text-right font-mono",children:(0,r.jsx)("span",{className:Math.abs(u-1)>.01?"text-red-600":"text-green-700",children:o(u,3)})}),(0,r.jsx)("td",{className:"border border-slate-300 px-3 py-2 text-right font-mono",children:o(b,2)}),(0,r.jsx)("td",{className:"border border-slate-300 px-3 py-2 text-right font-mono font-bold text-blue-700",children:o(g,4)}),(0,r.jsx)("td",{className:"border border-slate-300"})]})]})]}),(0,r.jsxs)("div",{className:"mt-2 flex items-center gap-3",children:[(0,r.jsx)("button",{onClick:()=>t(e=>[...e,{name:"Cat ".concat(e.length+1),observed:10,expectedProp:.1}]),className:"rounded bg-slate-200 px-3 py-1 text-xs font-medium text-slate-700 hover:bg-slate-300",children:"+ Add Category"}),Math.abs(u-1)>.01&&(0,r.jsxs)("span",{className:"text-xs text-red-600",children:["Warning: Expected proportions sum to ",o(u,3),", not 1.000"]})]})]}),(0,r.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,r.jsx)("span",{className:"font-medium text-slate-700",children:"Significance level (α):"}),(0,r.jsxs)("select",{value:s,onChange:e=>h(Number(e.target.value)),className:"rounded border border-slate-300 px-2 py-1 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500",children:[(0,r.jsx)("option",{value:.01,children:"0.01"}),(0,r.jsx)("option",{value:.05,children:"0.05"}),(0,r.jsx)("option",{value:.1,children:"0.10"})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("h3",{className:"mb-2 text-sm font-semibold uppercase tracking-wide text-slate-500",children:["χ\xb2 Distribution (df = ",N,")"]}),(0,r.jsxs)("svg",{viewBox:"0 0 ".concat(700," ").concat(280),className:"w-full h-auto","aria-label":"Chi-square distribution with shaded p-value",children:[(0,r.jsx)("path",{d:E,fill:"#ef4444",fillOpacity:.25}),(0,r.jsx)("path",{d:F,fill:"none",stroke:"#1e40af",strokeWidth:2}),(0,r.jsx)("line",{x1:d.left,y1:P(0),x2:700-d.right,y2:P(0),stroke:"#94a3b8",strokeWidth:1}),O.map(e=>(0,r.jsxs)("g",{children:[(0,r.jsx)("line",{x1:k(e),y1:P(0),x2:k(e),y2:P(0)+6,stroke:"#64748b",strokeWidth:1}),(0,r.jsx)("text",{x:k(e),y:P(0)+20,textAnchor:"middle",fill:"#475569",fontSize:11,children:e})]},e)),g<=M&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("line",{x1:k(g),y1:P(0),x2:k(g),y2:P(n(g,N)),stroke:"#dc2626",strokeWidth:2,strokeDasharray:"4,3"}),(0,r.jsxs)("text",{x:k(g),y:P(n(g,N))-8,textAnchor:"middle",fill:"#dc2626",fontSize:12,fontWeight:"bold",children:["χ\xb2 = ",o(g,3)]})]}),(0,r.jsxs)("text",{x:350,y:d.top+14,textAnchor:"middle",fill:"#64748b",fontSize:12,children:["p-value = ",v<1e-4?"< 0.0001":o(v)]}),(0,r.jsx)("text",{x:700-d.right+10,y:P(0)+5,fill:"#475569",fontSize:12,fontStyle:"italic",children:"χ\xb2"})]})]})]}),(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"rounded-lg border border-slate-200",children:[(0,r.jsxs)("button",{onClick:()=>A("state"),className:"flex w-full items-center justify-between px-4 py-3 text-left font-semibold text-slate-700 hover:bg-slate-50",children:[(0,r.jsx)("span",{children:"1. State"}),(0,r.jsx)("span",{className:"text-slate-400",children:"state"===p?"−":"+"})]}),"state"===p&&(0,r.jsxs)("div",{className:"border-t border-slate-200 px-4 py-3 text-sm text-slate-600 space-y-1",children:[(0,r.jsxs)("p",{children:[(0,r.jsx)("strong",{children:"H₀:"})," The distribution of the variable matches the claimed proportions."]}),(0,r.jsxs)("p",{children:[(0,r.jsx)("strong",{children:"Hₐ:"})," The distribution of the variable does NOT match the claimed proportions."]}),(0,r.jsxs)("p",{children:[(0,r.jsx)("strong",{children:"Significance level:"})," α = ",s]})]})]}),(0,r.jsxs)("div",{className:"rounded-lg border border-slate-200",children:[(0,r.jsxs)("button",{onClick:()=>A("plan"),className:"flex w-full items-center justify-between px-4 py-3 text-left font-semibold text-slate-700 hover:bg-slate-50",children:[(0,r.jsx)("span",{children:"2. Plan"}),(0,r.jsx)("span",{className:"text-slate-400",children:"plan"===p?"−":"+"})]}),"plan"===p&&(0,r.jsxs)("div",{className:"border-t border-slate-200 px-4 py-3 text-sm text-slate-600 space-y-2",children:[(0,r.jsxs)("p",{children:[(0,r.jsx)("strong",{children:"Procedure:"})," Chi-Square Goodness of Fit Test"]}),(0,r.jsx)("p",{className:"font-medium",children:"Conditions:"}),(0,r.jsxs)("ul",{className:"ml-4 space-y-1",children:[(0,r.jsxs)("li",{children:[(0,r.jsx)("span",{className:"text-amber-500",children:"⚠"})," ",(0,r.jsx)("strong",{children:"Random:"})," Data come from a random sample (assumed)"]}),(0,r.jsxs)("li",{children:[(0,r.jsx)("span",{className:w?"text-green-600":"text-red-600",children:w?"✓":"✗"})," ",(0,r.jsx)("strong",{children:"Large Counts:"})," ",w?"All expected counts ≥ 5":"Some expected counts < 5 — condition NOT met"]}),(0,r.jsxs)("li",{children:[(0,r.jsx)("span",{className:"text-amber-500",children:"⚠"})," ",(0,r.jsx)("strong",{children:"10% Condition:"})," n = ",b," is less than 10% of the population (assumed)"]})]})]})]}),(0,r.jsxs)("div",{className:"rounded-lg border border-slate-200",children:[(0,r.jsxs)("button",{onClick:()=>A("do"),className:"flex w-full items-center justify-between px-4 py-3 text-left font-semibold text-slate-700 hover:bg-slate-50",children:[(0,r.jsx)("span",{children:"3. Do"}),(0,r.jsx)("span",{className:"text-slate-400",children:"do"===p?"−":"+"})]}
1),"do"===p&&(0,r.jsxs)("div",{className:"border-t border-slate-200 px-4 py-3 text-sm text-slate-600 space-y-2",children:[(0,r.jsx)("p",{className:"font-medium",children:"Formula:"}),(0,r.jsx)("p",{className:"ml-4 font-mono text-slate-800",children:"χ\xb2 = Σ (O − E)\xb2 / E"}),(0,r.jsx)("p",{className:"font-medium mt-2",children:"Computation:"}),(0,r.jsxs)("ul",{className:"ml-4 space-y-1",children:[(0,r.jsxs)("li",{children:["df = k − 1 = ",e.length," − 1 = ",N]}),e.map((e,t)=>(0,r.jsxs)("li",{className:"font-mono text-xs",children:["(",e.observed," − ",o(j[t],2),")\xb2 / ",o(j[t],2)," = ",o(f[t],4)]},t)),(0,r.jsxs)("li",{className:"mt-1",children:["χ\xb2 = ",(0,r.jsx)("strong",{children:o(g,4)})]}),(0,r.jsxs)("li",{children:["p-value ="," ",(0,r.jsx)("strong",{className:y?"text-red-600":"text-green-700",children:v<1e-4?"< 0.0001":o(v)})]})]})]})]}),(0,r.jsxs)("div",{className:"rounded-lg border border-slate-200",children:[(0,r.jsxs)("button",{onClick:()=>A("conclude"),className:"flex w-full items-center justify-between px-4 py-3 text-left font-semibold text-slate-700 hover:bg-slate-50",children:[(0,r.jsx)("span",{children:"4. Conclude"}),(0,r.jsx)("span",{className:"text-slate-400",children:"conclude"===p?"−":"+"})]}),"conclude"===p&&(0,r.jsx)("div",{className:"border-t border-slate-200 px-4 py-3 text-sm text-slate-600",children:y?(0,r.jsxs)("p",{className:"text-red-700",children:["Since the p-value (",v<1e-4?"< 0.0001":o(v),") is less than α = ",s,", we"," ",(0,r.jsx)("strong",{children:"reject H₀"}),". There is convincing evidence that the distribution of the variable does not match the claimed proportions."]}):(0,r.jsxs)("p",{className:"text-green-800",children:["Since the p-value (",o(v),") is greater than or equal to α = ",s,", we"," ",(0,r.jsx)("strong",{children:"fail to reject H₀"}),". There is not convincing evidence that the distribution differs from the claimed proportions."]})})]})]})]})]})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.