From 28d43ba45a574883402d9fdc0c2fdcf75954f399 Mon Sep 17 00:00:00 2001 From: Steve Phelps Date: Fri, 29 Dec 2023 11:37:18 +0000 Subject: [PATCH] use persistent cache for memoization using mcapply and add theoretical predictions to GLMM interaction plot --- environment-frozen.yml | 157 ++++++++++++++++++----------------- environment.yml | 1 + jupyter-book/R-MixedModel.py | 80 ++++++++++++++++-- 3 files changed, 153 insertions(+), 85 deletions(-) diff --git a/environment-frozen.yml b/environment-frozen.yml index eff36ca..099f566 100644 --- a/environment-frozen.yml +++ b/environment-frozen.yml @@ -10,30 +10,30 @@ dependencies: - aiosignal=1.3.1=pyhd8ed1ab_0 - alabaster=0.7.13=pyhd8ed1ab_0 - annotated-types=0.6.0=pyhd8ed1ab_0 - - anyio=3.7.1=pyhd8ed1ab_0 + - anyio=4.2.0=pyhd8ed1ab_0 - appdirs=1.4.4=pyh9f0ad1d_0 - argon2-cffi=23.1.0=pyhd8ed1ab_0 - argon2-cffi-bindings=21.2.0=py311h459d7ec_4 - arrow=1.3.0=pyhd8ed1ab_0 - asn1crypto=1.5.1=pyhd8ed1ab_0 - - astroid=3.0.1=py311h38be061_0 + - astroid=3.0.2=py311h38be061_0 - asttokens=2.4.1=pyhd8ed1ab_0 - async-lru=2.0.4=pyhd8ed1ab_0 - attrs=23.1.0=pyh71513ae_1 - - aws-c-auth=0.7.0=h435f46f_0 - - aws-c-cal=0.6.0=h93469e0_0 - - aws-c-common=0.8.23=hd590300_0 - - aws-c-compression=0.2.17=h862ab75_1 - - aws-c-event-stream=0.3.1=h1e03375_0 - - aws-c-http=0.7.10=h9ab9c9b_2 - - aws-c-io=0.13.27=h3870b5a_0 - - aws-c-mqtt=0.8.13=hd4f18eb_5 - - aws-c-s3=0.3.12=he2a37c1_2 - - aws-c-sdkutils=0.1.11=h862ab75_1 - - aws-checksums=0.1.16=h862ab75_1 - - aws-crt-cpp=0.20.2=h2a5cb19_18 - - aws-sdk-cpp=1.10.57=h7b9373a_16 - - babel=2.13.1=pyhd8ed1ab_0 + - aws-c-auth=0.7.8=h538f98c_2 + - aws-c-cal=0.6.9=h5d48c4d_2 + - aws-c-common=0.9.10=hd590300_0 + - aws-c-compression=0.2.17=h7f92143_7 + - aws-c-event-stream=0.3.2=h0bcb0bb_8 + - aws-c-http=0.7.14=hd268abd_3 + - aws-c-io=0.13.36=he0cd244_2 + - aws-c-mqtt=0.10.0=h35285c7_0 + - aws-c-s3=0.4.5=h0448019_0 + - aws-c-sdkutils=0.1.13=h7f92143_0 + - aws-checksums=0.1.17=h7f92143_6 + - aws-crt-cpp=0.25.0=h1bbe558_2 + - aws-sdk-cpp=1.11.210=h0853bfa_5 + - babel=2.14.0=pyhd8ed1ab_0 - backoff=2.2.1=pyhd8ed1ab_0 - beautifulsoup4=4.12.2=pyha770c72_0 - binutils_impl_linux-64=2.40=hf600244_0 @@ -41,12 +41,12 @@ dependencies: - blackd=23.12.1=hd8ed1ab_0 - bleach=6.1.0=pyhd8ed1ab_0 - blobfile=2.1.0=pyhd8ed1ab_0 - - brotli=1.0.9=h166bdaf_9 - - brotli-bin=1.0.9=h166bdaf_9 - - brotli-python=1.0.9=py311ha362b79_9 + - brotli=1.1.0=hd590300_1 + - brotli-bin=1.1.0=hd590300_1 + - brotli-python=1.1.0=py311hb755f60_1 - bwidget=1.9.14=ha770c72_1 - bzip2=1.0.8=hd590300_5 - - c-ares=1.23.0=hd590300_0 + - c-ares=1.24.0=hd590300_0 - ca-certificates=2023.11.17=hbcca054_0 - cached-property=1.5.2=hd8ed1ab_1 - cached_property=1.5.2=pyha770c72_1 @@ -59,7 +59,7 @@ dependencies: - colorama=0.4.6=pyhd8ed1ab_0 - comm=0.1.4=pyhd8ed1ab_0 - contourpy=1.2.0=py311h9547e67_0 - - cryptography=38.0.4=py311h42a1071_0 + - cryptography=41.0.7=py311hcb13ee4_1 - curl=8.5.0=hca28451_0 - cycler=0.12.1=pyhd8ed1ab_0 - dataclasses=0.8=pyhc8e2a94_3 @@ -67,7 +67,7 @@ dependencies: - decorator=5.1.1=pyhd8ed1ab_0 - defusedxml=0.7.1=pyhd8ed1ab_0 - dill=0.3.7=pyhd8ed1ab_0 - - distlib=0.3.7=pyhd8ed1ab_0 + - distlib=0.3.8=pyhd8ed1ab_0 - distro=1.8.0=pyhd8ed1ab_0 - docutils=0.17.1=py311h38be061_4 - entrypoints=0.4=pyhd8ed1ab_0 @@ -84,11 +84,11 @@ dependencies: - fontconfig=2.14.2=h14ed4e7_0 - fonts-conda-ecosystem=1=0 - fonts-conda-forge=1=0 - - fonttools=4.46.0=py311h459d7ec_0 + - fonttools=4.47.0=py311h459d7ec_0 - fqdn=1.5.1=pyhd8ed1ab_0 - freetype=2.12.1=h267a509_2 - fribidi=1.0.10=h36c2ea0_0 - - frozenlist=1.4.0=py311h459d7ec_1 + - frozenlist=1.4.1=py311h459d7ec_0 - gcc_impl_linux-64=13.2.0=h338b0a0_3 - gettext=0.21.1=h27087fc_0 - gflags=2.2.2=he1b5a44_1004 @@ -96,14 +96,14 @@ dependencies: - glog=0.6.0=h6f12383_0 - gmp=6.3.0=h59595ed_0 - graphite2=1.3.13=h58526e2_1001 - - greenlet=3.0.1=py311hb755f60_0 + - greenlet=3.0.2=py311hb755f60_0 - gxx_impl_linux-64=13.2.0=h338b0a0_3 - h11=0.14.0=pyhd8ed1ab_0 - h2=4.1.0=pyhd8ed1ab_0 - harfbuzz=8.3.0=h3d44ed6_0 - hpack=4.0.0=pyh9f0ad1d_0 - httpcore=1.0.2=pyhd8ed1ab_0 - - httpx=0.25.2=pyhd8ed1ab_0 + - httpx=0.26.0=pyhd8ed1ab_0 - hyperframe=6.0.1=pyhd8ed1ab_0 - icu=73.2=h59595ed_0 - identify=2.5.33=pyhd8ed1ab_0 @@ -117,7 +117,7 @@ dependencies: - ipython=8.19.0=pyh707e725_0 - ipywidgets=8.1.1=pyhd8ed1ab_0 - isoduration=20.11.0=pyhd8ed1ab_0 - - isort=5.12.0=pyhd8ed1ab_1 + - isort=5.13.2=pyhd8ed1ab_0 - jedi=0.19.1=pyhd8ed1ab_0 - jinja2=3.1.2=pyhd8ed1ab_1 - joblib=1.3.2=pyhd8ed1ab_0 @@ -132,10 +132,10 @@ dependencies: - jupyter-lsp=2.2.1=pyhd8ed1ab_0 - jupyter_client=8.6.0=pyhd8ed1ab_0 - jupyter_console=6.6.3=pyhd8ed1ab_0 - - jupyter_core=5.5.0=py311h38be061_0 + - jupyter_core=5.5.1=py311h38be061_0 - jupyter_events=0.9.0=pyhd8ed1ab_0 - jupyter_server=2.12.1=pyhd8ed1ab_0 - - jupyter_server_terminals=0.4.4=pyhd8ed1ab_1 + - jupyter_server_terminals=0.5.0=pyhd8ed1ab_0 - jupyterlab=4.0.9=pyhd8ed1ab_0 - jupyterlab_pygments=0.3.0=pyhd8ed1ab_0 - jupyterlab_server=2.25.2=pyhd8ed1ab_0 @@ -151,18 +151,21 @@ dependencies: - lcms2=2.16=hb7c19ff_0 - ld_impl_linux-64=2.40=h41732ed_0 - lerc=4.0.0=h27087fc_0 - - libabseil=20230125.3=cxx17_h59595ed_0 - - libarrow=12.0.0=hc410076_9_cpu + - libabseil=20230802.1=cxx17_h59595ed_0 + - libarrow=14.0.2=hfb4d3a9_0_cpu + - libarrow-acero=14.0.2=h59595ed_0_cpu + - libarrow-dataset=14.0.2=h59595ed_0_cpu + - libarrow-substrait=14.0.2=h61ff412_0_cpu - libblas=3.9.0=20_linux64_openblas - - libbrotlicommon=1.0.9=h166bdaf_9 - - libbrotlidec=1.0.9=h166bdaf_9 - - libbrotlienc=1.0.9=h166bdaf_9 + - libbrotlicommon=1.1.0=hd590300_1 + - libbrotlidec=1.1.0=hd590300_1 + - libbrotlienc=1.1.0=hd590300_1 - libcblas=3.9.0=20_linux64_openblas - libcrc32c=1.1.2=h9c3ff4c_0 - libcurl=8.5.0=hca28451_0 - libdeflate=1.19=hd590300_0 - libedit=3.1.20191231=he28a2e2_2 - - libev=4.33=h516909a_1 + - libev=4.33=hd590300_2 - libevent=2.1.12=hf998b51_1 - libexpat=2.5.0=hcb278e6_1 - libffi=3.4.2=h7f98852_5 @@ -170,26 +173,27 @@ dependencies: - libgcc-ng=13.2.0=h807b86a_3 - libgfortran-ng=13.2.0=h69a702a_3 - libgfortran5=13.2.0=ha4646dd_3 - - libglib=2.78.2=h783c2da_0 + - libglib=2.78.3=h783c2da_0 - libgomp=13.2.0=h807b86a_3 - - libgoogle-cloud=2.12.0=hac9eb74_1 - - libgrpc=1.54.3=hb20ce57_0 - - libiconv=1.17=h166bdaf_0 + - libgoogle-cloud=2.12.0=h5206363_4 + - libgrpc=1.59.3=hd6c4280_0 + - libiconv=1.17=hd590300_2 - libjpeg-turbo=3.0.0=hd590300_1 - liblapack=3.9.0=20_linux64_openblas - - libnghttp2=1.58.0=h47da74e_0 + - libnghttp2=1.58.0=h47da74e_1 - libnsl=2.0.1=hd590300_0 - - libnuma=2.0.16=h0b41bf4_1 - libopenblas=0.3.25=pthreads_h413a1c8_0 + - libparquet=14.0.2=h352af49_0_cpu - libpng=1.6.39=h753d276_0 - - libprotobuf=3.21.12=hfc55251_2 + - libprotobuf=4.24.4=hf27288f_0 + - libre2-11=2023.06.02=h7a70373_0 - libsanitizer=13.2.0=h7e041cc_3 - libsodium=1.0.18=h36c2ea0_1 - libsqlite=3.44.2=h2797004_0 - libssh2=1.11.0=h0841786_0 - libstdcxx-devel_linux-64=13.2.0=ha9c7c90_103 - libstdcxx-ng=13.2.0=h7e041cc_3 - - libthrift=0.18.1=h8fd135c_2 + - libthrift=0.19.0=hb90f79a_1 - libtiff=4.6.0=ha9c0a0a_2 - libutf8proc=2.8.0=h166bdaf_0 - libuuid=2.38.1=h0b41bf4_0 @@ -201,7 +205,7 @@ dependencies: - libzlib=1.2.13=hd590300_5 - linkify-it-py=2.0.0=pyhd8ed1ab_0 - littleutils=0.2.2=py_0 - - lxml=4.9.3=py311h1a07684_2 + - lxml=4.9.3=py311h1a07684_3 - lz4=4.3.2=py311h38e4bf4_1 - lz4-c=1.9.4=hcb278e6_0 - make=4.3=hd18ef5c_1 @@ -235,24 +239,23 @@ dependencies: - notebook=7.0.6=pyhd8ed1ab_0 - notebook-shim=0.2.3=pyhd8ed1ab_0 - nspr=4.35=h27087fc_0 - - nss=3.95=h1d7d5a4_0 + - nss=3.96=h1d7d5a4_0 - numpy=1.26.2=py311h64a7726_0 - openai=1.6.1=pyhd8ed1ab_0 - openjpeg=2.5.0=h488ebb8_3 - openssl=3.2.0=hd590300_1 - - orc=1.8.4=h2f23424_0 - - oscrypto=1.2.1=pyhd3deb0d_0 + - orc=1.9.2=h4b38347_0 - outdated=0.2.2=pyhd8ed1ab_0 - overrides=7.4.0=pyhd8ed1ab_0 - packaging=23.2=pyhd8ed1ab_0 - pandas=2.1.4=py311h320fe9a_0 - pandas-flavor=0.6.0=pyhd8ed1ab_1 - - pandas-stubs=2.1.4.231218=pyhd8ed1ab_0 + - pandas-stubs=2.1.4.231227=pyhd8ed1ab_0 - pandoc=3.1.3=h32600fe_0 - pandocfilters=1.5.0=pyhd8ed1ab_0 - pango=1.50.14=ha41ecd1_2 - parso=0.8.3=pyhd8ed1ab_0 - - pathspec=0.11.2=pyhd8ed1ab_0 + - pathspec=0.12.1=pyhd8ed1ab_0 - patsy=0.5.4=pyhd8ed1ab_0 - pcre2=10.42=hcad00b1_0 - pexpect=4.8.0=pyh1a96a4e_2 @@ -268,13 +271,12 @@ dependencies: - portalocker=2.8.2=py311h38be061_1 - pre-commit=3.6.0=pyha770c72_0 - prometheus_client=0.19.0=pyhd8ed1ab_0 - - prompt-toolkit=3.0.41=pyha770c72_0 - - prompt_toolkit=3.0.41=hd8ed1ab_0 - - psutil=5.9.5=py311h459d7ec_1 + - prompt-toolkit=3.0.42=pyha770c72_0 + - prompt_toolkit=3.0.42=hd8ed1ab_0 + - psutil=5.9.7=py311h459d7ec_0 - pthread-stubs=0.4=h36c2ea0_1001 - ptyprocess=0.7.0=pyhd3deb0d_0 - pure_eval=0.2.2=pyhd8ed1ab_0 - - pyarrow=12.0.0=py311h39c9aba_9_cpu - pybtex=0.24.0=pyhd8ed1ab_2 - pybtex-docutils=1.0.3=py311h38be061_1 - pycparser=2.21=pyhd8ed1ab_0 @@ -286,7 +288,7 @@ dependencies: - pygments=2.17.2=pyhd8ed1ab_0 - pyjwt=2.8.0=pyhd8ed1ab_0 - pylint=3.0.3=pyhd8ed1ab_0 - - pyopenssl=22.1.0=pyhd8ed1ab_0 + - pyopenssl=23.3.0=pyhd8ed1ab_0 - pyparsing=3.1.1=pyhd8ed1ab_0 - pyppeteer=1.0.2=pyhd8ed1ab_0 - pysocks=1.7.1=pyha2e5f31_6 @@ -308,7 +310,7 @@ dependencies: - qtpy=2.4.1=pyhd8ed1ab_0 - r-abind=1.4_5=r43hc72bb7e_1005 - r-ape=5.7_1=r43h08d816e_1 - - r-arrow=12.0.0=r43h59595ed_1 + - r-arrow=14.0.1=r43h59595ed_0 - r-askpass=1.2.0=r43h57805ef_0 - r-assertthat=0.2.1=r43hc72bb7e_4 - r-backports=1.4.1=r43h57805ef_2 @@ -329,7 +331,7 @@ dependencies: - r-cellranger=1.1.0=r43hc72bb7e_1006 - r-checkmate=2.3.0=r43h57805ef_0 - r-class=7.3_22=r43h57805ef_1 - - r-cli=3.6.1=r43ha503ecb_1 + - r-cli=3.6.2=r43ha503ecb_0 - r-clipr=0.8.0=r43hc72bb7e_2 - r-clock=0.7.0=r43ha503ecb_1 - r-coda=0.19_4=r43hc72bb7e_2 @@ -340,13 +342,13 @@ dependencies: - r-conquer=1.3.3=r43h08d816e_2 - r-corpcor=1.6.10=r43hc72bb7e_2 - r-corrplot=0.92=r43hc72bb7e_2 - - r-cowplot=1.1.1=r43hc72bb7e_2 + - r-cowplot=1.1.2=r43hc72bb7e_0 - r-cpp11=0.4.7=r43hc72bb7e_0 - r-crayon=1.5.2=r43hc72bb7e_2 - r-crosstalk=1.2.1=r43hc72bb7e_0 - r-cubature=2.0.4.6=r43hcf54a89_1 - r-curl=5.1.0=r43hf9611b0_0 - - r-data.table=1.14.8=r43h029312a_2 + - r-data.table=1.14.10=r43h029312a_0 - r-datawizard=0.9.0=r43hc72bb7e_0 - r-dbi=1.1.3=r43hc72bb7e_2 - r-dbplyr=2.4.0=r43hc72bb7e_0 @@ -363,7 +365,7 @@ dependencies: - r-emmeans=1.9.0=r43hc72bb7e_0 - r-estimability=1.4.1=r43hc72bb7e_2 - r-evaluate=0.23=r43hc72bb7e_0 - - r-fansi=1.0.5=r43h57805ef_0 + - r-fansi=1.0.6=r43h57805ef_0 - r-farver=2.1.1=r43ha503ecb_2 - r-fastmap=1.1.1=r43ha503ecb_1 - r-fontawesome=0.5.2=r43hc72bb7e_0 @@ -429,10 +431,10 @@ dependencies: - r-mass=7.3_60=r43h57805ef_1 - r-matrix=1.6_0=r43h316c678_0 - r-matrixmodels=0.5_3=r43hc72bb7e_0 - - r-matrixstats=1.1.0=r43h57805ef_0 + - r-matrixstats=1.2.0=r43h57805ef_0 - r-mcmcglmm=2.35=r43ha503ecb_0 - r-memoise=2.0.1=r43hc72bb7e_2 - - r-mgcv=1.9_0=r43h316c678_0 + - r-mgcv=1.9_1=r43h316c678_0 - r-mime=0.12=r43h57805ef_2 - r-minqa=1.2.6=r43hcf54a89_0 - r-mitools=2.4=r43hc72bb7e_4 @@ -460,7 +462,7 @@ dependencies: - r-polynom=1.4_1=r43hc72bb7e_2 - r-prettyunits=1.2.0=r43hc72bb7e_0 - r-proc=1.18.5=r43ha503ecb_0 - - r-processx=3.8.2=r43h57805ef_0 + - r-processx=3.8.3=r43h57805ef_0 - r-prodlim=2023.08.28=r43ha503ecb_0 - r-progress=1.2.3=r43hc72bb7e_0 - r-progressr=0.14.0=r43hc72bb7e_0 @@ -470,11 +472,12 @@ dependencies: - r-purrr=1.0.2=r43h57805ef_0 - r-qgam=1.3.4=r43h57805ef_2 - r-quantreg=5.97=r43hd9ac46e_0 + - r-r.cache=0.16.0=r43hc72bb7e_2 - r-r.methodss3=1.8.2=r43hc72bb7e_2 - r-r.oo=1.25.0=r43hc72bb7e_2 - r-r.utils=2.12.3=r43hc72bb7e_0 - r-r6=2.5.1=r43hc72bb7e_2 - - r-ragg=1.2.6=r43h73ae6e3_0 + - r-ragg=1.2.7=r43h73ae6e3_0 - r-rappdirs=0.3.3=r43h57805ef_2 - r-rcolorbrewer=1.1_3=r43h785f33e_2 - r-rcpp=1.0.11=r43h7df8631_0 @@ -483,7 +486,7 @@ dependencies: - r-rcpptoml=0.2.2=r43ha503ecb_1 - r-readr=2.1.4=r43ha503ecb_1 - r-readxl=1.4.3=r43ha5c9fba_0 - - r-recipes=1.0.8=r43hc72bb7e_0 + - r-recipes=1.0.9=r43hc72bb7e_0 - r-rematch=2.0.0=r43hc72bb7e_0 - r-rematch2=2.1.2=r43hc72bb7e_3 - r-repr=1.1.6=r43h785f33e_1 @@ -514,7 +517,7 @@ dependencies: - r-squarem=2021.1=r43hc72bb7e_2 - r-stargazer=5.2.3=r43hc72bb7e_2 - r-statmod=1.5.0=r43hd8f1df9_1 - - r-stringi=1.8.2=r43h9facbd6_0 + - r-stringi=1.8.3=r43h9facbd6_0 - r-stringr=1.5.1=r43h785f33e_0 - r-survey=4.2_1=r43hc72bb7e_1 - r-survival=3.5_7=r43h57805ef_0 @@ -530,7 +533,7 @@ dependencies: - r-tidyselect=1.2.0=r43hc72bb7e_1 - r-tidyverse=2.0.0=r43h785f33e_1 - r-timechange=0.2.0=r43ha503ecb_1 - - r-timedate=4022.108=r43hc72bb7e_1 + - r-timedate=4032.109=r43hc72bb7e_0 - r-tinytex=0.49=r43hc72bb7e_0 - r-tmb=1.9.6=r43h08d816e_0 - r-tzdb=0.4.0=r43ha503ecb_1 @@ -545,19 +548,18 @@ dependencies: - r-xfun=0.41=r43ha503ecb_0 - r-xml2=1.3.6=r43h1ad5fc0_0 - r-xtable=1.8_4=r43hc72bb7e_5 - - r-yaml=2.3.7=r43h57805ef_1 + - r-yaml=2.3.8=r43h57805ef_0 - r-zoo=1.8_12=r43h57805ef_1 - - rdma-core=28.9=h59595ed_1 - - re2=2023.03.02=h8c504da_0 + - re2=2023.06.02=h2873b5e_0 - readline=8.2=h8228510_1 - - referencing=0.31.1=pyhd8ed1ab_0 + - referencing=0.32.0=pyhd8ed1ab_0 - regex=2023.10.3=py311h459d7ec_0 - requests=2.31.0=pyhd8ed1ab_0 - rfc3339-validator=0.1.4=pyhd8ed1ab_0 - rfc3986-validator=0.1.1=pyh9f0ad1d_0 - - rpds-py=0.13.2=py311h46250e7_0 - - s2n=1.3.46=h06160fa_0 - - sacrebleu=2.3.3=pyhd8ed1ab_0 + - rpds-py=0.15.2=py311h46250e7_0 + - s2n=1.4.0=h06160fa_0 + - sacrebleu=2.4.0=pyhd8ed1ab_0 - scikit-learn=1.3.2=py311hc009520_2 - scipy=1.11.4=py311h64a7726_0 - seaborn=0.13.0=hd8ed1ab_0 @@ -593,7 +595,7 @@ dependencies: - sqlalchemy=2.0.23=py311h459d7ec_0 - sqlite=3.44.2=h2c6b66d_0 - stack_data=0.6.2=pyhd8ed1ab_0 - - statsmodels=0.14.0=py311h1f0f07a_2 + - statsmodels=0.14.1=py311h1f0f07a_0 - sysroot_linux-64=2.12=he073ed8_16 - tabulate=0.9.0=pyhd8ed1ab_1 - tenacity=8.2.3=pyhd8ed1ab_0 @@ -613,12 +615,11 @@ dependencies: - types-python-dateutil=2.8.19.14=pyhd8ed1ab_0 - types-pytz=2023.3.1.1=pyhd8ed1ab_0 - typing=3.10.0.0=pyhd8ed1ab_0 - - typing-extensions=4.8.0=hd8ed1ab_0 - - typing_extensions=4.8.0=pyha770c72_0 + - typing-extensions=4.9.0=hd8ed1ab_0 + - typing_extensions=4.9.0=pyha770c72_0 - typing_utils=0.1.0=pyhd8ed1ab_0 - tzdata=2023c=h71feb2d_0 - uc-micro-py=1.0.1=pyhd8ed1ab_0 - - ucx=1.14.1=h64cca9d_5 - ukkonen=1.0.1=py311h9547e67_4 - uri-template=1.3.0=pyhd8ed1ab_0 - urllib3=1.26.18=pyhd8ed1ab_0 @@ -630,7 +631,7 @@ dependencies: - websockets=10.4=py311hd4cff14_1 - wheel=0.42.0=pyhd8ed1ab_0 - widgetsnbextension=4.0.9=pyhd8ed1ab_0 - - xarray=2023.11.0=pyhd8ed1ab_0 + - xarray=2023.12.0=pyhd8ed1ab_0 - xorg-kbproto=1.0.7=h7f98852_1002 - xorg-libice=1.1.1=hd590300_0 - xorg-libsm=1.2.4=h7391055_0 diff --git a/environment.yml b/environment.yml index 7b336bd..612259f 100644 --- a/environment.yml +++ b/environment.yml @@ -45,6 +45,7 @@ dependencies: - r-effects - r-sjPlot - r-patchwork + - r-R.cache - pip - pip: - -e ./ diff --git a/jupyter-book/R-MixedModel.py b/jupyter-book/R-MixedModel.py index 152234c..5a93a2e 100644 --- a/jupyter-book/R-MixedModel.py +++ b/jupyter-book/R-MixedModel.py @@ -35,6 +35,7 @@ library(purrr) library(memoise) library(patchwork) +library(R.cache) # %% options(repr.plot.width = 20, repr.plot.height = 10) @@ -105,12 +106,23 @@ # %% results.clean$Participant_group <- relevel(results.clean$Participant_group, ref='Control') -results.clean$Partner_condition <- relevel(results.clean$Partner_condition, ref='T4TD') +results.clean$Partner_condition <- relevel(results.clean$Partner_condition, ref='D') results.clean$Model <- relevel(results.clean$Model, ref='gpt-3.5-turbo-0613') results.clean$Participant_pronoun <- relevel(results.clean$Participant_pronoun, ref='they') results.clean$Participant_case <- relevel(results.clean$Participant_case, ref='standard') results.clean$Particpant_label <- relevel(results.clean$Participant_label, ref='colors') +# %% +levels(results.clean$Partner_condition) + +# %% +results.clean$Partner_condition <- + factor(results.clean$Partner_condition, + levels = c('D', 'T4TD', 'T4TC', 'C')) + +# %% +levels(results.clean$Partner_condition) + # %% names(results.clean) @@ -211,6 +223,54 @@ # %% xtable(coef(summary(model.pd))$cond, digits=3) +# %% +theoretical.altruistic <- list(D=1, C=1, T4TD=1, T4TC=1) +theoretical.altruistic + +# %% +theoretical.data <- function(group, frequencies) { + result <- data.frame(x = as.factor(c('D', 'T4TD', 'T4TC', 'C')), + predicted = frequencies, + std.error = rep(0, 4), + conf.low = frequencies, + conf.high = frequencies, + group = as.factor(rep('theoretical', 4)), + facet = as.factor(rep(group, 4)) + ) + return(result) +} + +theoretical.df <- function(group) { + case_when( + group == 'Selfish' ~ theoretical.data('Selfish', c(0, 0, 0, 0)), + group == 'Cooperative' ~ theoretical.data('Cooperative', c(1/6, 3/6, 1, 1)), + group == 'Competitive' ~ theoretical.data('Competitive', c(1/6, 1/6, 1/6, 1/6)), + group == 'Altruistic' ~ theoretical.data('Altruistic', c(1, 1, 1, 1)), + group == 'Control' ~ theoretical.data('Control', c(NA, NA, NA, NA)) + ) +} + +# %% +x.df <- theoretical.df("Selfish") +x.df + +# %% +y.df <- predictions.for.m("gpt-3.5-turbo-1106", "Selfish") +y.df + +# %% +names(x.df) + +# %% +names(y.df) + +# %% +merged.df <- rbind(x.df, y.df) +levels(merged.df$group) + +# %% +levels(merged.df$x) + # %% predictions.for <- function(model, participant.group) { ggpredict(model.pd.1, c("Partner_condition", @@ -218,7 +278,7 @@ sprintf("Participant_group [%s]", participant.group))) } -predictions.for.m <- memoise(predictions.for) +predictions.for.m <- addMemoization(predictions.for) # %% interaction.plots <- function(participant.group, legend) { @@ -226,17 +286,23 @@ function(model) predictions.for.m(model, participant.group), mc.cores=12) combined <- reduce(predictions, rbind) - names(combined)[6] <- 'model' + combined <- rbind(combined, theoretical.df(participant.group)) + names(combined)[6] <- 'Model' p <- ggplot(combined) + - aes(x = x, y = predicted, group = model) + + aes(x = x, y = predicted, group = Model) + geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = .1, position = position_dodge(0.06)) + - geom_line(aes(color=model), size = 1) + scale_y_continuous(limits = c(0.1, 1)) + + geom_line(aes(color=Model), size = 1) + scale_y_continuous(limits = c(0, 1)) + scale_color_brewer(palette = "Dark2", direction = -1) + labs(title = sprintf("Group: %s", participant.group), - x = "Partner condition", y = "Probability of cooperation") + x = "Partner condition", y = "Probability of cooperation") + + theme(legend.title = element_text(size=16), + legend.text = element_text(size=14)) if (!legend) { p <- p + theme(legend.position = "none") + } else { + p <- p + theme(legend.title = element_text(size=16), + legend.text = element_text(size=14)) } return(p) } @@ -256,7 +322,7 @@ # %% combined.plots <- all.interaction.plots() -pdf("figs/interaction-plots-all.pdf", width=9, height=10) +pdf("figs/interaction-plots-all.pdf", width=8, height=11) print(combined.plots) dev.off() combined.plots