Re: [R] Learning R - View datasets
guohao.hu...@gmail.com wrote: Please check the following pdf file. http://tw.nextmedia.com/applenews/article/art_id/32119622/IssueID/20091127 Besides a beautiful blond girl, I do not recognize any pdf here... Could you provide a direct link? Thanks! mario 1. First install.packages(Flury) 2. library(Flury) 3. data(wines) 'wines’ is a data frame with 26 observations, one factor denoting the country of origin and 15 quantitative variables denoting 15 free monoterpenes and C[13]-norisoprenoids. It is thought these influence the wine’s aroma. Country a factor with levels South Africa Germany Italy Y1 a numeric vector Y2 a numeric vector Y3 a numeric vector Y4 a numeric vector Y5 a numeric vector Y6 a numeric vector Y7 a numeric vector Y8 a numeric vector Y9 a numeric vector Y10 a numeric vector Y11 a numeric vector Y12 a numeric vector Y13 a numeric vector Y14 a numeric vector Y15 a numeric vector If you do not know how to get these value, you can read ``R introduction''. I hope this can help you. Guo-Hao Huang -- From: Brock Tibert btibe...@yahoo.com Sent: Friday, November 27, 2009 12:46 PM To: r-help@r-project.org Subject: [R] Learning R - View datasets Hi All, I am making a serious effort to try to learn R, but one hurdle I am facing is that I need to see the data as I walk through the examples in the packages. For instance, many examples on the web start by a command like data(wines). How can I actually view what the dataset looks like prior to transformations and analysis? I have tried to use edit() , print, and head. In short, I know that data() lists all of the available datasets, data(wines) will load the dataset wines, but how can I look at the raw data? I figure this is probably an easy question, but any help you can provide will be greatly appreciated. Thanks, Brock __ 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. -- Ing. Mario Valle Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82 __ 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] Overlapping x - axis lables
On Thu, 26-Nov-2009 at 11:03PM -0800, Julia Cains wrote: | Dear Sir, | | Thanks again for your help. Sir, actually I am working on a data containing 84 months and the corresponding savings (core) balances and non-core balances and I am plotting a stacked bar. | | The original code I am using is as follows | | x = read.csv('core-noncore.csv') | | x2 - data.frame(rep(x$month, 2), stack(x, select = -month))?? | names(x2) - c('month', 'Count', 'Type') | library(lattice) | barchart(Count ~ month, groups = Type, data =x2, horizontal = FALSE, stack =TRUE, auto.key = list(columns = 2))?? # stacked? vertical bar chart | | However, when I try to apply the code given by you, its showing the error | plot.new has not been called yet | | Sir, is it that the command works only with plot command and not | with barchart. More or less: more accurately, it works with base graphics, not with lattice graphics. If you wish to use lattice, you can make similar customizations using the scales list. Look through the help for xyplot, and search for scales. If you know how to make lists, you can use the same ideas that the axis() function uses to customize the axes. HTH | Warm regards | | Julia | | | | | | | Only a man of Worth sees Worth in other men | | | | | | --- On Fri, 11/27/09, Dennis Murphy djmu...@gmail.com wrote: | | From: Dennis Murphy djmu...@gmail.com | Subject: Re: [R] Overlapping x - axis lables | | Date: Friday, November 27, 2009, 6:36 AM | | Hi Julia: | | Two things: | ? (i) use axes = FALSE in your initial call to plot(); | ? (ii) use axis(1, at = 10 * (0:10))?? if you want it by tens, for example | ??? axis(2)? # use default | ??? box() # if you want a box around the plot. | | ?axis is your friend here. | | HTH, | Dennis | | | | Dear R helpers | | | | Suppose I am plotting a simple scatter plot where no of paired observations (x,y) are say 100. | | | | | | month ? ? length | | 1??? ? ? ? ? ?? 10 | | 2 ? ? ? ? ? 12 | | 3?? 17 | | 4??? ?? 21 | | 5?? 13 | | .. | | .. | | .. | | | | 100? 16 | | | | | | | | when i run the command | | | | plot(month, length) | | | | the required plot is generated. But the problem is that on? the X - axis, month values are also printed and it becomes difficult to read the month values on the graph. | | ? | | (Actually I am working on a stacked graph where I am facing this problem..) | | | | So, how to display only few month values (say 1, 5, 10 and so on) without affecting the original graph i.e. the graph should display all the data 100 points but on x - axix only few month values should be displayed in order to improve the readability. | | | | | Thanking in advance | | | | Julia | | | | | | | | | | | | | | | | | | Only a man of Worth sees Worth in other men | | | | | | | | | | | | | | | | ? ? ? ?[[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. -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ 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] Learning R - View datasets
Sorry, the correct link is the following http://cran.r-project.org/web/packages/Flury/Flury.pdf Guo-Hao, Huang -- From: Mario Valle mva...@cscs.ch Sent: Friday, November 27, 2009 4:00 PM To: guohao.hu...@gmail.com Cc: Brock Tibert btibe...@yahoo.com; r-help@r-project.org Subject: Re: [R] Learning R - View datasets guohao.hu...@gmail.com wrote: Please check the following pdf file. http://tw.nextmedia.com/applenews/article/art_id/32119622/IssueID/20091127 Besides a beautiful blond girl, I do not recognize any pdf here... Could you provide a direct link? Thanks! mario 1. First install.packages(Flury) 2. library(Flury) 3. data(wines) 'wines’ is a data frame with 26 observations, one factor denoting the country of origin and 15 quantitative variables denoting 15 free monoterpenes and C[13]-norisoprenoids. It is thought these influence the wine’s aroma. Country a factor with levels South Africa Germany Italy Y1 a numeric vector Y2 a numeric vector Y3 a numeric vector Y4 a numeric vector Y5 a numeric vector Y6 a numeric vector Y7 a numeric vector Y8 a numeric vector Y9 a numeric vector Y10 a numeric vector Y11 a numeric vector Y12 a numeric vector Y13 a numeric vector Y14 a numeric vector Y15 a numeric vector If you do not know how to get these value, you can read ``R introduction''. I hope this can help you. Guo-Hao Huang -- From: Brock Tibert btibe...@yahoo.com Sent: Friday, November 27, 2009 12:46 PM To: r-help@r-project.org Subject: [R] Learning R - View datasets Hi All, I am making a serious effort to try to learn R, but one hurdle I am facing is that I need to see the data as I walk through the examples in the packages. For instance, many examples on the web start by a command like data(wines). How can I actually view what the dataset looks like prior to transformations and analysis? I have tried to use edit() , print, and head. In short, I know that data() lists all of the available datasets, data(wines) will load the dataset wines, but how can I look at the raw data? I figure this is probably an easy question, but any help you can provide will be greatly appreciated. Thanks, Brock __ 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. -- Ing. Mario Valle Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82 __ 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] Learning R - View datasets
There are different ways to inspect the conent of a data frame. For example, View(CO2) 2009/11/27 Brock Tibert btibe...@yahoo.com: Hi All, I am making a serious effort to try to learn R, but one hurdle I am facing is that I need to see the data as I walk through the examples in the packages. For instance, many examples on the web start by a command like data(wines). How can I actually view what the dataset looks like prior to transformations and analysis? I have tried to use edit() , print, and head. In short, I know that data() lists all of the available datasets, data(wines) will load the dataset wines, but how can I look at the raw data? I figure this is probably an easy question, but any help you can provide will be greatly appreciated. Thanks, Brock __ 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. -- Wincent Ronggui HUANG Doctoral Candidate Dept of Public and Social Administration City University of Hong Kong http://asrr.r-forge.r-project.org/rghuang.html __ 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 compute Rolling analysis of Standard Deviation using ZOO package?
On Fri, 27 Nov 2009 15:19:11 +0800 Saji Ren saji@gmail.com wrote: I want to get a rolling estimation of the stdev of my data. There is a 'runsd' in the 'caTools' package which does exactly this. -- Karl Ove Hufthammer __ 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] Learning R - View datasets
Brock Tibert wrote: Hi All, I am making a serious effort to try to learn R, but one hurdle I am facing is that I need to see the data as I walk through the examples in the packages. For instance, many examples on the web start by a command like data(wines). How can I actually view what the dataset looks like prior to transformations and analysis? I have tried to use edit() , print, and head. In short, I know that data() lists all of the available datasets, data(wines) will load the dataset wines, but how can I look at the raw data? I figure this is probably an easy question, but any help you can provide will be greatly appreciated. Thanks, Brock __ 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. Hi Brock, Take a look at the summary() function and the str() function. Also try and type the name of the dataset or use plot() on it. data(cars) summary(cars) str(cars) cars plot(cars) Have you read the Introduction to R [1]? cheers, Paul [1] http://cran.r-project.org/doc/manuals/R-intro.pdf -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul __ 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] Best way to preallocate numeric NA array?
Hi There is one issue which I encountered recently with this type of behaviour, mat-matrix(NA,5,4) fix(mat) put some number in any cell and close fix mat col1 col2 col3 col4 [1,] NA NA NA NA [2,] NA NA NA NA [3,] NA NA NA NA [4,] NA NA NA NA [5,] NA NA NA NA No value is put into mat. There is easy workaround, but it can be frustrating if somebody tries to find why the value is not inputed. I know that it is not preferred way to fill a matrix but if you have such small matrix and it has only few non NA values this could be used. Maybe on help page could be some kind of explanation: Fix can not convert a type(mode) of its argument and therefore it is possible to input only values which match type of x. or something like that Regards Petr r-help-boun...@r-project.org napsal dne 26.11.2009 17:22:45: On Thu, Nov 26, 2009 at 10:03 AM, Rob Steele freenx.10.robste...@xoxy.net wrote: These are the ways that occur to me. ## This produces a logical vector, which will get converted to a numeric ## vector the first time a number is assigned to it. That seems ## wasteful. x - rep(NA, n) ## This does the conversion ahead of time but it's still creating a ## logical vector first, which seems wasteful. x - as.numeric(rep(NA, n)) ## This avoids type conversion but still involves two assignments for ## each element in the vector. x - numeric(n) x[] - NA ## This seems reasonable. x - rep(as.numeric(NA), n) Comments? My intuition would be to go with the third method (allocate a numeric vector then assign NA to its contents) but I haven't tested the different. In fact, it would be difficult to see differences in, for example, execution time unless n was very large. This brings up a different question which is, why do you want to consider this? Are you striving for readability, for speed, for low memory footprint, for efficiency in some other way? When we were programming in S on machines with 1 mips processors and a couple of megabytes of memory, such considerations were important. I'm not sure they are quite as important now. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] Comparing membership of clusters
Hello, I'm taking several physiological measurements on participants (e.g., skin conductivity, heart rate, etc.). I know that those participants belong to one of three groups (from another measurement), and I'm looking to find the physiological measurement that best describes group membership. The measurements are taken over several days and I computed an lm() for each participant for each measurement and used the regression coefficient as input for a hclust(). After cutree(x, k=3), I have a matrix with in columns group indices for each measurement. Now I need to assess which column is most similar to my gold standard. Q1: how to easiest and best abstract away from group labeling (because that's arbitrary, see below)? Q2: is there a statistic to compute level of similarity (other than tallying)? So I have (after the cutree) res - matrix(c(1,1,1,2,1,3,2,1,1,1,2,1,1,3,1,3,3,3,1,2,1,1,1,2,1,3,1,1,2,2,2,1,3,1,2,2,1, 1,1,2,2,3,1,1,1,1,2,1,2,1,2,3,2,1,1,2,3,2,2,1,2,2,1,1,1,1,2,1,3,1,1,2,1,2, 2,1,2,1,2,1,3,1,2,2,3,1,2,1,2,2,1,1,1,1,1,2,3,3,1,1,1,1,1,1,1,2,3,3,1,1,2, 1,1,3,2,2,2), nrow=9) colnames(res) - LETTERS[1:13] which has the cluster assignments for each measurement in the columns. My gold standard is gold - c(1, 1, 2, 2, 3, 3, 1, 2, 3) Now for each column in res, I want to see how similar it is to gold. Note that exact matching on number identity is not correct, because the gold standard could also be expressed as c(a, a, b, b, c, c, a, b, c), or even c(3, 3, 1, 1, 2, 2, 3, 1, 2). So the fact that participant (index) 1, 2, and 8 belong to each other is key. I am most puzzled about how to do the matching / find the similarity between each column and gold standard. Thank you for your time! best regards, Paul Lemmens __ 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] multicore: defunct R processes left
Dear All, At least in three different GNU/Linux systems, the parallel function from the multicore package leaves defunct (zombie) R processes. For instance library(multicore) parallel(1:5) collect() After collect, the child process (with pid as given by collect) is left defunct. (If we run the last two lines of code again, the previously defunct process will be replaced by the new defunct process). Is this to be expected? The documentation for 'collect' says it collects results from parallel processes (and I thought it also read the exit status of the child). Best, R. *** packageDescription(multicore)$Version [1] 0.1-3 version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status Patched major 2 minor 10.0 year 2009 month 11 day05 svn rev50317 language R version.string R version 2.10.0 Patched (2009-11-05 r50317) -- Ramon Diaz-Uriarte Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz Phone: +34-91-732-8000 ext. 3019 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Question about S4
I'm curious about why no one has answered my question below. I can't imagine it would be because no one knows how to answer, it must be something basic I am ignorant about. But I have never seen such a pattern, it seems strange to me that a class with an empty definition is automatically virtual, but a class extending it without adding anything is not. I am really puzzled, there must be some design decision behind this, but I can't figure out it's purpose and usefulness. I'd really appreciate an explanation. Thank you. -- Hun Dear R-ers, I don't understand the following, maybe someone will help me explain: setClasss('A') [1] A new('a') Error in new(a) : trying to generate an object from a virtual class (a) setClass('b', contains='a') [1] b new('b') An object of class “b” S4 Type Object In what way is B more concrete than A so that it's possible do instantiate B but not A? I don't quite get it. B adds nothing to nothing, and yet it's instantiable, while it's base is not. Makes no sense to me. -- Hun __ 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 compute Rolling analysis of Standard Deviation using ZOO package?
We will need a minimal reproducible example (as per last line on every message to r-help) to answer as trying it with made up data seems to work for me. If c is very long try cutting it down to the smallest you can get it to and still produce the error, e.g. cc - c[1:10] rollapply(cc, ...) and then post the output of dput(cc) Here is an example: library(zoo) c - zoo(1:100) rollapply(c, 10, sd, na.pad = TRUE, align = 'right') 123456 NA NA NA NA NA NA 789 10 11 12 NA NA NA 3.027650 3.027650 3.027650 13 14 15 16 17 18 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 19 20 21 22 23 24 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 25 26 27 28 29 30 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 31 32 33 34 35 36 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 37 38 39 40 41 42 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 43 44 45 46 47 48 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 49 50 51 52 53 54 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 55 56 57 58 59 60 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 61 62 63 64 65 66 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 67 68 69 70 71 72 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 73 74 75 76 77 78 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 79 80 81 82 83 84 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 85 86 87 88 89 90 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 91 92 93 94 95 96 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 97 98 99 100 3.027650 3.027650 3.027650 3.027650 R.version.string [1] R version 2.10.0 Patched (2009-11-21 r50532) packageDescription(zoo)$Version [1] 1.6-2 On Fri, Nov 27, 2009 at 2:19 AM, Saji Ren saji@gmail.com wrote: Hello: I want to get a rolling estimation of the stdev of my data. Searching the document, I found the function rollapply in the zoo package. For example, my series is c, and i want get a period of 10 days, so i write the command below: roll.sd = rollapply( c, 10, sd, na.pad = TRUE, align = 'right' ) but there is an error in it ,and the computing cannot be performed. Can anyone help? PLUS: I also found that there is a function called rollFun in package 'fSeries', but there isn't anymore. [[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.
[R] VAR forecasts and out-of-sample prediction
Dear users, I am struggling with this issue. I want to estimate a VAR(1) for three variables, say beta1 beta2 beta3, using monthly observations from January 1984 to September 2009. In-sample period January 1984 to December 2003, out-of-sample January 2004 to September 2009. This is what I have done at the moment betas-read.table(C:\\Users\\Manta\\Desktop\\betas.txt,header=T,dec=,) BETA-ts(betas,start=(1984),frequency=12) BETAS-TSdata(output=BETA) VAR1-estVARXls(window(BETAS,end=c(2003,12)),max.lag=1) pr-forecast(VAR1,horizon=1) pr3-forecast(VAR1,horizon=3) pr12-forecast(VAR1,horizon=12) and the model is estimated correctly (same estimates as found using other softwares) Then the tricky part: I want to estimate the betas for January 2004, March 2004 and January 2005 (that is, 1-3-12 months horizon). BUT, when estimating March 2004, I just want March 2004, and not also again January 2004 and February 2004. Same thing for January 2005. I tried to use the function horizonForecasts but it seems not working properly. Then, I want to compare the forecasts with the actual betas in order to get RMSE and MAE. So I tried the following: betas[241,]-pr$forecast error BETA[241,]-pr$forecast non-numeric argument to binary operator BETAS[241,]-pr$forecast incorrect number of dimensions So, I do not know how to solve this. This computation then needs to be put in a loop, with expanding (or rolling, that's not a big issue), so then I will compare betas forecasts for February 2004 (April 2004 and February 2005) with the actual data and so on. Thanks in advance! -- View this message in context: http://old.nabble.com/VAR-forecasts-and-out-of-sample-prediction-tp26540692p26540692.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] GAM plots
Are you using mgcv:::gam? To get plot data suitable for making plots of smooth effects, you probably need to use `predict.gam' to evaluate the smooth curves (and standard errors) at a nice regular set of points for plotting. Also don't forget that the residuals shown on plot.gam are the `partial residuals' (i.e. the residuals + the smooth concerned). best, Simon On Sunday 22 November 2009 01:09, Joe Trubisz wrote: Hello all... I'm attempting to write my own GAM plot function, so I can overlay it on top of an already existing plot. Problem is that after I do the gam, e.g. m-gam(...), I cannot match the graph that gam.plot outputs when I attempt to plot the values from m$residuals, m$linear.predictors or m$fitted.values. Kind of at a loss what variables to use or if I need to do something else before I attempt to plot them. Can someone explain to me where I'm going wrong and what I need to do to correct this? Thanks, Joe __ 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. -- Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK +44 1225 386603 www.maths.bath.ac.uk/~sw283 __ 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] Learning R - View datasets
Hello On Fri, Nov 27, 2009 at 4:46 AM, Brock Tibert btibe...@yahoo.com wrote: In short, I know that data() lists all of the available datasets, data(wines) will load the dataset wines, but how can I look at the raw data? See this [1]. [1] http://www.mail-archive.com/r-help@r-project.org/msg66111.html Liviu __ 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] layers in xYplot of Hmisc
do you mind me asking what code you used to create that data frame and name the groups 1 and 2? David Winsemius wrote: On Nov 26, 2009, at 10:26 PM, Joe King wrote: In the filled bands part of xYplot of the Hmisc package, is there a way to have multiple bands with multiple lines? or does it just allow one for now? No problem as long as you use groups... which means you probably ought to be providing a dataframe format with a grouping factor. (At least that was how I read the help page saying that: - Details Unlike xyplot, xYplot senses the presence of a groups variable and automatically invokes panel.superpose instead of panel.xyplot. The same is true for Dotplot vs. dotplot. - I would give it a dataset that does not have lines coincident if you want to see them. (You should also get rid of that space in your color parameter. dfci - structure(list(x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5), y = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4.5, 4, 3.5, 3, 2.5, 2, 1.5, 1), ciupper = c(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 11, 5.5, 4.95, 4.4, 3.85, 3.3, 2.75, 2.2, 1.65, 1.1), cilower = c(0.9, 1.8, 2.7, 3.6, 4.5, 5.4, 6.3, 7.2, 8.1, 9, 4.5, 4.05, 3.6, 3.15, 2.7, 2.25, 1.8, 1.35, 0.9), grp = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(1, 2), class = factor)), .Names = c(x, y, ciupper, cilower, grp), row.names = c(NA, -19L), class = data.frame) xYplot(Cbind(y,cilower,ciupper)~x, groups=grp, data=dfci, method=filled bands,col.fill=lightgrey, type=c(b)) -- David So I had an example bit ago had a made up line and CI, now if I wanted to make a second line with a CI filled in can I put them on the same plot? x-seq(1,10,1) y-seq(1,10,1) ci-y*.10 ciupper-y+ci cilower-y-ci xYplot(Cbind(y,cilower,ciupper)~x, method=filled bands, col.fill=light grey, type=c(b)) x2-seq(1,5,.5) y2-seq(1,5,.5) ci2-y2*.10 ciupper2-y2+ci2 cilower2-y2-ci2 xYplot(Cbind(y2,cilower2,ciupper2)~x2, method=filled bands,col.fill=light grey, type=c(b)) --- Joe King, M.A. Ph.D. Student University of Washington - Seattle 206-913-2912 j...@joepking.com --- Never throughout history has a man who lived a life of ease left a name worth remembering. --Theodore Roosevelt [[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 Heritage Laboratories West Hartford, CT __ 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. -- View this message in context: http://old.nabble.com/layers-in-xYplot-of-Hmisc-tp26537542p26541016.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Learning R - View datasets
Try this: # each of these three show entire data set wines dput(wines) View(wines) # get help ?wines # various info on data set head(wines) tail(wines) summary(wines) str(wines) class(wines) dim(wines) # plotting plot(wines) # for a better plot see the example at the bottom of ?wines On Thu, Nov 26, 2009 at 11:46 PM, Brock Tibert btibe...@yahoo.com wrote: Hi All, I am making a serious effort to try to learn R, but one hurdle I am facing is that I need to see the data as I walk through the examples in the packages. For instance, many examples on the web start by a command like data(wines). How can I actually view what the dataset looks like prior to transformations and analysis? I have tried to use edit() , print, and head. In short, I know that data() lists all of the available datasets, data(wines) will load the dataset wines, but how can I look at the raw data? I figure this is probably an easy question, but any help you can provide will be greatly appreciated. Thanks, Brock __ 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] generating a matrix after a for loop..
Hi all, I have to ask this and I know that the reason is that I am a newbie with R programming. So apologize if it is too obvious but I didn't find an answer after googling and reading An introduction to R. So i have return data from 30 instruments and I am fitting a mixture of normal distributions for the asymmetric marginal distributions and then simulating from those distributions. For this I have tried to build a function as below mclustSim - function(x){ library(mclust) nr=dim(x)[1] nc=dim(x)[2] NumberOfSim=100 for (i in 1:nc){ y-Mclust(as.matrix(x[,i])) z-sim(modelName=y$modelName,parameters=y$parameters,n=NumberOfSim) #print(c(colnames(x[i]),z[,2]),digits=3) } } z is the simulated return series. How can I say: print z next to previous z and form a matrix How could I get an matrix as a result..? So that I would have simulations from asset1 distribution at first column, simulation from asset2 at second column etc. And the result would be NumberOfSim X Ncol matrix.. Thanks for any help Br, John [[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] Learning R - View datasets
Hi Brock, Have you tried View() ? Regards. On Fri, Nov 27, 2009 at 7:46 AM, Brock Tibert btibe...@yahoo.com wrote: Hi All, I am making a serious effort to try to learn R, but one hurdle I am facing is that I need to see the data as I walk through the examples in the packages. For instance, many examples on the web start by a command like data(wines). How can I actually view what the dataset looks like prior to transformations and analysis? I have tried to use edit() , print, and head. In short, I know that data() lists all of the available datasets, data(wines) will load the dataset wines, but how can I look at the raw data? I figure this is probably an easy question, but any help you can provide will be greatly appreciated. Thanks, Brock __ 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. -- Ojal John Owino P.O Box 230-80108 Kilifi, Kenya. Mobile:+254 728 095 710 [[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] If condition using accessors
Hi, I'm quite new using R and have got no one to help me get through it. Hopefully someone can help me with one problem I've been struggling with for the last hours!! (Sorry if I'm using the wrong terminology as well!) I have a data matrix in which SIE is one of my variables. What I need to do now is to create a new variable (group) if a certain condition in SIE is met. I tried: if (data2$SIE 50.646){ data2$group=as.factor(small) } which gives me In if (data2$SIE 50.646) { : the condition has length 1 and only the first element will be used and ifelse (data2$SIE 50.64593, data2$group = as.factor(small),data2$group = as.factor(large)) with Error: unexpected '=' in ifelse (data2$SIE 50.64593, data2$group = I tried all other kinds of variations and so far, nothing!! Is there a good way to do this that someone could teach me? Thank you so much, Vitória __ 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] R help with princomp and pam clustering
Hi JorisMeys and thanks! JorisMeys wrote: On Thu, Nov 26, 2009 at 1:04 AM, Tyler82 procaccianti.clau...@gmail.com wrote: Hi all! I am working with R package cluster and I have a little problem: let's say I have two datasets...first one (A) is divided into 4 clusters by means of Pam algorythm. Let's say I want to project the second database (B) onto the Comp.1 X Comp.2 graph, and see where its elements are placed. The two datasets are made of different dim (54x19 and 28x19). I tried to extract the $loadings of the A clustering but I can't seem to figure out how to use them with B :( Prin - princomp(A) predict(Prin,B) in the assumption that the variable names in both dataframes are equal. A and B are equal in column names (variables) but different in rownames (observations), but still it doesn't work. If I use A-princomp(matrix, cor=ncol(pamX$data)!=2)$loadings and then predict(A,B) then the answer is that there is no valid method (My R version is in Italian...the original message is -Errore in UseMethod(predict) : nessun metodo applicabile per predict- ) If I use A-princomp(matrix, cor=ncol(pamX$data)!=2) then it says the index is out of limit Thank you again!! -- View this message in context: http://old.nabble.com/R-help-with-princomp-and-pam-clustering-tp26522485p26539667.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Arguments
hello,I would like to ask a question,Is there any way to pass arguments to a script?I have this code: Invernadero-read.table(file.choose(),header=T,sep=,) attach(Invernadero) names(Invernadero) Invernadero-ts(Invernadero-argument) //Here introduce the argument plot(Hora,Invernadero,main=arguemtn,xlab=Tiempo,ylab=argument) Thanks for your attention,I hope your answers. Cheers, Ignacio. -- View this message in context: http://old.nabble.com/Arguments-tp26539736p26539736.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Arguments
See ?commandArgs Also the getopt and optparse CRAN packages. On Fri, Nov 27, 2009 at 4:20 AM, yonosoyelmejor yonosoyelme...@hotmail.com wrote: hello,I would like to ask a question,Is there any way to pass arguments to a script?I have this code: Invernadero-read.table(file.choose(),header=T,sep=,) attach(Invernadero) names(Invernadero) Invernadero-ts(Invernadero-argument) //Here introduce the argument plot(Hora,Invernadero,main=arguemtn,xlab=Tiempo,ylab=argument) Thanks for your attention,I hope your answers. Cheers, Ignacio. -- View this message in context: http://old.nabble.com/Arguments-tp26539736p26539736.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] lattice --- different properties of lines corresponding to type=c(l, a) respectively
On Fri, Nov 27, 2009 at 1:13 AM, Kjetil Halvorsen kjetilbrinchmannhalvor...@gmail.com wrote: I think the subject says it all. I want to make a simple lattice plot, using xyplot with the argument type=c(l,a). The problem then is that in the resulting plot it is difficult/impossible to see which plot corresponds to the average and which to the individual profiles. I triedthings like extra arguments lwd=c(1,3) or col=c(blue,red) hoping this would be interpreteded parallely to the type= argument, but no. Like: xyplot(response ~ time|group, repa0, groups=~Participant, type=c(b, a), lwd=c(1, 3), ylim=c(0, 10)) Are you looking for per-group average or overall average? All your attempts will do per-group average, which is rather pointless here. For a global average you need to call panel.average with all the data, not through panel.superpose: mypanel - function(x, y, ..., groups, type){ panel.xyplot(x, y, ..., groups = groups, type=type) panel.average(x, y, horizontal = FALSE, col = black, lwd = 3) } xyplot(response ~ time|group, repa0, groups=~Participant, type=l, ylim=c(0, 10), panel=mypanel) -Deepayan and many other variants ... Then I vent for writing my own panel functions: mypanel - function(x, y, ..., type){ panel.average(x, y, ..., horizontal=FALSE) panel.xyplot(x, y, ..., type=type) } xyplot(response ~ time|group, repa0, groups=~Participant, type=l, ylim=c(0, 10), panel=panel.superpose, panel.groups=mypanel) (which doesn't work) ??? Kjetil Halvorsen To recreate the data: repa0 - structure(list(group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(1, 2), class = factor), Participant = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L), time = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), response = c(2L, 10L, 8L, 4L, 0L, 4L, 10L, 2L, 3L, 4L, 1L, 2L, 3L, 3L, 5L, 2L, 10L, 3L, 0L, 3L, 10L, 1L, 7L, 3L, 2L, 10L, 8L, 5L, 8L, 0L, 10L, 2L, 0L, 2L, 10L, 10L, 3L, 2L, 10L, 4L, 6L, 0L, 5L, 0L, 6L, 2L, 0L, 2L, 10L, 5L, 3L, 2L, 6L, 4L, 5L, 0L, 5L, 0L, 5L, 0L, 0L, 0L, 10L, 0L, 0L, 2L, 5L, 0L, 5L, 0L, 3L, 8L, 6L, 1L, 3L, 0L, 5L, 4L, 10L, 0L, 3L, 3L, 6L, 5L, 2L, 0L, 2L, 0L, 4L, 0L, 5L, 4L, 5L, 1L, 0L, 2L, 0L, 5L, 3L, 1L, 8L, 2L, 4L, 0L, 0L, 0L, 10L, 4L, 3L, 0L, 0L, 10L, 3L, 3L, 6L, 1L, 4L, 0L, 0L, 0L, 10L, 3L, 3L, 2L, 2L, 10L, 2L, 3L, 5L, 0L, 1L, 0L, 0L, 0L, 10L, 2L, 3L, 2L, 0L, 6L)), .Names = c(group, Participant, time, response), row.names = c(1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9.1, 10.1, 11.1, 12.1, 13.1, 14.1, 1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2, 8.2, 9.2, 10.2, 11.2, 12.2, 13.2, 14.2, 1.3, 2.3, 3.3, 4.3, 5.3, 6.3, 7.3, 8.3, 9.3, 10.3, 11.3, 12.3, 13.3, 14.3, 1.4, 2.4, 3.4, 4.4, 5.4, 6.4, 7.4, 8.4, 9.4, 10.4, 11.4, 12.4, 13.4, 14.4, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 1.11, 2.11, 3.11, 4.11, 5.11, 6.11, 7.11, 8.11, 9.11, 10.11, 11.11, 12.11, 13.11, 14.11, 1.21, 2.21, 3.21, 4.21, 5.21, 6.21, 7.21, 8.21, 9.21, 10.21, 11.21, 12.21, 13.21, 14.21, 1.31, 2.31, 3.31, 4.31, 5.31, 6.31, 7.31, 8.31, 9.31, 10.31, 11.31, 12.31, 13.31, 14.31, 1.41, 2.41, 3.41, 4.41, 5.41, 6.41, 7.41, 8.41, 9.41, 10.41, 11.41, 12.41, 13.41, 14.41, 1.51, 2.51, 3.51, 4.51, 5.51,
Re: [R] order of panels in xyplots
On Thu, Nov 26, 2009 at 12:09 AM, Titus Malsburg malsb...@gmail.com wrote: The documentation of xyplot could be improved here. It says: If 'index.cond' is a list, it has to be as long as the number of conditioning variables, and the 'i'-th component has to be a valid indexing vector for the integer vector '1:nlevels(g_i)' (which can, among other things, repeat some of the levels or drop some altogether). It should make explicit that nlevels is the number of levels actually used in the data and not length(levels(f)). Actually, it should say that whether unused levels are counted depends on the value of the 'drop.unused.levels' argument. I will update the documentation. -Deepayan __ 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] Concave hull
Thanks for the interesting reference to alphahull. It might be a good starting point for placing e.g. a legend in a plot (I think the usual techniques for this (gregmisc?) are a bit more brute-force.) baptiste 2009/11/27 Kjetil Halvorsen kjetilbrinchmannhalvor...@gmail.com: There is a package on CRAN implementing such an idea: alphahull, phull is other package, kjetil On Thu, Nov 26, 2009 at 6:11 PM, baptiste auguie baptiste.aug...@googlemail.com wrote: 2009/11/26 Ted Harding ted.hard...@manchester.ac.uk: Raising a rather general question here. This is a tantalising discussion, but the notion of concave hull strikes me as extremely ill-defined! I'd like to see statement of what it is (generically) supposed to be. I'm curious too, but I can imagine the following definition, Consider a sphere (n-dimensional maybe) that we let come in contact with the scatter of points from outside. The set of points that the sphere can attain may define unambiguously (I think) a concave hull, for a specified sphere radius. The convex hull is obtained in the limit of infinite radius (plane). It's probably not exactly this, but I guess that's the rough idea. Just a thought, baptiste __ 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] Adding text in the panels for Trellis plot ...
On Thu, Nov 26, 2009 at 6:22 AM, ychu066 ychu...@aucklanduni.ac.nz wrote: i was trying to do a for loop for plotting the histograms , but it doesnt work properly library(lattice) columns - 8:153 plots - vector(list, length(columns)) j - 0 for (i in columns) + { + plots[[ j - j+1 ]] - histogram( ~ data[,i] | data[,2],ylab = Frequency, + xlab = Score, xlim = c(1,5), ylim = c(0,100),layout=c(3,1), + main = c(colnames(data)[i],index,j+1),mycolors = colors()[c(536,552,652,254,26)], + panel = function(..., col, mycolors) { + panel.histogram(..., col = mycolors[panel.number()])}) + trellis.focus('strip', 1, 1, highlight=FALSE) + ltext(0.60, -0.25, 'PPM', col='blue', pos=3) + trellis.unfocus() + } Error in grid.Call.graphics(L_downviewport, name$name, strict) : Viewport 'plot1.strip.1.1.vp' was not found print(plots[[1]]) I am not sure what was happeneing. . . can anyone help me ? Panel functions are for controlling the panel display. If you want to control the strip, use the 'strip' argument to provide a custom strip function. -Deepayan __ 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] barchart() {Lattice} help.
On Fri, Nov 27, 2009 at 9:21 AM, Peng Cai pengcaimaill...@gmail.com wrote: @ Peter: I got it, thanks a lot for all your help! And yes, as you said the title option in auto.key is redundant. @ All, Hi: I need to add percentage sign to y-axis labels (like 0%, 20%, ..., 100%). How can I get it. I'm using barchart() function as given below along with the data set. Read ?barchart, specifically the entry for 'scales'. Hint: figure out what the line scales = list(y = list(at = myYscale)), does. -Deepayan Data: Sample Col1 Col2 Col3 Row1 -20 40 -10 Row2 30 -20 40 Row3 30 10 -20 Row4 20 20 -10 R code: library(lattice) dta-read.table(data.txt, header=TRUE, row.names=Sample) myYscale - seq(-140,140,20) barchart(data.matrix(dta), horizontal=FALSE, stack=TRUE, par.settings = simpleTheme(col = c(2:4)), auto.key=list(space = 'right', rows = 3, rectangles = TRUE, points = FALSE ), scales = list(y = list(at = myYscale)), panel=function(x,y,...){ panel.abline(h=c(myYscale), col.line=gray) panel.barchart(x,y,...)} ) Any help would be greatly appreciated, Peng On Thu, Nov 26, 2009 at 10:38 PM, P Ehlers ehl...@ucalgary.ca wrote: As I wrote earlier: I had to add the rectangles= and points= arguments to auto.key to get the same key as you had earlier. and the relevant line in the code was: auto.key = list(space = 'right', rectangles=TRUE, points=FALSE) -Peter Ehlers Peng Cai wrote: Hello Peter and David, Thanks for your help. I have added what you suggested and its working perfectly fine except: When I add the panel function, the legend changes. In the sense without the panel function the column names are shown with small colored rectangles (on right), but after adding it the rectangles change to tiny un-filled diamonds. Any suggestions? My current code and data is below, Thanks a lot, Peng Data: Sample Col1 Col2 Col3 Row1 -2 4 -1 Row2 3 -2 4 Row3 3 5 -2 Row4 4 1 -1 Code: dta-read.table(data.txt, header=TRUE, row.names=Sample) coltemp=c(619,376,497) myYscale - seq(-10, 10, 1) barchart(data.matrix(dta), horizontal=FALSE, stack=TRUE, par.settings = simpleTheme(col = colors()[coltemp]), auto.key=list(space=right), border=NA, panel=function(x,y,...){ panel.abline(h=c(myYscale), col.line=gray) panel.barchart(x,y,...) }, scales = list(y = list(at = myYscale)) ) Thanks, Peng On Thu, Nov 26, 2009 at 7:23 PM, Peng Cai pengcaimaill...@gmail.com wrote: Hi Again, Before I start getting into what you just suggested, let me confirm if I made my point clear previously. I'm looking for horizontal lines similar to one on the following link (It has parallel lines for each y=200, y=400,...): http://pfiles.5min.com/images/176735/176734313.jpg What you just suggested can solve this purpose? Thanks, Peng On Thu, Nov 26, 2009 at 7:09 PM, Peter Ehlers ehl...@ucalgary.ca wrote: Peng Cai wrote: Thanks David, I tried panel.abline(h=somevalue) -- both inside and outside of barchart() function but its not working. Any suggestions? Peng Here's some code related to the data you posted earlier. barchart(data.matrix(dta), horizontal = FALSE, stack = TRUE, par.settings = simpleTheme(col = 2:4), panel=function(x,y,...){ panel.abline(h=c(-2,0,3,4), col.line=gray) panel.barchart(x,y,...) }, scales = list(y = list(at = -2:8)), auto.key = list(space = 'right', rectangles=TRUE, points=FALSE) ) If you want the gray lines in front of the bars, switch the order of the panel functions. With lattice, it's all about what goes into each panel (you have only one panel here). If you want more than one thing in a panel, you have to set up a function to do those things. I had to add the rectangles= and points= arguments to auto.key to get the same key as you had earlier. -Peter Ehlers On Thu, Nov 26, 2009 at 6:42 PM, David Winsemius dwinsem...@comcast.netwrote: On Nov 26, 2009, at 6:12 PM, Peng Cai wrote: Thanks a lot Peter! One more help, is there a similar function abline() for barchart(). ?panel.abline I'm trying to add a (light gray colored) horizontal lines, one for each y-value. Peng On Thu, Nov 26, 2009 at 5:59 PM, Peter Ehlers ehl...@ucalgary.ca wrote: Peng Cai wrote: Hi Peter, I'm not sure but it seems scales command works only with integer values. If the y-axis values are very small (such as -0.03, -0.02, -0.01, 0, 0.01,..., 0.08). My current plot has values 0, 0.05, and 0.10 only. But I need it to extend it to negative numbers and reduce the scale width (like -0.04, -0.02, 0, 0.02,...). Can I change these too? Thanks! Use, e.g. myYscale - seq(-0.04,
[R] plotting two surfaces simultaneously in a single panel
Hi, I have recently begun using the lattice package, and have been using the wireframe command to visualise matrices which are model outputs. I have been trying to plot two surfaces (from two matrices) simultaneously in one panel, to visualise intersections etc., but neither my attempts or trawling the net are helping me find how to do this. Can someone help? Thanks Cheers, Umesh Srinivasan NCBS-TIFR, Bangalore, India __ 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] If condition using accessors
Vitória Magalhães Piai wrote: Hi, I'm quite new using R and have got no one to help me get through it. Hopefully someone can help me with one problem I've been struggling with for the last hours!! (Sorry if I'm using the wrong terminology as well!) I have a data matrix in which SIE is one of my variables. What I need to do now is to create a new variable (group) if a certain condition in SIE is met. I tried: if (data2$SIE 50.646){ data2$group=as.factor(small) } which gives me In if (data2$SIE 50.646) { : the condition has length 1 and only the first element will be used and ifelse (data2$SIE 50.64593, data2$group = as.factor(small),data2$group = as.factor(large)) with Error: unexpected '=' in ifelse (data2$SIE 50.64593, data2$group = I tried all other kinds of variations and so far, nothing!! Do all of the following: ?= ?== ?if ?ifelse -Peter Ehlers Is there a good way to do this that someone could teach me? Thank you so much, Vitória __ 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] If condition using accessors
Peter Ehlers wrote: Vitória Magalhães Piai wrote: Hi, I'm quite new using R and have got no one to help me get through it. Hopefully someone can help me with one problem I've been struggling with for the last hours!! (Sorry if I'm using the wrong terminology as well!) I have a data matrix in which SIE is one of my variables. What I need to do now is to create a new variable (group) if a certain condition in SIE is met. I tried: if (data2$SIE 50.646){ data2$group=as.factor(small) } which gives me In if (data2$SIE 50.646) { : the condition has length 1 and only the first element will be used and ifelse (data2$SIE 50.64593, data2$group = as.factor(small),data2$group = as.factor(large)) with Error: unexpected '=' in ifelse (data2$SIE 50.64593, data2$group = I tried all other kinds of variations and so far, nothing!! Do all of the following: ?= ?== ?if ?ifelse -Peter Ehlers Actually, I assumed without checking that ?ifelse would have an example of assignment of the result of the test. (Maybe it could be added.) yourVariable - ifelse(...) -Peter Ehlers Is there a good way to do this that someone could teach me? Thank you so much, Vitória __ 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] Barplot with confidence intervals
On Nov 26, 2009, at 3:23 PM, Jonhnny Weslley wrote: I have a file in the following format: Scenario1 Scenario1CIL Scenario1CIU Scenario2 Scenario2CIL Scenario2CIU 60 57 62 45 48 50 110 101 111 51 50 52 120 117 122 64 62 66 192 190 194 79 75 79 where: First column = Scenario1 mean value Second column = Scenario1 Low Confidence Interval Third column = Scenario1 Upper Confidence Interval Fourth column = Scenario2 mean value Fifth column = Scenario2 Low Confidence Interval Sixth column = Scenario2 Upper Confidence Interval Then, I tried this: library(gplots) data - read.table(data.file, header=T, sep= ) legend - c(line1,line2,line3,line4) ci.l - as.matrix(c(c(data$Scenario1CIL), c(data$Scenario2CIL))) ci.u - as.matrix(c(c(data$Scenario1CIU), c(data$Scenario2CIU))) barplot2(as.matrix(c(c(data$Scenario1), c(data$Scenario2))), beside=TRUE, legend=legend, ylim=c(0, 200), main=Experiment X, ylab=Total size, font.main=4, cex.axis=1.2, cex.lab=1.5, cex.names=1.5, plot.ci=TRUE, ci.l=ci.l, ci.u=ci.u, plot.grid=TRUE) But this code doesn't group the values in Scenario1 and Scenario2, as expected. All plotted bars are joined side by side. Considering the letter 'H' a bar, the expected result was: ' ' but the result of the above code was: '' (no space between the Scenario1's values and Scenario2'values) and no legends (Scenario1 and Scenario2). How I must to do? Thanks in advance! The data structures that you are passing to barplot2() are single column matrices. They need to be multicolumn matrices, where each column is a group and as per ?barplot2, the ci.l and ci.u arguments need to have the same structure as the height argument. Thus: DF Scenario1 Scenario1CIL Scenario1CIU Scenario2 Scenario2CIL 160 57 6245 48 2 110 101 11151 50 3 120 117 12264 62 4 192 190 19479 75 Scenario2CIU 1 50 2 52 3 66 4 79 height - as.matrix(DF[, c(1, 4)]) ci.l - as.matrix(DF[, c(2, 5)]) ci.u - as.matrix(DF[, c(3, 6)]) height Scenario1 Scenario2 [1,]6045 [2,] 11051 [3,] 12064 [4,] 19279 ci.l Scenario1CIL Scenario2CIL [1,] 57 48 [2,] 101 50 [3,] 117 62 [4,] 190 75 ci.u Scenario1CIU Scenario2CIU [1,] 62 50 [2,] 111 52 [3,] 122 66 [4,] 194 79 library(gplots) legend - c(line1, line2, line3, line4) barplot2(height, plot.ci = TRUE, ci.l = ci.l, ci.u = ci.u, beside = TRUE, legend = legend, ylim = c(0, 200), main = Experiment X, ylab = Total size, font.main = 4, cex.axis = 1.2, cex.lab = 1.5, cex.names = 1.5, plot.grid = TRUE) BTW, once you get the plot created, you may want to note some errors in your CI values. HTH, Marc Schwartz __ 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 analyze this design using lmer
Dear all, A friend of mine requested me to analyze some data she has generated. I am hoping for some advice on best way of properly analyzing the data as I have never worked with such complicated or nested designs. Here is the setup. She has taken material from 5 animals and each material is subdivided into 6 plate (30 plates in total). Each plate is then assigned as either a control or a treated with a chemical AND kept at one of three concentrations. A sample is taken daily from each plate for six continuous days and measured (180 measurement in total). Her main question is whether treatment has an effect. Here is a simulated dataset: df - expand.grid( animal=LETTERS[1:5], group=c(Control, Treated), conc=c(X, Y, Z), day=1:6 ) df$plate - as.numeric(factor(apply(df[ ,1:3], 1, paste, collapse=))) df - df[ order(df$plate), ] df$plate - as.factor(df$plate) rownames(df) - NULL set.seed(1066) df$value - runif(90, 1, 2)*(df$group==Control) + c(0, -0.5, -0.20)[as.numeric(df$conc)] + rnorm(30)[ as.numeric(df$plate) ] + runif(180, 0.9, 1.1)*df$day + rnorm(180, sd=0.5) df[1:10, ] animal group conc day plate value 1A ControlX 1 1 3.3403510 2A ControlX 2 1 5.1042965 3A ControlX 3 1 5.4003462 ... ... 178 E TreatedZ 430 2.8558186 179 E TreatedZ 530 4.4567206 180 E TreatedZ 630 5.4542460 I have tried analyzing the data as follows: library(lme4) lmer( value ~ group + day + conc + (1 | animal/plate), data=df ) lmer( value ~ group + day + conc + (1 | animal), data=df ) lmer( value ~ group + day + conc + (1 | plate), data=df ) BUT I am not sure which of the models above is appropriate. Any advice would be very useful. Many thanks in advance. Regards, Adai __ 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] layers in xYplot of Hmisc
I took the OP's variables, reversed the direction of the second y, bundled them up in a dataframe and then assigned the grp. So starting with the OP's code: x-seq(1,10,1) y-seq(1,10,1) ci-y*.10 ciupper-y+ci cilower-y-ci x2-seq(1,5,.5) y2-seq(5, 1, -.5) #reverse second variable ci2-y2*.10 ciupper2-y2+ci2 cilower2-y2-ci2 dfci - data.frame(x =c(x,x2), y=c(y,y2), ciupper=c(ciupper,ciupper2), cilower=c(cilower,cilower2) ) dfci$grp - 1:19 # groupify, needed to do it by hand since lengths were different dfci$grp[1:10] - 1 dfci$grp[11:19] - 2 dfci$grp - factor(dfci$grp) dfci dput(dfci) On Nov 27, 2009, at 6:13 AM, butter wrote: do you mind me asking what code you used to create that data frame and name the groups 1 and 2? David Winsemius wrote: On Nov 26, 2009, at 10:26 PM, Joe King wrote: In the filled bands part of xYplot of the Hmisc package, is there a way to have multiple bands with multiple lines? or does it just allow one for now? No problem as long as you use groups... which means you probably ought to be providing a dataframe format with a grouping factor. (At least that was how I read the help page saying that: - Details Unlike xyplot, xYplot senses the presence of a groups variable and automatically invokes panel.superpose instead of panel.xyplot. The same is true for Dotplot vs. dotplot. - I would give it a dataset that does not have lines coincident if you want to see them. (You should also get rid of that space in your color parameter. dfci - structure(list(x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5), y = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4.5, 4, 3.5, 3, 2.5, 2, 1.5, 1), ciupper = c(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 11, 5.5, 4.95, 4.4, 3.85, 3.3, 2.75, 2.2, 1.65, 1.1), cilower = c(0.9, 1.8, 2.7, 3.6, 4.5, 5.4, 6.3, 7.2, 8.1, 9, 4.5, 4.05, 3.6, 3.15, 2.7, 2.25, 1.8, 1.35, 0.9), grp = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(1, 2), class = factor)), .Names = c(x, y, ciupper, cilower, grp), row.names = c(NA, -19L), class = data.frame) xYplot(Cbind(y,cilower,ciupper)~x, groups=grp, data=dfci, method=filled bands,col.fill=lightgrey, type=c(b)) -- David So I had an example bit ago had a made up line and CI, now if I wanted to make a second line with a CI filled in can I put them on the same plot? x-seq(1,10,1) y-seq(1,10,1) ci-y*.10 ciupper-y+ci cilower-y-ci xYplot(Cbind(y,cilower,ciupper)~x, method=filled bands, col.fill=light grey, type=c(b)) x2-seq(1,5,.5) y2-seq(1,5,.5) ci2-y2*.10 ciupper2-y2+ci2 cilower2-y2-ci2 xYplot(Cbind(y2,cilower2,ciupper2)~x2, method=filled bands,col.fill=light grey, type=c(b)) --- Joe King, M.A. Ph.D. Student University of Washington - Seattle 206-913-2912 j...@joepking.com --- Never throughout history has a man who lived a life of ease left a name worth remembering. --Theodore Roosevelt [[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 Heritage Laboratories West Hartford, CT __ 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. -- View this message in context: http://old.nabble.com/layers-in-xYplot-of-Hmisc-tp26537542p26541016.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] If condition using accessors
On Nov 27, 2009, at 5:34 AM, Vitória Magalhães Piai wrote: Hi, I'm quite new using R and have got no one to help me get through it. Hopefully someone can help me with one problem I've been struggling with for the last hours!! (Sorry if I'm using the wrong terminology as well!) I have a data matrix in which SIE is one of my variables. What I need to do now is to create a new variable (group) if a certain condition in SIE is met. I tried: if (data2$SIE 50.646){ data2$group=as.factor(small) } which gives me In if (data2$SIE 50.646) { : the condition has length 1 and only the first element will be used If ( cond) is not vectorised. Ifelse is. and ifelse (data2$SIE 50.64593, data2$group = as.factor(small),data2$group = as.factor(large)) with Error: unexpected '=' in ifelse (data2$SIE 50.64593, data2$group = Almost... try: data2$group - ifelse (data2$SIE 50.64593, as.factor(small), as.factor(large) ) ... but that looks wrong to my wetware R interpreter, too, so could also try: data2$group - factor( ifelse (data2$SIE 50.64593, small, large ) (And of course this would have been tested had you supplied a small test dataset, but this week I am being passive aggressive toward persons who don't follow the Posting Guide.) -- David I tried all other kinds of variations and so far, nothing!! Is there a good way to do this that someone could teach me? Thank you so much, Vitória __ 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 Heritage Laboratories West Hartford, CT __ 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] post
Dear all, I have the following problem which I cannot solve: data - numeric (100) for (i in 1:100){ p - runif(1,min=0,max=1) data[i] - rnorm(1,mean=2,sd=1) } ke - density(data,bw=sj,n=61) How can I now find the value of this density function for example ke(0), ke(2) etc. Maybe this is an easy question but I cannot resolve it. Thank you very much for the help. On Fri, Nov 27, 2009 at 3:34 PM, r-help-requ...@r-project.org wrote: Welcome to the R-help@r-project.org mailing list! To post to this list, send your email to: r-help@r-project.org General information about the mailing list is at: https://stat.ethz.ch/mailman/listinfo/r-help If you ever want to unsubscribe or change your options (eg, switch to or from digest mode, change your password, etc.), visit your subscription page at: https://stat.ethz.ch/mailman/options/r-help/nastik1%40gmail.com You can also make such adjustments via email by sending a message to: r-help-requ...@r-project.org with the word `help' in the subject or body (don't include the quotes), and you will get back a message with instructions. You must know your password to change your options (including changing the password, itself) or to unsubscribe. It is: qwerty Normally, Mailman will remind you of your r-project.org mailing list passwords once every month, although you can disable this if you prefer. This reminder will also include instructions on how to unsubscribe or change your account options. There is also a button on your options page that will email your current password to you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Time Series Data
Hi All, I'm trying to analyze some time series data and I have run into difficulty. I have decadal sun spot data and I want to separate the very regular periodic function from the trend and noise. I looked into using stl(), but the frequency of the time series data must be greater than 1 for stl(). My data covers a 1000 year interval from 9095 BP to 8095BP and the frequency is, therefore, 0.1 (because the data are decadal). I've tried changing the frequency, but the only frequency that creates a plot of the time series data which matches the raw data is 0.1. Is there anything I can do to the data that will make it more amenable to stl(), or is there another package that I could use for decomposing the signal that does not require that the frequency of the time series to be greater than 1? Thanks, Chris _ Facebook. [[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 tick marker and text
Hi R-ers, I am struggling with my x-axis in a association plot. What I would like is to place the labels of the x-axis between the tick markers and normally the labels are printed at the place where the tick marker is placed. I donât want to move the tick marker (it gives the switch between one chromosome and the next) but I just want to put the chromosome number in between the two tick markers. This example from mhtplot has the chromosome number at the place of the tickmarker. How can I change this to âin betweenâ? Thanks!, Naomi # fake example with Affy500k data affy -c(40220, 41400, 33801, 32334, 32056, 31470, 25835, 27457, 22864, 28501, 26273, 24954, 19188, 15721, 14356, 15309, 11281, 14881, 6399, 12400, 7125, 62 07) CM - cumsum(affy) n.markers - sum(affy) n.chr - length(affy) test - data.frame(chr=rep(1:n.chr,affy),pos=1:n.markers,p=runif(n.markers)) oldpar - par() par(las=1,cex=0.6) colors - rep(c(blue,green),11) par(cex.axis=1.3) mhtplot(test,usepos=TRUE,colors=colors,gap=1,pch=19,bg=colors) box() par(oldpar) Disclaimer: De informatie opgenomen in dit bericht (en bijlagen) kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n). Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te gebruiken, de afzender direct te informeren en het bericht te vernietigen. Aan dit bericht kunnen geen rechten of plichten worden ontleend. Disclaimer: The information contained in this message may be confidential and is intended to be exclusively for the addressee. Should you receive this message unintentionally, you are expected not to use the contents herein, to notify the sender immediately and to destroy the message. No rights can be derived from this message. P Please consider the environment before printing this email __ 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] post
Anastasia wrote: Dear all, I have the following problem which I cannot solve: data - numeric (100) for (i in 1:100){ p - runif(1,min=0,max=1) data[i] - rnorm(1,mean=2,sd=1) } Er what is p doing in there. As far as I can see, you might as well do data - rnorm(200, 2, 1) ke - density(data,bw=sj,n=61) How can I now find the value of this density function for example ke(0), ke(2) etc. Maybe this is an easy question but I cannot resolve it. approxfun is your friend, e.g.: d - density(rnorm(200,2,1)) dd - approxfun(d) dd(3) [1] 0.2267764 dd(5) [1] 0.006181384 dd(20) # from default rule=1 in approxfun [1] NA Thank you very much for the help. And, BTW, please don't hijack old mails for new topics (and in particular, don't show your password to the world): On Fri, Nov 27, 2009 at 3:34 PM, r-help-requ...@r-project.org wrote: Welcome to the R-help@r-project.org mailing list! To post to this list, send your email to: r-help@r-project.org -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ 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 with dynformula from plm package
Hello list, I'm following the paper (http://www.jstatsoft.org/v27/i02/paper) on how to use plm to run panel regressions, and am having trouble with what I believe should be something very basic. When I run the command (p.9 in the paper): R dynformula(emp~wage+capital,log=list(capital=FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) I see: emp ~ wage + capital rather than the complete model that is given in the paper: log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) And indeed, when I try to run a regression using that formula, it appears to not contain any lags or logs (output below). Any ideas? Thanks in advance, ~Owen -- Owen Powell http://center.uvt.nl/phd_stud/powell R library(plm) R data(EmplUK, package=plm) R a = dynformula(emp~wage+capital,log=list(capital=FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) R testModel - plm(formula = a,data=EmplUK,model=within) [1] 10312 R summary(testModel) Oneway (individual) effect Within Model Call: plm(formula = a, data = EmplUK, model = within) Unbalanced Panel: n=140, T=7-9, N=1031 Residuals : Min. 1st Qu. Median 3rd Qu. Max. -17.1000 -0.3060 0.0137 0.3070 27.3000 Coefficients : Estimate Std. Error t-value Pr(|t|) wage-0.143626 0.032790 -4.3802 1.186e-05 *** capital 0.801495 0.064088 12.5062 2.2e-16 *** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Total Sum of Squares:5030.6 Residual Sum of Squares: 4207.8 F-statistic: 86.9179 on 2 and 889 DF, p-value: 2.22e-16 [[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] Time Series Data
On Nov 27, 2009, at 9:55 AM, chris carleton wrote: Hi All, I'm trying to analyze some time series data and I have run into difficulty. I have decadal sun spot data and I want to separate the very regular periodic function from the trend and noise. I looked into using stl(), but the frequency of the time series data must be greater than 1 for stl(). My data covers a 1000 year interval from 9095 BP to 8095BP and the frequency is, therefore, 0.1 (because the data are decadal). I've tried changing the frequency, but the only frequency that creates a plot of the time series data which matches the raw data is 0.1. Is there anything I can do to the data that will make it more amenable to stl(), or is there another package that I could use for decomposing the signal that does not require that the frequency of the time series to be greater than 1? Thanks, I do not understand why you are not multiplying by 10 and rounding. -- David David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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 with dynformula from plm package [RE-POST]
Hello list, I'm following the paper (http://www.jstatsoft.org/v27/i02/paper) on how to use plm to run panel regressions, and am having trouble with what I believe should be something very basic. When I run the command (p.9 in the paper): R dynformula(emp~wage+capital,log=list(capital=FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) I see: emp ~ wage + capital rather than the complete model that is given in the paper: log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) And indeed, when I try to run a regression using that formula, it appears to not contain any lags or logs (output below). Any ideas? Thanks in advance, ~Owen -- Owen Powell http://center.uvt.nl/phd_stud/powell R library(plm) R data(EmplUK, package=plm) R a = dynformula(emp~wage+capital,log=list(capital=FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) R testModel - plm(formula = a,data=EmplUK,model=within) [1] 10312 R summary(testModel) Oneway (individual) effect Within Model Call: plm(formula = a, data = EmplUK, model = within) Unbalanced Panel: n=140, T=7-9, N=1031 Residuals : Min. 1st Qu. Median 3rd Qu. Max. -17.1000 -0.3060 0.0137 0.3070 27.3000 Coefficients : Estimate Std. Error t-value Pr(|t|) wage-0.143626 0.032790 -4.3802 1.186e-05 *** capital 0.801495 0.064088 12.5062 2.2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Total Sum of Squares:5030.6 Residual Sum of Squares: 4207.8 F-statistic: 86.9179 on 2 and 889 DF, p-value: 2.22e-16 __ 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] problem with dynformula from plm package [RE-POST]
On Nov 27, 2009, at 10:25 AM, Owen Powell wrote: Hello list, I'm following the paper (http://www.jstatsoft.org/v27/i02/paper) on how to use plm to run panel regressions, and am having trouble with what I believe should be something very basic. When I run the command (p.9 in the paper): R dynformula(emp~wage + capital ,log = list (capital =FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) Perhaps you could have read the help page for the current version of the package which says the argument have been modified. Using the current arguments: dynformula(emp~wage + capital ,log .form = list (capital = FALSE ,TRUE),lag.form=list(emp=2,c(2,3)),diff.form=list(FALSE,capital=TRUE)) log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) -- David Winsemius, MD I see: emp ~ wage + capital rather than the complete model that is given in the paper: log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) And indeed, when I try to run a regression using that formula, it appears to not contain any lags or logs (output below). Any ideas? Thanks in advance, ~Owen -- Owen Powell http://center.uvt.nl/phd_stud/powell R library(plm) R data(EmplUK, package=plm) R a = dynformula(emp~wage + capital ,log = list (capital =FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) snipped David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] matching and extracting data
Dear all, I have querry on how to extract the data by matching between two data set where one has the same elements multiple times? For example, I have two matrix X and Y. X [,1] [,2] [,3] 1 A 5 P 2 B 6 P 3 C 7 P 4 D 5 Q 5 E 6 Q 6 F 7 Q 7 G 5 R 8 H 6 R 9 I 7 S 10 J 5 S 11 K 6 T 12 L 7 T and Y [,1] 1 P 2 Q 3 R 4 S Now, I want to select and extract all the data of P, Q, R and S elements of column 3 of X matrix by matching with column 1 of Y matrix like below: [,1] [,2] [,3] 1 A 5 P 2 B 6 P 3 C 7 P 4 D 5 Q 5 E 6 Q 6 F 7 Q 7 G 5 R 8 H 6 R 9 I 7 S 10 J 5 S I guess, the answer might be simple but i am not getting way to figure out. And, i have to select subset from very huge data set. So, i need some kinds of automated procedure. If some one can help me, it will be great Thanks in advance. Sincerely, Ram Kumar Basnet [[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] matching and extracting data
On 11/27/2009 10:25 AM, ram basnet wrote: Dear all, I have querry on how to extract the data by matching between two data set where one has the same elements multiple times? For example, I have two matrix X and Y. X [,1][,2] [,3] 1 A 5 P 2 B 6 P 3 C 7 P 4 D 5 Q 5 E 6 Q 6 F 7 Q 7 G 5 R 8 H 6 R 9 I 7 S 10 J 5 S 11 K6 T 12 L 7 T and Y [,1] 1 P 2 Q 3 R 4 S Now, I want to select and extract all the data of P, Q, R and S elements of column 3 of X matrix by matching with column 1 of Y matrix like below: [,1] [,2] [,3] 1 A 5 P 2 B 6 P 3 C 7 P 4 D 5 Q 5 E 6 Q 6 F 7 Q 7 G 5 R 8 H 6 R 9 I 7 S 10 J 5 S I guess, the answer might be simple but i am not getting way to figure out. And, i have to select subset from very huge data set. So, i need some kinds of automated procedure. If some one can help me, it will be great subset(X, X[,3] %in% Y[,1]) [,1] [,2] [,3] [1,] A 5 P [2,] B 6 P [3,] C 7 P [4,] D 5 Q [5,] E 6 Q [6,] F 7 Q [7,] G 5 R [8,] H 6 R [9,] I 7 S [10,] J 5 S Thanks in advance. Sincerely, Ram Kumar Basnet [[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. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ 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] Simple Function doesn't work?
Hello, I am new to R program, therefore, I am sorry if this is a really stupid question. I wrote a simple function and for some reason it doesn't work ReturnsGrid = function(x,y,m){ for (i in 1:m){ grid[i] - x + (i-1)*(y-x)/m } grid } xx=ReturnsGrid(0,9,3) Thanks a lot! [[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] matching and extracting data
On Nov 27, 2009, at 10:25 AM, ram basnet wrote: Dear all, I have querry on how to extract the data by matching between two data set where one has the same elements multiple times? For example, I have two matrix X and Y. X [,1][,2] [,3] 1 A 5 P 2 B 6 P 3 C 7 P 4 D 5 Q 5 E 6 Q 6 F 7 Q 7 G 5 R 8 H 6 R 9 I 7 S 10 J 5 S 11 K6 T 12 L 7 T and Y [,1] 1 P 2 Q 3 R 4 S Now, I want to select and extract all the data of P, Q, R and S elements of column 3 of X matrix by matching with column 1 of Y matrix like below: [,1] [,2] [,3] 1 A 5 P 2 B 6 P 3 C 7 P 4 D 5 Q 5 E 6 Q 6 F 7 Q 7 G 5 R 8 H 6 R 9 I 7 S 10 J 5 S Perhaps (untested): X[ X[,3] %in% Y[,1] , ] Would have been tested if you had used dput or dump on your matrices. -- David. I guess, the answer might be simple but i am not getting way to figure out. And, i have to select subset from very huge data set. So, i need some kinds of automated procedure. If some one can help me, it will be great Thanks in advance. Sincerely, Ram Kumar Basnet [[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 Heritage Laboratories West Hartford, CT __ 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] Force a variable substitution in expression
Hello, I have a function that creates an expression object with some variables substituted e.g foo - function(s){ expression({ v - s print(v) }) } Thus foo returns an expression, however the expression has the symbol 's' contained within it and thus returns an error when eval'd e.g x - foo(10) eval(x) Error in eval(expr, envir, enclos) : object 's' not found Q: How do I force a substitution so that the returned expression has the value of 's' 'hardcoded' in it e.g foo(10) returns expression({ v - 10 print(v) }) Regards Saptarshi -- saptarshi guha | http://www.stat.purdue.edu/~sguha It is when I struggle to be brief that I become obscure. -- Quintus Horatius Flaccus (Horace) __ 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] Simple Function doesn't work?
Hi, You need to create the grid object before you can assign values to it. Try ReturnsGrid = function(x,y,m){ grid - numeric() for (i in 1:m){ grid[i] - x + (i-1)*(y-x)/m } grid } On Fri, Nov 27, 2009 at 11:00 AM, Anastasia nast...@gmail.com wrote: Hello, I am new to R program, therefore, I am sorry if this is a really stupid question. I wrote a simple function and for some reason it doesn't work ReturnsGrid = function(x,y,m){ for (i in 1:m){ grid[i] - x + (i-1)*(y-x)/m } grid } xx=ReturnsGrid(0,9,3) Thanks a lot! [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.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] problem tick marker and text
Duijvesteijn, Naomi wrote: Hi R-ers, I am struggling with my x-axis in a association plot. What I would like is to place the labels of the x-axis between the tick markers and normally the labels are printed at the place where the tick marker is placed. I don’t want to move the tick marker (it gives the switch between one chromosome and the next) but I just want to put the chromosome number in between the two tick markers. This example from mhtplot has the chromosome number at the place of the tickmarker. How can I change this to ‘in between’? Thanks!, Naomi Kudos for including reproducible code, BUT 1. do you really consider a dataframe of dimension ~500K by 3 to be minimal? 2. there are over 2000 R-packages on CRAN; wouldn't it be polite to say which one contains mhtplot()? # fake example with Affy500k data affy -c(40220, 41400, 33801, 32334, 32056, 31470, 25835, 27457, 22864, 28501, 26273, 24954, 19188, 15721, 14356, 15309, 11281, 14881, 6399, 12400, 7125, 62 07) CM - cumsum(affy) is CM used anywhere? n.markers - sum(affy) n.chr - length(affy) test - data.frame(chr=rep(1:n.chr,affy),pos=1:n.markers,p=runif(n.markers)) oldpar - par() par(las=1,cex=0.6) colors - rep(c(blue,green),11) par(cex.axis=1.3) mhtplot(test,usepos=TRUE,colors=colors,gap=1,pch=19,bg=colors) box() par(oldpar) Here is one way, using about half the data. I use mtext() to place the labels, since axis= seems to be hard-coded in mhtplot. # make a vector of labels to place between ticks textvec - letters[1:5] # plot mhtplot(test[1:2e5,],usepos=TRUE,colors=colors,gap=1,pch=19,bg=colors) # now figure out where to put the labels. This would be # easy with seq() if the scale were uniform but it's not. # So we use the locator() function. xat - locator()$x xat - round(xat) xat #[1] 34316 85096 132458 173961 216929 # place the labels; adjust line= if you wish mtext(textvec, side=1, line=0, at=xat) If I had to do this frequently, I would hack the mhtplot() function. -Peter Ehlers Disclaimer: De informatie opgenomen in dit bericht (en bijlagen) kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n). Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te gebruiken, de afzender direct te informeren en het bericht te vernietigen. Aan dit bericht kunnen geen rechten of plichten worden ontleend. Disclaimer: The information contained in this message may be confidential and is intended to be exclusively for the addressee. Should you receive this message unintentionally, you are expected not to use the contents herein, to notify the sender immediately and to destroy the message. No rights can be derived from this message. P Please consider the environment before printing this email __ 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] Simple Function doesn't work?
Hi, The error message, Error in grid[i] - x + (i - 1) * (y - x)/m : object of type 'closure' is not subsettable indicates that grid is actually known to R as a function (type grid to see its definition). You can define your own variable with the same name, but that needs to be done before the assignment in the for loop, ReturnsGrid = function(x,y,m){ grid - vector(length = m) for (i in 1:m){ grid[i] - x + (i-1)*(y-x)/m } grid } ReturnsGrid(0,9,3) HTH, baptiste 2009/11/27 Anastasia nast...@gmail.com: Hello, I am new to R program, therefore, I am sorry if this is a really stupid question. I wrote a simple function and for some reason it doesn't work ReturnsGrid = function(x,y,m){ for (i in 1:m){ grid[i] - x + (i-1)*(y-x)/m } grid } xx=ReturnsGrid(0,9,3) Thanks a lot! [[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] Force a variable substitution in expression
On 27/11/2009 11:04 AM, Saptarshi Guha wrote: Hello, I have a function that creates an expression object with some variables substituted e.g foo - function(s){ expression({ v - s print(v) }) } Thus foo returns an expression, however the expression has the symbol 's' contained within it and thus returns an error when eval'd e.g x - foo(10) eval(x) Error in eval(expr, envir, enclos) : object 's' not found Q: How do I force a substitution so that the returned expression has the value of 's' 'hardcoded' in it e.g foo(10) returns expression({ v - 10 print(v) }) The substitute() function can do it, but the bquote() function is the most convenient: foo - function(s) { + bquote(expression({ +v - .(s) +print(v) + })) + } foo(10) expression({ v - 10 print(v) }) Duncan Murdoch __ 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] Simple Function doesn't work?
Hi, If you execute the following code it works but I wouldn't use grid if I were you as a vector as this name is already used by R (check help(grid)) and it explains why you have to define it in the function. ReturnsGrid = function(x,y,m){ grid - numeric(m) for (i in 1:m){ grid[i] - x + (i-1)*(y-x)/m } grid } xx=ReturnsGrid(0,9,3) Regards, Alain Anastasia wrote: Hello, I am new to R program, therefore, I am sorry if this is a really stupid question. I wrote a simple function and for some reason it doesn't work ReturnsGrid = function(x,y,m){ for (i in 1:m){ grid[i] - x + (i-1)*(y-x)/m } grid } xx=ReturnsGrid(0,9,3) Thanks a lot! [[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. -- Alain Guillet Statistician and Computer Scientist SMCS - Institut de statistique - Université catholique de Louvain Bureau c.316 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50 __ 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] If condition using accessors
Thanx. I'll just post in here the way I solved it in case someone happens to need something similar in the future. It may not be the most elegant way, but it worked! yes = small no = large data3$group = ifelse(data3$SIE 50.64593,yes,no) Peter Ehlers wrote: Peter Ehlers wrote: Vitória Magalhães Piai wrote: Hi, I'm quite new using R and have got no one to help me get through it. Hopefully someone can help me with one problem I've been struggling with for the last hours!! (Sorry if I'm using the wrong terminology as well!) I have a data matrix in which SIE is one of my variables. What I need to do now is to create a new variable (group) if a certain condition in SIE is met. I tried: if (data2$SIE 50.646){ data2$group=as.factor(small) } which gives me In if (data2$SIE 50.646) { : the condition has length 1 and only the first element will be used and ifelse (data2$SIE 50.64593, data2$group = as.factor(small),data2$group = as.factor(large)) with Error: unexpected '=' in ifelse (data2$SIE 50.64593, data2$group = I tried all other kinds of variations and so far, nothing!! Do all of the following: ?= ?== ?if ?ifelse -Peter Ehlers Actually, I assumed without checking that ?ifelse would have an example of assignment of the result of the test. (Maybe it could be added.) yourVariable - ifelse(...) -Peter Ehlers Is there a good way to do this that someone could teach me? Thank you so much, Vitória __ 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] Time Series Data
I'm not sure what you mean by 'multiplying by 10 and rounding'. I've tried to re-organize the data and then create a ts object that is analogous to the various sunspot datasets provided in the data package with R, but the matrix I generate by binning the data into centuries (which would make the frequency in stl() 10) is being read by plot() and stl() as a multivariate time series dataset (stl() requires that the data be univariate). For those that haven't read stl() docs, the frequency is the number of observations per unit of time. In the case of quarterly economic data the frequency is 4 (4 observations over a year), and in the case of decadal sunspot numbers the frequency is .1 (0.1 observations per year). I would have thought that after I binned the data into centuries (now ten observations per unit of time) that it would be sufficient, but I don't know why stl() interprets the matrix as a multivariate dataset when a similar matrix (sunspots - measured each month for a ! frequency of 12; although from what I can tell the sunspots data in R is not a ts object anyhow) encounters no such difficulty. Any suggestions would be appreciated, Chris CC: r-help@r-project.org From: dwinsem...@comcast.net To: w_chris_carle...@hotmail.com Subject: Re: [R] Time Series Data Date: Fri, 27 Nov 2009 10:10:36 -0500 On Nov 27, 2009, at 9:55 AM, chris carleton wrote: Hi All, I'm trying to analyze some time series data and I have run into difficulty. I have decadal sun spot data and I want to separate the very regular periodic function from the trend and noise. I looked into using stl(), but the frequency of the time series data must be greater than 1 for stl(). My data covers a 1000 year interval from 9095 BP to 8095BP and the frequency is, therefore, 0.1 (because the data are decadal). I've tried changing the frequency, but the only frequency that creates a plot of the time series data which matches the raw data is 0.1. Is there anything I can do to the data that will make it more amenable to stl(), or is there another package that I could use for decomposing the signal that does not require that the frequency of the time series to be greater than 1? Thanks, I do not understand why you are not multiplying by 10 and rounding. -- David David Winsemius, MD Heritage Laboratories West Hartford, CT _ Facebook. [[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 titlessymbols in plot.spm
Hi all, I'm trying my best in changing the names of my experiments in the spectral map. My experiments are from six different time points, two as control and two treated experiments. I set have for each time point a different color . Now I want to change the symbols so that I have for the treated experiments one and for the controls a different one. But I want only two different symbols which. The best option will be to have a C for the controls and a T for the treated Experiments. I than won't be needing the title of the experiments. But a different symbol will also be good. I tried it with this command: stress - c(control , control , treated , treated , control , control , treated , treated , control , control , treated , treated , control , control , treated , treated , control , control , treated , treated , control , control , treated , treated) # each four exp. are in one time point, therefore I am using six different colors for the experiments. stress.Factor - factor(stress) plot(r.sma,label.tol=0,scale=uvc,col.group=(ramgrp[,2]),colors = c(grey90,gray5,green3,gold1,dodgerblue2,indianred3,lightskyblue,hotpink4), col.areas = FALSE, col.symbols =unclass(stress.Factor) ,zoom=c(1,5),col.size=2) Unfortunately it's not working. What i get is to see in the attachment. i have two symbols but for the wrong experiments. I would happy for any suggestions which help me solve this problem. Thanks Assa -- Assa Yeroslaviz Kockelsberg 22 51371 Leverkusen __ 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] Force a variable substitution in expression
The substitute() function can do it, but the bquote() function is the most convenient: foo - function(s) { + bquote(expression({ + v - .(s) + print(v) + })) + } foo(10) expression({ v - 10 print(v) }) Duncan Murdoch Thanks, after sending this email, i used substitute, but first eval'ing the formals (since they are delayed assignments). I see bquote does this for me. Regards Saptarshi __ 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] Save workspace with ff objects
My script generates a mixture of normal and ff objects. Very often I would like to save the workspace for each parameter setting, so that I can get back to it later on. Is there an easy way to do this, instead of needing to save individual ff objects separately? With one save() you can store as many ff objects as you like. However, this does not save the ff files to a different location. I've tried the naive way of just saving the workspace, only to find that ff objects are empty. When loading the ff objects, the ff files need to be in their original locations. You need to make sure that you do not overwrite those and they survive finalizer and tempdir remove at rm(ff) or q() time. Do read the ff help on parameters 'filename', 'pattern', 'finalizer', 'finonexit'. The next version of ff will have ffsave() which will store a mixture of normal and ff objects *and* all ff-files into a ffarchive, i.e. two files ffarchive.RData and ffarchive.ffData from which you can restore all or a selection of ff objects / files using the ffload() command. Regards Jens Oehlschlägel __ 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] questions on the ff package
I wonder how efficiently it is to do the following command on a frequent basis. nrow(matFF) - nrow(matFF)+1 Obviously there is overhead (closing file, enlarging file, openeing file). I recommend you measure yourself whether this is acceptable for you. no large file copying is needed each time the nrow is changed? With a decent filesystem there is *no* copying from smaller to larger file. would you think I can open 2000 large matrices and leave them open or I need to close each after it is opened and used? Not tested yet. I guess the number of open files can be configured when compiling your OS. Please test and let us know your experience. Regards Jens Oehlschlägel __ 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] Simple Function doesn't work?
Hi, You would also make your code more efficient and possible more readable by doing ReturnsGrid - function(x, y, m) { x + (seq.int(m) - 1) * (y - x) / m } (xx - ReturnsGrid(0, 9, 3)) #[1] 0 3 6 And if you want to supply vector x and y you could do something like (there are probably better ways..) ReturnsGrid - function(x, y, m) { if (length(x) != length(y) (length(x)==1 | length(y) == 1)) stop (inputs not compatible) # or something n - max(length(x), length(y)) out - sapply(seq.int(n), function(i) x[i] + (1:m - 1) * (y[i] - x[i]) / m) drop(out) } (xx - ReturnsGrid(0, 9, 3)) #[1] 0 3 6 (xx - ReturnsGrid(0:2, 9:11, 3)) #[1,]012 #[2,]345 #[3,]678 But it seems like you could also do it using sequence ... seq(x, y-1, by = m) HTH, Colin -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Anastasia Sent: 27 November 2009 16:01 To: r-help@r-project.org Subject: [R] Simple Function doesn't work? Hello, I am new to R program, therefore, I am sorry if this is a really stupid question. I wrote a simple function and for some reason it doesn't work ReturnsGrid = function(x,y,m){ for (i in 1:m){ grid[i] - x + (i-1)*(y-x)/m } grid } xx=ReturnsGrid(0,9,3) Thanks a lot! [[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. __ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email __ 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] Simple Function doesn't work?
Erm... Maybe the sequence bit wont work ... A bit hasty there And also the length check should be if (length(x) != length(y) !(length(x) == 1 | length(y) == 1)) stop (inputs not compatible) # or something I missed out the not! -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Colin Millar Sent: 27 November 2009 16:41 To: Anastasia; r-help@r-project.org Subject: Re: [R] Simple Function doesn't work? Hi, You would also make your code more efficient and possible more readable by doing ReturnsGrid - function(x, y, m) { x + (seq.int(m) - 1) * (y - x) / m } (xx - ReturnsGrid(0, 9, 3)) #[1] 0 3 6 And if you want to supply vector x and y you could do something like (there are probably better ways..) ReturnsGrid - function(x, y, m) { if (length(x) != length(y) (length(x)==1 | length(y) == 1)) stop (inputs not compatible) # or something n - max(length(x), length(y)) out - sapply(seq.int(n), function(i) x[i] + (1:m - 1) * (y[i] - x[i]) / m) drop(out) } (xx - ReturnsGrid(0, 9, 3)) #[1] 0 3 6 (xx - ReturnsGrid(0:2, 9:11, 3)) #[1,]012 #[2,]345 #[3,]678 But it seems like you could also do it using sequence ... seq(x, y-1, by = m) HTH, Colin -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Anastasia Sent: 27 November 2009 16:01 To: r-help@r-project.org Subject: [R] Simple Function doesn't work? Hello, I am new to R program, therefore, I am sorry if this is a really stupid question. I wrote a simple function and for some reason it doesn't work ReturnsGrid = function(x,y,m){ for (i in 1:m){ grid[i] - x + (i-1)*(y-x)/m } grid } xx=ReturnsGrid(0,9,3) Thanks a lot! [[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. __ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email __ 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. __ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email __ __ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email __ 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] Best way to preallocate numeric NA array?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Rob Steele Sent: Thursday, November 26, 2009 8:03 AM To: r-h...@stat.math.ethz.ch Subject: [R] Best way to preallocate numeric NA array? These are the ways that occur to me. ## This produces a logical vector, which will get converted to a numeric ## vector the first time a number is assigned to it. That seems ## wasteful. x - rep(NA, n) ## This does the conversion ahead of time but it's still creating a ## logical vector first, which seems wasteful. x - as.numeric(rep(NA, n)) ## This avoids type conversion but still involves two assignments for ## each element in the vector. x - numeric(n) x[] - NA ## This seems reasonable. x - rep(as.numeric(NA), n) Comments? I like the rep-based ones because they are more 'functional': I can pass the output directly into another function. If speed is a big concern, I think that x - rep.int(NA_real_, n) may be the fastest but then it is not immediately apparent how to do the same for integer or fancier classes. (NA_real_ is to the numeric class as NA_integer_ is to the integer class.) Your last one, rep(as.class(NA), n), seems to me to be a good compromise between readability and speed. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com Thanks, Rob __ 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] R 2.10 Line Type Issue...
Morning folks (at least here on the western side of the U.S.)... This morning I constructed a contour plot of some bivariate distributions I'm working with. When I attempted to add a second contour to the plot using a dashed line (lty=2), R immediately went off to la-la land, requiring a force-quit. I finally tied the problem down to this statement: contour(u,v,ci,levels=c(0.30),add=TRUE,lty=2) I tried specifying lty=dash as well without any change. The plot works with no lty specification (but produces a solid line, of course). In researching the issue, I learned that the demo, demo(graphics), should produce a variety of lines on the first plot. On my system, the first plot is completely blank. My system: PowerMac dual-G5, Leopard 10.5.8, R 2.10 fresh install. I attempted re-installing with no change. Any ideas? Thanks... -=d __ 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] problem with dynformula from plm package [RE-POST]
Great! That did the trick, thanks David. To summarize for the list, to get dynformula to work (example): R a = dynformula(emp~wage+capital,log.form=list(capital=FALSE,TRUE),lag.form=list(emp=2,c(2,3)),diff.form=list(FALSE,capital=TRUE)) it might be necessary to use: R plm(formula = formula(a), data=EmplUK) rather than just: R plm(formula = a, data = EmplUK) ~Owen 2009/11/27 David Winsemius dwinsem...@comcast.net: You might also note that the authors hint on the help page that one might want to use the formula() operation on the result of dynformula. Following that path would have gotten us to a more successful conclusion. grun.fe - plm(formula = formula(a),data=EmplUK) grun.fe Model Formula: log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) Coefficients: lag(log(emp), 1) lag(log(emp), 2) lag(log(wage), 2) lag(log(wage), 3) diff(capital, 2) 0.8678675 -0.1936447 -0.1632724 0.3200785 0.0037612 diff(capital, 3) 0.0137866 -- David. On Nov 27, 2009, at 12:04 PM, Owen Powell wrote: Hi David, Thank you for the response. I forgot to mention that I'd already tried what (I think) you propose (adding .form to the end of the lag, log and diff) and I still see the same results (posted below). Specifically, I still see no lags, logs or diffs in my model. Any other ideas? ~Owen R rm(list = ls()) R options(prompt= R ) R library(plm) R data(EmplUK, package=plm) R EmplUK - plm.data(EmplUK, index = c(firm, year)) R log(emp)~lag(log(emp),1)+lag(log(emp),2)+lag(log(wage),2)+lag(log(wage),3)+diff(capital,2)+diff(capital,3) log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) R a = dynformula(emp~wage+capital,log.form=list(capital=FALSE,TRUE),lag.form=list(emp=2,c(2,3)),diff.form=list(FALSE,capital=TRUE)) R grun.fe - plm(formula = a,data=EmplUK,model=within) [1] 1031 2 R summary(grun.fe) Oneway (individual) effect Within Model Call: plm(formula = a, data = EmplUK, model = within) Unbalanced Panel: n=140, T=7-9, N=1031 Residuals : Min. 1st Qu. Median 3rd Qu. Max. -17.1000 -0.3060 0.0137 0.3070 27.3000 Coefficients : Estimate Std. Error t-value Pr(|t|) wage -0.143626 0.032790 -4.3802 1.186e-05 *** capital 0.801495 0.064088 12.5062 2.2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Total Sum of Squares: 5030.6 Residual Sum of Squares: 4207.8 F-statistic: 86.9179 on 2 and 889 DF, p-value: 2.22e-16 2009/11/27 David Winsemius dwinsem...@comcast.net On Nov 27, 2009, at 10:25 AM, Owen Powell wrote: Hello list, I'm following the paper (http://www.jstatsoft.org/v27/i02/paper) on how to use plm to run panel regressions, and am having trouble with what I believe should be something very basic. When I run the command (p.9 in the paper): R dynformula(emp~wage+capital,log=list(capital=FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) Perhaps you could have read the help page for the current version of the package which says the argument have been modified. Using the current arguments: dynformula(emp~wage+capital,log.form=list(capital=FALSE,TRUE),lag.form=list(emp=2,c(2,3)),diff.form=list(FALSE,capital=TRUE)) log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) -- David Winsemius, MD I see: emp ~ wage + capital rather than the complete model that is given in the paper: log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) And indeed, when I try to run a regression using that formula, it appears to not contain any lags or logs (output below). Any ideas? Thanks in advance, ~Owen -- Owen Powell http://center.uvt.nl/phd_stud/powell R library(plm) R data(EmplUK, package=plm) R a = dynformula(emp~wage+capital,log=list(capital=FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) snipped David Winsemius, MD Heritage Laboratories West Hartford, CT -- Owen Powell http://center.uvt.nl/phd_stud/powell David Winsemius, MD Heritage Laboratories West Hartford, CT -- Owen Powell http://center.uvt.nl/phd_stud/powell __ 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] problem with dynformula from plm package [RE-POST]
You might also note that the authors hint on the help page that one might want to use the formula() operation on the result of dynformula. Following that path would have gotten us to a more successful conclusion. grun.fe - plm(formula = formula(a),data=EmplUK) grun.fe Model Formula: log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) Coefficients: lag(log(emp), 1) lag(log(emp), 2) lag(log(wage), 2) lag(log(wage), 3) diff(capital, 2) 0.8678675-0.1936447-0.1632724 0.3200785 0.0037612 diff(capital, 3) 0.0137866 -- David. On Nov 27, 2009, at 12:04 PM, Owen Powell wrote: Hi David, Thank you for the response. I forgot to mention that I'd already tried what (I think) you propose (adding .form to the end of the lag, log and diff) and I still see the same results (posted below). Specifically, I still see no lags, logs or diffs in my model. Any other ideas? ~Owen R rm(list = ls()) R options(prompt= R ) R library(plm) R data(EmplUK, package=plm) R EmplUK - plm.data(EmplUK, index = c(firm, year)) R log(emp)~lag(log(emp),1)+lag(log(emp),2)+lag(log(wage), 2)+lag(log(wage),3)+diff(capital,2)+diff(capital,3) log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) R a = dynformula(emp~wage + capital ,log .form = list (capital = FALSE ,TRUE),lag.form=list(emp=2,c(2,3)),diff.form=list(FALSE,capital=TRUE)) R grun.fe - plm(formula = a,data=EmplUK,model=within) [1] 10312 R summary(grun.fe) Oneway (individual) effect Within Model Call: plm(formula = a, data = EmplUK, model = within) Unbalanced Panel: n=140, T=7-9, N=1031 Residuals : Min. 1st Qu. Median 3rd Qu. Max. -17.1000 -0.3060 0.0137 0.3070 27.3000 Coefficients : Estimate Std. Error t-value Pr(|t|) wage-0.143626 0.032790 -4.3802 1.186e-05 *** capital 0.801495 0.064088 12.5062 2.2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Total Sum of Squares:5030.6 Residual Sum of Squares: 4207.8 F-statistic: 86.9179 on 2 and 889 DF, p-value: 2.22e-16 2009/11/27 David Winsemius dwinsem...@comcast.net On Nov 27, 2009, at 10:25 AM, Owen Powell wrote: Hello list, I'm following the paper (http://www.jstatsoft.org/v27/i02/paper) on how to use plm to run panel regressions, and am having trouble with what I believe should be something very basic. When I run the command (p.9 in the paper): R dynformula(emp~wage + capital ,log = list (capital =FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) Perhaps you could have read the help page for the current version of the package which says the argument have been modified. Using the current arguments: dynformula(emp~wage + capital ,log .form = list (capital = FALSE ,TRUE ),lag.form=list(emp=2,c(2,3)),diff.form=list(FALSE,capital=TRUE)) log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) -- David Winsemius, MD I see: emp ~ wage + capital rather than the complete model that is given in the paper: log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) And indeed, when I try to run a regression using that formula, it appears to not contain any lags or logs (output below). Any ideas? Thanks in advance, ~Owen -- Owen Powell http://center.uvt.nl/phd_stud/powell R library(plm) R data(EmplUK, package=plm) R a = dynformula(emp~wage + capital ,log = list (capital =FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) snipped David Winsemius, MD Heritage Laboratories West Hartford, CT -- Owen Powell http://center.uvt.nl/phd_stud/powell David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] Modular inverses
I want to find the inverse of an integer k mod p (prime.) Is there a function that can do this for me? I know i could simply write (k^(p-2)) %% p, but i need to do this for large primes (above 100) and this gives the warning message: Warning message: probable complete loss of accuracy in modulus so this method does not work. Any ideas? Thanks, Samuel -- __ 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] problem with dynformula from plm package [RE-POST]
On Nov 27, 2009, at 12:04 PM, Owen Powell wrote: Hi David, Thank you for the response. I forgot to mention that I'd already tried what (I think) you propose (adding .form to the end of the lag, log and diff) and I still see the same results (posted below). Specifically, I still see no lags, logs or diffs in my model. Any other ideas? ~Owen R rm(list = ls()) R options(prompt= R ) R library(plm) R data(EmplUK, package=plm) R EmplUK - plm.data(EmplUK, index = c(firm, year)) R log(emp)~lag(log(emp),1)+lag(log(emp),2)+lag(log(wage), 2)+lag(log(wage),3)+diff(capital,2)+diff(capital,3) log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) R a = dynformula(emp~wage + capital ,log .form = list (capital = FALSE ,TRUE),lag.form=list(emp=2,c(2,3)),diff.form=list(FALSE,capital=TRUE)) R grun.fe - plm(formula = a,data=EmplUK,model=within) [1] 10312 If I instead use the results of dynformula in plm as copied as a string from the output, I get what appears to be more what one might expect: grun.fe - plm(log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(emp), + 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), + 3) + diff(capital, 2) + diff(capital, 3) ,data=EmplUK) grun.fe Model Formula: log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) Coefficients: lag(log(emp), 1) lag(log(emp), 2) lag(log(wage), 2) lag(log(wage), 3) diff(capital, 2) 0.8678675-0.1936447-0.1632724 0.3200785 0.0037612 diff(capital, 3) 0.0137866 It certainly appears that the function plm is not decoding its arguments as do most regression functions. Perhaps you should take up your concerns for this non-standard behavior up with the package authors? -- David. R summary(grun.fe) Oneway (individual) effect Within Model Call: plm(formula = a, data = EmplUK, model = within) Unbalanced Panel: n=140, T=7-9, N=1031 Residuals : Min. 1st Qu. Median 3rd Qu. Max. -17.1000 -0.3060 0.0137 0.3070 27.3000 Coefficients : Estimate Std. Error t-value Pr(|t|) wage-0.143626 0.032790 -4.3802 1.186e-05 *** capital 0.801495 0.064088 12.5062 2.2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Total Sum of Squares:5030.6 Residual Sum of Squares: 4207.8 F-statistic: 86.9179 on 2 and 889 DF, p-value: 2.22e-16 2009/11/27 David Winsemius dwinsem...@comcast.net On Nov 27, 2009, at 10:25 AM, Owen Powell wrote: Hello list, I'm following the paper (http://www.jstatsoft.org/v27/i02/paper) on how to use plm to run panel regressions, and am having trouble with what I believe should be something very basic. When I run the command (p.9 in the paper): R dynformula(emp~wage + capital ,log = list (capital =FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) Perhaps you could have read the help page for the current version of the package which says the argument have been modified. Using the current arguments: dynformula(emp~wage + capital ,log .form = list (capital = FALSE ,TRUE ),lag.form=list(emp=2,c(2,3)),diff.form=list(FALSE,capital=TRUE)) log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) -- David Winsemius, MD I see: emp ~ wage + capital rather than the complete model that is given in the paper: log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) And indeed, when I try to run a regression using that formula, it appears to not contain any lags or logs (output below). Any ideas? Thanks in advance, ~Owen -- Owen Powell http://center.uvt.nl/phd_stud/powell R library(plm) R data(EmplUK, package=plm) R a = dynformula(emp~wage + capital ,log = list (capital =FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) snipped David Winsemius, MD Heritage Laboratories West Hartford, CT -- Owen Powell http://center.uvt.nl/phd_stud/powell David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] problem with dynformula from plm package [RE-POST]
Hi David, Thank you for the response. I forgot to mention that I'd already tried what (I think) you propose (adding .form to the end of the lag, log and diff) and I still see the same results (posted below). Specifically, I still see no lags, logs or diffs in my model. Any other ideas? ~Owen R rm(list = ls()) R options(prompt= R ) R library(plm) R data(EmplUK, package=plm) R EmplUK - plm.data(EmplUK, index = c(firm, year)) R log(emp)~lag(log(emp),1)+lag(log(emp),2)+lag(log(wage),2)+lag(log(wage),3)+diff(capital,2)+diff(capital,3) log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) R a = dynformula(emp~wage+capital,log.form=list(capital=FALSE,TRUE),lag.form=list(emp=2,c(2,3)),diff.form=list(FALSE,capital=TRUE)) R grun.fe - plm(formula = a,data=EmplUK,model=within) [1] 10312 R summary(grun.fe) Oneway (individual) effect Within Model Call: plm(formula = a, data = EmplUK, model = within) Unbalanced Panel: n=140, T=7-9, N=1031 Residuals : Min. 1st Qu. Median 3rd Qu. Max. -17.1000 -0.3060 0.0137 0.3070 27.3000 Coefficients : Estimate Std. Error t-value Pr(|t|) wage-0.143626 0.032790 -4.3802 1.186e-05 *** capital 0.801495 0.064088 12.5062 2.2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Total Sum of Squares:5030.6 Residual Sum of Squares: 4207.8 F-statistic: 86.9179 on 2 and 889 DF, p-value: 2.22e-16 2009/11/27 David Winsemius dwinsem...@comcast.net On Nov 27, 2009, at 10:25 AM, Owen Powell wrote: Hello list, I'm following the paper (http://www.jstatsoft.org/v27/i02/paper) on how to use plm to run panel regressions, and am having trouble with what I believe should be something very basic. When I run the command (p.9 in the paper): R dynformula(emp~wage+capital,log=list(capital=FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) Perhaps you could have read the help page for the current version of the package which says the argument have been modified. Using the current arguments: dynformula(emp~wage+capital,log.form=list(capital=FALSE,TRUE),lag.form=list(emp=2,c(2,3)),diff.form=list(FALSE,capital=TRUE)) log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) -- David Winsemius, MD I see: emp ~ wage + capital rather than the complete model that is given in the paper: log(emp) ~ lag(log(emp), 1) + lag(log(emp), 2) + lag(log(wage), 2) + lag(log(wage), 3) + diff(capital, 2) + diff(capital, 3) And indeed, when I try to run a regression using that formula, it appears to not contain any lags or logs (output below). Any ideas? Thanks in advance, ~Owen -- Owen Powell http://center.uvt.nl/phd_stud/powell R library(plm) R data(EmplUK, package=plm) R a = dynformula(emp~wage+capital,log=list(capital=FALSE,TRUE),lag=list(emp=2,c(2,3)),diff=list(FALSE,capital=TRUE)) snipped David Winsemius, MD Heritage Laboratories West Hartford, CT -- Owen Powell http://center.uvt.nl/phd_stud/powell __ 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] Replace Values in Matrix
Hello, how to replace the NA by number zero? matrizt [,1] [,2] [,3][,4] [1,] 1.000NA NA NA [2,] 0.6717685 0.1453253 NA NA [3,] 0.3971276 0.1493241 0.14532526 NA [4,] 0.1493241 0.1453253 0.06795269 0.06217967 Thanks! Romildo __ 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] Replace Values in Matrix
Hi, Try this, matrizt[is.na(matrizt)] - 0 HTH, baptiste 2009/11/27 Romildo Martins romildo.mart...@gmail.com: Hello, how to replace the NA by number zero? matrizt [,1] [,2] [,3] [,4] [1,] 1.000 NA NA NA [2,] 0.6717685 0.1453253 NA NA [3,] 0.3971276 0.1493241 0.14532526 NA [4,] 0.1493241 0.1453253 0.06795269 0.06217967 Thanks! Romildo __ 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] Modular inverses
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of SJ Robson-Davis Sent: Friday, November 27, 2009 8:52 AM To: r-help@r-project.org Subject: [R] Modular inverses I want to find the inverse of an integer k mod p (prime.) Is there a function that can do this for me? I know i could simply write (k^(p-2)) %% p, but i need to do this for large primes (above 100) and this gives the warning message: Warning message: probable complete loss of accuracy in modulus so this method does not work. Any ideas? Brute force works: f-function(k, p) which(((1:(p-1))*k)%%p == 1) f(10,p=13) [1] 4 You can precompute the mapping from k to 1/k mod p if you will be working with the same p a lot. Use sapply() or mapply() if you will be working on a vector of k and p. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com Thanks, Samuel -- __ 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] using reshape to do ANOVA mixed models
Hi, I just started with R and I found that there are many options to rearrange the data to do mixed models. I want to use the reshape function. I have 2 between subject variables and one within. I was able to change the data structure but still - the result of the aov functions are calculating everything as a within subject. the table looks like this: SerialNobreedtreatmentdistance_1 distance_2 1 c57 dfp 235 3253 etc. I changed it to look like this: SerialNo breed treatmentexposure distance 1 c57 dfp 1 235 1 c57dfp2 3253 etc. Then I do: dt-aov(distance~(exposure*treatment*breed)+Error(SerialNo/exposure) + (treatment*breed), dataframe) what am I doing wrong? thank you. [[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] Replace Values in Matrix
matritz[is.na(matritz)] - 0 On Fri, Nov 27, 2009 at 04:15:45PM -0200, Romildo Martins wrote: Hello, how to replace the NA by number zero? matrizt [,1] [,2] [,3][,4] [1,] 1.000NA NA NA [2,] 0.6717685 0.1453253 NA NA [3,] 0.3971276 0.1493241 0.14532526 NA [4,] 0.1493241 0.1453253 0.06795269 0.06217967 Thanks! Romildo __ 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] Graphic Device - View/get all graphics
Hello, After some research, I didn't resolve my doubt yet... Maybe I didn't explain very well my question... So, I have a bootstrap simulation, but suppose just a simple part of my function: teste -function(x){ rw_mean_app-rnorm(x, mean = 10, sd = 2) rwy_mean_app-rnorm(x, mean = 10, sd = 2) rw_median_app_ori-rnorm(x, mean = 10, sd = 2) rw_median_app_mod-rnorm(x, mean = 10, sd = 2) histogram-par(mfrow=c(1,2),ask=TRUE) hist(rw_mean_app,main='Method RWOriginal',xlab='Mean',ylab=' ') hist(rwy_mean_app,main='Method RWY',xlab='Mean',ylab=' ') par(histogram) histogram-par(mfrow=c(1,2) ,ask=TRUE) hist(rw_median_app_ori,main='Method RWOriginal',xlab='Median',ylab=' ') hist(rw_median_app_mod,main='Method RWModified',xlab='Median',ylab=' ') par(histogram) } #END OF FUNCTION GRAF-teste(100) I cannot save rnorm objects in a list cause they are distribution from 1000 simulation... So, I would like to produce the graphics in my function and find out a way that I could save the graphics... I can save the object using the LIST procedure, but I dont know how I save an object that is a graphic... Listers, I just want some advices in order to make a research about what functions of R I could save the graphics in my function... Thanks again, Marcio MarcioRibeiro wrote: Hi Listers, I am producing some graphics that the commands are in a FUNCTION... The problem is that I end up viewing just last graphic and in my FUNCTION there are 4 graphics with the PAR command function... Like those below... How do I view/get the other 3 graphics? Any help? Thanks in advance... histogram-par(mfrow=c(1,2)) hist(rw_mean_app,main='Bootstrap Method RWOriginal',xlab='Mean',ylab=' ') hist(rwy_mean_app,main='Bootstrap Method RWY',xlab='Mean',ylab=' ') par(histogram) histogram-par(mfrow=c(1,3)) hist(rw_median_app_ori,main='Bootstrap Method RWOriginal',xlab='Median',ylab=' ') hist(rw_median_app_mod,main='Bootstrap Method RWModified',xlab='Median',ylab=' ') hist(rwy_median_app,main='Bootstrap Method RWY',xlab='Median',ylab=' ') par(histogram) -- View this message in context: http://old.nabble.com/Graphic-Device---View-get-all-graphics-tp26498560p26545221.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Build of XML package failed
Hi list, It may be a FAQ, but I searched the web and Uni of Newcastle Maths and Stats and R mailing list archive on this issue but was unable to find a solution. I would appreciate any pointer to help me solving this. I am using R version 2.10.0 (2009-10-26) on linux mandriva 2010.0 I tried to install the XML_2.6-0.tar.gz package both with install.packages('XML', dep=T) from within R and the R CMD INSTALL using a local tar.gz file. I am having the following error message (sorry it is partly in french): Dans le fichier inclus à partir de DocParse.c:13: Utils.h:175:2: attention : #warning Redefining COPY_TO_USER_STRING to use encoding from XML parser DocParse.c: In function notifyError: DocParse.c:1051: erreur: le format n'est pas une chaîne littérale et pas d'argument de format This last error message means: error: format not a string literal and no format arguments In the past when having such errors with other packages, I have been able to solve it with the help of this tip: http://mario79t.wordpress.com/2009/06/23/warning-format-not-a-string-literal-and-no-format-arguments/ and modifying the faulty source file accordingly. But in this specific case, I have been unable to find what to modify in the source file. Line 1051 in the DocParse.c source file only has the command WARN. I don't know anything about C programming and could not figure out what to modify in this case. I would appreciate any help on this issue. Best regards, Tito __ 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 reshape to do ANOVA mixed models
Or Duek wrote: Hi, I just started with R and I found that there are many options to rearrange the data to do mixed models. I want to use the reshape function. I have 2 between subject variables and one within. I was able to change the data structure but still - the result of the aov functions are calculating everything as a within subject. the table looks like this: SerialNobreedtreatmentdistance_1 distance_2 1 c57 dfp 235 3253 etc. I changed it to look like this: SerialNo breed treatmentexposure distance 1 c57 dfp 1 235 1 c57dfp2 3253 etc. Then I do: dt-aov(distance~(exposure*treatment*breed)+Error(SerialNo/exposure) + (treatment*breed), dataframe) what am I doing wrong? For a start, not showing us the output Also not showing us enough of the data and not convincing us that you are actually using the reshaped data frame. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ 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] Iteration idioms laziness
Hi all, I'm new to R. Having a functional background, I was wondering what's the idiomatic way to iterate. It seems that for loops are the default given there's no tail-call optimization. I'm curious to know whether there is a way to transform the following toy snippet into something that doesn't eat up gigabytes of memory (like it's for loop counterpart) using laziness: Reduce('+', seq(1,1e6)) Thanks! Best regards, A.S. __ 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] Build of XML package failed
Hi Luis. You can change the two lines PROBLEM buf WARN; to the one line warning(buf); That should compile. If not, please show us the compilation command for DocParse.c, i.e. all the arguments to the compiler, just above the error messages. D. Luis Tito de Morais wrote: Hi list, It may be a FAQ, but I searched the web and Uni of Newcastle Maths and Stats and R mailing list archive on this issue but was unable to find a solution. I would appreciate any pointer to help me solving this. I am using R version 2.10.0 (2009-10-26) on linux mandriva 2010.0 I tried to install the XML_2.6-0.tar.gz package both with install.packages('XML', dep=T) from within R and the R CMD INSTALL using a local tar.gz file. I am having the following error message (sorry it is partly in french): Dans le fichier inclus à partir de DocParse.c:13: Utils.h:175:2: attention : #warning Redefining COPY_TO_USER_STRING to use encoding from XML parser DocParse.c: In function ‘notifyError’: DocParse.c:1051: erreur: le format n'est pas une chaîne littérale et pas d'argument de format This last error message means: error: format not a string literal and no format arguments In the past when having such errors with other packages, I have been able to solve it with the help of this tip: http://mario79t.wordpress.com/2009/06/23/warning-format-not-a-string-literal-and-no-format-arguments/ and modifying the faulty source file accordingly. But in this specific case, I have been unable to find what to modify in the source file. Line 1051 in the DocParse.c source file only has the command WARN. I don't know anything about C programming and could not figure out what to modify in this case. I would appreciate any help on this issue. Best regards, Tito __ 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] Export kde object as shapefile
On Thu, Nov 26, 2009 at 6:56 PM, David Winsemius dwinsem...@comcast.net wrote: The situation that I see (after looking at the documentation for adehabit) is that for some as yet unarticulated reason, you have decided that the methods used in prior publications in your domain are not the best and you are going to invent new ones, There is nothing particularly cutting edge about wanting to estimate home range size from a utilization distribution - Worton (1987, 1989) applied kernel methods to estimate the UD and specifically home range size over 20 years ago. Based on the literature (Gitzen et al. 2006) and the spatial distribution of my data, it is reasonable to conclude the plug-in method of bandwidth selection is the best possible option. but you are as yet unable to provided a detailed specification or offer an implementation of the methods. Furthermore, you are unable even to manipulate the objects you have thus far created in service toward this effort. I never said I was a programmer. I simply asked if there was a way to convert a kde object into a spatial object (e.g. SpatialPixels, SpatialPolygons) for export into a GIS. Or, alternatively, to generate the 2-D spatial area underneath the 3-D utilisation distribution of a kde object. I am being somewhat harsh in my assessment because it seems that you really need is a statistical collaborator with whom you can bang ideas together and arrive, first at a more detailed rationale and plan, and then a forward effort using your data and his programming expertise to demonstrate the superiority of your method. That would seem to be most reasonably a joint effort with joint authorship as an outcome. Perhaps you are speculating beyond what is warranted under the circumstances. I'm sure this is well-intentioned, but perhaps it is not as appropriate as you would have wished. Tyler -- View this message in context: http://old.nabble.com/Export-kde-object-as-shapefile-tp26532782p26545381.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Graphic Device - View/get all graphics
I'm not entirely sure I understand the problem, but one possible solution would be to use some device like postscript that saves the graphics to a file. (Or some other device appropriate for your intended use and OS.) You could still save the data to a list if you wanted - just make it part of what your function returns. Sarah On Fri, Nov 27, 2009 at 12:10 PM, MarcioRibeiro mes...@pop.com.br wrote: Hello, After some research, I didn't resolve my doubt yet... Maybe I didn't explain very well my question... So, I have a bootstrap simulation, but suppose just a simple part of my function: teste -function(x){ rw_mean_app-rnorm(x, mean = 10, sd = 2) rwy_mean_app-rnorm(x, mean = 10, sd = 2) rw_median_app_ori-rnorm(x, mean = 10, sd = 2) rw_median_app_mod-rnorm(x, mean = 10, sd = 2) histogram-par(mfrow=c(1,2),ask=TRUE) hist(rw_mean_app,main='Method RWOriginal',xlab='Mean',ylab=' ') hist(rwy_mean_app,main='Method RWY',xlab='Mean',ylab=' ') par(histogram) histogram-par(mfrow=c(1,2) ,ask=TRUE) hist(rw_median_app_ori,main='Method RWOriginal',xlab='Median',ylab=' ') hist(rw_median_app_mod,main='Method RWModified',xlab='Median',ylab=' ') par(histogram) } #END OF FUNCTION GRAF-teste(100) I cannot save rnorm objects in a list cause they are distribution from 1000 simulation... So, I would like to produce the graphics in my function and find out a way that I could save the graphics... I can save the object using the LIST procedure, but I dont know how I save an object that is a graphic... Listers, I just want some advices in order to make a research about what functions of R I could save the graphics in my function... Thanks again, Marcio -- 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.
[R] my failing understanding ...
The following I do not understand, but then I did'nt really use S4 methods ... showMethods(plot) Function: plot (package graphics) x=ANY x=lmList.confint x=merMCMC (inherited from: x=ANY) plot(x=moda0MCMC) Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double' class(moda0MCMC) [1] merMCMC attr(,package) [1] lme4 Kjetil __ 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] Orthogonal regression in R
Dear R-Users! The most recent entries on orthogonal regression that I have found on this list date back to 2005. Is there, by now, any package available that allows for a multivariate orthogonal regression in R? Thanks and best regards. Georg georg.blind at gmx.net __ 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] Questions about use of multinomial for discrimination.
Dear All, I am looking at discriminating among several individuals based on a few variable sets (I think some variables do not make sense unless they are entered together, so I force them into the models together, hence datasets). I have done so with linear discriminant analysis (LDA) using MASS::lda, with acceptable results. However, one of my collaborators suggested I use multinomial regression instead. I think his suggestion is mainly concerned with the choice of which variables (sets) best describe the data. I have used a stepwise approach (using klaR::stepclass) using the proportion of correct classifications to choose among the sets of variables. However I've been suggested that use a method that will give out an AIC instead, that will penalize the use of more variables. I have never done multinomial regression, and am uncertain about some details. I am looking into using R for this, and function multinom from MASS in particular. In my previous analysis with LDA I have measured the proportion of correct classifications using a jackknife procedure (i.e. leaving each datum out of the LDA at a time, and using the obtained discriminant functions to classify it). I am thinking about doing the same with the multinomial regression. I would appreciate any ideas about if this may not be good for some reason. Also, with the LDA I have looked at how much better the discriminant functions are compared with random assignment of individual identity. To do this I randomly shuffle the categories prior to running the LDA, then run the LDA, and measure the proportion of correct classifications using the above described jackknife procedure. I run this for many iterations and compare the distribution of proportion of correct classifications obtained from random assignment, with the one I obtained initially. Again, I though about repeating this with the multinom. Is this unnecessary as another way of looking at this already included in the multinom function? Perhaps this is more of a general statistics question, that one about the use of R, but I would appreciate any helpful comments. Thank you in advance. Ricardo Antunes __ 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] Debugging the unexpected string constant error in the zp2ssg2.R
I posted the full extent of this question to Nabble, but essentially I'm having difficulty determining the route cause of the unexpected string constant error in the zp2ssg2.R (which I'm trying to port over from Octave). Here is my current Nabble posting: http://n2.nabble.com/Need-help-solving-the-unexpected-string-constant-error-td4077984.html Thanks for any insights and feedback. __ 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 combine matrix with sapply function?
I want an 'apply' function that can give me results by bind the result from each function call of g. Could somebody let me know how to do it? g-function(x){ if(x==1){ rbind(c(1,3,8)) } else if(x==2) { rbind(c(4,7,2), c(3,7,3)) #if I use line, sapply() below gives me a list #rbind(c(4,7,2)) #if I use this line, sapply() below gives me a matrix } else if(x==3) { rbind(c(4,3,1)) } } x=1:3 sapply(x,g) __ 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] [R-es] R en Windows 7 a 64 bits
Buenas noches César, Tal y como se estipula en la sección 8.1 de [1], la R 32-bits funciona en Windows 64-bits aunque con las limitaciones de RAM que todos conocemos (solo puedes usar hasta 4 GB de RAM en el mejor de los casos). Para instalarlo sólo descarga el ejecutable usual de CRAN, haz doble click y sigue el procedimiento de instalación como normalmente lo has hecho. Hasta donde tengo entendido no existe una versión disponible (gratuita) de R 64-bits, aunque esta puede adquirirse a través de REvolution Computing [2]. Ahora, si por el tipo de trabajo que realizas necesitas gran cantidad de RAM, entonces las plataformas Linux o Mac son buenas alternativas para ello. Espero sea de utilidad, Jorge Ivan Velez [1] http://cran.r-project.org/doc/manuals/R-admin.html http://cran.r-project.org/doc/manuals/R-admin.html[2] http://www.revolution-computing.com http://www.revolution-computing.com/ 2009/11/27 Cesar Escalante Buenas noches para cada uno. Me alegra saber que superamos los 200 usuarios y tengos expectativas con respecto a la I Conferencia de R-hispano en Murcia. No soy usuario de Linux por desconocimiento, algo que lamento. Debo instalar R en un equipo con Windows 7 a 64 bits. ¿Podrían indicarme por favor cómo instalarlo? ¿Se hace con el mismo archivo R-2.10.0-win32? ¿Debo cuidar o cambiar algo antes o después? Gracias de antemano por la amable atención. Saludos. César Escalante C. [[alternative HTML version deleted]] ___ R-help-es mailing list r-help...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es [[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] Export kde object as shapefile
I'm not a programmer either, if by programmer you mean one who took a computer science degree and is employed with some title that implies a creator of code. I am a user of software toward particular purposes. The purposes need to be defined in sufficiently specific manner to guide that activity and be used as a basis for successful completion of the task. -- David. On Nov 27, 2009, at 3:47 PM, T.D.Rudolph wrote: On Thu, Nov 26, 2009 at 6:56 PM, David Winsemius dwinsem...@comcast.net wrote: The situation that I see (after looking at the documentation for adehabit) is that for some as yet unarticulated reason, you have decided that the methods used in prior publications in your domain are not the best and you are going to invent new ones, There is nothing particularly cutting edge about wanting to estimate home range size from a utilization distribution - Worton (1987, 1989) applied kernel methods to estimate the UD and specifically home range size over 20 years ago. Based on the literature (Gitzen et al. 2006) and the spatial distribution of my data, it is reasonable to conclude the plug-in method of bandwidth selection is the best possible option. but you are as yet unable to provided a detailed specification or offer an implementation of the methods. Furthermore, you are unable even to manipulate the objects you have thus far created in service toward this effort. I never said I was a programmer. I simply asked if there was a way to convert a kde object into a spatial object (e.g. SpatialPixels, SpatialPolygons) for export into a GIS. Or, alternatively, to generate the 2-D spatial area underneath the 3-D utilisation distribution of a kde object. I am being somewhat harsh in my assessment because it seems that you really need is a statistical collaborator with whom you can bang ideas together and arrive, first at a more detailed rationale and plan, and then a forward effort using your data and his programming expertise to demonstrate the superiority of your method. That would seem to be most reasonably a joint effort with joint authorship as an outcome. Perhaps you are speculating beyond what is warranted under the circumstances. I'm sure this is well-intentioned, but perhaps it is not as appropriate as you would have wished. Tyler -- View this message in context: http://old.nabble.com/Export-kde-object-as-shapefile-tp26532782p26545381.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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 combine matrix with sapply function?
Peng Yu pengyu.ut at gmail.com writes: I want an 'apply' function that can give me results by bind the result from each function call of g. Could somebody let me know how to do it? g-function(x){ [snip] } x=1:3 sapply(x,g) do.call(rbind,sapply(x,g))? __ 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] my failing understanding ...
I get a different result, undoubtedly because I have different packages loaded: showMethods(plot) Function plot: not a generic function sessionInfo() R version 2.10.0 Patched (2009-10-29 r50258) x86_64-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] splines stats graphics grDevices utils datasets methods base other attached packages: [1] plm_1.2-1sandwich_2.2-1 zoo_1.5-8 MASS_7.3-3 Formula_0.2-0 [6] kinship_1.1.0-23 lattice_0.17-26 nlme_3.1-96 survival_2.35-7 loaded via a namespace (and not attached): [1] grid_2.10.0 tools_2.10.0 But I get a much longer and informative result with: methods(plot) -- David. On Nov 27, 2009, at 4:23 PM, Kjetil Halvorsen wrote: The following I do not understand, but then I did'nt really use S4 methods ... showMethods(plot) Function: plot (package graphics) x=ANY x=lmList.confint x=merMCMC (inherited from: x=ANY) plot(x=moda0MCMC) Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double' class(moda0MCMC) [1] merMCMC attr(,package) [1] lme4 Kjetil __ 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 Heritage Laboratories West Hartford, CT __ 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] my failing understanding ...
On Nov 27, 2009, at 9:39 PM, David Winsemius wrote: I get a different result, undoubtedly because I have different packages loaded: showMethods(plot) Function plot: not a generic function sessionInfo() R version 2.10.0 Patched (2009-10-29 r50258) x86_64-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] splines stats graphics grDevices utils datasets methods base other attached packages: [1] plm_1.2-1sandwich_2.2-1 zoo_1.5-8 MASS_7.3-3 Formula_0.2-0 [6] kinship_1.1.0-23 lattice_0.17-26 nlme_3.1-96 survival_2.35-7 loaded via a namespace (and not attached): [1] grid_2.10.0 tools_2.10.0 But I get a much longer and informative result with: methods(plot) As follow-up, I loaded lme4 (just guessing that was the package that was being used) and looked up merMCMC in R-search, finding that such objects were created with mcmcsamp. (I also noted that the methods available for such objects did NOT include plot, but they did include xyplot. So I made the sample object that is in the help page, and applied both plot and xyplot: xyplot(samp0) # plotted what I would expect from an MCMC object plot(samp0) Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double' plot(x=samp0) Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double' So my (posterior) hypothesis is that you are using the wrong plot function. -- David. -- David. On Nov 27, 2009, at 4:23 PM, Kjetil Halvorsen wrote: The following I do not understand, but then I did'nt really use S4 methods ... showMethods(plot) Function: plot (package graphics) x=ANY x=lmList.confint x=merMCMC (inherited from: x=ANY) plot(x=moda0MCMC) Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double' class(moda0MCMC) [1] merMCMC attr(,package) [1] lme4 Kjetil __ 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 Heritage Laboratories West Hartford, CT __ 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 Heritage Laboratories West Hartford, CT __ 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 compute Rolling analysis of Standard Deviation using ZOO package?
yeah, my mistake is that i did not make the data c into a zoo class. now the problem solved. thank you everybody 2009/11/27 Gabor Grothendieck ggrothendi...@gmail.com We will need a minimal reproducible example (as per last line on every message to r-help) to answer as trying it with made up data seems to work for me. If c is very long try cutting it down to the smallest you can get it to and still produce the error, e.g. cc - c[1:10] rollapply(cc, ...) and then post the output of dput(cc) Here is an example: library(zoo) c - zoo(1:100) rollapply(c, 10, sd, na.pad = TRUE, align = 'right') 123456 NA NA NA NA NA NA 789 10 11 12 NA NA NA 3.027650 3.027650 3.027650 13 14 15 16 17 18 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 19 20 21 22 23 24 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 25 26 27 28 29 30 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 31 32 33 34 35 36 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 37 38 39 40 41 42 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 43 44 45 46 47 48 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 49 50 51 52 53 54 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 55 56 57 58 59 60 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 61 62 63 64 65 66 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 67 68 69 70 71 72 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 73 74 75 76 77 78 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 79 80 81 82 83 84 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 85 86 87 88 89 90 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 91 92 93 94 95 96 3.027650 3.027650 3.027650 3.027650 3.027650 3.027650 97 98 99 100 3.027650 3.027650 3.027650 3.027650 R.version.string [1] R version 2.10.0 Patched (2009-11-21 r50532) packageDescription(zoo)$Version [1] 1.6-2 On Fri, Nov 27, 2009 at 2:19 AM, Saji Ren saji@gmail.com wrote: Hello: I want to get a rolling estimation of the stdev of my data. Searching the document, I found the function rollapply in the zoo package. For example, my series is c, and i want get a period of 10 days, so i write the command below: roll.sd = rollapply( c, 10, sd, na.pad = TRUE, align = 'right' ) but there is an error in it ,and the computing cannot be performed. Can anyone help? PLUS: I also found that there is a function called rollFun in package 'fSeries', but there isn't anymore. [[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] [R-es] R en Windows 7 a 64 bits
My apologies to all of you. I sent this email to the wrong email list :) Best, Jorge 2009/11/27 Jorge Ivan Velez Buenas noches César, Tal y como se estipula en la sección 8.1 de [1], la R 32-bits funciona en Windows 64-bits aunque con las limitaciones de RAM que todos conocemos (solo puedes usar hasta 4 GB de RAM en el mejor de los casos). Para instalarlo sólo descarga el ejecutable usual de CRAN, haz doble click y sigue el procedimiento de instalación como normalmente lo has hecho. Hasta donde tengo entendido no existe una versión disponible (gratuita) de R 64-bits, aunque esta puede adquirirse a través de REvolution Computing [2]. Ahora, si por el tipo de trabajo que realizas necesitas gran cantidad de RAM, entonces las plataformas Linux o Mac son buenas alternativas para ello. Espero sea de utilidad, Jorge Ivan Velez [1] http://cran.r-project.org/doc/manuals/R-admin.html http://cran.r-project.org/doc/manuals/R-admin.html[2] http://www.revolution-computing.com http://www.revolution-computing.com/ 2009/11/27 Cesar Escalante Buenas noches para cada uno. Me alegra saber que superamos los 200 usuarios y tengos expectativas con respecto a la I Conferencia de R-hispano en Murcia. No soy usuario de Linux por desconocimiento, algo que lamento. Debo instalar R en un equipo con Windows 7 a 64 bits. ¿Podrían indicarme por favor cómo instalarlo? ¿Se hace con el mismo archivo R-2.10.0-win32? ¿Debo cuidar o cambiar algo antes o después? Gracias de antemano por la amable atención. Saludos. César Escalante C. [[alternative HTML version deleted]] ___ R-help-es mailing list r-help...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es [[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] Debugging the unexpected string constant error in the zp2ssg2.R
Evidently it just needed a little more tweaking... http://n2.nabble.com/Need-help-solving-the-unexpected-string-constant-error-td4077984.html#a4078425 Hopefully all this will work out... - Original Message From: Jason Rupert jasonkrup...@yahoo.com To: R-help@r-project.org Sent: Fri, November 27, 2009 6:10:24 PM Subject: [R] Debugging the unexpected string constant error in the zp2ssg2.R I posted the full extent of this question to Nabble, but essentially I'm having difficulty determining the route cause of the unexpected string constant error in the zp2ssg2.R (which I'm trying to port over from Octave). Here is my current Nabble posting: http://n2.nabble.com/Need-help-solving-the-unexpected-string-constant-error-td4077984.html Thanks for any insights and feedback. __ 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] alternatives to mosiac plots and ?3D? mosiac plots
i had some great success with mosiacplots... http://stat.ethz.ch/R-manual/R-patched/library/graphics/html/mosaicplot.html http://stat.ethz.ch/R-manual/R-patched/library/graphics/html/mosaicplot.html ...does anyone know of any other hidden gems out there that allow you to examine the relationship among two or more categorical variables. Also is it possible to add a third dimension to a mosiac plot, as in adding a contour plot to it...if so how is it done? -- View this message in context: http://n4.nabble.com/alternatives-to-mosiac-plots-and-3D-mosiac-plots-tp865536p865536.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.