R code solutions - mdepasca/miniature-adventure GitHub Wiki
Kernel density plot
visualise the density of redshift measures in a sample using R. The simplest way is to use the density
function, provided by R-base
Read-in the data
df <- read.csv2('products/SIMGEN_PUBLIC_DES_REDSHIFTS.csv', dec='.')
plot(density(df$redshift))
A bandwidth for the kernel (in this case the default gaussian) can be provided by specifying the bw
keyword.
Comparative kernel density plot
To compare redshift distribution in training and testing the sm
package can be used (it has to be installed). To disinguish the two groups, the train_flag
value will be used.
install.packages('sm')
library(sm)
sm.density.compare(df$redshift, df$train_flag)
train.factor <- factor(df$train_flag, levels=c(1,0),
labels=c("Test", "Train")) # to be use in legend
colfill <- c(2:(1+length(levels(train.factor))))
legend(locator(1), levels(train.factor), fill=colfill)