Skip to content

Instantly share code, notes, and snippets.

@kagaya
kagaya / gist:3802904
Last active March 25, 2018 09:25
Automatic Recording of Force Data
function ForceData=autorec(duration, strikeThreshold, rewardThreshold)
%% DISCRIPTION
% This program automatically records foce data by detecting rising phase of
% the voltage change and it produce digital output whether the peak of the
% voltage above a threshold. The condition of output can be customized.
%% HOW TO USE
% The termination of this program is tricky. Please press "Ctrl - c" to
% quit the program and after that, command "daqreset" in the MATLAB prompt.
@kagaya
kagaya / gist:3918842
Created October 19, 2012 15:28
Convert Data from 'autorec.m' (https://gist.github.com/3802904) to Text Formatted Data
function formatted_data = format2txt()
%%
if ismac == 1
file_names = ls();
elseif ispc == 1
file_names = char(mat2str(ls()));
end
data_dir = regexp(file_names, '[0-9]*-[0-9]*\.[0-9]*', 'match');
data_dir
@kagaya
kagaya / Kagaya_Patek_kinem_control_stat.R
Last active March 25, 2018 08:36
functions for statistical analysis and data visualizations in the paper — Motor control of ultrafast, ballistic movements (by K. Kagaya and S. N. Patek)
## functions for statistical analysis and data visualizations in the paper,
## The paper's title: Motor control of ultrafast, ballistic movements (by K. Kagaya and S. N. Patek)
## This script is written by Katsushi Kagaya (k.kagaya@me.com)
## Gist URL: https://gist.github.com/kagaya/cbafe0a332e6d6766168
## to load libraries
library(ggplot2) # for plotting data and model prediction
library(mgcv) # for generalized addive modeling (GAM fitting)
library(plyr) # for data manipulation
library(nlme) # for linear mixed effects modeling
@kagaya
kagaya / Kagaya_Patek_kinem_control_hsv.R
Last active March 25, 2018 08:36
functions for 'mdf' files which stores digitized kinematic data from MTrackJ — Motor control of ultrafast, ballistic movements (by K. Kagaya and S. N. Patek)
## functions for 'mdf' files which stores digitized kinematic data from MTrackJ
## The paper's title: Motor control of ultrafast, ballistic movements (by K. Kagaya and S. N. Patek)
## This script is written by Katsushi Kagaya (k.kagaya@me.com)
## Gist URL: https://gist.github.com/kagaya/540596f6d1191c157cb7
library(ggplot2)
library(plyr)
@kagaya
kagaya / Kagaya_Patek_kinem_control_emg.R
Last active March 25, 2018 08:37
functions for physiological data analyses in the paper — Motor control of ultrafast, ballistic movements (by K. Kagaya and S. N. Patek)
## functions for physiological data analyses in the paper,
## The paper's title: Motor control of ultrafast, ballistic movements (by K. Kagaya and S. N. Patek)
## written by Katsushi Kagaya (k.kagaya@me.com)
## Gist URL: https://gist.github.com/kagaya/36145a370a1da0f4ba0d
## to load libraries necessary for the current script
library(ggplot2)
library(plyr)
@kagaya
kagaya / utility.R
Last active June 3, 2018 07:11
utilities for Harada and Kagaya, https://doi.org/10.1101/330787
library(tidyverse)
library(forcats)
library(rstan)
library(shinystan)
waic <- function(log_likelihood) {
# from https://gist.github.com/MatsuuraKentaro/3f6ae5863e700f5039c19e36a9bdf646
training_error <- - mean(log(colMeans(exp(log_likelihood))))
functional_variance_div_N <- mean(colMeans(log_likelihood^2) - colMeans(log_likelihood)^2)
waic <- training_error + functional_variance_div_N
@kagaya
kagaya / plot_f.R
Last active January 30, 2019 06:53
plot functions for Harada and Kagaya, https://doi.org/10.1101/330787
library(tidyverse)
library(ggrepel)
library(rstan)
rstan::expose_stan_functions("my_stan_functions.stan") # https://gist.github.com/kagaya/c726f16d82b80026bb1924b408a72b5c
source("utility.R")
###### choice #####
@kagaya
kagaya / main.rmd
Last active February 1, 2019 11:33
Harada and Kagaya, Customizing material into embodied cap by sponge crab, https://doi.org/10.1101/330787
---
header-includes:
- \usepackage{setspace}
- \doublespacing
- \usepackage{lineno}
- \linenumbers
output:
pdf_document: default
html_document:
df_print: paged
@kagaya
kagaya / Supplementary_Information.rmd
Last active February 4, 2020 16:01
Supplementary information for the paper entitled "Customizing material into embodied cap by sponge crab" by Harada and Kagaya (https://doi.org/10.1101/330787)
---
title: Supplementary information for the paper 'Individual behavioral type captured by a Bayesian model comparison in cap making by sponge crab'
---
This document is the supplementary information for the paper 'Individual behavioral type captured by a Bayesian framework in cap making by sponge crab' by Harada, Hayashi and Kagaya.
The basic conceptural framework for data analysis in the paper is a Bayesian framework based on the mathematical theory founded by Dr. Akaike and Dr. Watanabe (Watanabe, 'Mathematical Theory of Bayesian Statistics', 2018). The author of this document wrote an example of model selection by Widely Applicable Information Criterion (WAIC) using the data of 'artificial case' (http://rpubs.com/katzkagaya/460937). It may be of help for clarifying what the analysis of this document is doing, by using numerically generated 'artificial' data and several relatively simple hierarchical models.
In this study, we deal with the behavioral data of a 'natural case'. Therefore, we do not know
@kagaya
kagaya / kick_model_1_1_choice.R
Last active June 3, 2018 11:26
Harada and Kagaya, https://doi.org/10.1101/330787; kicking R codes for the Stan models
library(rstan)
library(tidyverse)
library(shinystan)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
# preprocessing
d <- read_csv(file='Dromiidae.csv') # https://gist.github.com/kagaya/0d309397300b7e8294fe53c44b6fc525
d <- d %>%