Skip to content

Commit 02ec979

Browse files
committed
style: apply code format
1 parent 4c546e5 commit 02ec979

File tree

4 files changed

+123
-107
lines changed

4 files changed

+123
-107
lines changed

src/components/statistics/KolmogorovSmirnovTest.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ export function KolmogorovSmirnovTest() {
6262
6363
| 变量 | 样本量 | D | D临界值 | 结果 |
6464
| :---: | :---: | :---: | :---: | :---: |
65-
${result.map(
66-
(row) =>
67-
`| ${row.name} | ${row.count} | ${row.d?.toFixed(3)} | ${row.decide?.toFixed(3)} | ${
68-
row.rejected ? '不符合正态分布' : '符合正态分布'
69-
} (p: ${row.p?.toFixed(3)}) |`,
70-
).join('\n')}
65+
${result
66+
.map(
67+
(row) =>
68+
`| ${row.name} | ${row.count} | ${row.d?.toFixed(3)} | ${row.decide?.toFixed(3)} | ${
69+
row.rejected ? '不符合正态分布' : '符合正态分布'
70+
} (p: ${row.p?.toFixed(3)}) |`,
71+
)
72+
.join('\n')}
7173
`)
7274
} else {
7375
if (!variable || !group) {
@@ -101,12 +103,14 @@ ${result.map(
101103
102104
| 组别 | 样本量 | D | D临界值 | 结果 |
103105
| :---: | :---: | :---: | :---: | :---: |
104-
${result.map(
105-
(row) =>
106-
`| ${row.name} | ${row.count} | ${row.d?.toFixed(3)} | ${row.decide?.toFixed(3)} | ${
107-
row.rejected ? '不符合正态分布' : '符合正态分布'
108-
} (p: ${row.p?.toFixed(3)}) |`,
109-
).join('\n')}
106+
${result
107+
.map(
108+
(row) =>
109+
`| ${row.name} | ${row.count} | ${row.d?.toFixed(3)} | ${row.decide?.toFixed(3)} | ${
110+
row.rejected ? '不符合正态分布' : '符合正态分布'
111+
} (p: ${row.p?.toFixed(3)}) |`,
112+
)
113+
.join('\n')}
110114
`)
111115
}
112116
messageApi?.destroy()

src/components/statistics/KurtosisSkewness.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export function KurtosisSkewness() {
5959
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
6060
${k
6161
.map(
62-
(k, i) => `| ${variables[i]} | ${data[i].length} | ${k.kurtosis.toFixed(3)} | ${markS(k.z, k.p)} | ${markP(k.p)} | ${s[i].skewness.toFixed(3)} | ${markS(s[i].z, s[i].p)} | ${markP(s[i].p)} |`,
62+
(k, i) =>
63+
`| ${variables[i]} | ${data[i].length} | ${k.kurtosis.toFixed(3)} | ${markS(k.z, k.p)} | ${markP(k.p)} | ${s[i].skewness.toFixed(3)} | ${markS(s[i].z, s[i].p)} | ${markP(s[i].p)} |`,
6364
)
6465
.join('\n')}
6566
`)
@@ -92,7 +93,8 @@ ${k
9293
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
9394
${k
9495
.map(
95-
(k, i) => `| ${groups[i]} | ${data[i].length} | ${k.kurtosis.toFixed(3)} | ${markS(k.z, k.p)} | ${markP(k.p)} | ${s[i].skewness.toFixed(3)} | ${markS(s[i].z, s[i].p)} | ${markP(s[i].p)} |`,
96+
(k, i) =>
97+
`| ${groups[i]} | ${data[i].length} | ${k.kurtosis.toFixed(3)} | ${markS(k.z, k.p)} | ${markP(k.p)} | ${s[i].skewness.toFixed(3)} | ${markS(s[i].z, s[i].p)} | ${markP(s[i].p)} |`,
9698
)
9799
.join('\n')}
98100
`)

src/components/statistics/MultiLinearRegression.tsx

Lines changed: 89 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function getSequenceLinearRegressionResult({
249249
return `
250250
## 1 序列多元线性回归
251251
252-
基于自变量${result.x.map((v, i) => `"${v}" (x${i+1})`).join('、')}和因变量"${result.y}"构建序列多元线性回归模型.
252+
基于自变量${result.x.map((v, i) => `"${v}" (x${i + 1})`).join('、')}和因变量"${result.y}"构建序列多元线性回归模型.
253253
254254
结果如表 1 所示.
255255
@@ -274,9 +274,11 @@ ${result.m.models
274274
## 2 最终模型
275275
276276
最终模型为: y = ${result.m.model.coefficients[0].toFixed(4)} + ${result.m.model.coefficients
277-
.slice(1)
278-
.map((coefficient, index) => `${coefficient.toFixed(4)} * x${index + 1}`)
279-
.join(' + ')}, 模型的测定系数 (R<sup>2</sup>) 为 ${result.m.model.r2.toFixed(4)}, 调整后测定系数 (R<sup>2</sup><sub>adj</sub>) 为 ${result.m.model.r2adj.toFixed(4)}.
277+
.slice(1)
278+
.map((coefficient, index) => `${coefficient.toFixed(4)} * x${index + 1}`)
279+
.join(
280+
' + ',
281+
)}, 模型的测定系数 (R<sup>2</sup>) 为 ${result.m.model.r2.toFixed(4)}, 调整后测定系数 (R<sup>2</sup><sub>adj</sub>) 为 ${result.m.model.r2adj.toFixed(4)}.
280282
281283
具体参数和细节如表 2 和表 3 所示.
282284
@@ -285,9 +287,11 @@ ${result.m.models
285287
| 参数 | 值 | H<sub>0</sub> | 统计量 | 显著性 |
286288
| :---: | :---: | :---: | :---: | :---: |
287289
| 模型 | ${result.m.model.coefficients.map((v, i) => `b${i}: ${v.toFixed(4)}${i === 0 ? ' (截距)' : ''}`).join('<br />')} | ${result.m.model.coefficients
288-
.slice(1)
289-
.map((_, index) => `b${index + 1}`)
290-
.join(' = ')} = 0 | F = ${markS(result.m.model.F, result.m.model.p)} | ${markP(result.m.model.p)} |
290+
.slice(1)
291+
.map((_, index) => `b${index + 1}`)
292+
.join(
293+
' = ',
294+
)} = 0 | F = ${markS(result.m.model.F, result.m.model.p)} | ${markP(result.m.model.p)} |
291295
${result.m.model.coefficients
292296
.slice(1)
293297
.map(
@@ -333,28 +337,30 @@ ${result.x
333337
}
334338

335339
function getStepwiseLinearRegressionResult({
336-
result,
340+
result,
337341
}: { result: Result<'stepwise'> }): string {
338-
return `
339-
## 1 逐步多元线性回归 (${result.method === 'stepwise-fwd'
340-
? '向前选择'
341-
: result.method === 'stepwise-bwd'
342-
? '向后剔除'
343-
: '双向选择'})
342+
return `
343+
## 1 逐步多元线性回归 (${
344+
result.method === 'stepwise-fwd'
345+
? '向前选择'
346+
: result.method === 'stepwise-bwd'
347+
? '向后剔除'
348+
: '双向选择'
349+
})
344350
345351
最终模型为 y = ${result.m.coefficients[0].toFixed(4)} + ${result.m.coefficients
346-
.slice(1)
347-
.map(
348-
(coefficient, index) => `${coefficient.toFixed(4)} * x${index + 1}`,
349-
)
350-
.join(' + ')}, 其中${result.m.selectedVariables
351-
.map((index, i) => `"${result.x[index]}" (x${i + 1})`)
352-
.join('、')}为自变量, 因变量为"${result.y}". 模型的测定系数 (R<sup>2</sup>) 为 ${result.m.r2.toFixed(4)}, 调整后测定系数 (R<sup>2</sup><sub>adj</sub>) 为 ${result.m.r2adj.toFixed(4)}.
352+
.slice(1)
353+
.map((coefficient, index) => `${coefficient.toFixed(4)} * x${index + 1}`)
354+
.join(' + ')}, 其中${result.m.selectedVariables
355+
.map((index, i) => `"${result.x[index]}" (x${i + 1})`)
356+
.join(
357+
'、',
358+
)}为自变量, 因变量为"${result.y}". 模型的测定系数 (R<sup>2</sup>) 为 ${result.m.r2.toFixed(4)}, 调整后测定系数 (R<sup>2</sup><sub>adj</sub>) 为 ${result.m.r2adj.toFixed(4)}.
353359
354360
变量${result.x
355-
.filter((_, index) => !result.m.selectedVariables.includes(index))
356-
.map((variable) => `"${variable}"`)
357-
.join('、')}已在逐步回归中剔除.
361+
.filter((_, index) => !result.m.selectedVariables.includes(index))
362+
.map((variable) => `"${variable}"`)
363+
.join('、')}已在逐步回归中剔除.
358364
359365
结果如表 1 和表 2 所示.
360366
@@ -363,21 +369,23 @@ function getStepwiseLinearRegressionResult({
363369
| 参数 | 值 | H<sub>0</sub> | 统计量 | 显著性 |
364370
| :---: | :---: | :---: | :---: | :---: |
365371
| 模型 | b0: ${result.m.coefficients[0].toFixed(4)} | ${result.m.coefficients
366-
.slice(1)
367-
.map((_, index) => `b${index + 1}`)
368-
.join(' + ')} = 0 | F = ${markS(result.m.F, result.m.p)} | ${markP(result.m.p)} |
372+
.slice(1)
373+
.map((_, index) => `b${index + 1}`)
374+
.join(
375+
' + ',
376+
)} = 0 | F = ${markS(result.m.F, result.m.p)} | ${markP(result.m.p)} |
369377
${result.m.coefficients
370-
.slice(1)
371-
.map(
372-
(_, index) =>
373-
`| b${index + 1} (${result.x[result.m.selectedVariables[index]]}) | ${result.m.coefficients[index + 1].toFixed(
374-
4,
375-
)} (偏回归系数) | b${index + 1} = 0 | t = ${markS(
376-
result.m.tValues[index],
377-
result.m.pValues[index],
378-
)} | ${markP(result.m.pValues[index])} |`,
379-
)
380-
.join('\n')}
378+
.slice(1)
379+
.map(
380+
(_, index) =>
381+
`| b${index + 1} (${result.x[result.m.selectedVariables[index]]}) | ${result.m.coefficients[
382+
index + 1
383+
].toFixed(4)} (偏回归系数) | b${index + 1} = 0 | t = ${markS(
384+
result.m.tValues[index],
385+
result.m.pValues[index],
386+
)} | ${markP(result.m.pValues[index])} |`,
387+
)
388+
.join('\n')}
381389
382390
> 表 2 - 模型细节
383391
@@ -398,36 +406,34 @@ ${result.m.coefficients
398406
| 变量 | 均值 | 标准差 | 与Y相关系数 |
399407
| :---: | :---: | :---: | :---: |
400408
${result.x
401-
.map(
402-
(variable, index) =>
403-
`| ${variable} (${
404-
result.m.selectedVariables.findIndex((i) => i === index) + 1
405-
? `x${result.m.selectedVariables.findIndex((i) => i === index) + 1}`
406-
: '已剔除'
407-
}) | ${result.m.ivMeans[index].toFixed(4)} | ${result.m.ivStds[index].toFixed(4)} | ${corr(
408-
result.m.iv.map((xRow) => xRow[index]),
409-
result.m.dv,
410-
).toFixed(4)} |`,
411-
)
412-
.join('\n')}
409+
.map(
410+
(variable, index) =>
411+
`| ${variable} (${
412+
result.m.selectedVariables.findIndex((i) => i === index) + 1
413+
? `x${result.m.selectedVariables.findIndex((i) => i === index) + 1}`
414+
: '已剔除'
415+
}) | ${result.m.ivMeans[index].toFixed(4)} | ${result.m.ivStds[index].toFixed(4)} | ${corr(
416+
result.m.iv.map((xRow) => xRow[index]),
417+
result.m.dv,
418+
).toFixed(4)} |`,
419+
)
420+
.join('\n')}
413421
| ${result.y} (y) | ${result.m.dvMean.toFixed(4)} | ${result.m.dvStd.toFixed(4)} | 1 |
414422
`
415423
}
416424

417425
function getStandardLinearRegressionResult({
418-
result,
426+
result,
419427
}: { result: Result<'standard'> }): string {
420-
return `
428+
return `
421429
## 1 标准多元线性回归
422430
423-
对自变量${result.x.map((v, i) => `"${v}" (x${i+1})`).join('、')}和因变量"${result.y}"进行标准多元线性回归分析. 原假设 (H<sub>0</sub>) 为"所有自变量的回归系数均为0", 显著性水平 (α) 为 0.05.
431+
对自变量${result.x.map((v, i) => `"${v}" (x${i + 1})`).join('、')}和因变量"${result.y}"进行标准多元线性回归分析. 原假设 (H<sub>0</sub>) 为"所有自变量的回归系数均为0", 显著性水平 (α) 为 0.05.
424432
425433
最终模型为 y = ${result.m.coefficients[0].toFixed(4)} + ${result.m.coefficients
426-
.slice(1)
427-
.map(
428-
(coefficient, index) => `${coefficient.toFixed(4)} * x${index + 1}`,
429-
)
430-
.join(' + ')}
434+
.slice(1)
435+
.map((coefficient, index) => `${coefficient.toFixed(4)} * x${index + 1}`)
436+
.join(' + ')}
431437
, 模型的测定系数 (R<sup>2</sup>) 为 ${result.m.r2.toFixed(4)}, 调整后测定系数 (R<sup>2</sup><sub>adj</sub>) 为 ${result.m.r2adj.toFixed(4)}.
432438
433439
结果如表 1 和表 2 所示.
@@ -437,21 +443,23 @@ function getStandardLinearRegressionResult({
437443
| 参数 | 值 | H<sub>0</sub> | 统计量 | 显著性 |
438444
| :---: | :---: | :---: | :---: | :---: |
439445
| 模型 | ${result.m.coefficients.map((v, i) => `b${i}: ${v.toFixed(4)}${i === 0 ? ' (截距)' : ''}`).join('<br />')} | ${result.m.coefficients
440-
.slice(1)
441-
.map((_, index) => `b${index + 1}`)
442-
.join(' + ')} = 0 | F = ${markS(result.m.F, result.m.p)} | ${markP(result.m.p)} |
446+
.slice(1)
447+
.map((_, index) => `b${index + 1}`)
448+
.join(
449+
' + ',
450+
)} = 0 | F = ${markS(result.m.F, result.m.p)} | ${markP(result.m.p)} |
443451
${result.m.coefficients
444-
.slice(1)
445-
.map(
446-
(_, index) =>
447-
`| b${index + 1} | ${result.m.coefficients[index + 1].toFixed(
448-
4,
449-
)} (偏回归系数) | b${index + 1} = 0 | t = ${markS(
450-
result.m.tValues[index],
451-
result.m.pValues[index],
452-
)} | ${markP(result.m.pValues[index])} |`,
453-
)
454-
.join('\n')}
452+
.slice(1)
453+
.map(
454+
(_, index) =>
455+
`| b${index + 1} | ${result.m.coefficients[index + 1].toFixed(
456+
4,
457+
)} (偏回归系数) | b${index + 1} = 0 | t = ${markS(
458+
result.m.tValues[index],
459+
result.m.pValues[index],
460+
)} | ${markP(result.m.pValues[index])} |`,
461+
)
462+
.join('\n')}
455463
456464
> 表 2 - 模型细节
457465
@@ -472,14 +480,14 @@ ${result.m.coefficients
472480
| 变量 | 均值 | 标准差 | 与Y相关系数 |
473481
| :---: | :---: | :---: | :---: |
474482
${result.x
475-
.map(
476-
(variable, index) =>
477-
`| ${variable} (x${index + 1}) | ${result.m.ivMeans[index].toFixed(4)} | ${result.m.ivStds[index].toFixed(4)} | ${corr(
478-
result.m.iv.map((xRow) => xRow[index]),
479-
result.m.dv,
480-
).toFixed(4)} |`,
481-
)
482-
.join('\n')}
483+
.map(
484+
(variable, index) =>
485+
`| ${variable} (x${index + 1}) | ${result.m.ivMeans[index].toFixed(4)} | ${result.m.ivStds[index].toFixed(4)} | ${corr(
486+
result.m.iv.map((xRow) => xRow[index]),
487+
result.m.dv,
488+
).toFixed(4)} |`,
489+
)
490+
.join('\n')}
483491
| ${result.y} (y) | ${result.m.dvMean.toFixed(4)} | ${result.m.dvStd.toFixed(4)} | 1 |
484492
`
485-
}
493+
}

src/components/statistics/SimpleMediatorTest.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SimpleMediationModel } from '@psych/lib'
2-
import { Button, Form, InputNumber, Select, Tag, Collapse } from 'antd'
2+
import { Button, Collapse, Form, InputNumber, Select, Tag } from 'antd'
33
import { useEffect, useState } from 'react'
44
import { flushSync } from 'react-dom'
55
import { useData } from '../../lib/hooks/useData'
@@ -123,17 +123,19 @@ export function SimpleMediatorTest() {
123123
>
124124
<div className='mb-4'>
125125
<Collapse
126-
items={[{
127-
key: 'smm',
128-
label: '简单中介效应模型示意图 (点击展开)',
129-
children: (
130-
<img
131-
src='/smm.png'
132-
alt='simple mediator model'
133-
className='w-full'
134-
/>
135-
),
136-
}]}
126+
items={[
127+
{
128+
key: 'smm',
129+
label: '简单中介效应模型示意图 (点击展开)',
130+
children: (
131+
<img
132+
src='/smm.png'
133+
alt='simple mediator model'
134+
className='w-full'
135+
/>
136+
),
137+
},
138+
]}
137139
/>
138140
</div>
139141
<Form.Item

0 commit comments

Comments
 (0)