51
R2 Ashish Mahabal AyBi199, Caltech 7 May 2009

Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

R2

AshishMahabalAyBi199,Caltech

7May2009

Page 2: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

Quickrecap

•  ?Togethelp•  #forcomments•  ‐>or<‐(or=)forassignments•  ==forcomparison

•  Concatenatewithc #x=c(a,b)•  seqtocreatesequence #z=seq(‐30,30)•  is.na(x)tolookfornotavailableness

Page 3: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  summary(x)•  data(x)•  read.table(file)•  save(file)•  source(file) #input

•  sink(file) #output

Page 4: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

CommonrouSnes

•  length(a) #lengthofvector•  max(a) #similarlymin,mean

•  sort(a),orsort(a,decreasing=T)•  unique(a)•  duplicated(a) #returnsalogicalarray!

Page 5: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

TomShort’sRrefcardhWp://www.rpad.org/Rpad/R‐refcard.pdf

Page 6: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

Example

•  a=rnorm(100,mean=5,sd=1)•  b=rnorm(200,mean=5,sd=1)

•  c=c(100*a,100*b)•  length(c)•  c

Page 7: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 8: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  d=as.integer(c)•  d•  mean(d);max(d);min(d);sd(d)

Page 9: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  unique(d)•  duplicated(d)•  plot(duplicated(d)) #coercion

Page 10: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  duplicated(unique(d))•  five(d) #whatsthefive‐of‐d•  ?five #nothing?Doyouknowfive?•  ??five #atleastsomethingthathasfive?•  fivenum(d) #ah,soitsfivenum.I’lltakethat•  ?fivenum #whatisitBTW?…minimum,lower‐hinge,median,upper‐hinge,maximum…

Page 11: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  fivenum(x,na.rm=TRUE) #opSons!•  g=d•  g[duplicated(d)]<‐NA•  fivenum(d)–  [1]264.0425.5483.5561.5742.0

•  fivenum(g,na.rm=TRUE)–  [1]264.0419.5492.0571.5742.0

Page 12: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  boxplot.stats(x,coef=1.5,do.conf=TRUE,do.out=TRUE)

•  quanSle,range,bxp

Page 13: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  whichselectsindices:•  a=which(d<500) #returnsindices•  a=d[which(d<500)] #returnstheelements

•  which.max(d) #indexofmaxelement

Page 14: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  match(x,y) #elementsofxiny,elseNA•  merge(a,b) #usingcommoncolumns/rows

Page 15: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

choose(n,k) #combinaSonsofkfromnchoose(5,3)returns10

sample(x,size) #resamplessizeelementsfromx(withtheopSonofreplacement)

Page 16: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  >sample(cards,5)[1]"S9""H4""D5""C3""C9"

•  >sample(cards,2)

[1]"H10""D10"

Page 17: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  Conj(4+3i)•  fft(x)•  solve(a) #matrixinverseofa

•  solve(a,b) #solvesa%*%x=bforx

Page 18: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 19: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 20: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 21: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

Stringsanddate/Sme

•  paste(…) #concatenaSngvectors•  substr(x,start,stop) #canalsoassign•  grep(paWern,x)•  as.Date(s)

Page 22: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

Graphicsdevices

•  x11(),windows()•  postscript(file)•  png,pdf,jpeg,…

Page 23: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

NextfewslidesfromhWp://scc.stat.ucla.edu/mini‐courses

Page 24: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 25: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 26: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 27: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 28: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

Replacerbyd,p,qtogetprobdensity,cumulaSveprobdensityandthevalueofthequanSle

Page 29: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  pnorm(4,5,1) –  #howmanybelow4formean5andsd1(asafracSon)

–  [1]0.1586553•  pnorm(6,5,1)–pnorm(4,5,1)–  #between4and6–  [1]0.6826895

•  qnorm(0.9,5,1)–  #90thpercenSle?–  [1]6.281552

Page 30: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

GeometricdistribuSon

•  dgeom(4,0.35)– Probabilityoffirstsuccessonthe5thtrialgiventhattheprobabilityofsuccessonagiventryis0.35

–  [1]0.06247719

Forafaircoinits0.5,0.25,0.125etc.pgeom(n,p)givestheprobabilityofsuccessunSlthatpoint.Soitwillbe0.5,0.75,0.875,…

Page 31: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

BinomialdistribuSon

•  dbinom(m,n,p)givesprobabilityofsuccessinmoutofnaWemptsgiventhatthesuccessatanygivenaWemptisp– dbinom(3,5,0.35) #successin3of5

•  [1]0.1811469– sum(dbinom(3:5,5,0.35))#in3or4or5of5

•  [1]0.2351694

Page 32: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 33: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

StaSsScaltests

•  shapiro.test Shapiro‐Wilk’sWtest(u)•  ks.testKolmogorov‐Smirnov2‐sampletest(b)

•  kruskal.test Kruskal‐Wallisk‐sampletest(b)

•  wilcox.test Wilcoxonrank‐sumtest(b)

•  cor.test BivariatecorrelaSoncoefficient(b)

•  cov Covarience(b)

•  rcorr CorrelaSonMatrix(m)

•  prcomp PrincipleComponentAnalysis(m)

Page 34: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

Linearregressionhelp(parSalsnapshot)

Page 35: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  library(Hmisc)•  table<‐read.table(fname,header=F)•  tposed=t(table)•  rcorr(tposed,type="pearson”)•  rcorr(tposed,type="spearman”)

Page 36: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 37: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

CorrelaSonwithopSonSpearman

Page 38: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

CorrelaSonwithopSonPearson

Page 39: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 40: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  library()•  RCMDINSTALL‐llibpath~/Hmisc_3.6‐0.tar.gz

•  Includethisinyour.Rprofilefile

Page 41: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 42: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

PrincipalComponentAnalysis

•  library(mva)•  table<‐read.table(”fname",header=T)

•  prcomp(table)

•  summary(prcomp(table))

Page 43: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 44: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 45: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 46: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:
Page 47: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

RediscoveringHRdiagram

•  Hyadesstars(Hipparcusmaincatalog)•  Mean/median/boxplot

•  DensityesSmaSon(Histogram)

•  Kernelsmoothing

•  CorrelaSonmatrix

•  X‐Yplot•  MulSvariateclustering

Page 48: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

HydStat(30Dec2004)AshishMahabal

•  X‐YplotbetweenVmagandB‐Vrevealsthefamousstructureinthedataset:thecolor‐magnitudeofbrightstarsshowingthemainsequence,giantbranch(withredclumpstars),andafewHyadeswhitedwarfs.

Page 49: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

FPofGlobularclusters

•  MatrixofpairwisecorrelaSoncoefficients•  Pairwiseplots•  PrincipalComponentAnalysis

Page 50: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

HydStat(30Dec2004)AshishMahabal

•  Coreparametersasagrouptendtobehighlycorrelated,unlikethehalf‐lightparameters.ThisisindicaSveofthedynamicalevoluSondrivenbythecorecollapse.

Page 51: Ashish Mahabal AyBi199, Caltech 7 May 2009george/aybi199/Old... · 2009. 5. 8. · Ashish Mahabal • X‐Y plot between Vmag and B‐V reveals the famous structure in the dataset:

•  RGUI(RcommanderhWp://socserv.mcmaster.ca/jfox/Misc/Rcmdr/)

•  hWp://vostat.org•  hWp://scc.stat.ucla.edu/mini‐courses

•  hWp://cran.r‐project.org•  hWp://www.r‐project.org•  hWp://en.wikipedia.org/wiki/R_(programming_language)