Документ взят из кэша поисковой машины. Адрес оригинального документа : http://hea-www.harvard.edu/astrostat/astro193/Rdemo.txt
Дата изменения: Thu Feb 5 02:51:11 2015
Дата индексирования: Sun Apr 10 08:37:13 2016
Кодировка:
#commands used during R demo done on Feb 4 for Astro 193

getwd() #shows which directory you are in

help.start() #pops up a browser window with online help

apropos("FITS") #FITSio is crucial for astronomers

library(FITSio) #load the FITSio library

?FITSio #get help about FITSio

ls() #what is available

a <- c(1,1,2,3,5,8,13) #define an array

ls() #now should see "a"
str(a) #what does "a" look like?
summary(a) #statistical summary of "a"

# sequences
seq(1,3)
seq(1,3,length.out=10)
sample(seq(0.01,3,length.out=10))

# nake a dataset
x <- sample(seq(0.01,3,length.out=500))
y <- 0.5*x + 0.3*x^2
plot(x,y)

# heteroskedastic errors
dy <- rnorm(500,mean=0,sd=(0.05*(1+x^2)))

plot(x,dy)
plot(x,y+dy)

y <- y+dy
plot(x,y)

summary(x)
summary(y)

#box/whisker plots
boxplot(x,y)
boxplot(x,y,sqrt(y))
boxplot(x,y,sqrt(y),dy)

#histograms
hist(x)
hist(y)

#images
dpik(x) ; dpik(y) #to figure out binning sizes

xy <- cbind(x,y) #make 2D
smxy <- bkde2D(xy,bandwidth=c(0.2,0.2)) #make grid for images
ls(smxy)
image(smxy$x1,smxy$x2,smxy$fhat) #display image
contour(smxy$x1,smxy$x2,smxy$fhat,add=T) #overplot contour

#fit a function defined on-the-fly to transformed y
plot(x,y)
plot(log10(x),log10(y))
logx <- log10(x) ; logx2 <- logx^2 ; logx3 <- logx^3
yfit <- lm(log10(y) ~ logx + logx2 + logx3)
lines(sort(logx),yfit$fit[order(logx)],lwd=3)

# Normal and t distributions
x <- seq(-10,10,length.out=100)
plot(x,dnorm(x,0,1))
plot(x,dt(x,1))
plot(x,dt(x,10))