Skip to content

Instantly share code, notes, and snippets.

@nozma
nozma / Sec4ans.R
Created July 25, 2016 13:44
カテゴリカルデータ解析第4章練習問題解答
# 練習問題
# 1.
Ctable <- xtabs(Freq ~ management + own, data = JobSatisfaction)
# (a)
chisq.test(Ctable)
# (b)
fisher.test(Ctable)
# 2.
Ctable <- xtabs(Freq ~ Sex + Survived, data = Titanic[,,"Child",])
@nozma
nozma / Sec6ans.R
Last active July 27, 2016 14:47
カテゴリカルデータ解析第6章練習問題解答
# 練習問題
# 1.
Titan <- data.frame(Titanic)
res <- glm(Survived ~ Class + Sex + Age, weights = Freq,
family = binomial, data = Titan)
res
summary(res)
exp(res$coefficients)
mosaicplot(Titanic, color = TRUE)
@nozma
nozma / Sec7ans.R
Created July 30, 2016 10:55
カテゴリカルデータ解析第7章練習問題解答
# 練習問題
# (a)
x <- c(314, 39, 78, 105, 77, 93, 140, 69)
pref <- c("A福岡", "B佐賀", "C長崎", "D熊本",
"E大分", "F宮崎", "G鹿児島", "H沖縄")
result <- glm(x ~ pref, family = poisson)
pred <- predict(result, type = "terms",
se.fit = TRUE)
ggplot(data.frame(pref, pred$fit), aes(x = pref, y = pred$fit)) +
geom_bar(stat = "identity") +
@nozma
nozma / Sec8ans.R
Created July 30, 2016 14:01
カテゴリカルデータ解析第8章練習問題解答
# 練習問題
# 1.
JointSports
result <- loglm(Freq ~ opinion * year * grade * gender, data = JointSports)
step(result)
step(result, k = log(sum(JointSports$Freq)))
mosaicplot(xtabs(Freq ~ year + grade + gender + opinion, data = JointSports))
# 2.
# (a)
tabledata <- xtabs(Freq ~ sex + method2 + age.group, data = Suicide)
@nozma
nozma / Sec10ans.R
Created August 7, 2016 13:01
カテゴリカルデータ解析第10章練習問題解答
# 1.
data("JointSports")
result <- ctree(opinion ~ year + grade + gender, data = JointSports,
weights = Freq)
plot(result)
# 2.
titan.d <- data.frame(Titanic)
head(titan.d)
result <- ctree(Survived ~ Class + Sex + Age, weights = Freq,
data = titan.d)
@nozma
nozma / file0.r
Created January 22, 2017 13:13
ggplot2で分割したグラフ毎に異なるtableGrobを書き込む ref: http://qiita.com/nozma/items/a87bbca80b77b3abd161
p <- ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(~drv) +
theme_bw() +
theme(panel.grid = element_blank()) +
geom_smooth(method = "lm")
@nozma
nozma / file0.r
Last active January 22, 2017 14:16
ggplot2における2軸プロットの使いみち ref: http://qiita.com/nozma/items/c50a8d45c73bf8b84794
library(ggplot2)
library(dplyr)
# hwy : highway miles per gallon
# 1mile == 1.60934km
# 1gallon == 3.78541L
# ∴ mile / gallon = 1.60934 / 3.78541 km / L
mpg2kpl <- function(x) x * 1.60934 / 3.78541
runner:
scopes:
python: "python3"
@nozma
nozma / file0.r
Last active April 30, 2017 10:40
Rで緯度経度から都道府県を求める ref: http://qiita.com/nozma/items/808bce2f496eabd50ff1
library(sf)
# 日本地図のシェープファイルを読み込む
f <- "N03-160101_GML/N03-16_160101.shp"
japan <- st_read(f)
@nozma
nozma / file0.txt
Last active July 26, 2017 15:06
AOL Reader向けの.vimperatorrc設定 ref: http://qiita.com/nozma/items/8e38c94943f616279f86
lazy fmaps -u='https?://reader\.aol\.co\.jp/.*' gh gs gd ga go gx ? r = - f u j k <Space> <S-Space> t v <Return> m 1 2 3 4 5 /
lazy fmaps -u='https?://reader\.aol\.co\.jp/.*' -events=vkeydown J K N P X O A