Re: [R] Glmnet survival cox predict
Thank you, both train and test are originated from the same data object. attached the missing code: data<-read.csv("old4.csv", header=TRUE) library(imputeMissings) data<-impute(data,object = NULL ,method = "median/mode") for (i in col[13:68]) { data[i]<-lapply(data[i], factor) } for (i in col[1:12]) { data[i]<-lapply(data[i], numeric) } data$TIME<-as.numeric(data$TIME) data<-data[-c(61,62,64,65,66,67,68)] data$TIME<-ceiling(data$TIME/12) data$TIME[which(data$TIME==37)]<-36 data1 = sort(sample(nrow(data), nrow(data)*.7)) train<-data[data1,] test<-data[-data1,] so test should be the exact same, and i still can't find the issue, thank you Amir On Sat, Nov 16, 2019 at 12:00 AM David Winsemius wrote: > > On 11/15/19 10:49 AM, Amir Hadanny wrote: > > Hi all, > > i'm trying to get the prediction probabilities for a survival elastic > net. > > When i use try to predict using the train model on the test set, it > creates > > an object with the number rows of the train data (6400 rows) instead of > the > > test data (2400 rows). I really don't understand why, and that doesn't > let > > me check for performance c-index. > > > If you call most `predict` functions with a second argument that fails > to contain the predictors in the model, it returns the predictions on > the original data. The only place where the `test` object appears prior > to the predict operation is in your call to `predict.coxph`, so my guess > is that it fails to meet the requirements of the function for a valid > newdata argument. (Another thought was that maybe `test` didn't exist, > but that should have thrown an error with the predict call and the nrow > call.) > > > But since you don't provide code that creates `test` or even an > unambiguous way of examining its structure, that is entirely a guess. > > > And finally ... Rhelp is a plain text mailing list, so please to read > the message at the bottom of every transmission from the mailserver ... > i.e. read the Posting Guide. (It is not at all difficult to get > gmail.com to send plain text.) > > > -- > > David. > > > the code: > > > > data<-read.csv("old4.csv", header=TRUE) > > library(imputeMissings) > > data<-impute(data,object = NULL ,method = "median/mode") > > > > trainstatus<-train$DIED1095 > > trainTime<-train$TIME > > y<-Surv(trainTime,trainstatus) > > > > trainX<-train[-c(12,63,64,65,66,67,68,69,70,71)] > > x<-data.matrix(trainX) > > > > > > library(glmnet) > > fit <- glmnet(x,Surv(trainTime,trainstatus),family="cox",alpha=0.1, > > ,maxit=1) > > max.dev.index <- which.max(fit$dev.ratio) > > optimal.lambda <- fit$lambda[max.dev.index] > > optimal.beta <- fit$beta[,max.dev.index] > > nonzero.coef <- abs(optimal.beta)>0 > > selectedBeta <- optimal.beta[nonzero.coef] > > selectedTrainX <- x[,nonzero.coef] > > > > coxph.model<- coxph(Surv(train$TIME,train$DIED365) ~x,data=train, > > init=selectedBeta,iter=0) > > coxph.predict<-predict(coxph.model,test) > > > > nrow(test) > > 2872 > > > > nrow(train > > 6701 > > > > length(coxph.predict) > > 6701 > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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 -- To UNSUBSCRIBE and more, see 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] Glmnet survival cox predict
Hi all, i'm trying to get the prediction probabilities for a survival elastic net. When i use try to predict using the train model on the test set, it creates an object with the number rows of the train data (6400 rows) instead of the test data (2400 rows). I really don't understand why, and that doesn't let me check for performance c-index. the code: data<-read.csv("old4.csv", header=TRUE) library(imputeMissings) data<-impute(data,object = NULL ,method = "median/mode") trainstatus<-train$DIED1095 trainTime<-train$TIME y<-Surv(trainTime,trainstatus) trainX<-train[-c(12,63,64,65,66,67,68,69,70,71)] x<-data.matrix(trainX) library(glmnet) fit <- glmnet(x,Surv(trainTime,trainstatus),family="cox",alpha=0.1, ,maxit=1) max.dev.index <- which.max(fit$dev.ratio) optimal.lambda <- fit$lambda[max.dev.index] optimal.beta <- fit$beta[,max.dev.index] nonzero.coef <- abs(optimal.beta)>0 selectedBeta <- optimal.beta[nonzero.coef] selectedTrainX <- x[,nonzero.coef] coxph.model<- coxph(Surv(train$TIME,train$DIED365) ~x,data=train, init=selectedBeta,iter=0) coxph.predict<-predict(coxph.model,test) nrow(test) 2872 nrow(train 6701 length(coxph.predict) 6701 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Welcome to the "R-help" mailing list (Digest mode)
I would greatly appreciate if anybody could help with the stack-overflow question : Updating and Forecasting times series with new data | | | | | | | | | | | Updating and Forecasting times series with new dataWe can fit a time series and use the model to make forecasts, for example using: fit <- auto.arima(WWWusage) plot(forecast(fit,h=20)) Consider the following scenari... | | | | View on stackoverflow.com | Preview by Yahoo | | | | | Thank you for your time,Pemfir On Thursday, September 24, 2015 10:31 AM, "r-help-requ...@r-project.org" wrote: Welcome to the R-help@r-project.org mailing list! To post to this list, send your message to: r-help@r-project.org General information about the mailing list is at: https://stat.ethz.ch/mailman/listinfo/r-help If you ever want to unsubscribe or change your options (eg, switch to or from digest mode, change your password, etc.), visit your subscription page at: https://stat.ethz.ch/mailman/options/r-help/elexira%40yahoo.com You can also make such adjustments via email by sending a message to: r-help-requ...@r-project.org with the word `help' in the subject or body (don't include the quotes), and you will get back a message with instructions. You must know your password to change your options (including changing the password, itself) or to unsubscribe without confirmation. It is: zoha1234 Normally, Mailman will remind you of your r-project.org mailing list passwords once every month, although you can disable this if you prefer. This reminder will also include instructions on how to unsubscribe or change your account options. There is also a button on your options page that will email your current password to you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] 3D plot
Dear all, I need to plot more than one surface in 3D using R. I tried with "persp" function, it produce only one surface. Could you please help me how can I do it? The X and Y axis are the same but I have Z1 and Z2. I want to have both results in one graph. Thanks Amir -- __ Amir Darehshoorzadeh | Computer Engineering Department PostDoc Fellow | University of Ottawa, Paradise LAb Email: adare...@uottawa.ca | 800 King Edward Ave Tel: - | ON K1N 6N5, Ottawa - CANADA http://personals.ac.upc.edu/amir __ 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] Combinations
Hi every one, I have two sets T1={c1,c2,..,cn} and T2={k1,k2,...,kn}. How can I find the sets as follow: (c1,k1), (c1,k2) ...(c1,kn) (c2,k1) (c2,k2) (c2,kn) ... (cn,kn) Thanks. Amir -- __ Amir Darehshoorzadeh | Computer Engineering Department PostDoc Fellow | University of Ottawa, PARADISE LAb Email: adare...@uottawa.ca | 800 King Edward Ave Tel: - | ON K1N 6N5, Ottawa - CANADA http://personals.ac.upc.edu/amir __ 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] error in unique() command
Dear all, Good day! I have a question in my codes, would you please help me how to rectify it? these are my coded but at the last line I received the error! mac_30 = read.dta("MAC results4.dta") mac_30 map_30 = read.dta("MAP results4.dta") map_30 mac_30$weight = 1/nrow(mac_30) mac_30 map_30$weight = 1/nrow(map_30) map_30 input.data = merge(mac_30, map_30, all = TRUE) input.data.no15to19 = subset(input.data, agegroup != "15-19" | is.na(agegroup)) input.data.no15to19 fit = loess(v5q0 ~ year, input.data.no15to19, weights = weight, span = 0.5) years.predict = seq(min(input.data.no15to19$year), max(input.data.no15to19$year)) combined.method = data.frame(iso3 = unique(input.data$iso3), svdate = unique(input.data$svdate), method = "Combined method", year = years.predict) the error is: Error in data.frame(iso3 = unique(input.data3$iso3), svdate =unique(input.data3$svdate), : arguments imply differing number of rows: 1, 4, 45 I know there is only one iso3 and 4 years but what I need is forty five 1 and forty five rows of different 4 svdate exactly equivalent to forty five rows of different years. Now, how can I have the same number of rows for the different variable to continue my code for rest of analysis? Thank you so much. Kind regards, Amir __ 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] Appending many different and separate Excel files using R
Dear all, Good day! I have a problem in reading Excel files in R and appending them to each other. Suppose we have several Excel files in a directory with headers and want to use R to append them in a single file with an additional variable in the final file indicating from which files the data come from. As I have many Excel files and their sizes are very big I should write a loop in R to do the work. I will be very happy if you guide and help me to write the codes. Thank you very much in advance. Kind regards, Amir Kasaeian Amir Kasaeian, PhD Student in Biostatistics, Dept. of Epidemiology and Biostatistics, School of Public Health, Tehran University of Medical Sciences (TUMS). P.B. : 14155-6446 Cell Phone: +98-912-2063511 E-mail: akasae...@razi.tums.ac.ir amir_kasae...@yahoo.com [[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] Dominating set
Hi, Is there any way to find the Connected Dominating Set (CDS) of a graph in R? Regards, Amir __ 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] CDS (Connecting Dominating Set )
Hi, Is there any way or function in R that can find the Connecting Dominating Set? Regards, Amir -- ___ Amir Darehshoorzadeh |Comp. Architecture Dept. PhD Student |UPC-Campus Nord, C6-221 Email: a...@ac.upc.edu |c/ Jordi Girona, 1-3 Tel: |08034 Barcelona - SPAIN http://personals.ac.upc.edu/amir __ 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] number of repetition
Hi, Is there any function or command in R that show that how many times a number is repeated in an array? Regards, Amir -- ___ Amir Darehshoorzadeh |Comp. Architecture Dept. PhD Student |UPC-Campus Nord, C6-221 Email: a...@ac.upc.edu |c/ Jordi Girona, 1-3 Tel: |08034 Barcelona - SPAIN http://personals.ac.upc.edu/amir __ 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] using scatter plot for different values
Hi everyone, I have two different results which is determined by (x,y) > x1 <- c(1,5,8) > y1 <- c(8,9,10) > x2 <- c(1,7,9) > y2 <- c(5,7,9) Let call one=(x1,y1) and Two=(x2,y2) how can I draw them in R in a scatter plot showing (x,y) with two different legends (One, Two) Regards, Amir __ 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] scatter graph of more than one value
Hi, I have two X1,X2 and Y1,Y2 and I want to draw them ((X1,Y1), (X2,Y2)) in a scatter graph. How can I draw both of them in a same graph with different legends? And is there any way to show different labels on each point? Regards, Amir __ 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] cycle in a directed graph
Hi, I have a directed graph and wants to find is there any cycle in it? If it is, which nodes or edges are in the cycle. Is there any way to find the cycle in a directed graph in R? Regards, Amir __ 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] directed MST
Hi every body, Is there any function in R to find the Directed Minimum Spanning tree? There are some for undirected but I am looking for a directed Minimum spannin tree. Regards, Amir __ 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] directed minimum spanning tree
Hi, Is there any function in R to find the Directed Minimum Spanning tree? There are some for undirected but I am looking for a directed tree. Regards, Amir -- ___ Amir Darehshoorzadeh |Comp. Architecture Dept. PhD Student |UPC-Campus Nord, C6-221 Email: a...@ac.upc.edu |c/ Jordi Girona, 1-3 Tel: |08034 Barcelona - SPAIN http://personals.ac.upc.edu/amir __ 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] minimum spanning tree
Hi, I have a graph G with n nodes (n=1..100). I want to find the spanning tree over only some specific nodes (not all nodes in G), for instance nodes (2,3,6). Is there any way in R that can do this? Maybe one solution is create another subgraph g' of graph G which consists nodes 2,3,6 and their edges. Then running minimum.spanning.tree(g'). I want to know is there any better solution? Regards, Amir -- ___ Amir Darehshoorzadeh |Comp. Architecture Dept. PhD Student |UPC-Campus Nord, C6-221 Email: a...@ac.upc.edu |c/ Jordi Girona, 1-3 Tel: |08034 Barcelona - SPAIN http://personals.ac.upc.edu/amir __ 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] minimum steiner tree
Dear All, Is there any function in R that find the minimum steiner tree not minimum spanning tree? Regards, Amir __ 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] combination value
<mailto:r-help@r-project.org>Hi every one, I want to calculate the combination function in R, the value not all the possible choices. I mean cmbn(5,2)=10. Is there any function unless using factorial? Regards, Amir [[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] intersection on more than two sets
Hi, I want to do an intersection or union on more than two sets. Is there any command to do this? Regards, Amir __ 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] writing a matrix in a file
Hi, I want to write a matrix (n*m) in a file (Text file) such that the file will be as Result file (below). I use the below command but it write all numbers in one column, > write(paste(matrixname),file="test.txt",append=TRUE) how can I do this? Result file: 55 -1 -1 -1 -1 882765 668275 Matrix: [,1] [,2] [,3] [,4] [,5] [,6] [1,]55 -1 -1 -1 -1 [2,]882765 [3,]66827 5 Regards, Amir __ 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] using R and for simulating a wireless network
Hi, I want to simulate a simple wireless network in R. There is a source and destination and source sends some data packets to the destination and some routing table and so on. Does anyone have any idea and knowledge about this or are there any packages for this. The thing that I am going to do is wiring a simple simulator using R that a node sends some packet and using some table to reach the destination (Like Ns-2 but with less details) Best Regards, Amir __ 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] Container/Collection Object to keep data structures and object
Here is an example of how I attempt to add elements to a given list denoted as l: > l <- list() > l list() > l[1] <- 5 > l [[1]] [1] 5 > l[2] <- "cd" > l [[1]] [1] 5 [[2]] [1] "cd" > l[3] <- matrix(1:4,2,2) Warning message: In l[3] <- matrix(1:4, 2, 2) : number of items to replace is not a multiple of replacement length > Date: Tue, 1 Dec 2009 17:31:41 -0800 > From: ch...@sharpsteen.net > To: r-help@r-project.org > Subject: Re: [R] Container/Collection Object to keep data structures and > object > > > > Amir Liu wrote: >> >> I want to have a collection object that can store objects. In R I only saw >> lists. But these only seem to be able to handle basic objects like numbers >> and strings. Whenever I tried to add more complicated objects or just very >> simple data structures like matrices I would get an error like: >> >> "number of items to replace is not a multiple of replacement length" >> >> What is the general purpose collection object in R to store more complex >> objects, or how are these things generally approached? >> >> >> Kind Regards, >> >> Amir >> > > Lists should be capable of holding any arbitrary R object. How are you > trying to insert components such as a matrix? > -- > View this message in context: > http://n4.nabble.com/Container-Collection-Object-to-keep-data-structures-and-object-tp932656p932666.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. _ Add your Gmail and Yahoo! Mail email accounts into Hotmail - it's easy __ 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] Passing additional argument to be numerically integrated function
Hi, I try to use the numerical integration functionality of R to integrate a univariate (1D) function. Below I am integrating function const1 which works nicely as expected. But for some reasons I need to pass to my function that I want to integrate an additional parameter. If it were object-oriented I just would invoke some setter methods onto a object providing functionality described in function constX and then pass this object on. And according to the help page the function can have more than one argument, just the first needs to be the argument vector for the integration function: - f: an R function taking a numeric first argument and returning a numeric vector of the same length. Returning a non-finite element will generate an error. But let us say I have an additional argument called nb that I want to pass as well. How would I pass this second argument (and possibly more additional arguments) to make case 2 work, i.e. how this is expressed in R syntax? "integ" <- function() { # case 1: no argument for function to be integrated # integrate box function of height 1 from 0 to 2 val <- integrate(const1,0,2) print(val) # case 2: one ore more argument for function to be integrated # integrate box function of height nb from 0 to 2 nb <- 5 val1 <- integrate(constX,0,2) print(val1) } "const1" <- function(x) { return(rep(1,length(x))) } "constX" <- function(x,nb) { return(rep(nb,length(nb))) } Kind Regards, Amir -- _ View your other email accounts from your Hotmail inbox. Add them now. __ 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] Container/Collection Object to keep data structures and object
I want to have a collection object that can store objects. In R I only saw lists. But these only seem to be able to handle basic objects like numbers and strings. Whenever I tried to add more complicated objects or just very simple data structures like matrices I would get an error like: "number of items to replace is not a multiple of replacement length" What is the general purpose collection object in R to store more complex objects, or how are these things generally approached? Kind Regards, Amir _ Use Hotmail to send and receive mail from your different email accounts __ 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] request for Unsubscribe
Dear Please unsubscribe my email from mailing list of R-Help. Thanks Amir Kavousi [EMAIL PROTECTED] - [[elided Yahoo spam]] [[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.