Re: [R] Calculate Specificity and Sensitivity for a given threshold value
Hi Pierre-Jean, Sensitivity (Se) and specificity (Sp) are calculated for cutoffs stored in the performance x.values of your prediction for Se and Sp: For example, let's generate the performance for Se and Sp: sens - performance(pred,sens) spec - performance(pred,spec) Now, you can have acces to: [EMAIL PROTECTED] # (or [EMAIL PROTECTED]), which is the list of cutoffs [EMAIL PROTECTED] # for the corresponding Se [EMAIL PROTECTED] # for the corresponding Sp You can for example sum up this information in a table: (SeSp - cbind ([EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED])) You can also write a function to give Se and Sp for a specific cutoff, but you will have to define what to do for cutoffs not stored in the list. For example, the following function keeps the closest stored cutoff to give corresponding Se and Sp (but this is not always the best solution, you may want to define your own way to interpolate): se.sp - function (cutoff, performance){ sens - performance(pred,sens) spec - performance(pred,spec) num.cutoff - which.min(abs([EMAIL PROTECTED] - cutoff)) return(list([EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED] [[1]][num.cutoff])) } se.sp(.5, pred) Hope this helps, Nael On Thu, Nov 13, 2008 at 5:59 PM, [EMAIL PROTECTED]wrote: Hi Frank, Thank you for your answer. In fact, I don't use this for clinical research practice. I am currently testing several scoring methods and I'd like to know which one is the most effective and which threshold value I should apply to discriminate positives and negatives. So, any idea for my problem ? Pierre-Jean -Original Message- From: Frank E Harrell Jr [mailto:[EMAIL PROTECTED] Sent: Thursday, November 13, 2008 5:00 PM To: Breton, Pierre-Jean-EXT RD/FR Cc: r-help@r-project.org Subject: Re: [R] Calculate Specificity and Sensitivity for a given threshold value Kaliss wrote: Hi list, I'm new to R and I'm currently using ROCR package. Data in input look like this: DIAGNOSIS SCORE 1 0.387945 1 0.50405 1 0.435667 1 0.358057 1 0.583512 1 0.387945 1 0.531795 1 0.527148 0 0.526397 0 0.372935 1 0.861097 And I run the following simple code: d - read.table(inputFile, header=TRUE); pred - prediction(d$SCORE, d$DIAGNOSIS); perf - performance( pred, tpr, fpr); plot(perf) So building the curve works easily. My question is: can I have the specificity and the sensitivity for a score threshold = 0.5 (for example)? How do I compute this ? Thank you in advance Beware of the utility/loss function you are implicitly assuming with this approach. It is quite oversimplified. In clinical practice the cost of a false positive or false negative (which comes from a cost function and the simple forward probability of a positive diagnosis, e.g., from a basic logistic regression model if you start with a cohort study) vary with the type of patient being diagnosed. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ 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.
Re: [R] detect repeated number in a vector
Can this be an answer ? which(v %in% names(table(v)[table(v)1])) [1] 2 5 Nael On Wed, Oct 8, 2008 at 8:36 PM, liujb [EMAIL PROTECTED] wrote: Dear R users, I have this vector that consists numeric numbers. Is there a command that detects the repeated numbers in a vector and returns the index of the repeated numbers (or the actual numbers)? For example, v - c(3,4,5,7,4). The command would return me index 2 and 5 (or the repeated number, 4). Thank you very much, Julia -- View this message in context: http://www.nabble.com/detect-repeated-number-in-a-vector-tp19884768p19884768.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. [[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] vectorized sub, gsub, grep, etc.
Hi John, Wouldn't you get the same with just mapply(sub, patt, repl, X) ? Nael On Tue, Oct 7, 2008 at 9:58 PM, Thaden, John J [EMAIL PROTECTED] wrote: R pattern-matching and replacement functions are vectorized: they can operate on vectors of targets. However, they can only use one pattern and replacement. Here is code to apply a different pattern and replacement for every target. My question: can it be done better? sub2 - function(pattern, replacement, x) { len - length(x) if (length(pattern) == 1) pattern - rep(pattern, len) if (length(replacement) == 1) replacement - rep(replacement, len) FUN - function(i, ...) { sub(pattern[i], replacement[i], x[i], fixed = TRUE) } idx - 1:length(x) sapply(idx, FUN) } #Example X - c(ab, cd, ef) patt - c(b, cd, a) repl - c(B, CD, A) sub2(patt, repl, X) -John Confidentiality Notice: This e-mail message, including a...{{dropped:8}} __ 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.
Re: [R] How can I easily rbind a list of data frames into one data frame?
Try do.call(rbind, nameofyourlist) Nael On Sat, Sep 27, 2008 at 8:51 AM, Matthew Pettis [EMAIL PROTECTED]wrote: Hi, I have a list output from the 'lapply' function where the value of each element of a list is a data frame (each data frame in the list has the same column types). How can I rbind all of the list entry values into one data frame? Thanks, Matt -- It is from the wellspring of our despair and the places that we are broken that we come to repair the world. -- Murray Waas __ 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.
Re: [R] Return a list
The answers that were previously given allow you to easily extract results from your returned list, but if I understand well, this list is created only because you cannot return several arguments whereas you need to keep the values of a, b, c, etc. Am I right? Another solution would be to directly send the values you want to keep into the environment where they are needed. The following example supposes you need to keep a only in the upper environment from which your function was launched, and b in another one (e.g. .GlobalEnv). Hope this may help. Nael # Here is a function such as yours: test - function(){ + a - 1 + b - 2 + return(list(a=a, b=b, c=c)) + } result - test() (a - result$a) [1] 1 (b - result$b) [1] 2 rm(a, b) # Now our variables will be automatically assigned into the chosen environment test2 - function(){ + a - 1 + b - 2 + assign(a, a, envir=parent.frame(n=1)) + assign(b, b, envir=.GlobalEnv) + return(NULL) + } # Suppose test2 is launched by another function test2.launcher - function() { + test2() + print(paste(a exists inside test2.launcher:, exists(a))) + print(paste(b exists inside test2.launcher:, exists(b))) + return (NULL) + } test2.launcher() [1] a exists inside test2.launcher: TRUE [1] b exists inside test2.launcher: TRUE NULL exists(a)# a still exists in the upper environment [1] FALSE exists(b)# b does not [1] TRUE On Fri, Sep 26, 2008 at 9:39 PM, Wacek Kusnierczyk [EMAIL PROTECTED] wrote: Mike Prager wrote: Stefan Fritsch [EMAIL PROTECTED] wrote: I have several output variables which I give back with the list command. test - function {return(list(a,b,c,d,e,f,g,...))} After the usage of the function I want to assign the variables to the output variables. result - test() a - result$a b - result$b c - result$c d - result$d ... is there a more elegant way to assign these variables, without writing them all down? arguably ugly and risky, but simple: for (name in names(result)) assign(name, result[[name]]) (note, for this to work you actually need to name the components of the returned list: return(list(a=a,b=b,...))) vQ __ 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.
Re: [R] Converting 1-D array to vector
You were very close to an answer : as.vector(unlist(df[1,])) Nael On Wed, Aug 27, 2008 at 7:53 AM, Ronnen Levinson [EMAIL PROTECTED] wrote: Hi. How do I convert a one-dimensional array of characters to a character vector? In the example below I am trying to get the result c(a,d). The function as.vector() returns the same one-dimensional array, and unlist() returns something more complicated than I seek. Yours truly, Ronnen. P.S. E-mailed CCs of posted replies appreciated. df=data.frame(x=letters[1:3],y=letters[4:6]) df x y 1 a d 2 b e 3 c f df[1,] x y 1 a d as.vector(df[1,]) x y 1 a d unlist(df[1,]) x y a d Levels: a b c d e f c(a,d) # desired result [1] a d version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 7.0 year 2008 month 04 day22 svn rev45424 language R version.string R version 2.7.0 (2008-04-22) -- Ronnen Levinson, Ph.D. scientist, Lawrence Berkeley National Lab The Onion horoscope: Libra September 23 - October 23 Your tactics of overwhelming your opposition with spectacular shows of force and choking the roads with fleeing refugees will be seen as inappropriate by the other electronics wholesalers. __ 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.
Re: [R] Coefficients of Logistic Regression from bootstrap - how to get them?
Hi Michal, This paper by John Fox may help you to precise what you are looking for and to perform your analyses http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-bootstrapping.pdf Nael On Tue, Jul 22, 2008 at 3:51 PM, Michal Figurski [EMAIL PROTECTED] wrote: Dear all, I don't want to argue with anybody about words or about what bootstrap is suitable for - I know too little for that. All I need is help to get the *equation coefficients* optimized by bootstrap - either by one of the functions or by simple median. Please help, -- Michal J. Figurski HUP, Pathology Laboratory Medicine Xenobiotics Toxicokinetics Research Laboratory 3400 Spruce St. 7 Maloney Philadelphia, PA 19104 tel. (215) 662-3413 Frank E Harrell Jr wrote: Michal Figurski wrote: Frank, How does bootstrap improve on that? I don't know, but I have an idea. Since the data in my set are just a small sample of a big population, then if I use my whole dataset to obtain max likelihood estimates, these estimates may be best for this dataset, but far from ideal for the whole population. The bootstrap, being a resampling procedure from your sample, has the same issues about the population as MLEs. I used bootstrap to virtually increase the size of my dataset, it should result in estimates more close to that from the population - isn't it the purpose of bootstrap? No When I use such median coefficients on another dataset (another sample from population), the predictions are better, than using max likelihood estimates. I have already tested that and it worked! Then your testing procedure is probably not valid. I am not a statistician and I don't feel what overfitting is, but it may be just another word for the same idea. Nevertheless, I would still like to know how can I get the coeffcients for the model that gives the nearly unbiased estimates. I greatly appreciate your help. More info in my book Regression Modeling Strategies. Frank -- Michal J. Figurski HUP, Pathology Laboratory Medicine Xenobiotics Toxicokinetics Research Laboratory 3400 Spruce St. 7 Maloney Philadelphia, PA 19104 tel. (215) 662-3413 Frank E Harrell Jr wrote: Michal Figurski wrote: Hello all, I am trying to optimize my logistic regression model by using bootstrap. I was previously using SAS for this kind of tasks, but I am now switching to R. My data frame consists of 5 columns and has 109 rows. Each row is a single record composed of the following values: Subject_name, numeric1, numeric2, numeric3 and outcome (yes or no). All three numerics are used to predict outcome using LR. In SAS I have written a macro, that was splitting the dataset, running LR on one half of data and making predictions on second half. Then it was collecting the equation coefficients from each iteration of bootstrap. Later I was just taking medians of these coefficients from all iterations, and used them as an optimal model - it really worked well! Why not use maximum likelihood estimation, i.e., the coefficients from the original fit. How does the bootstrap improve on that? Now I want to do the same in R. I tried to use the 'validate' or 'calibrate' functions from package Design, and I also experimented with function 'sm.binomial.bootstrap' from package sm. I tried also the function 'boot' from package boot, though without success - in my case it randomly selected _columns_ from my data frame, while I wanted it to select _rows_. validate and calibrate in Design do resampling on the rows Resampling is mainly used to get a nearly unbiased estimate of the model performance, i.e., to correct for overfitting. Frank Harrell Though the main point here is the optimized LR equation. I would appreciate any help on how to extract the LR equation coefficients from any of these bootstrap functions, in the same form as given by 'glm' or 'lrm'. Many thanks in advance! __ 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.
Re: [R] multiplication question
Hi Murali, Just an idea, probably not the best : x-1:4 y-1:6 z-matrix(1:(length(x)*length(y)),nrow=length(x)) I - matrix(1,nrow=length(x),ncol=length(y)) I[row(I)==col(I)] - 0 sum (outer (x, y, '*') * I) sum (outer (x, y, '*') * z * I) Hope this helps, Nael On Wed, Jul 2, 2008 at 6:30 PM, Murali Menon [EMAIL PROTECTED] wrote: folks, is there a clever way to compute the sum of the product of two vectors such that the common indices are not multiplied together? i.e. if i have vectors X, Y, how can i compute Sum (X[i] * Y[j]) i != j where i != j also, what if i wanted Sum (X[i] * Y[j] * R[i, j]) i != j where R is a matrix? thanks, murali _ Enter the Zune-A-Day Giveaway for your chance to win day after day after day M_Mobile_Zune_V1 [[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.
Re: [R] extracting columns from a list
Hi Mohamed Try: lapply (NameOfYourList, function (dat, NumCol) dat[,NumCol], c(12,13)) But there must be a shorter way to write this. Nael On Fri, May 23, 2008 at 3:37 PM, mohamed nur anisah [EMAIL PROTECTED] wrote: Dear all, i have 2 lists of data with each of the list contain 14 columns. How am i going to extract column 12 and 13 from each of the list ?? and can i combine my extracted columns to form a single list. Attach with are my data. Your coorperation is highly appreciated. Many thanks Regards, Anisah [[1]] CS(O) id no.anchor ref loc.start loc.end CS(O).size CS(O)ref.density tested loc.start loc.end breakp.start breakp.end den of anchor 1 CS 2.0 3 mmu19 6465196 6978022 512826 6 cfa18 55567952 55782336 6978022699273428 2 CS 3.057 mmu19 6992734 102499663257232 17 cfa18 55792632 57688808 10249966 1027743025 3 CS 4.021 mmu19 10277430 10955201 61 31 cfa18 57721864 58419812 10955201 1100852636 4 CS 5.0 2 mmu19 11008526 11045352 36826 54 cfa18 58462088 58518608 11045352 1131686532 5 CS 6.0 7 mmu19 11316865 11814604 497739 14 cfa21 53902028 53514536 11814604 1193722837 6 CS 7.014 mmu19 11937228 138476331910405 7 cfa18 40111560 41204940 13847633 1451509117 7 CS 8.0 3 mmu19 14515091 160227701507679 2 cfa1 82195232 83511824 16022770 16199850 5 8 CS 9.025 mmu19 16199850 236258567426006 3 cfa1 83903856 90638880 23625856 2375455414 9 CS 10.033 mmu19 23754554 296761925921638 6 cfa1 90773872 96913624 29676192 2976391816 10CS 11.0 6 mmu19 29763918 30164446 400528 15 cfa11 29919668 30510776 30164446 30611872 8 11CS 12.019 mmu19 30611872 345583123946440 5 cfa26 38767664 41958808 34558312 3473440415 12 CSO 13.173 mmu19 34734404 440096169275212 8 cfa28 7343952 15872122 44009616 4408825621 13 CSO 13.271 mmu19 44088256 535826329494376 7 cfa28 15923283 24830712 53582632 5365479614 [[2]] CS(O) id no.anchor ref loc.start loc.end CS(O).size CS(O)ref.density tested loc.start loc.end breakp.start breakp.end den of anchor 1CSO 2.1 4 mmuX 7311438 7428353 116915 34 cfaX 41732964 41660008 7428353835693216 2CSO 2.241 mmuX 8356932 20225456 11868524 3 cfaX 32299338 41540632 20225456 2064158413 3CSO 2.3 8 mmuX 20641584 33046200 12404616 1 cfaX 91770240 94412912 33046200 3317518815 4CSO 3.173 mmuX 33175188 57970280 24795092 3 cfaX 94538728 114133200 57970280 64939220 3 5CSO 3.229 mmuX 64939220 700112805072060 6 cfaX 119319152 124625688 70011280 7003978432 6 CS 4.021 mmuX 70039784 70677328 637544 33 cfaX 124652504 125280776 70677328 7124127229 7CSO 5.1 2 mmuX 71241272 71362456 121184 17 cfaX 125764816 125872960 71362456 7142557614 8CSO 6.1 4 mmuX 71425576 71824776 399200 10 cfaX 125917392 126261784 71824776 73894168 6 9CSO 6.2 2 mmuX 73894168 74014744 120576 17 cfaX 6363930 1898656 74014744 7470540811 10 CSO 6.317 mmuX 74705408 90487648 15782240 1 cfaX 32034930 19573208 90487648 9122816010 11 CSO 6.449 mmuX 91228160 1010581929830032 5 cfaX 51733740 61930260101058192 101967264 9 12CS 7.0 3 mmuX 101967264 102176888 209624 14 cfaX 62797768 63194052102176888 10223004011 13 CSO 8.1 2 mmuX 102230040 102409592 179552 11 cfaX 63307688 63460248102409592 103123352 9 14 CSO 8.216 mmuX 103123352 1105914647468112 2 cfaX 63896752 71000280110591464 116044144 2 15CS 9.0 2 mmuX 116044144 116407200 363056 6 cfaX 71543016 71752808116407200 118512328 1 16CS 10.024 mmuX 118512328 131185424 12673096 2 cfaX 72291072 79468544131185424 13161668820 17CS 11.0 8 mmuX 131616688 132395992 779304 10 cfaX 79821128 80586408132395992 13246176017 18CS 12.021 mmuX 132461760 1375643685102608 4 cfaX 80674704 85936464137564368 13792777612 19 CSO 13.114 mmuX 137927776 1427167524788976 3 cfaX 86288848 90933784142716752 145888160 5 20 CSO 13.2
Re: [R] extracting columns from a list
I forgot to answer to the last part of your question. I think what you call a list is actually an element of a list, right? If so, the command you want depends on the way you want to combine these elements. For example, the following lines will extract columns 12 and 13 of any array-like element of your list and bind them into columns of a same array (if all your elements have the same number of rows). List2 - lapply (NameOfYourList, function (dat, NumCol) dat[,NumCol], c(12,13)) Array2 - do.call (cbind, List2) If you meant something else by 'combine, please be more explicit. Nael On Fri, May 23, 2008 at 3:54 PM, N. Lapidus [EMAIL PROTECTED] wrote: Hi Mohamed Try: lapply (NameOfYourList, function (dat, NumCol) dat[,NumCol], c(12,13)) But there must be a shorter way to write this. Nael On Fri, May 23, 2008 at 3:37 PM, mohamed nur anisah [EMAIL PROTECTED] wrote: Dear all, i have 2 lists of data with each of the list contain 14 columns. How am i going to extract column 12 and 13 from each of the list ?? and can i combine my extracted columns to form a single list. Attach with are my data. Your coorperation is highly appreciated. Many thanks Regards, Anisah [[1]] CS(O) id no.anchor ref loc.start loc.end CS(O).size CS(O)ref.density tested loc.start loc.end breakp.start breakp.end den of anchor 1 CS 2.0 3 mmu19 6465196 6978022 512826 6 cfa18 55567952 55782336 6978022699273428 2 CS 3.057 mmu19 6992734 102499663257232 17 cfa18 55792632 57688808 10249966 1027743025 3 CS 4.021 mmu19 10277430 10955201 61 31 cfa18 57721864 58419812 10955201 1100852636 4 CS 5.0 2 mmu19 11008526 11045352 36826 54 cfa18 58462088 58518608 11045352 1131686532 5 CS 6.0 7 mmu19 11316865 11814604 497739 14 cfa21 53902028 53514536 11814604 1193722837 6 CS 7.014 mmu19 11937228 138476331910405 7 cfa18 40111560 41204940 13847633 1451509117 7 CS 8.0 3 mmu19 14515091 160227701507679 2 cfa1 82195232 83511824 16022770 16199850 5 8 CS 9.025 mmu19 16199850 236258567426006 3 cfa1 83903856 90638880 23625856 2375455414 9 CS 10.033 mmu19 23754554 296761925921638 6 cfa1 90773872 96913624 29676192 2976391816 10CS 11.0 6 mmu19 29763918 30164446 400528 15 cfa11 29919668 30510776 30164446 30611872 8 11CS 12.019 mmu19 30611872 345583123946440 5 cfa26 38767664 41958808 34558312 3473440415 12 CSO 13.173 mmu19 34734404 440096169275212 8 cfa28 7343952 15872122 44009616 4408825621 13 CSO 13.271 mmu19 44088256 535826329494376 7 cfa28 15923283 24830712 53582632 5365479614 [[2]] CS(O) id no.anchor ref loc.start loc.end CS(O).size CS(O)ref.density tested loc.start loc.end breakp.start breakp.end den of anchor 1CSO 2.1 4 mmuX 7311438 7428353 116915 34 cfaX 41732964 41660008 7428353835693216 2CSO 2.241 mmuX 8356932 20225456 11868524 3 cfaX 32299338 41540632 20225456 2064158413 3CSO 2.3 8 mmuX 20641584 33046200 12404616 1 cfaX 91770240 94412912 33046200 3317518815 4CSO 3.173 mmuX 33175188 57970280 24795092 3 cfaX 94538728 114133200 57970280 64939220 3 5CSO 3.229 mmuX 64939220 700112805072060 6 cfaX 119319152 124625688 70011280 7003978432 6 CS 4.021 mmuX 70039784 70677328 637544 33 cfaX 124652504 125280776 70677328 7124127229 7CSO 5.1 2 mmuX 71241272 71362456 121184 17 cfaX 125764816 125872960 71362456 7142557614 8CSO 6.1 4 mmuX 71425576 71824776 399200 10 cfaX 125917392 126261784 71824776 73894168 6 9CSO 6.2 2 mmuX 73894168 74014744 120576 17 cfaX 6363930 1898656 74014744 7470540811 10 CSO 6.317 mmuX 74705408 90487648 15782240 1 cfaX 32034930 19573208 90487648 9122816010 11 CSO 6.449 mmuX 91228160 1010581929830032 5 cfaX 51733740 61930260101058192 101967264 9 12CS 7.0 3 mmuX 101967264 102176888 209624 14 cfaX 62797768 63194052102176888 10223004011 13 CSO 8.1 2 mmuX 102230040 102409592 179552 11 cfaX 63307688 63460248102409592 103123352 9 14 CSO 8.216 mmuX 103123352 1105914647468112 2 cfaX 63896752 71000280110591464 116044144
Re: [R] Constructing dummy variables for months for a time series object
GenDummyVar - function (NumMonth) rep(c(rep(0, NumMonth-1), 1, rep(0, 12-NumMonth)), 17) NameDummy - c(DJan, DFeb, DMar, DApr, DMay, DJun, DJul, DAug, DSep, DOct, DNov, DDec) for (NumMonth in 1:12) assign(NameDummy, GenDummyVar (NumMonth)) DJan [1] 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 [74] 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 [147] 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 DFeb [1] 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 [74] 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 [147] 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 Is this what you need ? Why 11 (and not 12) months ? Nael On Fri, Apr 25, 2008 at 9:40 AM, Megh Dal [EMAIL PROTECTED] wrote: I have a TS of monthly observations. head(data4) 1991(1) 1991(2) 1991(3) 1991(4) 1991(5) 1991(6) 12.00864 11.94203 11.98386 12.01900 12.19226 12.15488 Now I want to make 11 dummy variables indicating months. Therefore I did followings : For Jan : rep(c(rep(0,0), 1, rep(0, 11)), 17) For Feb : rep(c(rep(0,1), 1, rep(0, 10)), 17) and so on But my question is there any way to aumate this? Or I have to do the above thing for all 11 months? - [[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. [[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] Constructing dummy variables for months for a time series object
Oops.. the last line should have been : for (NumMonth in 1:12) assign(NameDummy[NumMonth], GenDummyVar (NumMonth)) On Fri, Apr 25, 2008 at 10:18 AM, N. Lapidus [EMAIL PROTECTED] wrote: GenDummyVar - function (NumMonth) rep(c(rep(0, NumMonth-1), 1, rep(0, 12-NumMonth)), 17) NameDummy - c(DJan, DFeb, DMar, DApr, DMay, DJun, DJul, DAug, DSep, DOct, DNov, DDec) for (NumMonth in 1:12) assign(NameDummy, GenDummyVar (NumMonth)) DJan [1] 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 [74] 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 [147] 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 DFeb [1] 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 [74] 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 [147] 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 Is this what you need ? Why 11 (and not 12) months ? Nael On Fri, Apr 25, 2008 at 9:40 AM, Megh Dal [EMAIL PROTECTED] wrote: I have a TS of monthly observations. head(data4) 1991(1) 1991(2) 1991(3) 1991(4) 1991(5) 1991(6) 12.00864 11.94203 11.98386 12.01900 12.19226 12.15488 Now I want to make 11 dummy variables indicating months. Therefore I did followings : For Jan : rep(c(rep(0,0), 1, rep(0, 11)), 17) For Feb : rep(c(rep(0,1), 1, rep(0, 10)), 17) and so on But my question is there any way to aumate this? Or I have to do the above thing for all 11 months? - [[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. [[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] locate the rows in a dataframe with some criteria
Hi Zhihua, M - data.frame (x=c(10, 13, 8, 11), y=c('A', 'B', 'A', 'A')) which (M$x = 10 M$y == 'A') # [1] 1 4 Hope it helps, Nael 2008/3/7 N. Lapidus [EMAIL PROTECTED]: Hi Zhihua, M - data.frame (x=c(10, 13, 8, 11), y=c('A', 'B', 'A', 'A')) which (M$x = 10 M$y == 'A') # [1] 1 4 Hope it helps, Nael 2008/3/7 zhihuali [EMAIL PROTECTED]: Hi, netters, This is probably a rookie question but I couldn't find the answer after hours of searching and trying. Suppose there'a a dataframe M: x y 10 A 13 B 8 A 11 A I want to locate the rows where x =10 and y=A. I know how to do it to vectors by using which, but how to do it with the dataframe? Thank you very much! Zhihua Li _ MSN ÖÐÎÄÍø£¬×îÐÂʱÉÐÉú»î×ÊѶ£¬°×Áì¾Û¼¯ÃÅ»§¡£ [[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.
Re: [R] How can I join two lists?
Try c(q1,q2) Nael On Jan 25, 2008 4:45 PM, [EMAIL PROTECTED] wrote: How can I join two lists? I have q1 and q2 and I want to merge them. I have tried to use the comand merge, but not work. Any solutions? Thanks! q1 $Input1 7.84615384615385 0.5 $Input2 8.92307692307692 -3.2 $Input3 4.53846153846154 -5 q2 $Input1 7.84615384615385 2 $Input2 8.92307692307692 -0.3125 $Input3 4.53846153846154 -0.2 __ 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.
Re: [R] Function for AUC?
Hi Armin, Do you know the rocr package ? This is very easy to draw ROC curves and to calculate AUC with it. http://rocr.bioinf.mpi-sb.mpg.de/ Hope this will help. Nael On Dec 17, 2007 2:58 AM, Stephen Weigand [EMAIL PROTECTED] wrote: RSiteSearch(AUC) would lead you to http://finzi.psych.upenn.edu/R/Rhelp02a/archive/46416.html On Dec 13, 2007 12:38 PM, Armin Goralczyk [EMAIL PROTECTED] wrote: Hello Is there an easy way, i.e. a function in a package, to calculate the area under the curve (AUC) for drug serum levels? Thanks for any advice -- Armin Goralczyk, M.D. -- Universitätsmedizin Göttingen Abteilung Allgemein- und Viszeralchirurgie Rudolf-Koch-Str. 40 39099 Göttingen -- Dept. of General Surgery University of Göttingen Göttingen, Germany -- http://www.chirurgie-goettingen.de __ 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.