[R] A question about bugs.R: functions for running WinBUGs from R
Dear R users, I've found bugs.R : the functions for running WinBUGs from R that is writen by Dr. Andrew Gelman who is a professor from Columbia University. The bugs.R would be very useful for me, and I think many of you know it as well. I followed the instuctions on Dr. Gelman's web to install all of documents that bugs.R needs, but when I try to run the school example the web posted in R, I got an error. Would you please help me out? I am stuck on this for a while and really frustrated now. The program and the error as follow. Thanks a lot in advance! Jiaa _ > # R code for entering the data and fitting the Bugs model for 8 schools > # analysis from Section 5.5 of "Bayesian Data Analysis". > > # To run, the Bugs model must be in the file "schools.txt" in your working > # directory and you must load in the functions in the bugs.R file (see > # http://www.stat.columbia.edu/~gelman/bugsR/). > > J <- 8 > y <- c(28,8,-3,7,-1,1,18,12) > sigma.y <- c(15,10,16,11,9,11,10,18) > schools.data <- list ("J", "y", "sigma.y") > schools.inits <- function() + list (theta=rnorm(J,0,1), mu.theta=rnorm(1,0,100), + sigma.theta=runif(1,0,100)) > schools.parameters <- c("theta", "mu.theta", "sigma.theta") > > #run in winbugs14 > > schools.sim <- bugs (schools.data, schools.inits, schools.parameters, "schools.bug", n.chains=3, n.iter=1000, version=1.4) Error: couldn't find function "bugs" --- [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] The error in R while using bugs.R function
Dear R users, I followed the instuctions on Dr. Gelman's web to install all of documents that bugs.R needs, but when I try to run the school example that the web posted in R, I got an error: couldn't find function "bugs", what's wrong? Thanks, Jia __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to convert array to c()
How about? p1<-a[1,] p1 [1] 1 5 9 p2<-a[2,] > p2 [1] 2 6 10 p3<-a[3,] > p3 [1] 3 7 11 p4<-a[4,] > p4 [1] 4 8 12 Jia - Original Message - From: "Muhammad Subianto" <[EMAIL PROTECTED]> To: Sent: Wednesday, May 18, 2005 10:18 AM Subject: [R] How to convert array to c() > Dear R-helper, > > Is there possible to make this array: > > a <- array(1:12, c(4, 3)) > > a > [,1] [,2] [,3] > [1,]159 > [2,]26 10 > [3,]37 11 > [4,]48 12 > > > > like: > c(1,5,9) > c(2,6,10) > c(3,7,11) > c(4,8,12) > > Thank you very much in advance. > Regards, > Muhammad Subianto > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] install R packages
Dear All, When I tried to install R packages I found this error: > library(survival) Loading required package: splines > install.packages("splines") --- Please select a CRAN mirror for use in this session --- Warning message: package splines is in use and will not be installed But I just opened R, and have used anything yet, how come did it say "package splines is in use"? Thanks Jia __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] install R packages--sorry last letter that I sent I had an error, this one is the right one
Dear All, When I tried to install R packages I found this error: > library(survival) Loading required package: splines > install.packages("splines") --- Please select a CRAN mirror for use in this session --- Warning message: package splines is in use and will not be installed But I just opened R, and haven't used anything yet, how come did it say "package splines is in use"? Thanks Jia __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] The error while using R2WinBUGS
Dear all, I tried to run WinBUGS model in R by using package R2WinBUGS, but I failed because of the massage : cannot calculate DIC for model in log file of WinBUGS14. In fact, the model works in WinBUGS and I can get summaries of the model, such as density, stats..., except DIC , because DIC may not be appropriate in this kind of model due to some reasons(according to the manual of WinBUGS14), and WinBUGS cannot calculate it, but this is allowed in WinBUGS. If I just ran it in WinBUGS, that would be fine, because my goal is to get the summay not DIC, but I need to run it in R, and R must have DIC. (the example as follow). I am wondering what I can do to fix it in R? for exampe: the school example: the output in R: > print(schools.sim) Inference for Bugs model at "c:/schools/schools.bug" 3 chains, each with 1000 iterations (first 500 discarded) n.sims = 1500 iterations saved mean sd 2.5% 25% 50% 75% 97.5% Rhat n.eff theta[1] 11.1 9.1 -3.0 5.0 10.0 16.0 31.8 1.1 39 . theta[8] 8.3 8.4 -6.6 2.8 8.1 12.7 26.2 1.0 64 mu.theta 7.6 5.9 -3.0 3.7 8.0 11.0 19.5 1.1 35 . deviance 60.8 2.5 57.0 59.1 60.2 62.1 66.6 1.0 170 pD = 3 and DIC = 63.8 (using the rule, pD = var(deviance)/2) Thanks a lot, Jia [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] To find how R defined the function of "coxph"?
Dear all, I am wondering if there is a way to find how R defined(or wrote) the function of "coxph"? I don not mean the one that we get by checking help(coxph), but the one like coxph<-function(){...} Thanks, Jia __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] help--package:MIX
Hi all, The package MIX is for estimation and multiple imputation for mixed categorical and continuous data. I want to use multiple imputation to impute the missing values in the covariates of Cox model, I am wondering if I could use MIX to do that. I mean that my dataset is failure time distribution, dose MIX limit the dataset only for multivariate normal datasets with missing values as package NORM? Thank you for help, Jia __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] A warning message when using mix package.
Dear all, I just start using package mix in R and am inexperienced with it. When I ran my program several times, I sometimes got the warning message, and sometimes not : Warning message: Loglik converged before variable 2 ; beta may be infinite. in: fitter(X, Y, strats, offset, init, control, weights = weights, I cannot find what is wrong with my program. Does anyone have an idea with it and whether this would affect my results? Any help would be appreciated. Thanks! By the way, I copy a part of my program and hope it would help, beta <- c(0, 0,0,0,0) # 'True' coefficients #make a matrix of covariates---# Y=cbind(z4,z5,z1,z2,z3) s<-prelim.mix(Y,2) #run MI--# MI<-vector("list",10) fit.model.mi<-vector("list",10) rngseed(1234567) # set random number generator seed for (i in 1:10){ thetahat <- em.mix(s) newtheta <- da.mix(s, thetahat, steps=2000, showits=TRUE) MI[[i]] <- imp.mix(s, newtheta) } [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] A question about MIX package
Hello all, When I used commands "ecm.mix and dabipf.mix" to do a simulation (sample size is small 100), I got an error : Steps of ECM, missing value where True/False needed. I've checked the menu, and the option "prior" of ecm.mix said that if structural zeros appear in the table, hyperparameters for those cells should be set to NA. However, it didn't say how to do that in the command. I am wondering if someone knows how to fix this. I appreciate your help, Jia __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] A question about stepwise procedures: step function
Dear all, I tried to use "step" function to do model selection, but I got an error massage. What I don't understand is that data as data.frame worked well for my other programs, how come I cannot make it run this time. Could you please tell me how I can fix it? *** >all<-data.frame(z1,z2,z3) >fit.model.all<- coxph(Surv(t,cen) ~z1+z2+z3,data=all) > reg.model.all<-step(fit.model.all) Start: AIC= 689.1 Surv(t, cen) ~ z1 + z2 + z3 Error in as.data.frame.default(data) : cannot coerce class "function" into a data.frame *** Thanks a lot! Jia __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] A question about stepwise procedures: step function
Hi, Step works for a Cox model. And I got the same error massage using stepAIC. Jia _ From: Ritwik Sinha [mailto:[EMAIL PROTECTED] Sent: Thursday, June 15, 2006 12:12 AM To: Li, Jia Subject: Re: [R] A question about stepwise procedures: step function Hi, The step documentation says "object: an object representing a model of an appropriate class (mainly '"lm"' and '"glm"'). This is used as the initial model in the stepwise search. " I wonder if it will work for a cox proportional hazard model. You could try stepAIC in MASS. On 6/14/06, Li, Jia < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote: Dear all, I tried to use "step" function to do model selection, but I got an error massage. What I don't understand is that data as data.frame worked well for my other programs, how come I cannot make it run this time. Could you please tell me how I can fix it? *** >all<-data.frame(z1,z2,z3) >fit.model.all<- coxph(Surv(t,cen) ~z1+z2+z3,data=all) > reg.model.all<-step(fit.model.all) Start: AIC= 689.1 Surv(t, cen) ~ z1 + z2 + z3 Error in as.data.frame.default(data) : cannot coerce class "function" into a data.frame *** Thanks a lot! Jia __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Ritwik Sinha Graduate Student Epidemiology and Biostatistics Case Western Reserve University http://darwin.cwru.edu/~rsinha [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] A question about stepwise procedures: step function
Sorry, I still cannot find what's wrong with it. And it seems that nothing is wrong with t. Jia > z1<-rnorm(N,0,1) > z2<-rnorm(N,3,5) > z3<-rbinom(N,1,0.6) > > prop.cens<-0.45 > cen<-rbinom(N,1,1-prop.cens) #<-- censor indicator:45% censor in the data. > t<- rexp(N) > all<-data.frame(z1,z2,z3) > fit.model.all<- coxph(Surv(t,cen) ~z1+z2+z3,data=all) > fit.model.all Call: coxph(formula = Surv(t, cen) ~ z1 + z2 + z3, data = all) coef exp(coef) se(coef) zp z1 0.057466 1.059 0.1377 0.4173 0.68 z2 0.000907 1.001 0.0332 0.0273 0.98 z3 -0.349273 0.705 0.2867 -1.2184 0.22 Likelihood ratio test=1.81 on 3 df, p=0.613 n= 100 > reg.model.all<-step(fit.model.all) Start: AIC= 376.39 Surv(t, cen) ~ z1 + z2 + z3 Error in as.data.frame.default(data) : cannot coerce class "function" into a data.frame _ From: Hong Ooi [mailto:[EMAIL PROTECTED] Sent: Thursday, June 15, 2006 10:53 AM To: Li, Jia Subject: RE: [R] A question about stepwise procedures: step function Note: This e-mail is subject to the disclaimer contained at the bottom of this message. _ t is the name of a function. If you have a variable called t in your dataset, try renaming it. _ From: [EMAIL PROTECTED] on behalf of Li, Jia Sent: Thu 15/06/2006 11:52 PM To: r-help@stat.math.ethz.ch; [EMAIL PROTECTED] Subject: Re: [R] A question about stepwise procedures: step function Hi, Step works for a Cox model. And I got the same error massage using stepAIC. Jia _ From: Ritwik Sinha [mailto:[EMAIL PROTECTED] Sent: Thursday, June 15, 2006 12:12 AM To: Li, Jia Subject: Re: [R] A question about stepwise procedures: step function Hi, The step documentation says "object: an object representing a model of an appropriate class (mainly '"lm"' and '"glm"'). This is used as the initial model in the stepwise search. " I wonder if it will work for a cox proportional hazard model. You could try stepAIC in MASS. On 6/14/06, Li, Jia < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote: Dear all, I tried to use "step" function to do model selection, but I got an error massage. What I don't understand is that data as data.frame worked well for my other programs, how come I cannot make it run this time. Could you please tell me how I can fix it? *** >all<-data.frame(z1,z2,z3) >fit.model.all<- coxph(Surv(t,cen) ~z1+z2+z3,data=all) > reg.model.all<-step(fit.model.all) Start: AIC= 689.1 Surv(t, cen) ~ z1 + z2 + z3 Error in as.data.frame.default(data) : cannot coerce class "function" into a data.frame *** Thanks a lot! Jia __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Ritwik Sinha Graduate Student Epidemiology and Biostatistics Case Western Reserve University http://darwin.cwru.edu/~rsinha [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html _ The information transmitted in this message and its attachme...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Error in step() (or stepAIC) for Cox model
Hello all, I am trying to use stepwise procedure to select covariates in Cox model and use bootstrap to repeat stepwise selection, then record how many times variables are chosen by step() in bootstrap replications. When I use step() (or stepAIC) to do model selection, I got errors. Here is the part of my code for (j in 1:mm){#<--mm=10 for (b in 1:nrow(reg.bs)){ #<--bootstrap 10 times mi<-data.frame(tlfup,cen,complete(imp,j)) #<--completed data sets after MI in.star<-sample(1:n,n,replace=T) #<--to sample id number 1-1851. data.star<-mi[in.star,] M<-coxph(Surv(tlfup,cen)~mi$trt+mi$nodes+mi$htypeed1+mi$htypeed2+mi$ngra ded2+mi$agem40 +mi$agem40sq+mi$er+mi$pr,data=data.star) reg.model<-step(M) #<--do stepwise selection reg.step[[b]]<-c((reg.model$coef)) #<-store selected variables chosen.vb[[b]]<-names(reg.step[[b]]) #<--store names of selected variables } tot.vb[[j]]<-c(unlist(chosen.vb)) } Error in reg.step[[b]] : subscript out of bounds varibles<-unlist(tot.vb) #<--change to a vector table(varibles) #<--how many times the names have been selected Error in sort(unique.default(x), na.last = TRUE) : 'x' must be atomic I figure the reason may be that when stepwise procedure selects the chosen model with no varibles, that is Start: AIC= 12436.85 Surv(tlfup, cen) ~ mi$trt + mi$nodes + mi$htypeed1 + mi$htypeed2 + mi$ngraded2 + mi$agem40 + mi$agem40sq + mi$er + mi$pr Df AIC - mi$pr1 12435 - mi$trt 1 12435 - mi$agem40sq 1 12435 - mi$agem401 12435 - mi$htypeed2 1 12435 - mi$nodes 1 12435 - mi$er1 12436 - mi$ngraded2 1 12436 - mi$htypeed1 1 12436 12437 Step: AIC= 12425.91 Surv(tlfup, cen) ~ mi$htypeed1 + mi$ngraded2 + mi$er Df AIC - mi$er1 12425 - mi$ngraded2 1 12425 - mi$htypeed1 1 12426 12426 Step: AIC= 12424.77 Surv(tlfup, cen) ~ 1 then reg.model$coef dosen't exist anymore (am I right?), but I need to count the variables that are selected by step() in bootstrap replications, what should I do? Thanks, Jia [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] One more about Error in step() (or stepAIC) for Cox model
Thank you for Prof.Ripley's suggestion. I fixed the program by adding a lower scope, and the program ran, but I still got warning messages, and don't know what is going on, would this affect my results? ... Step: AIC= 12337.74 Surv(tlfup, cen) ~ MI[[j]]$trt + MI[[j]]$agem40 + MI[[j]]$agem40sq + mhtypeed1 + mhtypeed2 Df AIC 12338 - MI[[j]]$agem40sq 1 12338 - MI[[j]]$agem401 12339 - mhtypeed2 1 12353 - mhtypeed1 1 12365 There were 50 or more warnings (use warnings() to see the first 50) Warning messages: 1: X matrix deemed to be singular; variable 8 9 in: coxph(Surv(tlfup, cen) ~ MI[[j]]$trt + MI[[j]]$nodes + MI[[j]]$ngraded2 + ... 2: X matrix deemed to be singular; variable 7 8 in: coxph(formula = Surv(tlfup, cen) ~ MI[[j]]$nodes + MI[[j]]$ngraded2 + ... ... 7: X matrix deemed to be singular; variable 7 8 in: coxph(formula = Surv(tlfup, cen) ~ MI[[j]]$trt + MI[[j]]$nodes + ... 8: X matrix deemed to be singular; variable 8 in: coxph(formula = Surv(tlfup, cen) ~ MI[[j]]$trt + MI[[j]]$nodes + ... 11: X matrix deemed to be singular; variable 7 in: coxph(formula = Surv(tlfup, cen) ~ MI[[j]]$nodes + MI[[j]]$ngraded2 + ... ... Thanks, Jia -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Monday, October 24, 2005 4:05 PM To: Li, Jia Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Error in step() (or stepAIC) for Cox model On Mon, 24 Oct 2005, Li, Jia wrote: > Hello all, > > I am trying to use stepwise procedure to select covariates in Cox > model and use bootstrap to repeat stepwise selection, then record how > many times variables are chosen by step() in bootstrap replications. > When I use step() (or stepAIC) to do model selection, I got errors. > Here is the part of my code > > for (j in 1:mm){#<--mm=10 > > for (b in 1:nrow(reg.bs)){ #<--bootstrap 10 times > > mi<-data.frame(tlfup,cen,complete(imp,j)) #<--completed data sets > after MI > > in.star<-sample(1:n,n,replace=T) #<--to sample id number 1-1851. > > data.star<-mi[in.star,] > > M<-coxph(Surv(tlfup,cen)~mi$trt+mi$nodes+mi$htypeed1+mi$htypeed2+mi$ng > ra > ded2+mi$agem40 > > +mi$agem40sq+mi$er+mi$pr,data=data.star) > > reg.model<-step(M) #<--do stepwise selection > > reg.step[[b]]<-c((reg.model$coef)) #<-store selected variables > > chosen.vb[[b]]<-names(reg.step[[b]]) #<--store names of selected > variables > > } > > tot.vb[[j]]<-c(unlist(chosen.vb)) > > } > > Error in reg.step[[b]] : subscript out of bounds > > > varibles<-unlist(tot.vb) #<--change to a vector > > table(varibles) #<--how many times the names have been > selected > > Error in sort(unique.default(x), na.last = TRUE) : >'x' must be atomic > > > I figure the reason may be that when stepwise procedure selects the > chosen model with no varibles, that is > > Start: AIC= 12436.85 > Surv(tlfup, cen) ~ mi$trt + mi$nodes + mi$htypeed1 + mi$htypeed2 + >mi$ngraded2 + mi$agem40 + mi$agem40sq + mi$er + mi$pr > > Df AIC > - mi$pr1 12435 > - mi$trt 1 12435 > - mi$agem40sq 1 12435 > - mi$agem401 12435 > - mi$htypeed2 1 12435 > - mi$nodes 1 12435 > - mi$er1 12436 > - mi$ngraded2 1 12436 > - mi$htypeed1 1 12436 >12437 > > Step: AIC= 12425.91 > Surv(tlfup, cen) ~ mi$htypeed1 + mi$ngraded2 + mi$er > > Df AIC > - mi$er1 12425 > - mi$ngraded2 1 12425 > - mi$htypeed1 1 12426 >12426 > > Step: AIC= 12424.77 > Surv(tlfup, cen) ~ 1 > > then reg.model$coef dosen't exist anymore (am I right?), but I need to > count the variables that are selected by step() in bootstrap > replications, what should I do? Specify the lower scope suitably. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] About double-bootstrap
Dear all, I have to use double-bootstrap to resample a data set. I am not familiar with double-bootstrap in R, so I am wondering if there is a function that is related to it Thanks! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html