Skip to content

Instantly share code, notes, and snippets.

View jcheong0428's full-sized avatar
🥕

Jin Hyun Cheong jcheong0428

🥕
View GitHub Profile
@jcheong0428
jcheong0428 / backpain_1.py
Created November 15, 2021 03:35
backpain_1.py
# Install pystan
!pip install -q pystan
# Install Facebook Prophet
!pip install -q fbprophet
# Download Google Trends data
!git clone https://gist.github.com/jcheong0428/838a1b1daf67473373da50627bc1bbda
!cp 838a1b1daf67473373da50627bc1bbda/*.csv .
import pandas as pd
import seaborn as sns
Month back pain lower back pain chiropractor near me
2013-01 67 69 0
2013-02 64 66 0
2013-03 66 67 0
2013-04 69 71 0
2013-05 69 70 1
2013-06 67 68 1
2013-07 74 77 1
2013-08 71 75 1
2013-09 69 70 2
@jcheong0428
jcheong0428 / sliceds01e01.ipynb
Last active June 7, 2021 01:21
SLICED-s01e01.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jcheong0428
jcheong0428 / multiTimeline.csv
Created April 6, 2021 13:47
googleTrends_backPain
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 4. in line 1.
Category: All categories
Month,back pain: (United States),lower back pain: (United States),neck pain: (United States)
2004-01,29,8,7
2004-02,31,7,9
2004-03,33,9,7
2004-04,30,7,7
2004-05,35,8,9
2004-06,37,10,7
2004-07,33,9,9
@jcheong0428
jcheong0428 / lmer-in-python.ipynb
Last active May 17, 2024 07:23
LMER in Python.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jcheong0428
jcheong0428 / lmer_pymer4.py
Last active March 20, 2021 06:02
LMER in Pymer4
# Install pymer4
!pip install -q pymer4
# load pymer4
from pymer4.models import Lmer
model = Lmer('Weight ~ Time + Evit + (1 + Time|Pig)', data=data)
display(model.fit())
# ANOVA results from fitted model
display(model.anova())
# Plot estimated model coefficients
model.plot_summary()
@jcheong0428
jcheong0428 / LMER_rpy2_addons.py
Created March 20, 2021 05:33
Manipulating data in R from rpy2
%%R -i data
# Specify Evit as a factor and set a polynomial contrast.
data$Evit <- as.factor(data$Evit)
contrasts(data$Evit) <- contr.poly
m<-lmer('Weight ~ Time * Evit + (1|Pig)', data=data)
print(summary(m))
# Relevel categorical data so base level is Evit100
m<-lmer('Weight ~ Time * relevel(Evit, ref="Evit100") + (1|Pig)', data=data)
print(summary(m))
@jcheong0428
jcheong0428 / lmer_rpy2_input_output
Created March 20, 2021 05:27
LMER in Rpy2 with input and outputs from notebook
%%R -i data -o betas
m<-lmer('Weight ~ Time + (1+Time|Pig)', data=data)
print(summary(m))
betas <- fixef(m)
@jcheong0428
jcheong0428 / lmer_rpy2.py
Created March 20, 2021 05:26
Run LMER using Rpy2
# make sure rpy2 was loaded using %load_ext rpy2.ipython
%%R
library(lme4)
library(lmerTest)
data(dietox, package='geepack')
m<-lmer('Weight ~ Time + (1+Time|Pig)', data=dietox)
print(summary(m))
@jcheong0428
jcheong0428 / install_r_rpy2_lmer_on_colab.py
Created March 20, 2021 05:24
Install R, Rpy2, LMER on Google Colab
!apt-get install r-base
!pip install -q rpy2
packnames = ('lme4', 'lmerTest', 'emmeans', "geepack")
from rpy2.robjects.packages import importr
from rpy2.robjects.vectors import StrVector
utils = importr("utils")
utils.chooseCRANmirror(ind=1)
utils.install_packages(StrVector(packnames))