Figure-Eight-Knots


2.0 Correlation

As a first step, let’s use the contigency table we built to evaluate which marks are most typical to identify summand ranges in an Ascher sum.

2.1 Left-Handed 8-Knot Summand Marker Correlation Coefficients

Using the R language/data-science tools, we can develop a crosstab of correlation coefficients:

Code
```{python}
""" This is R Code. Extracted from R environment

library(tidyverse)
library(corrplot)
library(Hmisc)

readRenviron("~/.Renviron")
k_LOOM_DIR <- Sys.getenv("LOOM_DIR")
k_FIELDMARKS_DATA_DIR <- paste(k_LOOM_DIR, "/data/FIELDMARKS/CSV", sep='')
setwd(k_FIELDMARKS_DATA_DIR)

plot_correlation_df <- function(aDF, aTitle, aCSVFilename) {
  precorrelation_df <-  select(aDF, -kfg_name) 
  
  the_cor_data  <-  cor(precorrelation_df, method="spearman")
  the_cor_data.tbl <- tibble(the_cor_data)
  write.csv(the_cor_data.tbl, file=aCSVFilename)
  
  corrplot(the_cor_data, method="ellipse", title=paste("\n\n",aTitle))
  }

plot_correlation_df(left_handed_eightknotsums_df, "Left-Handed Sums Marked by 8Knot Cords", "eightknotsums_left_handed_correlation.csv")
plot_correlation_df(right_handed_eightknotsums_df, "Right-Handed Sums Marked by 8Knot Cords", "eightknotsums_right_handed_correlation.csv")

""";
```
Code
```{python}
import tabulate
def clean_name(df):
    for old_column_name in df.columns:
        new_column_name = old_column_name.replace("the_cor_data.", "")  
        df = df.rename(columns={old_column_name: new_column_name})
    return df

def print_names(df):
    for old_column_name in df.columns:
        new_column_name = old_column_name.replace("_", " ").replace("num", "#").title()
        df = df.rename(columns={old_column_name: new_column_name})
    return df

def remove_totals(df):
    """ Remove the totals column from a correlation matrix """
    drop_columns = [column_name for column_name in df.columns if column_name.startswith("total")]
    for column_name in drop_columns:
        df = df.drop(column_name, axis=1)    
    
    # Drop total rows
    df = df.drop(df.index[4:12])
    return df

def remove_detail(df):
    """ Remove the details columns from a correlation matrix """
    drop_columns = [column_name for column_name in df.columns if column_name.startswith("left") or column_name.startswith("right")]
    for column_name in drop_columns:
        df = df.drop(column_name, axis=1)   
    
    df = df[0:len(df.columns)-1]
    
    return df

left_handed_8knotsums_correlation_df = pd.read_csv(f"{uloc.fieldmarks_data_dir()}/eightknotsums_left_handed_correlation.csv")
right_handed_8knotsums_correlation_df = pd.read_csv(f"{uloc.fieldmarks_data_dir()}/eightknotsums_right_handed_correlation.csv")

do_print_totals = False
if do_print_totals:
    totals_left_handed_8knotsums_correlation_df = remove_detail(clean_name(left_handed_8knotsums_correlation_df))
    totals_left_handed_8knotsums_correlation_df = totals_left_handed_8knotsums_correlation_df.rename(columns={'Unnamed: 0': 'markers'})
    totals_left_handed_8knotsums_correlation_df = print_names(totals_left_handed_8knotsums_correlation_df)
    totals_left_handed_8knotsums_correlation_df['Markers'] = totals_left_handed_8knotsums_correlation_df.columns[1:]

    totals_right_handed_8knotsums_correlation_df = remove_detail(clean_name(right_handed_8knotsums_correlation_df))
    totals_right_handed_8knotsums_correlation_df = totals_right_handed_8knotsums_correlation_df.rename(columns={'Unnamed: 0': 'markers'})
    totals_right_handed_8knotsums_correlation_df = print_names(totals_right_handed_8knotsums_correlation_df)
    totals_right_handed_8knotsums_correlation_df['Markers'] = totals_right_handed_8knotsums_correlation_df.columns[1:]

    print("\nLeft-Handed 8Knot Sum Totals Correlation:")
    print(  "=========================================\n")
    print(tabulate.tabulate(totals_left_handed_8knotsums_correlation_df, headers='keys', tablefmt='html')    )
    print("\nRight-Handed 8Knot Sum Totals Correlation:")
    print(  "==========================================\n")
    print(tabulate.tabulate(totals_right_handed_8knotsums_correlation_df, headers='keys', tablefmt='html')    )

do_print_details = False
if do_print_details:
    details_left_handed_8knotsums_correlation_df = remove_totals(clean_name(left_handed_8knotsums_correlation_df))
    details_left_handed_8knotsums_correlation_df = details_left_handed_8knotsums_correlation_df.rename(columns={'Unnamed: 0': 'markers'})
    details_left_handed_8knotsums_correlation_df = print_names(details_left_handed_8knotsums_correlation_df)
    details_left_handed_8knotsums_correlation_df['Markers'] = details_left_handed_8knotsums_correlation_df.columns[1:]


    details_right_handed_8knotsums_correlation_df = remove_totals(clean_name(right_handed_8knotsums_correlation_df))
    details_right_handed_8knotsums_correlation_df = details_right_handed_8knotsums_correlation_df.rename(columns={'Unnamed: 0': 'markers'})
    details_right_handed_8knotsums_correlation_df = print_names(details_right_handed_8knotsums_correlation_df)
    details_right_handed_8knotsums_correlation_df['Markers'] = details_right_handed_8knotsums_correlation_df.columns[1:]

    print("\nLeft-Handed 8Knot Sum Details Correlation:")
    print(  "==========================================\n")
    print(tabulate.tabulate(details_left_handed_8knotsums_correlation_df, headers='keys', tablefmt='html'))
    print("\nRight-Handed 8Knot Sum Details Correlation:")
    print(  "===========================================\n")
    print(tabulate.tabulate(details_right_handed_8knotsums_correlation_df, headers='keys', tablefmt='html'))  
```

2.1 Correlation for Left-Handed 8Knot Sums

Click on image to view larger
Correlation of Left-Handed Sums Marked by 8Knot Cords

2.1.1 Totals Correlation Matrix for Left-Handed 8Knot Sums

Markers # Ascher Sums # Pps Sums # Cps Sums # Ips Sums Total 8Knot Cords Total Sum8Knots Total Sole8Knots Total Trailing8Knots Total Exact Sole8Knots Total Exact Trailing8Knots Total Close Sole8Knots Total Close Trailing8Knots
0 # Ascher Sums 1 0.948807 0.742891 0.679007 0.570751 0.628623 0.505053 0.579329 0.485423 0.569114 0.503967 0.540172
1 # Pps Sums 0.948807 1 0.588574 0.593235 0.544039 0.594524 0.475439 0.588339 0.459165 0.564179 0.468157 0.558728
2 # Cps Sums 0.742891 0.588574 1 0.469379 0.532935 0.582093 0.483551 0.469604 0.458989 0.469438 0.47675 0.432925
3 # Ips Sums 0.679007 0.593235 0.469379 1 0.397665 0.431915 0.35567 0.388948 0.338436 0.384091 0.386655 0.371352
4 Total 8Knot Cords 0.570751 0.544039 0.532935 0.397665 1 0.861506 0.744322 0.649461 0.707029 0.62683 0.708696 0.577937
5 Total Sum8Knots 0.628623 0.594524 0.582093 0.431915 0.861506 1 0.900431 0.639022 0.835829 0.655497 0.857926 0.538485
6 Total Sole8Knots 0.505053 0.475439 0.483551 0.35567 0.744322 0.900431 1 0.399872 0.945118 0.389912 0.912097 0.361942
7 Total Trailing8Knots 0.579329 0.588339 0.469604 0.388948 0.649461 0.639022 0.399872 1 0.388338 0.903811 0.384371 0.893418
8 Total Exact Sole8Knots 0.485423 0.459165 0.458989 0.338436 0.707029 0.835829 0.945118 0.388338 1 0.391587 0.77947 0.339827
9 Total Exact Trailing8Knots 0.569114 0.564179 0.469438 0.384091 0.62683 0.655497 0.389912 0.903811 0.391587 1 0.360856 0.684955
10 Total Close Sole8Knots 0.503967 0.468157 0.47675 0.386655 0.708696 0.857926 0.912097 0.384371 0.77947 0.360856 1 0.362621
11 Total Close Trailing8Knots 0.540172 0.558728 0.432925 0.371352 0.577937 0.538485 0.361942 0.893418 0.339827 0.684955 0.362621 1

2.1.2 Details Correlation Matrix for Left-Handed 8Knot Sums

Markers # Ascher Sums # Pps Sums # Cps Sums # Ips Sums Left Exact Pendant 8Knot Cord Type Sole8Knot Left Exact Pendant 8Knot Cord Type Trailing8Knot Right Exact Pendant 8Knot Cord Type Sole8Knot Right Exact Pendant 8Knot Cord Type Trailing8Knot Left Exact Subsidiary 8Knot Cord Type Sole8Knot Left Exact Subsidiary 8Knot Cord Type Trailing8Knot Right Exact Subsidiary 8Knot Cord Type Sole8Knot Right Exact Subsidiary 8Knot Cord Type Trailing8Knot Left Close Pendant 8Knot Cord Type Sole8Knot Left Close Pendant 8Knot Cord Type Trailing8Knot Right Close Pendant 8Knot Cord Type Sole8Knot Right Close Pendant 8Knot Cord Type Trailing8Knot Left Close Subsidiary 8Knot Cord Type Sole8Knot Left Close Subsidiary 8Knot Cord Type Trailing8Knot Right Close Subsidiary 8Knot Cord Type Sole8Knot Right Close Subsidiary 8Knot Cord Type Trailing8Knot
0 # Ascher Sums 1 0.948807 0.742891 0.679007 0.41734 0.513025 0.427799 0.545608 0.363461 0.238475 0.395055 0.242144 0.378807 0.413304 0.369599 0.546995 0.41413 0.248631 0.369947 0.210695
1 # Pps Sums 0.948807 1 0.588574 0.593235 0.38125 0.517785 0.382904 0.529056 0.351608 0.245243 0.389071 0.239335 0.336569 0.431289 0.309897 0.563085 0.407803 0.231669 0.353896 0.217777
2 # Cps Sums 0.742891 0.588574 1 0.469379 0.416983 0.411542 0.46799 0.471311 0.349467 0.184721 0.337134 0.179364 0.391751 0.330903 0.430067 0.446049 0.342143 0.204782 0.319785 0.148004
3 # Ips Sums 0.679007 0.593235 0.469379 1 0.284562 0.362618 0.302116 0.39742 0.225712 0.132278 0.271894 0.172722 0.327295 0.270626 0.284538 0.385501 0.326215 0.181261 0.26559 0.171859
12 Left Exact Pendant 8Knot Cord Type Sole8Knot 0.41734 0.38125 0.416983 0.284562 1 0.214084 0.688097 0.246541 0.375901 0.0457201 0.360164 0.0878349 0.703917 0.182259 0.502263 0.208521 0.303417 0.0572445 0.308434 0.0547797
13 Left Exact Pendant 8Knot Cord Type Trailing8Knot 0.513025 0.517785 0.411542 0.362618 0.214084 1 0.245139 0.639403 0.279633 0.24995 0.342603 0.254849 0.20946 0.53409 0.145712 0.538393 0.270505 0.30012 0.301544 0.222699
14 Right Exact Pendant 8Knot Cord Type Sole8Knot 0.427799 0.382904 0.46799 0.302116 0.688097 0.245139 1 0.237838 0.36745 0.0967522 0.331345 0.100344 0.603116 0.195804 0.652987 0.247054 0.342444 0.116278 0.315668 0.0933847
15 Right Exact Pendant 8Knot Cord Type Trailing8Knot 0.545608 0.529056 0.471311 0.39742 0.246541 0.639403 0.237838 1 0.283334 0.22287 0.385689 0.259653 0.221541 0.446826 0.13447 0.595174 0.333079 0.292786 0.261043 0.27072
16 Left Exact Subsidiary 8Knot Cord Type Sole8Knot 0.363461 0.351608 0.349467 0.225712 0.375901 0.279633 0.36745 0.283334 1 0.268888 0.685392 0.281259 0.326636 0.177943 0.301021 0.257645 0.647528 0.168586 0.62934 0.296692
17 Left Exact Subsidiary 8Knot Cord Type Trailing8Knot 0.238475 0.245243 0.184721 0.132278 0.0457201 0.24995 0.0967522 0.22287 0.268888 1 0.15891 0.552854 0.0136631 0.234946 0.0178539 0.25461 0.190897 0.367369 0.157244 0.527578
18 Right Exact Subsidiary 8Knot Cord Type Sole8Knot 0.395055 0.389071 0.337134 0.271894 0.360164 0.342603 0.331345 0.385689 0.685392 0.15891 1 0.292359 0.356131 0.249186 0.272893 0.332134 0.59031 0.24276 0.695243 0.29347
19 Right Exact Subsidiary 8Knot Cord Type Trailing8Knot 0.242144 0.239335 0.179364 0.172722 0.0878349 0.254849 0.100344 0.259653 0.281259 0.552854 0.292359 1 0.0929279 0.208627 0.0452505 0.271329 0.227464 0.482741 0.23339 0.61148
20 Left Close Pendant 8Knot Cord Type Sole8Knot 0.378807 0.336569 0.391751 0.327295 0.703917 0.20946 0.603116 0.221541 0.326636 0.0136631 0.356131 0.0929279 1 0.126613 0.575509 0.170884 0.338788 0.12239 0.33364 0.0611192
21 Left Close Pendant 8Knot Cord Type Trailing8Knot 0.413304 0.431289 0.330903 0.270626 0.182259 0.53409 0.195804 0.446826 0.177943 0.234946 0.249186 0.208627 0.126613 1 0.122714 0.490765 0.251387 0.199824 0.274054 0.252267
22 Right Close Pendant 8Knot Cord Type Sole8Knot 0.369599 0.309897 0.430067 0.284538 0.502263 0.145712 0.652987 0.13447 0.301021 0.0178539 0.272893 0.0452505 0.575509 0.122714 1 0.138937 0.297894 0.0786808 0.275281 0.0889176
23 Right Close Pendant 8Knot Cord Type Trailing8Knot 0.546995 0.563085 0.446049 0.385501 0.208521 0.538393 0.247054 0.595174 0.257645 0.25461 0.332134 0.271329 0.170884 0.490765 0.138937 1 0.357727 0.328861 0.319765 0.206607
24 Left Close Subsidiary 8Knot Cord Type Sole8Knot 0.41413 0.407803 0.342143 0.326215 0.303417 0.270505 0.342444 0.333079 0.647528 0.190897 0.59031 0.227464 0.338788 0.251387 0.297894 0.357727 1 0.228697 0.59576 0.312794
25 Left Close Subsidiary 8Knot Cord Type Trailing8Knot 0.248631 0.231669 0.204782 0.181261 0.0572445 0.30012 0.116278 0.292786 0.168586 0.367369 0.24276 0.482741 0.12239 0.199824 0.0786808 0.328861 0.228697 1 0.182084 0.385694
26 Right Close Subsidiary 8Knot Cord Type Sole8Knot 0.369947 0.353896 0.319785 0.26559 0.308434 0.301544 0.315668 0.261043 0.62934 0.157244 0.695243 0.23339 0.33364 0.274054 0.275281 0.319765 0.59576 0.182084 1 0.271141
27 Right Close Subsidiary 8Knot Cord Type Trailing8Knot 0.210695 0.217777 0.148004 0.171859 0.0547797 0.222699 0.0933847 0.27072 0.296692 0.527578 0.29347 0.61148 0.0611192 0.252267 0.0889176 0.206607 0.312794 0.385694 0.271141 1

2.2 Right-Handed 8-Knot Summand Marker Correlation Coefficients

Click on image to view larger
Correlation of Right-Handed Sums Marked by 8Knot Cords

2.2.1 Totals Correlation Matrix for Right-Handed 8Knot Sums

Markers # Ascher Sums # Pps Sums # Cps Sums # Ips Sums Total 8Knot Cords Total Sum8Knots Total Sole8Knots Total Trailing8Knots Total Exact Sole8Knots Total Exact Trailing8Knots Total Close Sole8Knots Total Close Trailing8Knots
0 # Ascher Sums 1 0.939332 0.800366 0.713307 0.573015 0.664177 0.509671 0.621999 0.532267 0.632791 0.507827 0.568578
1 # Pps Sums 0.939332 1 0.655455 0.598529 0.53477 0.620943 0.477433 0.605176 0.500382 0.610611 0.47216 0.561434
2 # Cps Sums 0.800366 0.655455 1 0.527032 0.549278 0.59831 0.475298 0.536619 0.493177 0.539519 0.472877 0.491748
3 # Ips Sums 0.713307 0.598529 0.527032 1 0.436404 0.492266 0.355097 0.495715 0.366676 0.503991 0.369016 0.447228
4 Total 8Knot Cords 0.573015 0.53477 0.549278 0.436404 1 0.880645 0.763182 0.637174 0.760499 0.624552 0.727233 0.574227
5 Total Sum8Knots 0.664177 0.620943 0.59831 0.492266 0.880645 1 0.875236 0.65349 0.846803 0.685631 0.854764 0.551337
6 Total Sole8Knots 0.509671 0.477433 0.475298 0.355097 0.763182 0.875236 1 0.372837 0.968696 0.373629 0.943621 0.332265
7 Total Trailing8Knots 0.621999 0.605176 0.536619 0.495715 0.637174 0.65349 0.372837 1 0.38226 0.912383 0.375496 0.904691
8 Total Exact Sole8Knots 0.532267 0.500382 0.493177 0.366676 0.760499 0.846803 0.968696 0.38226 1 0.39136 0.867862 0.338447
9 Total Exact Trailing8Knots 0.632791 0.610611 0.539519 0.503991 0.624552 0.685631 0.373629 0.912383 0.39136 1 0.377167 0.727431
10 Total Close Sole8Knots 0.507827 0.47216 0.472877 0.369016 0.727233 0.854764 0.943621 0.375496 0.867862 0.377167 1 0.328479
11 Total Close Trailing8Knots 0.568578 0.561434 0.491748 0.447228 0.574227 0.551337 0.332265 0.904691 0.338447 0.727431 0.328479 1

2.2.2 Details Correlation Matrix for Right-Handed 8Knot Sums

Markers # Ascher Sums # Pps Sums # Cps Sums # Ips Sums Left Exact Pendant 8Knot Cord Type Sole8Knot Left Exact Pendant 8Knot Cord Type Trailing8Knot Right Exact Pendant 8Knot Cord Type Sole8Knot Right Exact Pendant 8Knot Cord Type Trailing8Knot Left Exact Subsidiary 8Knot Cord Type Sole8Knot Left Exact Subsidiary 8Knot Cord Type Trailing8Knot Right Exact Subsidiary 8Knot Cord Type Sole8Knot Right Exact Subsidiary 8Knot Cord Type Trailing8Knot Left Close Pendant 8Knot Cord Type Sole8Knot Left Close Pendant 8Knot Cord Type Trailing8Knot Right Close Pendant 8Knot Cord Type Sole8Knot Right Close Pendant 8Knot Cord Type Trailing8Knot Left Close Subsidiary 8Knot Cord Type Sole8Knot Left Close Subsidiary 8Knot Cord Type Trailing8Knot Right Close Subsidiary 8Knot Cord Type Sole8Knot Right Close Subsidiary 8Knot Cord Type Trailing8Knot
0 # Ascher Sums 1 0.939332 0.800366 0.713307 0.399687 0.604616 0.44337 0.591881 0.372098 0.236934 0.397923 0.272567 0.387249 0.539967 0.395177 0.523485 0.398641 0.306553 0.408651 0.235105
1 # Pps Sums 0.939332 1 0.655455 0.598529 0.402435 0.583419 0.422585 0.586111 0.329716 0.229645 0.355146 0.263212 0.375652 0.533139 0.361325 0.524896 0.386428 0.286542 0.359598 0.219833
2 # Cps Sums 0.800366 0.655455 1 0.527032 0.37661 0.522281 0.423763 0.510917 0.356355 0.197998 0.395577 0.240902 0.380441 0.47233 0.405324 0.445796 0.364102 0.275713 0.413595 0.220166
3 # Ips Sums 0.713307 0.598529 0.527032 1 0.249146 0.490033 0.337277 0.462593 0.309 0.218203 0.279618 0.195836 0.300178 0.394717 0.289449 0.42989 0.288791 0.260018 0.312279 0.195163
12 Left Exact Pendant 8Knot Cord Type Sole8Knot 0.399687 0.402435 0.37661 0.249146 1 0.178685 0.648193 0.209645 0.283104 0.0124537 0.337608 -0.0148578 0.738293 0.195852 0.610128 0.15968 0.370028 0.012975 0.314333 0.0148751
13 Left Exact Pendant 8Knot Cord Type Trailing8Knot 0.604616 0.583419 0.522281 0.490033 0.178685 1 0.271785 0.697343 0.287746 0.228418 0.283734 0.312874 0.216206 0.668737 0.210201 0.577349 0.287554 0.328771 0.275379 0.277126
14 Right Exact Pendant 8Knot Cord Type Sole8Knot 0.44337 0.422585 0.423763 0.337277 0.648193 0.271785 1 0.271077 0.365724 0.0592264 0.381023 0.0505534 0.679436 0.240034 0.715463 0.191983 0.430866 0.135784 0.396913 0.082391
15 Right Exact Pendant 8Knot Cord Type Trailing8Knot 0.591881 0.586111 0.510917 0.462593 0.209645 0.697343 0.271077 1 0.317658 0.24441 0.302013 0.357137 0.232217 0.602267 0.181283 0.638875 0.314117 0.379622 0.325728 0.308684
16 Left Exact Subsidiary 8Knot Cord Type Sole8Knot 0.372098 0.329716 0.356355 0.309 0.283104 0.287746 0.365724 0.317658 1 0.310723 0.712757 0.269956 0.314619 0.253967 0.361568 0.190594 0.692194 0.304425 0.702125 0.285374
17 Left Exact Subsidiary 8Knot Cord Type Trailing8Knot 0.236934 0.229645 0.197998 0.218203 0.0124537 0.228418 0.0592264 0.24441 0.310723 1 0.303167 0.664067 -0.0186791 0.259496 0.00223261 0.248021 0.308222 0.588608 0.276163 0.583068
18 Right Exact Subsidiary 8Knot Cord Type Sole8Knot 0.397923 0.355146 0.395577 0.279618 0.337608 0.283734 0.381023 0.302013 0.712757 0.303167 1 0.257631 0.36188 0.265124 0.372944 0.249857 0.698246 0.296793 0.714776 0.20677
19 Right Exact Subsidiary 8Knot Cord Type Trailing8Knot 0.272567 0.263212 0.240902 0.195836 -0.0148578 0.312874 0.0505534 0.357137 0.269956 0.664067 0.257631 1 0.0312377 0.322955 0.0425252 0.33746 0.252457 0.685554 0.260263 0.694134
20 Left Close Pendant 8Knot Cord Type Sole8Knot 0.387249 0.375652 0.380441 0.300178 0.738293 0.216206 0.679436 0.232217 0.314619 -0.0186791 0.36188 0.0312377 1 0.149124 0.643274 0.156699 0.341948 0.034155 0.329152 0.0292368
21 Left Close Pendant 8Knot Cord Type Trailing8Knot 0.539967 0.533139 0.47233 0.394717 0.195852 0.668737 0.240034 0.602267 0.253967 0.259496 0.265124 0.322955 0.149124 1 0.192524 0.589833 0.238974 0.350788 0.309794 0.263385
22 Right Close Pendant 8Knot Cord Type Sole8Knot 0.395177 0.361325 0.405324 0.289449 0.610128 0.210201 0.715463 0.181283 0.361568 0.00223261 0.372944 0.0425252 0.643274 0.192524 1 0.132001 0.362932 0.0687638 0.372978 0.0527134
23 Right Close Pendant 8Knot Cord Type Trailing8Knot 0.523485 0.524896 0.445796 0.42989 0.15968 0.577349 0.191983 0.638875 0.190594 0.248021 0.249857 0.33746 0.156699 0.589833 0.132001 1 0.238546 0.361342 0.311055 0.261411
24 Left Close Subsidiary 8Knot Cord Type Sole8Knot 0.398641 0.386428 0.364102 0.288791 0.370028 0.287554 0.430866 0.314117 0.692194 0.308222 0.698246 0.252457 0.341948 0.238974 0.362932 0.238546 1 0.322512 0.734032 0.273338
25 Left Close Subsidiary 8Knot Cord Type Trailing8Knot 0.306553 0.286542 0.275713 0.260018 0.012975 0.328771 0.135784 0.379622 0.304425 0.588608 0.296793 0.685554 0.034155 0.350788 0.0687638 0.361342 0.322512 1 0.292727 0.715569
26 Right Close Subsidiary 8Knot Cord Type Sole8Knot 0.408651 0.359598 0.413595 0.312279 0.314333 0.275379 0.396913 0.325728 0.702125 0.276163 0.714776 0.260263 0.329152 0.309794 0.372978 0.311055 0.734032 0.292727 1 0.249226
27 Right Close Subsidiary 8Knot Cord Type Trailing8Knot 0.235105 0.219833 0.220166 0.195163 0.0148751 0.277126 0.082391 0.308684 0.285374 0.583068 0.20677 0.694134 0.0292368 0.263385 0.0527134 0.261411 0.273338 0.715569 0.249226 1

3.0 Chi-squared test between Basic Ascher Sums and Figure 8 Knot Cords

Code
```{python}
from scipy.stats import chi2_contingency

def perform_chi_squared_8knot_test(df):
    chi_sq_input_df = df[['num_ascher_sums', 'total_sum8knots', 'total_sole8knots', 'total_trailing8knots']]
    chi_sq_input_df = chi_sq_input_df[chi_sq_input_df['num_ascher_sums'] > 0]
    
    # Perform chi-squared test
    chi2, p, dof, expected = chi2_contingency(chi_sq_input_df)

    # Print the results
    print(f"p-value: {p:e}")
    return chi_sq_input_df

print("\nChi-squared  p values for Left-Handed 8Knot Sums")
print(  "================================================")
left_chi_sq_df = perform_chi_squared_8knot_test(left_handed_eightknotsums_df)

print("\nChi-squared  p values for Right-Handed 8Knot Sums")
print(  "=================================================")
right_chi_sq_df = perform_chi_squared_8knot_test(right_handed_eightknotsums_df)
```

Chi-squared  p values for Left-Handed 8Knot Sums
================================================
p-value: 0.000000e+00

Chi-squared  p values for Right-Handed 8Knot Sums
=================================================
p-value: 0.000000e+00
Code
```{python}
print("Left-Handed Chi-Squared Input Data:")
left_chi_sq_df.head(5)
```
Left-Handed Chi-Squared Input Data:
num_ascher_sums total_sum8knots total_sole8knots total_trailing8knots
0 6 3 2 3
1 1 1 1 1
2 1 0 0 0
3 4 10 7 4
4 6 4 3 2
Code
```{python}
print("Right-Handed Chi-Squared Input Data:")
right_chi_sq_df.head(5)
```
Right-Handed Chi-Squared Input Data:
num_ascher_sums total_sum8knots total_sole8knots total_trailing8knots
0 1 0 0 0
1 5 0 0 0
2 2 7 5 2
3 3 9 5 1
4 70 97 59 7

4.0 Angle Between Pendant Ascher Sums vs. Figure-8-Knot Markers

What is the vector angle between pendant Ascher sums, and the various figure-eight-knot markers (i.e. how closely do they match?)

Code
```{python}
print(f"Angle between num_pendant_ascher_sums and:")
for i in range(2, len(all_eightknotsums_df.columns)):
    print(f"\t{all_eightknotsums_df.columns[i]}: {uloom.degrees_between(all_eightknotsums_df['num_ascher_sums'].to_list(), all_eightknotsums_df[all_eightknotsums_df.columns[i]].to_list()):.1f}°")

```
Angle between num_pendant_ascher_sums and:
    num_pps_sums: 18.1°
    num_cps_sums: 23.5°
    num_ips_sums: 31.1°
    total_8knot_cords: 49.3°
    total_sum8knots: 44.5°
    total_sole8knots: 49.1°
    total_trailing8knots: 42.1°
    total_exact_sole8knots: 45.4°
    total_exact_trailing8knots: 39.6°
    total_close_sole8knots: 54.5°
    total_close_trailing8knots: 48.1°
    left_exact_pendant_8knot_cord_type_sole8knot: 45.8°
    left_exact_pendant_8knot_cord_type_trailing8knot: 42.5°
    right_exact_pendant_8knot_cord_type_sole8knot: 48.4°
    right_exact_pendant_8knot_cord_type_trailing8knot: 39.4°
    left_exact_subsidiary_8knot_cord_type_sole8knot: 64.6°
    left_exact_subsidiary_8knot_cord_type_trailing8knot: 65.1°
    right_exact_subsidiary_8knot_cord_type_sole8knot: 61.2°
    right_exact_subsidiary_8knot_cord_type_trailing8knot: 67.4°
    left_close_pendant_8knot_cord_type_sole8knot: 57.1°
    left_close_pendant_8knot_cord_type_trailing8knot: 49.4°
    right_close_pendant_8knot_cord_type_sole8knot: 59.7°
    right_close_pendant_8knot_cord_type_trailing8knot: 49.6°
    left_close_subsidiary_8knot_cord_type_sole8knot: 63.6°
    left_close_subsidiary_8knot_cord_type_trailing8knot: 70.8°
    right_close_subsidiary_8knot_cord_type_sole8knot: 62.6°
    right_close_subsidiary_8knot_cord_type_trailing8knot: 69.3°
    num_total_cords: 39.6°
    num_pendant_cords: 33.2°

5.0 Figure-8-Knot Cords Marking Sums vs Sums Marked by Figure-8-Knot Cords.

There is a difference between:

  • The number of 8 knot cords that mark an ascher sum and
  • The number of ascher sums marked by an eight knot cord

The reason is that we allow ascher sums to be marked by neighboring cords, as well as the left and right edges of the summand range. Consequently one cord can serve as a left-edge summand marker, and a close right-edge of a previous summand range. A similar duplicity exists for right/left summand ranges. For example, in KH0696, pendant p24 marks an exact sum relationship with p38, and a left close relationship with sum cord p35. In the figure8 knot dataframe we mark this as figure8knot p24 matches with p38, and leave it at that, ignoring p35. But in the Ascher sum dataframe we record both.

Code
```{python}
aDF=pendant_ascher_sums_df    
khipu_df = aDF[aDF['kfg_name']=='AK001'].fillna('')
khipu_df = khipu_df[khipu_df['has_figure8knot_indicator']==True]
print("Sums with a Figure 8 Knot Indicator for AK001")
khipu_df.head(10)
```
Sums with a Figure 8 Knot Indicator for AK001
kfg_name cord_name cord_index cord_value cord_color num_summands handedness has_figure8knot_indicator has_left_exact_8knot_cord has_right_exact_8knot_cord ... summand_string sum_type left_exact_pendant_8knot_cord_type right_exact_pendant_8knot_cord_type left_exact_subsidiary_8knot_cord_type right_exact_subsidiary_8knot_cord_type left_close_pendant_8knot_cord_type right_close_pendant_8knot_cord_type left_close_subsidiary_8knot_cord_type right_close_subsidiary_8knot_cord_type
0 AK001 p24 [2, 0] 11 W 3 -2 True False False ... W:YB:G@[1, 5]:4 + AB@[1, 6]:4 + AB@[1, 7]:3 pendant_pendant_sum trailing_8knot
1 AK001 p33 [4, 0] 68 W 14 -8 True True False ... W:YB:G@[1, 2]:1 + W:YB:G@[1, 3]:9 + W:YB:G@[1,... pendant_pendant_sum sole_8knot
3 AK001 p35 [4, 2] 33 YB 7 -7 True False False ... W@[2, 1]:9 + W@[2, 2]:7 + W@[2, 3]:2 + W@[2, 4... pendant_pendant_sum trailing_8knot
4 AK001 p37 [4, 4] 27 W:YB:G 3 -12 True True False ... W@[2, 0]:11 + W@[2, 1]:9 + W@[2, 2]:7 pendant_pendant_sum trailing_8knot
5 AK001 p38 [4, 5] 13 W:YB 3 -9 True True False ... W@[2, 4]:1 + AB@[2, 5]:4 + AB@[2, 6]:8 pendant_pendant_sum sole_8knot

5 rows × 31 columns

Code
```{python}
aKFGName = 'AK001'
from fieldmark_figure8knots import FieldmarkFigure8Knots
figure8knot_fieldmark = FieldmarkFigure8Knots()  
aDF = figure8knot_fieldmark.relations_df()
khipu_df = aDF[aDF['kfg_name']==aKFGName].fillna('')
khipu_df = khipu_df[khipu_df['sum_type'].str.len() > 0]

print("Figure 8 Knot Cords with Sum Indicators for AK001")
khipu_df.head(10)
```
Figure 8 Knot Cords with Sum Indicators for AK001
kfg_name cord_name cord_value cord_color eight_knot_type is_subsidiary is_sum_match sum_type handedness sum_cord_name num_summands is_edge_match is_neighbor_match match_side is_parity_bit summand_string
0 AK001 p18 1 W:YB:G sole_8knot False True pendant_pendant_sums left p33 14 True False left True p18 + p19 + p20 + p21 + p22 + p23 + p24 + p25 ...
1 AK001 p24 11 W trailing_8knot False True pendant_pendant_sums left p24 3 False True right False p21 + p22 + p23
2 AK001 p24 11 W trailing_8knot False True pendant_pendant_sums left p37 3 True False left False p24 + p25 + p26
3 AK001 p28 1 W sole_8knot False True pendant_pendant_sums left p38 3 True False left True p28 + p29 + p30

Appendix.

One question to ask is what if figure8knots occur over a khipu because of 1 being the last digit

We’ve already seen above that figure8knots are NOT uniformly distributed over a summand range, but instead bunched at the “edges”. If a khipu’s numbers are “randomly distributed” then there is a 1% chance of a sole 8 knot occuring every 100 cords. Clearly the frequency of sole 8 knot cords is not that:

Code
```{python}
from fieldmark_figure8knots import FieldmarkFigure8Knots
import utils_math as umath
figure8knot_fieldmark = FieldmarkFigure8Knots()
the_khipu_df = figure8knot_fieldmark.fieldmark_df()
eightknot_kfg_names = the_khipu_df['kfg_name'].to_list()
the_khipu_df.head()
```
kfg_name num_pendant_cords num_subsidiary_cords num_8knot_cords num_pendant_8knot_cords num_subsidiary_8knot_cords num_sole_8knot_cords num_pendant_sole_8_knot_cords num_subsidiary_sole_8_knot_cords num_trailing_8knot_cords num_pendant_trailing_8_knot_cords num_subsidiary_trailing_8_knot_cords num_ascher_sums num_8knot_sums sole_8knot_cord_positions trailing_8knot_cord_positions
0 AK001 38 1 3 3 0 2 2 0 1 1 0 7 4 p18, p28 p24
1 AK002 77 6 6 5 1 0 0 0 5 4 1 5 0 NaN p2, p27, p29s1, p37, p42
2 AS001 14 17 6 2 4 4 0 4 2 2 0 0 0 p1s1, p2s2, p10s1, p12s2 p7, p13
3 AS002 7 8 2 0 2 2 0 2 0 0 0 0 0 p1s1, p3s1 NaN
4 AS003 7 2 0 0 0 0 0 0 0 0 0 0 0 NaN NaN
Code
```{python}
num_pendant_cords = the_khipu_df['num_pendant_cords'].to_list()
num_sole_8knots = the_khipu_df['num_sole_8knot_cords'].to_list()
pct_sole_8knots = [round(100.0*float(num_sole_8knots[i])/float(num_pendant_cords[i]),1) for i in range(len(num_pendant_cords))]
pct_sole_8knots_df = pd.DataFrame({'kfg_name':eightknot_kfg_names, 'num_pendant_cords':num_pendant_cords, 'num_sole_8knots':num_sole_8knots, 'pct_sole_8knots':pct_sole_8knots}) 

import utils_math as umath
print("Statistics for % Sole 8 Knot Cords vs Pendant Cords")
print(umath.get_statistics(pct_sole_8knots))

fig = (px.scatter(pct_sole_8knots_df, 
                    x='num_pendant_cords',
                    y='num_sole_8knots', 
                    color='pct_sole_8knots', 
                    color_continuous_scale='Bluered_r', 
                    log_x=True, log_y=True,
                    title="By Khipu - # Pendant Cords vs # Sole 8 Knot Cords - Hover over Dot for Detail",
                    labels={'num_pendant_cords':'# Pendant Cords (Log scale)', 
                            'num_sole_8knots':'# Sole Figure-8-Knot Cords (Log scale)',
                            'pct_sole_8knots': '% Sole 8 Knot Cords vs Pendant Cords',
                            'kfg_name':'Khipu Name',
                            },
                    width=944, height=944,
                    trendline="ols",
                    hover_data=['num_pendant_cords', 'num_sole_8knots', 'pct_sole_8knots', 'kfg_name'])).show()

```
Statistics for % Sole 8 Knot Cords vs Pendant Cords
{'min': 0.0, 'mean': 14.603915662650602, 'median': 3.1500000000000004, 'max': 400.0, 'stddev': 31.583377881412815, 'range': 400.0, 'spread': 0.15791688940706408}

So clearly Sole8Knots are occuring at a much higher rate than 1% (14.6%!), with a trendline of 11%.

A similar line of reasoning can occur with trailing 8 knots. For example in 100 cords we have a 10% chance of getting cords that end with 1 (ie. 01,11,21,…91). Here we have to find trailing knot cords whose cord value ends in 1. (ie. the last eight knot is not added to the penultimate knot).

Code
```{python}
# Collect all trailing 8 knot cords which end in a 1 digit
the_8knotcords_df = figure8knot_fieldmark.relations_df()
pendant_trailing8knot_cords_mask = (the_8knotcords_df['is_subsidiary']==False) & (the_8knotcords_df['eight_knot_type']=='trailing_8knot')
pendant_trailing8knot_cords_df = the_8knotcords_df[pendant_trailing8knot_cords_mask]   
print(f"Number of Pendant Trailing 8 Knot Cords ending in '1': {len(pendant_trailing8knot_cords_df)}")

```
Number of Pendant Trailing 8 Knot Cords ending in '1': 2920
Code
```{python}
ends_in_one_mask = [str(cord_value).endswith('1') for cord_value in pendant_trailing8knot_cords_df['cord_value'].tolist()]
ends_in_one_df = pendant_trailing8knot_cords_df[ends_in_one_mask]
ends_in_one_df.head()
print(f"Number of Trailing 8 Knot Cords ending in '1': {len(ends_in_one_df)}")
```
Number of Trailing 8 Knot Cords ending in '1': 2028
Code
```{python}
kfg_names = ukhipu.lexigraphic_order(list(set(ends_in_one_df['kfg_name'].to_list())))
trailing8knot_1s_cords = []
for kfg_name in kfg_names:
    num_trailing8knot_1s_cords = len(ends_in_one_df[ends_in_one_df['kfg_name']==kfg_name])
    num_pendant_cords = khipu_dict[kfg_name].num_pendant_cords()
    pct_trailing8knot_cords = round(100.0*num_trailing8knot_1s_cords/num_pendant_cords)
    trailing8knot_cord_dict = {'kfg_name':kfg_name,
                               'num_trailing8knot_1s_cords':num_trailing8knot_1s_cords,
                               'num_pendant_cords':num_pendant_cords,
                               'pct_trailing8knot_cords':pct_trailing8knot_cords,
                               }
    trailing8knot_1s_cords.append(trailing8knot_cord_dict)  
trailing8knot_1s_cords_df = pd.DataFrame(trailing8knot_1s_cords)
```
Code
```{python}
print("Statistics for % Trailing 8 Knot Cords ending in 1 vs Pendant Cords")
print(umath.get_statistics(trailing8knot_1s_cords_df['pct_trailing8knot_cords'].to_list()))

fig = (px.scatter(trailing8knot_1s_cords_df, 
                    x='num_pendant_cords',
                    y='num_trailing8knot_1s_cords', 
                    color='pct_trailing8knot_cords', 
                    color_continuous_scale='Bluered_r', 
                    log_x=True, log_y=True,
                    title="By Khipu - # Pendant Cords vs # Sole 8 Knot Cords - Hover over Dot for Detail",
                    labels={'num_pendant_cords':'# Pendant Cords (Log scale)', 
                            'num_trailing8knot_1s_cords':'# Trailing Figure-8-Knot Cords (Log scale)',
                            'pct_trailing8knot_cords': '% Trailing 8 Knot Cords vs Pendant Cords',
                            'kfg_name':'Khipu Name',
                            },
                    width=944, height=944,
                    trendline="ols",
                    hover_data=['num_pendant_cords', 'num_trailing8knot_1s_cords', 'pct_trailing8knot_cords', 'kfg_name'])).show()

```
Statistics for % Trailing 8 Knot Cords ending in 1 vs Pendant Cords
{'min': 0, 'mean': 7.828488372093023, 'median': 6.0, 'max': 58, 'stddev': 6.965320344696113, 'range': 58, 'spread': 0.24018346016193493}

Here we see a closer match - a mean of 7.8% of the pendant cords are trailing 8-knot cords ending in ‘1’, with a standard deviation of 7%, with a skeptically extracted trendline of only 4%. While this might argue against trailing 8 knots being a significant marker, there is this curious issue as to how the existing trailing 1’s gravitate to the edges of a summand range.