This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# データフレーム全体を標準化 | |
mydf_standardized <- scale(mydf[,c(1:4)]) | |
is.data.frame(mydf_standardized) # FALSE | |
is.matrix(mydf_standardized) # TRUE | |
# [修正版]データフレーム全体を標準化 | |
mydf_standardized <- data.frame(scale(mydf[,c(1:4)])) | |
is.data.frame(mydf_standardized) # TRUE | |
is.matrix(mydf_standardized) # FALSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 再度インタラクションプロット作成 | |
fit_iris <- lm(Petal.Length ~ Petal.Width_centered * Species, data = mydf) | |
summary(fit_iris) | |
interact_plot(fit_iris, pred = Petal.Width_centered, modx = Species, plot.points = TRUE) # 成功 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 中心化済み変数の形式をチェック | |
is.numeric(mydf$Petal.Width_centered) # TRUE | |
is.vector(mydf$Petal.Width_centered) # FALSE | |
is.matrix(mydf$Petal.Width_centered) # TRUE | |
# データフレームに投入する直前にベクター形式に変換 | |
mydf$Petal.Width_centered <- as.vector(scale(mydf$Petal.Width, center = T, scale = F)) | |
is.numeric(mydf$Petal.Width_centered) # TRUE | |
is.vector(mydf$Petal.Width_centered) # TRUE | |
is.matrix(mydf$Petal.Width_centered) # FALSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# jtoolsをインストール&読み込み | |
wants <- c("jtools") | |
has <- wants %in% rownames(installed.packages()) | |
if(any(!has)) install.packages(wants[!has]) | |
# インタラクションプロット作成 | |
interact_plot(fit_iris, pred = Petal.Width_centered, modx = Species, plot.points = TRUE) | |
# エラー発生 | |
# Error: variable 'Petal.Width_centered' was fitted with type "nmatrix.1" but type "numeric" was supplied |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lm()を使って回帰分析 | |
fit_iris <- lm(Petal.Length ~ Petal.Width_centered * Species, data = mydf) | |
summary(fit_iris) | |
# plot()を使って散布図 | |
plot(mydf[,c("Petal.Width_centered","Petal.Length")]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# データフレームとしてirisを使用 | |
mydf <- iris | |
# scale()関数で中心化した変数を元のデータフレームに追加 | |
mydf$Petal.Width_centered <- scale(mydf$Petal.Width, center = T, scale = F) |