Skip to content

Instantly share code, notes, and snippets.

View syu-id's full-sized avatar

Shaoyun Yu syu-id

  • The Hong Kong Polytechnic University
  • Hong Kong SAR
View GitHub Profile
library(dplyr)
tokens <- read.csv('data/tokens.csv')
result <- tokens %>%
group_by(native, id) %>%
summarise(
n_token = length(token),
n_type = length(unique(token)),
ttr = n_type / n_token,
@syu-id
syu-id / LC-2015.11.27-ttr_gi.csv
Last active December 4, 2015 12:38
学習者コーパス論 2015.11.27 結果のCSV
native id n_token n_type ttr gi
591 365 144 0.394520547945205 7.53730448529908
en 501 738 361 0.489159891598916 13.2885936376732
en 502 636 340 0.534591194968553 13.4818769572084
en 503 834 353 0.42326139088729 12.2233903227874
en 504 824 336 0.407766990291262 11.7051146400992
en 505 898 393 0.437639198218263 13.1145798598269
en 506 834 341 0.408872901678657 11.8078643061488
en 507 600 264 0.44 10.777754868246
en 508 848 332 0.391509433962264 11.4009268077412
@syu-id
syu-id / LC-2015.12.04-awl_asl.R
Created December 5, 2015 06:33
学習者コーパス論 2015.12.04 AWL と ASL の計算
library(dplyr)
tokens <- read.csv('data/tokens.csv', as.is = TRUE)
result <- tokens %>%
group_by(native, id) %>%
summarise(
n_token = n(),
n_type = n_distinct(token),
@syu-id
syu-id / 2015.12.04-learner_corpus-2
Created December 5, 2015 17:57
2015.12.04-learner_corpus-2
トークン数と TTR について少し数学的に考えてみると、プロットの結果が当たり前のことです。
トークン数とタイプ数は線形的な関係にあると仮定します。
$$
type = \beta_0 + \beta_1 \cdot token
$$
$token = 1$ の場合、$type=1$ になるので、$\beta_0$ と $\beta_1$ の和が $1$ に決まっています。
@syu-id
syu-id / LC-2015.12.04-graph.R
Last active December 17, 2015 13:20
学習者コーパス論 2015.12.04 作図
library(dplyr)
library(ggplot2)
df <- read.csv('out/2015.12.04-awl_asl.csv')
df_plot <- df %>%
mutate(
native = plyr::revalue(native, c(en = 'L1 English ', ja='L1 Japanese'))
)
@syu-id
syu-id / LC-2015.12.11-graph.R
Last active December 17, 2015 13:54
学習者コーパス論 2015.12.11 作図
library(dplyr)
library(ggplot2)
library(scales)
df <- read.csv('out/2015.12.04-awl_asl.csv')
df_plot <- df %>%
mutate(
native = plyr::revalue(native, c(en = 'L1 English ', ja='L1 Japanese'))
@syu-id
syu-id / mattr.R
Last active May 20, 2016 11:32
RによるMATTRの実装 https://github.com/rongmu/mattr
# An alternative implementation of the MATTR algorithm in R
# author: Shaoyun YU <eric.rongmu@gmail.com>
# ref: Covington & Mcfall (2010) Cutting the Gordian Knot: The Moving-Average Type-Token Ratio
# usage: mattr(vector_of_tokens, window_size)
window_types <- function(i_start, win_size, data) {
i_end <- i_start + win_size - 1
win <- data[i_start:i_end]