Created
April 30, 2021 12:39
-
-
Save achetverikov/5fbd5535686cb20ad78f167c04485659 to your computer and use it in GitHub Desktop.
DatasauRus as the noisy data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(datasauRus) | |
library(data.table) | |
library(ragg) | |
library(ggplot2) | |
dsd <- datasaurus_dozen | |
setDT(dsd) | |
dsd <- dsd[dataset%in%c('star','dino','away', 'circle')] | |
dsd[,z:=rnorm(.N, sd = 0.4)] | |
dsd[,y_new:=0.2*x+z+y, by = dataset] | |
res = 320 | |
ragg::agg_png('dsd_1.png', res = res, width = 4*res, height = 4*res) | |
ggplot(dsd, aes(x = x, y = y_new))+facet_wrap(~dataset)+geom_point()+labs(y = 'y', x = 'x')+theme(strip.text = element_blank()) | |
dev.off() | |
ragg::agg_png('dsd_2.png', res = res, width = 4*res, height = 4*res) | |
ggplot(dsd, aes(x = x, y = y_new-y))+facet_wrap(~dataset)+geom_point()+labs(y = 'y after removing confounds', x = 'x')+theme(strip.text = element_blank()) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment