Showing posts with label sample selection. Show all posts
Showing posts with label sample selection. Show all posts

Wednesday, December 4, 2013

Python: bootstrapping with sklearn

sklearn.cross_validation.Bootstrap returns indices of random bootstrap samples from your data. I am not yet well familiar with the use of bootstrapping for 2 sample comparison, so I'm using means as a way to characterise the two distributions (that's better than 2D K-S test, which doesn't exist anyway!). This is of course an incomplete statistic (I have a reason to suspect that two of the samples I am working with have different skewnesses). I'm working with three sets of absolute r magnitudes (M_r) here.
Here's how it looks in practice:

from sklearn import cross_validation

#let's call our sample array data. It can be N-dimensional.

#len(data) -- total number of data points in my dataset, 
#nBoot -- number of bootstrap samples, 
#train_size = bootstrap sample size (proportion of the whole sample, or just number)
#Here we create an empty array we will store the means of bootstrapped 

means = np.empty((nBoot, ))

#then we get the class instance, drawing half of the sample with replacement every time

bs = cross_validation.Bootstrap(len(data), nBoot, train_size=0.5, random_state=0)

#Filling the means array while iterating over the bootstrap samples (indexed by train_index):

i = 0
for train_index, test_index in bsJ:
    means[i] = np.mean(data[train_index])
    i+=1



I've repeated it for all three distributions I'm interested in, and here is a histogram of all the bootstrap sample means. The difference is just what what I've expected: basically, some faint galaxies (with M_r < 20 or so) were manually rejected from the green and red distributions, so the mean of them is shifted towards brighter absolute magnitudes. It remains to be seen how important this is. If we think this is worth it, I'll try using other distributions' statistics some other time.

Tuesday, April 30, 2013

Tuesday, February 19, 2013

Matplotlib: strings as axis labels

I wanted to make a plot that shows the relation of some galaxy properties vs. their Hubble subtype. The subtypes were saved as strings at my database, I selected them, converted back to numbers. Why back? Because some colleagues of mine, who think in words, classified all the 900 galaxies by their Hubble types, then their classifications were converted into numbers, means and probabilities calculated, and converted back to types.
Anyway, I wanted to have types on my axis, so I did it thus. Here's the plot:

Friday, February 15, 2013

lit: Intrinsic properties of SDSS galaxies

Maller et al.. It's important in many other ways, but here is an interesting excerpt on why TF relation is different:
However, with the notable exception of the Tully-Fisher relation these distributions and relations are traditionally measured in terms of the observed properties of galaxies. That is, the measurements used are K-corrected and corrected for foreground dust extinction, but no correction is attempted to compensate for the viewing angle from which the galaxies are observed. In contrast, the Tully-Fisher relation is not a relationship between a galaxy's observed luminosity and rotation velocity, but a relation between a galaxy luminosity and rotation velocity corrected for inclination. The inclination correction attempts to recover the intrinsic properties of a galaxy and not properties that are measured because of the particular angle from which the galaxy is viewed. For a long time there was great controversy over whether spiral galaxies are optically thin or optically thick (e.g., Holmberg 1958; Disney et al. 1989), but in the early 1990s it was established that galaxies become redder and fainter as they are inclined (e.g., Burstein et al. 1991).

Thursday, February 7, 2013

SDSS: a query for clean photometry galaxies with redshifts

SELECT g.objid, g.ra, g.dec, g.petroMag_u, g.petroMag_g, g.petromag_r, g.petromag_i, g.petromag_z, s.z, g.petroR50_r, g.petroR90_r, g.rho, g.isoA_r, g.isoB_r, g.isophi_r,
dbo.fPhotoFlagsN(flags) as flags into mydb.galaxies from Galaxy as G
   JOIN SpecObj as S ON G.objId=S.bestObjId 
WHERE ((flags & 0x10000000) != 0)       
AND ((flags & 0x8100000c00a0) = 0)     
       
       
       
AND (((flags & 0x400000000000) = 0) or (psfmagerr_g <= 0.2))
       
       
AND (((flags & 0x100000000000) = 0) or (flags & 0x1000) = 0)