/
dz_from_t_correlated_samples.dart
72 lines (59 loc) · 2.26 KB
/
dz_from_t_correlated_samples.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import 'dart:math';
import 'package:flutter/widgets.dart';
import 'package:pocket_statistics/dists/normal.dart';
import 'package:pocket_statistics/dists/student_t.dart';
import 'package:pocket_statistics/widgets/base/base_container.dart';
import 'package:pocket_statistics/widgets/base/sharted_tools_mixin.dart';
import 'package:pocket_statistics/widgets/my_editable.dart';
import 'package:pocket_statistics/widgets/my_result.dart';
import 'package:pocket_statistics/widgets/title.dart';
String DsFromTCorrelatedSamplesTitle = 'dz from t for correlated samples';
class DsFromTCorrelatedSamples extends StatefulWidget {
@override
DsFromTCorrelatedSamplesState createState() {
return new DsFromTCorrelatedSamplesState();
}
}
class DsFromTCorrelatedSamplesState extends State<DsFromTCorrelatedSamples> with SharedToolsMixin {
final TextEditingController totalN = new TextEditingController(text: '');
final TextEditingController tValue = new TextEditingController(text: '');
double _cohens_d, _p, _CL;
void _onChanged() {
double _nPairs = double.tryParse(totalN.text);
double _tValue = double.tryParse(tValue.text);
if (_nPairs == null || _tValue == null) {
_cohens_d = _p = _CL = null;
} else {
_cohens_d = _tValue / sqrt(_nPairs);
_p = (1 - StudentT(_nPairs - 1).cdf(_tValue.abs())) * 2;
Normal cl = Normal(1.0, 1.0);
//TODO verify below is correct. 9 dp and later, some inconsistencies
_CL = 1 - cl.cdf(1 - _cohens_d);
}
setState(() {});
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(mainAxisAlignment: MainAxisAlignment.start, children: [
MyTitle(DsFromTCorrelatedSamplesTitle),
Row(
children: <Widget>[
MyEditable(
title: 'n pairs', onChanged: _onChanged, controller: totalN),
MyEditable(
title: 't-value', onChanged: _onChanged, controller: tValue)
],
),
Row(children: [
MyResult(title: "Cohen's dz", value: safeVal(_cohens_d)),
MyResult(title: "p-value", value: safeVal(_p))
]),
Row(children: [
MyResult(title: "CL effect size", value: safeVal(_CL)),
Blank()
])
]),
);
}
}