Help us understand the problem. What is going on with this article?

Rでデータの密度を見る(カーネル密度関数・ラグプロット)

tags: rBasicLearning

データの密度を見る

ヒストグラムを密度で表す

まずは, 一つ目のヒストグラムを描く.
freq = FALSEにすると, 度数ではなく, 密度で表示してくれる.

hist(lynx,
     breaks = 14,          # "Suggests" 14 bins
     freq   = FALSE,       # Axis shows density, not freq.
     col    = "thistle1",  # Color for histogram
     main   = "Histogram of Annual Canadian Lynx Trappings, 1821-1934",
     xlab   = "Number of Lynx Trapped")

正規分布を加える

次に, 正規分布を加える.
dnorm( x, mean=m, sd=n )で平均m、標準偏差nの正規分布確率密度を返す.
curve( dnorm(x), from=始点, to=終点 )で, from~toの範囲の標準正規分布を描画
add = TRUEで, 前のグラフに上から重ね書きする.

curve(dnorm(x, mean = mean(lynx), sd = sd(lynx)),
      col = "thistle4",  # Color of curve
      lwd = 2,           # Line width of 2 pixels
      add = TRUE)        # Superimpose on previous graph

カーネル密度推定を加える

また, カーネル密度推定を加える.
カーネル密度推定は, データの値の分布を連続した曲線で表す密度プロット.
ヒストグラムを滑らかにしたものとも考えられる.
ヒストグラムの縦軸を, 度数ではなく密度にする必要がある.

# Add kernel density estimators
lines(density(lynx), col = "blue", lwd = 2)

ラグプロット

ラグプロットは, 量的変数を縦軸に表したものである.
データの密度を知ることができる.
ヒストグラムを一次元にしたものとも捉えられる.

# Add a rug plot
rug(lynx, lwd = 2, col = "gray")

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした