Re: [R] read.pnm question
On Mar 22, 2013, at 4:04, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: I am trying to replicate a cool example that I saw on the R-bloggers some time ago by kafka399. Here are the lines tI think may be causing the trouble: gray_file - read.pnm(path) pos[i,] - c(gray_file@grey) Hi Erin, This is basically impossible to debug as is -- though I do note you spell that color between white and black inconsistently; could you please put some effort into making a true reproducible example or, at the very least, linking to the project you are attempting to replicate? Michael http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example The warning error that I get is In rep(cellres, length=2): x is NULL so the result will be NULL Any suggestions would be much appreciated. Thanks, Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] spatstat error
Why do you first say min(Datos$x) and then give the numeric value of this minimum? Just delete all numerical values: danta=ppp(Datos$x, Datos$y, c(min(Datos$x), max(Datos$x)), c(min(Datos$y), max(Datos$y))) or if you really want to type the numeric constants (probably a bad idea) danta=ppp(Datos$x,Datos$y,c(1177842,1180213),c(1013581,1015575)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of papao Sent: Freitag, 22. März 2013 00:20 To: R-help@r-project.org Subject: [R] spatstat error Good day Im working with some coordinates, and want to create a PPP object, I found that error: Datos=read.table(puntos_texto.txt,dec=.,sep=\t,header=T) summary(Datos) id y x Min. : 1.0 Min. :1013581 Min. :1177842 1st Qu.: 821.2 1st Qu.:1014442 1st Qu.:1179658 Median :1641.5 Median :1014455 Median :1179670 Mean :1641.8 Mean :1014465 Mean :1179652 3rd Qu.:2462.8 3rd Qu.:1014473 3rd Qu.:1179680 Max. :3283.0 Max. :1015575 Max. :1180213 danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842,max(Datos$x)1180213),c(min(D atos$y)1013581,max(Datos$y)1015575)) Error: inesperado constante numérica en danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842 danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842,max(Datos$x)1180213),c(m in(Datos$y)1013581,max(Datos$y)1015575)) Error: inesperado string constante en danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842 danta=ppp(Datos$x,Datos$y,window=owin(c(min(Datos$x)1177842,max(Datos$x)1 180213),c(min(Datos$y)1013581,max(Datos$y)1015575))) Error: inesperado string constante en danta=ppp(Datos$x,Datos$y,window=owin(c(min(Datos$x)1177842 Thank you so much [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help on indicator variables
What Bill says, plus the fact that the default handling of logicals in modelling is to convert them to factors and then use treatment contrasts, which will effectively give you the right indicator variables automagically (This in contrast to SAS where you can confuse yourself by declaring a 0/1 variable as a CLASS variable): cond - rep(c(TRUE, FALSE),4) y - rnorm(8) lm(y~cond) Call: lm(formula = y ~ cond) Coefficients: (Intercept) condTRUE -0.5741 1.1845 lm(y~as.numeric(cond)) Call: lm(formula = y ~ as.numeric(cond)) Coefficients: (Intercept) as.numeric(cond) -0.57411.1845 On Mar 21, 2013, at 15:49 , William Dunlap wrote: I would use a logical variable, with values TRUE and FALSE, instead of a numeric indicator. E.g., I find the following easier to follow bL - ABS==1 | DEFF==1 if (any(bL)) { do.this() } than bN - ifelse(ABS == 1 | DEFF == 1, 1, 0) if (any(bN == 1)) { do.this() } The latter leaves me wondering what other values bN might have; the former makes it clear this is a TRUE/FALSE dichotomy. Logicals get converted to numbers (FALSE-0, TRUE-1) when used in arithmetic so you can do, e.g., mean(bL) to see what proportion of your cases satisfy the condition. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tasnuva Tabassum Sent: Thursday, March 21, 2013 6:03 AM To: R help Subject: [R] Help on indicator variables I have two indicator variables ABS and DEFF. I want to create another indicator variable which will take value 1 if either ABS=1 or DEFF=1. Otherwise, it will take value 0. How can I make that? [[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. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multiple peak fit
Thank you Jean Basically I know that it is possible, however it is quite sensitive to starting values and those 2 peaks do not provide perfect fit. There is probably third peak between those 2 (based on other results). But if I put third peak to nls I get an error fit - nls(sig ~ d + + a1*exp(-0.5*((time-c1)/b1)^2) + + a2*exp(-0.5*((time-c2)/b2)^2)+ + a3*exp(-0.5*((time-c3)/b3)^2), + start=list(a1=12.3, b1=18, c1=315, a2=.5, b2=80, c2=390, a3=3, b3=90, c3=480, d=1.5), data=temp) Error in nls(sig ~ d + a1 * exp(-0.5 * ((time - c1)/b1)^2) + a2 * exp(-0.5 * : singular gradient There has to be another option which seems ALS function is based on but the source is rather complicated for my math knowledge. Anyway, thank for your code. Petr From: Adams, Jean [mailto:jvad...@usgs.gov] Sent: Thursday, March 21, 2013 10:58 PM To: PIKAL Petr Cc: r-help@r-project.org Subject: Re: [R] multiple peak fit Petr, You could use nonlinear regression to fit two Guassian peaks. For example, fit - nls(sig ~ d + a1*exp(-0.5*((time-c1)/b1)^2) + a2*exp(-0.5*((time-c2)/b2)^2), start=list(a1=15, b1=20, c1=315, a2=4, b2=50, c2=465, d=1.5), data=temp) plot(temp, type=l) lines(temp$time, predict(fit), lty=2, col=red) Jean On Thu, Mar 21, 2013 at 8:17 AM, PIKAL Petr petr.pi...@precheza.czmailto:petr.pi...@precheza.cz wrote: Hi I went through some extensive search to find suitable method (package, function) to fit multiple peaks. The best I found is ALS package but it requires rather complicated input structure probably resulting from GC-MS experimental data and seems to be an overkill to my problem. I have basically simple two column data frame with columns time and sig dput(temp) structure(list(time = c(33, 34, 37.3, 44.7, 56, 70, 85, 99.7, 114, 127.3, 140, 151.7, 163, 174, 185, 196, 206.7, 217.3, 228, 238.7, 249.3, 260, 271, 282, 292.7, 303.7, 314.3, 325.3, 336, 346.7, 357.3, 368, 379, 389.7, 400.3, 411, 421.7, 432.3, 443, 454, 465, 476, 487, 497.7, 508.3, 519, 530, 541, 551.7, 562.3, 573, 584, 595, 606, 616.7, 627.3, 638, 649, 659.7, 670.3, 681, 692, 703, 713.7, 724.3, 735, 746, 757, 768, 779, 789), sig = c(1.558, 1.5549, 1.5619, 1.5614, 1.5618, 1.6044, 1.6161, 1.6287, 1.6432, 1.6925, 1.7273, 1.6932, 1.669, 1.6863, 1.6962, 1.7186, 1.7513, 1.8325, 1.9181, 2.01, 2.1276, 2.2821, 2.5596, 2.9844, 4.1272, 13.421, 15.422, 14.119, 11.491, 8.8799, 6.7774, 5.6223, 4.8775, 4.3628, 4.0517, 3.9146, 3.8704, 3.9162, 4.0372, 4.0948, 4.2054, 4.1221, 3.9145, 3.5724, 3.2108, 2.8311, 2.4605, 2.1985, 1.9685, 1.8158, 1.7487, 1.692, 1.6565, 1.6374, 1.609, 1.5927, 1.5401, 1.5366, 1.5614, 1.5314, 1.4989, 1.5053, 1.4953, 1.4824, 1.4743, 1.4468, 1.4698, 1.4671, 1.4675, 1.4704, 1.4966)), .Names = c(time, sig), row.names = c(NA, -71L), class = data.frame) When it is plotted there are clearly 2 peaks visible. plot(temp, type=l) Does anybody know how to decompose those data to two (or more) gaussian (or other) peaks? I can only think about nlme but before I start from scratch I try to ask others. Best regards Petr __ R-help@r-project.orgmailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] holding argument(s) fixed within lapply
For the record, one may also nest one do.call within another, e.g. via functional::Curry lapply(X = mylist2, FUN = do.call, what = Curry(FUN = f2, y = Y) ) On 03/13/2013 12:22 PM, Blaser Nello wrote: One way is to use the do.call function. For example: ret2 - lapply(X=mylist2, FUN=do.call, what=function(...) f2(y=Y, ...)) Best, Nello -Original Message- Date: Tue, 12 Mar 2013 22:37:52 -0400 From: Benjamin Tyner bty...@gmail.com To: r-help@r-project.org Subject: Re: [R] holding argument(s) fixed within lapply Message-ID: 513fe680.2070...@gmail.com Content-Type: text/plain; charset=iso-8859-1 Apologies; resending in plain text... Given a function with several arguments, I would like to perform an lapply (or equivalent) while holding one or more arguments fixed to some common value, and I would like to do it in as elegant a fashion as possible, without resorting to wrapping a separate wrapper for the function if possible. Moreover I would also like it to work in cases where one or more arguments to the original function has a default binding. # Here is an example; the original function f - function(w, y, z){ w + y + z } # common value I would like y to take Y - 5 # I have a list of arguments for the lapply() mylist - list(one = list(w = 1, z = 2), two = list(w = 3, z = 4) ) # one way to do it involves a custom wrapper; I do not like this method ret - lapply(FUN = function(x,...) f(w = x$w, z = x$z, ...), X = mylist, y = Y ) # another way ret - lapply(FUN = with.default, X= mylist, expr = f(w, y = Y, z) ) # yet another way ret - lapply(FUN = eval, X= mylist, expr = substitute(f(w, y = Y, z)) ) # now, the part I'm stuck on is for a version of f where z has a default binding f2 - function(w, y, z = 0){ w + y + z } # the same as mylist, but now z is optional mylist2 - list(one = list(w = 1), two = list(w = 3, z = 4) ) # undesired result (first element has length 0) ret2 - lapply(FUN = function(x,...) f2(w = x$w, z = x$z, ), X = mylist2, y = Y ) # errors out ('z' not found) ret2 - lapply(FUN = with.default, X= mylist2, expr = f2(w, y = Y, z) ) # errors out again ret2 - lapply(FUN = eval, X= mylist2, expr = substitute(f2(w, y = Y, z)) ) # not quite... ret2 - lapply(FUN = gtools::defmacro(y = Y, expr = f2(w, y = Y, z)), X = mylist2 ) It seems like there are many ways to skin this cat; open to any and all guidance others care to offer. Regards, Ben __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] basic sweave question
I typically run R CMD Sweave which resolves issues with style files in directories unknown to your LaTeX distribution. Best, Uwe Ligges On 21.03.2013 18:44, lgh0504 wrote: The pdflatex is the an excutable programe located in your MiKTex‘ bin folder, I guess you have not add your MikTex bin folder into your Windows PATH environment On Thu, Mar 14, 2013 at 12:55 AM, susieboyce [via R] ml-node+s789695n4661220...@n4.nabble.com wrote: I have located my Sweave.sty in my R program files and I've tried copying and pasting this into many folders in the C/.../MiKTeX/tex/latex environment, including making a new folder called 'Sweave' and storing in here and still my .tex file gives me an error when I try to compile it. What is this pdflatex? Is it an R command? If so, what package is it in? Where does this go? In the original .rnw file, do you type this into R or somewhere else?: pdflatex --include-directory=C:\Program Files\R\R-2.14.0\share\texmf\tex\latex your_tex.tex -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/basic-sweave-question-tp876734p4661220.html To unsubscribe from basic sweave question, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=876734code=bGdoMDUwNEBnbWFpbC5jb218ODc2NzM0fC0xODczMTIwODc1 . NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://r.789695.n4.nabble.com/basic-sweave-question-tp876734p4662100.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sen's slope - fume package different output than zyp or wq
On 22.03.2013 01:09, Abby Frazier wrote: Hello, I am trying to decide which package to use to calculate the non-parametric Sen's Slope for identifying trends in rainfall data (determine the slope between all pairs of points and take the median of those slopes). I have found three packages that output Sen's: zyp, wq and fume. The outputs of zyp.sen() and mannKen() from the zyp and wq packages match, but the output from fume's mkTrend is different. I tried looking at the code from these three and I could not really understand what zyp and wq are doing differently. It seems like fume is the only package that calculates a corrected Mann Kendall p-value based on temporal autocorrelation, so I would like to use this package to calculate my p-values, but I am cautious because if the calculations for Sen's are incorrect, maybe the corrected p-value is not correct either? Please let me know if I should provide some examples - but the discrepancies seem to show up in any dataset I use. Thanks! I'd start to discuss inaccuracies or errors you found with the package maintainer in in case your are still in doubt look into the source code. Best, Uwe Ligges Abby [[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] fisher.alpha warnings
Kulupp kulupp at online.de writes: I have two vectors (a and b) with counts of animals and wanted to calculate fisher's alpha: library(vegan) a - c(2043, 1258, 52, 1867, 107, 1624, 2, 157, 210, 402, 5, 107, 267, 2, 13683) b - c(2043, 1258, 52, 1867, 107, 1624, 2, 157, 210, 402, 5, 107, 267, 2, 3000) fisher.alpha(a) fisher.alpha(b) fisher.alpha(a) gave the following warnings: fisher.alpha(a) [1] 1.572964 Warnmeldungen: 1: In log(p) : NaNs wurden erzeugt 2: In log(1 - x) : NaNs wurden erzeugt 3: In nlm(Dev.logseries, n.r = n.r, p = p, N = N, hessian = TRUE, ...) : NA/Inf durch größte positive Zahl ersetzt fisher.alpha(b) gave no warnings (note: only the last number in the vector 'b' differs from 'a'!) Why did vector 'a' gave warnings and what does that mean for the validity of the calculated alpha-value? Dear Kulupp, It gives the warning because it uses non-linear iterative methods in solving Fisher's alpha, and it took too long a step so that at one stage it studied negative alpha. That gives a warning. In general, it may be difficult to say how this influences the results. It seems that in this case the initial estimate of the starting value of alpha was too high, and the next iteration was over-corrected to a negative value. It also seems that the estimation recovered from this bad step. It is difficult to say when there is no need to worry. However, if you use fucntion fisherfit() instead of its wrapper, fisher.alpha(), you can plot the profile close to the solution: plot(profile(fisherfit(a))) The profile() function may be able to find cases where the solution was really bad and a better solution could be found nearby. In this case the situation looks good. Best wishes, Jari Oksanen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Trouble embedding functions (e.g., deltaMethod) in other functions
Dear R community, I've been writing simple functions for the past year and half and have come across a similar problem several times. The execution of a function within my own function produces NaN's or fails to execute as intended. My conundrum is that I can execute the function outside of my function without error, so it's difficult for me, as a novice functioneer, to figure out what's going wrong. Here's my example for deltaMethod(): t - c(0.0, 26.24551, 61.78180, 86.88254, 221.75480) m - c(48.591707, 15.655895, 12.284635, 5.758547, 0.00) dat - data.frame(t = t, m = m) m0 - m[1] t0 - t[5] nlls - nls(m ~ (m0^(1/lambda) - (t * m0/t0)^(1/lambda))^lambda, start = list(lambda = 1), data = dat) xVal - seq(0, t0, length = 10) mod.SE - list() for(i in 1:length(xVal)){ z - xVal[i] mod.SE[[i]] - deltaMethod(nlls, (m0^(1/lambda) - (z * m0/t0)^(1/lambda))^lambda)$SE } mod.SE This code executes deltaMethod() flawlessly (NOTE: [[1]] and [[10]] are supposed to be NaN's). However, my goal is to embed the deltaMethod inside another function I'm writing. For brevity's sake, here's a very simple example that produces the same problem. deltaSE - function(mod, x){ mod.SE - list() for(i in 1:length(xVal)){ z - xVal[i] mod.SE[[i]] - deltaMethod(mod, (m0^(1/lambda) - (z * m0/t0)^(1/lambda))^lambda)$SE } mod.SE } deltaSE(nlls, xVal) deltaMethod, when embedded in my deltaSE function produces only NaN's. When I debug(deltaSE) and debug(deltaMethod), and then debug(deltaMethod.default) once delta method is debugging within deltaSE, I can see that eval() is producing a value of 0 for the estimate value of m. An m of 0 indeed would produce an NaN. I'm just not sure why this function is performing differently inside and outside my function. Any help for a lowly functioneer would be great! Patrick -- View this message in context: http://r.789695.n4.nabble.com/Trouble-embedding-functions-e-g-deltaMethod-in-other-functions-tp4662178.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] trouble with data frame
Hi everyone, I am trying to use the values from every cell of the data frame in a further calculation. This is the code that I am using to catch every element of the data-frame. while (a=10) { while (b=10) { n-as.numeric(df[a,b)]; ...; } } The problem is that when I print out 'n' I get the following errors : NULL (if printed without as.numeric), and numeric(0) if printed with the as.numeric. Again, if I use the same command without the loop, it gives the correct answer. Would be grateful for your inputs and ideas on this matter. Thanks in advance, Sahana. [[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] trouble with data frame
Sahana, The notation df[a,b)] is plain wrong. I think you meant (but I may be mistaken) df[a, b] and I am not still sure if that would work in your example. Have you instead considered subset()? E.g., subset(df, a = 10 b = 10) See ?subset for more details. Also, df is a very bad name for your data.frame. Check ?df to know why. HTH, Jorge.- On Fri, Mar 22, 2013 at 10:34 PM, Sahana Srinivasan wrote: Hi everyone, I am trying to use the values from every cell of the data frame in a further calculation. This is the code that I am using to catch every element of the data-frame. while (a=10) { while (b=10) { n-as.numeric(df[a,b)]; ...; } } The problem is that when I print out 'n' I get the following errors : NULL (if printed without as.numeric), and numeric(0) if printed with the as.numeric. Again, if I use the same command without the loop, it gives the correct answer. Would be grateful for your inputs and ideas on this matter. Thanks in advance, Sahana. [[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] trouble with data frame
On 22-03-2013, at 12:34, Sahana Srinivasan sahanasrinivasan...@gmail.com wrote: Hi everyone, I am trying to use the values from every cell of the data frame in a further calculation. This is the code that I am using to catch every element of the data-frame. while (a=10) { while (b=10) { n-as.numeric(df[a,b)]; The )] should be ]). ...; } } The problem is that when I print out 'n' I get the following errors : NULL (if printed without as.numeric), and numeric(0) if printed with the as.numeric. Again, if I use the same command without the loop, it gives the correct answer. Would be grateful for your inputs and ideas on this matter. Thanks in advance, Data? Reproducible example? Without the contents of your dataframe no sensible answer can be given. E.g. use dput(head(df)) Berend Sahana. [[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] Trouble embedding functions (e.g., deltaMethod) in other functions
Here is what you sent: deltaSE - function(mod, x){ mod.SE - list() for(i in 1:length(xVal)){ z - xVal[i] mod.SE[[i]] - deltaMethod(mod, (m0^(1/lambda) - (z * m0/t0)^(1/lambda))^lambda)$SE } mod.SE } deltaSE(nlls, xVal) but within the function, there is no 'xVal'; did you really mean 'x' as in: deltaSE - function(mod, x){ mod.SE - list() for(i in 1:length(x)){ z - x[i] mod.SE[[i]] - deltaMethod(mod, (m0^(1/lambda) - (z * m0/t0)^(1/lambda))^lambda)$SE } mod.SE } deltaSE(nlls, xVal) On Fri, Mar 22, 2013 at 7:28 AM, PatGauthier pgaut...@lakeheadu.ca wrote: Dear R community, I've been writing simple functions for the past year and half and have come across a similar problem several times. The execution of a function within my own function produces NaN's or fails to execute as intended. My conundrum is that I can execute the function outside of my function without error, so it's difficult for me, as a novice functioneer, to figure out what's going wrong. Here's my example for deltaMethod(): t - c(0.0, 26.24551, 61.78180, 86.88254, 221.75480) m - c(48.591707, 15.655895, 12.284635, 5.758547, 0.00) dat - data.frame(t = t, m = m) m0 - m[1] t0 - t[5] nlls - nls(m ~ (m0^(1/lambda) - (t * m0/t0)^(1/lambda))^lambda, start = list(lambda = 1), data = dat) xVal - seq(0, t0, length = 10) mod.SE - list() for(i in 1:length(xVal)){ z - xVal[i] mod.SE[[i]] - deltaMethod(nlls, (m0^(1/lambda) - (z * m0/t0)^(1/lambda))^lambda)$SE } mod.SE This code executes deltaMethod() flawlessly (NOTE: [[1]] and [[10]] are supposed to be NaN's). However, my goal is to embed the deltaMethod inside another function I'm writing. For brevity's sake, here's a very simple example that produces the same problem. deltaSE - function(mod, x){ mod.SE - list() for(i in 1:length(xVal)){ z - xVal[i] mod.SE[[i]] - deltaMethod(mod, (m0^(1/lambda) - (z * m0/t0)^(1/lambda))^lambda)$SE } mod.SE } deltaSE(nlls, xVal) deltaMethod, when embedded in my deltaSE function produces only NaN's. When I debug(deltaSE) and debug(deltaMethod), and then debug(deltaMethod.default) once delta method is debugging within deltaSE, I can see that eval() is producing a value of 0 for the estimate value of m. An m of 0 indeed would produce an NaN. I'm just not sure why this function is performing differently inside and outside my function. Any help for a lowly functioneer would be great! Patrick -- View this message in context: http://r.789695.n4.nabble.com/Trouble-embedding-functions-e-g-deltaMethod-in-other-functions-tp4662178.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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[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] trouble with data frame
Le 22/03/13 12:34, Sahana Srinivasan a écrit : while (a=10) { while (b=10) { n-as.numeric(df[a,b)]; ...; } } The problem is that when I print out 'n' I get the following errors : NULL (if printed without as.numeric), and numeric(0) if printed with the as.numeric. Perhaps with n-as.numeric(df[a,b]) )] are reversed Marc -- __ Marc Girondot, Pr Laboratoire Ecologie, Systématique et Evolution Equipe de Conservation des Populations et des Communautés CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079 Bâtiment 362 91405 Orsay Cedex, France Tel: 33 1 (0)1.69.15.72.30 Fax: 33 1 (0)1.69.15.73.53 e-mail: marc.giron...@u-psud.fr Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html Skype: girondot __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] read.pnm question
In R-beta (Masked Marvel), when I do the example from the read.pnm help file, this is what happens: x - read.pnm(system.file(pictures/logo.pgm,package=pixmpap)[1]) Warning message: In rep(cellres, length=2): x is NULL so the result will be NULL In R-2.15.3, it's all right. Thanks, Erin On Fri, Mar 22, 2013 at 2:13 AM, Michael Weylandt michael.weyla...@gmail.com wrote: On Mar 22, 2013, at 4:04, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: I am trying to replicate a cool example that I saw on the R-bloggers some time ago by kafka399. Here are the lines tI think may be causing the trouble: gray_file - read.pnm(path) pos[i,] - c(gray_file@grey) Hi Erin, This is basically impossible to debug as is -- though I do note you spell that color between white and black inconsistently; could you please put some effort into making a true reproducible example or, at the very least, linking to the project you are attempting to replicate? Michael http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example The warning error that I get is In rep(cellres, length=2): x is NULL so the result will be NULL Any suggestions would be much appreciated. Thanks, Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Trouble embedding functions (e.g., deltaMethod) in other functions
Ah Yes, good point. However, it still does not correct the situation. I still get NaN's. -- View this message in context: http://r.789695.n4.nabble.com/Trouble-embedding-functions-e-g-deltaMethod-in-other-functions-tp4662178p4662187.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] order statistic of multivariate normal
Thank you all for the reply. One example of my question is as follows. Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. My question is that whether there is a R function that would help compute the c which satisfies P(X(4) c)=beta. Here beta is a known constant between 0 and 1. Thank you. Hanna 2013/3/21 Rui Barradas ruipbarra...@sapo.pt Hello, Em 21-03-2013 21:42, Albyn Jones escreveu: R^n for n 1 is not an ordered set. Theorem. All sets are well ordered. (This theorem is equivalent to the Axiom of Choice.) Rui Barradas albyn On Thu, Mar 21, 2013 at 02:32:44PM -0700, David Winsemius wrote: On Mar 21, 2013, at 1:44 PM, li li wrote: Hi all, Is there an R function that computes the probabilty or quantiles of order statistics of multivariate normal? Thank you. There is an mvtnorm package. I don't know what you mean by quantiles of order statistics of multivariate normal, though. -- David Winsemius Alameda, CA, USA __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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] Trouble embedding functions (e.g., deltaMethod) in other functions
Instead of NaN's, I get the error message: Error in eval(expr, envir, enclos) : object 'z' not found. The reason you get the NaN's is, because you defined z in your global environment. The deltaMethod doesn't find the z defined in your function. I don't know why or how to fix this. Somebody with more R experience could probably do this. But if you look at the source code of deltaMethod you can solve the problem in your specific case with these function. deltaMethod2 - function(object, g, vcov., z, ...){ if (!is.character(g)) stop(The argument 'g' must be a character string) if ((car:::exists.method(coef, object, default = FALSE) || (!is.atomic(object) !is.null(object$coefficients))) car:::exists.method(vcov, object, default = FALSE)) { if (missing(vcov.)) vcov. - vcov(object) object - coef(object) } para - object para.names - names(para) g - parse(text = g) q - length(para) for (i in 1:q) { assign(names(para)[i], para[i]) } est - eval(g) names(est) - NULL gd - rep(0, q) for (i in 1:q) { gd[i] - eval(D(g, names(para)[i])) } se.est - as.vector(sqrt(t(gd) %*% vcov. %*% gd)) data.frame(Estimate = est, SE = se.est) } deltaSE - function(mod, x){ mod.SE - list() for(i in 1:length(x)){ z - x[i] mod.SE[[i]] - deltaMethod2(mod, g=(m0^(1/lambda) - (z * m0/t0)^(1/lambda))^lambda, z=z)$SE } mod.SE } deltaSE(nlls, xVal) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of PatGauthier Sent: Freitag, 22. März 2013 13:54 To: r-help@r-project.org Subject: Re: [R] Trouble embedding functions (e.g., deltaMethod) in other functions Ah Yes, good point. However, it still does not correct the situation. I still get NaN's. -- View this message in context: http://r.789695.n4.nabble.com/Trouble-embedding-functions-e-g-deltaMethod-in-other-functions-tp4662178p4662187.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] read.pnm question
On Mar 22, 2013, at 13:21 , Erin Hodgess wrote: In R-beta (Masked Marvel), when I do the example from the read.pnm help file, this is what happens: x - read.pnm(system.file(pictures/logo.pgm,package=pixmpap)[1]) pixmpap? Any chance of a typo? -pd Warning message: In rep(cellres, length=2): x is NULL so the result will be NULL In R-2.15.3, it's all right. Thanks, Erin On Fri, Mar 22, 2013 at 2:13 AM, Michael Weylandt michael.weyla...@gmail.com wrote: On Mar 22, 2013, at 4:04, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: I am trying to replicate a cool example that I saw on the R-bloggers some time ago by kafka399. Here are the lines tI think may be causing the trouble: gray_file - read.pnm(path) pos[i,] - c(gray_file@grey) Hi Erin, This is basically impossible to debug as is -- though I do note you spell that color between white and black inconsistently; could you please put some effort into making a true reproducible example or, at the very least, linking to the project you are attempting to replicate? Michael http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example The warning error that I get is In rep(cellres, length=2): x is NULL so the result will be NULL Any suggestions would be much appreciated. Thanks, Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] order statistic of multivariate normal
On 22-Mar-2013 13:02:25 li li wrote: Thank you all for the reply. One example of my question is as follows. Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. My question is that whether there is a R function that would help compute the c which satisfies P(X(4) c)=beta. Here beta is a known constant between 0 and 1. Thank you. Hanna The basic question which needs to be answered (which has been hinted at in earlier replis) is: How do you define order statistic for multivariate observations? For example, here is a sample of 10 (to 3 d.p.) from a bivariate normal distribution: [,1] [,2] [1,] 1.143 -0.396 [2,] -0.359 -0.217 [3,] -0.391 -0.601 [4,] -0.416 -1.093 [5,] -1.810 -1.499 [6,] -0.367 -0.636 [7,] -2.238 0.563 [8,] 0.811 1.230 [9,] 0.082 0.174 [10,] -1.359 -0.364 Which one of these 10 rows is X(4)? There is an alternative interpretation of your question: Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. This could mean that the vector (X1,...,X10) has a multivariate normal distribution with 10 dimensions, and, for a single vector (X1,...,X10) drawn from this distribution, (X(1), ..., X(10)) is a vector consisting of these same values (X1,...,X10), but in increasing order. Is that what you mean? Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 22-Mar-2013 Time: 13:31:31 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] read.pnm question
This is off-topic in this forum. Please go to R-devel for questions about R-beta. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Erin Hodgess erinm.hodg...@gmail.com wrote: In R-beta (Masked Marvel), when I do the example from the read.pnm help file, this is what happens: x - read.pnm(system.file(pictures/logo.pgm,package=pixmpap)[1]) Warning message: In rep(cellres, length=2): x is NULL so the result will be NULL In R-2.15.3, it's all right. Thanks, Erin On Fri, Mar 22, 2013 at 2:13 AM, Michael Weylandt michael.weyla...@gmail.com wrote: On Mar 22, 2013, at 4:04, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: I am trying to replicate a cool example that I saw on the R-bloggers some time ago by kafka399. Here are the lines tI think may be causing the trouble: gray_file - read.pnm(path) pos[i,] - c(gray_file@grey) Hi Erin, This is basically impossible to debug as is -- though I do note you spell that color between white and black inconsistently; could you please put some effort into making a true reproducible example or, at the very least, linking to the project you are attempting to replicate? Michael http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example The warning error that I get is In rep(cellres, length=2): x is NULL so the result will be NULL Any suggestions would be much appreciated. Thanks, Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Distance calculation
Hi Elisa, I hope this is what you wanted. dat1-read.csv(peaks.csv,sep=,) #Subset dat2-dat1[1:5,] res1-do.call(cbind,lapply(seq_len(nrow(dat2)),function(i) do.call(rbind,lapply(split(rbind(dat2[i,],dat2[-i,]),1:nrow(rbind(dat2[i,],dat2[-i,]))), function(x) {x1-rbind(dat2[i,],x); abs((x1$Peak1.v.[1]-x1$Peak1.v.[2])*(x1$Peak1.t.[1]-x1$Peak1.t.[2]))+abs((x1$Peak2.v.[1]-x1$Peak2.v.[2])*(x1$Peak2.t.[1]-x1$Peak2.t.[2]))+abs((x1$Npeak1.v.[1]-x1$Npeak1.v.[2])*(x1$Npeak1.t.[1]-x1$Npeak1.t.[2]))+abs((x1$Npeak2.v.[1]-x1$Npeak2.v.[2])*(x1$Npeak2.t.[1]-x1$Npeak2.t.[2]))} res2-do.call(cbind,lapply(seq_len(ncol(res1)),function(i) c(c(tail(res1[seq(1,i,1),i],-1),0),res1[-c(1:i),i]))) row.names(res2)-1:nrow(res2) res2 # [,1] [,2] [,3] [,4] [,5] #1 0. 0. 0. 379.1364 0. #2 0. 0. 0. 312.8267 0. #3 0. 0. 0. 379.6576 0. #4 379.1364 312.8267 379.6576 0. 324.4063 #5 0. 0. 0. 324.4063 0. resWhole-do.call(cbind,lapply(seq_len(nrow(dat1)),function(i) do.call(rbind,lapply(split(rbind(dat1[i,],dat1[-i,]),1:nrow(rbind(dat1[i,],dat1[-i,]))), function(x) {x1-rbind(dat1[i,],x); abs((x1$Peak1.v.[1]-x1$Peak1.v.[2])*(x1$Peak1.t.[1]-x1$Peak1.t.[2]))+abs((x1$Peak2.v.[1]-x1$Peak2.v.[2])*(x1$Peak2.t.[1]-x1$Peak2.t.[2]))+abs((x1$Npeak1.v.[1]-x1$Npeak1.v.[2])*(x1$Npeak1.t.[1]-x1$Npeak1.t.[2]))+abs((x1$Npeak2.v.[1]-x1$Npeak2.v.[2])*(x1$Npeak2.t.[1]-x1$Npeak2.t.[2]))} res2Whole-do.call(cbind,lapply(seq_len(ncol(resWhole)),function(i) c(c(tail(resWhole[seq(1,i,1),i],-1),0),resWhole[-c(1:i),i]))) row.names(res2Whole)-1:nrow(res2Whole) dim(res2Whole) #[1] 124 124 res2Whole[1:5,1:5] # [,1] [,2] [,3] [,4] [,5] #1 0. 0. 0. 379.1364 0. #2 0. 0. 0. 312.8267 0. #3 0. 0. 0. 379.6576 0. #4 379.1364 312.8267 379.6576 0. 324.4063 #5 0. 0. 0. 324.4063 0. A.K. From: eliza botto eliza_bo...@hotmail.com To: smartpink...@yahoo.com smartpink...@yahoo.com Sent: Friday, March 22, 2013 8:26 AM Subject: Dear Arun, I hope you are fine. the attached text file has my recent question and excel file contains the data. thanks in advance Elisa __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help on indicator variables
Thanks all. you guys are really helpful. On Fri, Mar 22, 2013 at 2:48 PM, peter dalgaard pda...@gmail.com wrote: What Bill says, plus the fact that the default handling of logicals in modelling is to convert them to factors and then use treatment contrasts, which will effectively give you the right indicator variables automagically (This in contrast to SAS where you can confuse yourself by declaring a 0/1 variable as a CLASS variable): cond - rep(c(TRUE, FALSE),4) y - rnorm(8) lm(y~cond) Call: lm(formula = y ~ cond) Coefficients: (Intercept) condTRUE -0.5741 1.1845 lm(y~as.numeric(cond)) Call: lm(formula = y ~ as.numeric(cond)) Coefficients: (Intercept) as.numeric(cond) -0.57411.1845 On Mar 21, 2013, at 15:49 , William Dunlap wrote: I would use a logical variable, with values TRUE and FALSE, instead of a numeric indicator. E.g., I find the following easier to follow bL - ABS==1 | DEFF==1 if (any(bL)) { do.this() } than bN - ifelse(ABS == 1 | DEFF == 1, 1, 0) if (any(bN == 1)) { do.this() } The latter leaves me wondering what other values bN might have; the former makes it clear this is a TRUE/FALSE dichotomy. Logicals get converted to numbers (FALSE-0, TRUE-1) when used in arithmetic so you can do, e.g., mean(bL) to see what proportion of your cases satisfy the condition. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tasnuva Tabassum Sent: Thursday, March 21, 2013 6:03 AM To: R help Subject: [R] Help on indicator variables I have two indicator variables ABS and DEFF. I want to create another indicator variable which will take value 1 if either ABS=1 or DEFF=1. Otherwise, it will take value 0. How can I make that? [[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. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error while extracting the p-value from adf.test
Hello all, I tried to extract the p-value from adf.test in tseries; however, I got the error message such as ht=adf.test(list.var$aa) ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht Augmented Dickey-Fuller Test data: list.var$aa Dickey-Fuller = -2.3147, Lag order = 4, p-value = 0.4461 alternative hypothesis: stationary ht$data [1] list.var$aa ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht$p NULL I do not have problem extracting the data in ht, but why not p-value? Is that because the - between p and value? Thanks, Rebecca -- This message, and any attachments, is for the intended r...{{dropped:5}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] order statistic of multivariate normal
As you suggest, Ted, it appears from the question that the OP really means order statistics of a sample of 10 from the distribution. So what she appears to want is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. The independent case is standard first statistics course stuff, but I believe this would require a 10-d integral (please correct if wrong!) for non-iid. So it would seem that simulation would be the simplest approach, and, indeed, should be straightforward. E.g. the mvrnorm() function in MASS could be used to simulate the samples. Again, corrections appreciated if I am wrong on any of this. -- Bert On Fri, Mar 22, 2013 at 6:31 AM, Ted Harding ted.hard...@wlandres.netwrote: On 22-Mar-2013 13:02:25 li li wrote: Thank you all for the reply. One example of my question is as follows. Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. My question is that whether there is a R function that would help compute the c which satisfies P(X(4) c)=beta. Here beta is a known constant between 0 and 1. Thank you. Hanna The basic question which needs to be answered (which has been hinted at in earlier replis) is: How do you define order statistic for multivariate observations? For example, here is a sample of 10 (to 3 d.p.) from a bivariate normal distribution: [,1] [,2] [1,] 1.143 -0.396 [2,] -0.359 -0.217 [3,] -0.391 -0.601 [4,] -0.416 -1.093 [5,] -1.810 -1.499 [6,] -0.367 -0.636 [7,] -2.238 0.563 [8,] 0.811 1.230 [9,] 0.082 0.174 [10,] -1.359 -0.364 Which one of these 10 rows is X(4)? There is an alternative interpretation of your question: Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. This could mean that the vector (X1,...,X10) has a multivariate normal distribution with 10 dimensions, and, for a single vector (X1,...,X10) drawn from this distribution, (X(1), ..., X(10)) is a vector consisting of these same values (X1,...,X10), but in increasing order. Is that what you mean? Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 22-Mar-2013 Time: 13:31:31 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error while extracting the p-value from adf.test
Hi, When I look at ?adf.test I see: A list with class htest containing the following components: statistic the value of the test statistic. parameter the lag order. p.valuethe p-value of the test. method a character string indicating what type of test was performed. data.name a character string giving the name of the data. alternative a character string describing the alternative hypothesis So why don't you try ht$p.value instead, just as the help file tells you? Sarah On Fri, Mar 22, 2013 at 10:03 AM, Yuan, Rebecca rebecca.y...@bankofamerica.com wrote: Hello all, I tried to extract the p-value from adf.test in tseries; however, I got the error message such as ht=adf.test(list.var$aa) ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht Augmented Dickey-Fuller Test data: list.var$aa Dickey-Fuller = -2.3147, Lag order = 4, p-value = 0.4461 alternative hypothesis: stationary ht$data [1] list.var$aa ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht$p NULL I do not have problem extracting the data in ht, but why not p-value? Is that because the - between p and value? Thanks, Rebecca -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error while extracting the p-value from adf.test
On Fri, Mar 22, 2013 at 2:03 PM, Yuan, Rebecca rebecca.y...@bankofamerica.com wrote: Hello all, I tried to extract the p-value from adf.test in tseries; however, I got the error message such as ht=adf.test(list.var$aa) ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht Augmented Dickey-Fuller Test data: list.var$aa Dickey-Fuller = -2.3147, Lag order = 4, p-value = 0.4461 alternative hypothesis: stationary ht$data [1] list.var$aa ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht$p NULL I do not have problem extracting the data in ht, but why not p-value? Is that because the - between p and value? Basically yes: x$p-value parses as x[[p, exact = FALSE]] - value instead of x[[p-value, exact = FALSE]] because `p-value` is not a syntactic name. I think a more common name for R would be p.value which is perfectly fine. MW Thanks, Rebecca -- This message, and any attachments, is for the intended r...{{dropped:5}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] error while extracting the p-value from adf.test
Hello Sarah, Thanks! I will look into help next time before sending out the question. Thanks, Rebecca -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Friday, March 22, 2013 10:22 AM To: Yuan, Rebecca Cc: R help Subject: Re: [R] error while extracting the p-value from adf.test Hi, When I look at ?adf.test I see: A list with class htest containing the following components: statistic the value of the test statistic. parameter the lag order. p.valuethe p-value of the test. method a character string indicating what type of test was performed. data.name a character string giving the name of the data. alternative a character string describing the alternative hypothesis So why don't you try ht$p.value instead, just as the help file tells you? Sarah On Fri, Mar 22, 2013 at 10:03 AM, Yuan, Rebecca rebecca.y...@bankofamerica.com wrote: Hello all, I tried to extract the p-value from adf.test in tseries; however, I got the error message such as ht=adf.test(list.var$aa) ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht Augmented Dickey-Fuller Test data: list.var$aa Dickey-Fuller = -2.3147, Lag order = 4, p-value = 0.4461 alternative hypothesis: stationary ht$data [1] list.var$aa ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht$p NULL I do not have problem extracting the data in ht, but why not p-value? Is that because the - between p and value? Thanks, Rebecca -- Sarah Goslee http://www.functionaldiversity.org -- This message, and any attachments, is for the intended r...{{dropped:2}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] boxplot
Hello All, On the subject of boxplots, I have multiple data sets of unequal sample sizes and was wondering what would be the most efficient way to read in the data and plot side-by-side boxplots, with options for controlling the orientation of the plots (i.e. vertical or horizontal) and the spacing? Your assistance is greatly appreciated, but please try to be explicit as I am no R expert. Thanks Janh On Thu, Mar 21, 2013 at 9:19 AM, David L Carlson dcarl...@tamu.edu wrote: Your variable loc_type combines information from two variables (loc and type). Since you are subsetting on loc, why not just plot by type? boxplot(var1~type, data[data$loc==nice,]) -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jim Lemon Sent: Thursday, March 21, 2013 4:05 AM To: carol white Cc: r-h...@stat.math.ethz.ch Subject: Re: [R] boxplot On 03/21/2013 07:40 PM, carol white wrote: Hi, It must be an easy question but how to boxplot a subset of data: data = read.table(my_data.txt, header = T) boxplot(data$var1[data$loc == nice]~data$loc_type[data$loc == nice]) #in this case, i want to display only the boxplot loc == nice #doesn't display the boxplot of only loc == nice. It also displays loc == mice Hi Carol, It's them old factors sneakin' up on you. Try this: boxplot(data$var1[data$loc == nice]~ as.character(data$loc_type[data$loc == nice])) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] order statistic of multivariate normal
Yes. What I meant is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. Thanks for the idea of simulation. I guess there is no other way around. Hanna 2013/3/22 Bert Gunter gunter.ber...@gene.com As you suggest, Ted, it appears from the question that the OP really means order statistics of a sample of 10 from the distribution. So what she appears to want is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. The independent case is standard first statistics course stuff, but I believe this would require a 10-d integral (please correct if wrong!) for non-iid. So it would seem that simulation would be the simplest approach, and, indeed, should be straightforward. E.g. the mvrnorm() function in MASS could be used to simulate the samples. Again, corrections appreciated if I am wrong on any of this. -- Bert On Fri, Mar 22, 2013 at 6:31 AM, Ted Harding ted.hard...@wlandres.netwrote: On 22-Mar-2013 13:02:25 li li wrote: Thank you all for the reply. One example of my question is as follows. Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. My question is that whether there is a R function that would help compute the c which satisfies P(X(4) c)=beta. Here beta is a known constant between 0 and 1. Thank you. Hanna The basic question which needs to be answered (which has been hinted at in earlier replis) is: How do you define order statistic for multivariate observations? For example, here is a sample of 10 (to 3 d.p.) from a bivariate normal distribution: [,1] [,2] [1,] 1.143 -0.396 [2,] -0.359 -0.217 [3,] -0.391 -0.601 [4,] -0.416 -1.093 [5,] -1.810 -1.499 [6,] -0.367 -0.636 [7,] -2.238 0.563 [8,] 0.811 1.230 [9,] 0.082 0.174 [10,] -1.359 -0.364 Which one of these 10 rows is X(4)? There is an alternative interpretation of your question: Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. This could mean that the vector (X1,...,X10) has a multivariate normal distribution with 10 dimensions, and, for a single vector (X1,...,X10) drawn from this distribution, (X(1), ..., X(10)) is a vector consisting of these same values (X1,...,X10), but in increasing order. Is that what you mean? Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 22-Mar-2013 Time: 13:31:31 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Trouble embedding functions (e.g., deltaMethod) in other functions
Dear Blaser and Pat, I missed the original posting because deltaMethod appears near the end of the message subject and was truncated by my email reader. The problem is caused by lexical scoping. That is, deltaMethod(), which is in the car namespace, will see objects in the global environment, but not in the environment of your function -- you're proceeding as if R used dynamic scoping. Here's another solution, which also cleans up some other problems in your function, is more general, and doesn't depend on variables in the global environment: deltaSE - function(mod, x, func, ...){ constants - c(...) for (i in seq_along(constants)) assign(names(constants[i]), constants[i]) myDelta - car:::deltaMethod.default exists.method - car:::exists.method environment(myDelta) - environment() b - coef(mod) V - vcov(mod) mod.SE - vector(length(x), mode=list) for(i in 1:length(x)){ z - x[i] mod.SE[[i]] - myDelta(b, func, vcov.=V, ...)$SE } mod.SE } unlist(deltaSE(nlls, xVal, (mm0^(1/lambda) - (z * mm0/tt0)^(1/lambda))^lambda, mm0=m0, tt0=t0)) Maybe this approach can be adapted to make deltaMethod() in car more flexible. I hope this helps, John -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Blaser Nello Sent: Friday, March 22, 2013 9:14 AM To: PatGauthier; r-help@r-project.org Subject: Re: [R] Trouble embedding functions (e.g., deltaMethod) in other functions Instead of NaN's, I get the error message: Error in eval(expr, envir, enclos) : object 'z' not found. The reason you get the NaN's is, because you defined z in your global environment. The deltaMethod doesn't find the z defined in your function. I don't know why or how to fix this. Somebody with more R experience could probably do this. But if you look at the source code of deltaMethod you can solve the problem in your specific case with these function. deltaMethod2 - function(object, g, vcov., z, ...){ if (!is.character(g)) stop(The argument 'g' must be a character string) if ((car:::exists.method(coef, object, default = FALSE) || (!is.atomic(object) !is.null(object$coefficients))) car:::exists.method(vcov, object, default = FALSE)) { if (missing(vcov.)) vcov. - vcov(object) object - coef(object) } para - object para.names - names(para) g - parse(text = g) q - length(para) for (i in 1:q) { assign(names(para)[i], para[i]) } est - eval(g) names(est) - NULL gd - rep(0, q) for (i in 1:q) { gd[i] - eval(D(g, names(para)[i])) } se.est - as.vector(sqrt(t(gd) %*% vcov. %*% gd)) data.frame(Estimate = est, SE = se.est) } deltaSE - function(mod, x){ mod.SE - list() for(i in 1:length(x)){ z - x[i] mod.SE[[i]] - deltaMethod2(mod, g=(m0^(1/lambda) - (z * m0/t0)^(1/lambda))^lambda, z=z)$SE } mod.SE } deltaSE(nlls, xVal) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of PatGauthier Sent: Freitag, 22. März 2013 13:54 To: r-help@r-project.org Subject: Re: [R] Trouble embedding functions (e.g., deltaMethod) in other functions Ah Yes, good point. However, it still does not correct the situation. I still get NaN's. -- View this message in context: http://r.789695.n4.nabble.com/Trouble- embedding-functions-e-g-deltaMethod-in-other-functions- tp4662178p4662187.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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] order statistic of multivariate normal
I don't believe that you necessarily need to use simulation for this. But you do need numerical integration. Here is a skeletal approach. Calculate the density (distribution) of the order statistics of a multivariate sample. Then since the underlying distribution is multivariate normal, use a multivariate integration routine in R (try the mnormt package) to get the integration part of the calculation and proceed. As I said before, here is the outline of an approach I would first take. You get to work through the details:-) Ranjan On Fri, 22 Mar 2013 10:48:06 -0400 li li hannah@gmail.com wrote: Yes. What I meant is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. Thanks for the idea of simulation. I guess there is no other way around. Hanna 2013/3/22 Bert Gunter gunter.ber...@gene.com As you suggest, Ted, it appears from the question that the OP really means order statistics of a sample of 10 from the distribution. So what she appears to want is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. The independent case is standard first statistics course stuff, but I believe this would require a 10-d integral (please correct if wrong!) for non-iid. So it would seem that simulation would be the simplest approach, and, indeed, should be straightforward. E.g. the mvrnorm() function in MASS could be used to simulate the samples. Again, corrections appreciated if I am wrong on any of this. -- Bert On Fri, Mar 22, 2013 at 6:31 AM, Ted Harding ted.hard...@wlandres.netwrote: On 22-Mar-2013 13:02:25 li li wrote: Thank you all for the reply. One example of my question is as follows. Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. My question is that whether there is a R function that would help compute the c which satisfies P(X(4) c)=beta. Here beta is a known constant between 0 and 1. Thank you. Hanna The basic question which needs to be answered (which has been hinted at in earlier replis) is: How do you define order statistic for multivariate observations? For example, here is a sample of 10 (to 3 d.p.) from a bivariate normal distribution: [,1] [,2] [1,] 1.143 -0.396 [2,] -0.359 -0.217 [3,] -0.391 -0.601 [4,] -0.416 -1.093 [5,] -1.810 -1.499 [6,] -0.367 -0.636 [7,] -2.238 0.563 [8,] 0.811 1.230 [9,] 0.082 0.174 [10,] -1.359 -0.364 Which one of these 10 rows is X(4)? There is an alternative interpretation of your question: Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. This could mean that the vector (X1,...,X10) has a multivariate normal distribution with 10 dimensions, and, for a single vector (X1,...,X10) drawn from this distribution, (X(1), ..., X(10)) is a vector consisting of these same values (X1,...,X10), but in increasing order. Is that what you mean? Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 22-Mar-2013 Time: 13:31:31 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Important Notice: This mailbox is ignored: e-mails are set to be deleted on receipt. For those needing to send personal or professional e-mail, please use appropriate addresses. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained,
Re: [R] error while extracting the p-value from adf.test
Yes, it should be $p.value Have a look at the components here: names(ht) José José Iparraguirre Chief Economist Age UK T 020 303 31482 E jose.iparragui...@ageuk.org.uk Twitter @jose.iparraguirre@ageuk Tavis House, 1- 6 Tavistock Square London, WC1H 9NB www.ageuk.org.uk | ageukblog.org.uk | @ageukcampaigns -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Yuan, Rebecca Sent: 22 March 2013 14:03 To: R help Subject: [R] error while extracting the p-value from adf.test Hello all, I tried to extract the p-value from adf.test in tseries; however, I got the error message such as ht=adf.test(list.var$aa) ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht Augmented Dickey-Fuller Test data: list.var$aa Dickey-Fuller = -2.3147, Lag order = 4, p-value = 0.4461 alternative hypothesis: stationary ht$data [1] list.var$aa ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht$p NULL I do not have problem extracting the data in ht, but why not p-value? Is that because the - between p and value? Thanks, Rebecca -- This message, and any attachments, is for the intended r...{{dropped:5}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Please donate to the Syria Crisis Appeal by text or online: To donate £5 by mobile, text SYRIA to 70800. To donate online, please visit http://www.ageinternational.org.uk/syria Over one million refugees are desperately in need of water, food, healthcare, warm clothing, blankets and shelter; Age International urgently needs your support to help affected older refugees. Age International is a subsidiary charity of Age UK and a member of the Disasters Emergency Committee (DEC). The DEC launches and co-ordinates national fundraising appeals for public donations on behalf of its member agencies. Texts cost £5 plus one standard rate message. Age International will receive a minimum of £4.96. More info at ageinternational.org.uk/SyriaTerms --- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you receive a message in error, please advise the sender and delete immediately. Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing through its network and may block or modify mails which are deemed to be unsuitable. Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged on 1st April 2009. Together they have formed the Age UK Group, dedicated to improving the lives of people in later life. The three national Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities: Age Scotland, Age NI, Age Cymru. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] order statistic of multivariate normal
Thank you! Hanna 2013/3/22 Ranjan Maitra maitra.mbox.igno...@inbox.com I don't believe that you necessarily need to use simulation for this. But you do need numerical integration. Here is a skeletal approach. Calculate the density (distribution) of the order statistics of a multivariate sample. Then since the underlying distribution is multivariate normal, use a multivariate integration routine in R (try the mnormt package) to get the integration part of the calculation and proceed. As I said before, here is the outline of an approach I would first take. You get to work through the details:-) Ranjan On Fri, 22 Mar 2013 10:48:06 -0400 li li hannah@gmail.com wrote: Yes. What I meant is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. Thanks for the idea of simulation. I guess there is no other way around. Hanna 2013/3/22 Bert Gunter gunter.ber...@gene.com As you suggest, Ted, it appears from the question that the OP really means order statistics of a sample of 10 from the distribution. So what she appears to want is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. The independent case is standard first statistics course stuff, but I believe this would require a 10-d integral (please correct if wrong!) for non-iid. So it would seem that simulation would be the simplest approach, and, indeed, should be straightforward. E.g. the mvrnorm() function in MASS could be used to simulate the samples. Again, corrections appreciated if I am wrong on any of this. -- Bert On Fri, Mar 22, 2013 at 6:31 AM, Ted Harding ted.hard...@wlandres.netwrote: On 22-Mar-2013 13:02:25 li li wrote: Thank you all for the reply. One example of my question is as follows. Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. My question is that whether there is a R function that would help compute the c which satisfies P(X(4) c)=beta. Here beta is a known constant between 0 and 1. Thank you. Hanna The basic question which needs to be answered (which has been hinted at in earlier replis) is: How do you define order statistic for multivariate observations? For example, here is a sample of 10 (to 3 d.p.) from a bivariate normal distribution: [,1] [,2] [1,] 1.143 -0.396 [2,] -0.359 -0.217 [3,] -0.391 -0.601 [4,] -0.416 -1.093 [5,] -1.810 -1.499 [6,] -0.367 -0.636 [7,] -2.238 0.563 [8,] 0.811 1.230 [9,] 0.082 0.174 [10,] -1.359 -0.364 Which one of these 10 rows is X(4)? There is an alternative interpretation of your question: Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. This could mean that the vector (X1,...,X10) has a multivariate normal distribution with 10 dimensions, and, for a single vector (X1,...,X10) drawn from this distribution, (X(1), ..., X(10)) is a vector consisting of these same values (X1,...,X10), but in increasing order. Is that what you mean? Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 22-Mar-2013 Time: 13:31:31 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Important Notice: This mailbox is ignored: e-mails are set to be deleted on receipt. For those needing to send personal or professional e-mail, please use appropriate addresses. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!®
Re: [R] error while extracting the p-value from adf.test
Hello José, This is a much convenient way of looking at the components! Thanks very much! Cheers, Rebecca -Original Message- From: Jose Iparraguirre [mailto:jose.iparragui...@ageuk.org.uk] Sent: Friday, March 22, 2013 11:25 AM To: Yuan, Rebecca; R help Subject: RE: error while extracting the p-value from adf.test Yes, it should be $p.value Have a look at the components here: names(ht) José José Iparraguirre Chief Economist Age UK T 020 303 31482 E jose.iparragui...@ageuk.org.uk Twitter @jose.iparraguirre@ageuk Tavis House, 1- 6 Tavistock Square London, WC1H 9NB www.ageuk.org.uk | ageukblog.org.uk | @ageukcampaigns -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Yuan, Rebecca Sent: 22 March 2013 14:03 To: R help Subject: [R] error while extracting the p-value from adf.test Hello all, I tried to extract the p-value from adf.test in tseries; however, I got the error message such as ht=adf.test(list.var$aa) ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht Augmented Dickey-Fuller Test data: list.var$aa Dickey-Fuller = -2.3147, Lag order = 4, p-value = 0.4461 alternative hypothesis: stationary ht$data [1] list.var$aa ht$p-value Error in ht$p - value : non-numeric argument to binary operator ht$p NULL I do not have problem extracting the data in ht, but why not p-value? Is that because the - between p and value? Thanks, Rebecca -- This message, and any attachments, is for the intended r...{{dropped:5}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Please donate to the Syria Crisis Appeal by text or online: To donate £5 by mobile, text SYRIA to 70800. To donate online, please visit http://www.ageinternational.org.uk/syria Over one million refugees are desperately in need of water, food, healthcare, warm clothing, blankets and shelter; Age International urgently needs your support to help affected older refugees. Age International is a subsidiary charity of Age UK and a member of the Disasters Emergency Committee (DEC). The DEC launches and co-ordinates national fundraising appeals for public donations on behalf of its member agencies. Texts cost £5 plus one standard rate message. Age International will receive a minimum of £4.96. More info at ageinternational.org.uk/SyriaTerms --- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you receive a message in error, please advise the sender and delete immediately. Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing through its network and may block or modify mails which are deemed to be unsuitable. Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged on 1st April 2009. Together they have formed the Age UK Group, dedicated to improving the lives of people in later life. The three national Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities: Age Scotland, Age NI, Age Cymru. -- This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at http://www.bankofamerica.com/emaildisclaimer. If you are not the intended recipient, please delete this message. __ R-help@r-project.org mailing list
Re: [R] contourplot
Look carefully at the help file. Your x1 and x2 need to define a rectangular grid so that there is a value of y for each combination of different x1 and x2 values. When this is not the case, you don't get an error, just a blank plot. It is not clear from the little piece of data that you included if that is the case, but the blank plot suggests that you don't have a grid. You can created gridded data using expand.grid and predict.lm() to generate estimates of y for every combination of x1 and x2: # Reproducible data set.seed(42) x1 - rnorm(100, 60, 10) x2 - rnorm(100, 37, 5) y - x1+x2 pr - data.frame(x1, x2, y) # Create grid that spans x1/x2 ranges # 50 values each ranging from min to max xg - seq(min(x1), max(x2), length.out=50) yg - seq(min(x2), max(x2), length.out=50) # Grid will have 50 x 50 = 2500 values xygrid - expand.grid(xg, yg) # Create data frame from gridded data and compute y # from a linear regression of x1 and x2 on y lmmodel - lm(y~x1+x2, pr) prgrid - data.frame(x1=xygrid$Var1, x2=xygrid$Var2) prgrid$y - predict(lmmodel, prgrid) # Draw contour plot contourplot(y~x1+x2, prgrid) -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Pascal Oettli Sent: Thursday, March 21, 2013 11:41 PM To: Steven LeBlanc Cc: r-help@r-project.org Subject: Re: [R] contourplot Hi, What is the result of: contourplot(Y~X1+X2,data=pr2) HTH, Pascal Le 13/03/22 8:57, Steven LeBlanc a écrit : Greets, I'm using a data frame that looks like: head(pr2) X1 X2 X3 X4Y fit res 1 44 33.2 5 30 41.2 39.22201 1.977991 2 43 33.8 4 41 31.7 38.48476 -6.784761 3 48 40.6 3 38 39.4 44.78278 -5.382783 4 52 39.2 7 48 57.5 51.48134 6.018656 5 71 45.5 11 53 74.8 68.25585 6.544153 6 44 37.5 9 65 59.8 53.27743 6.522569 Along with the command: contourplot(Y~X1*X2,data=pr2) But I get a blank plot. I thought it might be because the data were unsorted or sparse, so I made another ordered data frame as follows: head(new) X1 X2 X3 X4 resp 1 1 1 1 1 -10.810406 2 2 2 2 2 -7.657712 3 3 3 3 3 -4.505018 4 4 4 4 4 -1.352323 5 5 5 5 5 1.800371 6 6 6 6 6 4.953065 But the result is the same. Any idea why this does not work? Best Regards, Steven [[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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] order statistic of multivariate normal
Well... On Fri, Mar 22, 2013 at 8:20 AM, Ranjan Maitra maitra.mbox.igno...@inbox.com wrote: I don't believe that you necessarily need to use simulation for this. But you do need numerical integration. Here is a skeletal approach. Calculate the density (distribution) of the order statistics of a multivariate sample. Therein lies the difficulty. Try it for the non-iid case. Cheers, Bert Then since the underlying distribution is multivariate normal, use a multivariate integration routine in R (try the mnormt package) to get the integration part of the calculation and proceed. As I said before, here is the outline of an approach I would first take. You get to work through the details:-) Ranjan On Fri, 22 Mar 2013 10:48:06 -0400 li li hannah@gmail.com wrote: Yes. What I meant is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. Thanks for the idea of simulation. I guess there is no other way around. Hanna 2013/3/22 Bert Gunter gunter.ber...@gene.com As you suggest, Ted, it appears from the question that the OP really means order statistics of a sample of 10 from the distribution. So what she appears to want is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. The independent case is standard first statistics course stuff, but I believe this would require a 10-d integral (please correct if wrong!) for non-iid. So it would seem that simulation would be the simplest approach, and, indeed, should be straightforward. E.g. the mvrnorm() function in MASS could be used to simulate the samples. Again, corrections appreciated if I am wrong on any of this. -- Bert On Fri, Mar 22, 2013 at 6:31 AM, Ted Harding ted.hard...@wlandres.netwrote: On 22-Mar-2013 13:02:25 li li wrote: Thank you all for the reply. One example of my question is as follows. Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. My question is that whether there is a R function that would help compute the c which satisfies P(X(4) c)=beta. Here beta is a known constant between 0 and 1. Thank you. Hanna The basic question which needs to be answered (which has been hinted at in earlier replis) is: How do you define order statistic for multivariate observations? For example, here is a sample of 10 (to 3 d.p.) from a bivariate normal distribution: [,1] [,2] [1,] 1.143 -0.396 [2,] -0.359 -0.217 [3,] -0.391 -0.601 [4,] -0.416 -1.093 [5,] -1.810 -1.499 [6,] -0.367 -0.636 [7,] -2.238 0.563 [8,] 0.811 1.230 [9,] 0.082 0.174 [10,] -1.359 -0.364 Which one of these 10 rows is X(4)? There is an alternative interpretation of your question: Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. This could mean that the vector (X1,...,X10) has a multivariate normal distribution with 10 dimensions, and, for a single vector (X1,...,X10) drawn from this distribution, (X(1), ..., X(10)) is a vector consisting of these same values (X1,...,X10), but in increasing order. Is that what you mean? Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 22-Mar-2013 Time: 13:31:31 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Important Notice: This mailbox is ignored: e-mails are set to be deleted on receipt. For those needing to send personal or professional e-mail, please use appropriate addresses. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN®
Re: [R] order statistic of multivariate normal
On Fri, 22 Mar 2013 09:31:53 -0700 Bert Gunter gunter.ber...@gene.com wrote: Well... On Fri, Mar 22, 2013 at 8:20 AM, Ranjan Maitra maitra.mbox.igno...@inbox.com wrote: I don't believe that you necessarily need to use simulation for this. But you do need numerical integration. Here is a skeletal approach. Calculate the density (distribution) of the order statistics of a multivariate sample. Therein lies the difficulty. Try it for the non-iid case. I doubt this. The derivation should exactly be the same as for the iid case, except that the multivariate density does not factorize so you keep it as is. That is where the Genz routines in that R package help. Ranjan Cheers, Bert Then since the underlying distribution is multivariate normal, use a multivariate integration routine in R (try the mnormt package) to get the integration part of the calculation and proceed. As I said before, here is the outline of an approach I would first take. You get to work through the details:-) Ranjan On Fri, 22 Mar 2013 10:48:06 -0400 li li hannah@gmail.com wrote: Yes. What I meant is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. Thanks for the idea of simulation. I guess there is no other way around. Hanna 2013/3/22 Bert Gunter gunter.ber...@gene.com As you suggest, Ted, it appears from the question that the OP really means order statistics of a sample of 10 from the distribution. So what she appears to want is the distribution of order statistics from a non-iid sample of a (normal) distribution with specified sample covariance matrix. The independent case is standard first statistics course stuff, but I believe this would require a 10-d integral (please correct if wrong!) for non-iid. So it would seem that simulation would be the simplest approach, and, indeed, should be straightforward. E.g. the mvrnorm() function in MASS could be used to simulate the samples. Again, corrections appreciated if I am wrong on any of this. -- Bert On Fri, Mar 22, 2013 at 6:31 AM, Ted Harding ted.hard...@wlandres.netwrote: On 22-Mar-2013 13:02:25 li li wrote: Thank you all for the reply. One example of my question is as follows. Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. My question is that whether there is a R function that would help compute the c which satisfies P(X(4) c)=beta. Here beta is a known constant between 0 and 1. Thank you. Hanna The basic question which needs to be answered (which has been hinted at in earlier replis) is: How do you define order statistic for multivariate observations? For example, here is a sample of 10 (to 3 d.p.) from a bivariate normal distribution: [,1] [,2] [1,] 1.143 -0.396 [2,] -0.359 -0.217 [3,] -0.391 -0.601 [4,] -0.416 -1.093 [5,] -1.810 -1.499 [6,] -0.367 -0.636 [7,] -2.238 0.563 [8,] 0.811 1.230 [9,] 0.082 0.174 [10,] -1.359 -0.364 Which one of these 10 rows is X(4)? There is an alternative interpretation of your question: Suppose X1, ..., X10 has multivariate normal distribution and X(1), ..., X(10) are the corresponding order statistics. This could mean that the vector (X1,...,X10) has a multivariate normal distribution with 10 dimensions, and, for a single vector (X1,...,X10) drawn from this distribution, (X(1), ..., X(10)) is a vector consisting of these same values (X1,...,X10), but in increasing order. Is that what you mean? Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 22-Mar-2013 Time: 13:31:31 This message was sent by XFMail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
[R] Double condition
Hi, I would appreciate if somebody could help me with this small issue... I have a dataframe like this (originaly has more than 100 000 rows): subz jultimedtime fixddawnddusk day 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333 1 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667 1 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333 1 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667 0 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333 1 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667 0 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333 1 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667 0 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333 0 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667 0 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333 0 dput(subz) structure(list(jul = c(15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006), time = structure(c(1296587689, 1296588289, 1296588289, 129659, 129659, 1296589489, 1296589489, 1296590089, 1296590089, 1296590689, 1296590689), class = c(POSIXct, POSIXt), tzone = GMT), dtime = c(19.24694, 19.41361, 19.41361, 19.58028, 19.58028, 19.74694, 19.74694, 19.91361, 19.91361, 20.08028, 20.08028), fix = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c(midnight, noon), class = factor), ddawn = c(7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667 ), ddusk = c(19.88333, 19.56667, 19.88333, 19.56667, 19.88333, 19.56667, 19.88333, 19.56667, 19.88333, 19.56667, 19.88333 ), day = c(1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0)), .Names = c(jul, time, dtime, fix, ddawn, ddusk, day), row.names = 101608:101618, class = data.frame) where day is calculated as subz$day - ifelse( subz$dtime subz$ddusk | subz$dtime subz$ddawn, 0, 1 ) The way I would like to calculate day is this - for the same time, the day is calculated for noon as mentioned above but for midnight is just copying the same value as for noon. So for the same time the day value should be the same for noon and midnight. Something like this: jultimedtime fixddawnddusk day 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333 1 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667 1 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333 1 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667 1 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333 1 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667 1 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333 1 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667 0 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333 0 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667 0 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333 0 Where I get stuck, is I don't know how to get the value for midnight. Any suggestion is welcome. Thanks Zuzana [[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] A question on function return
Hello again, Let say I have following user defined function: fn - function(x, y) { Vec1 - letters[1:6] Vec2 - 1:5 return(list(ifelse(x 0, Vec1, NA), ifelse(y 0, Vec2, NA))) } Now I have following calculation: fn(-3, -3) [[1]] [1] NA [[2]] [1] NA fn(3, -3) [[1]] [1] a [[2]] [1] NA Here I can not understand why in the second case, I get only the first element a of the corresponding vector 'Vec1'? I want to get complete vector(s) as the function return. Can somebody help me how to achieve that? Thanks and regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 on dendrogram reorder
I plot a dendrogram using the following code: hc - hclust(dist(USArrests[1:10,]), ave) unlist(as.dendrogram(hc)) [1] 7 1 8 4 6 10 9 2 3 5 how can I easily flip some leaves so that the unlist results are: [1] 7 1 8 4 6 10 9 5 3 2 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] A question on function return
Hello, You get only one value because ifelse is vectorized, and the condition has length(x 0) == 1. (You get as many values as there are in the condition.) Try instead fn2 - function(x, y) { Vec1 - letters[1:6] Vec2 - 1:5 list(if(x 0) Vec1 else NA, if(y 0) Vec2 else NA) } fn2(-3, -3) fn2(3, -3) Hope this helps, Rui Barradas Em 22-03-2013 18:43, Christofer Bogaso escreveu: Hello again, Let say I have following user defined function: fn - function(x, y) { Vec1 - letters[1:6] Vec2 - 1:5 return(list(ifelse(x 0, Vec1, NA), ifelse(y 0, Vec2, NA))) } Now I have following calculation: fn(-3, -3) [[1]] [1] NA [[2]] [1] NA fn(3, -3) [[1]] [1] a [[2]] [1] NA Here I can not understand why in the second case, I get only the first element a of the corresponding vector 'Vec1'? I want to get complete vector(s) as the function return. Can somebody help me how to achieve that? Thanks and regards, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Double condition
Hello, Try the following. idx - which(subz$fix == noon) if(idx[length(idx)] == nrow(subz)) idx - idx[-length(idx)] subz$day[idx + 1] - subz$day[idx] Hope this helps, Rui Barradas Em 22-03-2013 18:18, zuzana zajkova escreveu: Hi, I would appreciate if somebody could help me with this small issue... I have a dataframe like this (originaly has more than 100 000 rows): subz jultimedtime fixddawnddusk day 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333 1 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667 1 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333 1 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667 0 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333 1 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667 0 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333 1 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667 0 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333 0 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667 0 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333 0 dput(subz) structure(list(jul = c(15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006), time = structure(c(1296587689, 1296588289, 1296588289, 129659, 129659, 1296589489, 1296589489, 1296590089, 1296590089, 1296590689, 1296590689), class = c(POSIXct, POSIXt), tzone = GMT), dtime = c(19.24694, 19.41361, 19.41361, 19.58028, 19.58028, 19.74694, 19.74694, 19.91361, 19.91361, 20.08028, 20.08028), fix = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c(midnight, noon), class = factor), ddawn = c(7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667 ), ddusk = c(19.88333, 19.56667, 19.88333, 19.56667, 19.88333, 19.56667, 19.88333, 19.56667, 19.88333, 19.56667, 19.88333 ), day = c(1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0)), .Names = c(jul, time, dtime, fix, ddawn, ddusk, day), row.names = 101608:101618, class = data.frame) where day is calculated as subz$day - ifelse( subz$dtime subz$ddusk | subz$dtime subz$ddawn, 0, 1 ) The way I would like to calculate day is this - for the same time, the day is calculated for noon as mentioned above but for midnight is just copying the same value as for noon. So for the same time the day value should be the same for noon and midnight. Something like this: jultimedtime fixddawnddusk day 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333 1 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667 1 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333 1 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667 1 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333 1 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667 1 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333 1 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667 0 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333 0 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667 0 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333 0 Where I get stuck, is I don't know how to get the value for midnight. Any suggestion is welcome. Thanks Zuzana [[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] A question on function return
On 2013-03-22 11:43, Christofer Bogaso wrote: Hello again, Let say I have following user defined function: fn - function(x, y) { Vec1 - letters[1:6] Vec2 - 1:5 return(list(ifelse(x 0, Vec1, NA), ifelse(y 0, Vec2, NA))) } Now I have following calculation: fn(-3, -3) [[1]] [1] NA [[2]] [1] NA fn(3, -3) [[1]] [1] a [[2]] [1] NA Here I can not understand why in the second case, I get only the first element a of the corresponding vector 'Vec1'? I want to get complete vector(s) as the function return. Can somebody help me how to achieve that? From help(ifelse): ifelse returns a value with the same shape as test i.e. in your case, the same 'shape' as 'x 0', a single value. You _could_ make ifelse() work with, e.g., ifelse(rep(x, 6) 0, ) but you probably want if() instead. Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] [mgcv][gam] Odd error: Error in PredictMat(object$smooth[[k]], data) : , `by' variable must be same dimension as smooth arguments
Solved my own problem. If interested: http://stackoverflow.com/questions/15563589/odd-error-error-in-predictmatobjectsmoothk-data-by-variable-must On 03/21/2013 02:14 PM, Andrew Crane-Droesch wrote: Dear List, I'm getting an error in mgcv, and I can't figure out where it comes from. The setup is the following: I've got a fitted GAM object called MI, and a vector of prediction data (with default values for predictors). I feed this into predict.gam(object, newdata = whatever) via the following function: makepred = function(varstochange,val){ for (i in 1:length(varstochange)){ if (varstochange[i] == pot.trial){j=1} if (varstochange[i] == year){j=2} if (varstochange[i] == crop.legume){j=3} if (varstochange[i] == crop.fruit){j=4} if (varstochange[i] == feedstock){j=5} if (varstochange[i] == BCAR.imp){j=8} if (varstochange[i] == INAR.imp){j=9} if (varstochange[i] == bcph.imp){j=10} if (varstochange[i] == phi.imp){j=11} if (varstochange[i] == htt.imp){j=12} if (varstochange[i] == bc.prc.C.imp){j=13} if (varstochange[i] == CEC.imp){j=14} if (varstochange[i] == soc.imp){j=15} if (varstochange[i] == sand.imp){j=16} if (varstochange[i] == clay.imp){j=17} if (varstochange[i] == abslat.imp){j=18} preddat[j] = val[i] } predict.gam(MI,newdata=preddat,se.fit=TRUE) } I then make predictions that look like this: a = makepred(c(phi.imp,bcph.imp,year),c(4.5,7.25,1)) b = makepred(c(phi.imp,bcph.imp,year),c(5.5,7.25,1)) c = makepred(c(phi.imp,bcph.imp,year),c(6.5,7.25,1)) d = makepred(c(phi.imp,bcph.imp,year),c(7.5,7.25,1)) makepHplot(a,b,c,d,title=1st harvest, BC pH = 7.25) where makepHplot is a different function that I made. This worked for quite some time. Then I added some data to the model and changed the specification slightly. Now I'm getting this error message: 1 a = makepred(c(bcph.imp,year),c(7.5,1)) Error in PredictMat(object$smooth[[k]], data) : `by' variable must be same dimension as smooth arguments I never got this message with the old fitted model (and still don't). What is happening? I can't figure out what about the new fitted model is causing this problem. Typing PredictMat isn't helping me, nor is google. The problem isn't that all of the variables aren't in the prediction data. Would appreciate any help here. Thanks, Andrew __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Integration of vector syntax unknown
Hello, I'm very new to using R, but I was told it could do what I want. I'm not sure how best to enter the information but here goes... I'm trying to transfer the following integral into R to solve for ln(gamma_1), on the left, for multiple instances of gamma_i and variable N_i. gamma_i is, for example, (0, 0.03012048, 0.0500, 0.1920, 0.4400, 0.62566845) N_i (N_1 or N_2) is between 0 and 1 so that N_1+N_2=1, so if N_1=(0,.166,.180,.250,.325,.374), then N_2=(1.000, 0.834, 0.820, 0.750, 0.675, 0.626) a_i (a_1 or a_2) So, for gamma_i (in this case gamma_2), N_i (N_2), and a_i (a_2) first the following a_i = ln(gamma_i)/(1-N_i)^2 then, ln(gamma_1) = -a_2*N_1*N*2 - integration (from N_1=1, to N_1) a_2 dN_1 I hope that makes sense... __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Reading dataset in R
Hi, I also need to read this format of file in R, it is a Wordpad file. On Thu, Mar 21, 2013 at 5:07 PM, arun smartpink...@yahoo.com wrote: Hi, con-file(Rout1112.text) Lines1- readLines(con) close(con) indx-rep(rep(c(TRUE,FALSE),each=2),2) Lines2-Lines1[!grepl([A-Za-z],Lines1)] res-read.table(text=paste(gsub(^\\d+\\s+,,Lines2[indx]),gsub(^\\d+\\s+,,Lines2[!indx])),sep=,header=FALSE) nm1-unlist(strsplit(gsub(^ +,,paste(Lines1[grepl([A-Za-z],Lines1)][1:2],collapse= )), )) colnames(res)- nm1[nm1!=] res #m1 n1 m n cterm1_P0L cterm1_P0H c11 c12 c1 c2 alpha beta T_error N #1 4 5 11 9 0.8145062 0.6302494 0.03 0.03 0.15 0.15 0.1 0.4 0.6339515 20 #2 7 4 11 8 0.6983373 0.000 0.03 0.03 0.15 0.15 0.1 0.4 0.4899431 19 #3 4 5 10 9 0.8145062 0.6302494 0.03 0.03 0.15 0.20 0.1 0.4 0.6831988 19 #4 5 4 9 8 0.7737809 0.000 0.03 0.03 0.15 0.20 0.1 0.4 0.6458095 17 # EN BHBL AH AL #1 11.77746 0.12159579 0.3846999 0.09567271 0.03198315 #2 16.20665 0.09819012 0.2550532 0.09581478 0.04088503 #3 11.59196 0.15166360 0.3943098 0.08405337 0.05317206 #4 13.90488 0.14031630 0.3624458 0.08268336 0.06036395 A.K. From: Joanna Zhang zjoanna2...@gmail.com To: arun smartpink...@yahoo.com Sent: Thursday, March 21, 2013 3:03 PM Subject: Re: [R] cumulative sum by group and under some criteria Hi, I used a computer cluster and output the file attached here, I need to read the file in R. I tried to use read.table, but it seems that the format is not recognized by R, could you help? Rout2122.text (528 bytes) http://r.789695.n4.nabble.com/attachment/4662237/0/Rout2122.text -- View this message in context: http://r.789695.n4.nabble.com/cumulative-sum-by-group-and-under-some-criteria-tp4657074p4662237.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Double condition
It sounds like, although your noon and midnight data are separate rows, they are not fully independent. If I understand correctly, the operation you want to perform would be simple if you had (at least temporarily) a single row with columns ddawn.midnight, ddusk.midnight, ddawn.noon, ddusk.noon, rather than two separate rows. I recommend you check out the reshape package http://had.co.nz/reshape/, and read the paper Hadley wrote about it for a conceptual understanding of wide vs. long data. On Fri, Mar 22, 2013 at 11:18 AM, zuzana zajkova zuzu...@gmail.com wrote: Hi, I would appreciate if somebody could help me with this small issue... I have a dataframe like this (originaly has more than 100 000 rows): subz jultimedtime fixddawnddusk day 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333 1 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667 1 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333 1 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667 0 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333 1 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667 0 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333 1 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667 0 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333 0 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667 0 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333 0 dput(subz) structure(list(jul = c(15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006, 15006), time = structure(c(1296587689, 1296588289, 1296588289, 129659, 129659, 1296589489, 1296589489, 1296590089, 1296590089, 1296590689, 1296590689), class = c(POSIXct, POSIXt), tzone = GMT), dtime = c(19.24694, 19.41361, 19.41361, 19.58028, 19.58028, 19.74694, 19.74694, 19.91361, 19.91361, 20.08028, 20.08028), fix = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c(midnight, noon), class = factor), ddawn = c(7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667, 7.916667 ), ddusk = c(19.88333, 19.56667, 19.88333, 19.56667, 19.88333, 19.56667, 19.88333, 19.56667, 19.88333, 19.56667, 19.88333 ), day = c(1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0)), .Names = c(jul, time, dtime, fix, ddawn, ddusk, day), row.names = 101608:101618, class = data.frame) where day is calculated as subz$day - ifelse( subz$dtime subz$ddusk | subz$dtime subz$ddawn, 0, 1 ) The way I would like to calculate day is this - for the same time, the day is calculated for noon as mentioned above but for midnight is just copying the same value as for noon. So for the same time the day value should be the same for noon and midnight. Something like this: jultimedtime fixddawnddusk day 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333 1 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667 1 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333 1 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667 1 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333 1 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667 1 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333 1 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667 0 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333 0 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667 0 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333 0 Where I get stuck, is I don't know how to get the value for midnight. Any suggestion is welcome. Thanks Zuzana [[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] Reading dataset in R
Hi, Try this: con-file(Rout2122.text) Lines1- readLines(con) close(con) indx-rep(c(TRUE,FALSE),each=2) #changed here Lines2-Lines1[!grepl([A-Za-z],Lines1)] res-read.table(text=paste(gsub(^\\s+,,Lines2[indx]),gsub(^\\s+,,Lines2[!indx])),sep=,header=FALSE)#some changes nm1-unlist(strsplit(gsub(^ +,,paste(Lines1[grepl([A-Za-z],Lines1)][1:2],collapse= )), )) colnames(res)- nm1[nm1!=] res # m1 n1 m n cterm1_P0L cterm1_P0H c11 c12 c1 c2 alpha beta T_error N #1 4 4 10 8 0.8145062 0.6634204 0.03 0.05 0.15 0.2 0.1 0.4 0.6918138 18 #2 5 4 9 8 0.7737809 0.6302494 0.03 0.05 0.15 0.2 0.1 0.4 0.6643599 17 # EN BH BL AH AL #1 10.45928 0.1690183 0.3952494 0.07470420 0.05284197 #2 11.38388 0.1694641 0.3624458 0.07208597 0.06036395 A.K. From: Zjoanna zjoanna2...@gmail.com To: r-help@r-project.org Sent: Friday, March 22, 2013 3:54 PM Subject: Re: [R] Reading dataset in R Hi, I also need to read this format of file in R, it is a Wordpad file. On Thu, Mar 21, 2013 at 5:07 PM, arun smartpink...@yahoo.com wrote: Hi, con-file(Rout1112.text) Lines1- readLines(con) close(con) indx-rep(rep(c(TRUE,FALSE),each=2),2) Lines2-Lines1[!grepl([A-Za-z],Lines1)] res-read.table(text=paste(gsub(^\\d+\\s+,,Lines2[indx]),gsub(^\\d+\\s+,,Lines2[!indx])),sep=,header=FALSE) nm1-unlist(strsplit(gsub(^ +,,paste(Lines1[grepl([A-Za-z],Lines1)][1:2],collapse= )), )) colnames(res)- nm1[nm1!=] res #m1 n1 m n cterm1_P0L cterm1_P0H c11 c12 c1 c2 alpha beta T_error N #1 4 5 11 9 0.8145062 0.6302494 0.03 0.03 0.15 0.15 0.1 0.4 0.6339515 20 #2 7 4 11 8 0.6983373 0.000 0.03 0.03 0.15 0.15 0.1 0.4 0.4899431 19 #3 4 5 10 9 0.8145062 0.6302494 0.03 0.03 0.15 0.20 0.1 0.4 0.6831988 19 #4 5 4 9 8 0.7737809 0.000 0.03 0.03 0.15 0.20 0.1 0.4 0.6458095 17 # EN BH BL AH AL #1 11.77746 0.12159579 0.3846999 0.09567271 0.03198315 #2 16.20665 0.09819012 0.2550532 0.09581478 0.04088503 #3 11.59196 0.15166360 0.3943098 0.08405337 0.05317206 #4 13.90488 0.14031630 0.3624458 0.08268336 0.06036395 A.K. From: Joanna Zhang zjoanna2...@gmail.com To: arun smartpink...@yahoo.com Sent: Thursday, March 21, 2013 3:03 PM Subject: Re: [R] cumulative sum by group and under some criteria Hi, I used a computer cluster and output the file attached here, I need to read the file in R. I tried to use read.table, but it seems that the format is not recognized by R, could you help? Rout2122.text (528 bytes) http://r.789695.n4.nabble.com/attachment/4662237/0/Rout2122.text -- View this message in context: http://r.789695.n4.nabble.com/cumulative-sum-by-group-and-under-some-criteria-tp4657074p4662237.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX
What am I missing? When I run the code below I get the error message Error: ggplot2 doesn't know how to deal with data of class function Googling suggests a message of Error: ggplot2 doesn't know how to deal with data of class XXX is not uncommon but I don't see why I am getting a function error unless I am using some reserved word? ##=Start Code= library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rect, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ##=End Code== sessionInfo() R version 2.15.3 (2013-03-01) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_CA.UTF-8 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_CA.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.3 loaded via a namespace (and not attached): [1] colorspace_1.2-1 dichromat_2.0-0digest_0.6.3 grid_2.15.3 [5] gtable_0.1.2 labeling_0.1 MASS_7.3-23munsell_0.4 [9] plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2 [13] scales_0.2.3 stringr_0.6.2 John Kane Kingston ON Canada FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX
Hi John, This bit of your code: geom_rect(data=rect Your reproducible example doesn't create rect, and rect() already exists, so geom_rect() is trying to treat a function as data. Sarah On Fri, Mar 22, 2013 at 4:42 PM, John Kane jrkrid...@inbox.com wrote: What am I missing? When I run the code below I get the error message Error: ggplot2 doesn't know how to deal with data of class function Googling suggests a message of Error: ggplot2 doesn't know how to deal with data of class XXX is not uncommon but I don't see why I am getting a function error unless I am using some reserved word? ##=Start Code= library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rect, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ##=End Code== sessionInfo() R version 2.15.3 (2013-03-01) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_CA.UTF-8 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_CA.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.3 loaded via a namespace (and not attached): [1] colorspace_1.2-1 dichromat_2.0-0digest_0.6.3 grid_2.15.3 [5] gtable_0.1.2 labeling_0.1 MASS_7.3-23munsell_0.4 [9] plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2 [13] scales_0.2.3 stringr_0.6.2 John Kane Kingston ON Canada -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX
Ah , thanks Sarah So that's why the error message changed! I was getting different one earlier. I had defined rect earlier and apparently, when stripping down the code I negelected to include it in the example. Renamed rect as rectlib Now what I get is Error in eval(expr, envir, enclos) : object 'federal.ps' not found which is what I was getting ealier although at one point I was getting year not found. See revised code. library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) rectlib - data.frame (xmin = as.POSIXct(2000-03-31, %Y-%m-%d), xmax = as.POSIXct(2006-10-31, %Y-%m-%d)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rectlib, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ###===End Code== John Kane Kingston ON Canada -Original Message- From: sarah.gos...@gmail.com Sent: Fri, 22 Mar 2013 16:49:34 -0400 To: jrkrid...@inbox.com Subject: Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX Hi John, This bit of your code: geom_rect(data=rect Your reproducible example doesn't create rect, and rect() already exists, so geom_rect() is trying to treat a function as data. Sarah On Fri, Mar 22, 2013 at 4:42 PM, John Kane jrkrid...@inbox.com wrote: What am I missing? When I run the code below I get the error message Error: ggplot2 doesn't know how to deal with data of class function Googling suggests a message of Error: ggplot2 doesn't know how to deal with data of class XXX is not uncommon but I don't see why I am getting a function error unless I am using some reserved word? ##=Start Code= library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rect, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ##=End Code== sessionInfo() R version 2.15.3 (2013-03-01) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_CA.UTF-8 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_CA.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.3 loaded via a namespace (and not attached): [1] colorspace_1.2-1 dichromat_2.0-0digest_0.6.3 grid_2.15.3 [5] gtable_0.1.2 labeling_0.1 MASS_7.3-23 munsell_0.4 [9] plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2 [13] scales_0.2.3 stringr_0.6.2 John Kane Kingston ON Canada -- Sarah Goslee http://www.functionaldiversity.org GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX
I get year not found and we've exceeded my ability to debug ggplot code. I hope someone else chimes in: I'd like to know what the answer is too. Sarah On Fri, Mar 22, 2013 at 5:01 PM, John Kane jrkrid...@inbox.com wrote: Ah , thanks Sarah So that's why the error message changed! I was getting different one earlier. I had defined rect earlier and apparently, when stripping down the code I negelected to include it in the example. Renamed rect as rectlib Now what I get is Error in eval(expr, envir, enclos) : object 'federal.ps' not found which is what I was getting ealier although at one point I was getting year not found. See revised code. library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) rectlib - data.frame (xmin = as.POSIXct(2000-03-31, %Y-%m-%d), xmax = as.POSIXct(2006-10-31, %Y-%m-%d)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rectlib, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ###===End Code== John Kane Kingston ON Canada -Original Message- From: sarah.gos...@gmail.com Sent: Fri, 22 Mar 2013 16:49:34 -0400 To: jrkrid...@inbox.com Subject: Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX Hi John, This bit of your code: geom_rect(data=rect Your reproducible example doesn't create rect, and rect() already exists, so geom_rect() is trying to treat a function as data. Sarah On Fri, Mar 22, 2013 at 4:42 PM, John Kane jrkrid...@inbox.com wrote: What am I missing? When I run the code below I get the error message Error: ggplot2 doesn't know how to deal with data of class function Googling suggests a message of Error: ggplot2 doesn't know how to deal with data of class XXX is not uncommon but I don't see why I am getting a function error unless I am using some reserved word? ##=Start Code= library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rect, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ##=End Code== sessionInfo() R version 2.15.3 (2013-03-01) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_CA.UTF-8 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_CA.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.3 loaded via a namespace (and not attached): [1] colorspace_1.2-1 dichromat_2.0-0digest_0.6.3 grid_2.15.3 [5] gtable_0.1.2 labeling_0.1 MASS_7.3-23 munsell_0.4 [9] plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2 [13] scales_0.2.3 stringr_0.6.2 -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] boxplot
Hi Janh, When you say that you have multiple data sets of unequal sample sizes are you speaking of the same kind of data For example are you speaking of data from a set of experiments where the variables measured are all the same and where when you graph them you expect the same x and y scales? Or are you talking about essentilly independent data sets that it makes sense to graph in a grid ? John Kane Kingston ON Canada -Original Message- From: annij...@gmail.com Sent: Fri, 22 Mar 2013 10:46:21 -0400 To: dcarl...@tamu.edu Subject: Re: [R] boxplot Hello All, On the subject of boxplots, I have multiple data sets of unequal sample sizes and was wondering what would be the most efficient way to read in the data and plot side-by-side boxplots, with options for controlling the orientation of the plots (i.e. vertical or horizontal) and the spacing? Your assistance is greatly appreciated, but please try to be explicit as I am no R expert. Thanks Janh On Thu, Mar 21, 2013 at 9:19 AM, David L Carlson dcarl...@tamu.edu wrote: Your variable loc_type combines information from two variables (loc and type). Since you are subsetting on loc, why not just plot by type? boxplot(var1~type, data[data$loc==nice,]) -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jim Lemon Sent: Thursday, March 21, 2013 4:05 AM To: carol white Cc: r-h...@stat.math.ethz.ch Subject: Re: [R] boxplot On 03/21/2013 07:40 PM, carol white wrote: Hi, It must be an easy question but how to boxplot a subset of data: data = read.table(my_data.txt, header = T) boxplot(data$var1[data$loc == nice]~data$loc_type[data$loc == nice]) #in this case, i want to display only the boxplot loc == nice #doesn't display the boxplot of only loc == nice. It also displays loc == mice Hi Carol, It's them old factors sneakin' up on you. Try this: boxplot(data$var1[data$loc == nice]~ as.character(data$loc_type[data$loc == nice])) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX
Thanks, that shows that I am not making one of my really stupid mistakes. What is really annoying is that I can find examples on the web that work just fine and I cannot se how my example is that different. I even tried changing from using as.Date() to POSIXct() and to POSIXlt in case the dates were the problem but with no luck. I think it's time for dinner here so I will have another look at it tommorrow --hopefully someone will see the problem. Thanks again. John Kane Kingston ON Canada -Original Message- From: sarah.gos...@gmail.com Sent: Fri, 22 Mar 2013 17:29:42 -0400 To: jrkrid...@inbox.com Subject: Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX I get year not found and we've exceeded my ability to debug ggplot code. I hope someone else chimes in: I'd like to know what the answer is too. Sarah On Fri, Mar 22, 2013 at 5:01 PM, John Kane jrkrid...@inbox.com wrote: Ah , thanks Sarah So that's why the error message changed! I was getting different one earlier. I had defined rect earlier and apparently, when stripping down the code I negelected to include it in the example. Renamed rect as rectlib Now what I get is Error in eval(expr, envir, enclos) : object 'federal.ps' not found which is what I was getting ealier although at one point I was getting year not found. See revised code. library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) rectlib - data.frame (xmin = as.POSIXct(2000-03-31, %Y-%m-%d), xmax = as.POSIXct(2006-10-31, %Y-%m-%d)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rectlib, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ###===End Code== John Kane Kingston ON Canada -Original Message- From: sarah.gos...@gmail.com Sent: Fri, 22 Mar 2013 16:49:34 -0400 To: jrkrid...@inbox.com Subject: Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX Hi John, This bit of your code: geom_rect(data=rect Your reproducible example doesn't create rect, and rect() already exists, so geom_rect() is trying to treat a function as data. Sarah On Fri, Mar 22, 2013 at 4:42 PM, John Kane jrkrid...@inbox.com wrote: What am I missing? When I run the code below I get the error message Error: ggplot2 doesn't know how to deal with data of class function Googling suggests a message of Error: ggplot2 doesn't know how to deal with data of class XXX is not uncommon but I don't see why I am getting a function error unless I am using some reserved word? ##=Start Code= library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rect, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ##=End Code== sessionInfo() R version 2.15.3 (2013-03-01) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_CA.UTF-8 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_CA.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.3 loaded via a namespace (and not attached): [1] colorspace_1.2-1 dichromat_2.0-0digest_0.6.3 grid_2.15.3 [5] gtable_0.1.2 labeling_0.1 MASS_7.3-23 munsell_0.4 [9] plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2 [13] scales_0.2.3 stringr_0.6.2 -- Sarah Goslee
[R] Median across matrices
Hey all, I have a list of matrices. I'd like to calculate the median across all those matrices for each element. What I'd like to end up with is a matrix containing the median of all [1,1] [1,2] etc. elements across all matrices. Is there a concise way of doing that? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] spatstat error
Questions about spatstat should be directed to the R-Sig-Geo list, or better still, to the package maintainers. To add a bit to what Blaser Nello has already told you: (1) Your syntax in respect of the use of the min() function is indeed incomprehensibly bizarre. (2) Blaser Nello has indicated useful *correct* alternatives. Another possibility is to use the ripras() function from spatstat, e.g. Dantos - with(Datos,ppp(x,y,window=ripras(x,y,shape=rectangle))) (3) If you are actually going to do any statistical analysis of the point pattern then it is a VERY BAD idea to estimate the observation window from the data. The observation window should be *known* a priori, else the statistical results can be wrong or misleading. To quote from Adrian Baddeley's notes: It is important to know the window W, since we need to know where points were not observed. Even something as simple as estimating the density of points depends on the window. It would be wrong, or at least different, to analyze a point pattern dataset by “guessing” the appropriate window. An analogy may be drawn with the difference between sequential experiments and experiments in which the sample size is fixed a priori. See: @techreport{Baddeley2010, author = {Adrian Baddeley}, title = {Analysing spatial point patterns in \textsf{R}, \textbf{Version 4.1}}, institution = {CSIRO}, year = {2010}, month = {December}, note = {URL: \url{http://www.csiro.au/resources/Spatial-Point-Patterns-in-R}}, type = {Workshop Notes} } cheers, Rolf Turner On 03/22/2013 12:19 PM, papao wrote: Good day Im working with some coordinates, and want to create a PPP object, I found that error: Datos=read.table(puntos_texto.txt,dec=.,sep=\t,header=T) summary(Datos) id y x Min. : 1.0 Min. :1013581 Min. :1177842 1st Qu.: 821.2 1st Qu.:1014442 1st Qu.:1179658 Median :1641.5 Median :1014455 Median :1179670 Mean :1641.8 Mean :1014465 Mean :1179652 3rd Qu.:2462.8 3rd Qu.:1014473 3rd Qu.:1179680 Max. :3283.0 Max. :1015575 Max. :1180213 danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842,max(Datos$x)1180213),c(min(D atos$y)1013581,max(Datos$y)1015575)) Error: inesperado constante numérica en danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842 danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842,max(Datos$x)1180213),c(m in(Datos$y)1013581,max(Datos$y)1015575)) Error: inesperado string constante en danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842 danta=ppp(Datos$x,Datos$y,window=owin(c(min(Datos$x)1177842,max(Datos$x)1 180213),c(min(Datos$y)1013581,max(Datos$y)1015575))) Error: inesperado string constante en danta=ppp(Datos$x,Datos$y,window=owin(c(min(Datos$x)1177842 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] spatstat error
Questions about spatstat should be directed to the R-Sig-Geo list, or better still, to the package maintainers. To add a bit to what Blaser Nello has already told you: (1) Your syntax in respect of the use of the min() function is indeed incomprehensibly bizarre. (2) Blaser Nello has indicated useful *correct* alternatives. Another possibility is to use the ripras() function from spatstat, e.g. Dantos - with(Datos,ppp(x,y,window=ripras(x,y,shape=rectangle))) (3) If you are actually going to do any statistical analysis of the point pattern then it is a VERY BAD idea to estimate the observation window from the data. The observation window should be *known* a priori, else the statistical results can be wrong or misleading. To quote from Adrian Baddeley's notes: It is important to know the window W, since we need to know where points were not observed. Even something as simple as estimating the density of points depends on the window. It would be wrong, or at least different, to analyze a point pattern dataset by guessing the appropriate window. An analogy may be drawn with the difference between sequential experiments and experiments in which the sample size is fixed a priori. See: @techreport{Baddeley2010, author = {Adrian Baddeley}, title = {Analysing spatial point patterns in \textsf{R}, \textbf{Version 4.1}}, institution = {CSIRO}, year = {2010}, month = {December}, note = {URL: \url{http://www.csiro.au/resources/Spatial-Point-Patterns-in-R}}, type = {Workshop Notes} } cheers, Rolf Turner On 03/22/2013 12:19 PM, papao wrote: Good day Im working with some coordinates, and want to create a PPP object, I found that error: Datos=read.table(puntos_texto.txt,dec=.,sep=\t,header=T) summary(Datos) id y x Min. : 1.0 Min. :1013581 Min. :1177842 1st Qu.: 821.2 1st Qu.:1014442 1st Qu.:1179658 Median :1641.5 Median :1014455 Median :1179670 Mean :1641.8 Mean :1014465 Mean :1179652 3rd Qu.:2462.8 3rd Qu.:1014473 3rd Qu.:1179680 Max. :3283.0 Max. :1015575 Max. :1180213 danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842,max(Datos$x)1180213),c(min(D atos$y)1013581,max(Datos$y)1015575)) Error: inesperado constante numérica en danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842 danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842,max(Datos$x)1180213),c(m in(Datos$y)1013581,max(Datos$y)1015575)) Error: inesperado string constante en danta=ppp(Datos$x,Datos$y,c(min(Datos$x)1177842 danta=ppp(Datos$x,Datos$y,window=owin(c(min(Datos$x)1177842,max(Datos$x)1 180213),c(min(Datos$y)1013581,max(Datos$y)1015575))) Error: inesperado string constante en danta=ppp(Datos$x,Datos$y,window=owin(c(min(Datos$x)1177842 Thank you so much. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX
ggplot(fcs,aes(x=year,y=federal.ps))+geom_line()+geom_rect(data=rectlib,aes(x=xmin,y=Inf,xmin=xmin,xmax=xmax),ymin=-Inf,ymax=Inf,fill=red,alpha=0.2) For some reason x and y must be defined as data sources for all layers. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. John Kane jrkrid...@inbox.com wrote: Thanks, that shows that I am not making one of my really stupid mistakes. What is really annoying is that I can find examples on the web that work just fine and I cannot se how my example is that different. I even tried changing from using as.Date() to POSIXct() and to POSIXlt in case the dates were the problem but with no luck. I think it's time for dinner here so I will have another look at it tommorrow --hopefully someone will see the problem. Thanks again. John Kane Kingston ON Canada -Original Message- From: sarah.gos...@gmail.com Sent: Fri, 22 Mar 2013 17:29:42 -0400 To: jrkrid...@inbox.com Subject: Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX I get year not found and we've exceeded my ability to debug ggplot code. I hope someone else chimes in: I'd like to know what the answer is too. Sarah On Fri, Mar 22, 2013 at 5:01 PM, John Kane jrkrid...@inbox.com wrote: Ah , thanks Sarah So that's why the error message changed! I was getting different one earlier. I had defined rect earlier and apparently, when stripping down the code I negelected to include it in the example. Renamed rect as rectlib Now what I get is Error in eval(expr, envir, enclos) : object 'federal.ps' not found which is what I was getting ealier although at one point I was getting year not found. See revised code. library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) rectlib - data.frame (xmin = as.POSIXct(2000-03-31, %Y-%m-%d), xmax = as.POSIXct(2006-10-31, %Y-%m-%d)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rectlib, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ###===End Code== John Kane Kingston ON Canada -Original Message- From: sarah.gos...@gmail.com Sent: Fri, 22 Mar 2013 16:49:34 -0400 To: jrkrid...@inbox.com Subject: Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX Hi John, This bit of your code: geom_rect(data=rect Your reproducible example doesn't create rect, and rect() already exists, so geom_rect() is trying to treat a function as data. Sarah On Fri, Mar 22, 2013 at 4:42 PM, John Kane jrkrid...@inbox.com wrote: What am I missing? When I run the code below I get the error message Error: ggplot2 doesn't know how to deal with data of class function Googling suggests a message of Error: ggplot2 doesn't know how to deal with data of class XXX is not uncommon but I don't see why I am getting a function error unless I am using some reserved word? ##=Start Code= library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rect, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ##=End Code== sessionInfo() R version 2.15.3 (2013-03-01)
Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX
Hello, You're forgeting to tell gfeom_rect that the x and y aesthetics are already set elsewhere. You must include NULL, NULL as the first two arguments: p + geom_rect(data = rectlib, aes(NULL, NULL, xmin = xmin, xmax = xmax, ymin = -Inf, ymax = Inf), fill='red', alpha=0.2) Hope this helps, Rui Barradas Em 22-03-2013 21:01, John Kane escreveu: Ah , thanks Sarah So that's why the error message changed! I was getting different one earlier. I had defined rect earlier and apparently, when stripping down the code I negelected to include it in the example. Renamed rect as rectlib Now what I get is Error in eval(expr, envir, enclos) : object 'federal.ps' not found which is what I was getting ealier although at one point I was getting year not found. See revised code. library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) rectlib - data.frame (xmin = as.POSIXct(2000-03-31, %Y-%m-%d), xmax = as.POSIXct(2006-10-31, %Y-%m-%d)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rectlib, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ###===End Code== John Kane Kingston ON Canada -Original Message- From: sarah.gos...@gmail.com Sent: Fri, 22 Mar 2013 16:49:34 -0400 To: jrkrid...@inbox.com Subject: Re: [R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX Hi John, This bit of your code: geom_rect(data=rect Your reproducible example doesn't create rect, and rect() already exists, so geom_rect() is trying to treat a function as data. Sarah On Fri, Mar 22, 2013 at 4:42 PM, John Kane jrkrid...@inbox.com wrote: What am I missing? When I run the code below I get the error message Error: ggplot2 doesn't know how to deal with data of class function Googling suggests a message of Error: ggplot2 doesn't know how to deal with data of class XXX is not uncommon but I don't see why I am getting a function error unless I am using some reserved word? ##=Start Code= library(ggplot2) fcs - structure(list(year = structure(c(954478800, 986014800, 1017550800, 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000, 1238472000, 1270008000, 1301544000, 1333166400), class = c(POSIXct, POSIXt), tzone = ), federal.ps = c(211925L, 223933L, 237251L, 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L, 282955L, 282352L, 278092L)), .Names = c(year, federal.ps), class = data.frame, row.names = c(NA, -13L)) p - ggplot(fcs, aes(year, federal.ps )) + geom_line() p + geom_rect(data=rect, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf), fill='red', alpha=0.2) ##=End Code== sessionInfo() R version 2.15.3 (2013-03-01) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_CA.UTF-8 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_CA.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.3 loaded via a namespace (and not attached): [1] colorspace_1.2-1 dichromat_2.0-0digest_0.6.3 grid_2.15.3 [5] gtable_0.1.2 labeling_0.1 MASS_7.3-23 munsell_0.4 [9] plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2 [13] scales_0.2.3 stringr_0.6.2 John Kane Kingston ON Canada -- Sarah Goslee http://www.functionaldiversity.org GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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
Re: [R] Median across matrices
HI, Try this: set.seed(15) lst- list(matrix(sample(1:15,20,replace=TRUE),ncol=5),matrix(sample(4:20,20,replace=TRUE),ncol=5),matrix(sample(8:25,20,replace=TRUE),ncol=5)) library(abind) arr1-abind(lst,along=3) apply(arr1,c(1,2),median) # [,1] [,2] [,3] [,4] [,5] #[1,] 17 13 19 12 7 #[2,] 16 15 12 11 15 #[3,] 15 13 12 12 9 #[4,] 10 6 10 15 12 #or library(plyr) aaply(laply(lst,as.matrix),c(2,3),median) # X2 #X1 1 2 3 4 5 # 1 17 13 19 12 7 # 2 16 15 12 11 15 # 3 15 13 12 12 9 # 4 10 6 10 15 12 A.K. - Original Message - From: Lucas Holland hollandlu...@gmail.com To: r-help@R-project.org r-help@r-project.org Cc: Sent: Friday, March 22, 2013 5:17 PM Subject: [R] Median across matrices Hey all, I have a list of matrices. I'd like to calculate the median across all those matrices for each element. What I'd like to end up with is a matrix containing the median of all [1,1] [1,2] etc. elements across all matrices. Is there a concise way of doing that? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] boxplot
On the subject of boxplots, I have multiple data sets of unequal sample sizes and was wondering what would be the most efficient way to read in the data and plot side-by-side boxplots, with options for controlling the orientation of the plots (i.e. vertical or horizontal) and the spacing? Your assistance is greatly appreciated, but please try to be explicit as I am no R expert. Thanks Janh Not sure without a reproducible example (please read posting guide) but maybe this will help: a = sample(1:100, 30) b = sample(1:100, 50) c = sample(50:100,19) d = sample(1:50, 15) e = sample(1:50, 15) f = sample(1:50, 25) x11(width = 7, height = 3.5) op =par(mfrow = c(1,2)) # plot side by side # horizontal boxplot(list(a,b,c), horizontal = TRUE, main = 'Horizontal', xlim = c(0,9), names = c('a', 'b','c')) boxplot(list(e, f), horizontal = TRUE, xlim = c(0,9), names = c('e', 'f'), at = c(7,8), add = TRUE, col ='red') # vertical boxplot(list(a,b,c), horizontal = FALSE, xlim = c(0,9), main = 'Verticalal', names = c('a', 'b','c')) boxplot(list(e, f), horizontal = FALSE, xlim = c(0,9), names = c('e', 'f'), at = c(7,8), add = TRUE, col ='red') par(op) Cheers, Rob ___ Robert W. Baer, Ph.D. Professor of Physiology Kirksille College of Osteopathic Medicine A. T. Still University of Health Sciences Kirksville, MO 63501 USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] predict.Arima error 'xreg' and 'newxreg' have different numbers of columns
Hello all, I use arima to fit the model with fit - arima(y, order = c(1,0,1), xreg = list.indep, include.mean = TRUE) and would like to use predict() to forecast: chn.forecast - rep(0,times=num.record) chn.forecast[1] - y[1] for (j in 2:num.record){ indep- c(aa=chn.forecast[j-1], list.indep[j,2:num.indep]) # this is the newxreg in the forecast. chn.forecast[j] - predict(fit, newxreg=indep, n.ahead = 1) } However, I got the error message as 'xreg' and 'newxreg' have different numbers of columns. So I debug into predict.Arima (as shown in (*)). (*): debugging in: predict.Arima(fit, newxreg = indep, n.ahead = 1) debug: { myNCOL - function(x) if (is.null(x)) 0 else NCOL(x) rsd - object$residuals xr - object$call$xreg xreg - if (!is.null(xr)) eval.parent(xr) else NULL ncxreg - myNCOL(xreg) if (myNCOL(newxreg) != ncxreg) stop('xreg' and 'newxreg' have different numbers of columns) class(xreg) - NULL xtsp - tsp(rsd) n - length(rsd) arma - object$arma coefs - object$coef narma - sum(arma[1L:4L]) if (length(coefs) narma) { if (names(coefs)[narma + 1L] == intercept) { xreg - cbind(intercept = rep(1, n), xreg) newxreg - cbind(intercept = rep(1, n.ahead), newxreg) ncxreg - ncxreg + 1L } xm - if (narma == 0) drop(as.matrix(newxreg) %*% coefs) else drop(as.matrix(newxreg) %*% coefs[-(1L:narma)]) } else xm - 0 if (arma[2L] 0L) { ma - coefs[arma[1L] + 1L:arma[2L]] if (any(Mod(polyroot(c(1, ma))) 1)) warning(MA part of model is not invertible) } if (arma[4L] 0L) { ma - coefs[sum(arma[1L:3L]) + 1L:arma[4L]] if (any(Mod(polyroot(c(1, ma))) 1)) warning(seasonal MA part of model is not invertible) } z - KalmanForecast(n.ahead, object$model) pred - ts(z[[1L]] + xm, start = xtsp[2L] + deltat(rsd), frequency = xtsp[3L]) if (se.fit) { se - ts(sqrt(z[[2L]] * object$sigma2), start = xtsp[2L] + deltat(rsd), frequency = xtsp[3L]) return(list(pred = pred, se = se)) } else return(pred) } Browse[3] debug: myNCOL - function(x) if (is.null(x)) 0 else NCOL(x) Browse[3] debug: rsd - object$residuals Browse[3] debug: xr - object$call$xreg Browse[3] debug: xreg - if (!is.null(xr)) eval.parent(xr) else NULL Browse[3] debug: eval.parent(xr) Browse[3] debug: ncxreg - myNCOL(xreg) Browse[3] debug: if (myNCOL(newxreg) != ncxreg) stop('xreg' and 'newxreg' have different numbers of columns) Browse[3] head(xreg) aa dummy1 dummy2 bb cc [1,] 0.015538 00 0.941 1.241 [2,] 0.015478 00 0.952 1.185 [3,] 0.015607 00 0.955 1.422 [4,] 0.015861 00 1.038 1.777 [5,] 0.016005 00 1.286 2.118 [6,] 0.016180 00 1.351 2.084 Browse[3] newxreg aa dummy1 dummy2 bb 0.015478 0.00 0.00 0.952000 cc 1.185000 Browse[3] NCOL(xreg) [1] 5 Browse[3] NCOL(newxreg) [1] 1 Browse[3] NCOL(t(newxreg)) [1] 5 When comparing the column numbers of xreg and newxreg, the function NCOL is used. It seems to me that they all have the same number of columns (ncol(xreg)=ncol(newxreg)=5, yellow highlighted part), however, ncol(newxreg)=1. If I check the transpose ncol(t(newxreg)), it is 5. So I think about put t(indep) instead of indep as the newxreg, but got error message(**): (**) Error in as.matrix(newxreg) %*% coefs : requires numeric/complex matrix/vector arguments In addition: Warning message: In chn.forecast[j] - predict(fit, newxreg = t(indep), n.ahead = 1) : number of items to replace is not a multiple of replacement length How could I fix such a problem? Thanks very much! Cheers, Rebecca -- This message, and any attachments, is for the intended r...{{dropped:5}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 trends with GAM
Hi all, I am using GAM to model time trends in a logistic regression. Yet I would like to extract the the fitted spline from it to add it to another model, that cannot be fitted in GAM or GAMM. Thus I have 2 questions: 1) How can I fit a smoother over time so that I force one knot to be at a particular location while letting the model to find the other knots? 2) how can I extract the matrix from the fitted GAM so that I can use it in as an impute for a different model. The types of models I am running are to the following form: gam - gam(mortality.under.2~ maternal_age_c+ I(maternal_age_c^2)+ s(birth_year,by=wealth2) + + wealth2 + sex + residence+ maternal_educ + birth_order, ,data=colombia2,family=binomial) I've read the extensive documentation for the GAM but I am not sure still. Any suggestion is really appreciated. Thanks, Antonio Pedro [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to change background and text colors in script window?
Hello, Does anyone know how to change background and text colors in script windows in R? (I have changed the console's background and text colors by using EditGUI preferences, but that doesn't seem to work for script windows.) I am using R 2.15.1 (32-bit) for Windows, and am using Windows 7. Thanks! -Steve Pfeiffer [[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] Getting a vector result from a computed index
Greetings, I confess to being new to R, which I am exploring for some simulation modeling purposes. I am a long time programmer in PHP. I am having some trouble getting over the steep learning curve with some very basic things which are probably just little a-ha things in R. I have hunted and hunted through the manual and cannot figure this one out, so I am appealing for help. I have the following program: results - replicate(1,0) for (year in 2000:2050) { print(year); for (i in 1:1) { x=results[i]; if (x == 0) { prev = results[i-1]; next = results[i+1]; prob=0.1; if (i=1) { if (prev==1) { prob=prob+0.4; } } if (i1) { if (next==1) { prob=prob+0.4; } } y=runif(1,0,1); if (yprob) { x=1; } results[i]=x; } } } No matter how I try this (and I've tried a number of variations), I get an error similar to Error in next = results[i + 1] : invalid (NULL) left side of assignment I need to be able to loop through the results vector and compare the previous/next items in the list to the current one. Is that possible? What am I missing? Cordially, Justin Long __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Getting a vector result from a computed index
Hi, On Mar 22, 2013, at 11:09 PM, Justin Long wrote: Greetings, I confess to being new to R, which I am exploring for some simulation modeling purposes. I am a long time programmer in PHP. I am having some trouble getting over the steep learning curve with some very basic things which are probably just little a-ha things in R. I have hunted and hunted through the manual and cannot figure this one out, so I am appealing for help. I have the following program: results - replicate(1,0) for (year in 2000:2050) { print(year); for (i in 1:1) { x=results[i]; if (x == 0) { prev = results[i-1]; next = results[i+1]; prob=0.1; if (i=1) { if (prev==1) { prob=prob+0.4; } } if (i1) { if (next==1) { prob=prob+0.4; } } y=runif(1,0,1); if (yprob) { x=1; } results[i]=x; } } } No matter how I try this (and I've tried a number of variations), I get an error similar to Error in next = results[i + 1] : invalid (NULL) left side of assignment I need to be able to loop through the results vector and compare the previous/next items in the list to the current one. Is that possible? What am I missing? I'm not very clear on what you are trying in the above code block, but comparing neighbor values is very easy. n - 10 x - floor(runif(n, min = 1, max = 10)) dx - diff(x) x [1] 6 3 2 4 8 8 2 2 4 2 dx [1] -3 -1 2 4 0 -6 0 2 -2 Is that what you are aiming for? Also, 'next' is a reserved word in R, that might be why an error is raised. See ?next Even if you could get past that, you'll get unexpected results if the index [i-1] falls to less than 1 or the index [i+1] rises to greater than the length of results. x[0] numeric(0) x[101] [1] NA Cheers, Ben Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.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] Integration of vector syntax unknown
You hope it makes sense, but it doesn't to me. Can you describe it without the multiple instances? Your last equation in particular seems confusing (e.g. undefined variable N, integrating by a variable N_1 to a limit of N_1, what is a_2 and why is it being used to determine gamma_1). For clarity, R can do a lot of things vectorially, but multiple parallel integrations is not something R has an unusually simple or fast ability to accomplish. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Benjamin Sabatini art_archaeol...@yahoo.com wrote: Hello, I'm very new to using R, but I was told it could do what I want. I'm not sure how best to enter the information but here goes... I'm trying to transfer the following integral into R to solve for ln(gamma_1), on the left, for multiple instances of gamma_i and variable N_i. gamma_i is, for example, (0, 0.03012048, 0.0500, 0.1920, 0.4400, 0.62566845) N_i (N_1 or N_2) is between 0 and 1 so that N_1+N_2=1, so if N_1=(0,.166,.180,.250,.325,.374), then N_2=(1.000, 0.834, 0.820, 0.750, 0.675, 0.626) a_i (a_1 or a_2) So, for gamma_i (in this case gamma_2), N_i (N_2), and a_i (a_2) first the following a_i = ln(gamma_i)/(1-N_i)^2 then, ln(gamma_1) = -a_2*N_1*N*2 - integration (from N_1=1, to N_1) a_2 dN_1 I hope that makes sense... __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.