Re: [R] Confusing behavior when using gsub to insert unicode character (minimal working example provided)

2014-06-04 Thread Thomas Stewart
Yep. You are right. That is better. -tgs On Thu, May 29, 2014 at 5:23 PM, Ista Zahn wrote: > 10Hi Thomas, > > On Thu, May 29, 2014 at 9:15 AM, Thomas Stewart > wrote: > > Thanks to to Ista Zahn, I was able to find a work around solution. The > key > > seems to

Re: [R] Confusing behavior when using gsub to insert unicode character (minimal working example provided)

2014-05-29 Thread Thomas Stewart
65",string1); new_string1 new_string2 <- substring(new_string1,2); new_string2 If you know of a less hackish way to accomplish this, I'm interested to hear it. However, this work around is sufficient for now. Thanks, -tgs On Wed, May 28, 2014 at 10:25 PM, Thomas Stewart wrote: > Can anyon

[R] Confusing behavior when using gsub to insert unicode character (minimal working example provided)

2014-05-28 Thread Thomas Stewart
Can anyone help me understand the following behavior? I want to replace the letter 'X' in ​the string ​ 'text X' with '≥' (\u226 ​5 ). The output from gsub is not what I expect. It gives: "text ≥". Now, suppose I want to replace the character '≤' in ​ the string​ 'text ≤'

Re: [R] convert data frame: two variables into _one_ binary variable

2013-11-25 Thread Thomas Stewart
I do not think Carl's solution answers your question. Try this: z <- textConnection( "education gender agree disagree sexe 1 0 Male 420 2 1 Male 200 3 2 Male 400 4 3 Male 630 5 4 Male

Re: [R] overlaying 2D grid on randomly distributed points

2013-11-21 Thread Thomas Stewart
How about this? require(FNN) #FOR DEMONSTRATION PURPOSES, GENERATE 2D DATA set.seed(3242) X <- matrix(runif(50),ncol=2) plot(X,pch=16,cex=1.5, asp=1) #PLOT GRID grid <- as.matrix(expand.grid(seq(0,1,by=.1),seq(0,1,by=.1)) ) abline(v=unique(grid[,1]),col="#FF30") abline(h=unique(grid[,2]),co

Re: [R] Plotting multiple confidence intervals in the same graph

2013-11-21 Thread Thomas Stewart
I'd recommend something along these lines: set.seed(32438786) plot.new() plot.window(xlim=c(-.5,.5),ylim=c(1,50)) for(i in 1:50){ X <- rnorm(100) CI <- confint(lm(X~1)) ifelse( sum(0 > CI) == 2 | sum(0 wrote: > Hi, > > I have 100 observations X1,X2,..,X100 and the confidence interval > lim

Re: [R] can par()$pin be used to guarantee equal horizontal and vertical image lengths?

2013-11-20 Thread Thomas Stewart
How about using the asp option? For example, A <- matrix(rnorm(200),20) image(A, asp=ncol(A)/nrow(A)) -tgs On Tue, Nov 19, 2013 at 3:56 AM, Mercutio Florid wrote: > > Today at 10:03 AM > I use several different versions of R, including RGui on Windows and > rstudio on Linux. In all cases, I

Re: [R] How to stop Kaplan-Meier curve at a time point

2013-11-20 Thread Thomas Stewart
One solution is to format the data as if the follow-up period ended on day 2190. For example, TTT <- Survival_days DDD <- Outcome DDD[ TTT>2190 ] <- 0 TTT[ TTT>2190 ] <- 2190 survfit(Surv(TTT, DDD) ~ Gender) -tgs On Wed, Nov 20, 2013 at 3:01 PM, Dr.Vinay Pitchika wrote: > Hello R users > >

Re: [R] Perform task on error

2013-07-24 Thread Thomas Stewart
H ow about a custom error handling function? As in, options(error = quote( ...CODE TO SEND EMAIL ... )) On Wed, Jul 24, 2013 at 4:06 PM, brt wrote: > I have a web service that uses an R script to perform the analysis. At the > end of the R script, I use the system function to call an external

Re: [R] non-conformable arrays

2013-07-24 Thread Thomas Stewart
You need to be careful how you index. In the example code, y is a 'zoo series' and y[i] is gives the ith row, as in y[i, ]. This means t(y[i]) %*% y[i] is actually a 2X2 matrix. Also, the code c(S)[c(1,4,2)] picks off the diagonal and lower triangular elements. The example involves two stocks,

Re: [R] Apply a PCA to other datasets

2013-06-10 Thread Thomas Stewart
Short answer: Yes. Long answer: Your question does not provide specific information; therefore, I cannot provide a specific answer. On Mon, Jun 10, 2013 at 1:23 PM, edelance wrote: > I have run a PCA on one data set. I need the standard deviation of the > first > two bands for my analysis. I

Re: [R] What does this say? Error in rep("(Intercept)", nrow(a0)) : invalid 'times' argument

2013-05-25 Thread Thomas Stewart
Mike- You can use the traceback function to see where the error is: > bob <- matrix(rnorm(100*180), nrow=180) > yyy <- rnorm(180) > fit1 <- cv.glmnet(bob, yyy, family="mgaussian") Error in rep("(Intercept)", nrow(a0)) : invalid 'times' argument > traceback() 6: predict.multnet(object, newx, s

Re: [R] When creating a data frame with data.frame() transforms "integers" into "factors"

2013-05-25 Thread Thomas Stewart
Antonio- What exactly do you want as output? You stated you wanted a scatter plot, but which variable do you want on the X axis and which variable do you want on the Y axis? -tgs On Sat, May 25, 2013 at 3:36 PM, António Camacho wrote: > Hello > > > I am novice to R and i was learning how to

Re: [R] how to get a value from a list (using paste function)?

2012-12-18 Thread Thomas Stewart
Soyeon- A possible solution: get(lambda.rule,envir=list2env(cvtest)) On Tue, Dec 18, 2012 at 12:34 PM, Soyeon Kim wrote: > Dear my R friends, > > I want to get a number from a list using paste function. > In my example, > lambda.rule <- "lambda.1se" > cvtest is a list (result from cv.glmnet)

Re: [R] Combined Marimekko/heatmap

2012-12-14 Thread Thomas Stewart
e approach. Either way, I > still need to figure out how to do the true/false color coding so any > pointers on that are welcome. > > ** ** > > ** ** > > ** ** > > *Neal Humphrey* > > Tel: +1 202.662.7241 | Skype: neal.s.humphrey | nhumph...@clasponline.org* &

Re: [R] Combined Marimekko/heatmap

2012-12-14 Thread Thomas Stewart
Neal- Perhaps the following code is a start for what you want. -tgs par(mar=c(1,1,1,1), oma = c(0,0,0,0), mgp=c(1.5,.2,0), tcl=0, cex.axis=.75, col.axis="black", pch=16) Z <- textConnection(" country A1 A2 A3 A 3 4 5 B 6 9 8 C 6 9 5") ddd <- read.table(Z,header=TRUE) close(Z) Count

Re: [R] Matrix multiplication

2012-12-12 Thread Thomas Stewart
One solution that does not require matrix multiplication: Remember that the steady state vector is in the nullspace of I - T. Therefore: require(MASS) n1 <- Null(t(diag(nrow(T)) - T)) n1 / sum(n1) On Wed, Dec 12, 2012 at 2:19 AM, annek wrote: > Hi, > I have a transition matrix T for which I

Re: [R] help with predict.glm, and charting with factors

2012-12-12 Thread Thomas Stewart
Chad- The plot you hope to create is meaningful when the variable temperature is treated as a continuous variable. Below is some code that treats temperature as a continuous variable and creates the plot. Note that temperature enters the model "linearly", and you may want to explore other possib

Re: [R] splitting dataset based on variable and re-combining

2012-12-10 Thread Thomas Stewart
Why not use an indicator variable? P1 <- ... # prediction from model 1 (Setosa) for entire dataset P2 <- ... # prediction from model 2 for entire dataset I <- Species=="setosa" # Predictions <- P1 * I + P2 * ( 1 - I ) On Monday, December 10, 2012, Brian Feeny wrote: > > I have a dataset and I

Re: [R] How to efficiently compare each row in a matrix with each row in another matrix?

2012-12-08 Thread Thomas Stewart
One option is to consider a Kronecker-type expansion. See code below. -tgs perhaps <- function(A,B){ nA <- nrow(A) nB <- nrow(B) C <- kronecker(matrix(1,nrow=nA,ncol=1),B) >= kronecker(A,matrix(1,nrow=nB,ncol=1)) matrix(rowSums(C) == ncol(A), nA, nB, byrow=TRUE) } Marius <- function(A,B) apply

Re: [R] Get an expected value for Order Statistics by applying double integrals

2012-12-06 Thread Thomas Stewart
Kyong- It isn't clear to me why are you using a double integral. You have the pdf and your goal is to calculate the expected value of a univariate random variable (the first order statistic). Shouldn't the expected value be E[X_(1)] = int x * 5 * f(x) * (1-F(x))^4 dx? A single integral? Here

Re: [R] Can somebody help me with following data manipulation?

2012-12-06 Thread Thomas Stewart
You can directly use the tapply function. -tgs tapply(dat[,3],dat[,-3],mean) On Thu, Dec 6, 2012 at 3:03 PM, Sarah Goslee wrote: > If I understand what you want correctly, aggregate() should do it. > > > aggregate(V3 ~ V1 + V2, "mean", data=dat) >V1 V2V3 > 1 C 0 0.500 > 2

Re: [R] Analyze multiple data set simultaneoulsy

2012-12-06 Thread Thomas Stewart
Mindy- > > If the sub-directories are named in a structured way --- say sd1, sd2, > sd3, ..., sd100 --- then one option is a simple for-loop. Something like > the code below. > > -tgs > > directory.path <- '~/blahblah/' # or 'C:/blahblah/' for windows > sd.names <- paste(directory.path,'sd',1:10

Re: [R] how to keep all zeros in 1st row (not NA)

2012-11-28 Thread Thomas Stewart
Irucka- I got the following, which seems to be what you want. Perhaps you could provide reproducible code. -tgs > as.matrix(data) Time.day X1 X2 X3 X4 [1,]0 0.0 0.0 0.0 0.0 [2,]1 0.16387 0.60612 0.87705 0.83798 [3,]2 0.32774 1.212

Re: [R] How to change smoothing constant selection procedure for Winters Exponential Smoothing models?

2012-11-28 Thread Thomas Stewart
Jonathan- First, consider starting the algorithm at this alternative solution. You do this with the optim.start option. HoltWinters( , optim.start = c(alpha = 0.99, beta = 0.001, gamma = 0.001)) If this solution is indeed better, the function should not converge to the old solution. If i

Re: [R] Add a density line to a cumulative histogram - second try

2011-07-14 Thread Thomas Stewart
This is a hack which uses the output of the density function. rrr <- cumsum(diff(cumsum(denspoints$y))*diff(denspoints$x)) lines(denspoints$x[-512],rrr) I don't believe this is the best solution, because it is not a direct estimate of the cumulative density function. I think there are methods fo

Re: [R] Help needed

2011-01-27 Thread Thomas Stewart
For question 2, TTT <- rt(1000,3) mean(TTT[rank(TTT) <= 975 & rank(TTT) >25]) On Thu, Jan 27, 2011 at 8:16 AM, Ben Boyadjian wrote: > Hello I am trying to solve these problems and I am not allowed to use loops > or ifs. > > 1st Question > My first question is that I have generated 100 random num

Re: [R] Movie Question

2011-01-23 Thread Thomas Stewart
Along with imdb.com, boxofficemojo.com might be a potential database. -tgs On Sun, Jan 23, 2011 at 3:46 AM, Barry Rowlingson < b.rowling...@lancaster.ac.uk> wrote: > On Sat, Jan 22, 2011 at 10:07 PM, Matt Curcio > wrote: > > Greetings all, > > I am wondering if anyone is aware of any studies th

Re: [R] how to store a number into a vector

2011-01-23 Thread Thomas Stewart
Here is a hack, crude solution to get the digits: Digits <- function(a){ out <- rep(NA,nchar(a)) for(i in 1:nchar(a)) out[i] <- substr(a,i,i) return(as.numeric(out)) } Digits(183429) If all you want is the last three numbers, consider another hack solution: Last3Digits <- function(a) a

Re: [R] how to add these "axis" label?

2010-12-08 Thread Thomas Stewart
It isn't clear to me what you want to do. Do you want the axes to show? Do you want labels for the lines? Do you want a legend? What is your desired output? -tgs On Wed, Dec 8, 2010 at 2:42 PM, casperyc wrote: > > Hi All, > > How do I add these axis labels? > > #

Re: [R] Formatting 'names.arg' in barplot

2010-12-08 Thread Thomas Stewart
Try this modification of your code. -tgs ynames <- base.dat.sel2$base.dat.Covariate[order(base.dat.sel2$base.dat.US.Num.Obs.to.Achieve.Starting.Residual,decreasing=F)] ynames <- as.character(ynames) ynames[12]<-expression(theta[r]) ynames[13]<-expression(EC[gw]) ttt<-barplot(base.dat.sel2$base.d

Re: [R] library(datasets)

2010-11-19 Thread Thomas Stewart
You may want to consider using eurodist in matrix form. As in, ED <- as.matrix(eurodist) Then you could manipulate the matrix using standard or homemade functions, like this one: max.matrix <- function(A) { column <- ceiling(which.max(A)/nrow(A)) row <- which.max(A) - (column-1)*nrow(A) A

Re: [R] separate elements of a character vector

2010-10-19 Thread Thomas Stewart
You may want to try something like this: x1<-rnorm(500) plot(x1) test<-seq(1987, 2002, by=1) test_2<-seq(2003, 2006, by=1) test<-format(c(test, test_2), width=5) xxx<-seq(1,500,length=length(test)) axis(1,at=xxx,labels=test,line=1,col=0) You'll need to specify where you want the labels (in this c

Re: [R] nls & optimize

2010-10-19 Thread Thomas Stewart
Let f be your estimated function. Suppose we have a root function, say root(). You are looking for b = root(f-a) where a is some constant. Now suppose we consider the inverse of f, call it f.inv. Then the following holds: a = root(f.inv-b). In your code, you find b = root(f-a) and c = ro

Re: [R] Does R have function/package works similar to SAS's 'PROC REG'?

2010-10-07 Thread Thomas Stewart
CZ- How exactly are you using the regression output? Are you using the regression parameter estimates? Or, are you using the predicted (or fitted) response variable. The fact that your model matrix (sometimes called the X matrix) has dimension 60 X 2000 means there is not a unique least square

Re: [R] problem with colors

2010-10-07 Thread Thomas Stewart
I would be helpful if you provided a more complete, reproducible example. Consider the following code. It colors the boxes according to the first 47 colors listed in the color() vector. -tgs data<-as.data.frame(matrix(rnorm(47*23),ncol=47)) boxplot(data,col=colors()[1:47]) On Thu, Oct 7, 20

Re: [R] Question about assigning values in a matrix, conditional on column first row; how to do the loop.

2010-10-05 Thread Thomas Stewart
Paula- Look at this example. R in this case is your data matrix. -tgs R<-matrix(sample(0:2,100,replace=T),nrow=10) R[1,]<-round(runif(10),3) f<-function(x){ show(x) y<-x[-1] y[y!=2]<--999 y[y==2]<-x[1] c(x[1],y) } apply(R,2,f) On Tue, Oct 5, 2010 at 11:54 AM, Paula Fergnani Salvi

Re: [R] adding a legend to the plot (but outside of it)

2010-10-05 Thread Thomas Stewart
> through var, it grabs col=all.colors[which(names(my.data) %in% var)]. > I am wondering if it's possible to do the same for the legend? Because > I just want the legend to have the same colors as in the graph... (in > real life I'll have a lot of colors and it'll be hard

Re: [R] adding a legend to the plot (but outside of it)

2010-10-04 Thread Thomas Stewart
Right before the plot statement add: par(mar=c(5,4,4,6),xpd=F) then at the end add legend(par()$usr[2], mean(par()$usr[3:4]), c("Blue","Yellow","Green","Orange"), xpd=T, bty="n", pch=15, col=c("Blue","Yellow","Green","Orange")) On Mon, Oct 4, 2010 at 5:16 PM, Dimitri Liakhovitski <

Re: [R] R squared for lm prediction

2010-10-04 Thread Thomas Stewart
I'm not sure I understand what you want, but here is a guess. Let y be the hold out response values. Let y.hat be the model predictions for the corresponding ys. The key is to remember that R^2 = cor( y , y.hat )^2. So, cor( cbind(y,y.hat))[1,2]^2 should give you a measure you want. -tgs On

Re: [R] Fisher exact test?

2010-10-04 Thread Thomas Stewart
To find the probability directly, you'll need to clearly state how you are sampling. Are you sampling with replacement? (Draw then put back.) Or are you sampling without replacement? (Draw. Draw from the remaining. Draw from the remaining.) Also, of the N genes, do you know how many are of the

Re: [R] plotmath: how to use greek symbols in expression(integral(f(tau)*dtau, 0, t))?

2010-10-04 Thread Thomas Stewart
Try expression(paste(integral(),"f(",tau,") d",tau,sep=""))) it works for me. -tgs On Mon, Oct 4, 2010 at 9:25 AM, Czerminski, Ryszard < ryszard.czermin...@astrazeneca.com> wrote: > I would like to use greek "tau" as a symbol of variable to integrate > over in plotmath > > expression(integral(

Re: [R] How to iterate through different arguments?

2010-10-03 Thread Thomas Stewart
There are several ways to do this. The following is only one of the ways. One of the advantages of this approach is that it allows including both continuous and categorical variables. I'll demonstrate with the iris dataset. Place your variables in a dataframe with the y variable in the first co

Re: [R] Pass Arguments to R with an LSF submit

2010-10-01 Thread Thomas Stewart
you know of another solution, please let me know. Thanks, -tgs On Fri, Oct 1, 2010 at 3:01 PM, Thomas Stewart wrote: > I'm trying to run R in batch mode on an LSF managed cluster. In simple > settings, I can do it just fine. The trouble I'm having is when I try to > pass ar

Re: [R] Contrasts for MANOVA

2010-10-01 Thread Thomas Stewart
There are several ways to perform a MANOVA analysis in R. You'll have to be more specific about your approach. For example, which function are you using? -tgs On Fri, Oct 1, 2010 at 3:31 PM, Ali S wrote: > Can anyone tell me how to run contrasts for MANOVA? > Thanks! > > > >[[alternati

[R] Pass Arguments to R with an LSF submit

2010-10-01 Thread Thomas Stewart
I'm trying to run R in batch mode on an LSF managed cluster. In simple settings, I can do it just fine. The trouble I'm having is when I try to pass arguments to the batch job. For example, bsub R CMD BATCH --args 1 3 commandfile.R & LSF doesn't like the &, and it doesn't run. I'm hoping one

Re: [R] FW: creating a custom background

2010-09-29 Thread Thomas Stewart
Ethan- You need to be more explicit about what you mean by 'background'. Do you mean: (a) the entire plot including margins?, or (b) only the plotting area?, or (c) a different color for both margins and plotting area? If you want (a), the solution is par(bg = '#003D79'). If you want (b), the s

Re: [R] matrix plot

2010-09-29 Thread Thomas Stewart
HH- I'm not familiar with the plots you mention, but the following is a quick attempt to create the plot you describe. data<-data.frame( org=1:10, q1=sample(1:10,replace=T), q2=sample(1:10,replace=T), q3=sample(1:10,replace=T)) # This generates a random data set like the one you describ

Re: [R] Help with customizing a histogram figure

2010-09-16 Thread Thomas Stewart
Josh- The link you included with your post provides the code for the example plot. Simply click on the icon in the "Download Source Code" section. I think you'll be able to learn a lot by playing with that source code. -tgs On Thu, Sep 16, 2010 at 9:40 AM, Josh B wrote: > Hi all, > > Please

Re: [R] barplot: space between axis and bars

2010-09-15 Thread Thomas Stewart
Try par(xaxs="i") barplot(rnorm(10), space=0) -tgs On Wed, Sep 15, 2010 at 7:54 AM, Daniel Stepputtis < daniel.stepput...@vti.bund.de> wrote: > Hi all, > I have a problem with a rather simple plot (which I have used several > times) - barplot. > > I want to create a barplot, where no space is b

Re: [R] Homogeneity of regression slopes

2010-09-14 Thread Thomas Stewart
kage, as you mentioned. > > Thanks. > > Cliff > > > On Mon, Sep 13, 2010 at 10:02 PM, Thomas Stewart wrote: > >> Allow me to add to Michael's and Clifford's responses. >> >> If you fit the same regression model for each group, then you are also >

Re: [R] Homogeneity of regression slopes

2010-09-13 Thread Thomas Stewart
Allow me to add to Michael's and Clifford's responses. If you fit the same regression model for each group, then you are also fitting a standard deviation parameter for each model. The solution proposed by Michael and Clifford is a good one, but the solution assumes that the standard deviation pa

Re: [R] Help on simple problem with optim

2010-09-09 Thread Thomas Stewart
This is only a guess because I don't have your data: sigma is must be positive in the dnorm function. My guess is that optim may attempt an iteration with a negative sigma. You may want to see help(optim) for dealing with this constraint. Specifically see the lower argument. If you specify th

Re: [R] mixed-effects model with two fixed effects: interaction

2010-06-29 Thread Thomas Stewart
IIona- I think you may be misinterpreting the t-test. In model 1, consider the speciesH coefficient. A test that speciesH = 0, essentially asks: Is speciesH the same as speciesB? The test statistic for this hypothesis is the t-value reported in the table. (t-value= -4.2, p-value=0.0001) In mo

Re: [R] add one point to contourplot()

2010-06-08 Thread Thomas Stewart
Because contourplot comes from the lattice package, I think you'll want to look at these help pages: + help(trellis.focus) + help(lpoints) Below, I've used the example from help(contourplot) to demonstrate how one might add points and text to a lattice plot. -tgs # #

Re: [R] General Question regarding Lists

2010-05-25 Thread Thomas Stewart
Hopefully I understand your goal. You have several datasets of the same dimension, and you want to calculate the pairwise correlations of each dataset's row mean. Depending on the dataset names, it may be easy to put all the data in a 1359 X 15 X 40 dimension array. Then, the following code woul

Re: [R] Fast Matrix Computation

2010-05-22 Thread Thomas Stewart
One possibility: n.A<-nrow(A) n.B<-nrow(B) abs( kronecker(A,rep(1,n.B)) - kronecker(rep(1,n.A),B) ) -tgs On Sat, May 22, 2010 at 3:20 PM, Shi, Tao wrote: > One way to do it: > > apply(B, 1, function(x) t(apply(A, 1, function(y) abs(y-x) )) ) > > > > > > - Original Message > > From: D

Re: [R] Data reconstruction following PCA using Eigen function

2010-05-22 Thread Thomas Stewart
Looks like you have some numerical precision issues. Why not use the svd function directly? (See below.) -tgs x <- read.table( textConnection( "Sample1 0.7329881 0.76912670 2.45906143 -0.06411602 1.2427801 0.3785717 2.34508664 1.1043552 -0.1883830 0.6503095 Sample2 -2.0446131 1.727832

[R] Specify correlation structure in lme4

2010-05-20 Thread Thomas Stewart
I know this was asked and answered in 2005, I just want to make sure the answer still holds in 2010. Question: If I have the mixed-model with lmer( y ~ x1 + x2 + (1 | id) + (z1 | w ) , ... ) there is no way for me to specify a correlation structure for the random effects? Right? If I want to s

Re: [R] Change order of columns in table?

2010-05-17 Thread Thomas Stewart
7 data points? What's wrong with with doing it manually? x<-c(173,193,194,167,119,80,96) labs<-c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday") pie3D(x,labels=labs) -tgs On Mon, May 17, 2010 at 8:46 AM, someone wrote: > > I'm an R noob and have a (maybe) stupid questi

Re: [R] Discretize factors?

2010-05-16 Thread Thomas Stewart
Maybe this will lead you to an acceptable solution. Note that changed how the data set is created. (In your example, the numeric variables were being converted to factor variables. It seems to me that you want something different.) The key difference between my code and yours is that I use the

Re: [R] Discretize factors?

2010-05-15 Thread Thomas Stewart
Maybe this? group <- factor(c("A", "B","B","C","C","C")) model.matrix(~0+group) -tgs On Sat, May 15, 2010 at 2:02 PM, Noah Silverman wrote: > Hi, > > I'm looking for an easy way to discretize factors in R > > I've noticed that the lm function does this automatically with a nice > result. > > If

Re: [R] multhist,labels and percentages

2010-05-14 Thread Thomas Stewart
r maybe directly calculate the bin percentages and plot them directly. I think you have a lot of options to plot what you want. -tgs On Fri, May 14, 2010 at 11:51 AM, Federico Calboli wrote: > On 14 May 2010, at 16:09, Thomas Stewart wrote: > > > Please be more specific with your questi

Re: [R] multhist,labels and percentages

2010-05-14 Thread Thomas Stewart
Please be more specific with your question. Perhaps a simple subset of the data you are trying to plot? Here is some non-specific advice: Plotting histograms as percentages instead of frequency counts is already an option of the hist function. For example, pop1<-rnorm(100) hist(pop1,freq=F) I

Re: [R] smooth line overlap with histogram

2010-05-06 Thread Thomas Stewart
Try x<-rowMeans(matrix((rbinom(1000,4,.45)-4*.45)/sqrt(.45*.55/4),ncol=10)) hist(x,freq=F,ylim=c(0,.5)) ### The key is the freq=F option. curve(dnorm(x),add=T) ### You can use curve to plot a function lines(density(x)) ### Or density for a kernel density estimate. -tgs On Thu, May 6, 2010

Re: [R] Derivative of the probit

2010-05-06 Thread Thomas Stewart
f<-function(x) 1/dnorm(qnorm(x)) for x in (0,1) -tgs On Thu, May 6, 2010 at 4:40 PM, Andrew Redd wrote: > Is there a function to compute the derivative of the probit (qnorm) > function > in R, or in any of the packages? > > Thanks, > -Andrew > >[[alternative HTML version deleted]] > > _

Re: [R] Apologies : question on transforming a table

2010-05-06 Thread Thomas Stewart
This is definitely a hack, but it gets the job done. X<-model.matrix(~0+pheno,data=data) data2<-apply(X,2,function(X){tapply(X,data$ID,sum)}) data2 phenoAppendicitis phenoAutism phenoBreast Cancer phenoMicrocephaly phenoPolyps A 1 0 1 1

Re: [R] Visualizing binary response data?

2010-05-04 Thread Thomas Stewart
For binary w.r.t. continuous, how about a smoothing spline? As in, x<-rnorm(100) y<-rbinom(100,1,exp(.3*x-.07*x^2)/(1+exp(.3*x-.07*x^2))) plot(x,y) lines(smooth.spline(x,y)) OR how about a more parametric approach, logistic regression? As in, glm1<-glm(y~x+I(x^2),family=binomial) plot(x,y) lin

Re: [R] Help needed with legend

2010-05-03 Thread Thomas Stewart
Something like this? plot(0,0) legend.text<-c("VAR 1","Higher","Average","Lower","VAR 2","Higher","Average","Lower") legend.pch=1:8 legend.col=c(0,1,1,1,0,1,1,1) legend("bottomright",legend=legend.text,pch=legend.pch,col=legend.col,ncol=2) -tgs On Mon, May 3, 2010 at 3:10 PM, Nish wrote: > > H

Re: [R] Plotting the explanatory against the dependent in a GAM

2010-05-03 Thread Thomas Stewart
See example(gam) particularly plot(gam.object,se=TRUE). On Mon, May 3, 2010 at 5:20 AM, Oscar Saenz de Miera wrote: > > To whoever it may correspond, > > My name is Oscar Saenz and I am working on my thesis in Spain. > > I am using GAMs in "R" and, now that I have estimated my models, I need t

Re: [R] binary logistic regression taking account clustering

2010-05-01 Thread Thomas Stewart
See help(lmer, package="lme4") for a mixed-effects model approach. See help(geeglm, package="geepack") for a GEE approach. -tgs On Sat, May 1, 2010 at 1:52 PM, kende jan wrote: > Hello > > I would like to perform with R, a binary logistic regression analysis > taking account clustering >

Re: [R] Split a vector by NA's - is there a better solution then a loop ?

2010-04-29 Thread Thomas Stewart
Or, you can modify Romain's function to account for sequential NAs. x <- c(1,2,NA,1,1,2,NA,NA,4,5,2,3) foo <- function( x ){ idx <- 1 + cumsum( is.na( x ) ) not.na <- ! is.na( x ) f<-factor(idx[not.na],levels=1:max(idx)) split( x[not.na], f ) } $`1` [1] 1 2 $`2` [1] 1 1 2 $`3` nu

Re: [R] Generalized Estimating Equation (GEE): Why is Link = Identity?

2010-04-29 Thread Thomas Stewart
>From the GEE article in R News, Vol. 2/3, December 2002: "Allows different covariates in separate models for the mean, scale, and correlation via various link functions." Geepack offers link functions for the scale, correlation, and mean models. As the output suggests, "Correlation: Structure

Re: [R] Maximum Likelihood Estimation in R

2010-04-21 Thread Thomas Stewart
Henrik- A coding solutions may be ... + (1/(2*stdev*stdev))*sum( ( y-(rev/12)- c(0,y[-n]) *exp(-lap/12) )^2 ) where n is the number of observations in y. Personally, I would use lm. Your model can be written as a linear function. Let x=c(0,y[-n]). Then run lm(y~x). The parameter estimat

Re: [R] how to select the first observation only?

2010-04-21 Thread Thomas Stewart
Try the duplicated() function. As in m[!duplicated(id), ] -tgs On Wed, Apr 21, 2010 at 10:17 PM, gallon li wrote: > Dear r-helpers, > > I have a very simple question. Suppose my data is like > > id=c(rep(1,2),rep(2,2)) > b=c(2,3,4,5) > m=cbind(id,b) > > > m > id b > [1,] 1 2 > [2,] 1 3

Re: [R] Maximum Likelihood Estimation in R

2010-04-21 Thread Thomas Stewart
Two possible problems: (a) If you're working with a normal likelihood---and it seems that you are---the exponent should be squared. As in: ... + (1/(2*stdev*stdev))*sum( ( y-(rev/12)-lag(y)*exp(-lap/12) )^2 ) (b) lag may not be working like you think it should. Consider this silly example: y<

Re: [R] log-linear regression question

2010-04-20 Thread Thomas Stewart
I think you'll need the offset option. ln( Y ) = ln( K ) + b1 ln( X1 ) + b2 ln( X2 / X3 ) + 1 ln( 1 / X3 ) as in: glm( log(Y) ~ log( X1 ) + I(log( X2 / X3 )), offset=I(log( 1 / X3 ))) -tgs On Tue, Apr 20, 2010 at 7:14 AM, rajiv guha wrote: > I am trying to estimate a demand function: >

Re: [R] multiple plots problem

2010-04-20 Thread Thomas Stewart
The stretching of plot two occurs because you are allotting more space for plot two. You set Plot 1: mar=c(0,4,4,2) Plot 2: mar=c(0,4,0,2) Plot 3: mar=c(4,4,0,2) In plot one your are dedicating 4 lines to the top margin, in plot three you are dedicating 4 lines to the bottom margin. In plot two,

Re: [R] problem with retreaving column from a data.frame

2010-04-20 Thread Thomas Stewart
Maybe you want something like this. temp<-data.frame(id=rbinom(10,5,.5),grp=rbinom(10,3,.3),stdid=rnorm(10)) kk<-"stdid" temp[,kk] -tgs On Tue, Apr 20, 2010 at 7:32 AM, venkata kirankumar wrote: > Hi all, > I have a problem with retreaving column from a data.frame that is > > I have a data.fra

Re: [R] Unwanted boxes in legend

2010-04-19 Thread Thomas Stewart
Try border=c(0,0,1,0). -tgs On Mon, Apr 19, 2010 at 4:21 AM, Steve Murray wrote: > > Dear all, > > Thanks for the response, however I'm getting the following error message > when I execute the legend command using the 'border' argument: > > Error in legend(10, par("usr")[4], c("A", "B", : > un

Re: [R] R loop.

2010-04-16 Thread Thomas Stewart
I'm not sure I completely understand your question, but I think the solution to your problem is the reshape function in the reshape package. Here is a silly example of how it would work: > V<-matrix(rbinom(15,4,.5),nrow=3) > X<-data.frame(A=c("A","B","C"),V=V) > X A V.1 V.2 V.3 V.4 V.5 1 A 1