Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View johnjdavisiv's full-sized avatar
📝
Writing!

John Davis johnjdavisiv

📝
Writing!
View GitHub Profile
@johnjdavisiv
johnjdavisiv / covid19_by_us_state.R
Last active March 25, 2020 23:42
Plot the total number of COVID-19 cases for each US state
library(tidyverse)
library(ggplot2)
library(shadowtext)
#John J Davis IV
#Biomechanics PhD Student
#Indiana University School of Public Health
#Twitter: @JDRuns
#Email: jjd1@iu.edu
#25 March 2020
@johnjdavisiv
johnjdavisiv / add_us_state_covid19_cases_for_kaggle.R
Last active March 24, 2020 21:48
This script pulls JHU data on COVID19 in the US and matches it with the Kaggle competition data prior to March 9th.
#Kaggle COVID19 prediction model
#JJD
#24 march 2020
#johnjdiv@gmail.com
library(tidyverse)
library(nlme)
library(HRW)
@johnjdavisiv
johnjdavisiv / join_world_dev_covid19_week3.R
Last active April 7, 2020 22:22
Joins simple world development data with Covid-19 data for week 3 on Kaggle
#----------------------------------------------------------------
# Add economic development data to train and test
#-------------------------------------------------------------------
covid_train <- read.csv("train.csv", stringsAsFactors = FALSE) %>%
mutate(Province_State = ifelse(Province_State == "", "none", Province_State)) %>%
unite(country_and_province,
Country_Region, Province_State,
remove=FALSE)
@johnjdavisiv
johnjdavisiv / plotFFT.m
Created June 30, 2020 19:39
Plot FFT of a signal
function plotFFT(v,fs)
%plotFFT Quick function to plot the frequency content of a signal
% Input:
%
% v - (vector) signal
% fs - sample frequency in Hz
%
% Output:
% none, just plots the FFT spectrum and highlights dominant frequency
@johnjdavisiv
johnjdavisiv / thin_plate_demo.R
Created December 2, 2020 00:58
A quick demo of thin plate regression splines in mgcv
library(mgcv)
library(plot3D)
#Set up sample data
set.seed(42)
x <- runif(200, -1,1)
y <- runif(200, -1,1)
z <- exp(-(x^2 + y^2)) + rnorm(200, 0, 0.15)
#Fit 2D thin-plate regression spline
@johnjdavisiv
johnjdavisiv / cmc_dgf.log
Created November 29, 2021 20:57
Log of successful CMC in walking data with DGF muscles replacing the left vastii on the Rajagopal 2015 model
[2021-11-29 15:39:05.587] [info] Loaded model subject_scale_walk from file C:/Users/johnj/Google Drive/IU Grad school/OpenSim/Resources/Models/Rajagopal 2015 Model and Data/RRA/walk/subject_walk_rra2_v4_3_left_vasti_dgf.osim
[2021-11-29 15:39:26.211] [info] Adding force object set from C:\Users\johnj\Google Drive\IU Grad school\OpenSim\Resources\Models\Rajagopal 2015 Model and Data\CMC\walk\cmc_actuators.xml
[2021-11-29 15:39:26.301] [info] Running tool 'cmc'.
[2021-11-29 15:39:26.322] [warning] ExternalLoades: external_loads_model_kinematics_file option is not supported anymore. Results may change.
[2021-11-29 15:39:26.331] [info] ExternalLoads 'grf_walk' was renamed and is being reset to 'externalloads'.
[2021-11-29 15:39:26.389] [info] TaskSet size = 29.
[2021-11-29 15:39:26.511] [info] Storage: read data file = ../../ExpData/grf_walk.mot (nr=4778 nc=19)
[2021-11-29 15:39:26.553] [info] ExternalForce::Right_GRF Data source being set to subject11_noload_free_trial03_ground_reaction
[2021-11-29 15:39:26.553]
@johnjdavisiv
johnjdavisiv / cmc_dgf_fail.log
Last active November 29, 2021 21:22
Log of failed CMC in walking data with DGF muscles replacing the left rectus femoris on the Rajagopal 2015 model
[2021-11-29 16:19:53.753] [info] Loaded model subject_scale_walk from file C:\Users\johnj\Google Drive\IU Grad school\OpenSim\Resources\Models\Rajagopal 2015 Model and Data\RRA\walk\subject_walk_rra2_v4_3_recfem_l.osim
[2021-11-29 16:20:18.823] [info] Adding force object set from C:\Users\johnj\Google Drive\IU Grad school\OpenSim\Resources\Models\Rajagopal 2015 Model and Data\CMC\walk\cmc_actuators.xml
[2021-11-29 16:20:18.902] [info] Running tool 'cmc'.
[2021-11-29 16:20:18.922] [warning] ExternalLoades: external_loads_model_kinematics_file option is not supported anymore. Results may change.
[2021-11-29 16:20:18.931] [info] ExternalLoads 'grf_walk' was renamed and is being reset to 'externalloads'.
[2021-11-29 16:20:18.986] [info] TaskSet size = 29.
[2021-11-29 16:20:19.112] [info] Storage: read data file = ../../ExpData/grf_walk.mot (nr=4778 nc=19)
[2021-11-29 16:20:19.155] [info] ExternalForce::Right_GRF Data source being set to subject11_noload_free_trial03_ground_reaction
[2021-11-29 16:20:19.156] [info
@johnjdavisiv
johnjdavisiv / calculate_joint_stiffness.m
Created April 6, 2022 03:03
Calculate joint stiffness using Hamill et al. 2014 method
function k_joint = calculate_joint_stiffness(ankle_angle, joint_angle, joint_moment, joint_name)
%Calculates joint stiffness per the Hamill et al 2014 method
% John J Davis IV
%IU Biomechanics Lab
% @JDruns
%30 June 2020
% --- INPUT: ---
% ankle_angle - (vector) ankle angle data in degrees, respecting right hand rule
@johnjdavisiv
johnjdavisiv / demo_smooth_interactions.R
Created August 13, 2022 03:49
Demo of testing smooth interaction terms in an additive model
library(tidyverse)
library(mgcv)
library(gratia) #For nicer gam plots
library(viridis) #For nicer colors
#if you don't have above libraries run
# install.packages("tidyverse")
# install.packages("mgcv")
# install.packages("gratia")
# install.packages("viridis")
@johnjdavisiv
johnjdavisiv / plot_fft.m
Last active August 16, 2022 18:43
Plot frequency spectrum of timeseries data
function plotFFT(v,fs)
%plotFFT
%Plot the Fourier spectrum of a real-valued signal
%John J Davis IV
%john@johnjdavis.io
% Released under MIT license: https://opensource.org/licenses/MIT
% Input:
%
% v - (vector) signal