[R] Nomogram (rms) for model with shrunk coefficients
Dear R-users, I have used the nomogram function from the rms package for a logistic regresison model made with lrm(). Everything works perfectly (r version 2.15.1 on a mac). My question is this: if my final model is not the one created by lrm, but I internally validated the model and 'shrunk' the regression coefficients and computed a new intercept, how can I build a nomogram using that object? Please see the simplified code for details: library(rms) x1<-rnorm(100,1,1) x2<-rnorm(100,1,1) y<-rbinom(100,1,0.5) d<-data.frame(x1,x2,y) attach(d) ddist<-datadist(d) options(datadist='ddist') model<-lrm(y~x1+x2, x=TRUE, y=TRUE, data=d) plot(nomogram(model)) ##Nomogram is printed, as expected ##Now the model is internally validated, and regression coefficients are penalized bootstrap<-validate(model, bw=FALSE, B=100) shrinkage<-round(bootstrap[4,5],2) final<-round(model$coef*shrinkage, 3) final.lp<-cbind(model$x)%*%final[-1] final["Intercept"]<-round(lrm.fit(y=d$y, offset=final.lp)$coef,3) final.lp<-final[1]+model$x%*%final[-1] ##The object 'final' now contains all model parameters, yet in a different fashion than the lrm-created model. Does anyone have an idea how to make this compatible again with nomogram()? Thanks in advance for any thoughts on it. Best wishes, Sander [[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] add data to a file while doing a loop
So you're looking for: write.table(dataset, file="x.txt", append=TRUE) Or do I understand your question wrongly? __ 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] Datadist error
Dear all, I have performed a simple logistic regression using the lrm function from the Design library. Now I want to plot the summary, or make a nomogram. I keep getting a datadist error: options(datadist= m.full ) not created with datadist. I have tried to specify datadist beforhand (although I don't know why it should be done): ddist<-datadist(d)##where d is my dataset options(datadist="ddist") This doesn't work. It only works when I convert my original dataset to datadistL d<-datadist(d) options(datadist="d") After this I can perform all the diagnostics and make a nomogram. However, my dataset 'd' is now completely useless, and I have to run the code to read in my data again and again to perform actions that are not related to datadist. Please let me know what I am overlooking. This is some more of the code: m.full<-lrm(event~pa+pb+pc, x=TRUE, y=TRUE, data=d) stats<-m.full$stats hshrink<-(stats["Model L.R."]-stats["d.f."])/stats["Model L.R."] hshrink ddist<-datadist(d) options(datadist="ddist") par(mfrow=c(2,2)) plot(m.fulldesign) ##Error I described f.sum<-summary(m.fulldesign) ##Error I described nomogram(m.full)##Error I described Best regards, Sander van Kuijk [[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] selecting predictors for model from dataframe
Dear all, I think I have a rather strange question, but I'd like to give it a try: I want to perform a simulation numerous times, thats why I can't do it by hand. I sample a small dataset from a very large one, and use backward selection to select significant predictors for some arbitrary outcome variable Y. These predictors are to be placed in a model, and regression coefficients estimated in a new small dataset. This is what I got: #First I sample a small dataset from the large one, lrm is logistic regression from the Design package (as is the command fastbw) fsubset=lrm(Ysub~X1sub+X2sub+X3sub+X4sub, data=dsubset1) variables[i]=as.vector(fastbw(fsubset, rule="p", type="individual", sls=0.5)[2]) variables=unlist(variables[i]) #So my "variables" are the significant ones. #Below is the sampling of the testset, in which I want to estimate a model, but the only predictors in the model should be the ones I found to be significant. dderiveset=sample(patnr, 50, replace=FALSE) dderiveset=d[dderiveset,] colnames(dderiveset)=c("pat", "X1d", "X2d", "X3d", "X4d", "Yd") attach(dderiveset) #Now in this new set of data, I want to build a model, but only using the coefficients that were significant #in the fsubset model, thus from "variables" I've tried everything and anything, even building logical expression within the model, but this was not accepted. Best regards, Sander van Kuijk [[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] Little's MCAR test
L.S., Does anyone know if there is an R library which implements Little's MCAR test for completely at random missing values? It is implemented in SPSS and SAS, and widely mentioned in the literature. Thanks in advance! Sander van Kuijk -- View this message in context: http://r.789695.n4.nabble.com/Little-s-MCAR-test-tp2331137p2331137.html Sent from the R help mailing list archive at Nabble.com. __ 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] Question regarding S4 objects and reading in excel data with RODBC
L.S. I am trying to get data from an excel sheet using the RODBC library, quite like the example on page 34 of the 'Data manipulation with R' book written by Phil Spector. It seems very straightforward, yet I get the same error everytime I try it, with different excel sheets and trying to tweek the code a bit. This is what I do: library(RODBC) sheet='X:\\example.xls' con=odbcConnectExcel(sheet) tbls=sqlTables(con) tbls$TABLE_NAME qry=paste("SELECT * FROM '",t...@table_name[1],"'", sep=" ") The error I get is: Error in paste("SELECT * FROM '", t...@table_name[1], "'", sep = " ") : trying to get slot "TABLE_NAME" from an object (class "data.frame") that is not an S4 object Does anyone know what I'm doing wrong here? I have to admit that I don't know much about sql. Best regards, Sander van Kuijk -- View this message in context: http://r.789695.n4.nabble.com/Question-regarding-S4-objects-and-reading-in-excel-data-with-RODBC-tp2313170p2313170.html Sent from the R help mailing list archive at Nabble.com. __ 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] Regular expression substitution ...
It's a bit strange: > sub("/pc", '\\%', x) [1] "%" > > sub("/pc", '%', x) [1] "\\%" Also with fixed I'm not able to get a single \ as return value. Sander On 2 nov 2009, at 12:36, Roberto Brunelli wrote: I would like to replace all occurences of /pc with \% using something like sub("/pc", "\%", x) but I am unable to make the '\' pass through. Any hint? Thanks, Roberto __ 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@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] trouble with combining png and pdf
L.S., I would like to add a downsized image to a pdf file and got stuck on the code to use. My goal is to open a pdf device, add a plot, add the downsized image, and then close the pdf device. Making the downsized image is easy using png(), png(file="x.png", width = 600, height = 600, units="px", pointsize=12) image(very large image) dev.off() making a pdf with a plot as well using pdf(), pdf(file = "y.pdf", paper="letter", width=8.5, height=11) plot(1:100) dev.off() However this produces two separate files and my goal is to export the downsized image (as png) into the pdf file (behind the plot)! Maybe anyone has some suggestions? Regards, Sander Botter Erasmus Medical Centre, Rotterdam, The Netherlands [[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.