Photometric redshift estimation using generalized linear models

User-friendly interfaces to perform fast and reliable photometric redshift estimation. The code makes use of generalized linear models and can adopt gamma or inverse gaussian families, either from a frequentist or a Bayesian perspective. The code additionally provides a Shiny application providing a simple user interface.

title: "Photometric Redshift with CosmoPhotoz" authors: Rafael S. de Souza, Jonny Elliot, Alberto Krone-Martins, Émille Ishida, Joseph Hilbe output: html_document runtime: shiny

This is a short tutorial explaining how to perform photometric redshift estimation using the CosmoPhotoz R package.


Load the PHAT0 data included in the package. Here we are using 5% of all dataset for training.


Number of variance explained by each PC


Add the redshift column to the PCA projections of the Training sample


Store the PCA projections for the testing sample in the vector Testpc


Train the glm model using Gamma Family. 6 PCs explain 99.5% of data variance. In order to account for small variations in the shape, we include a polynomial term for the 2 first PCs (95% of data variance)


Once we fit our GLM model, we can predict the redshift for the "photometric" sample

photoz<-predict(Fit$glmfit,newdata = Testpc,type="response")

Store the redshift from the testing sample in the vector specz for comparison


Compute basic diagnostic statistics

computeDiagPhotoZ(photoz, specz)

Create basic diagnostic plots

Kernel density distribution of the full scatter $(specz-photoz)/(1+specz)$

plotDiagPhotoZ(photoz, specz, type = "errordist")

Predicted vs Actuall values Select 15,000 points to show

plotDiagPhotoZ(photoz[datashow], specz[datashow], type = "predobs")+coord_cartesian(xlim =c(0,1.5), ylim = c(0,1.5))

Scatter distribution as a function of redshift, violin plot

plotDiagPhotoZ(photoz, specz, type = "errorviolins")

Scatter distribution as a function of redshift, box plot

plotDiagPhotoZ(photoz, specz, type = "box")


Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.1 by Rafael S. de Souza, 3 years ago

Browse source code at

Authors: Rafael S. de Souza, Alberto Krone-Martins, Jonathan Elliott, Joseph Hilbe

Documentation:   PDF Manual  

Task views: Chemometrics and Computational Physics

GPL (>= 3) license

Imports ggplot2, ggthemes, arm, COUNT, gridExtra, pcaPP, mvtnorm, shiny

See at CRAN