Skip to content

Commit

Permalink
add matched/unmatched events results
Browse files Browse the repository at this point in the history
  • Loading branch information
xinmingxu committed Jun 24, 2024
1 parent 1b5a5e3 commit 70a5b4a
Show file tree
Hide file tree
Showing 10 changed files with 4,504 additions and 180 deletions.
215 changes: 169 additions & 46 deletions code/r_code.ipynb

Large diffs are not rendered by default.

65 changes: 62 additions & 3 deletions code/r_code_rep.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
"- Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()\n",
"- Methods for calculating p-values with mixed(): 'S', 'KR', 'LRT', and 'PB'\n",
"- 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests\n",
"- NEWS: emmeans() for ANOVA models now uses model = 'multivariate' as default.\n",
"- Get and set global package options with: afex_options()\n",
"- Set orthogonal sum-to-zero contrasts globally: set_sum_contrasts()\n",
"- Set sum-to-zero contrasts globally: set_sum_contrasts()\n",
"- For example analyses see: browseVignettes(\"afex\")\n",
"************\n",
"\n",
Expand Down Expand Up @@ -741,6 +740,66 @@
"saveRDS(p0r0_hit_econd_total, \"../stats_models/rep/p0r0_hit_econd_total.rds\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"'data.frame':\t1756 obs. of 15 variables:\n",
" $ sub : Factor w/ 37 levels \"0522-1\",\"0522-2\",..: 1 1 3 3 5 5 7 7 9 9 ...\n",
" $ story : int 3 3 3 3 3 3 3 3 3 3 ...\n",
" $ segment : Factor w/ 13 levels \"3_01\",\"3_02\",..: 1 1 1 1 1 1 1 1 1 1 ...\n",
" $ segment_count : num 12 12 12 12 12 12 12 12 12 12 ...\n",
" $ segment_num : int 1 1 1 1 1 1 1 1 1 1 ...\n",
" $ base_segment : Factor w/ 13 levels \"3_01\",\"3_02\",..: 2 2 2 2 2 2 2 2 2 2 ...\n",
" $ segment_count_demean: num 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 ...\n",
" $ segment_num_demean : int -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 ...\n",
" $ segment_pair : Factor w/ 12 levels \"3_01-02\",\"3_02-03\",..: 1 1 1 1 1 1 1 1 1 1 ...\n",
" $ condition : Factor w/ 4 levels \"p\",\"p0\",\"r\",\"r0\": 4 3 4 3 4 3 4 3 4 3 ...\n",
" $ cond_direction : Factor w/ 2 levels \"b\",\"f\": 1 1 1 1 1 1 1 1 1 1 ...\n",
" $ cond_amount : Factor w/ 2 levels \"p/r\",\"p0/r0\": 2 1 2 1 2 1 2 1 2 1 ...\n",
" $ e_cond_bin : Factor w/ 2 levels \"e_match\",\"e_unmatch\": 1 1 1 1 1 1 1 1 1 1 ...\n",
" $ n_hits : num 0 4 1 3.5 1 2.5 2 1 1 1.5 ...\n",
" $ n_hits_2 : num 0 8 2 7 2 5 4 2 2 3 ...\n"
]
}
],
"source": [
"df_pr_econd_bin <- read.csv(file = '../data/rep/R/df_pr_econd_bin_for_R.csv', stringsAsFactors = TRUE)\n",
"df_pr_econd_bin$n_hits_2 <- df_pr_econd_bin$n_hits*2 # integers required\n",
"str(df_pr_econd_bin)\n",
"\n",
"df_p0r0_econd_bin <- dplyr::filter(df_pr_econd_bin, cond_amount=='p0/r0')\n",
"df_cpr_econd_bin <- dplyr::filter(df_pr_econd_bin, cond_amount=='p/r')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "r"
}
},
"outputs": [],
"source": [
"p0r0_hit_econd_bin <- mixed(n_hits_2 ~ \n",
" cond_direction*segment_count_demean*e_cond_bin + \n",
" (cond_direction*e_cond_bin|segment) + \n",
" (segment_count_demean*e_cond_bin|sub), \n",
" df_p0r0_econd_bin, family = poisson, method = \"LRT\", cl=cl)\n",
"p0r0_hit_econd_bin\n",
"saveRDS(p0r0_hit_econd_bin, \"../stats_models/rep/p0r0_hit_econd_bin.rds\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand Down Expand Up @@ -1739,7 +1798,7 @@
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "4.1.2"
"version": "4.4.0"
},
"orig_nbformat": 4
},
Expand Down
38 changes: 36 additions & 2 deletions code/results.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-05T18:10:35.388571Z",
Expand All @@ -117,6 +117,7 @@
"cond_pr_recall = ['r0','p0','r','p','r_p','p_r','r_recall','p_recall'] \n",
"cond_full = ['r0','p0','r','p','r_p','p_r','r_recall','p_recall','r_p_recall','p_r_recall','recall_f','recall_b']\n",
"e_cond = ['e_target','e_gap','e_ahead','e_unmatch']\n",
"e_cond_bin = ['e_match','e_unmatch']\n",
"\n",
"cmap_old = {'p_1':Category20[8][1], 'r_1':Category20[8][3],\n",
" 'p_2':Category20[8][0], 'r_2':Category20[8][2],\n",
Expand Down Expand Up @@ -620,7 +621,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 4,
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-05T18:10:40.878068Z",
Expand Down Expand Up @@ -847,6 +848,39 @@
"df_pr_recall_R.shape"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1962, 14)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# df_pr_econd_bin_R (for figure 2 stats)\n",
"cols = ['sub','story','segment','segment_count','segment_num','base_segment',\n",
" 'segment_pair','condition','cond_direction','cond_amount']\n",
"\n",
"df_pr_econd_R_bin = pd.melt(df, id_vars=cols, value_vars=e_cond_bin, \n",
" var_name='e_cond_bin', value_name='n_hits')\n",
"\n",
"df_pr_econd_R_bin = df_pr_econd_R_bin.query(\"condition==['p0','r0','p','r','p_r','r_p']\")\n",
"\n",
"df_pr_econd_R_bin['segment_count_demean'] = df_pr_econd_R_bin['segment_count']-5.5\n",
"df_pr_econd_R_bin['segment_num_demean'] = df_pr_econd_R_bin['segment_num']-6\n",
"\n",
"df_pr_econd_R_bin.to_csv(\"../data/main/R/df_pr_econd_bin_for_R.csv\", index=False)\n",
"df_pr_econd_R_bin.shape"
]
},
{
"cell_type": "code",
"execution_count": 25,
Expand Down
37 changes: 33 additions & 4 deletions code/results_rep.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-05T18:10:25.867414Z",
Expand Down Expand Up @@ -31,7 +31,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-05T18:10:35.374315Z",
Expand Down Expand Up @@ -118,6 +118,7 @@
"cond_re = ['r_recall','p_recall','r_p_recall','p_r_recall','recall_f','recall_b']\n",
"e_cond = ['e_target','e_gap','e_ahead','e_unmatch']\n",
"e_cond_sl = ['e_target_sl','e_gap_sl','e_ahead_sl','e_across_sl','e_unmatch']\n",
"e_cond_bin = ['e_match','e_unmatch']\n",
"\n",
"cmap_old = {'p_1':Category20[8][1], 'r_1':Category20[8][3],\n",
" 'p_2':Category20[8][0], 'r_2':Category20[8][2],\n",
Expand Down Expand Up @@ -753,7 +754,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 5,
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-05T18:10:40.878068Z",
Expand All @@ -768,7 +769,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"(878, 236)\n"
"(878, 235)\n"
]
}
],
Expand Down Expand Up @@ -853,6 +854,34 @@
"print(df_pr_R.shape)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1756, 14)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# df_pr_econd_bin_R (for figure 2 stats)\n",
"cols = ['sub','story','segment','segment_count','segment_num','base_segment','segment_count_demean','segment_num_demean',\n",
" 'segment_pair','condition','cond_direction','cond_amount']\n",
"\n",
"df_pr_econd_bin_R = pd.melt(df, id_vars=cols, value_vars=e_cond_bin, \n",
" var_name='e_cond_bin', value_name='n_hits')\n",
"\n",
"df_pr_econd_bin_R.to_csv(\"../data/rep/R/df_pr_econd_bin_for_R.csv\", index=False)\n",
"df_pr_econd_bin_R.shape"
]
},
{
"cell_type": "code",
"execution_count": 29,
Expand Down
Loading

0 comments on commit 70a5b4a

Please sign in to comment.