a <- read.csv("C:/Users/TIU sota kurihara/Downloads/heart.data.csv")
u <- a[ ,-1]
library(DT)
datatable(u)
cor(u$biking,u$smoking)
## [1] 0.01513618
cor(u$biking,u$heart.disease)
## [1] -0.9354555
cor(u$smoking,u$heart.disease)
## [1] 0.309131
r <- cor(u)
r
## biking smoking heart.disease
## biking 1.00000000 0.01513618 -0.9354555
## smoking 0.01513618 1.00000000 0.3091310
## heart.disease -0.93545547 0.30913098 1.0000000
#コメント
#bikingとsmokingの間には相関はない
#bikingとheart.diseaseの間には強い負の相関がある
#smokingとheart.diseaseの間には弱い正の相関がある
library(kableExtra)
kable(round(r, 2), caption = '相関表') |> kable_classic('striped', full_width = F)
相関表
|
biking
|
smoking
|
heart.disease
|
biking
|
1.00
|
0.02
|
-0.94
|
smoking
|
0.02
|
1.00
|
0.31
|
heart.disease
|
-0.94
|
0.31
|
1.00
|
library(psych)
pairs.panels(u)

cor.plot(u)

library(corrplot)
## corrplot 0.92 loaded
corrplot.mixed(r, lower = 'ellips', upper = 'number')

library(plotly)
## 要求されたパッケージ ggplot2 をロード中です
##
## 次のパッケージを付け加えます: 'ggplot2'
## 以下のオブジェクトは 'package:psych' からマスクされています:
##
## %+%, alpha
##
## 次のパッケージを付け加えます: 'plotly'
## 以下のオブジェクトは 'package:ggplot2' からマスクされています:
##
## last_plot
## 以下のオブジェクトは 'package:stats' からマスクされています:
##
## filter
## 以下のオブジェクトは 'package:graphics' からマスクされています:
##
## layout
kyokasho <- list(size = 11, color = 'blue', family = 'UD Digi Kyokasho NK-R')
plot_ly(x = rownames(r),
y = colnames(r),
z = as.matrix(r),
text = paste(r),
type = 'heatmap') |>
layout(font = kyokasho,
title = 'heartdisease',
xaxis = list(title = 'x'),
yaxis = list(title = 'y'))