포인트 클라우드에 대해 r에서 jitter 기능을 사용하는 방법


이 튜토리얼에서는 포인트 클라우드에 대해 R에서 지터 기능을 사용하는 시기와 방법을 설명합니다.

지터를 사용해야 하는 경우

산점도는 두 연속 변수 간의 관계를 시각화하는 데 탁월합니다. 예를 들어, 다음 산점도는 운동선수 100명의 키와 몸무게 사이의 관계를 시각화하는 데 도움이 됩니다.

 #define vectors of heights and weights
weights <- runif(100, 160, 240) 
heights <- (weights/3) + rnorm(100)

#create data frame of heights and weights
data <- as.data.frame(cbind(weights, heights))

#view first six rows of data frame
head(data)

# weights heights
#1 170.8859 57.20745
#2 183.2481 62.01162
#3 235.6884 77.93126
#4 231.9864 77.12520
#5 200.8562 67.93486
#6 169.6987 57.54977
#create scatterplot of heights vs weights
plot(data$weights, data$heights, pch = 16, col = 'steelblue')

그러나 때로는 연속형 변수와 거의 연속형인 다른 변수 사이의 관계를 시각화하고 싶을 수도 있습니다.

예를 들어, 농구 선수가 시즌의 처음 10경기 동안 시작한 경기 수와 경기당 평균 점수를 보여주는 다음 데이터 세트가 있다고 가정해 보겠습니다.

 #create data frame
games_started <- sample(1:10, 300, TRUE)
points_per_game <- 3*games_started + rnorm(300)
data <- as.data.frame(cbind(games_started, points_per_game))

#view first six rows of data frame
head(data)

# games_started points_per_game
#1 9 25.831554
#2 9 26.673983
#3 10 29.850948
#4 4 12.024353
#5 4 11.534192
#6 1 4.383127

게임당 점수 는 연속형 변수이지만 시작된 게임은 이산형 변수입니다. 이 두 변수의 산점도를 만들려고 하면 다음과 같습니다.

 #create scatterplot of games started vs average points per game
plot(data$games_started, data$points_per_game, pch = 16, col = 'steelblue')

이 산점도에서 우리는 시작된 게임게임당 평균 점수가 양의 관계를 가지고 있다고 말할 수 있지만, 많은 부분이 겹치기 때문에 플롯의 개별 점수를 확인하기가 약간 어렵습니다.

Jitter 기능을 사용하면 던져진 X축 변수 세트 에 약간의 “노이즈”를 추가하여 플롯의 개별 지점을 더 명확하게 볼 수 있습니다.

 #add jitter to games started
plot( jitter (data$games_started), data$points_per_game, pch = 16, col = 'steelblue')

선택적으로 지터에 숫자 인수를 추가하여 데이터에 더 많은 노이즈를 추가할 수 있습니다.

 #add jitter to games started
plot( jitter (data$games_started, 2 ), data$points_per_game, pch = 16, col = 'steelblue')

그러나 너무 많은 지터를 추가하지 않도록 주의해야 합니다. 이렇게 하면 원본 데이터가 너무 많이 왜곡될 수 있습니다.

 plot( jitter (data$games_started, 20 ), data$points_per_game, pch = 16, col = 'steelblue')

지터링은 데이터에 대한 더 나은 보기를 제공합니다.

불안정성은 이산변수의 수준 중 하나가 다른 수준보다 더 많은 값을 가질 때 특히 유용합니다.

예를 들어, 다음 데이터 세트에는 시즌의 첫 5경기 중 2경기를 시작한 농구 선수가 300명이 있지만 1, 3, 4 또는 5경기를 시작한 선수는 약 100명뿐입니다.

 games_started <- sample(1:5, 100, TRUE)
points_per_game <- 3*games_started + rnorm(100)
data <- as.data.frame(cbind(games_started, points_per_game))

games_twos <- rep(2, 200)
points_twos <- 3*games_twos + rnorm(200)
data_twos <- as.data.frame(cbind(games_twos, points_twos))
names(data_twos) <- c('games_started', 'points_per_game')

all_data <- rbind(data, data_twos)

게임당 평균 점수를 기준으로 플레이한 게임 수를 시각화하면 2게임을 플레이한 플레이어가 더 많다고 말할 수 있지만 2게임을 플레이한 다른 플레이어가 정확히 몇 명인지 말하기는 어렵습니다.

 plot(all_data$games_started, all_data$points_per_game, pch = 16, col = 'steelblue')

그러나 게임 시작 변수에 지터를 추가하면 2개의 게임을 시작한 추가 플레이어 수를 확인할 수 있습니다.

 plot( jitter (all_data$games_started), all_data$points_per_game,
     pch=16, col='steelblue')

지터의 양을 약간 늘리면 이 차이가 더욱 드러납니다.

 plot( jitter (all_data$games_started, 1.5 ), all_data$points_per_game,
     pch=16, col='steelblue')

시각화 전용 지터

앞서 언급했듯이 지터링은 데이터에 무작위 노이즈를 추가하므로 포인트 클라우드에서 데이터를 시각화하려는 경우 유용할 수 있습니다. 지터 기능을 사용하면 데이터 세트에 있는 두 변수 간의 실제 기본 관계를 더 잘 이해할 수 있습니다.

그러나 회귀와 같은 통계 분석을 사용할 때 데이터 세트의 변수에 무작위 노이즈를 추가하는 것은 분석 결과에 영향을 미칠 수 있으므로 의미가 없습니다.

따라서 지터는 데이터 분석이 아닌 데이터 시각화에만 사용하도록 고안되었습니다.

의견을 추가하다

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다