2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rでの単回帰分析テンプレート(グラフへの出力付き)

Last updated at Posted at 2020-02-25
tags: rBasicLearning

単回帰分析テンプレート

単回帰分析のテンプレートを, 以下に作りました!
宜しければ, 使ってください!

テンプレート

SLR <- function(X, Y){ # SimpleLinearRegression(単回帰分析)
  plot(X, Y) # 散布図を描く
  result <- lm(Y ~ X) # 回帰分析を行う
  abline(result) # 線を引く
  
  legend("topleft", # 相関係数を左上に貼り付ける
         legend= c(paste0("r : ", round(cor(X, Y), digits = 2)))) #小数点2桁で出力
}

具体例

X <- c(1, 3, 5, 7) # 自分の使いたいデータを入れてください
Y <- c(2, 5, 9, 11) # 自分の使いたいデータを入れてください

SLR(X, Y)

image.png
![](uploading-0
https://i.imgur.com/2KlZ9ZN.png)

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?