myVoc <- function(){
files <- list.files()
for (i in files) {
lines.tmp <- scan(i, what="char", sep="\n")
body.tmp <- grep("^\\*\\w+:\t", lines.tmp, value=T)
data.tmp <- gsub("^\\*\\w+:\t", "", body.tmp)
data.tmp <- data.tmp[data.tmp != ""]
tmp4 <- gsub("[[:punct:]]", " ", data.tmp)
tmp5 <- gsub(" +", " ", tmp4)
tmp6 <- tolower(tmp5)
tmp7 <- strsplit(tmp6, " ")
tmp8 <- unlist(tmp7)
token <- sort(tmp8)
type <- unique(token)
ttr <- length(type)/length(token)
gi <- length(type)/sqrt(length(token))
cat(length(type), length(token), ttr, gi, "\n")
}
}
myVocSink <- function(){
sink("../myVocResult.txt")
files <- list.files()
for (i in files) {
lines.tmp <- scan(i, what="char", sep="\n")
body.tmp <- grep("^\\*\\w+:\t", lines.tmp, value=T)
data.tmp <- gsub("^\\*\\w+:\t", "", body.tmp)
data.tmp <- data.tmp[data.tmp != ""]
tmp4 <- gsub("[[:punct:]]", " ", data.tmp)
tmp5 <- gsub(" +", " ", tmp4)
tmp6 <- tolower(tmp5)
tmp7 <- strsplit(tmp6, " ")
tmp8 <- unlist(tmp7)
token <- sort(tmp8)
type <- unique(token)
ttr <- length(type)/length(token)
gi <- length(type)/sqrt(length(token))
cat(length(type), length(token), ttr, gi, "\n")
}
sink()
}
myIndexesDf <- function(){
# 各指標のベクトルを作っておいて、できたものをデータフレームにまとめる
# ベクトルの初期化
typeV <- c()
tokenV <- c()
ttrV <- c()
giV <- c()
awlV <- c()
aslV <- c()
nosV <- c()
files <- list.files()
for (i in files) {
lines.tmp <- scan(i, what="char", sep="\n")
body.tmp <- grep("^\\*\\w+:\t", lines.tmp, value=T)
data.tmp <- gsub("^\\*\\w+:\t", "", body.tmp)
data.tmp <- data.tmp[data.tmp != ""]
tmp4 <- gsub("[[:punct:]]", " ", data.tmp)
tmp5 <- gsub(" +", " ", tmp4)
tmp6 <- tolower(tmp5)
tmp7 <- strsplit(tmp6, " ")
tmp8 <- unlist(tmp7)
token <- sort(tmp8)
type <- unique(token)
ttr <- length(type)/length(token)
gi <- length(type)/sqrt(length(token))
tmp <- paste(token, collapse = "")
awl <- nchar(tmp)/length(token)
asl <- length(token)/length(data.tmp)
nos <- length(body.tmp) # Number of Sentences
# cat(length(type), length(token), ttr, gi, awl, asl,"\n")
# 各数値をベクトルに入れる
typeV <- c(typeV, length(type))
tokenV <- c(tokenV, length(token))
ttrV <- c(ttrV, ttr)
giV <- c(giV, gi)
awlV <- c(awlV, awl)
aslV <- c(aslV, asl)
nosV <- c(nosV, nos)
}
# 最後に全部をデータフレームにまとめる
data.frame(typeV, tokenV, ttrV, giV, awlV, aslV, nosV)
}
setwd("../NICER1_3_2/NICER_NS")
myIndexesDf()
setwd("../NICER1_3_2/NICER_NS")
indexes.df <- myIndexesDf()
indexes.df
head(indexes.df)
names(indexes.df) <- c("Type","Token","TTR","GI","AWL","ASL", "NoS")
head(indexes.df)
str(indexes.df)
## 'data.frame': 71 obs. of 7 variables:
## $ Type : int 359 343 356 340 396 337 264 334 370 300 ...
## $ Token: int 742 648 849 832 908 845 605 852 1092 763 ...
## $ TTR : num 0.484 0.529 0.419 0.409 0.436 ...
## $ GI : num 13.2 13.5 12.2 11.8 13.1 ...
## $ AWL : num 4.56 5.1 5.47 5.23 4.7 ...
## $ ASL : num 19 24.9 38.6 27.7 23.3 ...
## $ NoS : int 39 26 22 30 39 31 27 43 57 22 ...
indexes.df$Token
## [1] 742 648 849 832 908 845 605 852 1092 763 887 604 531 916 1154
## [16] 904 672 1158 2340 1133 965 1078 944 1094 1060 1496 977 974 805 1019
## [31] 943 1073 1346 893 1545 800 1080 1059 1091 1482 1024 1050 736 512 676
## [46] 1187 1197 559 1503 547 1163 456 1822 701 1037 891 1088 963 1187 714
## [61] 786 991 962 1181 966 1229 557 947 1133 965 1156
write.table(indexes.df, "indexes.df.txt", row.names=F)
summary(indexes.df)
## Type Token TTR GI
## Min. :222.0 Min. : 456.0 Min. :0.3116 Min. : 9.928
## 1st Qu.:336.5 1st Qu.: 802.5 1st Qu.:0.3608 1st Qu.:11.507
## Median :383.0 Median : 965.0 Median :0.4037 Median :12.288
## Mean :387.3 Mean : 986.5 Mean :0.4044 Mean :12.376
## 3rd Qu.:428.0 3rd Qu.:1113.5 3rd Qu.:0.4362 3rd Qu.:13.269
## Max. :761.0 Max. :2340.0 Max. :0.5293 Max. :15.732
## AWL ASL NoS
## Min. :4.013 Min. :11.75 Min. : 22.00
## 1st Qu.:4.572 1st Qu.:19.10 1st Qu.: 34.50
## Median :4.774 Median :21.93 Median : 43.00
## Mean :4.751 Mean :22.59 Mean : 45.66
## 3rd Qu.:4.900 3rd Qu.:25.00 3rd Qu.: 50.50
## Max. :5.571 Max. :38.59 Max. :155.00
summary(indexes.df$Token)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 456.0 802.5 965.0 986.5 1113.5 2340.0
• 真ん中の太い線:中央値 Median(50%)、平均ではないので注意
• 箱の範囲:25%から75%の範囲(これを四分範囲と呼ぶ)
(つまり、半分のデータはこの範囲に入る)
• ひげの範囲:箱の端から箱の長さの1.5倍以内にある「実際の」数値の最大値と最小値
• 外れている○印:外れ値(ひげの範囲外のもの)
boxplot(indexes.df)
boxplot(indexes.df$Type, indexes.df$Token)
plot(indexes.df)
plot(indexes.df$Type, indexes.df$Token)
barplot(indexes.df$Token)
barplot(sort(indexes.df$Token))
hist(indexes.df$Token)
plot(indexes.df$Token, indexes.df$TTR)
plot(indexes.df$Token, indexes.df$TTR)
abline(lm(indexes.df$TTR~indexes.df$Token))
plot(indexes.df$Token, indexes.df$GI)
abline(lm(indexes.df$GI~indexes.df$Token))
plot(indexes.df$Token, indexes.df$TTR)
abline(lm(indexes.df$TTR~indexes.df$Token))
par(new=T)
plot(indexes.df$Token, indexes.df$GI, col="red")
abline(lm(indexes.df$GI~indexes.df$Token), col="red")
Michael A. Covington & Joe D. McFall (2010) Cutting the Gordian Knot: The Moving-Average Type–Token Ratio (MATTR), Journal of Quantitative Linguistics, 17:2, 94-100, DOI: 10.1080/09296171003643098
# 阿部大輔 2014, 杉浦正利 2020 NICER用に話者記号の削除・修正
mattr <- function () {
wttr <- 0
ttrsum <- 0
lines.tmp <- scan(choose.files(), what="char", sep="\n")
# body部分の抽出と話者記号と句読点の削除
body.tmp <- grep("^\\*\\w+:\t", lines.tmp, value=T)
data.tmp <- gsub("^\\*\\w+:\t", "", body.tmp)
data.tmp <- data.tmp[data.tmp != ""]
tmp4 <- gsub("[[:punct:]]", " ", data.tmp)
tmp5 <- gsub(" +", " ", tmp4)
token <- tolower(unlist(strsplit(tmp5, "\\W+")))
numwords <- length(token) # 元々の語数を記録しておく
token <- c(token,token) # yを一周するとまた先頭の語が出てくるようにyとyをつなげる
for(i in 1:numwords){ #↑で記録した総語数の回数ループする
mado <- token[i:(99+i)] # 100語の幅で順に右にずらしていく
wttr <- length(unique(sort(mado)))/100 #100語ずつ=tokenが100
ttrsum <- ttrsum + wttr # 出てきたTTRを足していく
}
ttrsum/numwords # 総TTR数を総語数の回数で割って平均を出す
}
#setwd("NICER1_3/NICER_NS")
mattr()
mattr2 <- function () {
mattrV <- c() # ベクトルデータの準備
wttr <- 0
ttrsum <- 0
files <- list.files() # ファイルのリスト
for (i in files) { # すべてのファイルに対して
lines.tmp <- scan(i, what="char", sep="\n")
body.tmp <- grep("^\\*\\w+:\t", lines.tmp, value=T)
data.tmp <- gsub("^\\*\\w+:\t", "", body.tmp)
data.tmp <- data.tmp[data.tmp != ""]
tmp4 <- gsub("[[:punct:]]", " ", data.tmp)
tmp5 <- gsub(" +", " ", tmp4)
token <- tolower(unlist(strsplit(tmp5, "\\W+")))
numwords <- length(token) # 元々の語数を記録しておく
token <- c(token,token) # yを一周するとまた先頭の語が出てくるようにyとyをつなげる
for(i in 1:numwords){ #↑で記録した総語数の回数ループする
mado <- token[i:(99+i)] # 100語の幅で順に右にずらしていく
wttr <- length(unique(sort(mado)))/100 #100語ずつ=tokenが100
ttrsum <- ttrsum + wttr # 出てきたTTRを足していく
}
#ttrsum/numwords # 総TTR数を総語数の回数で割って平均を出す
mattr <- ttrsum/numwords # mattrに代入
mattrV <- c(mattrV, mattr) # ベクトルデータとして保存
} # forに対応して閉じる
mattrV # ベクトルデータを表示・出力
}
#setwd("NICER1_3/NICER_NS") # 母語話者データ
#setwd("NICER1_3/NICER_NNS") # 学習者データ
mattr2()
setwd("../NICER1_3_2/NICER_NS")
mattr <- mattr2()
indexes.df2 <- data.frame(indexes.df, mattr) #
head(indexes.df2)
plot(indexes.df2$Token, indexes.df2$mattr)
abline(lm(indexes.df2$mattr~indexes.df2$Token))
plot(indexes.df$Token, indexes.df$TTR)
abline(lm(indexes.df$TTR~indexes.df$Token))
par(new=T)
plot(indexes.df$Token, indexes.df$GI, col="red")
abline(lm(indexes.df$GI~indexes.df$Token), col="red")
par(new=T)
plot(indexes.df2$Token, indexes.df2$mattr, col="blue")
abline(lm(indexes.df2$mattr~indexes.df2$Token), col="blue")
@Begin
@Participants: JPN501
@PID: PIDJP501
@Age: 21
@Sex: F
@YearInSchool: U2
@Major: agriculture
@StudyHistory: 8
@OtherLanguage: Chinese=1.0;none=
@Qualification: TOEIC=590(2013);none=;none=
@Abroad: none=;none=
@Reading: 3
@Writing: 2
@Listening: 2
@Speaking: 1
@JapaneseEssay: 4
@EnglishEssayEx: 3
@EnglishEssay: 2
@Difficulty:
@EssayTraining: 3
@SelfEval: 2
@TopicEase: 4
@Topic: sports
@Criterion: 4
@Proctor: 1
@Comments:
@Date: 2013-12-17
@Version: 1.3
@Begin
@Participants: NS501
@PID: PIDNS501
@Age: 27
@Sex: M
@L1: AmE
@FatherL1: none
@MotherL1: none
@AcademicBackground: M1
@OtherLanguage: Japanese=0.7=good;none==
@Topic: education
@EnglishEssay: 5
@SelfEval: 1
@TopicEase: 3
@EssayTraining: 5
@Proctor: 1
@Criterion: 5
@Comments:
@Date: 2013-12-02
@Version: 1.3
criterion.tmp <- grep("@Criterion", lines.tmp, value = T)
score <- gsub("@Criterion:\t", "", criterion.tmp)
setwd("../NICER1_3_2/NICER_NS")
myScore <- function(){
scoreV <- c() # ベクトルscoreVの初期化
files <- list.files()
for (i in files) {
lines.tmp <- scan(i, what="char", sep="\n")
criterion.tmp <- grep("@Criterion", lines.tmp, value = T) # @Criterionの行を検索
score <- gsub("@Criterion:\t", "", criterion.tmp) # スコアのみに
scoreV <- c(scoreV , score) # ベクトルデータとして保存
}
scoreV
}
setwd("NICER1_3/NICER_NS")
myScore()
setwd("../NICER1_3_2/NICER_NS")
score <- myScore()
indexes.df3 <- data.frame(indexes.df2, score)
head(indexes.df3)
setwd("../NICER1_3_2/NICER_NS")
myID <- function(){
idV <- c() # ベクトルidVの初期化
files <- list.files()
for (i in files) {
lines.tmp <- scan(i, what="char", sep="\n")
id.tmp <- grep("@Participants:", lines.tmp, value = T) # @Participantsの行を検索
id <- gsub("@Participants:\t", "", id.tmp) # IDのみに
idV <- c(idV , id) # ベクトルデータとして保存
}
idV
}
setwd("../NICER1_3_2/NICER_NS")
id <- myID()
indexes.df4 <- data.frame(indexes.df3, id)
head(indexes.df4)
plot(indexes.df4)
myNICERindex <- function(){
# 各指標のベクトルを作っておいて、できたものをデータフレームにまとめる
# ベクトルの初期化
typeV <- c()
tokenV <- c()
ttrV <- c()
giV <- c()
awlV <- c()
aslV <- c()
nosV <- c()
mattrV <- c() # MATTR追加 以下同じ
scoreV <- c()
idV <- c()
topicV <- c()
files <- list.files()
for (i in files) {
lines.tmp <- scan(i, what="char", sep="\n")
body.tmp <- grep("^\\*\\w+:\t", lines.tmp, value=T)
data.tmp <- gsub("^\\*\\w+:\t", "", body.tmp)
data.tmp <- data.tmp[data.tmp != ""]
tmp4 <- gsub("[[:punct:]]", " ", data.tmp)
tmp5 <- gsub(" +", " ", tmp4)
tmp6 <- tolower(tmp5)
tmp7 <- strsplit(tmp6, " ")
tmp8 <- unlist(tmp7)
token <- sort(tmp8)
type <- unique(token)
ttr <- length(type)/length(token)
gi <- length(type)/sqrt(length(token))
tmp <- paste(token, collapse = "")
awl <- nchar(tmp)/length(token)
asl <- length(token)/length(data.tmp)
nos <- length(body.tmp) # Number of Sentences
#MATTR 追加
numwords <- length(token)
token <- c(token,token)
ttrsum <- 0 # ttrsum の初期化
mattr <- 0 # mattr の初期化
for(i in 1:numwords){
mado <- token[i:(99+i)]
wttr <- length(unique(sort(mado)))/100
ttrsum <- ttrsum + wttr
}
mattr <- ttrsum/numwords # mattrに代入
mattrV <- c(mattrV, mattr) # ベクトルデータとして保存
#スコア 追加
criterion.tmp <- grep("@Criterion", lines.tmp, value = T) # @Criterionの行を検索
score <- gsub("@Criterion:\t", "", criterion.tmp) # スコアのみに
scoreV <- c(scoreV , score) # ベクトルデータとして保存
#ID 追加
id.tmp <- grep("@Participants:", lines.tmp, value = T) # @Participantsの行を検索
id <- gsub("@Participants:\t", "", id.tmp) # IDのみに
idV <- c(idV , id) # ベクトルデータとして保存
#Topic 追加
topic.tmp <- grep("@Topic:", lines.tmp, value = T) # @Participantsの行を検索
topic <- gsub("@Topic:\t", "", topic.tmp) # IDのみに
topicV <- c(topicV , topic) # ベクトルデータとして保存
# 各数値をベクトルに入れる
typeV <- c(typeV, length(type))
tokenV <- c(tokenV, length(token))
ttrV <- c(ttrV, ttr)
giV <- c(giV, gi)
awlV <- c(awlV, awl)
aslV <- c(aslV, asl)
nosV <- c(nosV, nos)
}
# 最後に全部をデータフレームにまとめる
data.frame(idV, topicV, scoreV, typeV, tokenV, ttrV, giV, mattrV, awlV, aslV, nosV)
}
setwd("../NICER1_3_2/NICER_NS")
ns_indexes.df <- myNICERindex()
head(ns_indexes.df )
names(ns_indexes.df ) <- c("ID", "Topic", "Score", "Type", "Token", "TTR", "GI", "MATTR", "AWL","ASL", "NoS")
head(ns_indexes.df )
setwd("../NICER1_3_2/NICER_NNS") # ディレクトリーを変える NNS
jp_indexes.df <- myNICERindex()
names(jp_indexes.df ) <- c("ID", "Topic", "Score", "Type", "Token", "TTR", "GI", "MATTR", "AWL","ASL", "NoS")
head(jp_indexes.df )
統合した後、カテゴリーでデータを分けることができるように
新しいカラムを追加:使ってない見出しを設定し、そこに入れたいものを代入
jp_indexes.df$Lang <- 2
head(jp_indexes.df)
ns_indexes.df$Lang <- 1
head(ns_indexes.df)
all_indexes.df <- rbind(jp_indexes.df, ns_indexes.df)
head(all_indexes.df)
tail(all_indexes.df)
str(all_indexes.df)
## 'data.frame': 452 obs. of 12 variables:
## $ ID : chr "JPN501" "JPN502" "JPN503" "JPN504" ...
## $ Topic: chr "sports" "education" "education" "sports" ...
## $ Score: chr "4" "4" "3" "4" ...
## $ Type : int 134 160 121 139 175 124 151 98 104 99 ...
## $ Token: int 638 712 402 520 840 522 724 396 526 366 ...
## $ TTR : num 0.42 0.449 0.602 0.535 0.417 ...
## $ GI : num 7.5 8.48 8.53 8.62 8.54 ...
## $ MATTR: num 0.426 0.455 0.606 0.539 0.423 ...
## $ AWL : num 4.3 4.23 4.75 4.77 4 ...
## $ ASL : num 10.63 12.28 15.46 9.63 16.8 ...
## $ NoS : int 30 29 13 27 25 20 26 20 19 14 ...
## $ Lang : num 2 2 2 2 2 2 2 2 2 2 ...
plot(all_indexes.df)
ID_S_L <- data.frame(all_indexes.df$ID, all_indexes.df$Score, all_indexes.df$Lang)
head(ID_S_L)
subset(all_indexes.df, Score == 6)
subset(all_indexes.df, Score <= 2)
subset(all_indexes.df, Score == 6 & Lang == 2)
subset(all_indexes.df, Score == 5 & Lang == 2)
subset(all_indexes.df, Score == 5 & Lang == 2 & (Topic == "sports" | Topic == "money" ))
subset(all_indexes.df, Score == 5 & Lang == 2 & Topic != "education")
L2token <- subset(all_indexes.df, Lang == 2, select = c(Score, Token))
str(L2token)
## 'data.frame': 381 obs. of 2 variables:
## $ Score: chr "4" "4" "3" "4" ...
## $ Token: int 638 712 402 520 840 522 724 396 526 366 ...
head(L2token)
plot(L2token)
## Warning in xy.coords(x, y, xlabel, ylabel, log): 強制変換により NA が生成されま
## した
plot(L2token$Token, L2token$Score)
## Warning in xy.coords(x, y, xlabel, ylabel, log): 強制変換により NA が生成されま
## した
str(L2token)
## 'data.frame': 381 obs. of 2 variables:
## $ Score: chr "4" "4" "3" "4" ...
## $ Token: int 638 712 402 520 840 522 724 396 526 366 ...
L2token$Score <- as.numeric(L2token$Score)
## Warning: 強制変換により NA が生成されました
str(L2token)
## 'data.frame': 381 obs. of 2 variables:
## $ Score: num 4 4 3 4 4 3 4 3 4 3 ...
## $ Token: int 638 712 402 520 840 522 724 396 526 366 ...
cor.test(L2token$Score, L2token$Token)
##
## Pearson's product-moment correlation
##
## data: L2token$Score and L2token$Token
## t = 27.644, df = 377, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.7820537 0.8490645
## sample estimates:
## cor
## 0.8183211
plot(L2token$Token, L2token$Score)
abline(lm(L2token$Score~L2token$Token))
y = ax + b
lm(目的変数 ~ 説明変数, データ)
因果関係が想定されている。xが増えると、その結果yが増える。
yが増える要因(原因)は一つxだけ。(単回帰分析)
jp_indexes.df$Score <- as.numeric(jp_indexes.df$Score)
## Warning: 強制変換により NA が生成されました
plot(Score ~ Token, jp_indexes.df)
lm.result <- lm(Score ~ Token, jp_indexes.df)
abline(lm.result)
summary(lm.result)
##
## Call:
## lm(formula = Score ~ Token, data = jp_indexes.df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.5569 -0.2748 0.0109 0.2933 1.3232
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.6669449 0.0708166 23.54 <2e-16 ***
## Token 0.0033220 0.0001202 27.64 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4396 on 377 degrees of freedom
## ( 2 個の観測値が欠損のため削除されました )
## Multiple R-squared: 0.6696, Adjusted R-squared: 0.6688
## F-statistic: 764.2 on 1 and 377 DF, p-value: < 2.2e-16
http://sugiura-ken.org/wiki/wiki.cgi/exp?page=Multiple+Regression+Analysis
y = ax1 + bx2 + cx3 + ... + e
yが増える原因は複数ある。複数の要因が影響した結果がyとなる。
関数は lm()
lm(目的変数 ~ 説明変数1 + 説明変数2 + 説明変数3 + … , データ)
lm(Score ~ Token + Type + TTR + GI + MATTR + AWL + ASL + NoS, jp_indexes.df)
##
## Call:
## lm(formula = Score ~ Token + Type + TTR + GI + MATTR + AWL +
## ASL + NoS, data = jp_indexes.df)
##
## Coefficients:
## (Intercept) Token Type TTR GI MATTR
## -0.535503 0.001256 -0.008998 -9.016308 0.577063 2.682524
## AWL ASL NoS
## 0.506956 0.041955 0.013926
データが前提としている確率分布(この場合は正規分布)に従っているか
重回帰分析では、目的変数の誤差(説明変数からのズレ)が正規分布に従っているという前提
Normal Q-Q プロットで確認 ** Y軸:観測データの標準化残差 ** X軸:期待値
hist(jp_indexes.df$Score)
qqnorm(jp_indexes.df$Score) # 散布図
qqline(jp_indexes.df$Score) # 直線
lm(Score ~ scale(Token) + scale(Type) + scale(TTR) + scale(GI) + scale(MATTR) + scale(AWL) + scale(ASL) + scale(NoS), jp_indexes.df)
##
## Call:
## lm(formula = Score ~ scale(Token) + scale(Type) + scale(TTR) +
## scale(GI) + scale(MATTR) + scale(AWL) + scale(ASL) + scale(NoS),
## data = jp_indexes.df)
##
## Coefficients:
## (Intercept) scale(Token) scale(Type) scale(TTR) scale(GI)
## 3.52043 0.23632 -0.29043 -0.59159 0.55935
## scale(MATTR) scale(AWL) scale(ASL) scale(NoS)
## 0.17387 0.17130 0.11596 0.09719
install.packages("car", repos="http://cran.rstudio.com/")
library(car)
## 要求されたパッケージ carData をロード中です
jukaiki.result <- lm(Score ~ scale(Token) + scale(Type) + scale(TTR) + scale(GI) + scale(MATTR) + scale(AWL) + scale(ASL) + scale(NoS), jp_indexes.df)
vif(jukaiki.result)
## scale(Token) scale(Type) scale(TTR) scale(GI) scale(MATTR) scale(AWL)
## 101.018056 291.500537 474.789406 135.912033 512.414581 1.125987
## scale(ASL) scale(NoS)
## 12.071882 25.998623
jukaiki.result2 <- lm(Score ~ scale(Token) + scale(Type) + scale(MATTR) + scale(AWL) + scale(ASL) + scale(NoS), jp_indexes.df)
vif(jukaiki.result2)
## scale(Token) scale(Type) scale(MATTR) scale(AWL) scale(ASL) scale(NoS)
## 41.462335 20.388950 6.864829 1.117988 11.244092 24.131301
jukaiki.result3 <- lm(Score ~ scale(Token) + scale(MATTR) + scale(AWL) + scale(ASL) + scale(NoS), jp_indexes.df)
vif(jukaiki.result3)
## scale(Token) scale(MATTR) scale(AWL) scale(ASL) scale(NoS)
## 24.554126 1.756094 1.117927 10.574447 22.395073
jukaiki.result4 <- lm(Score ~ scale(Token) + scale(MATTR) + scale(AWL) + scale(ASL), jp_indexes.df)
vif(jukaiki.result4)
## scale(Token) scale(MATTR) scale(AWL) scale(ASL)
## 1.812922 1.750001 1.117058 1.210238
lm(Score ~ scale(Token) + scale(MATTR) + scale(AWL) + scale(ASL), jp_indexes.df)
##
## Call:
## lm(formula = Score ~ scale(Token) + scale(MATTR) + scale(AWL) +
## scale(ASL), data = jp_indexes.df)
##
## Coefficients:
## (Intercept) scale(Token) scale(MATTR) scale(AWL) scale(ASL)
## 3.520855 0.625732 0.006836 0.176912 0.051028
summary(jukaiki.result4)
##
## Call:
## lm(formula = Score ~ scale(Token) + scale(MATTR) + scale(AWL) +
## scale(ASL), data = jp_indexes.df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.38673 -0.25294 -0.00528 0.25302 1.15642
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.520855 0.020380 172.763 < 2e-16 ***
## scale(Token) 0.625732 0.027469 22.779 < 2e-16 ***
## scale(MATTR) 0.006836 0.027054 0.253 0.8006
## scale(AWL) 0.176912 0.021538 8.214 3.53e-15 ***
## scale(ASL) 0.051028 0.022397 2.278 0.0233 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3967 on 374 degrees of freedom
## ( 2 個の観測値が欠損のため削除されました )
## Multiple R-squared: 0.7331, Adjusted R-squared: 0.7302
## F-statistic: 256.8 on 4 and 374 DF, p-value: < 2.2e-16
jukaiki.result5 <- lm(Score ~ scale(Token) + scale(AWL) + scale(ASL), jp_indexes.df)
summary(jukaiki.result5)
##
## Call:
## lm(formula = Score ~ scale(Token) + scale(AWL) + scale(ASL),
## data = jp_indexes.df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.37835 -0.25224 -0.00619 0.25823 1.16749
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.52086 0.02035 172.979 < 2e-16 ***
## scale(Token) 0.62168 0.02227 27.911 < 2e-16 ***
## scale(AWL) 0.17830 0.02080 8.571 2.72e-16 ***
## scale(ASL) 0.05083 0.02236 2.274 0.0236 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3963 on 375 degrees of freedom
## ( 2 個の観測値が欠損のため削除されました )
## Multiple R-squared: 0.733, Adjusted R-squared: 0.7309
## F-statistic: 343.2 on 3 and 375 DF, p-value: < 2.2e-16
説明変数をすべて入れたモデル
欠損値があるとsetp関数がエラーになるので、na.omit()でデータフレームを処置しておく
jukaiki.result <- step(lm(Score ~ scale(Token) + scale(Type) + scale(TTR) + scale(GI) + scale(MATTR) + scale(AWL) + scale(ASL) + scale(NoS), na.omit(jp_indexes.df)))
## Start: AIC=-740.94
## Score ~ scale(Token) + scale(Type) + scale(TTR) + scale(GI) +
## scale(MATTR) + scale(AWL) + scale(ASL) + scale(NoS)
##
## Df Sum of Sq RSS AIC
## - scale(MATTR) 1 0.0222 51.187 -742.77
## - scale(Type) 1 0.1096 51.275 -742.13
## - scale(NoS) 1 0.1373 51.303 -741.92
## - scale(Token) 1 0.2091 51.374 -741.39
## <none> 51.165 -740.94
## - scale(TTR) 1 0.2774 51.443 -740.89
## - scale(ASL) 1 0.4230 51.588 -739.82
## - scale(GI) 1 0.8721 52.037 -736.53
## - scale(AWL) 1 9.8783 61.044 -676.03
##
## Step: AIC=-742.77
## Score ~ scale(Token) + scale(Type) + scale(TTR) + scale(GI) +
## scale(AWL) + scale(ASL) + scale(NoS)
##
## Df Sum of Sq RSS AIC
## - scale(NoS) 1 0.1434 51.331 -743.71
## - scale(Type) 1 0.1467 51.334 -743.69
## - scale(Token) 1 0.2294 51.417 -743.08
## <none> 51.187 -742.77
## - scale(ASL) 1 0.4373 51.625 -741.55
## - scale(GI) 1 1.0482 52.236 -737.09
## - scale(TTR) 1 3.7103 54.898 -718.25
## - scale(AWL) 1 10.0173 61.205 -677.04
##
## Step: AIC=-743.71
## Score ~ scale(Token) + scale(Type) + scale(TTR) + scale(GI) +
## scale(AWL) + scale(ASL)
##
## Df Sum of Sq RSS AIC
## - scale(Type) 1 0.2030 51.534 -744.22
## <none> 51.331 -743.71
## - scale(Token) 1 0.6320 51.963 -741.08
## - scale(ASL) 1 0.9065 52.237 -739.08
## - scale(GI) 1 1.3288 52.660 -736.03
## - scale(TTR) 1 4.8778 56.209 -711.31
## - scale(AWL) 1 10.0497 61.380 -677.95
##
## Step: AIC=-744.22
## Score ~ scale(Token) + scale(TTR) + scale(GI) + scale(AWL) +
## scale(ASL)
##
## Df Sum of Sq RSS AIC
## <none> 51.534 -744.22
## - scale(Token) 1 0.8577 52.392 -739.96
## - scale(ASL) 1 0.9203 52.454 -739.51
## - scale(TTR) 1 5.9727 57.507 -704.66
## - scale(GI) 1 7.3450 58.879 -695.72
## - scale(AWL) 1 10.2535 61.787 -677.44
summary(jukaiki.result)
##
## Call:
## lm(formula = Score ~ scale(Token) + scale(TTR) + scale(GI) +
## scale(AWL) + scale(ASL), data = na.omit(jp_indexes.df))
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.32107 -0.24903 -0.01515 0.25641 1.49021
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.52243 0.01909 184.489 < 2e-16 ***
## scale(Token) 0.16837 0.06758 2.492 0.0132 *
## scale(TTR) -0.39965 0.06078 -6.575 1.64e-10 ***
## scale(GI) 0.39869 0.05468 7.291 1.85e-12 ***
## scale(AWL) 0.17389 0.02019 8.615 < 2e-16 ***
## scale(ASL) 0.05430 0.02104 2.581 0.0102 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3717 on 373 degrees of freedom
## Multiple R-squared: 0.7663, Adjusted R-squared: 0.7632
## F-statistic: 244.7 on 5 and 373 DF, p-value: < 2.2e-16
jukaiki.best.result <- lm(formula = Score ~ scale(TTR) + scale(GI) + scale(AWL) + scale(ASL) +
scale(NoS), data = jp_indexes.df)
vif(jukaiki.best.result)
## scale(TTR) scale(GI) scale(AWL) scale(ASL) scale(NoS)
## 10.013866 8.159103 1.114485 5.472266 11.398238
par(mfrow=c(2,2),oma = c(1,1,2,1),mar = c(4, 4, 2, 1))
plot(jukaiki.best.result)