Repository: CSchoel/nolds (language: python)

Issue:
Check if DFA needs to be fixed
Following the discussion in NeuroKit2 (https://github.com/neuropsychology/NeuroKit/issues/206) it seems that there are multiple ways to implement DFA. => Check that we really use the correct implementation according to Peng 1995 and update the reference list accordingly.


Discussion / hints:
Hey @CSchoel I am also working on NeuroKit2 issue [#206](https://github.com/neuropsychology/NeuroKit/issues/206) and as far as I can judge from your code there shouldn't be any issues. I have compared it to my [MFDFA](https://github.com/LRydin/MFDFA) and algorithm-wise, I can't detect any hiccups.

I will use you code and mine to serve as tests for NeuroKit2 [fractal_dfa](https://github.com/neuropsychology/NeuroKit/blob/master/neurokit2/complexity/fractal_dfa.py). I hope this also helps you out. I'll report on the tests later.
Hey, thank you very much for looking into this! :smile: And also thanks for the hint at Lévy motion in your NeuroKit2 comment. I am always happy to have data sets/processes with prescribed theoretical results against which I can test the algorithms in nolds.
:) Cheers! Happy to help, I'll keep you in the loop with the work with NeuroKit2. I'll add some tests based on your nolds and my MFDFA, to be sure things we have to validating codes for NK2.
I finally came back to this: Retracing my steps from https://github.com/neuropsychology/NeuroKit/issues/206, there is indeed a change required:

We need to apply the square root only after we summed _all_ of the individual squared differences and took the mean. This is consistent with the PhysioNet implementation and the (now discontinued) R-package fractal.

This does not change the unit tests for fractal brownian motion, random noise, and random walks. But it _does_ change the output for the Lorenz system quite a bit. This makes me a bit suspicious about the reference paper for that experiment. I'll try to verify this by using the PhysioNet implementation on the Lorenz data to see if the output is closer to 1 (with the fix) or 1.5 (without the fix, prescribed by González-Salas et al. (2016)).

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7cc593a..5e40a5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
   - `barabasi_1991_figure2` and `barabasi_1991_figure3` recreate the respective plots from Barabasi et al. 1991
   - `lorenz` calculates all main measures of `nolds` for x, y, and z coordinates of a Lorenz plot and compares them to prescribed values from the literature
 - tests for all `nolds` existing measures based on the Lorenz system
+- additional tests for `dfa` allowing a direct comparison to the implementation in PhysioNet and using Lévy motion.
 
 ### Changed
 
@@ -30,11 +31,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 - the parameter `tolerance` in `sampen` now has a more sophisticated default value that takes into account that the chebyshev distance rises logarithmically with increasing dimension
 - uses `np.float64` as standard `dtype` instead of `"float32"`
 - input data of `lyap_e` is now converted to `np.float64` to avoid errors with `inf` values for integer inputs (see https://github.com/CSchoel/nolds/issues/21)
+- completely revises the explanation of `dfa` with new and more accurate sources
 
 ### Fixed
 
 - the test `test_measures.TestNoldsCorrDim.test_corr_dim` would fail if `sklearn` was not installed, because the standard "RANSAC" fitting method produces quite different results compared to the fallback "poly" method
 - uses `ddof=1` in `np.std` when creating debug plot for `sampen` and when computing default `rvals` for `corr_dim`
+- `dfa` was applying `np.sqrt` too early in the process. We actually only take the square root once after averaging over _all_ windows.
 
 ## [0.5.2]
 
diff --git a/nolds/datasets.py b/nolds/datasets.py
index 2b206ff..739403c 100644
--- a/nolds/datasets.py
+++ b/nolds/datasets.py
@@ -159,6 +159,36 @@ def load_brown72():
     return np.load(f)
 
 
+def load_lorenz_physionet():
+  """
+  Loads a dataset containing the X variable of the Lorenz system
+    as well as the output of PhysioNet's dfa implementation on that dataset.
+
+  The input data was created with the following code:
+
+      data = datasets.lorenz_euler(
+        3000, 10, 28, 8/3.0, start=[0.1,0.1,0.1], dt=0.012
+      )[1000:,0]
+
+  The ouptut from PhysioNet was created by calling:
+
+      dfa < lorenz.txt > lorenz_physionet.txt
+ 
+  Returns:
+    1d float array:
+      time series of the X variable of the Lorenz system that was used as input
+    2d float array:
+      x- and y-coordinates of the line fitting step in the PhysioNet output
+  """
+  fname = "datasets/lorenz.txt"
+  with pkg_resources.resource_stream(__name__, fname) as f:
+    data_in = np.loadtxt(f)
+  fname = "datasets/lorenz_physionet.txt"
+  with pkg_resources.resource_stream(__name__, fname) as f:
+    data_out = np.loadtxt(f)
+  return data_in, data_out
+
+
 def tent_map(x, steps, mu=2):
   """
   Generates a time series of the tent map.
diff --git a/nolds/datasets/lorenz.txt b/nolds/datasets/lorenz.txt
new file mode 100644
index 0000000..47110d3
--- /dev/null
+++ b/nolds/datasets/lorenz.txt
@@ -0,0 +1,2000 @@
+-14.465592
+-13.954063
+-13.257725
+-12.399457
+-11.411456
+-10.331937
+-9.201211
+-8.057907
+-6.935963
+-5.862731
+-4.858233
+-3.935360
+-3.100700
+-2.355696
+-1.697878
+-1.122010
+-0.621081
+-0.187083
+0.188384
+0.513688
+0.796874
+1.045484
+1.266460
+1.466109
+1.650108
+1.823545
+1.990969
+2.156459
+2.323694
+2.496017
+2.676512
+2.868059
+3.073391
+3.295148
+3.535912
+3.798238
+4.084679
+4.397788
+4.740111
+5.114165
+5.522379
+5.967025
+6.450097
+6.973152
+7.537104
+8.141940
+8.786379
+9.467441
+10.179949
+10.915966
+11.664201
+12.409451
+13.132177
+13.808348
+14.409731
+14.904833
+15.260629
+15.445167
+15.430908
+15.198431
+14.739860
+14.061225
+13.183046
+12.138760
+10.971169
+9.727644
+8.455097
+7.195714
+5.984083
+4.845871
+3.797862
+2.848908
+2.001377
+1.252722
+0.596955
+0.025897
+-0.469840
+-0.900108
+-1.274709
+-1.603045
+-1.893910
+-2.155379
+-2.394768
+-2.618652
+-2.832900
+-3.042747
+-3.252860
+-3.467418
+-3.690183
+-3.924567
+-4.173687
+-4.440417
+-4.727413
+-5.037132
+-5.371831
+-5.733541
+-6.124023
+-6.544687
+-6.996488
+-7.479778
+-7.994122
+-8.538064
+-9.108856
+-9.702144
+-10.311624
+-10.928702
+-11.542191
+-12.138083
+-12.699515
+-13.206966
+-13.638826
+-13.972383
+-14.185288
+-14.257422
+-14.173029
+-13.922812
+-13.505644
+-12.929482
+-12.211234
+-11.375464
+-10.452146
+-9.473835
+-8.472790
+-7.478483
+-6.515835
+-5.604268
+-4.757502
+-3.983936
+-3.287370
+-2.667907
+-2.122858
+-1.647581
+-1.236190
+-0.882128
+-0.578599
+-0.318889
+-0.096578
+0.094324
+0.259299
+0.403303
+0.530760
+0.645599
+0.751292
+0.850909
+0.947168
+1.042499
+1.139091
+1.238952
+1.343953
+1.455878
+1.576464
+1.707442
+1.850571
+2.007673
+2.180662
+2.371575
+2.582593
+2.816065
+3.074527
+3.360712
+3.677558
+4.028201
+4.415954
+4.844270
+5.316671
+5.836639
+6.407462
+7.032002
+7.712384
+8.449566
+9.242783
+10.088828
+10.981180
+11.908967
+12.855840
+13.798856
+14.707585
+15.543742
+16.261759
+16.810764
+17.138329
+17.196064
+16.946606
+16.370779
+15.473166
+14.284187
+12.857506
+11.263000
+9.577048
+7.872715
+6.212156
+4.642428
+3.194627
+1.885446
+0.719989
+-0.305097
+-1.198771
+-1.973290
+-2.642488
+-3.220579
+-3.721375
+-4.157812
+-4.541690
+-4.883565
+-5.192729
+-5.477250
+-5.744046
+-5.998971
+-6.246906
+-6.491844
+-6.736969
+-6.984718
+-7.236835
+-7.494412
+-7.757909
+-8.027173
+-8.301441
+-8.579343
+-8.858894
+-9.137500
+-9.411963
+-9.678511
+-9.932835
+-10.170173
+-10.385418
+-10.573267
+-10.728410
+-10.845757
+-10.920692
+-10.949349
+-10.928868
+-10.857635
+-10.735467
+-10.563714
+-10.345279
+-10.084526
+-9.787103
+-9.459672
+-9.109594
+-8.744576
+-8.372330
+-8.000257
+-7.635200
+-7.283241
+-6.949591
+-6.638532
+-6.353428
+-6.096777
+-5.870296
+-5.675031
+-5.511471
+-5.379669
+-5.279350
+-5.210015
+-5.171023
+-5.161669
+-5.181239
+-5.229054
+-5.304497
+-5.407032
+-5.536208
+-5.691647
+-5.873034
+-6.080080
+-6.312488
+-6.569899
+-6.851826
+-7.157585
+-7.486197
+-7.836295
+-8.205998
+-8.592797
+-8.993415
+-9.403675
+-9.818382
+-10.231223
+-10.634708
+-11.020179
+-11.377904
+-11.697286
+-11.967200
+-12.176478
+-12.314519
+-12.372007
+-12.341677
+-12.219035
+-12.002957
+-11.696043
+-11.304676
+-10.838734
+-10.310983
+-9.736217
+-9.130268
+-8.508988
+-7.887355
+-7.278754
+-6.694510
+-6.143641
+-5.632840
+-5.166613
+-4.747525
+-4.376519
+-4.053244
+-3.776385
+-3.543953
+-3.353549
+-3.202568
+-3.088377
+-3.008441
+-2.960421
+-2.942238
+-2.952120
+-2.988628
+-3.050663
+-3.137468
+-3.248626
+-3.384040
+-3.543926
+-3.728785
+-3.939385
+-4.176733
+-4.442047
+-4.736707
+-5.062219
+-5.420140
+-5.812008
+-6.239229
+-6.702948
+-7.203873
+-7.742062
+-8.316654
+-8.925544
+-9.564997
+-10.229219
+-10.909892
+-11.595708
+-12.271975
+-12.920373
+-13.518980
+-14.042701
+-14.464238
+-14.755704
+-14.890865
+-14.847882
+-14.612203
+-14.179115
+-13.555378
+-12.759444
+-11.820064
+-10.773434
+-9.659445
+-8.517767
+-7.384475
+-6.289689
+-5.256382
+-4.300234
+-3.430242
+-2.649776
+-1.957807
+-1.350095
+-0.820252
+-0.360601
+0.037148
+0.381407
+0.680370
+0.941787
+1.172843
+1.380093
+1.569461
+1.746259
+1.915244
+2.080669
+2.246362
+2.415791
+2.592131
+2.778333
+2.977183
+3.191347
+3.423425
+3.675979
+3.951560
+4.252720
+4.582016
+4.941982
+5.335100
+5.763730
+6.230009
+6.735720
+7.282098
+7.869585
+8.497514
+9.163716
+9.864054
+10.591875
+11.337430
+12.087284
+12.823816
+13.524921
+14.164083
+14.710999
+15.132960
+15.397068
+15.473301
+15.338136
+14.978203
+14.393232
+13.597493
+12.619180
+11.497653
+10.279058
+9.011235
+7.739007
+6.500626
+5.325786
+4.235106
+3.240749
+2.347705
+1.555357
+0.859021
+0.251304
+-0.276790
+-0.735017
+-1.133277
+-1.481202
+-1.787889
+-2.061750
+-2.310448
+-2.540887
+-2.759247
+-2.971038
+-3.181171
+-3.394032
+-3.613560
+-3.843312
+-4.086527
+-4.346176
+-4.625002
+-4.925540
+-5.250122
+-5.600866
+-5.979633
+-6.387969
+-6.827004
+-7.297326
+-7.798809
+-8.330401
+-8.889872
+-9.473507
+-10.075787
+-10.689040
+-11.303123
+-11.905164
+-12.479445
+-13.007504
+-13.468553
+-13.840297
+-14.100206
+-14.227232
+-14.203843
+-14.018160
+-13.665831
+-13.151284
+-12.488007
+-11.697699
+-10.808371
+-9.851713
+-8.860200
+-7.864433
+-6.891090
+-5.961668
+-5.092009
+-4.292477
+-3.568562
+-2.921721
+-2.350290
+-1.850346
+-1.416470
+-1.042359
+-0.721323
+-0.446632
+-0.211779
+-0.010634
+0.162449
+0.312600
+0.444413
+0.561979
+0.668911
+0.768402
+0.863272
+0.956027
+1.048913
+1.143971
+1.243083
+1.348026
+1.460508
+1.582214
+1.714840
+1.860126
+2.019893
+2.196065
+2.390699
+2.606012
+2.844395
+3.108436
+3.400930
+3.724880
+4.083491
+4.480150
+4.918374
+5.401741
+5.933771
+6.517754
+7.156507
+7.852032
+8.605066
+9.414480
+10.276519
+11.183878
+12.124623
+13.081025
+14.028438
+14.934451
+15.758657
+16.453468
+16.966461
+17.244596
+17.240299
+16.918772
+16.265175
+15.289747
+14.028975
+12.541869
+10.901950
+9.187011
+7.469396
+5.808961
+4.249640
+2.819271
+1.531621
+0.389439
+-0.612365
+-1.483922
+-2.238197
+-2.889389
+-3.451823
+-3.939255
+-4.364456
+-4.738995
+-5.073163
+-5.375974
+-5.655214
+-5.917527
+-6.168501
+-6.412760
+-6.654053
+-6.895328
+-7.138795
+-7.385980
+-7.637760
+-7.894395
+-8.155539
+-8.420252
+-8.687007
+-8.953693
+-9.217629
+-9.475580
+-9.723799
+-9.958082
+-10.173863
+-10.366330
+-10.530579
+-10.661805
+-10.755524
+-10.807800
+-10.815495
+-10.776487
+-10.689871
+-10.556080
+-10.376959
+-10.155732
+-9.896897
+-9.606030
+-9.289533
+-8.954331
+-8.607573
+-8.256320
+-7.907291
+-7.566646
+-7.239830
+-6.931488
+-6.645422
+-6.384617
+-6.151286
+-5.946952
+-5.772551
+-5.628528
+-5.514944
+-5.431576
+-5.378002
+-5.353674
+-5.357986
+-5.390318
+-5.450074
+-5.536703
+-5.649709
+-5.788653
+-5.953139
+-6.142790
+-6.357217
+-6.595973
+-6.858501
+-7.144062
+-7.451657
+-7.779942
+-8.127120
+-8.490832
+-8.868046
+-9.254933
+-9.646769
+-10.037836
+-10.421381
+-10.789610
+-11.133764
+-11.444289
+-11.711112
+-11.924042
+-12.073284
+-12.150053
+-12.147228
+-12.060003
+-11.886436
+-11.627831
+-11.288869
+-10.877456
+-10.404291
+-9.882188
+-9.325245
+-8.747962
+-8.164403
+-7.587499
+-7.028530
+-6.496820
+-5.999624
+-5.542172
+-5.127844
+-4.758411
+-4.434325
+-4.155002
+-3.919107
+-3.724796
+-3.569932
+-3.452258
+-3.369538
+-3.319659
+-3.300715
+-3.311052
+-3.349309
+-3.414431
+-3.505680
+-3.622628
+-3.765150
+-3.933406
+-4.127820
+-4.349056
+-4.597982
+-4.875633
+-5.183159
+-5.521766
+-5.892633
+-6.296818
+-6.735128
+-7.207963
+-7.715123
+-8.255569
+-8.827136
+-9.426209
+-10.047352
+-10.682917
+-11.322667
+-11.953458
+-12.559047
+-13.120131
+-13.614715
+-14.018910
+-14.308256
+-14.459542
+-14.453047
+-14.274925
+-13.919388
+-13.390205
+-12.701152
+-11.875169
+-10.942300
+-9.936767
+-8.893722
+-7.846255
+-6.823101
+-5.847251
+-4.935465
+-4.098499
+-3.341821
+-2.666568
+-2.070560
+-1.549258
+-1.096581
+-0.705575
+-0.368926
+-0.079330
+0.170246
+0.386406
+0.575227
+0.742227
+0.892362
+1.030058
+1.159252
+1.283451
+1.405792
+1.529103
+1.655964
+1.788769
+1.929775
+2.081158
+2.245058
+2.423618
+2.619023
+2.833532
+3.069504
+3.329422
+3.615899
+3.931689
+4.279675
+4.662846
+5.084249
+5.546919
+6.053760
+6.607388
+7.209910
+7.862612
+8.565567
+9.317123
+10.113266
+10.946864
+11.806811
+12.677132
+13.536147
+14.355904
+15.102097
+15.734829
+16.210514
+16.485165
+16.519039
+16.282196
+15.760010
+14.957327
+13.899906
+12.632359
+11.212759
+9.705181
+8.171990
+6.667603
+5.234692
+3.902944
+2.689817
+1.602488
+0.640253
+-0.203130
+-0.937432
+-1.574383
+-2.126514
+-2.606355
+-3.025918
+-3.396386
+-3.727952
+-4.029757
+-4.309894
+-4.575459
+-4.832619
+-5.086689
+-5.342215
+-5.603042
+-5.872376
+-6.152835
+-6.446472
+-6.754792
+-7.078741
+-7.418681
+-7.774345
+-8.144772
+-8.528225
+-8.922110
+-9.322876
+-9.725936
+-10.125595
+-10.515022
+-10.886279
+-11.230420
+-11.537698
+-11.797881
+-12.000699
+-12.136398
+-12.196389
+-12.173933
+-12.064795
+-11.867779
+-11.585067
+-11.222288
+-10.788290
+-10.294621
+-9.754792
+-9.183387
+-8.595163
+-8.004220
+-7.423325
+-6.863443
+-6.333481
+-5.840219
+-5.388405
+-4.980953
+-4.619217
+-4.303283
+-4.032269
+-3.804603
+-3.618262
+-3.470982
+-3.360423
+-3.284305
+-3.240501
+-3.227112
+-3.242511
+-3.285375
+-3.354699
+-3.449797
+-3.570302
+-3.716150
+-3.887564
+-4.085033
+-4.309287
+-4.561262
+-4.842060
+-5.152903
+-5.495066
+-5.869803
+-6.278244
+-6.721267
+-7.199344
+-7.712334
+-8.259248
+-8.837952
+-9.444831
+-10.074407
+-10.718935
+-11.368010
+-12.008227
+-12.622988
+-13.192519
+-13.694255
+-14.103663
+-14.395606
+-14.546239
+-14.535338
+-14.348791
+-13.980847
+-13.435674
+-12.727777
+-11.881089
+-10.926770
+-9.900136
+-8.837276
+-7.771974
+-6.733370
+-5.744596
+-4.822333
+-3.977102
+-3.214041
+-2.533917
+-1.934181
+-1.409942
+-0.954808
+-0.561554
+-0.222634
+0.069448
+0.321888
+0.541420
+0.734239
+0.905958
+1.061625
+1.205744
+1.342335
+1.474983
+1.606907
+1.741024
+1.880007
+2.026349
+2.182419
+2.350507
+2.532878
+2.731804
+2.949605
+3.188673
+3.451499
+3.740678
+4.058923
+4.409043
+4.793924
+5.216476
+5.679554
+6.185841
+6.737679
+7.336845
+7.984239
+8.679487
+9.420441
+10.202554
+11.018165
+11.855688
+12.698798
+13.525713
+14.308751
+15.014416
+15.604290
+16.037031
+16.271631
+16.271852
+16.011377
+15.478745
+14.680878
+13.644023
+12.411518
+11.038630
+9.585660
+8.110955
+6.665306
+5.288561
+4.008532
+2.841680
+1.794877
+0.867599
+0.054068
+-0.654887
+-1.270357
+-1.804261
+-2.268579
+-2.674846
+-3.033851
+-3.355466
+-3.648586
+-3.921129
+-4.180074
+-4.431534
+-4.680828
+-4.932561
+-5.190694
+-5.458611
+-5.739163
+-6.034700
+-6.347088
+-6.677699
+-7.027383
+-7.396420
+-7.784446
+-8.190357
+-8.612199
+-9.047041
+-9.490840
+-9.938315
+-10.382844
+-10.816398
+-11.229556
+-11.611618
+-11.950848
+-12.234876
+-12.451275
+-12.588289
+-12.635691
+-12.585680
+-12.433736
+-12.179282
+-11.826066
+-11.382147
+-10.859473
+-10.273086
+-9.640043
+-8.978226
+-8.305167
+-7.637062
+-6.988019
+-6.369618
+-5.790742
+-5.257643
+-4.774171
+-4.342121
+-3.961611
+-3.631477
+-3.349633
+-3.113390
+-2.919728
+-2.765508
+-2.647640
+-2.563210
+-2.509562
+-2.484359
+-2.485617
+-2.511722
+-2.561431
+-2.633873
+-2.728530
+-2.845233
+-2.984137
+-3.145708
+-3.330705
+-3.540162
+-3.775362
+-4.037820
+-4.329249
+-4.651523
+-5.006627
+-5.396594
+-5.823412
+-6.288910
+-6.794600
+-7.341471
+-7.929735
+-8.558490
+-9.225324
+-9.925833
+-10.653075
+-11.396985
+-12.143791
+-12.875534
+-13.569794
+-14.199807
+-14.735151
+-15.143176
+-15.391295
+-15.450082
+-15.296887
+-14.919437
+-14.318652
+-13.509918
+-12.522296
+-11.395630
+-10.176105
+-8.911200
+-7.645075
+-6.415169
+-5.250338
+-4.170441
+-3.187013
+-2.304577
+-1.522191
+-0.834976
+-0.235440
+0.285436
+0.737380
+1.130235
+1.473552
+1.776343
+2.046929
+2.292888
+2.521044
+2.737503
+2.947713
+3.156529
+3.368292
+3.586903
+3.815890
+4.058473
+4.317610
+4.596038
+4.896296
+5.220724
+5.571458
+5.950386
+6.359085
+6.798728
+7.269951
+7.772687
+8.305949
+8.867575
+9.453922
+10.059541
+10.676819
+11.295651
+11.903175
+12.483636
+13.018475
+13.486732
+13.865858
+14.132983
+14.266648
+14.248874
+14.067333
+13.717293
+13.202916
+12.537590
+11.743099
+10.847713
+9.883515
+8.883446
+7.878583
+6.896039
+5.957663
+5.079557
+4.272246
+3.541296
+2.888174
+2.311175
+1.806305
+1.368048
+0.990004
+0.665374
+0.387330
+0.149264
+-0.055042
+-0.231320
+-0.384777
+-0.520081
+-0.641390
+-0.752384
+-0.856318
+-0.956076
+-1.054228
+-1.153084
+-1.254753
+-1.361191
+-1.474250
+-1.595722
+-1.727381
+-1.871018
+-2.028478
+-2.201692
+-2.392701
+-2.603689
+-2.836998
+-3.095151
+-3.380865
+-3.697052
+-4.046816
+-4.433434
+-4.860313
+-5.330923
+-5.848687
+-6.416829
+-7.038139
+-7.714672
+-8.447315
+-9.235247
+-10.075223
+-10.960722
+-11.880931
+-12.819644
+-13.754176
+-14.654497
+-15.482884
+-16.194500
+-16.739332
+-17.065855
+-17.126503
+-16.884460
+-16.320662
+-15.439243
+-14.269627
+-12.864076
+-11.290930
+-9.625176
+-7.938856
+-6.293556
+-4.736189
+-3.298025
+-1.996119
+-0.836006
+0.185238
+1.076202
+1.848839
+2.516757
+3.094009
+3.594305
+4.030521
+4.414437
+4.756613
+5.066365
+5.351803
+5.619900
+5.876572
+6.126772
+6.374573
+6.623243
+6.875310
+7.132613
+7.396335
+7.667031
+7.944636
+8.228464
+8.517205
+8.808910
+9.100987
+9.390198
+9.672671
+9.943942
+10.199016
+10.432473
+10.638618
+10.811672
+10.946012
+11.036448
+11.078515
+11.068782
+11.005119
+10.886930
+10.715282
+10.492963
+10.224394
+9.915454
+9.573195
+9.205486
+8.820634
+8.426986
+8.032579
+7.644848
+7.270400
+6.914882
+6.582917
+6.278111
+6.003115
+5.759718
+5.548971
+5.371317
+5.226727
+5.114817
+5.034966
+4.986412
+4.968328
+4.979893
+5.020338
+5.088974
+5.185223
+5.308611
+5.458778
+5.635451
+5.838425
+6.067520
+6.322540
+6.603204
+6.909078
+7.239483
+7.593398
+7.969332
+8.365201
+8.778181
+9.204556
+9.639568
+10.077290
+10.510511
+10.930697
+11.328019
+11.691494
+12.009271
+12.269069
+12.458782
+12.567235
+12.585028
+12.505409
+12.325057
+12.044645
+11.669106
+11.207500
+10.672484
+10.079461
+9.445476
+8.788052
+8.124095
+7.468985
+6.835929
+6.235605
+5.676059
+5.162817
+4.699142
+4.286379
+3.924334
+3.611648
+3.346140
+3.125109
+2.945583
+2.804516
+2.698944
+2.626096
+2.583472
+2.568897
+2.580546
+2.616961
+2.677052
+2.760090
+2.865699
+2.993835
+3.144778
+3.319107
+3.517684
+3.741631
+3.992309
+4.271289
+4.580313
+4.921252
+5.296043
+5.706607
+6.154746
+6.641996
+7.169448
+7.737507
+8.345598
+8.991794
+9.672376
+10.381330
+11.109784
+11.845452
+12.572130
+13.269365
+13.912439
+14.472840
+14.919399
+15.220215
+15.345387
+15.270354
+14.979416
+14.468759
+13.748268
+12.841501
+11.783623
+10.617621
+9.389589
+8.144051
+6.920193
+5.749489
+4.654770
+3.650486
+2.743745
+1.935740
+1.223236
+0.599938
+0.057638
+-0.412888
+-0.821213
+-1.176790
+-1.488648
+-1.765202
+-2.014169
+-2.242529
+-2.456557
+-2.661856
+-2.863431
+-3.065757
+-3.272857
+-3.488369
+-3.715619
+-3.957673
+-4.217385
+-4.497433
+-4.800335
+-5.128454
+-5.483979
+-5.868883
+-6.284858
+-6.733213
+-7.214739
+-7.729530
+-8.276754
+-8.854383
+-9.458861
+-10.084752
+-10.724341
+-11.367267
+-12.000202
+-12.606680
+-13.167146
+-13.659352
+-14.059196
+-14.342081
+-14.484786
+-14.467747
+-14.277469
+-13.908696
+-13.365881
+-12.663548
+-11.825366
+-10.881987
+-9.868050
+-8.818902
+-7.767611
+-6.742713
+-5.766884
+-4.856506
+-4.021952
+-3.268330
+-2.596468
+-2.003934
+-1.485989
+-1.036409
+-0.648138
+-0.313795
+-0.026037
+0.222189
+0.437493
+0.625950
+0.793070
+0.943801
+1.082560
+1.213280
+1.339465
+1.464253
+1.590481
+1.720741
+1.857443
+2.002869
+2.159222
+2.328674
+2.513404
+2.715638
+2.937677
+3.181925
+3.450904
+3.747267
+4.073799
+4.433397
+4.829049
+5.263766
+5.740508
+6.262043
+6.830776
+7.448493
+8.116034
+8.832851
+9.596470
+10.401814
+11.240421
+12.099587
+12.961491
+13.802457
+14.592552
+15.295783
+15.871225
+16.275379
+16.465899
+16.406534
+16.072681
+15.456450
+14.569903
+13.445306
+12.131886
+10.689693
+9.182011
+7.668158
+6.198133
+4.809755
+3.528177
+2.367080
+1.330786
+0.416632
+-0.382830
+-1.077996
+-1.680797
+-2.203683
+-2.658925
+-3.058179
+-3.412225
+-3.730845
+-4.022781
+-4.295762
+-4.556551
+-4.811025
+-5.064251
+-5.320564
+-5.583635
+-5.856529
+-6.141746
+-6.441246
+-6.756454
+-7.088245
+-7.436912
+-7.802109
+-8.182780
+-8.577071
+-8.982230
+-9.394507
+-9.809056
+-10.219863
+-10.619711
+-11.000210
+-11.351907
+-11.664509
+-11.927232
+-12.129283
+-12.260470
+-12.311902
+-12.276726
+-12.150824
+-11.933370
+-11.627161
+-11.238648
+-10.777644
+-10.256720
+-9.690372
+-9.094060
+-8.483232
+-7.872468
+-7.274792
+-6.701222
+-6.160545
+-5.659293
+-5.201878
+-4.790831
+-4.427110
+-4.110414
+-3.839504
+-3.612484
+-3.427054
+-3.280714
+-3.170933
+-3.095272
+-3.051485
+-3.037577
+-3.051855
+-3.092947
+-3.159818
+-3.251768
+-3.368425
+-3.509736
+-3.675947
+-3.867584
+-4.085429
+-4.330490
+-4.603966
+-4.907205
+-5.241647
+-5.608757
+-6.009935
+-6.446398
+-6.919038
+-7.428234
+-7.973620
+-8.553805
+-9.166035
+-9.805799
+-10.466409
+-11.138538
+-11.809814
+-12.464491
+-13.083314
+-13.643703
+-14.120363
+-14.486471
+-14.715455
+-14.783358
+-14.671542
+-14.369381
+-13.876403
+-13.203382
+-12.371975
+-11.412859
+-10.362644
+-9.260173
+-8.142909
+-7.044018
+-5.990481
+-5.002295
+-4.092584
+-3.268335
+-2.531475
+-1.880035
+-1.309264
+-0.812588
+-0.382382
+-0.010574
+0.310932
+0.589953
+0.833842
+1.049385
+1.242755
+1.419514
+1.584647
+1.742607
+1.897384
+2.052567
+2.211415
+2.376921
+2.551879
+2.738939
+2.940657
+3.159543
+3.398095
+3.658827
+3.944291
+4.257076
+4.599808
+4.975118
+5.385596
+5.833714
+6.321711
+6.851438
+7.424140
+8.040180
+8.698673
+9.397048
+10.130508
+10.891425
+11.668678
+12.447012
+13.206502
+13.922291
+14.564774
+15.100471
+15.493780
+15.709703
+15.717485
+15.494736
+15.031368
+14.332435
+13.418996
+12.326548
+11.101149
+9.794061
+8.456094
+7.132812
+5.861331
+4.668912
+3.573072
+2.582723
+1.699822
+0.921136
+0.239859
+-0.353034
+-0.867738
+-1.314844
+-1.704801
+-2.047571
+-2.352421
+-2.627820
+-2.881410
+-3.120025
+-3.349744
+-3.575953
+-3.803428
+-4.036406
+-4.278657
+-4.533548
+-4.804091
+-5.092979
+-5.402606
+-5.735066
+-6.092127
+-6.475191
+-6.885211
+-7.322596
+-7.787066
+-8.277484
+-8.791649
+-9.326063
+-9.875672
+-10.433610
+-10.990957
+-11.536570
+-12.057010
+-12.536661
+-12.958081
+-13.302654
+-13.551585
+-13.687211
+-13.694565
+-13.563013
+-13.287741
+-12.870811
+-12.321551
+-11.656130
+-10.896312
+-10.067600
+-9.197051
+-8.311120
+-7.433856
+-6.585618
+-5.782400
+-5.035680
+-4.352698
+-3.736995
+-3.189090
+-2.707177
+-2.287785
+-1.926348
+-1.617674
+-1.356315
+-1.136845
+-0.954050
+-0.803063
+-0.679438
+-0.579191
+-0.498805
+-0.435221
+-0.385813
+-0.348353
+-0.320973
+-0.302129
+-0.290561
+-0.285260
+-0.285432
+-0.290471
+-0.299937
+-0.313531
+-0.331077
+-0.352511
+-0.377869
+-0.407278
+-0.440950
+-0.479180
+-0.522347
+-0.570908
+-0.625413
+-0.686497
+-0.754896
+-0.831452
+-0.917124
+-1.013000
+-1.120311
+-1.240447
+-1.374975
+-1.525661
+-1.694488
+-1.883681
+-2.095734
+-2.333430
+-2.599873
+-2.898502
+-3.233116
+-3.607880
+-4.027320
+-4.496298
+-5.019949
+-5.603580
+-6.252484
+-6.971677
+-7.765482
+-8.636955
+-9.587064
+-10.613600
+-11.709749
+-12.862327
+-14.049711
+-15.239668
+-16.387411
+-17.434544
+-18.309774
+-18.932495
+-19.220139
+-19.099495
+-18.520657
+-17.470377
+-15.980270
+-14.125779
+-12.014787
+-9.769028
+-7.504439
+-5.316381
+-3.272640
+-1.413587
+0.243177
+1.696537
+2.955883
+4.036366
+4.955545
+5.731258
+6.380393
+6.918293
+7.358557
+7.713074
+7.992185
+8.204907
+8.359165
+8.462008
+8.519803
+8.538393
+8.523212
+8.479374
+8.411719
+8.324849
+8.223127
+8.110675
+7.991353
+7.868743
+7.746134
+7.626499
+7.512493
+7.406450
+7.310385
+7.226006
+7.154728
+7.097697
+7.055809
+7.029730
+7.019926
+7.026676
+7.050095
+7.090147
+7.146661
+7.219328
+7.307716
+7.411258
+7.529253
+7.660852
+7.805050
+7.960665
+8.126325
+8.300446
+8.481220
+8.666600
+8.854290
+9.041741
+9.226166
+9.404552
+9.573703
+9.730285
+9.870902
+9.992180
+10.090872
+10.163978
+10.208869
+10.223415
+10.206105
+10.156151
+10.073561
+9.959185
+9.814715
+9.642648
+9.446196
+9.229176
+8.995860
+8.750814
+8.498730
+8.244262
+7.991888
+7.745787
+7.509750
+7.287115
+7.080740
+6.892996
+6.725779
+6.580550
+6.458372
+6.359967
+6.285765
+6.235958
+6.210547
+6.209388
+6.232223
+6.278711
+6.348447
+6.440968
+6.555761
+6.692253
+6.849793
+7.027636
+7.224903
+7.440549
+7.673315
+7.921674
+8.183783
+8.457416
+8.739915
+9.028132
+9.318394
+9.606465
+9.887558
+10.156353
+10.407072
+10.633594
+10.829621
+10.988906
+11.105515
+11.174137
+11.190410
+11.151231
+11.055037
+10.902001
+10.694141
+10.435296
+10.130983
+9.788139
+9.414764
+9.019510
+8.611251
+8.198678
+7.789948
+7.392410
+7.012422
+6.655252
+6.325062
+6.024957
+5.757074
+5.522716
+5.322483
+5.156424
+5.024173
+4.925076
+4.858301
+4.822929
+4.818035
+4.842741
+4.896258
+4.977917
+5.087176
+5.223630
+5.386993
+5.577083
+5.793789
+6.037029
+6.306696
+6.602592
+6.924345
+7.271316
+7.642483
+8.036314
+8.450622
+8.882403
+9.327676
+9.781312
+10.236894
+10.686600
+11.121159
+11.529896
+11.900904
+12.221377
+12.478126
+12.658270
+12.750102
+12.744036
+12.633562
+12.416076
+12.093438
+11.672160
+11.163140
+10.580969
+9.942876
+9.267477
+8.573482
+7.878537
+7.198323
+6.545956
+5.931708
+5.363005
+4.844621
+4.379020
+3.966759
+3.606905
+3.297442
+3.035619
+2.818258
+2.641996
+2.503476
+2.399490
+2.327080
+2.283604
+2.266779
+2.274700
+2.305848
+2.359085
+2.433642
+2.529109
+2.645414
+2.782810
+2.941855
+3.123400
+3.328567
+3.558737
+3.815527
+4.100770
+4.416479
+4.764809
+5.148003
+5.568310
+6.027884
+6.528640
+7.072069
+7.658990
+8.289235
+8.961258
+9.671647
+10.414565
+11.181115
+11.958680
+12.730310
+13.474277
+14.163957
+14.768247
+15.252749
+15.581881
+15.721949
+15.645008
+15.332988
+14.781294
+14.000976
+13.018703
+11.874291
+10.616177
+9.295842
+7.962401
\ No newline at end of file
diff --git a/nolds/datasets/lorenz_physionet.txt b/nolds/datasets/lorenz_physionet.txt
new file mode 100644
index 0000000..298f15d
--- /dev/null
+++ b/nolds/datasets/lorenz_physionet.txt
@@ -0,0 +1,51 @@
+0.60206 -0.552437
+0.69897 -0.329913
+0.778151 -0.158909
+0.845098 -0.018926
+0.90309 0.103394
+0.954243 0.202777
+1 0.303933
+1.04139 0.384157
+1.07918 0.456
+1.11394 0.524857
+1.17609 0.653908
+1.20412 0.697786
+1.23045 0.764917
+1.27875 0.83224
+1.32222 0.927356
+1.36173 0.996491
+1.39794 1.0685
+1.43136 1.08883
+1.4624 1.13295
+1.50515 1.20733
+1.54407 1.31363
+1.57978 1.34387
+1.61278 1.40501
+1.65321 1.44724
+1.6902 1.51637
+1.73239 1.59028
+1.77085 1.60669
+1.80618 1.71927
+1.8451 1.67582
+1.88081 1.81187
+1.91908 1.85253
+1.95904 1.89105
+1.99564 1.91875
+2.03342 1.97935
+2.06819 2.00785
+2.10721 2.04319
+2.14613 2.13157
+2.18184 2.08953
+2.22011 2.11158
+2.25768 2.09104
+2.29447 2.14402
+2.33244 2.206
+2.37107 2.27114
+2.40824 2.20083
+2.4456 2.26255
+2.48287 2.2345
+2.52114 2.30591
+2.55871 2.30442
+2.5966 2.40574
+2.63448 2.32489
+2.6721 2.38404
diff --git a/nolds/examples.py b/nolds/examples.py
index ead3ab3..b13801d 100644
--- a/nolds/examples.py
+++ b/nolds/examples.py
@@ -456,11 +456,12 @@ def lorenz():
        similarities in the analysis of Lorenz, Chen, and Lu systems,”
        Applied Mathematics and Computation, vol. 256, pp. 334–343, 2015,
        doi: 10.1016/j.amc.2014.12.132.
-    .. [l_5] J. S. González-Salas, M. S. Shbat, F. C. Ordaz-Salazar, and
-       J. Simón, “Analyzing Chaos Systems and Fine Spectrum Sensing
-       Using Detrended Fluctuation Analysis Algorithm,” Mathematical
-       Problems in Engineering, vol. 2016, pp. 1–18, 2016,
-       doi: 10.1155/2016/2865195.
+    .. [l_5] S. Wallot, J. P. Irmer, M. Tschense, N. Kuznetsov, A. Højlund,
+       and M. Dietz, “A Multivariate Method for Dynamic System Analysis:
+       Multivariate Detrended Fluctuation Analysis Using Generalized Variance,”
+       Topics in Cognitive Science, p. tops.12688, Sep. 2023,
+       doi: 10.1111/tops.12688.
+
 
   """
   import matplotlib.pyplot as plt
@@ -540,16 +541,18 @@ def lorenz():
   print("hurst_rs(z)            : ", hz)
   print()
 
-  # reference Gonzáles-Salas 2016
+  # reference: Wallot 2023, Table 1
   # Rationale for argument values: Just follow paper
-  # NOTE: discrepancies here can be explained by different solver (RK4 vs euler)
-  # and different step size (0.01 vs 0.012).
-  nvals = nolds.logarithmic_n(round(2**4.75), 2**7, 2**0.2) # only use scales < 2^7 and >= 2^4.75
-  dfa_args = dict(nvals=nvals, fit_exp="poly")
-  dx = nolds.dfa(data[:, 0], **dfa_args)
-  dy = nolds.dfa(data[:, 1], **dfa_args)
-  dz = nolds.dfa(data[:, 2], **dfa_args)
-  print("Expected hurst parameter: [1.5, 1.4, 1.4]")
+  # NOTE since DFA is quite fast and Wallot 2023 use different initial values
+  # (x = y = z = 0.1 + e) and size of data (100k data points, 1000 runs) and
+  # don't report step size, we use different data here
+  data_dfa = datasets.lorenz_euler(120000, 10, 28, 8/3.0, start=[0.1,0.1,0.1], dt=0.002)[20000:]
+  nvals = nolds.logarithmic_n(200, len(data_dfa)/8, 2**0.2)
+  dfa_args = dict(nvals=nvals, order=2, overlap=False, fit_exp="poly")
+  dx = nolds.dfa(data_dfa[:, 0], **dfa_args)
+  dy = nolds.dfa(data_dfa[:, 1], **dfa_args)
+  dz = nolds.dfa(data_dfa[:, 2], **dfa_args)
+  print("Expected hurst parameter: [1.008 ±0.016, 0.926 ±0.016, 0.650 ±0.22]")
   print("dfa(x)                  : ", dx)
   print("dfa(y)                  : ", dy)
   print("dfa(z)                  : ", dz)
diff --git a/nolds/measures.py b/nolds/measures.py
index b97c5d3..7b5fdb1 100644
--- a/nolds/measures.py
+++ b/nolds/measures.py
@@ -1993,7 +1993,7 @@ def dfa(data, nvals=None, overlap=True, order=1, fit_trend="poly",
     * nvals should be equally spaced on a logarithmic scale so that each window
       scale hase the same weight
     * min(nvals) < 4 does not make much sense as fitting a polynomial (even if
-      it is only of order 1) to 3 or less data points is very prone.
+      it is only of order 1) to 3 or less data points is very prone to errors.
     * max(nvals) > len(data) / 10 does not make much sense as we will then have
       less than 10 windows to calculate the average fluctuation
     * use overlap=True to obtain more windows and therefore better statistics
@@ -2001,51 +2001,74 @@ def dfa(data, nvals=None, overlap=True, order=1, fit_trend="poly",
 
   Explanation of DFA:
     Detrended fluctuation analysis, much like the Hurst exponent, is used to
-    find long-term statistical dependencies in time series.
-
-    The idea behind DFA originates from the definition of self-affine
-    processes. A process X is said to be self-affine if the standard deviation
-    of the values within a window of length n changes with the window length
-    factor L in a power law:
-
-    std(X,L * n) = L^H * std(X, n)
-
-    where std(X, k) is the standard deviation of the process X calculated over
-    windows of size k. In this equation, H is called the Hurst parameter, which
-    behaves indeed very similar to the Hurst exponent.
-
-    Like the Hurst exponent, H can be obtained from a time series by
-    calculating std(X,n) for different n and fitting a straight line to the
-    plot of log(std(X,n)) versus log(n).
-
-    To calculate a single std(X,n), the time series is split into windows of
-    equal length n, so that the ith window of this size has the form
-
-    W_(n,i) = [x_i, x_(i+1), x_(i+2), ... x_(i+n-1)]
-
-    The value std(X,n) is then obtained by calculating std(W_(n,i)) for each i
-    and averaging the obtained values over i.
-
-    The aforementioned definition of self-affinity, however, assumes that the
-    process is  non-stationary (i.e. that the standard deviation changes over
-    time) and it is highly influenced by local and global trends of the time
-    series.
-
-    To overcome these problems, an estimate alpha of H is calculated by using a
-    "walk" or "signal profile" instead of the raw time series. This walk is
-    obtained by substracting the mean and then taking the cumulative sum of the
-    original time series. The local trends are removed for each window
-    separately by fitting a polynomial p_(n,i) to the window W_(n,i) and then
-    calculating W'_(n,i) = W_(n,i) - p_(n,i) (element-wise substraction).
-
-    We then calculate std(X,n) as before only using the "detrended" window
-    W'_(n,i) instead of W_(n,i). Instead of H we obtain the parameter alpha
-    from the line fitting.
-
-    For alpha < 1 the underlying process is stationary and can be modelled as
-    fractional Gaussian noise with H = alpha. This means for alpha = 0.5 we
-    have no correlation or "memory", for 0.5 < alpha < 1 we have a memory with
-    positive correlation and for alpha < 0.5 the correlation is negative.
+    find long-term statistical dependencies in time series. However, while the
+    Hurst exponent will indicate long-term correlations for any non-stationary
+    process (i.e. a stochastic process whose probability distribution changes
+    when shifted in time, such as a random walk whose mean changes over time),
+    DFA was designed to distinguish between correlations that are purely an
+    artifact of non-stationarity and those that show inherent long-term
+    behavior of the studied system.
+
+    Mathematically, the long-term correlations that we are interested in can
+    be characterized using the autocorrelation function C(s). For a time series
+    (x_i) with i = 1, ..., N it is defined as follows:
+
+    C(s) = 1/(N-s) * (y_1 * y_1+s + y_2 * y_2+s + ... y_(N-s) * y_N)
+
+    with y_i = x_i - mean(x). If there are no correlations at all, C(s) would
+    be zero for s > 0. For short-range correlations, C(s) will decline
+    exponentially, but for long-term correlations the decline follows a power
+    law of the form C(s) ~ s^(-gamma) instead with 0 < gamma < 1.
+
+    Due to noise and underlying trends, calculating C(s) directly is usually not
+    feasible. The main idea of DFA is therefore to remove trends up to a given
+    order from the input data and analyze the remaining fluctuations. Trends
+    in this sense are smooth signals with monotonous or slowly oscillating
+    behavior that are caused by external effects and not the dynamical system
+    under study.
+  
+    To get a hold of these trends, the first step is to calculate the "profile"
+    of our time series as the cumulative sum of deviations from the mean,
+    effectively integrating our data. This both smoothes out measurement noise
+    and makes it easier to distinguish the fractal properties of bounded time
+    series (i.e. time series whose values cannot grow or shrink beyond certain
+    bounds such as most biological or physical signals) by applying random walk
+    theory (see [dfa_3]_ and [dfa_4]_).
+
+    y_i = x_1 - mean(x) + x_2 - mean(x) + ... + x_i - mean(x).
+
+    After that, we split Y(i) into (usually non-overlapping) windows of length
+    n to calculate local trends at this given scale. The ith window of this
+    size has the form
+
+    W_(n,i) = [y_i, y_(i+1), y_(i+2), ... y_(i+n-1)]
+    
+    The local trends are then removed for each window separately by fitting a
+    polynomial p_(n,i) to the window W_(n,i) and then calculating
+    W'_(n,i) = W_(n,i) - p_(n,i) (element-wise subtraction).
+
+    This leaves us with the deviations from the trend - the "fluctuations" -
+    that we are interested in. To quantify them, we take the root mean square
+    of these fluctuations. It is important to note that we have to sum up all
+    individual fluctuations across all windows and divide by the total number
+    of fluctuations here before finally taking the root as last step. Some
+    implementations apply another root per window, which skews the result.
+
+    The resulting fluctuation F(n) is then only dependent on the window size n,
+    the scale at which we observe our data. It behaves similar to the
+    autocorrelation function in that it follows a power-law for long-term
+    correlations:
+
+    F(n) ~ n^alpha
+
+    Where alpha is the Hurst parameter, which we can obtain from fitting a line
+    into the plot of log(n) versus log(F(n)) and taking the slope.
+
+    The result can be interpreted as follows: For alpha < 1 the underlying
+    process is stationary and can be modelled as fractional Gaussian noise with
+    H = alpha. This means for alpha = 0.5 we have no long-term correlation or
+    "memory", for 0.5 < alpha < 1 we have positive long-term correlations and
+    for alpha < 0.5 the long-term correlations are negative.
 
     For alpha > 1 the underlying process is non-stationary and can be modeled
     as fractional Brownian motion with H = alpha - 1.
@@ -2054,7 +2077,23 @@ def dfa(data, nvals=None, overlap=True, order=1, fit_trend="poly",
     .. [dfa_1] C.-K. Peng, S. V. Buldyrev, S. Havlin, M. Simons,
                H. E. Stanley, and A. L. Goldberger, “Mosaic organization of
                DNA nucleotides,” Physical Review E, vol. 49, no. 2, 1994.
-    .. [dfa_2] R. Hardstone, S.-S. Poil, G. Schiavone, R. Jansen,
+    .. [dfa_2] J. W. Kantelhardt, E. Koscielny-Bunde, H. H. A. Rego, S.
+               Havlin, and A. Bunde, “Detecting long-range correlations with
+               detrended fluctuation analysis,” Physica A: Statistical
+               Mechanics and its Applications, vol. 295, no. 3–4, pp. 441–454,
+               Jun. 2001, doi: 10.1016/S0378-4371(01)00144-3.
+    .. [dfa_3] C. Peng, J. M. Hausdorff, and A. L. Goldberger, “Fractal
+               mechanisms in neuronal control: human heartbeat and gait
+               dynamics in health and disease,” in Self-Organized Biological
+               Dynamics and Nonlinear Control, 1st ed., J. Walleczek, Ed.,
+               Cambridge University Press, 2000, pp. 66–96.
+               doi: 10.1017/CBO9780511535338.006.
+    .. [dfa_4] A. Bashan, R. Bartsch, J. W. Kantelhardt, and S. Havlin,
+               “Comparison of detrending methods for fluctuation analysis,”
+               Physica A: Statistical Mechanics and its Applications, vol. 387,
+               no. 21, pp. 5080–5090, Sep. 2008,
+               doi: 10.1016/j.physa.2008.04.023.
+    .. [dfa_5] R. Hardstone, S.-S. Poil, G. Schiavone, R. Jansen,
                V. V. Nikulin, H. D. Mansvelder, and K. Linkenkaer-Hansen,
                “Detrended fluctuation analysis: A scale-free view on neuronal
                oscillations,” Frontiers in Physiology, vol. 30, 2012.
@@ -2145,10 +2184,13 @@ def dfa(data, nvals=None, overlap=True, order=1, fit_trend="poly",
              for i in range(len(d))]
     tpoly = np.array(tpoly)
     trend = np.array([np.polyval(tpoly[i], x) for i in range(len(d))])
-    # calculate standard deviation ("fluctuation") of walks in d around trend
-    flucs = np.sqrt(np.sum((d - trend) ** 2, axis=1) / n)
-    # calculate mean fluctuation over all subsequences
-    f_n = np.sum(flucs) / len(flucs)
+    # calculate mean-square differences for each walk in d around trend
+    flucs = np.sum((d - trend) ** 2, axis=1) / n
+    # take another mean across all walks and finally take the square root of that
+    # NOTE: To map this to the formula in Peng1995, observe that this simplifies
+    # to np.sqrt(np.sum((d - trend) ** 2) / total_N) if we have non-overlapping
+    # windows and the last window matches the end of the data perfectly.
+    f_n = np.sqrt(np.sum(flucs) / len(flucs))
     fluctuations.append(f_n)
   fluctuations = np.array(fluctuations)
   # filter zeros from fluctuations


Test patch:
diff --git a/nolds/test_measures.py b/nolds/test_measures.py
index 0df5d34..8f4fded 100644
--- a/nolds/test_measures.py
+++ b/nolds/test_measures.py
@@ -19,6 +19,12 @@
 
 # TODO split up tests into smaller units => one hypothesis = one test
 
+try:
+  from scipy.stats import levy_stable
+  SCIPY_AVAILABLE = True
+except ImportError:
+  SCIPY_AVAILABLE = False
+
 
 class TestNoldsHelperFunctions(unittest.TestCase):
   """
@@ -370,27 +376,48 @@ def test_dfa_fbm(self):
   def test_dfa_lorenz(self):
     """Test hypothesis: We get correct values for estimating the Hurst parameter of the Lorenz system.
 
-    All parameter values are chosen to replicate the experiment by González-Salas et al. (see [l_5]_)
+    All parameter values are chosen to replicate the experiment by Wallot et al. (see [l_5]_)
     as closely as possible.
 
     For performance reasons the size of the input data was reduced and therefore the
     assert conditions needed to be relaxed a bit.
 
-    .. [l_5] J. S. González-Salas, M. S. Shbat, F. C. Ordaz-Salazar, and
-       J. Simón, “Analyzing Chaos Systems and Fine Spectrum Sensing
-       Using Detrended Fluctuation Analysis Algorithm,” Mathematical
-       Problems in Engineering, vol. 2016, pp. 1–18, 2016,
-       doi: 10.1155/2016/2865195.
+    .. [l_5] S. Wallot, J. P. Irmer, M. Tschense, N. Kuznetsov, A. Højlund,
+       and M. Dietz, “A Multivariate Method for Dynamic System Analysis:
+       Multivariate Detrended Fluctuation Analysis Using Generalized Variance,”
+       Topics in Cognitive Science, p. tops.12688, Sep. 2023,
+       doi: 10.1111/tops.12688.
     """
-    data = datasets.lorenz_euler(3000, 10, 28, 8/3.0, start=[1,1,1], dt=0.012)[1000:]
-    nvals = nolds.logarithmic_n(round(2**4.75), 2**7, 2**0.2)
-    dfa_args = dict(nvals=nvals, fit_exp="poly")
+    data = datasets.lorenz_euler(120000, 10, 28, 8/3.0, start=[0.1,0.1,0.1], dt=0.002)[20000:]
+    nvals = nolds.logarithmic_n(200, len(data)/8, 2**0.2)
+    dfa_args = dict(nvals=nvals, order=2, overlap=False, fit_exp="poly")
     dx = nolds.dfa(data[:, 0], **dfa_args)
     dy = nolds.dfa(data[:, 1], **dfa_args)
     dz = nolds.dfa(data[:, 2], **dfa_args)
-    self.assertAlmostEqual(1.5, dx, delta=0.4)
-    self.assertAlmostEqual(1.4, dy, delta=0.4)
-    self.assertAlmostEqual(1.4, dz, delta=0.4)
+    self.assertAlmostEqual(1.008, dx, delta=0.04)
+    self.assertAlmostEqual(0.926, dy, delta=0.032)
+    self.assertAlmostEqual(0.650, dz, delta=0.44)
+
+  def test_dfa_agreement_with_physionet(self):
+    """Test hypothesis: Using the same parameters, the output of nolds is identical to the output of PhysioNet."""
+    lorenz_x, physionet_points = datasets.load_lorenz_physionet()
+    nvals = [round(x) for x in 10 ** physionet_points[:,0]]
+    _, (_, nolds_rs, _) = nolds.dfa(lorenz_x, nvals=nvals, overlap=False, fit_exp="poly", debug_data=True)
+    nolds_rs_log10 = nolds_rs / np.log(10)
+    # assert that sum of squared errors is less than 1e-9
+    self.assertLess(sum((physionet_points[:,1] - nolds_rs_log10)**2), 1e-9)
+
+  @unittest.skipUnless(SCIPY_AVAILABLE, "Tests using Lévy motion require scipy.")
+  def test_dfa_levy(self):
+    """Test hypothesis: We get correct values for estimating the Hurst parameter of Lévy motion.
+
+    Reference: https://github.com/CSchoel/nolds/issues/17#issuecomment-1905472813.
+    """
+    alpha = 1.5
+    x = levy_stable.rvs(alpha=alpha, beta=0, size=10000)
+    h = nolds.dfa(x, fit_exp="poly")
+    self.assertAlmostEqual(0.5, h, delta=0.1)
+
 
 
 class TestNoldsCorrDim(unittest.TestCase):