[R] A Lattice Question
To the Lattice expert - I am new to the lattice package and I would like to add a curve to the xyplot(). I know that I need to use panel function to add it. But it doesn't work. Is there anyone can help me out on how to transfer the data into the function? The following is my code and I would like to add lines for xx,yy xx <- seq(0,1,length = 100); yy <- mean(PS$theta)*(1-exp(mean(PS$k)*xx))/(1-exp(mean(PS$k))) ts1 <- xyplot(VCFB ~ Visit , groups = ID, data = CFB_M, type = c('g','l'),strip = strip.custom(style =4), as.table=TRUE,xlab = 'Time',ylab = 'FBG CFB',main = '3mg Change from Baseline FBG',panel=function (xx,yy,...) { panel.xyplot(...); panel.lines(xx,yy,...);}); Many thanks!! Best, Haoda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How do I know where is R? - VB Programming
Dear all - Is there anyone know how to let VB or C# know where I install R automatically(i.e. auto detect R directory)? Many thanks! Best, Haoda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] HELP: BRUGS/WinBUGS/RBUGS Response is a combination of random variables
Hi, Is there anyone know if BUGS language allows the combination of variables as response such as Y[i] <- a*X1[i]+b*X2[i] Y[i] ~ dnorm(c,d) It seems doesn't work in my model. The problem is between two ##. The error message is > modelCheck("BayesBioMarker.BUGS") model is syntactically correct > modelData(paste("BUGS_data.txt",sep="")) data loaded > modelCompile(numChains=1) multiple definitions of node bm[1] === model { for(iter in 1:numSubj){ bmd[iter] ~ dnorm(u[trt[iter]+1],sdbmd.precision); ### bm[iter] <- inprod(biomarker[iter,1:4], bta[1:4]) bm[iter] ~ dnorm(bmu[iter], sdbm.precision); ### bmu[iter] <- (1-delta[trt[iter]+1])*u[trt[iter]+1]+ delta[trt[iter]+1]*(u[1]+u[2])/2; } for(iter in 1:4){ bta[iter] ~ dnorm(0, 0.01); } for (iter in 1:2){ delta[iter] ~ dbeta(0.0001,0.0001); u[iter] ~ dnorm(0,01); } sdbmd.precision ~ dgamma(0.1,0.1); sdbm.precision ~ dgamma(0.1,0.1); } === Data list(biomarker= structure(.Data= c(-1.6332505600E-01, -9.9820335000E-02, 4.0692602900E-01, -8.265000E-03, -6.6739468400E-01, -1.9444291700E-01, -2.5035248500E-01, -1.592600E-02, 2.5951119500E-01, 3.1943077100E-01, 2.1915456300E-01, -7.06E-04, -1.1407237740E+00, -4.7155522000E-01, -1.4495155440E+00, 1.703600E-02, -1.9105523700E-01, -5.698021E-03, -8.4883829700E-01, 4.939000E-03), .Dim=c(5, 4)), bmd=c(-4.944000E-03, 3.520700E-02, 2.597500E-02, 2.739400E-02, 7.501000E-03), trt=c(1.00E+00, 0.00E+00, 0.00E+00, 1.00E+00, 1.00E+00), numSubj=5.00E+00) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Any simple way to make this happen?
Hi, The data is x <- c(4,3,5); I need to translate it to y <- c(1,2,3,4,1,2,3,1,2,3,4,5); i.e. for each number in x, we need to generate 1:x and put it in y. The program need to evaluate this type of calculation for millions of times in simulation. Is there any elegant way to make this happen without iteration? Many thanks!! Best, Haoda [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Any simple way to make this happen?
It works like a magic~!! Many thanks A.K. Best, Haoda From: arun Cc: R help Sent: Friday, December 28, 2012 12:51 PM Subject: Re: [R] Any simple way to make this happen? Hi, Try: y<-paste("c","(",paste(unlist(sapply(x,seq)),collapse=","),")",sep="") y #[1] "c(1,2,3,4,1,2,3,1,2,3,4,5)" A.K. - Original Message - To: "r-help@r-project.org" Cc: "haod...@yahoo.com" Sent: Friday, December 28, 2012 12:43 PM Subject: [R] Any simple way to make this happen? Hi, The data is x <- c(4,3,5); I need to translate it to y <- c(1,2,3,4,1,2,3,1,2,3,4,5); i.e. for each number in x, we need to generate 1:x and put it in y. The program need to evaluate this type of calculation for millions of times in simulation. Is there any elegant way to make this happen without iteration? Many thanks!! Best, Haoda [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Any similar solution for C# (Integrating R with C++: Rcpp, RInside, and RProtobuf)
Friends - I am pretty excited for the following talk and I was wondering if there is a similar solution for C#. I googled but didn't find a good solution. Previously, I let C# to send R code to Rscript.exe. But it is not an integrated solution. Integrating R with C++: Rcpp, RInside, and RProtobuf http://google-opensource.blogspot.com/2010/10/integrating-r-with-c-rcpp-rinside-and.html Many thanks! Haoda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R Plots for Recurrent Events - Suggestions are needed
Hi, I am wondering if there is a simple way to plot MCF(mean cumulative function) for recurrent events in R? MCF (http://www.weibull.com/hotwire/issue57/relbasics57.htm) And do you have some other recommendation in visualize recurrent events? I did some research online. Some people use ggplot2 to plot MCF, but it requires some additional coding. http://user2010.org/slides/Shentu.pdf Your help and suggestions are highly appreciated. Warm regards from Haoda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Can we fit this model in nlme or lme4?
Hi, I was wondering if the following model can be fitted by nlme/lme4. The difficult part is that the error term is combined with other parameters. The model that we need to fit is as below and the R codes to generate data is provided as well. Many thanks!!! # Y_{ijk} = (E_0 + Emax*dose_i/(ED_50+dose_i) + S_{ij} + e_{ijk})*(1-exp(k*X_{ijk}))/(1-exp(k*d)); ## Parameters to be estimated E0, Emax, ED50, sigma_S, sigma_e, kn Patients <- 100; # 100 patients nVisit <- 12; # total 12 visit d <- 6; # 6 month study dose <- c(0,5,10,20,40,100,200); visits <- seq(6/12,6,by = 6/12); # true parameters E0 <- 2; Emax <- 20; ED50 <- 10; sigma_S <- 5; sigma_e <- 4; k <- -1; dataM <- matrix(NA, nrow = nPatients*nVisit, ncol= 4); for(iter in 1:nPatients){ dose_i <- sample(dose,1); S_i <- rep(rnorm(n=1, mean=0, sd=sigma_S),nVisit); # random effect for this patients e_i <- rnorm(n=nVisit, mean=0, sd=sigma_e); response_i <- (E0+Emax*dose_i/(ED50+dose_i)+S_i+e_i)*(1-exp(k*visits))/(1-exp(k*d)); patients_i <- cbind(rep(iter,nVisit),rep(dose_i,nVisit),visits,response_i); dataM[(nVisit*(iter-1)+1):(nVisit*(iter-1)+nVisit),] <- patients_i; } colnames(dataM) <- c("PatientID","Dose","VisitTime","Response") Best, Haoda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] BRugs removed?
All - I am new to this help list. Please forgive me if this question has been asked before. A couple of questions about running BRugs in R. 1. I found that it has been removed from R package list. Why is it removed? Is there any improved package to replace BRugs? 2.I run BRugs and sometimes it crashed the R. How can I fix it? Many thanks! Best, Haoda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R plot
All - When I plot something like a<-rnorm(5) b<-rnorm(5) plot(a,b,col = "red") points(10,-10) The last point is missing because it is out of range of the first plot. I just try to switch from Matlab to R. In Matlab, it always can automatic adjust the xlim and ylim for such case. Is it possible auto adjust in R? Otherwise keep tracking xlim and ylim is really annoying. Best, Haoda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Lattice Plot Ordering?
Hi, When I plot multi-panel in R by using lattice package, the order is always starting from bottom to the top, e.g., panel 1,2,3,4 will looks like the following, 3,4 1,2 How can I change it to 1,2 3,4 ? many thanks! Best, Haoda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help in Lattice!
Hi - How can I add different notes in different panels? My data looks like ID Dose Visit Value 110 0.5 -6.5802e-02 210 1.0 2.4085e-01 310 1.5 -2.2907e-01 410 2.0 2.4074e-01 ... ... ... ... ... 270 45 30 3.0 -8.1316e-01 271 46 30 0.5 -2.0786e-01 272 46 30 1.0 -2.9336e-01 273 46 30 1.5 -5.5657e-01 274 46 30 2.0 -2.1659e-01 I use xyplot(Value ~ Visit | factor(ID), data = dataM, typ = 'o',layout = c(3,3),as.table=TRUE); to plot each patient longitudinal observations. How can I add dose information to each panel? e.g., adding "Dose = 30" Best, Haoda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Lattice xyplot help please.
Hi - I am not R expert and I would appreciate your time if you can help me about my xyplot question. I would like to add text (p-value) in a 4 panels xyplot. I thought panel = function{} should work but I am not sure where I did it wrong. The error message from the following code is "Argument subscripts is missing with no default values" xyplot(GLG ~ PD | factor(TRT) , groups = GLG_ind,strip = strip.custom(style =4),ref = T, as.table=TRUE,data = splitPD, subscripts = TRUE,cex = 2, panel = function(x, y, pvalue,subscripts,...){ panel.xyplot(x,y,...); panel.abline(h = 51.95); grid.text(paste("p-value =", pvalue[subscripts]), .25, .15, gp = gpar(cex = .8))} ) I really appreciate your time to help me. Best, Haoda Appendix - Data > pvalue [1] 0.88313298 0.02224550 0.8000 0.12663046 > splitPD PD TRT GLG GLG_ind 1 -8 30 38.5 0 2 -81 30 58.6 1 4 -33 30 35.0 0 5 -18 30 41.1 0 6 -45 90 64.3 1 8 -39 90 41.9 0 9 -45 90 56.2 1 10 -98 90 53.6 1 11 27 90 46.4 0 12 -45 90 74.2 1 15 -22 5 56.4 1 16 -25 5 63.8 1 17 4 5 50.2 0 18 -52 30 64.6 1 21 -31 60 44.5 0 22 -36 5 42.1 0 23 -56 5 37.8 0 24 -5 5 31.3 0 26 -29 5 31.7 0 27 -9 5 39.0 0 28 -9 5 26.7 0 31 -41 30 52.7 1 32 -24 30 50.4 0 33 -18 30 32.4 0 35 -36 30 41.3 0 36 -22 30 41.1 0 37 -36 90 42.5 0 39 -18 90 63.9 1 40 -25 60 40.6 0 42 -43 60 86.4 1 43 -58 60 48.1 0 44 -16 60 48.5 0 45 -26 60 59.2 1 Code works rm(list=ls()); library(lattice); library(grid); library(rpart); xyplot(GLG ~ PD | factor(TRT) , groups = GLG_ind,strip = strip.custom(style =4),ref = T, as.table=TRUE,data = splitPD, cex = 2, panel = function(x, y,...){panel.xyplot(x,y,...); panel.abline(h = 51.95); }) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.