[R] stiff delay differential equations
Hello List, Can you recommend me if odeSolve can handle stiff delay differential equations with discontinuities? Or any other package? Best, -m __ 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] list to matrix?
On Wed, Dec 5, 2012 at 12:02 AM, arun smartpink...@yahoo.com wrote: Hi, p - lapply(1:1e6, function(i)c(i, log2(i))) system.time(z1 - t(sapply(p,function(x)x))) # user system elapsed # 2.568 0.048 2.619 system.time(z1 - do.call(rbind,p)) # user system elapsed # 4.000 0.052 4.060 A.K. Thanks for that Arun -- I'll have to look into why rbind is so slow. Some interesting notes: 1) On my machine t(sapply(p, function(x) x)) is about 2x faster than t(sapply(p, identity)) 2) Similarly, do.call(rbind, p) is about 4x slower than do.call(cbind, p) which all goes to show, profiling is all-important (as Bill reminds me often) and often counter-intuitive. Michael __ 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 do I get internal nodes of dendograms produced by R?
Le mardi 04 décembre 2012 à 16:17 -0500, sagnik ray choudhury a écrit : I am using R for hierarchical clustering of a number of documents. I have a distance matrix on which I have applied hclust method. When I plot the result of hclust method, I can see the dendogram plotted. What I need now is the dendogram stored as a tree in a data structure. My goal is to automatically label all internal nodes. For that, I need to know, which leaf nodes make a first level cluster, and which first level clusters make a second level cluster and so on. Is there a way in R to get this information? You probably want to convert you 'hclust' object to a 'dendrogram' object using as.dendrogram(), and work with that tree. See ?dendrogram, in particular the Details section. My two cents __ 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] Global variable in the C code used to create R extension
Hi , I am writing a function in C and i wish to call it from R. Thanks to this tutorial , this is easily possible - http://www.nceas.ucsb.edu/scicomp/usecases/CreateRPackageWithC Now , i have a server written in R which listens on a port for requests and process the requests. Now what i need is to load a large amount of data in startup of the server. And later this data should be available to any part of the R. So basically i want to maintain a global pointer to the data , i have loaded and access them globally from the C code within the R extension which is executed from any wehre in the code. How can i achieve this. Thanks Vineeth [[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] Problem in summary of var results
Hello I am running var on dataset data1 is the name of my dataset cn.chf us.chf 2005-07-01 -1.18656633 -1.18656633 2005-07-04 -0.48835920 -0.48835920 2005-07-05 -0.01534272 -0.01534272 2005-07-06 0.08825279 0.08825279 2005-07-07 0.34223563 0.34223563 2005-07-08 -0.05776229 -0.05776229 commands which I am usings are 1) lag.var - VARselect(data1, 10, type=both)$selection[AIC(n)] 2) reg1 - VAR(data1, p=lag.var) but when I am saying summary(reg1) and I am getting same error for irfs as well. Its's giving me and error Error in merge(lhs, rhs, all = FALSE) : error in evaluating the argument 'y' in selecting a method for function 'merge': Error: argument rhs is missing, with no default Please help me how to solve this :-( Regards -- Akhil Dua Consultant National Institute of Public Finance and Policy [[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] request
Dear Dr. bernhard cc. r-help Thank you very much for deverlopping rneos package. I read the document of rneos. however, due to my inability, i could not figure-out how to connect with neos server from R environment. let me explain the steps, i took. my laptop is using wireless of my laboratory. to connect the internet, i need proxy address and specific port (that i have mentioned in protocols in CreateNeosComm). However, the proxy server does not have any password though to access wifi i need password. After inserting the protocols as shown in Input (below), i have go the output as shown in below. input library (rneos) NC-CreateNeosComm(curlopts=list(httpheader=c('content-type'=text/xml, 'User-Agent'=R), protocols=proxy.noc.titech.ac.jp:3128, port=3332),curlhandle=getCurlHandle()) #to check the neos server is activeNeosServer is alive is returned Nping(convert=T, nc=NC) output library (rneos) NC-CreateNeosComm(curlopts=list(httpheader=c('content-type'=text/xml, 'User-Agent'=R), protocols=proxy.noc.titech.ac.jp:3128, port=3332),curlhandle=getCurlHandle()) Error in match(x, table, nomatch = 0L) : object 'proxy.noc.titech.ac.jp' not found #to check the neos server is activeNeosServer is alive is returned Nping(convert=T, nc=NC) Error in .postForm(curl, .opts, .params, style) : Stale CURL handle being passed to libcurl Error in curlSetOpt(writefunction = NULL, curl = curl) : Stale CURL handle being passed to libcurl Since this procedure is not working, would you suggest me how can i fix the problem? i appreciate your help. -- With best Regards Rubel Das Hanaoka Research Group/Transport Planning Dept. of International Development Engineering Tokyo Institute of Technology 2-12-1-I4-12, O-okayama, Meguro-ku, Tokyo, 152-8550, Japan email: rubeldas2...@gmail.com rubel...@tp.ide.titech.ac.jp [[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] Réponse automatique
Bonjour, Je serais en congés jusqu'au Jeudi 6 Décembre. Pour des raisons d'urgence, vous pourrez me contacter par téléphone au 06 46 34 81 03. Cordialement, -- Jérôme Boutet Conservatoire d'espaces naturels de Picardie 1, place Ginkgo - village Oasis 80 044 AMIENS cedex tél : 03 22 89 84 24 From: r-help-requ...@r-project.org Subject: R-help Digest, Vol 118, Issue 5 Date: Wed, 05 Dec 2012 12:00:08 +0100 __ 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] Trim
Hello, I have a dataframe 1 2006-11 NaN 2 2006-12 NaN 3 2006-10 0.1577647 4 2006-11 NaN 5 2006-12 NaN 6 2007-01 NaN 7 2007-02 NaN 8 2007-03 0.2956429 9 2007-01 NaN 10 2007-02 NaN I need to trim first and last NaN rows Result - 1 2006-10 0.1577647 2 2006-11 NaN 3 2006-12 NaN 4 2007-01 NaN 5 2007-02 NaN 6 2007-03 0.2956429 Thanks. __ 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] how to assign factor level into each value
HI, All I met the following problem. I dont know how to handle it. Country Price 1 CN 44.25 2 CN 21.07 3 CN 92.70 4 CN 47.41 5 CN111.67 6 CN 50.57 I want to create the 3rd colume with different factor levels: [1] 0-3051-75 31-50 76-100 101-150 151-200 201-300 500+ [9] 301-400 401-500 then the final result which I want is: Country Pricelevels 1 CN 44.25 31-50 2 CN 21.07 0-30 3 CN 92.70 76-100 4 CN 47.41 31-50 5 CN111.67101-150 6 CN 50.57 51-75 How can I do this? Thanks. Tammy [[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 to assign factor level into each value
Hi Tammy, Check ?cut and its examples. HTH, Jorge.- On Wed, Dec 5, 2012 at 11:26 PM, Tammy Ma wrote: HI, All I met the following problem. I dont know how to handle it. Country Price 1 CN 44.25 2 CN 21.07 3 CN 92.70 4 CN 47.41 5 CN111.67 6 CN 50.57 I want to create the 3rd colume with different factor levels: [1] 0-3051-75 31-50 76-100 101-150 151-200 201-300 500+ [9] 301-400 401-500 then the final result which I want is: Country Pricelevels 1 CN 44.25 31-50 2 CN 21.07 0-30 3 CN 92.70 76-100 4 CN 47.41 31-50 5 CN111.67101-150 6 CN 50.57 51-75 How can I do this? Thanks. Tammy [[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.
[R] alternative to leaps command
Dear UseRs, I wanted to know that i have been using leaps for the proper models selection for my work. I read so many articles from internet which categorically outlined that leaps command for model selection should never be used as its not efficient. Moreover, as a matter of fact, i personally noticed that the accuracy of leaps package is very much questionable. Is there an alternative package, which is more efficient your help will be deeply acknowledged... warm regards eliza [[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] Trim
Hello, Try the following. dat - structure(list(V1 = structure(c(2L, 3L, 1L, 2L, 3L, 4L, 5L, 6L, 4L, 5L), .Label = c(2006-10, 2006-11, 2006-12, 2007-01, 2007-02, 2007-03), class = factor), V2 = c(NaN, NaN, 0.1577647, NaN, NaN, NaN, NaN, 0.2956429, NaN, NaN)), .Names = c(V1, V2 ), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) idx - cumsum(!is.nan(dat$V2)) * rev(cumsum(rev(!is.nan(dat$V2 != 0 dat[idx, ] Hope this helps, Rui Barradas Em 05-12-2012 10:46, Vasilchenko Aleksander escreveu: Hello, I have a dataframe 1 2006-11 NaN 2 2006-12 NaN 3 2006-10 0.1577647 4 2006-11 NaN 5 2006-12 NaN 6 2007-01 NaN 7 2007-02 NaN 8 2007-03 0.2956429 9 2007-01 NaN 10 2007-02 NaN I need to trim first and last NaN rows Result - 1 2006-10 0.1577647 2 2006-11 NaN 3 2006-12 NaN 4 2007-01 NaN 5 2007-02 NaN 6 2007-03 0.2956429 Thanks. __ 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] What is print print print ?
Hi all. What is print print print? I don't see output of the print command in for loop and have found this link: http://stackoverflow.com/questions/1816200/chisq-test-doesnt-print-results-when-in-a-loop It describes a problem, similar to mine. My problem. I want to execute print command in for loop. If I copy for loop body with print() and paste it to console, I don't see any output. If I type the command, I do see the output. If I paste the command by parts I also see the output. If I construct the command by picking parts of the history with the up arrow, I also don't see any output. Search for print print print still didn't bring anything useful. -- Best regards, Vladimir mailto:wl2...@gmail.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] catching errors in RNetCDF
Dear R community, I quite frequently run into errors while using the RNetCDF package which do not seem to be recognised as normal R errors and, hence, do not stop the execution of the code making it hard to debug the code. Consider, for example: library(RNetCDF) con - create.nc('test.nc') test - try(var.get.nc(con, 'dummy')) In this case, some sort of error message is printed to the screen, but R does not recognise this as an error. Is there any way to solve this? I contacted the author of the package but it seems that there will be no solution from that side. Any Ideas? Cheers Jannis __ 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] Trim
Hi, May be this helps: dat1-read.table(text= 1 2006-11 NaN 2 2006-12 NaN 3 2006-10 0.1577647 4 2006-11 NaN 5 2006-12 NaN 6 2007-01 NaN 7 2007-02 NaN 8 2007-03 0.2956429 9 2007-01 NaN 10 2007-02 NaN ,sep=,header=FALSE,stringsAsFactors=FALSE) res-dat1[seq(which(!is.na(dat1$V3))[1],which(!is.na(dat1$V3))[2],by=1),] res # V1 V2 V3 #3 3 2006-10 0.1577647 #4 4 2006-11 NaN #5 5 2006-12 NaN #6 6 2007-01 NaN #7 7 2007-02 NaN #8 8 2007-03 0.2956429 A.K. - Original Message - From: Vasilchenko Aleksander vasilchenko@gmail.com To: r-help@r-project.org Cc: Sent: Wednesday, December 5, 2012 5:46 AM Subject: [R] Trim Hello, I have a dataframe 1 2006-11 NaN 2 2006-12 NaN 3 2006-10 0.1577647 4 2006-11 NaN 5 2006-12 NaN 6 2007-01 NaN 7 2007-02 NaN 8 2007-03 0.2956429 9 2007-01 NaN 10 2007-02 NaN I need to trim first and last NaN rows Result - 1 2006-10 0.1577647 2 2006-11 NaN 3 2006-12 NaN 4 2007-01 NaN 5 2007-02 NaN 6 2007-03 0.2956429 Thanks. __ 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] Makehelpneeded:No rule to make target `w'. Stop
Hello, I am Trying to Build a project, Makefile written so that outer make file calls the inner Makefiles to Build, I am invoking the Makefile as gmake depend at the perent directory of project (Makefile here digs in and executes inner Makefiles to build the project) .DEFAULT: @for subdir in `ls */Makefile`; \ do \ echo + Making $@ in `dirname $$subdir` ...; \ (cd `dirname $$subdir`; $(MAKE) $@); \ done the automatic variable $@ is set to depend, till some inner directories make process is going well and good ,after some point after I could see the error Message as *** No rule to make target `w'. Stop., with google help I found reasons like 1.infinite recursion 2.The value of $@ is set to w, as target now is w that won't be found in the Makefile so causing such an error. Ø I have gmake output I could see make entering in to directories only once and leaving from directories only once, so error is not because of recursion. Ø I could see @ := wp when I issued gmake -p depend. Could you suggest me the approach to solve this issue Regards, Revathi R DISCLAIMER\ ==\ This e-mail ...{{dropped:13}} __ 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] Trim
Hi, I guess with only one rev() should also work: idx-cumsum(!is.na(dat$V2))*rev(cumsum(!is.na(dat$V2)))!=0 dat[idx,] # V1 V2 #3 2006-10 0.1577647 #4 2006-11 NaN #5 2006-12 NaN #6 2007-01 NaN #7 2007-02 NaN #8 2007-03 0.2956429 A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: Vasilchenko Aleksander vasilchenko@gmail.com Cc: r-help@r-project.org Sent: Wednesday, December 5, 2012 7:59 AM Subject: Re: [R] Trim Hello, Try the following. dat - structure(list(V1 = structure(c(2L, 3L, 1L, 2L, 3L, 4L, 5L, 6L, 4L, 5L), .Label = c(2006-10, 2006-11, 2006-12, 2007-01, 2007-02, 2007-03), class = factor), V2 = c(NaN, NaN, 0.1577647, NaN, NaN, NaN, NaN, 0.2956429, NaN, NaN)), .Names = c(V1, V2 ), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) idx - cumsum(!is.nan(dat$V2)) * rev(cumsum(rev(!is.nan(dat$V2 != 0 dat[idx, ] Hope this helps, Rui Barradas Em 05-12-2012 10:46, Vasilchenko Aleksander escreveu: Hello, I have a dataframe 1 2006-11 NaN 2 2006-12 NaN 3 2006-10 0.1577647 4 2006-11 NaN 5 2006-12 NaN 6 2007-01 NaN 7 2007-02 NaN 8 2007-03 0.2956429 9 2007-01 NaN 10 2007-02 NaN I need to trim first and last NaN rows Result - 1 2006-10 0.1577647 2 2006-11 NaN 3 2006-12 NaN 4 2007-01 NaN 5 2007-02 NaN 6 2007-03 0.2956429 Thanks. __ 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-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] Trim
On 05-12-2012, at 11:46, Vasilchenko Aleksander wrote: Hello, I have a dataframe 1 2006-11 NaN 2 2006-12 NaN 3 2006-10 0.1577647 4 2006-11 NaN 5 2006-12 NaN 6 2007-01 NaN 7 2007-02 NaN 8 2007-03 0.2956429 9 2007-01 NaN 10 2007-02 NaN I need to trim first and last NaN rows Result - 1 2006-10 0.1577647 2 2006-11 NaN 3 2006-12 NaN 4 2007-01 NaN 5 2007-02 NaN 6 2007-03 0.2956429 dat - + structure(list(V1 = structure(c(2L, 3L, 1L, 2L, 3L, 4L, 5L, 6L, + 4L, 5L), .Label = c(2006-10, 2006-11, 2006-12, 2007-01, + 2007-02, 2007-03), class = factor), V2 = c(NaN, NaN, 0.1577647, + NaN, NaN, NaN, NaN, 0.2956429, NaN, NaN)), .Names = c(V1, V2 + ), class = data.frame, row.names = c(1, 2, 3, 4, 5, + 6, 7, 8, 9, 10)) library(zoo) na.trim(dat) Berend __ 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] [R-pkgs] glm2 version 1.1
glm2 (1.1) is now available on CRAN. glm2 fits generalized linear models using the same model specification as glm, but with a modified fitting method that is more stable for models that may fail to converge using glm (see: R Journal 3/2, 2011, pp.12-15). The previous version of glm2 had to be archived because it called a Fortran routine no longer available in R = 2.15.1. This has been addressed in the current version of glm2. --- Ian Marschner Professor, Dept. of Statistics Macquarie University, Sydney, Australia ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] [R-pkgs] AQ-R 0.2 // realtime messaging.
Hi there, I am glad to announce AQ-R 0.2 has been successfully built and is available via install.packages(aqr, repos=http://R-Forge.R-project.org;). The most important new feature is real-time messaging from within R. AQ-R 0.2 enables you to send and receive byte[] messages within R through a STOMP compliant messaging server, such as the ActiveQuant Master Server. There are various STOMP protocol compliant servers [1]. You can build arbitrarily complex messaging infrastructures, where messages flow between R instances or other-language messaging components. The key functions are: aqSubscribe(aChannel) - subscribe to messages in a channel aqWaitForData() - a blocking call that waits for data to arrive aqPoll() - fetches all messages from the internal buffer (not the STOMP server) aqSend(channel, text) - send a message to a channel This extension does buffer incoming data between consecutive aqPoll() calls. The core loop for using this should look like: while(aqWaitForData()){ data = aqPoll() } Version 0.2 is beta. I have thoroughly tested it on Windows and on Linux. I am looking for more testers and feedback. Demo video at [2]. buzzI hope it opens up an easy venue to build distributed calculators without the hassle of going through MPI or anything similar, in a truely cross-platform approach, making R a viable citizen in highly heterogenous message processing environments. /buzz Cheers, Ulrich References: [1] http://stomp.github.com/implementations.html#STOMP_1_0_Servers [2] http://www.youtube.com/watch?v=h1gLgJOEWW0 -- Ulrich Staudinger, ActiveQuant GmbH P: +41 79 702 05 95 E:ustaudin...@activequant.com http://www.activequant.com Connect online:https://www.xing.com/profile/Ulrich_Staudinger [[alternative HTML version deleted]] ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] alternative to leaps command
One correction, one comment, one suggestion: On Wed, Dec 5, 2012 at 4:44 AM, eliza botto eliza_bo...@hotmail.com wrote: Dear UseRs, I wanted to know that i have been using leaps for the proper models selection for my work. I read so many articles from internet which categorically outlined that leaps command for model selection should never be used as its not efficient. No. That is not the problem. The problem is that it efficiently produces nonsense, as your next line indicates. Moreover, as a matter of fact, i personally noticed that the accuracy of leaps package is very much questionable. Is there an alternative package, which is more efficient You are asking about model selection/building, which is a central theme in statistics. There is no simple answer to your question. Moreover, this is not the place for such discussions. I strongly recommend that you consult a local statistician, as you are clearly out of your depth. Failing that, post to a statistics list like stats.stackexchange.com . -- Bert your help will be deeply acknowledged... warm regards eliza [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[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] MBA with FP Growth
Somebody knows about a MBA (Market Basket Analysis) implementation using FP-Growth and Arules in R?. I'm no programmer, instead I am a user of this application and given the computational cost of the APRIORI algorithm, this does not work well with big Datasets like what you find in the real world. TIA, -- LIBARDO LÓPEZ GUZMÁN QR vCARDhttp://chart.apis.google.com/chart?cht=qrchs=350x350chld=Mchoe=UTF-8chl=BEGIN%3AVCARD%0AN%3ALIBARDO+LOPEZ+GUZMAN%0ATEL%3A3176397899%0AEMAIL%3Alilopezg%40gmail.com%0AADR%3ABOGOTA+COLOMBIA%0ANOTE%3ABI%2C+DM%2C+Marketing+Especialist%0AEND%3AVCARD [[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] Help for a function
Hello, Also, t1 and min(xt) do not vary inside the loop so if it enters the loop it never exits. And res1[j] -(a*h) res2 -sum( res1[j]) is equivalent to res2 - a*h so the inner-most loop is not needed at all. Hope this helps, Rui Barradas Em 05-12-2012 04:20, Jim Lemon escreveu: On 12/05/2012 01:01 AM, anoumou wrote: Hello all, I need a help. I am modeling a disease and a create a R function like that: ... But i do not get the results,i try by all means but i d'ont understant the problem. Hi anoumou, Your function provides almost no indication of what two of its five arguments are supposed to be. If, with a certain degree of optimistic inference, we suppose x to be a data frame organized as shown below the function. t, i and CONTAGIEUX must be the appropriately named columns of the data frame. This leaves two columns, Symptomes and Incubation. Say we flip a coin to decide which of these to assign to r, and with all of our degrees of freedom gone, we assume that the other is h. We are forced to the conclusion that a is a nuisance argument, added to throw us off the scent. Peering within the function, we notice that the date format is wrong, braces are unmatched and that our data frame is alphabetically ordered by name of country to no purpose whatsoever. The best I can do here is to make the function potentially able to do something if you can work out what to do with it. Lambda-function (x,date1,r,h,a) { ndate1 - as.Date(date1, %Y-%m-%d) t1 - as.numeric(ndate1) x[order(x$i),] xt -x[,t] xi -x[,i] CONTAGIEUX -x[,CONTAGIEUX] while ( t1 min(xt) ){ for (i in 1:length(xi) ){ for (j in 1:CONTAGIEUX[length(CONTAGIEUX)]){ res1[j] -(a*h) res2 -sum( res1[j]) } } lambda[i] - r*res2 } x-data.frame(x,lambda) x } Jim __ 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.
Re: [R] Help for a function
Thanks you all Maurice TEKO Biostatisticien,Doctorant. Université de Liège Département des Sciences et Gestion de l'environnement 185 avenue de Longwy 6700 Arlon (Belgique) Mail :teko_maur...@yahoo.fr :anoumou.tekoahate...@ulg.ac.be http://www.ulg.ac.be De : Rui Barradas ruipbarra...@sapo.pt À : Jim Lemon j...@bitwrit.com.au Envoyé le : Mercredi 5 décembre 2012 16h26 Objet : Re: [R] Help for a function Hello, Also, t1 and min(xt) do not vary inside the loop so if it enters the loop it never exits. And res1[j] -(a*h) res2 -sum( res1[j]) is equivalent to res2 - a*h so the inner-most loop is not needed at all. Hope this helps, Rui Barradas Em 05-12-2012 04:20, Jim Lemon escreveu: On 12/05/2012 01:01 AM, anoumou wrote: Hello all, I need a help. I am modeling a disease and a create a R function like that: ... But i do not get the results,i try by all means but i d'ont understant the problem. Hi anoumou, Your function provides almost no indication of what two of its five arguments are supposed to be. If, with a certain degree of optimistic inference, we suppose x to be a data frame organized as shown below the function. t, i and CONTAGIEUX must be the appropriately named columns of the data frame. This leaves two columns, Symptomes and Incubation. Say we flip a coin to decide which of these to assign to r, and with all of our degrees of freedom gone, we assume that the other is h. We are forced to the conclusion that a is a nuisance argument, added to throw us off the scent. Peering within the function, we notice that the date format is wrong, braces are unmatched and that our data frame is alphabetically ordered by name of country to no purpose whatsoever. The best I can do here is to make the function potentially able to do something if you can work out what to do with it. Lambda-function (x,date1,r,h,a) { ndate1 - as.Date(date1, %Y-%m-%d) t1 - as.numeric(ndate1) x[order(x$i),] xt -x[,t] xi -x[,i] CONTAGIEUX -x[,CONTAGIEUX] while ( t1 min(xt) ){ for (i in 1:length(xi) ){ for (j in 1:CONTAGIEUX[length(CONTAGIEUX)]){ res1[j] -(a*h) res2 -sum( res1[j]) } } lambda[i] - r*res2 } x-data.frame(x,lambda) x } Jim __ 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] Help for a function
Rui , I discover all this when running and rerunning my function one and thousand times and per line. Now it's perfect, and work so well. Thanks. À : Rui Barradas ruipbarra...@sapo.pt; Jim Lemon j...@bitwrit.com.au Cc : r-help@r-project.org r-help@r-project.org Envoyé le : Mercredi 5 décembre 2012 16h45 Objet : Re: [R] Help for a function Thanks you all Maurice TEKO Biostatisticien,Doctorant. Université de Liège Département des Sciences et Gestion de l'environnement 185 avenue de Longwy 6700 Arlon (Belgique) :anoumou.tekoahate...@ulg.ac.be http://www.ulg.ac.be De : Rui Barradas ruipbarra...@sapo.pt À : Jim Lemon j...@bitwrit.com.au Envoyé le : Mercredi 5 décembre 2012 16h26 Objet : Re: [R] Help for a function Hello, Also, t1 and min(xt) do not vary inside the loop so if it enters the loop it never exits. And res1[j] -(a*h) res2 -sum( res1[j]) is equivalent to res2 - a*h so the inner-most loop is not needed at all. Hope this helps, Rui Barradas Em 05-12-2012 04:20, Jim Lemon escreveu: On 12/05/2012 01:01 AM, anoumou wrote: Hello all, I need a help. I am modeling a disease and a create a R function like that: ... But i do not get the results,i try by all means but i d'ont understant the problem. Hi anoumou, Your function provides almost no indication of what two of its five arguments are supposed to be. If, with a certain degree of optimistic inference, we suppose x to be a data frame organized as shown below the function. t, i and CONTAGIEUX must be the appropriately named columns of the data frame. This leaves two columns, Symptomes and Incubation. Say we flip a coin to decide which of these to assign to r, and with all of our degrees of freedom gone, we assume that the other is h. We are forced to the conclusion that a is a nuisance argument, added to throw us off the scent. Peering within the function, we notice that the date format is wrong, braces are unmatched and that our data frame is alphabetically ordered by name of country to no purpose whatsoever. The best I can do here is to make the function potentially able to do something if you can work out what to do with it. Lambda-function (x,date1,r,h,a) { ndate1 - as.Date(date1, %Y-%m-%d) t1 - as.numeric(ndate1) x[order(x$i),] xt -x[,t] xi -x[,i] CONTAGIEUX -x[,CONTAGIEUX] while ( t1 min(xt) ){ for (i in 1:length(xi) ){ for (j in 1:CONTAGIEUX[length(CONTAGIEUX)]){ res1[j] -(a*h) res2 -sum( res1[j]) } } lambda[i] - r*res2 } x-data.frame(x,lambda) x } Jim __ 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.
[R] Reminder: useR! 2013 call for tutorials
Dear all, This is a reminder that the deadline for submitting a tutorial proposal for the useR! 2013 conference is December 15, 2012. See details below. Best wishes, Virgilio --- We are pleased to announce that the R user conference useR! 2013 is scheduled for July 10-12, 2013, and will take place at the University of Castilla-La Mancha, Albacete, Spain. As for the predecessor conferences, the program will consist of two parts: invited lectures and user-contributed sessions (abstract submission will be available soon). Prior to the conference, there will be tutorials on R (proposals for tutorials should be sent before December 15, 2012, see below). CONFIRMED INVITED SPEAKERS María Jesús Bayarri, José Manuel Benítez-Sánchez, Havard Rue, Steve Scott and Hadley Wickham USER-CONTRIBUTED SESSIONS The conference will feature both talks and posters illustrating the use of R in practice. Contributions are welcome that introduce recent developments in the R Project (including CRAN packages), demonstrate applications of R in areas of current interest, or otherwise engage and inspire participants in their use of R. PRE-CONFERENCE TUTORIALS Before the official program, half-day tutorials will be offered on Tuesday, July 9. We invite R users to submit proposals for three hour tutorials on special topics regarding R. The proposals should give a brief description of the tutorial, including goals, detailed outline, justification of why the tutorial is important, background knowledge required and potential attendees. The proposals should be sent before December 15, 2012 to useR-2013_at_R-project.org. A web page offering more information on the `useR!' conference is available at http://www.R-project.org/useR-2013 We hope to see you in Albacete! The organizing committee: Esteban Alfaro, José Luis Alfaro, M. Teresa Alonso, Emilio L. Cano, Gonzalo García-Donato, Matías Gámez, Noelia García, Virgilio Gómez-Rubio, María José Haro, Eva J. Moreno and Francisco Parreño. __ 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] Incidence Matrix of Experimental Design Using R language Program
Hi I am working on educational assignment to produce an *Incidence matrix *from a *BIB design *using R language software. I found a web page *http://wiki.math.yorku.ca/index.php/R:_Incidence_matrix * about the problem. But it produces Data matrix instead of Incidence matrix. can you please help me out using R software. thanks and regards zaheer *following are the sample codes of my assignment with resultant Incidence Matrix as mentioned in above link, but this is, according to my knowledge, Data matrix of any experimental design. * b=4 #Number of Blocks t=4 #Number of Column z=c(1,2,3)#Shift m=NULL y=c(0) w=c(y,cumsum(z) %%t) print(The Initial Block is=) print(w) p=seq(from=0, to=t-1, by=1) l=NULL for(i in 1:b) { for(j in 1:t) { l=c(l,rep((w[i]+p[j]+t)%% t)) } } x= matrix(c(l),nrow=b,ncol=t,byrow = TRUE) print(The Design Layout is ) print.matrix - function(x){ write.table(format(x, justify=right), row.names=F,col.names=F,quote=F }) print(x) *BIB design Output* [,1] [,2] [,3] [,4] [1,]0123 [2,]1230 [3,]3012 [4,]2301 vec - c(as.matrix(x)) # converting matrix into Vector for incidence correct matrix a=t(x)%*%x print.matrix - function(a){ write.table(format(a, justify=right), row.names=F, col.names=F, quote=F) } print(XX ) print(a) A=contrasts( as.factor(x), contrasts =FALSE)[ as.factor(x),] print.matrix - function(A){ write.table(format(A, justify=right), row.names=F, col.names=F, quote=F) } print(The Incidence Matrix is=) print(A) *OUTPUT* 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 1 0 0 *I need this * * 1 1 1 1* * 1 1 1 1* * 1 1 1 1* * 1 1 1 1* [[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] How can I unsubscrie to this R forum¿?
Hi, even though the help and the community was a greta plus and a very welcome experience, I wanted to know I can I exit it? thanks for you support. BR [[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] Using multcomp::glht() with Anova object
Hello everyone, I've conducted a Type III repeated-measures ANOVA using Anova() from the car package, based on the suggestions at http://blog.gribblelab.org/2009/03/09/repeated-measures-anova-using-r/(option 3) and http://languagescience.umd.edu/wiki/EEG#ERP_ANOVA_in_R. My ANOVA has two factors: Condition (3 levels) and Region (6 levels) and their interaction. Below is code to run the Anova and get the model object (the data are at https://docs.google.com/open?id=0B6-m45Jvl3ZmOVFTYVpZYV9sUUk). data - as.matrix( read.table( file=EEGpriming.txt, header=T, sep=\t) ) Condition - c( rep(Cond1, 6), rep(Cond2, 6), rep(Cond3, 6) ) Region - factor( rep( c(la, ma, ra, lp, mp, rp), 3 ) ) library(car) model.Anova - Anova( lm(eeg ~ 1), idata=data.frame(Condition, Region), idesign=~Condition*Region ) ) I'm now trying to do post-hoc comparisons between all levels of Condition using glht() from the multcomp package. I do this using the way that has worked for me with lmer() objects in the past: set up a contrast matrix and then feed it to glht(): designmatrix - matrix(0, nrow=3, ncol=18) rownames(designmatrix) - c(Cond1_minus_Cond2, Cond3_minus_Cond1, Cond3_minus_Cond2) designmatrix[1, 1:6] - 1 designmatrix[1, 7:12] - -1 designmatrix[2, 1:6] - -1 designmatrix[2, 13:18] - 1 designmatrix[3, 13:18] - 1 designmatrix[3, 7:12] - -1 library(multcomp) glht( model.Anova, linfct=designmatrix ) However, when I give glht() an Anova object, I get the following error: glht( model.anova, linfct=designmatrix ) Error in UseMethod(vcov) : no applicable method for 'vcov' applied to an object of class Anova.mlm Error in modelparm.default(model, ...) : no âvcovâ method for âmodelâ found! Does anyone know how if it's possible to use glht with an Anova object? (I guess I can get these same comparisons by re-doing the anova using aov() or lme(), since I don't need the Huynh-Feldt corrections in the post-hoc tests...but I am just curious if i can do the post-hocs directly on my Anova object.) Best, Steve Politzer-Ahles -- Stephen Politzer-Ahles University of Kansas Linguistics Department http://people.ku.edu/~sjpa/ [[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 unsubscrie to this R forum¿?
Follow the link in the footer of any message from the list to the web page that lets you modify your list subscription. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Sébastien Morant sebmor...@gmail.com wrote: Hi, even though the help and the community was a greta plus and a very welcome experience, I wanted to know I can I exit it? thanks for you support. BR [[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-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] reformatting some data
On Dec 4, 2012, at 1:44 PM, arun wrote: Hi, You can also do this: dat1-structure(list(group = c(4L, 3L, 4L, 4L, 4L, 2L), X3.Hydroxybutyrate = c(4e-04, 5e-04, 4e-04, 6e-04, 5e-04, 7e-04), X3.Hydroxyisovalerate = c(3e-04, 3e-04, 3e-04, 3e-04, 3e-04, 4e-04), ADP = c(5e-04, 6e-04, 6e-04, 5e-04, 7e-04, 7e-04)), .Names = c(group, X3.Hydroxybutyrate, X3.Hydroxyisovalerate, ADP), row.names = c(347L, 353L, 359L, 365L, 371L, 377L), class = data.frame) datM-melt(dat1,id.var=group) An explicit call to library(reshape2) might be in order before a melt call. xtabs(value~variable+group,data=datM) # group #variable 2 3 4 # X3.Hydroxybutyrate0.0007 0.0005 0.0019 # X3.Hydroxyisovalerate 0.0004 0.0003 0.0012 # ADP 0.0007 0.0006 0.0023 This has implicitly summed the entires from items by group values. That might or might not have been what the OP wanted. xtabs does not allow a function to be specified. (It's output is expected to be a contingency table of counts so it only makes sense to sum values.) The aggregate function allows either choice within the base package: I see that arun used `mean` as his function in an earlier post using reshape2::dcast aggregate(dat1[-1] , dat1['group'], FUN=mean) group X3.Hydroxybutyrate X3.Hydroxyisovalerate ADP 1 2 0.000700 4e-04 0.000700 2 3 0.000500 3e-04 0.000600 3 4 0.000475 3e-04 0.000575 This is the aggregate method for summation: aggregate(dat1[-1] , dat1['group'], FUN=sum) group X3.Hydroxybutyrate X3.HydroxyisovalerateADP 1 2 0.00070.0004 0.0007 2 3 0.00050.0003 0.0006 3 4 0.00190.0012 0.0023 A.K. - Original Message - From: Charles Determan Jr deter...@umn.edu To: r-help@r-project.org Cc: Sent: Tuesday, December 4, 2012 4:17 PM Subject: [R] reformatting some data Hello, I am trying to reformat some data so that it is organized by group in the columns. The data currently looks like this: group X3.Hydroxybutyrate X3.Hydroxyisovalerate ADP 347 4 4e-04 3e-04 5e-04 353 3 5e-04 3e-04 6e-04 359 4 4e-04 3e-04 6e-04 365 4 6e-04 3e-04 5e-04 371 4 5e-04 3e-04 7e-04 377 2 7e-04 4e-04 7e-04 I would like to reformat it so it is like this: 2 3 4 var1 var2 var3 I realize that there unequal numbers in each group but I would like to none-the-less if possible. Here is a subset of the data: structure(list(group = c(4L, 3L, 4L, 4L, 4L, 2L), X3.Hydroxybutyrate = c(4e-04, 5e-04, 4e-04, 6e-04, 5e-04, 7e-04), X3.Hydroxyisovalerate = c(3e-04, 3e-04, 3e-04, 3e-04, 3e-04, 4e-04), ADP = c(5e-04, 6e-04, 6e-04, 5e-04, 7e-04, 7e-04)), .Names = c(group, X3.Hydroxybutyrate, X3.Hydroxyisovalerate, ADP), row.names = c(347L, 353L, 359L, 365L, 371L, 377L), class = data.frame) David Winsemius, MD Alameda, CA, USA __ 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] Using multcomp::glht() with Anova object
Dear Steve, Usually the best place to look for information about functions in the car package, along with the help files for the package, is the book with which the package is associated. In this case, there's an on-line appendix to the book on multivariate linear models which describes how to use the linearHypothesis() function in the car package with repeated measures: sec. 3.2 of http://socserv.socsci.mcmaster.ca/jfox/Books/Companion/appendix/Appendix-Multivariate-Linear-Models.pdf. I think that this should help you do what you want. I hope this helps, John John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ On Wed, 5 Dec 2012 11:09:44 -0600 Stephen Politzer-Ahles politzerahl...@gmail.com wrote: Hello everyone, I've conducted a Type III repeated-measures ANOVA using Anova() from the car package, based on the suggestions at http://blog.gribblelab.org/2009/03/09/repeated-measures-anova-using-r/(option 3) and http://languagescience.umd.edu/wiki/EEG#ERP_ANOVA_in_R. My ANOVA has two factors: Condition (3 levels) and Region (6 levels) and their interaction. Below is code to run the Anova and get the model object (the data are at https://docs.google.com/open?id=0B6-m45Jvl3ZmOVFTYVpZYV9sUUk). data - as.matrix( read.table( file=EEGpriming.txt, header=T, sep=\t) ) Condition - c( rep(Cond1, 6), rep(Cond2, 6), rep(Cond3, 6) ) Region - factor( rep( c(la, ma, ra, lp, mp, rp), 3 ) ) library(car) model.Anova - Anova( lm(eeg ~ 1), idata=data.frame(Condition, Region), idesign=~Condition*Region ) ) I'm now trying to do post-hoc comparisons between all levels of Condition using glht() from the multcomp package. I do this using the way that has worked for me with lmer() objects in the past: set up a contrast matrix and then feed it to glht(): designmatrix - matrix(0, nrow=3, ncol=18) rownames(designmatrix) - c(Cond1_minus_Cond2, Cond3_minus_Cond1, Cond3_minus_Cond2) designmatrix[1, 1:6] - 1 designmatrix[1, 7:12] - -1 designmatrix[2, 1:6] - -1 designmatrix[2, 13:18] - 1 designmatrix[3, 13:18] - 1 designmatrix[3, 7:12] - -1 library(multcomp) glht( model.Anova, linfct=designmatrix ) However, when I give glht() an Anova object, I get the following error: glht( model.anova, linfct=designmatrix ) Error in UseMethod(vcov) : no applicable method for 'vcov' applied to an object of class Anova.mlm Error in modelparm.default(model, ...) : no âvcovâ method for âmodelâ found! Does anyone know how if it's possible to use glht with an Anova object? (I guess I can get these same comparisons by re-doing the anova using aov() or lme(), since I don't need the Huynh-Feldt corrections in the post-hoc tests...but I am just curious if i can do the post-hocs directly on my Anova object.) Best, Steve Politzer-Ahles -- Stephen Politzer-Ahles University of Kansas Linguistics Department http://people.ku.edu/~sjpa/ [[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] Using multcomp::glht() with Anova object
Thank you John, I'll take a look at that! Best, Steve On Wed, Dec 5, 2012 at 11:39 AM, John Fox j...@mcmaster.ca wrote: Dear Steve, Usually the best place to look for information about functions in the car package, along with the help files for the package, is the book with which the package is associated. In this case, there's an on-line appendix to the book on multivariate linear models which describes how to use the linearHypothesis() function in the car package with repeated measures: sec. 3.2 of http://socserv.socsci.mcmaster.ca/jfox/Books/Companion/appendix/Appendix-Multivariate-Linear-Models.pdf. I think that this should help you do what you want. I hope this helps, John John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ 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] Import multiple data frames and combine them using cbind
On Dec 4, 2012, at 8:56 PM, Gyanendra Pokharel wrote: Thanks Dennis, Your code also produces same as Jim's but I am not looking that one, I need to use cbind so that finally I will get the data frame of size 200X320 (i,e, 200 X(16X20)). Thanks Here we are a day later and your question risks sinking beneath the waves because you have not realized that you are implicitly making impossible demands on your volunteer consultants. Please review your postings and responses and try to put yourself in the position of someone who doesn't have the capacity to read your mind or see your screen. -- David. On Tue, Dec 4, 2012 at 10:46 PM, Dennis Murphy djmu...@gmail.com wrote: In addition to Jim's reply, had you used the plyr package, you could have done this in one shot: library(plyr) DF - ldply(llply(temp, read.table), rbind) The inner llply call is equivalent to your lapply() and the outer ldply() is equivalent to Jim's do.call() code. Dennis On Tue, Dec 4, 2012 at 6:37 PM, Gyanendra Pokharel gyanendra.pokha...@gmail.com wrote: Hi group, I imported 16 data frames using the function list.files temp - list.files(path=...) myfiles = lapply(temp, read.table,sep = ) Now I have 16 data set imported in R window. I want to combine them by row and tried some thing like (Here I am considering only 20 columns) for(i in 1:16){ data- cbind(myfiles[[i]][,1:20]) } but it returns only first data set. I can combine them using data - cbind(myfiles[[1]][,1:20],myfiles[[2]] [1:20],...) But I want in a loop so that I can make the efficient code. Any kind of suggestion will be great for me. Thanks [[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. David Winsemius, MD Alameda, CA, USA __ 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] What is print print print ?
On Dec 5, 2012, at 5:03 AM, Vladimir eremeev wrote: Hi all. What is print print print? I don't see output of the print command in for loop and have found this link: http://stackoverflow.com/questions/1816200/chisq-test-doesnt-print-results-when-in-a-loop It describes a problem, similar to mine. My problem. I want to execute print command in for loop. If I copy for loop body with print() and paste it to console, I don't see any output. Code we, want code. If I type the command, I do see the output. If I paste the command by parts I also see the output. If I construct the command by picking parts of the history with the up arrow, I also don't see any output. Code? Search for print print print still didn't bring anything useful. The questioner on SO was executing print chisq.test print and he was advised (and apparently understood ) that he need to be executing print print print. Get it now? If you have a specific problem to be addressed then you should post the code, but I think using Rhelp to explain cryptic answers on SO might be expecting a bit much. -- David Winsemius, MD Alameda, CA, USA __ 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] data manipulation between vector and matrix
Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) I want, x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements of x against column elements in mat. But x-mat won't do it. Thanks, Mike [[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 unsubscrie to this R forum¿?
On Dec 5, 2012, at 8:33 AM, Sébastien Morant wrote: Hi, even though the help and the community was a greta plus and a very welcome experience, I wanted to know I can I exit it? thanks for you support. The same place you signed up ... and the link is at the bottom of every posting to Rhelp. BR [[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. David Winsemius, MD Alameda, CA, USA __ 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] Import multiple data frames and combine them using cbind
I am sorry David, I don't mean to give the answer of the impossible questions. Just you can say impossible. If there is no way to do what I explained, that's fine, we do have other alternatives what I wrote in the beginning. Thank you so much. On Wed, Dec 5, 2012 at 1:12 PM, David Winsemius dwinsem...@comcast.netwrote: beneath [[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] data manipulation between vector and matrix
The only solution I found was x-t(mu) Is there a better way? Mike On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) I want, x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements of x against column elements in mat. But x-mat won't do it. Thanks, Mike [[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] data manipulation between vector and matrix
Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) Thanks for the actual reproducible example. I want, x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements of x against column elements in mat. But x-mat won't do it. This will (note the modification to get x - mat): sweep(-mat, 2, x, +) [,1] [,2] [1,]0 -19 [2,] -1 -20 [3,] -2 -21 [4,] -3 -22 [5,] -4 -23 etc. -- Sarah Goslee http://www.functionaldiversity.org __ 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] Import multiple data frames and combine them using cbind
On Dec 5, 2012, at 10:36 AM, Gyanendra Pokharel wrote: I am sorry David, I don't mean to give the answer of the impossible questions. Just you can say impossible. If there is no way to do what I explained, that's fine, we do have other alternatives what I wrote in the beginning. I did not say it was impossible to do what you are thinking you want to do, only that it is impossible to read your mind. You need to to describe what you are thinking in greater detail. Thank you so much. On Wed, Dec 5, 2012 at 1:12 PM, David Winsemius dwinsem...@comcast.net wrote: beneath David Winsemius, MD Alameda, CA, USA [[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] data manipulation between vector and matrix
Thanks, Sarah. First time heard about sweep(), it worked just the way I wanted. Mike On Wed, Dec 5, 2012 at 1:42 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) Thanks for the actual reproducible example. I want, x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements of x against column elements in mat. But x-mat won't do it. This will (note the modification to get x - mat): sweep(-mat, 2, x, +) [,1] [,2] [1,]0 -19 [2,] -1 -20 [3,] -2 -21 [4,] -3 -22 [5,] -4 -23 etc. -- Sarah Goslee http://www.functionaldiversity.org [[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] Import multiple data frames and combine them using cbind
On 05-12-2012, at 03:37, Gyanendra Pokharel wrote: Hi group, I imported 16 data frames using the function list.files temp - list.files(path=...) myfiles = lapply(temp, read.table,sep = ) Now I have 16 data set imported in R window. I want to combine them by row and tried some thing like (Here I am considering only 20 columns) for(i in 1:16){ data- cbind(myfiles[[i]][,1:20]) } but it returns only first data set. I can combine them using data - cbind(myfiles[[1]][,1:20],myfiles[[2]][1:20],...) But I want in a loop so that I can make the efficient code. Slightly guessing what you want. Toy example set.seed(123) mydf - lapply(1:4,FUN=function(dname) data.frame(x=round(runif(10),2), y=round(runif(10),2),z=round(runif(10),2))) mydf do.call(cbind,lapply(mydf, function(df) df[,1:2])) Berend __ 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] Import multiple data frames and combine them using cbind
Thanks Berend, your Idea is great, that,s what I was looking. Thanks again On Wed, Dec 5, 2012 at 2:06 PM, Berend Hasselman b...@xs4all.nl wrote: do.call(cbind,lapply(mydf, function(df) df[,1:2])) [[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] fitting a gamma frailty model (coxph)
I looked at your data: table(x, cluster) 1 2 3 4 5 6 0 0 48 0 48 48 0 1 48 0 48 0 0 48 Your covariate x is perfectly predicted by the cluster variable. If you fit a fixed effects model: coxph(Surv(time, event) ~ factor(cluster) +x) then the x variable is declared redundant. When the variance of the random effect is sufficiently large, the same happens in the gamma model when the variance is sufficiently large. Your model approaches this limit, and the solution fails. As mentioned in the manual page, the coxme function is now preferred. Last, your particular error message is caused by an invalid value for sparse. I'll add a check to the program. You likely want sparse=10 to force non-sparse computation. Terry Therneau On 12/04/2012 05:00 AM, r-help-requ...@r-project.org wrote: Dear all, I have a data sethttp://yaap.it/paste/c11b9fdcfd68d02b#gIVtLrrme3MaiQd9hHy1zcTjRq7VsVQ8eAZ2fol1lUc=with 6 clusters, each containing 48 (possibly censored, in which case event = 0) survival times. The x column contains a binary explanatory variable. I try to describe that data with a gamma frailty model as follows: library(survival) mod- coxph(Surv(time, event) ~ x + frailty.gamma(cluster, eps=1e-10, method=em, sparse=0), outer.max=1000, iter.max=1, data=data) Here is the error message: Error in if (history[2, 3] (history[1, 3] + 1)) theta- mean(history[1:2, : missing value where TRUE/FALSE needed Does anyone have an idea on how to debug? Yours sincerely, Marco __ 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] loading using Ryacas
I'm having trouble loading Ryacas. I've downloaded and extracted Ryacas 0.2-9 (also tried Ryacas ) and yacas 1.0.63, have the latest version of R and have tried the following (this works for installing other packages): install.packages(Ryacas) library(Ryacas) install.packages(yacas) library(yacas) and get this: Warning message: package yacas is not available (for R version 2.15.2) Got the same thing for R version 2.15.1. Suggestions? I'm fairly new to R and could use some detailed instructions. Working on Mac OSx 10.8.2 Thanks! -- Alicia Ellis Postdoc Gund Institute for Ecological Economics University of Vermont 617 Main Street Burlington, VT 05405 (802) 656-1046 http://www.uvm.edu/~aellis5/ http://entomology.ucdavis.edu/faculty/scott/aellis/ [[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] Changing data frame column headings
I have a reshaped data frame with value column headings concatenated from two column headings in the melted data frame. I want to change all 56 headings in a single command, but 'names' allows me to change only one at a time. In Hadley's 2007 article on reshape in the Journal of Statistical Software he mentions a 'rename' function, but I cannot find that. Is there a way to change all data frame column headings in a single command? Rich __ 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] Changing data frame column headings
x - data.frame(a = 1:5, b = rnorm(5)) names(x) - LETTERS[2:1] print(x) seems to work. Can you be more explicit about your problem? Michael On Wed, Dec 5, 2012 at 6:51 PM, Rich Shepard rshep...@appl-ecosys.com wrote: I have a reshaped data frame with value column headings concatenated from two column headings in the melted data frame. I want to change all 56 headings in a single command, but 'names' allows me to change only one at a time. In Hadley's 2007 article on reshape in the Journal of Statistical Software he mentions a 'rename' function, but I cannot find that. Is there a way to change all data frame column headings in a single command? Rich __ 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] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring?
Hi I have used fa() to perform a factor analysis of a psychological battery which is thought to have 11 factors. I can identify which factors the loadings relate to easily enough because I can see which items are loading onto each of the columns in the $loading output. However, how can I identify which items or loadings are being used to create each of the columns in the $scores output? I have used generalised linear models which have shown that some of the scores are significant predictors of treatment outcome, but I can't work out which of the 11 factors they are scoring? when I export to csv the $loadings I get the following columns in this order: MR4, MR3, MR2, MR6, MR7, MR5, MR1, MR8, MR10, MR9, MR11 When I export to csv the $scores I get the following columns in this order: V1, V2, V3, V4, V5, V6, V7, V8, V9, V10,V11 Are the scores in the column V1 derived from the loadings in column MR1 ? Or are the scores in the first column of $scores (ie V1) derived from the loadings in the first column of $loadings (ie MR4)? Thank you very much for your guidance, and your patience with my confusion Best wishes Brent Brent Caldwell, MBChB, DPH, MPH. Research Fellow Department of Medicine University of Otago, Wellington New Zealand U brent.caldw...@otago.ac.nz b 04 918 6041 021 87 22 64 23a Mein Street, PO Box 7343, Newtown, WELLINGTON 6021, NEW ZEALAND brent.ower.caldwell Zonnic study __ 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] loading using Ryacas
On Dec 5, 2012, at 10:21 AM, Alicia Ellis wrote: I'm having trouble loading Ryacas. I've downloaded and extracted Ryacas 0.2-9 (also tried Ryacas ) and yacas 1.0.63, have the latest version of R and have tried the following (this works for installing other packages): install.packages(Ryacas) library(Ryacas) install.packages(yacas) Yacas is an external program and on the Mac (and Linux) needs to be installed outside of R. library(yacas) and get this: Warning message: package yacas is not available (for R version 2.15.2) Got the same thing for R version 2.15.1. Suggestions? I'm fairly new to R and could use some detailed instructions. Working on Mac OSx 10.8.2 Thanks! -- Alicia Ellis Postdoc Gund Institute for Ecological Economics University of Vermont 617 Main Street Burlington, VT 05405 (802) 656-1046 http://www.uvm.edu/~aellis5/ http://entomology.ucdavis.edu/faculty/scott/aellis/ [[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. David Winsemius, MD Alameda, CA, USA __ 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] Changing data frame column headings
Hi, I am not sure why ?rename() is not working. a - list(a = 1, b = 2, c = 3) rename(a, c(b = a, c = b, a=c)) A.K. - Original Message - From: Rich Shepard rshep...@appl-ecosys.com To: r-help@r-project.org Cc: Sent: Wednesday, December 5, 2012 1:51 PM Subject: [R] Changing data frame column headings I have a reshaped data frame with value column headings concatenated from two column headings in the melted data frame. I want to change all 56 headings in a single command, but 'names' allows me to change only one at a time. In Hadley's 2007 article on reshape in the Journal of Statistical Software he mentions a 'rename' function, but I cannot find that. Is there a way to change all data frame column headings in a single command? Rich __ 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] duplicated() with long vectors
Hello, duplicated() does not seem to work for a long vector. For example, if you download the data from https://docs.google.com/open?id=0B6-m45Jvl3ZmNmpaSlJWMXo5bmc (a vector with about 12,000 numbers) and then run the following code which does duplicated() over the whole vector but just shows the last 30 elements: data.frame( tail(verylong, 30), tail(duplicated(verylong), 30) ) you'll see that at the end of the very long vector everything is listed as a duplicate of the preceding element (even though it shouldn't be). On the other hand, if you run the following code which just takes out the last 30 elements of the vector and does duplicated on them: data.frame( tail(verylong, 30), duplicated(tail(verylong, 30)) ) you get the correct results (FALSE shows up wherever the value in the first column changes). Does anyone know why this happens, and if there's a fix? I notice the documentation for duplicated() says: Long vectors are supported for the default method of duplicated, but may only be usable if nmax is supplied. But I've tried running this with a high value of nmax given, and it still gives me the same problem. So far the only way I've figured out to get this duplicated()-like vector is to use a for loop going through one item at a time, but that takes about a minute to run. Best, Steve Politzer-Ahles -- Stephen Politzer-Ahles University of Kansas Linguistics Department http://people.ku.edu/~sjpa/ __ 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] duplicated() with long vectors
Hi, duplicated() doesn't just look at consecutive values, but anywhere in the object. Since your 12320-element vector has only 48 separate values, and all of them occur before the last 30 elements, so duplicated() returns TRUE. You might be looking for something involving rle(). What are you trying to accomplish? Sarah On Wed, Dec 5, 2012 at 3:53 PM, Stephen Politzer-Ahles politzerahl...@gmail.com wrote: Hello, duplicated() does not seem to work for a long vector. For example, if you download the data from https://docs.google.com/open?id=0B6-m45Jvl3ZmNmpaSlJWMXo5bmc (a vector with about 12,000 numbers) and then run the following code which does duplicated() over the whole vector but just shows the last 30 elements: data.frame( tail(verylong, 30), tail(duplicated(verylong), 30) ) you'll see that at the end of the very long vector everything is listed as a duplicate of the preceding element (even though it shouldn't be). On the other hand, if you run the following code which just takes out the last 30 elements of the vector and does duplicated on them: data.frame( tail(verylong, 30), duplicated(tail(verylong, 30)) ) you get the correct results (FALSE shows up wherever the value in the first column changes). Does anyone know why this happens, and if there's a fix? I notice the documentation for duplicated() says: Long vectors are supported for the default method of duplicated, but may only be usable if nmax is supplied. But I've tried running this with a high value of nmax given, and it still gives me the same problem. So far the only way I've figured out to get this duplicated()-like vector is to use a for loop going through one item at a time, but that takes about a minute to run. Best, Steve Politzer-Ahles -- Sarah Goslee http://www.functionaldiversity.org __ 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] data manipulation between vector and matrix
thanks, I knew about apply, but did not you you can put plus signs with quotes. That's a cool tricky, Mike On Wed, Dec 5, 2012 at 4:05 PM, arun smartpink...@yahoo.com wrote: HI, In addition to ?sweep(), you can use apply(-mat,1,`+`,x) #or library(plyr) aaply(-mat,1,+,x) A.K. - Original Message - From: C W tmrs...@gmail.com To: Sarah Goslee sarah.gos...@gmail.com Cc: r-help r-help@r-project.org Sent: Wednesday, December 5, 2012 1:51 PM Subject: Re: [R] data manipulation between vector and matrix Thanks, Sarah. First time heard about sweep(), it worked just the way I wanted. Mike On Wed, Dec 5, 2012 at 1:42 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) Thanks for the actual reproducible example. I want, x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements of x against column elements in mat. But x-mat won't do it. This will (note the modification to get x - mat): sweep(-mat, 2, x, +) [,1] [,2] [1,]0 -19 [2,] -1 -20 [3,] -2 -21 [4,] -3 -22 [5,] -4 -23 etc. -- Sarah Goslee http://www.functionaldiversity.org [[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 to assign factor level into each value
?cut x - read.table(text = Country Price + 1 CN 44.25 + 2 CN 21.07 + 3 CN 92.70 + 4 CN 47.41 + 5 CN111.67 + 6 CN 50.57, as.is = TRUE, header = TRUE) x$levels - cut(x$Price, breaks = c(0,30,50,75,100,150,200,300,400,500,Inf)) x Country Pricelevels 1 CN 44.25 (30,50] 2 CN 21.07(0,30] 3 CN 92.70 (75,100] 4 CN 47.41 (30,50] 5 CN 111.67 (100,150] 6 CN 50.57 (50,75] On Wed, Dec 5, 2012 at 7:26 AM, Tammy Ma metal_lical...@live.com wrote: HI, All I met the following problem. I dont know how to handle it. Country Price 1 CN 44.25 2 CN 21.07 3 CN 92.70 4 CN 47.41 5 CN111.67 6 CN 50.57 I want to create the 3rd colume with different factor levels: [1] 0-3051-75 31-50 76-100 101-150 151-200 201-300 500+ [9] 301-400 401-500 then the final result which I want is: Country Pricelevels 1 CN 44.25 31-50 2 CN 21.07 0-30 3 CN 92.70 76-100 4 CN 47.41 31-50 5 CN111.67101-150 6 CN 50.57 51-75 How can I do this? Thanks. Tammy [[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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] Changing data frame column headings
On Wed, 5 Dec 2012, R. Michael Weylandt wrote: Can you be more explicit about your problem? Michael, Data frame contains water chemistry data; site, date, parameter, value. The column names after dcast() are, for example, alk_quant, ph_quant, tds_quant. I wanted to remove the '_quant' from each column header. Using names() with a string vector of the new names did not work, so I specified each one and names() made the changes. Rich __ 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] Changing data frame column headings
On Wed, 5 Dec 2012, arun wrote: I am not sure why ?rename() is not working. a - list(a = 1, b = 2, c = 3) rename(a, c(b = a, c = b, a=c)) I have the reshape2 library loaded and ?rename did not find the help page. Are the parentheses required in the command? Thanks, Rich __ 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] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring?
Without seeing what options you have specified in your call to fa(), it is not possible to answer the question. There are detailed discussions in ?fa and ?factor.scores in the psych package, but for the final word you should probably contact the package maintainer: Package: psych Version: 1.2.8 Date: 2012-08-08 Title: Procedures for Psychological, Psychometric, and Personality Research Author: William Revelle reve...@northwestern.edu Maintainer: William Revelle reve...@northwestern.edu -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Brent Caldwell Sent: Wednesday, December 05, 2012 2:53 PM To: r-help@R-project.org Subject: [R] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring? Hi I have used fa() to perform a factor analysis of a psychological battery which is thought to have 11 factors. I can identify which factors the loadings relate to easily enough because I can see which items are loading onto each of the columns in the $loading output. However, how can I identify which items or loadings are being used to create each of the columns in the $scores output? I have used generalised linear models which have shown that some of the scores are significant predictors of treatment outcome, but I can't work out which of the 11 factors they are scoring? when I export to csv the $loadings I get the following columns in this order: MR4, MR3, MR2, MR6, MR7, MR5, MR1, MR8, MR10, MR9, MR11 When I export to csv the $scores I get the following columns in this order: V1, V2, V3, V4, V5, V6, V7, V8, V9, V10,V11 Are the scores in the column V1 derived from the loadings in column MR1 ? Or are the scores in the first column of $scores (ie V1) derived from the loadings in the first column of $loadings (ie MR4)? Thank you very much for your guidance, and your patience with my confusion Best wishes Brent Brent Caldwell, MBChB, DPH, MPH. Research Fellow Department of Medicine University of Otago, Wellington New Zealand U brent.caldw...@otago.ac.nz b 04 918 6041 021 87 22 64 23a Mein Street, PO Box 7343, Newtown, WELLINGTON 6021, NEW ZEALAND brent.ower.caldwell Zonnic study __ 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.
Re: [R] data manipulation between vector and matrix
HI, In addition to ?sweep(), you can use apply(-mat,1,`+`,x) #or library(plyr) aaply(-mat,1,+,x) A.K. - Original Message - From: C W tmrs...@gmail.com To: Sarah Goslee sarah.gos...@gmail.com Cc: r-help r-help@r-project.org Sent: Wednesday, December 5, 2012 1:51 PM Subject: Re: [R] data manipulation between vector and matrix Thanks, Sarah. First time heard about sweep(), it worked just the way I wanted. Mike On Wed, Dec 5, 2012 at 1:42 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) Thanks for the actual reproducible example. I want, x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements of x against column elements in mat. But x-mat won't do it. This will (note the modification to get x - mat): sweep(-mat, 2, x, +) [,1] [,2] [1,] 0 -19 [2,] -1 -20 [3,] -2 -21 [4,] -3 -22 [5,] -4 -23 etc. -- Sarah Goslee http://www.functionaldiversity.org [[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-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] Changing data frame column headings
On Wed, Dec 5, 2012 at 9:23 PM, Rich Shepard rshep...@appl-ecosys.com wrote: On Wed, 5 Dec 2012, R. Michael Weylandt wrote: Can you be more explicit about your problem? Michael, Data frame contains water chemistry data; site, date, parameter, value. The column names after dcast() are, for example, alk_quant, ph_quant, tds_quant. I wanted to remove the '_quant' from each column header. Using names() with a string vector of the new names did not work, so I specified each one and names() made the changes. Rich I'm afraid I'm still having trouble visualizing -- perhaps you could work up a reproducible example? http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Michael __ 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] data manipulation between vector and matrix
Thanks for the benchmark. I actually wanted to go with the winner, except the x-t(mat) output is very different than the others. Mike On Wed, Dec 5, 2012 at 4:40 PM, arun smartpink...@yahoo.com wrote: Hi, By comparing the different methods: set.seed(5) mat1-matrix(sample(1:1e6,1e6,replace=TRUE),ncol=1) set.seed(25) x-sample(1:1e6,1,replace=TRUE) system.time(z1-sweep(-mat1,2,x,+)) # user system elapsed # 0.076 0.000 0.069 system.time(z2-apply(-mat1,1,`+`,x)) # user system elapsed # 0.036 0.000 0.031 system.time(z3-aaply(-mat1,1,`+`,x)) # user system elapsed # 1.880 0.000 1.704 system.time(z4- x-t(mat1)) #winner # user system elapsed # 0.004 0.000 0.007 system.time(z5- t(x-t(mat1))) # user system elapsed # 0.008 0.000 0.009 A.K. From: C W tmrs...@gmail.com To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; Sarah Goslee sarah.gos...@gmail.com Sent: Wednesday, December 5, 2012 4:11 PM Subject: Re: [R] data manipulation between vector and matrix thanks, I knew about apply, but did not you you can put plus signs with quotes. That's a cool tricky, Mike On Wed, Dec 5, 2012 at 4:05 PM, arun smartpink...@yahoo.com wrote: HI, In addition to ?sweep(), you can use apply(-mat,1,`+`,x) #or library(plyr) aaply(-mat,1,+,x) A.K. - Original Message - From: C W tmrs...@gmail.com To: Sarah Goslee sarah.gos...@gmail.com Cc: r-help r-help@r-project.org Sent: Wednesday, December 5, 2012 1:51 PM Subject: Re: [R] data manipulation between vector and matrix Thanks, Sarah. First time heard about sweep(), it worked just the way I wanted. Mike On Wed, Dec 5, 2012 at 1:42 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) Thanks for the actual reproducible example. I want, x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements of x against column elements in mat. But x-mat won't do it. This will (note the modification to get x - mat): sweep(-mat, 2, x, +) [,1] [,2] [1,]0 -19 [2,] -1 -20 [3,] -2 -21 [4,] -3 -22 [5,] -4 -23 etc. -- Sarah Goslee http://www.functionaldiversity.org [[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] Changing data frame column headings
If you check, the help files, you will find rename in reshape and plyr, but not reshape2. But you have never shown us the command you used with names() and what didn't work: a - data.frame(alk_quant=rnorm(5, 5), ph_quant= rnorm(5, 5), + tds_quant=rnorm(5, 5)) a alk_quant ph_quant tds_quant 1 6.569293 5.494560 5.521039 2 4.854873 5.612902 5.235817 3 4.636218 5.116499 5.973769 4 5.430009 6.273394 3.511017 5 5.714755 6.876349 4.035907 names(a) - gsub(_quant, , names(a)) a alk ph tds 1 6.569293 5.494560 5.521039 2 4.854873 5.612902 5.235817 3 4.636218 5.116499 5.973769 4 5.430009 6.273394 3.511017 5 5.714755 6.876349 4.035907 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rich Shepard Sent: Wednesday, December 05, 2012 3:25 PM To: R help Subject: Re: [R] Changing data frame column headings On Wed, 5 Dec 2012, arun wrote: I am not sure why ?rename() is not working. a - list(a = 1, b = 2, c = 3) rename(a, c(b = a, c = b, a=c)) I have the reshape2 library loaded and ?rename did not find the help page. Are the parentheses required in the command? Thanks, Rich __ 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.
Re: [R] Changing data frame column headings
On Wed, 5 Dec 2012, arun wrote: You can get ?rename() by either loading library(reshape) or library(plyr). A.K. I wondered about that, but assumed that reshape functions would also be found in reshape2. I now know that's not the case. :-) Much appreciated, Rich __ 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] stiff delay differential equations
Suzen, Mehmet msuzen at gmail.com writes: Hello List, Can you recommend me if odeSolve can handle stiff delay differential equations with discontinuities? Or any other package? Best, -m I don't know, but I think you're probably best off trying it out for yourself and seeing how it works -- the start-up cost shouldn't be *that* high. Looking at http://finzi.psych.upenn.edu/R/library/deSolve/html/dede.html is useful. Also, library(sos) findFn({delay differential equation}) might be helpful. __ 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] duplicated() with long vectors
Hi Sarah, Thanks a lot for your explanation. I was mistakenly under the impression that duplicated() only looked at immediately preceding element, not all preceding elements. What I was trying to do was get a vector saying, for each item, whether that item is the same as the preceding item. Now that I think of it, I could do this easily by copying the vector, shifting it over one (by removing the first element and adding something to the end), and then just compare the elements of the two vectors directly. Best, Steve On Wed, Dec 5, 2012 at 3:08 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Hi, duplicated() doesn't just look at consecutive values, but anywhere in the object. Since your 12320-element vector has only 48 separate values, and all of them occur before the last 30 elements, so duplicated() returns TRUE. You might be looking for something involving rle(). What are you trying to accomplish? Sarah On Wed, Dec 5, 2012 at 3:53 PM, Stephen Politzer-Ahles politzerahl...@gmail.com wrote: Hello, duplicated() does not seem to work for a long vector. For example, if you download the data from https://docs.google.com/open?id=0B6-m45Jvl3ZmNmpaSlJWMXo5bmc (a vector with about 12,000 numbers) and then run the following code which does duplicated() over the whole vector but just shows the last 30 elements: data.frame( tail(verylong, 30), tail(duplicated(verylong), 30) ) you'll see that at the end of the very long vector everything is listed as a duplicate of the preceding element (even though it shouldn't be). On the other hand, if you run the following code which just takes out the last 30 elements of the vector and does duplicated on them: data.frame( tail(verylong, 30), duplicated(tail(verylong, 30)) ) you get the correct results (FALSE shows up wherever the value in the first column changes). Does anyone know why this happens, and if there's a fix? I notice the documentation for duplicated() says: Long vectors are supported for the default method of duplicated, but may only be usable if nmax is supplied. But I've tried running this with a high value of nmax given, and it still gives me the same problem. So far the only way I've figured out to get this duplicated()-like vector is to use a for loop going through one item at a time, but that takes about a minute to run. Best, Steve Politzer-Ahles -- Sarah Goslee http://www.functionaldiversity.org -- Stephen Politzer-Ahles University of Kansas Linguistics Department http://people.ku.edu/~sjpa/ __ 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] duplicated() with long vectors
What I was trying to do was get a vector saying, for each item, whether that item is the same as the preceding item. Now that I think of it, I could do this easily by copying the vector, shifting it over one (by removing the first element and adding something to the end), and then just compare the elements of the two vectors directly. Right. Did you look at rle() yet? Though for your particular simple case, system.time(verylong[1:(n-1)] == verylong[2:n]) user system elapsed 0.001 0.000 0.002 is nearly instantaneous. On Wed, Dec 5, 2012 at 5:04 PM, Stephen Politzer-Ahles politzerahl...@gmail.com wrote: Hi Sarah, Thanks a lot for your explanation. I was mistakenly under the impression that duplicated() only looked at immediately preceding element, not all preceding elements. What I was trying to do was get a vector saying, for each item, whether that item is the same as the preceding item. Now that I think of it, I could do this easily by copying the vector, shifting it over one (by removing the first element and adding something to the end), and then just compare the elements of the two vectors directly. Best, Steve On Wed, Dec 5, 2012 at 3:08 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Hi, duplicated() doesn't just look at consecutive values, but anywhere in the object. Since your 12320-element vector has only 48 separate values, and all of them occur before the last 30 elements, so duplicated() returns TRUE. You might be looking for something involving rle(). What are you trying to accomplish? Sarah On Wed, Dec 5, 2012 at 3:53 PM, Stephen Politzer-Ahles politzerahl...@gmail.com wrote: Hello, duplicated() does not seem to work for a long vector. For example, if you download the data from https://docs.google.com/open?id=0B6-m45Jvl3ZmNmpaSlJWMXo5bmc (a vector with about 12,000 numbers) and then run the following code which does duplicated() over the whole vector but just shows the last 30 elements: data.frame( tail(verylong, 30), tail(duplicated(verylong), 30) ) you'll see that at the end of the very long vector everything is listed as a duplicate of the preceding element (even though it shouldn't be). On the other hand, if you run the following code which just takes out the last 30 elements of the vector and does duplicated on them: data.frame( tail(verylong, 30), duplicated(tail(verylong, 30)) ) you get the correct results (FALSE shows up wherever the value in the first column changes). Does anyone know why this happens, and if there's a fix? I notice the documentation for duplicated() says: Long vectors are supported for the default method of duplicated, but may only be usable if nmax is supplied. But I've tried running this with a high value of nmax given, and it still gives me the same problem. So far the only way I've figured out to get this duplicated()-like vector is to use a for loop going through one item at a time, but that takes about a minute to run. Best, Steve Politzer-Ahles -- Sarah Goslee http://www.functionaldiversity.org __ 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] Changing data frame column headings
On Wed, 5 Dec 2012, David L Carlson wrote: names(a) - gsub(_quant, , names(a)) a David, I did not pick that up from the names() help page. Thanks for the insight. Rich __ 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] error reading xlsm file with read.xls
On Dec 4, 2012, at 10:05 AM, Sebastian Kruk wrote: Dear all, I cannot reading a .xlsm file using read.xls. That doesn't surprise me. It's a macro format. Why should R be reading Excel macros? I executed: read.xls(resultados.xlsm, colNames = TRUE, sheet = 1, type = data.frame, from = 1, rowNames = NA, colClasses = character, checkNames = TRUE, dateTime = numeric, naStrings = NA, stringsAsFactors = F) Error: Call(ReadXls, file, colNames, sheet, type, from, rowNames, : Incorrect number of arguments (11), expecting 10 for 'ReadXls' If I just write read.xls(resultados.xlsm) It give me the same error. -- David Winsemius, MD Alameda, CA, USA __ 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] duplicated() with long vectors
On 05/12/2012 21:08, Sarah Goslee wrote: Hi, duplicated() doesn't just look at consecutive values, but anywhere in the object. Since your 12320-element vector has only 48 separate values, and all of them occur before the last 30 elements, so duplicated() returns TRUE. You might be looking for something involving rle(). What are you trying to accomplish? And BTW, 'long vector' is a technical term in R: not 12,000, but more than 2 billion elements. You will hear it a lot more in the run-up to the next 'minor' release of R (currently R-devel, maybe 2.16.0-to-be, which is the only version from which that quote comes that I am aware of). The posting guide asked for 'at a minimum' information: if you are using an unreleased development version of R you really must tell us (and should not be reporting to the R-help list). Sarah On Wed, Dec 5, 2012 at 3:53 PM, Stephen Politzer-Ahles politzerahl...@gmail.com wrote: Hello, duplicated() does not seem to work for a long vector. For example, if you download the data from https://docs.google.com/open?id=0B6-m45Jvl3ZmNmpaSlJWMXo5bmc (a vector with about 12,000 numbers) and then run the following code which does duplicated() over the whole vector but just shows the last 30 elements: data.frame( tail(verylong, 30), tail(duplicated(verylong), 30) ) you'll see that at the end of the very long vector everything is listed as a duplicate of the preceding element (even though it shouldn't be). On the other hand, if you run the following code which just takes out the last 30 elements of the vector and does duplicated on them: data.frame( tail(verylong, 30), duplicated(tail(verylong, 30)) ) you get the correct results (FALSE shows up wherever the value in the first column changes). Does anyone know why this happens, and if there's a fix? I notice the documentation for duplicated() says: Long vectors are supported for the default method of duplicated, but may only be usable if nmax is supplied. But I've tried running this with a high value of nmax given, and it still gives me the same problem. So far the only way I've figured out to get this duplicated()-like vector is to use a for loop going through one item at a time, but that takes about a minute to run. Best, Steve Politzer-Ahles -- Brian D. Ripley, rip...@stats.ox.ac.uk 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@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 to reset R settings to original state other than remove .Rdata and .Rhistory
Read the ?Startup page, it documents the files that are read on startup and how to skip them, it may suggest another way to start a fresh session without deleting files to see if that works for you, it also gives other files or sources that you may investigate to find the differences in the 2 machines. On Tue, Dec 4, 2012 at 9:53 AM, Tian3507 dbb_t...@hotmail.com wrote: Dear all, Do you know how to return all the R settings to original state? Other than .Rdata and .Rhistory Some weid thing happened to my machine. I was trying to get shaded confidence band ploted using survplot from rms liberary. It worked on one machine, but not on the other. I tried unstall R and reinstall R and remove. Rdata and .Rhisotory. Nothing helped so far. Thanks for your input. Best regards, Hong Codes are library(rms) data generation n - 1000 set.seed(731) age - 50 + 12*rnorm(n) label(age) - Age sex - factor(sample(c('male','female'), n, TRUE)) cens - 15*runif(n) h - .02*exp(.04*(age-50)+.8*(sex=='female')) dt - -log(runif(n))/h label(dt) - 'Follow-up Time' e - ifelse(dt = cens,1,0) dt - pmin(dt, cens) units(dt) - 'Year' dd - datadist(age, sex) options(datadist='dd') S - Surv(dt,e) tte-data.frame(dt,e,age,sex) male group KM curve with bands# f - survfit(Surv(dt,e)~1, data=tte,subset=sex=='male') survplot(f,conf=bands) female group KM curve with bands# g - survfit(Surv(dt,e)~1, data=tte,subset=sex!='male') survplot(g,conf=bands, col=3, add=T) [[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. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.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.
Re: [R] duplicated() with long vectors
Sorry, that's my mistake, I should not have said 'long vector'; mine is just a normal vector. I'm not actually using a development version. Best, Steve On Wed, Dec 5, 2012 at 4:22 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: And BTW, 'long vector' is a technical term in R: not 12,000, but more than 2 billion elements. You will hear it a lot more in the run-up to the next 'minor' release of R (currently R-devel, maybe 2.16.0-to-be, which is the only version from which that quote comes that I am aware of). The posting guide asked for 'at a minimum' information: if you are using an unreleased development version of R you really must tell us (and should not be reporting to the R-help list). Sarah On Wed, Dec 5, 2012 at 3:53 PM, Stephen Politzer-Ahles politzerahl...@gmail.com wrote: Hello, duplicated() does not seem to work for a long vector. For example, if you download the data from https://docs.google.com/open?id=0B6-m45Jvl3ZmNmpaSlJWMXo5bmc (a vector with about 12,000 numbers) and then run the following code which does duplicated() over the whole vector but just shows the last 30 elements: data.frame( tail(verylong, 30), tail(duplicated(verylong), 30) ) you'll see that at the end of the very long vector everything is listed as a duplicate of the preceding element (even though it shouldn't be). On the other hand, if you run the following code which just takes out the last 30 elements of the vector and does duplicated on them: data.frame( tail(verylong, 30), duplicated(tail(verylong, 30)) ) you get the correct results (FALSE shows up wherever the value in the first column changes). Does anyone know why this happens, and if there's a fix? I notice the documentation for duplicated() says: Long vectors are supported for the default method of duplicated, but may only be usable if nmax is supplied. But I've tried running this with a high value of nmax given, and it still gives me the same problem. So far the only way I've figured out to get this duplicated()-like vector is to use a for loop going through one item at a time, but that takes about a minute to run. Best, Steve Politzer-Ahles -- Brian D. Ripley, rip...@stats.ox.ac.uk 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 -- Stephen Politzer-Ahles University of Kansas Linguistics Department http://people.ku.edu/~sjpa/ __ 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] stiff delay differential equations
On 12/5/2012 9:15 AM, Suzen, Mehmet wrote: Hello List, Can you recommend me if odeSolve can handle stiff delay differential equations with discontinuities? Or any other package? Best, -m Package deSolve (the successor of odesolve) can candle: - stiff differential equations: yes (solvers: lsoda, lsode, vode, vode, radau) - delay differential equations: yes (function dede, that calls lsoda, lsode, vode, radau, ...) - discontinuities: yes (events and root finding) A combination is also possible, but please keep in mind that this can become difficult by definition, so that it is good modelling practise to start with a simple system first - and to introduce all the complications only when necessary. I am not aware that any other package contains all the requested features, but if please let me know if there is something new and we'll add it to the DifferentialEquations task view. Thomas Petzoldt __ 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] What is print print print ?
On 12/06/2012 12:03 AM, Vladimir eremeev wrote: Hi all. What is print print print? I don't see output of the print command in for loop and have found this link: http://stackoverflow.com/questions/1816200/chisq-test-doesnt-print-results-when-in-a-loop It describes a problem, similar to mine. My problem. I want to execute print command in for loop. If I copy for loop body with print() and paste it to console, I don't see any output. If I type the command, I do see the output. If I paste the command by parts I also see the output. If I construct the command by picking parts of the history with the up arrow, I also don't see any output. Search for print print print still didn't bring anything useful. Hi Vladimir, Your problem is twofold. First, the print command simply tries to display whatever is passed as the first argument to it. Invoking: print() prints nothing, as there is nothing passed to display. Second, the print command is often used in R scripts because most functions will display their return values when invoked directly in the R console, but not when invoked within a for loop. The problem that you mentioned was due to the chisq.test function displaying its return value on its own, but not within the loop. The print print print comment was intended to mean: print(rownames(cl.vs.Onerall)[i]) print(chisq.test(observed, p=expected.fr)) print(--) in the loop so that the successive return values would be displayed. Try it for yourself with this simple example: x-1:5 length(x) for(i in 1:3) length(x) for(i in 1:3) print(length(x)) Jim __ 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] error reading xlsm file with read.xls
On Dec 5, 2012, at 2:19 PM, David Winsemius wrote: On Dec 4, 2012, at 10:05 AM, Sebastian Kruk wrote: Dear all, I cannot reading a .xlsm file using read.xls. That doesn't surprise me. It's a macro format. Why should R be reading Excel macros? I executed: read.xls(resultados.xlsm, colNames = TRUE, sheet = 1, type = data.frame, from = 1, rowNames = NA, colClasses = character, checkNames = TRUE, dateTime = numeric, naStrings = NA, stringsAsFactors = F) The other point I would make is that you should be looking at the help page for read.xls and making sure that on the off-chance that the authors did intend for you to have access to Excel macros for some readsin in R tha thtey were using the same aruments. The error message says you are having problems with you argument list and looking at the help page makes me think you are using read.tabe arguments for read.xls. Not a wise idea.This is the list of formals: read.xlsx(file, sheetIndex, sheetName=NULL, rowIndex=NULL, colIndex=NULL, as.data.frame=TRUE, header=TRUE, colClasses=NA, keepFormulas=FALSE, encoding=unknown, ...) And it says the 'dots' are sent to data.frame rather than to read.table. Error: Call(ReadXls, file, colNames, sheet, type, from, rowNames, : Incorrect number of arguments (11), expecting 10 for 'ReadXls' If I just write read.xls(resultados.xlsm) It give me the same error. -- David Winsemius, MD Alameda, CA, USA __ 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. David Winsemius, MD Alameda, CA, USA __ 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] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring?
Dear Prof Carlson Thank you very much. As far as I can tell, factor.scores requires an object from class grm, itm, rason, or tpm; which I think are part of the irt package with which I am unfamiliar. I had used the psych package to do the following factor analysis: fa.11factors.rawdata - fa(WISDMrawdataframe,nfactors=11) # WISDMrawdataframe has 37 columns and 2408 rows, and contain 1051 rows that are NA (having NA in this dataframe allows the raw data to have the same length as my vector of ID numbers so I can work out which participants the data belong to) fa.11factors.rawdata$loadings #on the computer screen this gives me the loadings with column namesMR4MR3MR2MR6MR7MR5MR1 MR8MR10 MR9MR11 fa.11factors.rawdata$scores # on the computer screen this gives me the scores with column names [,1] [,2][,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] Am I safe in assuming that the scores in the first column relate to the loadings in the column called MR4? If this is a safe assumption, then I can work out which factor the scores relate to, by looking at which items load onto MR4MR3MR2MR6MR7 MR5MR1MR8MR10 MR9MR11 Thank you, I've taken your advice and cc'd this to Prof William Revelle Thank you Best wishes Brent -Original Message- From: David L Carlson [mailto:dcarl...@tamu.edu] Sent: Thursday, 6 December 2012 10:33 a.m. To: Brent Caldwell; 'r-help@R-project.org' Subject: RE: [R] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring? Without seeing what options you have specified in your call to fa(), it is not possible to answer the question. There are detailed discussions in ?fa and ?factor.scores in the psych package, but for the final word you should probably contact the package maintainer: Package: psych Version: 1.2.8 Date: 2012-08-08 Title: Procedures for Psychological, Psychometric, and Personality Research Author: William Revelle reve...@northwestern.edu Maintainer: William Revelle reve...@northwestern.edu -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Brent Caldwell Sent: Wednesday, December 05, 2012 2:53 PM To: r-help@R-project.org Subject: [R] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring? Hi I have used fa() to perform a factor analysis of a psychological battery which is thought to have 11 factors. I can identify which factors the loadings relate to easily enough because I can see which items are loading onto each of the columns in the $loading output. However, how can I identify which items or loadings are being used to create each of the columns in the $scores output? I have used generalised linear models which have shown that some of the scores are significant predictors of treatment outcome, but I can't work out which of the 11 factors they are scoring? when I export to csv the $loadings I get the following columns in this order: MR4, MR3, MR2, MR6, MR7, MR5, MR1, MR8, MR10, MR9, MR11 When I export to csv the $scores I get the following columns in this order: V1, V2, V3, V4, V5, V6, V7, V8, V9, V10,V11 Are the scores in the column V1 derived from the loadings in column MR1 ? Or are the scores in the first column of $scores (ie V1) derived from the loadings in the first column of $loadings (ie MR4)? Thank you very much for your guidance, and your patience with my confusion Best wishes Brent Brent Caldwell, MBChB, DPH, MPH. Research Fellow Department of Medicine University of Otago, Wellington New Zealand U brent.caldw...@otago.ac.nz b 04 918 6041 021 87 22 64 23a Mein Street, PO Box 7343, Newtown, WELLINGTON 6021, NEW ZEALAND brent.ower.caldwell Zonnic study __ 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.
Re: [R] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring?
I think you are safe in assuming that the first factor is used to compute the first factor score column. The factor.scores() procedure is used by fa() to compute the factor scores so it provides details regarding how they are computed beyond the information in the fa() help page. As I understand the help file, the default rotation is oblimin so In the oblique case, the factor loadings are referred to as Pattern coefficients and are related to the Structure coefficients by S = P and thus P = S 1. When estimating factor scores, fa and factanal differ in that fa finds the factors from the Structure matrix and factanal seems to find them from the Pattern matrix. Thus, although in the orthogonal case, fa and factanal agree perfectly in their factor score estimates, they do not agree in the case of oblique factors. Setting oblique.scores = FALSE will produce factor score estimate that match those of factanal. So you might want to look at $Structure. The $scores part of the output is a matrix without column names (they are just numbered). The V1, V2, . . . is added by the write.csv() function and is not part of the actual output from fa(). --- David -Original Message- From: Brent Caldwell [mailto:brent.caldw...@otago.ac.nz] Sent: Wednesday, December 05, 2012 7:08 PM To: dcarl...@tamu.edu; 'r-help@R-project.org' Cc: William R Revelle (reve...@northwestern.edu) Subject: RE: [R] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring? Dear Prof Carlson Thank you very much. As far as I can tell, factor.scores requires an object from class grm, itm, rason, or tpm; which I think are part of the irt package with which I am unfamiliar. I had used the psych package to do the following factor analysis: fa.11factors.rawdata - fa(WISDMrawdataframe,nfactors=11) # WISDMrawdataframe has 37 columns and 2408 rows, and contain 1051 rows that are NA (having NA in this dataframe allows the raw data to have the same length as my vector of ID numbers so I can work out which participants the data belong to) fa.11factors.rawdata$loadings #on the computer screen this gives me the loadings with column namesMR4MR3MR2MR6MR7MR5 MR1MR8MR10 MR9MR11 fa.11factors.rawdata$scores # on the computer screen this gives me the scores with column names [,1] [,2][,3] [,4][,5] [,6] [,7] [,8] [,9] [,10] [,11] Am I safe in assuming that the scores in the first column relate to the loadings in the column called MR4? If this is a safe assumption, then I can work out which factor the scores relate to, by looking at which items load onto MR4MR3MR2 MR6MR7MR5MR1MR8MR10 MR9MR11 Thank you, I've taken your advice and cc'd this to Prof William Revelle Thank you Best wishes Brent -Original Message- From: David L Carlson [mailto:dcarl...@tamu.edu] Sent: Thursday, 6 December 2012 10:33 a.m. To: Brent Caldwell; 'r-help@R-project.org' Subject: RE: [R] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring? Without seeing what options you have specified in your call to fa(), it is not possible to answer the question. There are detailed discussions in ?fa and ?factor.scores in the psych package, but for the final word you should probably contact the package maintainer: Package: psych Version: 1.2.8 Date: 2012-08-08 Title: Procedures for Psychological, Psychometric, and Personality Research Author: William Revelle reve...@northwestern.edu Maintainer: William Revelle reve...@northwestern.edu -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Brent Caldwell Sent: Wednesday, December 05, 2012 2:53 PM To: r-help@R-project.org Subject: [R] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring? Hi I have used fa() to perform a factor analysis of a psychological battery which is thought to have 11 factors. I can identify which factors the loadings relate to easily enough because I can see which items are loading onto each of the columns in the $loading output. However, how can I identify which items or loadings are being used to create each of the columns in the $scores output? I have used generalised linear models which have shown that some of the scores are significant predictors of treatment outcome, but I can't work out which of the 11 factors they are scoring? when I
Re: [R] catching errors in RNetCDF
Hi, When I try your example, I simply get an error: library(RNetCDF) con - create.nc('test.nc') test - try(var.get.nc(con, 'dummy')) Error : NetCDF: Variable not found Regards, Pascal Le 05/12/2012 22:08, Jannis a écrit : Dear R community, I quite frequently run into errors while using the RNetCDF package which do not seem to be recognised as normal R errors and, hence, do not stop the execution of the code making it hard to debug the code. Consider, for example: library(RNetCDF) con - create.nc('test.nc') test - try(var.get.nc(con, 'dummy')) In this case, some sort of error message is printed to the screen, but R does not recognise this as an error. Is there any way to solve this? I contacted the author of the package but it seems that there will be no solution from that side. Any Ideas? Cheers Jannis __ 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] Assignment of values with different indexes
I would like to take the values of observations and map them to a new index. I am not sure how to accomplish this. The result would look like so: x[1,2,3,4,5,6,7,8,9,10] becomes y[2,4,6,8,10,12,14,16,18,20] The newindex would not necessarily be this sequence, but a sequence I have stored in a vector, so it could be all kinds of values. here is what happens: x - rnorm(10) myindex - seq(from = 1,to = 20, by = 2) y - numeric() y[myindex] - x y [1] -0.03745988 NA -0.09078822 NA 0.92484413 NA 0.32057426 NA [9] 0.01536279 NA 0.02200198 NA 0.37535438 NA 1.46606535 NA [17] 1.44855796 NA -0.05048738 So yes, it maps the values to my new indexes, but I have NA's. The result I want would look like this instead: [1] -0.03745988 [3] -0.09078822 [5] 0.92484413 [7] 0.32057426 [9] 0.01536279 [11] 0.02200198 [13] 0.37535438 [15] 1.46606535 [17] 1.44855796 [19] -0.05048738 and remove the NA's. I tried this with na.omit() on x, but it looks like so: x - rnorm(10) myindex - seq(from = 1,to = 20, by = 2) y - numeric() y[myindex] - na.omit(x) y [1] 0.87399523 NA -0.39908184 NA 0.14583051 NA 0.01850755 NA [9] -0.47413632 NA 0.88410517 NA -1.64939190 NA 0.57650807 NA [17] 0.44016971 NA -0.56313802 Brian __ 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] Assignment of values with different indexes
Hello, I am sorry, but I sincerely don't understand what you are trying to do. Regards, Pascal Le 06/12/2012 11:47, Brian Feeny a écrit : I would like to take the values of observations and map them to a new index. I am not sure how to accomplish this. The result would look like so: x[1,2,3,4,5,6,7,8,9,10] becomes y[2,4,6,8,10,12,14,16,18,20] The newindex would not necessarily be this sequence, but a sequence I have stored in a vector, so it could be all kinds of values. here is what happens: x - rnorm(10) myindex - seq(from = 1,to = 20, by = 2) y - numeric() y[myindex] - x y [1] -0.03745988 NA -0.09078822 NA 0.92484413 NA 0.32057426 NA [9] 0.01536279 NA 0.02200198 NA 0.37535438 NA 1.46606535 NA [17] 1.44855796 NA -0.05048738 So yes, it maps the values to my new indexes, but I have NA's. The result I want would look like this instead: [1] -0.03745988 [3] -0.09078822 [5] 0.92484413 [7] 0.32057426 [9] 0.01536279 [11] 0.02200198 [13] 0.37535438 [15] 1.46606535 [17] 1.44855796 [19] -0.05048738 and remove the NA's. I tried this with na.omit() on x, but it looks like so: x - rnorm(10) myindex - seq(from = 1,to = 20, by = 2) y - numeric() y[myindex] - na.omit(x) y [1] 0.87399523 NA -0.39908184 NA 0.14583051 NA 0.01850755 NA [9] -0.47413632 NA 0.88410517 NA -1.64939190 NA 0.57650807 NA [17] 0.44016971 NA -0.56313802 Brian __ 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.
Re: [R] Assignment of values with different indexes
On Dec 5, 2012, at 6:47 PM, Brian Feeny wrote: I would like to take the values of observations and map them to a new index. I am not sure how to accomplish this. The result would look like so: x[1,2,3,4,5,6,7,8,9,10] becomes y[2,4,6,8,10,12,14,16,18,20] This suggests to me that you are having difficulty transfering your Matlab knowldege to R. The newindex would not necessarily be this sequence, but a sequence I have stored in a vector, so it could be all kinds of values. here is what happens: x - rnorm(10) myindex - seq(from = 1,to = 20, by = 2) y - numeric() y[myindex] - x y [1] -0.03745988 NA -0.09078822 NA 0.92484413 NA 0.32057426 NA [9] 0.01536279 NA 0.02200198 NA 0.37535438 NA 1.46606535 NA [17] 1.44855796 NA -0.05048738 So yes, it maps the values to my new indexes, but I have NA's. The result I want would look like this instead: The only structure in R that allows NULL values is a list. Matrices need to have either value or NA. [1] -0.03745988 [3] -0.09078822 [5] 0.92484413 [7] 0.32057426 [9] 0.01536279 [11] 0.02200198 [13] 0.37535438 [15] 1.46606535 [17] 1.44855796 [19] -0.05048738 and remove the NA's. I tried this with na.omit() on x, but it looks like so: x - rnorm(10) myindex - seq(from = 1,to = 20, by = 2) y - numeric() y[myindex] - na.omit(x) y [1] 0.87399523 NA -0.39908184 NA 0.14583051 NA 0.01850755 NA [9] -0.47413632 NA 0.88410517 NA -1.64939190 NA 0.57650807 NA [17] 0.44016971 NA -0.56313802 However it will not display the way you were inteniding: y - list() y[seq(1,20, by=2)] - 1:10 y [[1]] [1] 1 [[2]] NULL [[3]] [1] 2 [[4]] NULL [[5]] [1] 3 snipped -- David. Brian __ 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. David Winsemius, MD Alameda, CA, USA __ 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] Line numbers with errors and warnings?
If you `source(test.R, keep.source=FALSE)`, you will see that the line number is not reported. Not always. I have code that uses sapply to call another function and all I get back is the line of the sapply. Useful but in the 21st century I do think I could get more aid from the runtime and compiler to help me. I am giving up. In the short term I am giving yup on expecting line numbers (running with anything other than options(error=NULL) is a pain for all sorts of reasons) and in the medium term I am giving up on R. It is sad. R is very powerful and I can say a lot with very little. But I have been using it intensely for 3 years, written (and debugged) thousands of lines of code. It is exactly what I need *but* the debugging facilities are too primitive and the time gained in design and implementation is lost, with interest, in debugging. IMO R is very suitable for simple tasks that would be complex in other languages. But once it gets complex in R, it is too hard. I am not saying R is very bad - far from it. But for ambitious projects it cannot compete without proper debugging facilities. It may be that I am not good enough at programming - fair enough. But I am what I am, and I have been beating my head against this for far too long. Having large amounts of code in R that I use every day I am not running away at high speed. But I am moving away. If R gets modern debugging (lets say up to where gdb was in the early 1990s) I'll be back with a big smile on my face. But I cannot dictate the priorities of the R maintainers, and I will not try. peace Worik Stanton Dunedin New Zealand [[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] Line numbers with errors and warnings?
Hi, On Thu, Dec 6, 2012 at 12:01 AM, Worik R wor...@gmail.com wrote: If you `source(test.R, keep.source=FALSE)`, you will see that the line number is not reported. Not always. I have code that uses sapply to call another function and all I get back is the line of the sapply. The function that is being called inside the sapply that throws the error -- is it in a different package? If you reinstall *that* package w/ `options(keep.source.pkg=TRUE)` (or R_KEEP_PKG_SOURCE=yes in your environment if installing from cmd line (see ?options)), does that help? If not -- could you provide, in a similar fashion as I did w/ the BadPackage on github from an earlier message in this thread, an example that recapitulates this no-line-number-on-error problem and point out where/how it happens so we can also trigger it and see? (I have a function that does xxx is hard for anybody else to help you with). Also, emacs/ess also has tracebug: http://code.google.com/p/ess-tracebug/ which may be useful. anyway ... if you are leaving R for greener pastures, do us a favor and send us an email w/ an update if you find Nirvana in another language ;-) -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ 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] Assignment of values with different indexes
No, because it does not assign the indexes of myindex. If its not possible, which I am assuming its not, thats OK. I thought that if I had say 10 observations, sequentially ordered (or any order, it doesn't matter), and I wanted to assign them specific indexes, and not have NA's, that it was possible. I am OK with knowing that I can assign them the specific indexes, and that there will be empty spots, which are marked NA. Most functions I would need to use can handle NA's by telling the function to ignore. I appreciate all the help that has been given. Brian On Dec 5, 2012, at 11:49 PM, arun smartpink...@yahoo.com wrote: Hi, Would it be okay to use: y-na.omit(y[myindex]-x) y # [1] -1.36025132 -0.57529211 1.18132359 0.41038489 1.83108252 -0.03563686 #[7] 1.25267314 1.08311857 1.56973422 -0.30752939 A.K. - Original Message - From: Brian Feeny bfe...@mac.com To: r-help@r-project.org help r-help@r-project.org Cc: Sent: Wednesday, December 5, 2012 9:47 PM Subject: [R] Assignment of values with different indexes I would like to take the values of observations and map them to a new index. I am not sure how to accomplish this. The result would look like so: x[1,2,3,4,5,6,7,8,9,10] becomes y[2,4,6,8,10,12,14,16,18,20] The newindex would not necessarily be this sequence, but a sequence I have stored in a vector, so it could be all kinds of values. here is what happens: x - rnorm(10) myindex - seq(from = 1,to = 20, by = 2) y - numeric() y[myindex] - x y [1] -0.03745988 NA -0.09078822 NA 0.92484413 NA 0.32057426 NA [9] 0.01536279 NA 0.02200198 NA 0.37535438 NA 1.46606535 NA [17] 1.44855796 NA -0.05048738 So yes, it maps the values to my new indexes, but I have NA's. The result I want would look like this instead: [1] -0.03745988 [3] -0.09078822 [5] 0.92484413 [7] 0.32057426 [9] 0.01536279 [11] 0.02200198 [13] 0.37535438 [15] 1.46606535 [17] 1.44855796 [19] -0.05048738 and remove the NA's. I tried this with na.omit() on x, but it looks like so: x - rnorm(10) myindex - seq(from = 1,to = 20, by = 2) y - numeric() y[myindex] - na.omit(x) y [1] 0.87399523 NA -0.39908184 NA 0.14583051 NA 0.01850755 NA [9] -0.47413632 NA 0.88410517 NA -1.64939190 NA 0.57650807 NA [17] 0.44016971 NA -0.56313802 Brian __ 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.
Re: [R] Line numbers with errors and warnings?
Bert R is compiled. Compile and go cycle is quick, but it is compiled. Not to a machine executable but to an object the R runtinme can interperet. Steve It is all a bit hard. I can make progress the old fashioned way with debug messages and conditional execution and dozens of other techniques. From the 1960s! Do not get me wrong. i accept the situation. I see why it is like it is. I am being too ambitious with my R code. As for Nirvana. I'll not announce it here, that would be rude! Frankly I think I'll be using Perl for data processing and C++ for heavy lifting and the data structures I need. I might take a quick look at Julia: http://julialang.org/ but life is short, new languages hard. I will not abandon R, but I have learnt some respect - I'll use R appropriately in the future. W On Thu, Dec 6, 2012 at 6:33 PM, Steve Lianoglou mailinglist.honey...@gmail.com wrote: Hi, On Thu, Dec 6, 2012 at 12:01 AM, Worik R wor...@gmail.com wrote: If you `source(test.R, keep.source=FALSE)`, you will see that the line number is not reported. Not always. I have code that uses sapply to call another function and all I get back is the line of the sapply. The function that is being called inside the sapply that throws the error -- is it in a different package? If you reinstall *that* package w/ `options(keep.source.pkg=TRUE)` (or R_KEEP_PKG_SOURCE=yes in your environment if installing from cmd line (see ?options)), does that help? If not -- could you provide, in a similar fashion as I did w/ the BadPackage on github from an earlier message in this thread, an example that recapitulates this no-line-number-on-error problem and point out where/how it happens so we can also trigger it and see? (I have a function that does xxx is hard for anybody else to help you with). Also, emacs/ess also has tracebug: http://code.google.com/p/ess-tracebug/ which may be useful. anyway ... if you are leaving R for greener pastures, do us a favor and send us an email w/ an update if you find Nirvana in another language ;-) -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact [[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] Changing data frame column headings
Hi Rich, You can get ?rename() by either loading library(reshape) or library(plyr). A.K. - Original Message - From: Rich Shepard rshep...@appl-ecosys.com To: R help r-help@r-project.org Cc: Sent: Wednesday, December 5, 2012 4:24 PM Subject: Re: [R] Changing data frame column headings On Wed, 5 Dec 2012, arun wrote: I am not sure why ?rename() is not working. a - list(a = 1, b = 2, c = 3) rename(a, c(b = a, c = b, a=c)) I have the reshape2 library loaded and ?rename did not find the help page. Are the parentheses required in the command? Thanks, Rich __ 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.
Re: [R] data manipulation between vector and matrix
Hi, By comparing the different methods: set.seed(5) mat1-matrix(sample(1:1e6,1e6,replace=TRUE),ncol=1) set.seed(25) x-sample(1:1e6,1,replace=TRUE) system.time(z1-sweep(-mat1,2,x,+)) # user system elapsed # 0.076 0.000 0.069 system.time(z2-apply(-mat1,1,`+`,x)) # user system elapsed # 0.036 0.000 0.031 system.time(z3-aaply(-mat1,1,`+`,x)) # user system elapsed # 1.880 0.000 1.704 system.time(z4- x-t(mat1)) #winner # user system elapsed # 0.004 0.000 0.007 system.time(z5- t(x-t(mat1))) # user system elapsed # 0.008 0.000 0.009 A.K. From: C W tmrs...@gmail.com To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; Sarah Goslee sarah.gos...@gmail.com Sent: Wednesday, December 5, 2012 4:11 PM Subject: Re: [R] data manipulation between vector and matrix thanks, I knew about apply, but did not you you can put plus signs with quotes. That's a cool tricky, Mike On Wed, Dec 5, 2012 at 4:05 PM, arun smartpink...@yahoo.com wrote: HI, In addition to ?sweep(), you can use apply(-mat,1,`+`,x) #or library(plyr) aaply(-mat,1,+,x) A.K. - Original Message - From: C W tmrs...@gmail.com To: Sarah Goslee sarah.gos...@gmail.com Cc: r-help r-help@r-project.org Sent: Wednesday, December 5, 2012 1:51 PM Subject: Re: [R] data manipulation between vector and matrix Thanks, Sarah. First time heard about sweep(), it worked just the way I wanted. Mike On Wed, Dec 5, 2012 at 1:42 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) Thanks for the actual reproducible example. I want, x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements of x against column elements in mat. But x-mat won't do it. This will (note the modification to get x - mat): sweep(-mat, 2, x, +) [,1] [,2] [1,] 0 -19 [2,] -1 -20 [3,] -2 -21 [4,] -3 -22 [5,] -4 -23 etc. -- Sarah Goslee http://www.functionaldiversity.org [[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-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] request
Dear Dr. Bernhard Thank you very much for quick reply. One good news is that i can connect with Neos server. I appreciate your suggestion to change 'protocols' to 'proxy'. after assigning proxy, i can connect with my desired website. Thankyou very much With best regards Rubel On Thu, Dec 6, 2012 at 3:32 AM, Bernhard Pfaff bernh...@pfaffikus.dewrote: Hello Rubel, many thanks for your email. Diagnosing your problem is a bit hard without further information, hence I can only provide you with some pointers for further checking/testing: 1) You specify implictly a port for the proxy. Is this the correct one? 2) Specify, 'proxy' as a list element for your proxy. See listCurlOptions() on what is available and can be included in your list object for 'curlopts'. 3) Can you establish a connection to some other site by means of the provided functions in RCurl and your chosen setting? Best, Bernhard Am Mittwoch, den 05.12.2012, 19:15 +0900 schrieb Rubel Das: Dear Dr. bernhard cc. r-help Thank you very much for deverlopping rneos package. I read the document of rneos. however, due to my inability, i could not figure-out how to connect with neos server from R environment. let me explain the steps, i took. my laptop is using wireless of my laboratory. to connect the internet, i need proxy address and specific port (that i have mentioned in protocols in CreateNeosComm). However, the proxy server does not have any password though to access wifi i need password. After inserting the protocols as shown in Input (below), i have go the output as shown in below. input library (rneos) NC-CreateNeosComm(curlopts=list(httpheader=c('content-type'=text/xml, 'User-Agent'=R), protocols=proxy.noc.titech.ac.jp:3128, port=3332),curlhandle=getCurlHandle()) #to check the neos server is activeNeosServer is alive is returned Nping(convert=T, nc=NC) output library (rneos) NC-CreateNeosComm(curlopts=list(httpheader=c('content-type'=text/xml, 'User-Agent'=R), protocols=proxy.noc.titech.ac.jp:3128, port=3332),curlhandle=getCurlHandle()) Error in match(x, table, nomatch = 0L) : object 'proxy.noc.titech.ac.jp' not found #to check the neos server is activeNeosServer is alive is returned Nping(convert=T, nc=NC) Error in .postForm(curl, .opts, .params, style) : Stale CURL handle being passed to libcurl Error in curlSetOpt(writefunction = NULL, curl = curl) : Stale CURL handle being passed to libcurl Since this procedure is not working, would you suggest me how can i fix the problem? i appreciate your help. -- With best Regards Rubel Das Hanaoka Research Group/Transport Planning Dept. of International Development Engineering Tokyo Institute of Technology 2-12-1-I4-12, O-okayama, Meguro-ku, Tokyo, 152-8550, Japan email: rubeldas2...@gmail.com rubel...@tp.ide.titech.ac.jp -- With best Regards Rubel Das Hanaoka Research Group/Transport Planning Dept. of International Development Engineering Tokyo Institute of Technology 2-12-1-I4-12, O-okayama, Meguro-ku, Tokyo, 152-8550, Japan email: rubeldas2...@gmail.com rubel...@tp.ide.titech.ac.jp [[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] bootstrap based confidence band
I'm trying to find a bootstrap based confidence band for a linear model. I have created a data set with X and Y X=runif(n,-1.25,1.25) e=rnorm(n,0,1) Y=exp(3*X)+5*sin((30*X)/(2*pi))+2*e fit=lm(Y~X) summary(fit) I define a bootstrap function named PairedBootstrap which is not listed here. Than I try many ways to find the confidence band. One way is to predict Y using the model I get above for 1000 times. Data.Orig=data.frame(cbind(X,Y)) B=1000 Boot.Result=matrix(nrow=B,ncol=n) for ( b in 1:B){ Data.Orig.Boot=PairedBootstrap(Data.Orig) fit.Boot=predict(fit,newdata=Data.Orig.Boot,type=response) Boot.Result[b,]=fit.Boot } And try to find 95% confidence interval for 1000 copies of y corresponding to each x. ConfidenceSet.Pointwise=function(Boot.Result,alpha){ n=ncol(Boot.Result) B=nrow(Boot.Result) SetBounds=matrix(ncol=2,nrow=n) for(j in 1:n){ Result.Sort=sort(Boot.Result[,j]) SetBounds[j,1]=Result.Sort[floor(0.5*B*alpha)] SetBounds[j,2]=Result.Sort[ceiling(B*(1-0.5*alpha))] } return(SetBounds) } And then try to line them up. But the result is not what I want. alpha=0.05 Boot.Pointwise=ConfidenceSet.Pointwise(Boot.Result,alpha) lines(Data.Orig[,1],Boot.Pointwise[,1], col=2, lwd=3) Could someone tell where I'm wrong, or is there another better way to do it? Thank you so much! [[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] Changing data frame column headings
Hi, This could be done using ?gsub() set.seed(5) dat1-data.frame(alk_quant=sample(1:15,6,replace=TRUE),ph_quant=sample(5:9,6,replace=TRUE),tds_quant=sample(10:20,6,replace=TRUE)) names(dat1)-gsub((.*)\\_.*,\\1,names(dat1)) head(dat1,2) # alk ph tds #1 4 7 13 #2 11 9 16 A.K. - Original Message - From: Rich Shepard rshep...@appl-ecosys.com To: r-help@r-project.org Cc: Sent: Wednesday, December 5, 2012 4:23 PM Subject: Re: [R] Changing data frame column headings On Wed, 5 Dec 2012, R. Michael Weylandt wrote: Can you be more explicit about your problem? Michael, Data frame contains water chemistry data; site, date, parameter, value. The column names after dcast() are, for example, alk_quant, ph_quant, tds_quant. I wanted to remove the '_quant' from each column header. Using names() with a string vector of the new names did not work, so I specified each one and names() made the changes. Rich __ 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.
Re: [R] data manipulation between vector and matrix
HI, The option z5 takes care of it. z5-t(x-t(mat)) #still faster than ?sweep() dim(z5) [1] 20 2 identical(sweep(-mat,2,x,+),z5) #[1] TRUE A.K. From: C W tmrs...@gmail.com To: arun smartpink...@yahoo.com Sent: Wednesday, December 5, 2012 5:09 PM Subject: Re: [R] data manipulation between vector and matrix Hi Arun, Sorry, I might be a little unclear with my words. The dimensions are different. This is what I got: x-t(mat) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,] 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 [2,] -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 [,15] [,16] [,17] [,18] [,19] [,20] [1,] -14 -15 -16 -17 -18 -19 [2,] -33 -34 -35 -36 -37 -38 sweep(-mat, 2, x, +) [,1] [,2] [1,] 0 -19 [2,] -1 -20 [3,] -2 -21 [4,] -3 -22 [5,] -4 -23 [6,] -5 -24 [7,] -6 -25 [8,] -7 -26 [9,] -8 -27 [10,] -9 -28 [11,] -10 -29 [12,] -11 -30 [13,] -12 -31 [14,] -13 -32 [15,] -14 -33 [16,] -15 -34 [17,] -16 -35 [18,] -17 -36 [19,] -18 -37 [20,] -19 -38 dim(x-t(mat)) [1] 2 20 dim(sweep(-mat, 2, x, +)) [1] 20 2 On Wed, Dec 5, 2012 at 4:55 PM, arun smartpink...@yahoo.com wrote: HI Mike, I didn't understand except the x-t(mat) output is very different than the others. Are you saying that it needs to be transposed? BTW, that was z5. A.K. From: C W tmrs...@gmail.com To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; Sarah Goslee sarah.gos...@gmail.com Sent: Wednesday, December 5, 2012 4:47 PM Subject: Re: [R] data manipulation between vector and matrix Thanks for the benchmark. I actually wanted to go with the winner, except the x-t(mat) output is very different than the others. Mike On Wed, Dec 5, 2012 at 4:40 PM, arun smartpink...@yahoo.com wrote: Hi, By comparing the different methods: set.seed(5) mat1-matrix(sample(1:1e6,1e6,replace=TRUE),ncol=1) set.seed(25) x-sample(1:1e6,1,replace=TRUE) system.time(z1-sweep(-mat1,2,x,+)) # user system elapsed # 0.076 0.000 0.069 system.time(z2-apply(-mat1,1,`+`,x)) # user system elapsed # 0.036 0.000 0.031 system.time(z3-aaply(-mat1,1,`+`,x)) # user system elapsed # 1.880 0.000 1.704 system.time(z4- x-t(mat1)) #winner # user system elapsed # 0.004 0.000 0.007 system.time(z5- t(x-t(mat1))) # user system elapsed # 0.008 0.000 0.009 A.K. From: C W tmrs...@gmail.com To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org; Sarah Goslee sarah.gos...@gmail.com Sent: Wednesday, December 5, 2012 4:11 PM Subject: Re: [R] data manipulation between vector and matrix thanks, I knew about apply, but did not you you can put plus signs with quotes. That's a cool tricky, Mike On Wed, Dec 5, 2012 at 4:05 PM, arun smartpink...@yahoo.com wrote: HI, In addition to ?sweep(), you can use apply(-mat,1,`+`,x) #or library(plyr) aaply(-mat,1,+,x) A.K. - Original Message - From: C W tmrs...@gmail.com To: Sarah Goslee sarah.gos...@gmail.com Cc: r-help r-help@r-project.org Sent: Wednesday, December 5, 2012 1:51 PM Subject: Re: [R] data manipulation between vector and matrix Thanks, Sarah. First time heard about sweep(), it worked just the way I wanted. Mike On Wed, Dec 5, 2012 at 1:42 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W tmrs...@gmail.com wrote: Dear list, I was curious how to subtract a vector from matrix? Say, I have mat - matrix(1:40, nrow=20, ncol=2) x -c(1,2) Thanks for the actual reproducible example. I want, x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements of x against column elements in mat. But x-mat won't do it. This will (note the modification to get x - mat): sweep(-mat, 2, x, +) [,1] [,2] [1,] 0 -19 [2,] -1 -20 [3,] -2 -21 [4,] -3 -22 [5,] -4 -23 etc. -- Sarah Goslee http://www.functionaldiversity.org [[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-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] Assignment of values with different indexes
Hi, Would it be okay to use: y-na.omit(y[myindex]-x) y # [1] -1.36025132 -0.57529211 1.18132359 0.41038489 1.83108252 -0.03563686 #[7] 1.25267314 1.08311857 1.56973422 -0.30752939 A.K. - Original Message - From: Brian Feeny bfe...@mac.com To: r-help@r-project.org help r-help@r-project.org Cc: Sent: Wednesday, December 5, 2012 9:47 PM Subject: [R] Assignment of values with different indexes I would like to take the values of observations and map them to a new index. I am not sure how to accomplish this. The result would look like so: x[1,2,3,4,5,6,7,8,9,10] becomes y[2,4,6,8,10,12,14,16,18,20] The newindex would not necessarily be this sequence, but a sequence I have stored in a vector, so it could be all kinds of values. here is what happens: x - rnorm(10) myindex - seq(from = 1,to = 20, by = 2) y - numeric() y[myindex] - x y [1] -0.03745988 NA -0.09078822 NA 0.92484413 NA 0.32057426 NA [9] 0.01536279 NA 0.02200198 NA 0.37535438 NA 1.46606535 NA [17] 1.44855796 NA -0.05048738 So yes, it maps the values to my new indexes, but I have NA's. The result I want would look like this instead: [1] -0.03745988 [3] -0.09078822 [5] 0.92484413 [7] 0.32057426 [9] 0.01536279 [11] 0.02200198 [13] 0.37535438 [15] 1.46606535 [17] 1.44855796 [19] -0.05048738 and remove the NA's. I tried this with na.omit() on x, but it looks like so: x - rnorm(10) myindex - seq(from = 1,to = 20, by = 2) y - numeric() y[myindex] - na.omit(x) y [1] 0.87399523 NA -0.39908184 NA 0.14583051 NA 0.01850755 NA [9] -0.47413632 NA 0.88410517 NA -1.64939190 NA 0.57650807 NA [17] 0.44016971 NA -0.56313802 Brian __ 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] gamcheck doubts
Dear All, I am fitting scallop count data to negative binomial GAMs. I have two significant parameters that explain 43%of the deviance. The adjusted r square is 0.25. The gam.check function gives me the figure attached. In the graph of linear predictor vs. residuals there seems to be more negative residual values than positive. Is that telling me that the fit is underestimating the response? Can I accept this model? Tania Mendo PhD Candidate | Institute for Marine and Antarctic Studies (IMAS) University of Tasmania __ 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] nlme starting values are not the correct length
Hi see inline -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Lara Reichmann Sent: Wednesday, December 05, 2012 1:53 AM To: r-h...@lists.r-project.org Subject: [R] nlme starting values are not the correct length Dear R community, I am trying to fit an nlme model where I want to estimate the fixed effects of two treatments on the parameters on the following equation Photo~(a*(1-exp(-c*PARi/a)))-b I was able to fit a simple model without covariates following the method described in Mixed-Effects Methods and Classes for S and S-PLUS, version 3.0, but when I add the covariates, I get the error starting values for the fixed component are not the correct length My data has the following structure Subject Species Fert Photo PARi , where several Photo measurements where taken on the same subject by changing PARi, 4 Species levels and 2 Fert levels, there are 31 Subjects (one missing value), and 323 observations DATA extract Subject Species FertPhoto PARi 1 bb 1 22.5389 1499.3307 1 bb 1 21.881 1248.913 1 bb 1 21.2862 999.3387 1 bb 1 20.5836 799.9308 1 bb 1 19.3758 601.1412 1 bb 1 15.5915 399.815 1 bb 1 8.7978 200.1087 1 bb 1 4.4347 99.686 1 bb 1 2.0387 49.7842 1 bb 1 -1.4854 0.0576 2 sw 0 6.782 1500.5337 2 sw 0 7.1432 1249.2749 2 sw 0 7.3319 1000.9891 2 sw 0 7.5848 799.1752 2 sw 0 7.1882 599.5544 2 sw 0 6.809 399.988 2 sw 0 5.3877 198.7574 2 sw 0 3.5104 100.7115 2 sw 0 0.8856 50.7015 2 sw 0 -1.121 0.0569 3 jg 1 16.0827 2000.4941 3 jg 1 16.0236 1501.1957 3 jg 1 16.3818 1248.9551 3 jg 1 16.7815 1499.6414 3 jg 1 17.175 2000.6851 3 jg 1 16.6529 1000.2707 3 jg 1 15.7987 799.676 3 jg 1 15.5437 598.9409 3 jg 1 11.7683 400.7715 3 jg 1 4.89200.7468 3 jg 1 4.1294 100.9664 3 jg 1 1.6008 50.9254 3 jg 1 -0.89 0.5347 4 sw 1 25.2889 2000.1454 4 sw 1 24.7284 1499.6191 4 sw 1 24.3637 1249.7523 4 sw 1 23.3523 1000.0944 4 sw 1 21.6057 800.2209 4 sw 1 18.8926 599.7022 4 sw 1 14.6598 398.9366 4 sw 1 7.7182 201.5697 4 sw 1 3.4775 100.5139 4 sw 1 1.169 49.7045 4 sw 1 -1.3558 1.6914 5 jg 0 6.1626 2000.9351 5 jg 0 7.5573 1499.6581 5 jg 0 7.7129 1249.5073 5 jg 0 7.442 1000.7276 5 jg 0 7.5135 799.1286 5 jg 0 7.1559 599.5568 5 jg 0 6.8161 400.3576 5 jg 0 4.0097 199.7442 5 jg 0 2.7202 101.1253 5 jg 0 1.0746 51.1787 5 jg 0 -0.5913 0.975 This works so far: lightresponse-groupedData(Photo~PARi|Subject,data=lightr,outer = ~ Species * Fert,labels = list(x = PAR, y = CO2 uptake rate),units = list(x = (photon s-1), y = (umol/m?2 s))) Photo.resp- function(PARi,A,B,C)A*(1-exp(-C*PARi/A))-B Photo.resp-deriv ((~A *(1-exp(-C*PARi/A))- B),c(A,B,C),function(PARi,A,B,C){}) lightresp.fit1- nlme(model=Photo~Photo.resp(PARi,A,B,C),fixed=A+B+C~1,d ata=lightresponse,start=c(30,-5,0.1))#fitting nlme without any covariates lightresp.fit1 OUTPUT lightresp.fit1 Nonlinear mixed-effects model fit by maximum likelihood Model: Photo ~ Photo.resp(PARi, A, B, C) Data: lightresponse Log-likelihood: -494.5926 Fixed: A + B + C ~ 1 A B C 24.89334793 1.77983637 0.06499634 Random effects: Formula: list(A ~ 1, B ~ 1, C ~ 1) Level: Subject2 Structure: General positive-definite, Log-Cholesky parametrization StdDev Corr A10.67382785 A B B 0.52572012 1.000 C 0.01433605 0.371 0.384 Residual 0.71900020 Number of Observations: 323 Number of Groups: 31 ##Now, I want to test the effect of Species and Fert, I don't fully understand how to modify the start vector, as I tried several options and no one seems to be correct. Do the number of levels in each factor matter? In that case 4 Species and 2 Fert levels, I would need 6 initial parameters x 3? This didn't work either lightresp.fit2-nlme(model=Photo~Photo.resp(PARi,A,B,C),fixed=A+B+C ~ Species*Fert,random=A+B+C~1,data=lightresponse, start=c(24.89,0,0,0,1.78,0,0,0,0.065,0,0,0)) Error in nlme.formula(model = Photo ~ Photo.resp(PARi, A, B, C), fixed = A + : starting values
Re: [R] What is print print print ?
Yes, now I see. It's ridiculous that I haven't noticed this elementary error, which I know of for over 10 years. :) Now my problem, it's another question. Here is the code and data, as requested. Sample data, I've copied a part of text file: Charge Strobe [1] Charge FC [2] Charge SG [3] Carcass FC [1] Carcass Strobe [2] Carcass SG [3] ChartStrobe [1] ChartFC [2] ChartSG [3] Boy Strobe [1] Boy FC [2] Boy SG [3] Wires Strobe [1] Wires SG [2] Wires FC [3] Now I read them and make last column numeric: votes-read.table(comparison.txt, col.names=c(Object, Method, Vote)) votes$Rank - as.numeric(votes$Vote) Now I want to see for each method how many it has first, second and last places: for(m in levels(votes$Metod)) { print(c(m, hist(votes[with(votes, Method == m), Rank], breaks=0:3, plot=FALSE)$counts)) } Oups... And now I've found my error, thanks to Opera's spell checker. I have missed the letter 'h' in Method. -- Best regards, Vladimirmailto:wl2...@gmail.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] Incorrect DST time changes in DateTimeClasses
Can anyone please shed any light on why R DateTimeClasses give weird times for when daylight saving time information changes, and which aren't consistent with the OS? Example: Expected result: in New Zealand DST stopped (NZDT - NZST) at 03:00 NZDT on 2010-04-04, as confirmed by the OS time zone info (OS X 10.8.2): zdump -v /etc/localtime /etc/localtime Sat Apr 3 13:59:59 2010 UTC = Sun Apr 4 02:59:59 2010 NZDT isdst=1 /etc/localtime Sat Apr 3 14:00:00 2010 UTC = Sun Apr 4 02:00:00 2010 NZST isdst=0 Result in R: R has DST changing at 02:26:08, instead of 03:00! a-as.POSIXlt('2010-04-04 02:26:07',tz=NZ) a$isdst [1] 1 b-as.POSIXlt('2010-04-04 02:26:08',tz=NZ) b$isdst [1] 0 So does R get its DST information from somewhere else? Any suggestions would be much appreciated! Thanks [[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.