Re: [R] QQ plotting of various distributions...

2009-09-25 Thread Sunil Suchindran
#same shape some_data - rgamma(500,shape=6,scale=2) test_data - rgamma(500,shape=6,scale=2) plot(sort(some_data),sort(test_data)) # You can also use qqplot(some_data,test_data) abline(0,1) # different shape some_data - rgamma(500,shape=6,scale=2) test_data - rgamma(500,shape=4,scale=2)

Re: [R] plotting least-squares regression against x-axis

2009-09-19 Thread Sunil Suchindran
x - seq(50) y - 10 + x * 2 + rnorm(50,0,10) plot(y~x) mylm = lm(y~x) # Use str(mylm) to see how to get the residuals plot(x,mylm$residuals) On Sat, Sep 19, 2009 at 8:35 PM, Jason Priem pr...@email.unc.edu wrote: Hi, I want to plot the residuals of a least-squares regression.

Re: [R] What does model.matrix() return?

2009-09-17 Thread Sunil Suchindran
This describes the way in which categorical variables are coded in the model. In this case, we see treatment coding, although this can go by different names in textbooks (for example, reference cell coding). attr(,assign) [1] 0 1 2 2 means that the first column of the model matrix corresponds to

Re: [R] lean text label below barplot table

2009-09-10 Thread Sunil Suchindran
#Example data df - data.frame(trt = factor(c(A long label, Another long \n label)), outcome = c(1,4)) #Install ggplot2 if needed library(ggplot2) p - ggplot(df, aes(y=outcome, x=trt)) p - p + geom_bar(position=dodge, stat=identity) p - p + opts(axis.text.x = theme_text(angle = 45, hjust=1)) p

Re: [R] standard error associated with correlation coefficient

2009-08-30 Thread Sunil Suchindran
Here are some options for confidence intervals. #by hand sample_r - .5 n_sample - 100 df - n_sample-1 fisher_z - 0.5*(log(1+sample_r)-log(1-sample_r)) se_z - 1/sqrt(n_sample-3) t_crit - qt(.975,df ,lower.tail=TRUE) z_lci - fisher_z - (t_crit * se_z) z_uci - fisher_z + (t_crit * se_z) (r_lci -

Re: [R] Select values at random by id value

2009-07-01 Thread Sunil Suchindran
#Highlight the text below (without the header) # read the data in from clipboard df - do.call(data.frame, scan(clipboard, what=list(id=0, date=,loctype=0 ,haptype=0))) # split the data by date, sample 1 observation from each split, and rbind sampled_df - do.call(rbind, lapply(split(df,

Re: [R] text() to label points in ggplot

2009-05-19 Thread Sunil Suchindran
# Here are two options: p - ggplot(mtcars, aes(wt, mpg)) + geom_point() + geom_text(aes(x = 5, y = 30, label = A Label)) #or response - c(2,4) xvar - c(1,2) label - response; myData - data.frame(response,xvar,label) p - ggplot(myData, aes(y=response, x=xvar)) p + geom_bar(position=dodge,

Re: [R] how to control lattice plot parameters

2009-04-18 Thread Sunil Suchindran
We can see the plotting options using trellis.par.get(). For example, one listed parameter is $superpose.line for which we can set col, lty, and lwd. Load the mlmRev package to obtain the Gcsemv data (used in Lattice book). One way to set the parameters is data(Gcsemv, package = mlmRev) my.fonts

Re: [R] loglm fitting

2009-01-14 Thread Sunil Suchindran
If we check the data, we see a mistake in the entry. tbl.8.3 mara cig alc count 1 Yes Yes Yes 911 2 No No No 538 3 Yes Yes Yes44 4 No No No 456 5 Yes Yes Yes 3 6 No No No43 7 Yes Yes Yes 2 8 No No No 279 Try: table8.3 -