Custom Search

Plotting density in R

Posted by admin on Wednesday Oct 13, 2010 Under Statistics

How to plot density
plot(density(DATA))

Rainbow color in R
If you want to make a plot have rainbow color range, you can use rainbow function:

rcol=rainbow(length(YOURDATA))
plot(DATAX, DATAY, type=”l”)
points(DATAX, DATAY, pch=16, col=rcol)

Simple Plot

How to change the size of text in a plot?
Use argument cex.[attribute] , and examples are below:

main titles by cex.main
sub titles by cex.sub
axis annonation by cex.axis
xlab and ylab by cex.lab

Legend
legend(x, y = NULL, legend, fill = NULL, col = par(“col”),
border=”black”, lty, lwd, pch,
angle = 45, density = NULL, bty = “o”, bg = par(“bg”),
box.lwd = par(“lwd”), box.lty = par(“lty”), box.col = par(“fg”),
pt.bg = NA, cex = 1, pt.cex = cex, pt.lwd = lwd,
xjust = 0, yjust = 1, x.intersp = 1, y.intersp = 1,
adj = c(0, 0.5), text.width = NULL, text.col = par(“col”),
merge = do.lines && has.pch, trace = FALSE,
plot = TRUE, ncol = 1, horiz = FALSE, title = NULL,
inset = 0, xpd, title.col = text.col, title.adj = 0.5)

symbols for R

Tags : , , , , , | Comments Off

Validating assumption of multivariate normal data

Posted by admin on Monday Aug 2, 2010 Under Statistics

Univariate and Multivariate diagnostics

Univariate diagnostic (Histogram and QQ plot)

Plot a histogram

hist(mydata.st, main="histgram", xlab="X values")

Plot QQ plot

## pch =16 (16 is a symbol for a filled circle)
qqnorm(mydata.st, main="QQ plot", pch=16, col="navy")


Multivariate dignostics

Chi-squre plot
We will graph distance vs chsq

# function to compute distance between X and X.bar
# argument is X, X.bar and S.inv
f.dist <- function(x,x.bar,S.inv){
return(t(x-x.bar)%*%S.inv%*%(x-x.bar))
}

dist_<-apply(mydat.dat, 1, f.dist, x.bar=apply(mydat.dat, 2, mean), S.inv= solve(cov(mydat.dat)))

# Compute u's from chi-square
u.cs <- qchisq((1:150-.5)/150, 4)

Make a plot
plot(u.cs, sort(dist_), pch=16, col="navy", xlab="Theoretical Quantiles", ylab="Sample Quantiles", main="Chi-Square Plot")

If the chi-square plot has a line with a slope=1 and intercept=0, then the data can be assumed to be multivariate normal

Tags : , , , , , , , , , , | 2 comments