x <- 1:30
y <- seq(1, 300, 10) + rnorm(30)
y[5] <- y[5] + 10
y[10] <- y[10] + 5
y[25] <- y[25] - 10
fit <- lm(y ~ x)
plot(fit)




x <- 1:30
y <- seq(1, 300, 10) + rnorm(30)
y[5] <- y[5] + 20
y[10] <- y[10] + 15
y[25] <- y[25] - 20
fit <- lm(y ~ x)
plot(fit)




x <- 1:30
y <- seq(1, 300, 10) + rnorm(30)
y[5] <- y[5] + 30
y[10] <- y[10] + 25
y[25] <- y[25] - 30
fit <- lm(y ~ x)
plot(fit)




x <- 1:30
y <- seq(1, 300, 10) + rnorm(30)
y[5] <- y[5] + 40
y[10] <- y[10] + 35
y[25] <- y[25] - 40
fit <- lm(y ~ x)
plot(fit)




x <- 1:30
y <- seq(1, 300, 10) + rnorm(30)
y[5] <- y[5] + 50
y[10] <- y[10] + 45
y[25] <- y[25] - 50
fit <- lm(y ~ x)
plot(fit)




x <- 1:30
y <- seq(1, 300, 10) + rnorm(30)
y[5] <- y[5] + 60
y[10] <- y[10] + 55
y[25] <- y[25] - 60
fit <- lm(y ~ x)
plot(fit)




d <- read.csv('https://stats.dip.jp/01_ds/data/heart.data.csv')[, -1]
library(DT)
datatable(round(d, 1))
# カラーパレット
COL <- c(rgb(255, 0, 0, 255, max = 255), # 赤
rgb( 0, 0, 255, 255, max = 255), # 青
rgb( 0, 155, 0, 255, max = 255)) # 緑
library(psych)
pairs.panels(d)

#install.packages("ggcorrplot")
library(ggcorrplot)
## 要求されたパッケージ ggplot2 をロード中です
##
## 次のパッケージを付け加えます: 'ggplot2'
## 以下のオブジェクトは 'package:psych' からマスクされています:
##
## %+%, alpha
library(plotly)
##
## 次のパッケージを付け加えます: 'plotly'
## 以下のオブジェクトは 'package:ggplot2' からマスクされています:
##
## last_plot
## 以下のオブジェクトは 'package:stats' からマスクされています:
##
## filter
## 以下のオブジェクトは 'package:graphics' からマスクされています:
##
## layout
cor(d) |> ggcorrplot(lab = T, hc.order = T, outline.color = "white", p.mat = cor_pmat(d)) |> ggplotly() |>
layout(font = list(size = 11, color = 'blue', family = 'UD Digi Kyokasho NK-R'),
title = '主タイトル',
xaxis = list(title = 'x軸カテゴリラベル'),
yaxis = list(title = 'y軸カテゴリラベル'))
fit <- lm(heart.disease ~ biking + smoking, data = d)
#summary(fit)
library(sjPlot)
tab_model(fit, show.stat = T, show.aic = T)
|
|
heart.disease
|
|
Predictors
|
Estimates
|
CI
|
Statistic
|
p
|
|
(Intercept)
|
14.98
|
14.83 – 15.14
|
186.99
|
<0.001
|
|
biking
|
-0.20
|
-0.20 – -0.20
|
-146.53
|
<0.001
|
|
smoking
|
0.18
|
0.17 – 0.19
|
50.39
|
<0.001
|
|
Observations
|
498
|
|
R2 / R2 adjusted
|
0.980 / 0.980
|
|
AIC
|
995.353
|
plot_model(fit, show.values = T, show.intercept = T, width = 0.1)

plot(fit)




d <- read.csv('https://stats.dip.jp/01_ds/data/real_estate_price.csv')
datatable(round(d, 1))