library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
X6portfolio <- read.csv("6portfolio.csv")
# Split into two halves
half_n <- nrow(X6portfolio) / 2
first_half <- X6portfolio[1:half_n, ]
second_half <- X6portfolio[(half_n + 1):nrow(X6portfolio), ]

# Compute statistics for both halves
summary_stats <- function(data) {
     return(data.frame(
         Mean = colMeans(data[,-1], na.rm=TRUE),
         SD = apply(data[,-1], 2, sd, na.rm=TRUE),
         Skewness = apply(data[,-1], 2, function(x) moments::skewness(x, na.rm=TRUE)),
         Kurtosis = apply(data[,-1], 2, function(x) moments::kurtosis(x, na.rm=TRUE))
     ))
 }
 
 library(moments)  # Required for skewness & kurtosis
 
 stats_first <- summary_stats(first_half)
 stats_second <- summary_stats(second_half)
 
 print(stats_first)
##                 Mean       SD   Skewness  Kurtosis
## SMALL.LoBM 0.9819132 6.411052 -0.9315746  6.371651
## ME1.BM2    1.4896987 4.879410 -1.4529046  9.185263
## SMALL.HiBM 1.6030573 4.699320 -1.7512081 10.850068
## BIG.LoBM   1.4644427 4.828790 -0.5786937  5.601247
## ME2.BM2    1.3976927 4.340999 -0.7815101  6.954528
## BIG.HiBM   1.5438009 4.074755 -0.8734925  6.352997
 print(second_half)
##          X SMALL.LoBM  ME1.BM2 SMALL.HiBM BIG.LoBM  ME2.BM2 BIG.HiBM
## 235 199907    -1.1252  -0.5169    -1.1700  -2.9887  -3.7973  -3.8208
## 236 199908    -2.7649  -3.0498    -3.4268   0.0456  -3.4353  -3.0357
## 237 199909     0.6314  -0.1897    -2.8843  -1.7866  -5.6162  -5.2602
## 238 199910     0.9525  -0.4475    -2.7004   6.6470   7.5254   3.5624
## 239 199911    13.3583   6.4205     4.3349   4.1944  -2.6936   0.9766
## 240 199912    18.3003   9.0252     6.6659   8.3424   1.2492   3.3242
## 241 200001     1.1975  -0.9354     0.3625  -4.8391  -4.0904  -7.7629
## 242 200002    28.0883  15.6498    13.1301   1.2418  -5.4572  -2.9891
## 243 200003   -13.4840  -4.8054    -1.2043   8.6671  10.7953  12.6437
## 244 200004   -14.6459  -5.7927    -4.3476  -4.2256  -0.5153  -0.0027
## 245 200005    -7.4689  -5.3605    -4.9489  -3.4721   0.3541   3.4989
## 246 200006    17.7779   9.2663     8.5776   4.7732  -4.8059  -2.8696
## 247 200007    -7.1352   1.3482     1.8849  -3.0452   3.7998   4.5455
## 248 200008     8.7960   5.1353     6.6710   7.5806   7.9300   6.9300
## 249 200009    -7.2712  -0.5730    -0.4569  -5.9659   1.5545   1.5671
## 250 200010    -8.4071  -1.3294    -1.5683  -2.0153  -0.2313   2.5737
## 251 200011   -16.5288  -4.3038    -2.9313 -10.5537  -3.4093   0.4395
## 252 200012     2.7926   8.7299     8.6265  -0.1828   8.9452   9.2058
## 253 200101    12.6089   5.0389     6.8630   3.4848   1.8940  -0.9000
## 254 200102   -12.4032  -0.6751     0.0022 -11.2013  -0.8604   1.3265
## 255 200103    -7.6214  -0.8824    -1.5864  -8.0352  -1.5624  -1.2367
## 256 200104    10.1832   5.0033     5.0816   8.9573   4.9486   4.7177
## 257 200105     3.8731   4.6138     6.3100   0.4381   2.1237   4.7252
## 258 200106     6.3064   4.6371     3.1503  -2.2317  -1.0819  -1.3252
## 259 200107    -9.3319  -4.5299    -1.0890  -1.7118  -1.1436   0.4601
## 260 200108    -7.4609  -2.6798    -1.4791  -6.9023  -3.8984  -8.2732
## 261 200109   -17.0159 -13.4339   -14.1521  -8.1659  -9.6087  -8.1314
## 262 200110    11.1180   5.4265     4.4857   3.3534   0.5583  -5.3216
## 263 200111     9.0378   7.3094     9.0717   7.8875   6.6540  12.2742
## 264 200112     6.7106   6.8199     6.6890   0.6646   2.9847   2.3635
## 265 200201    -5.1916   0.3734     3.3048  -0.9182  -1.6239  -2.5436
## 266 200202    -8.1298  -1.2577    -1.0152  -2.3962   0.1967  -5.1829
## 267 200203     8.8781   7.6614     9.9117   3.5933   5.5297   4.6840
## 268 200204    -4.0034   2.3893     4.2270  -7.1199  -0.5419  -7.5924
## 269 200205    -6.7104  -3.6309    -2.6494  -1.3862   0.4151  -2.3928
## 270 200206    -7.0903  -3.2247    -2.4015  -7.4377  -5.9293 -12.2215
## 271 200207   -14.9396 -14.5371   -15.3101  -6.4478  -8.7317 -13.7713
## 272 200208    -0.4395   0.3783    -0.4485  -0.1006   1.7138   6.4683
## 273 200209    -8.3430  -7.4921    -7.1005 -10.8017 -10.2357  -9.1350
## 274 200210     6.6600   4.6300     0.5400   9.7548   4.3438   7.9856
## 275 200211    13.2743   8.3005     7.6826   5.3780   5.8461   8.4496
## 276 200212    -8.6937  -4.6337    -3.5830  -6.1715  -3.9938  -6.9949
## 277 200301    -2.3741  -2.6034    -1.2782  -2.8369  -1.8127  -5.5572
## 278 200302    -3.9343  -1.9031    -3.7313  -1.4217  -2.3934  -4.3684
## 279 200303     1.8119   0.5505     1.0764   1.5895   0.3344  -1.5555
## 280 200304    11.0670   9.3698     9.5335   7.7629   8.7516  11.5916
## 281 200305    13.2044  10.8523    10.6693   5.0071   7.3773   8.3270
## 282 200306     2.4827   2.3886     3.5209   1.3366   1.3129   0.5109
## 283 200307     8.2183   5.6878     6.6437   1.7695   2.7525   0.8599
## 284 200308     4.8971   4.5309     6.0561   2.1260   1.5654   4.0295
## 285 200309    -1.6754  -1.9102     0.9220  -1.1320  -0.5218  -3.3924
## 286 200310     8.3925   8.0205    10.7909   5.2059   7.1717   6.7510
## 287 200311     2.9676   3.6610     4.6760   0.8079   1.6078   2.6610
## 288 200312     1.0783   2.5792     3.1070   4.6141   4.3907   5.7836
## 289 200401     3.8846   3.4793     7.2328   1.4411   2.4336   3.0770
## 290 200402     0.4228   0.9521     0.2898   1.0861   2.2999   2.9757
## 291 200403     1.2928   0.4204     0.4087  -1.8648  -0.7461  -0.4333
## 292 200404    -3.3578  -3.2731    -6.0914  -0.2311  -3.7625  -3.6398
## 293 200405     1.0182   1.2810     0.7002   1.2499   1.2698   1.0769
## 294 200406     3.1157   5.0647     4.3401   1.5136   1.5590   2.6548
## 295 200407    -9.4967  -5.6319    -5.2013  -4.3756  -2.3170  -2.1818
## 296 200408    -2.2001  -0.2903    -0.6391  -0.2820   1.4836   0.1024
## 297 200409     5.5244   5.1974     3.6371   0.8519   1.7287   2.7342
## 298 200410     2.7869   1.6822     1.2476   1.5958   0.9939   2.6893
## 299 200411     8.5101   8.6825     8.7784   3.7051   4.7825   6.2587
## 300 200412     4.4048   2.5672     3.7097   3.5207   3.4817   3.7746
## 301 200501    -5.3911  -3.2935    -2.6630  -3.0957  -1.3806  -1.7037
## 302 200502     0.7712   2.0300     2.8040   2.1229   2.0273   3.1604
## 303 200503    -4.1540  -2.4534    -1.4772  -1.2856  -2.7057   0.1157
## 304 200504    -6.3511  -6.0278    -5.7186  -1.7369  -2.3195  -2.2342
## 305 200505     7.4980   6.3501     5.7183   3.6683   3.0790   4.1685
## 306 200506     2.7806   4.0791     4.7555  -0.7926   1.7881   2.8856
## 307 200507     6.9998   6.9442     5.9866   4.5699   2.6374   3.9961
## 308 200508    -2.2529  -1.1745    -1.2413  -1.2405  -0.8856   0.3806
## 309 200509     0.3822   0.9053     0.2636   0.3871   1.1889   1.9333
## 310 200510    -3.9638  -2.6604    -2.2453  -1.2382  -1.7791  -2.1076
## 311 200511     5.1198   4.6368     4.0298   4.1346   3.7700   2.8948
## 312 200512     0.0933  -0.3940    -0.3230  -0.7290   1.2761   0.0853
## 313 200601     8.5807   9.3029     8.1654   1.8137   3.6573   4.3913
## 314 200602    -0.5483  -0.1125    -0.5208  -0.0917   0.8676  -0.8040
## 315 200603     4.0319   5.2599     5.3598   1.6908   1.0619   1.5704
## 316 200604    -0.5657   1.0112     0.8286   0.0059   2.2492   3.2858
## 317 200605    -7.6554  -4.7814    -4.0432  -2.9029  -3.0052  -1.6874
## 318 200606    -0.7189   0.4315     0.0187  -0.1141   0.1660   0.8541
## 319 200607    -5.8879  -2.8192    -2.1527  -0.7869   1.1701   0.6862
## 320 200608     3.4981   2.5366     2.5223   3.3106   1.9982   0.1641
## 321 200609     0.8236   0.8351     1.3171   2.5161   2.3538   2.1895
## 322 200610     6.1777   5.2030     4.5665   3.3829   2.9276   4.3813
## 323 200611     2.5686   2.7873     2.7404   1.8462   2.1992   1.9554
## 324 200612    -0.5996   0.6809     2.0235   0.3481   2.0059   3.1865
## 325 200701     2.5527   0.8449     1.9196   1.9159   1.8344   1.1933
## 326 200702    -0.1024  -0.0710    -1.0489  -1.9498  -1.5525  -1.2836
## 327 200703     1.7726   1.3221     0.3487   0.8422   1.7789   0.3330
## 328 200704     2.8135   2.0631     0.9535   4.8417   3.6568   3.7988
## 329 200705     4.5063   3.6801     3.1037   3.2198   4.0191   3.3277
## 330 200706    -0.5887  -1.1938    -1.6191  -1.1139  -2.3413  -2.1834
## 331 200707    -4.8084  -5.7876    -8.2207  -1.4022  -4.1777  -5.4141
## 332 200708     1.5001   2.3987    -0.6619   1.5856   2.0066   0.0271
## 333 200709     2.5885   0.9265     0.0934   4.9638   2.2985   3.0316
## 334 200710     3.5844   1.7201     0.1482   3.1527   1.4203   0.6368
## 335 200711    -7.5145  -6.6169    -7.9013  -3.1057  -5.5464  -4.5989
## 336 200712     0.1682  -0.6274    -0.9297  -0.4386  -0.8883  -0.4388
## 337 200801    -8.5654  -6.4989    -3.9366  -7.1977  -4.8299  -3.8873
## 338 200802    -4.6707  -2.8308    -3.9608  -2.1100  -3.5707  -4.4916
## 339 200803    -2.1235   1.1709     0.1903   0.6612  -2.5090  -1.0498
## 340 200804     4.7454   3.4388     1.5267   3.7378   6.0470   5.0753
## 341 200805     5.5150   5.3921     3.0015   2.3412   0.6904   1.9916
## 342 200806    -7.2838  -7.3808    -8.8965  -7.0126  -9.4254 -10.8237
## 343 200807     2.2876   2.9039     5.2999  -1.0748  -2.9991   6.7510
## 344 200808     3.1047   3.8880     7.0479   1.4728   1.0545   0.7139
## 345 200809   -11.0960  -7.2827    -6.9905  -9.7800  -9.8463  -2.0570
## 346 200810   -22.1126 -19.3522   -20.5932 -15.4972 -17.1430 -21.6172
## 347 200811   -11.7044 -11.2504   -14.3367  -6.2057  -6.3444 -16.1953
## 348 200812     4.9088   4.3153     5.3899   1.7000   1.0346   1.5085
## 349 200901    -7.8913 -10.1085   -16.0718  -5.3342  -9.2189 -19.7425
## 350 200902    -9.8277 -11.4073   -15.0774  -7.9555 -11.9113 -16.6032
## 351 200903     9.1856  10.3208    11.0487   8.3258   8.7151  13.4126
## 352 200904    16.4844  16.6446    18.3040   7.9415  10.4615  16.8494
## 353 200905     3.8848   3.1554     2.4796   4.5172   6.0893   6.4772
## 354 200906     5.4172   1.7453     0.7106   0.8703  -1.0007   0.1140
## 355 200907     6.9131  10.3276    13.3708   6.7746   8.2384   9.9829
## 356 200908     1.0155   3.0144     8.1881   1.7045   3.9404   9.8001
## 357 200909     6.3176   5.8375     7.5795   3.4573   4.7055   4.2793
## 358 200910    -6.9838  -6.3198    -9.3979  -0.4418  -2.7689  -6.4484
## 359 200911     2.0214   1.9394     4.1184   6.6381   4.7671   3.8618
## 360 200912     8.4759   8.0740     8.3772   1.9456   3.1202   1.7169
## 361 201001    -3.7834  -3.0201    -2.6859  -4.2125  -2.0265  -4.4504
## 362 201002     3.3733   4.1291     7.4536   3.0580   2.9082   5.4191
## 363 201003     7.0160   8.1488     8.9499   5.2329   6.7363   7.7161
## 364 201004     3.9334   6.2370     9.2931   0.8520   2.7427   1.2645
## 365 201005    -5.9602  -7.1246   -10.3687  -7.3779  -8.5019  -7.8501
## 366 201006    -5.7705  -7.5702   -10.8838  -4.4235  -5.6504  -8.7076
## 367 201007     6.7868   6.6902     7.2318   6.7418   7.6803   5.6834
## 368 201008    -7.1815  -7.6696    -8.6118  -4.0632  -3.9597  -6.4365
## 369 201009    14.0514  12.7735    10.9568  10.0755   8.9842   6.8510
## 370 201010     4.4471   4.2271     3.6404   4.5444   3.8611   0.5078
## 371 201011     3.7207   4.1029     3.3312   0.5094   0.3779  -1.0253
## 372 201012     7.3154   8.3352     9.4636   4.9391   7.7950  10.1774
## 373 201101    -0.4693   0.0666     0.3442   2.0293   2.5443   2.8643
## 374 201102     5.1092   5.3242     5.6043   2.5012   4.4024   4.5472
## 375 201103     3.3512   2.8300     1.4611   0.1939   1.3976  -1.5739
## 376 201104     3.2949   2.1079     1.0561   3.7506   2.7078   1.1332
## 377 201105    -1.3995  -2.1296    -3.1974  -0.5623  -1.3945  -3.0000
## 378 201106    -1.7937  -2.1296    -1.8913  -1.4636  -1.7685  -2.2103
## 379 201107    -4.5512  -3.9686    -3.0352  -0.7561  -2.9443  -4.0590
## 380 201108    -9.3859  -8.8784    -9.7399  -3.9976  -6.4878  -8.3585
## 381 201109   -11.1072 -11.4956   -10.8019  -6.3705  -6.9662 -10.1269
## 382 201110    15.6731  15.5059    13.1351   9.8325  12.0524  12.5813
## 383 201111    -1.8459  -0.2643    -0.1686  -0.0524   0.9022  -2.6363
## 384 201112    -0.5648   0.7812     1.1746  -0.1342   1.9194   1.3800
## 385 201201     8.2697   6.8063     5.8503   5.4881   3.3587   5.9724
## 386 201202     3.4330   2.3748     2.9373   4.6300   3.6923   5.9852
## 387 201203     2.4252   2.8281     3.0831   3.6960   1.2495   5.3242
## 388 201204    -1.4498  -2.0557    -0.9131  -0.4648  -0.1512  -2.5525
## 389 201205    -6.5426  -6.3568    -6.2397  -5.4838  -5.9420  -7.9175
## 390 201206     5.7113   4.2133     4.7887   2.9353   4.6708   5.0942
## 391 201207    -3.3857  -0.8420    -1.7068   1.2935   1.4434  -0.4303
## 392 201208     3.2884   3.1286     3.7404   2.3725   1.8713   4.5117
## 393 201209     3.2688   3.5176     4.1139   1.9087   3.2017   4.2734
## 394 201210    -4.0430  -1.3322    -0.8733  -2.4805  -1.8315   1.5199
## 395 201211     1.0919   1.0314     0.8674   1.1244   0.3005  -0.3317
## 396 201212     2.6308   3.4715     4.4199  -0.1907   1.2208   5.0406
## 397 201301     6.8825   6.3575     5.8106   4.4787   6.0958   7.4690
## 398 201302     1.0361   0.8591     1.3242   1.3647   1.3768   1.3000
## 399 201303     5.1794   4.5401     4.5439   3.7607   4.0516   4.0252
## 400 201304    -0.7799  -0.8766    -0.1701   1.8584   1.2847   2.1417
## 401 201305     5.0181   5.3202     5.1990   1.9508   1.4377   7.0326
## 402 201306    -0.2285   0.3531    -0.1188  -1.7702  -0.3864  -1.8251
## 403 201307     7.3800   7.1582     7.8817   5.6309   4.8920   6.2744
## 404 201308    -1.0563  -3.5344    -3.8395  -1.7433  -3.1653  -4.3434
## 405 201309     6.3876   6.2537     5.6102   4.0527   3.1904   2.3976
## 406 201310     1.0547   3.1436     3.9460   4.1757   4.7556   3.7778
## 407 201311     5.2474   3.9232     4.5237   3.2912   1.8741   4.6570
## 408 201312     1.8901   2.7539     1.8888   2.1376   3.7106   2.0897
## 409 201401    -0.1005  -4.1373    -3.6886  -3.3492  -3.3583  -3.8951
## 410 201402     4.0185   4.7223     5.1966   5.0204   4.6768   3.2149
## 411 201403    -3.4318   1.3038     1.3785  -0.5888   0.7922   4.4634
## 412 201404    -6.3726  -3.0373    -2.7400   0.3706   0.9417  -0.9228
## 413 201405    -0.6871   0.8394     0.0861   2.4590   2.0113   1.4194
## 414 201406     7.1987   5.0731     4.4407   1.6430   2.8017   3.0089
## 415 201407    -6.4083  -6.3564    -5.4594  -1.4006  -1.6522  -2.2657
## 416 201408     5.0677   4.0537     4.5295   4.7978   3.2260   4.4380
## 417 201409    -4.7034  -5.2698    -6.4390  -0.9312  -2.4773  -1.9052
## 418 201410     7.4874   5.8190     5.2151   2.8233   1.5928   1.4990
## 419 201411     1.7998  -0.2640    -1.0665   3.7087   2.5528   0.3802
## 420 201412     2.0810   2.8713     3.2662  -1.3474   0.1043   2.0002
## 421 201501    -2.8534  -4.9049    -5.1879  -1.5607  -3.2987  -6.3993
## 422 201502     7.6765   7.0046     5.0056   6.4876   5.8840   5.4379
## 423 201503     2.0609   1.8086     1.1345  -1.3767  -1.5381  -1.2115
## 424 201504    -3.2016  -2.1341    -0.7281   0.3415   1.2764   1.5106
## 425 201505     2.9169   2.7074     0.8810   1.2186   1.5029   0.9607
## 426 201506     2.7242   0.3338     0.6035  -1.8323  -1.9434  -1.2916
## 427 201507    -0.2299  -2.3624    -5.6037   2.9657   1.2570   0.0800
## 428 201508    -9.3032  -4.7374    -3.3404  -6.1721  -5.6180  -6.5880
## 429 201509    -7.8251  -4.6104    -4.7172  -2.2242  -2.8566  -4.2145
## 430 201510     5.0061   6.4663     5.7017   8.0276   8.4164   6.4103
## 431 201511     5.6571   3.3772     3.6571   0.5054  -0.2685   1.6709
## 432 201512    -3.8734  -4.9903    -6.8243  -1.3060  -2.2722  -3.5730
## 433 201601   -14.1147  -7.6824    -6.9269  -5.1637  -5.1326  -8.1763
## 434 201602    -0.7099   0.9697     0.3780   0.0215   0.6254  -2.2142
## 435 201603     7.7058   7.8565     8.4662   6.5760   6.7935   8.2047
## 436 201604     2.6434   1.1620     3.8478  -0.6295   1.2854   4.7317
## 437 201605     2.3290   1.2799     0.5247   2.1877   1.7826   0.6654
## 438 201606     0.2961  -0.4164    -0.0412   0.0131   0.5954  -2.6015
## 439 201607     7.0391   5.6284     5.6740   4.9510   2.2505   3.6762
## 440 201608     1.3009   2.6586     3.2507  -0.5452   0.4159   3.8652
## 441 201609     3.2742   1.3322     1.6892   0.4472  -0.0784  -0.4406
## 442 201610    -8.1473  -5.1409    -3.0228  -1.9605  -2.2550   1.0938
## 443 201611     9.1400  12.5651    14.9658   1.9430   5.0565  12.5388
## 444 201612    -0.4427   2.9047     4.4845   1.3517   1.8021   3.4784
## 445 201701     1.9775  -0.1849    -0.7168   3.2210   1.0026   0.4064
## 446 201702     3.3431   1.1594     0.2891   4.2757   2.6548   3.9975
## 447 201703     2.3122   0.0705    -0.6854   1.1103  -0.2497  -2.5873
## 448 201704     1.9398   1.4351     0.6314   2.0535   0.6725  -0.8974
## 449 201705    -0.8419  -1.6384    -3.8611   2.8958   0.1204  -1.6445
## 450 201706     4.8044   3.1399     3.4308  -0.1294   0.5599   4.2068
## 451 201707     0.7584   0.5109     0.4881   2.4781   1.6575   2.1367
## 452 201708    -0.6147  -2.0376    -2.3459   1.2965  -0.1186  -1.1635
## 453 201709     5.4328   8.3527     8.3274   1.3548   2.6473   4.7097
## 454 201710     0.3610   0.3246     1.0050   3.1219   1.5413   2.8620
## 455 201711     2.7001   2.7212     2.7554   3.3234   3.2685   3.2153
## 456 201712     0.8678  -0.7691     0.0149   0.9718   1.1421   1.9459
## 457 201801     3.1386   2.9959     1.8416   6.4966   5.6052   5.2253
## 458 201802    -3.0811  -3.7637    -3.7139  -2.5784  -4.7349  -4.0181
## 459 201803     1.3875   0.9719     1.9354  -2.3638  -2.2034  -3.3156
## 460 201804     1.2044   1.0672     2.4007   0.6196   0.1555   0.5007
## 461 201805     8.0057   7.5384     5.6984   3.8336   1.9238  -0.2962
## 462 201806     2.8843   0.2033     0.6187   1.0924   0.4914  -1.2985
## 463 201807     1.4298   2.1783     1.0524   3.3424   3.3649   4.6186
## 464 201808     5.7090   3.3666     2.2897   5.3918   1.7127   0.8061
## 465 201809    -1.7387  -2.7490    -2.8453   0.5834   0.6728  -1.7224
## 466 201810   -13.3209 -11.4005    -9.1791  -8.1926  -5.9586  -5.5280
## 467 201811     1.0437   2.1254     0.8349   1.4792   2.2986   2.2556
## 468 201812   -12.0918 -11.9107   -12.6489  -8.3897  -9.5705 -11.5847