[R] simple predict question
Excuse the simple question... I'm not sure what I'm doing wrong with predict, but let me use this example: Suppose I do: dat<-matrix(c(0,0,10,20),2,byrow=T) lm1<-lm(dat[,2]~dat[,1]) Suppose I want to generate the linearly-interpolated y-values between the point (0,0) and (0,20) at every unit interval. I thought I just do: predict(lm1, data.frame(seq(0,10,1))) to get 0,2,4,6...,18,20, but instead I just get: 12 0 20 Any suggestions? Thanks, Steven __ 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] Weibull survival modeling with covariate
I was wondering if someone familiar with survival analysis can help me with the following. I would like to fit a Weibull curve, that may be dependent on a covariate, my dataframe "labdata" that has the fields "cov", "time", and "censor". Do I do the following? wieb<-survreg(Surv(labdata$time, labadata$censor)~labdata$cov, dist="weibull") This returns: weib Call: survreg(formula = Surv(labdata$time, labdata$censor) ~ labdata$cov, dist = "weibull") Coefficients: (Intercept) labdata$cov 8.091955112 0.001552897 Scale= 0.7532474 Loglik(model)= -12633.6 Loglik(intercept only)= -12734.8 Chisq= 202.41 on 1 degrees of freedom, p= 0 n= 5496 I am not quite sure how to use the output. I see that it gives the Scale parameter. How do I find the Shape paramater as a function of the covariate? Thank you, Steven --- - Steven Shechter PhD Candidate in Industrial Engineering University of Pittsburgh www.pitt.edu/~sms13 __ 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] interpreting Weibull survival regression
Hi, I was wondering if someone can help me interpret the results of running weibreg. I run the following and get the following R output. > weibreg(Surv(time, censor)~covar) fit$fail = 0 Call: weibreg(formula = Surv(time, censor)~covar) Covariate Mean Coef Rel.Risk L-R p Wald p covar 319.880-0.002 0.998 0.000 log(scale) 0.000 8.239 3786.326 0.000 log(shape) 0.000 0.265 1.304 0.000 Events172 Total time at risk845891 Max. log. likelihood -1609.4 LR test statistic 34.4 Degrees of freedom3 Overall p-value 1.65026e-07 I would just like to find the estimated mean survival time as a function of the covariate in the model, but am not sure how to use this output to find that. Any help would be greatly appreciated. Thank you, Steven __ 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] plotting with same axes
I have used the 'par' command to overlay one plot on another. But how do I overlay it with the x-values plotted at the same points on the x-axis? Thank you, Steven __ 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] set differences
Can anyone tell me how to do set differences in R? e.g., if I have a vector a<-c(1,2,3,4,5) and another vector b<-c(2,5), how can I do something like a/b = (1,3,4)? Thanks! --- - Steven Shechter PhD Candidate in Industrial Engineering University of Pittsburgh www.pitt.edu/~sms13 __ 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] efficient filtering of matrices
I was wondering if someone can tell me the best way to search through a matrix and choose certain rows (based on certain conditions) to put into a separate matrix. What I have tried so far is very slow for a large dataset I'm working with. e.g., I have this piece of code to create a new matrix (newmat) based on my filtering conditions. Do I need to do this kind of thing where I keep rbinding? newmat<-rep(NA,12) for (i in 1:length(origmat[,1]) { if ( is.na(origmat[i,10]) | (!is.na(origmat[i,10]) & (origmat[i,2] <= origmat[i,10]) ) ) newmat<-rbind(newmat, origmat[i,]) } Thanks, Steven __ 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] 2 simple questions
Please excuse what I'm sure are very easy questions but I'm relatively new to the R environment. How can I view a range of list elements, but not all. e.g., I had a matrix of patients and then split them out by patient id. I know I can do patlist[[1]] to see the first one, but how can I view, say, the first ten patients? My other question is how to count how many patients have a record in which a certain condition holds. E.g., I was trying something like this to get a count: ctr<-0 temp<-lapply(mylist, function(x){is.na(x$date1[1]) & !is.na(x$date2[1])) ctr<-ctr+1}) But I don't think that's working correctly. Thanks, Steven __ 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] from list to dataframe
I was wondering if someone can help me figure out the following: I have two patient datasets, ds1 and ds2. ds1 has fields "patid", "date", and "lab1". ds2 has "patid", "date", and "lab2". I want to find all the patids that have at least 2 dated records for each lab. I started by splitting each dataset by patid, to create ds1.list and ds2.list. Then I did some processing (with sapply) to each list to get the lengths of each patient list item. Then I kind of lost my way and things got messy as I tried to extract just the patids of those with lengths >= 2, convert them to dataframes (which I didn't have much success with), and then merge the two dataframes to get a vector of the desired patids. Any help would be much appreciated. Thanks, Steven __ 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] obtaining first and last record for rows with same identifier
I have a dataframe that contains fields such as patid, labdate, labvalue. The same patid may show up in multiple rows because of lab measurements on multiple days. Is there a simple way to obtain just the first and last record for each patient, or do I need to write some code that performs that. Thanks, Steven __ 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