-
Notifications
You must be signed in to change notification settings - Fork 4
/
Setup.Rmd
99 lines (77 loc) · 2.79 KB
/
Setup.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
title: "SetUp"
author: "Matt"
date: "17/11/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Setup
Modified from 'Prelim_Analysis_rewarded' written by Sarah Tennant. Goal here is to load data, functions and required packages.
```{r}
# Load packages
library(tidyverse)
library(broom)
library(lme4)
library(ggExtra)
library(ggthemes)
library(scales)
library(Hmisc)
library(Metrics)
library(plotrix)
library(pheatmap) # this package lets you make nice heatmaps
library(RColorBrewer) # import color palettes
library(networkD3) # This package lets you make and plot Sankey diagrams
library(zoo) # some mathematical functions that are useful
library(tibbletime)
library(agricolae) # post hoc Tukey test
library(ggallin) # this is for the pseudolog10_trans function used in coeff plots in Figure2_Analysis
library(car)
library(arrow)
library(cowplot)
# library(glmmTMB)
library(furrr)
future::plan(multisession)
# Load functions used in later analyses.
source("Functions.R")
# Parameter to save figures. Set to 1 if you'd like to save them.
save_figures = 0
# Parameter to save data snapshots as analysis proceeds. Set to 1 to save.
save_results = 0
# Type of shuffle to use
# Change this to "circular" to use circular shuffles of the data. # requires shuffled.feather file
# Change this to "mean" to use a space binned shuffled method
shuffle_type <- "circular"
## Load data
# Alternative file names commented out
## This file contains data exported from Python and is prior to any R analysis:
#spatial_firing <- readRDS(file="data_in/PythonOutput_Concat_final.Rda")
## This file already contains completed analyses, useful for quickly checking results:
spatial_firing <- readRDS(file="data_in/SpatialFiring_with_Results.Rda")
## Other previously used data files:
# spatial_firing <- readRDS(file="data_in/PythonOutput_Concat_final_unsmoothened.Rda")
# spatial_firing <- readRDS(file="data_in/SpatialFiring_with_1000_shuffles_of.Rda")
# spatial_firing <- readRDS(file="SpatialFiring_with_glmer.Rda")
# To work on a subset of data for testing
# spatial_firing <- slice_head(spatial_firing, n = 10)
spatial_firing <- as_tibble(spatial_firing)
# Make unique id for each neuron (session_id + cluster_id)
spatial_firing <- spatial_firing %>%
mutate(unique_id = pmap(list(session_id, cluster_id, sep = "_"), paste),
unique_id = unlist(unique_id),
unique_mouse = pmap(list(cohort, Mouse, sep = "_"), paste),
unique_mouse = unlist(unique_mouse))
```
***Warning***
Spatial firing is a very large object. Even running str takes many minutes.
```{r}
options(max.print = 1000)
dim(spatial_firing)
# Things measured:
colnames(spatial_firing)
# Cells:
# row.names(spatial_firing)
# stop from printing too much if looking at variables
options(max.print = 100)
```