Re: [R] day, month, year functions
Gabor Grothendieck wrote: On 8/17/06, Martin Maechler [EMAIL PROTECTED] wrote: Gregor == Gregor Gorjanc [EMAIL PROTECTED] on Fri, 11 Aug 2006 00:27:27 + (UTC) writes: [snip] There are two problems: 1. as.POSIXlt is not generic. (This problem may not be too important given that as.POSIXlt does handle Date and chron dates classes already but in terms of handling all potential classes its a limitation.) But as.POSIXlt can be implemented as generic. Given the variatey of potential classes this would be a reasonable move. -- Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana PhD student Biotechnical Faculty Zootechnical Department URI: http://www.bfro.uni-lj.si/MR/ggorjan Groblje 3 mail: gregor.gorjanc at bfro.uni-lj.si SI-1230 Domzale tel: +386 (0)1 72 17 861 Slovenia, Europefax: +386 (0)1 72 17 888 -- One must learn by doing the thing; for though you think you know it, you have no certainty until you try. Sophocles ~ 450 B.C. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R Site Search directly from Firefox's address bar
Le 17.08.2006 20:56, Adrian Dusa a écrit : On Thursday 17 August 2006 21:41, Peter Dalgaard wrote: [...] Breaks the feature that you get to www.r-project.org just by typing r, though... It breaks also every usage of the google feeling lucky default behaviour which is really useful I think. There are R related firefox search plugins on mycroft. Find more info on that on the wiki : http://wiki.r-project.org/rwiki/doku.php?id=tips:misc:firefox-search-plugins You just have to type (*) [Ctrl]+[K] to go to the search textbox (and maybe [Alt]+[Up]) instead of [Ctrl]+[L] that leads to the location textbox and if you do it with the mouse, it's not too far away neither Cheers, Romain (*) the keyboard shortcuts may not be these one on your configuration Oh, this is very simple to fix. I created a bookmark named R with the above location and assigned it a keyword r. Now, everytime I type r in the address bar it takes me to www.r-project.org :) - +---+ | Romain FRANCOIS | | R Graph Gallery : http://addictedtor.free.fr/graphiques | `---+ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R Site Search directly from Firefox's address bar
On Friday 18 August 2006 10:08, Romain Francois wrote: Le 17.08.2006 20:56, Adrian Dusa a écrit : [...] It breaks also every usage of the google feeling lucky default behaviour which is really useful I think. There are R related firefox search plugins on mycroft. Find more info on that on the wiki : http://wiki.r-project.org/rwiki/doku.php?id=tips:misc:firefox-search-plugins Thanks, very nice! Already added a couple of search plugins. Well, it's just a matter of taste, what one use Firefox's address bar for: Google Feeling Lucky vs. R Site Search (I prefer the later). All the best, Adrian -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd 050025 Bucharest sector 5 Romania Tel./Fax: +40 21 3126618 \ +40 21 3120210 / int.101 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Odd behaviour of R
Dear R-users I need your help. I am agonised by the odd behaviour of R described below In the following program, data.frame work contains no rows, when Pb set to 0.3 and 0.7 data-read.csv(output.csv,header=TRUE) for(N in c(20,40,80,160,320,640,1280)){ for(Pb in seq(0.1,0.9,0.1)){ work-data[((data$N==N) (data$Pb==Pb)),] print(work) } } That is, when Pb set to 0.3 and 0.7, print(work) prints out the message [1] NPb a bcdoutcomeA outcomeB 0 rows (or 0-length row.names) However, data does exist when Pb is 0.3 or 0.7. And when line work-data[((data$N==N) (data$Pb==Pb)),] is placed outside the for loops after Pb is manually set to 0.3, print(work) successfully prints out the appropriate data. Namely, N-20 Pb-0.3 work-data[((data$N==N) (data$Pb==Pb)),] work N Pb a b c d outcomeA outcomeB 22 20 0.3 6 0 0 14FALSEFALSE 23 20 0.3 5 1 0 14FALSEFALSE 24 20 0.3 5 1 1 13FALSEFALSE ... Why is this happen? I am using R version 2.3.0. Any help is greatly appreciated. Thank you. Hiroto Miyoshi [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using R to perform a word count - syntax refinement and incorrect number of dimensions error
Hello, I am hoping someone can advise me regarding an error message I received and if needed, refine some syntax. I am wanting to calculate the word count for each row of a dataframe. Below, I have 3 variables (V3.PD, V3.HD, V3.LP) which I want to obtain a word count for, by each row which contains these variables. Any assistance is much appreciated, Bob Green wordcount1 - read.csv(c:\\newstext.csv,header=T) attach(wordcount1) names(wordcount1) [1] X i V3.PD V3.PG V3.HD V3.BY V3.SN V3.LP V3.TD wc1 -c(V3.PD, V3.HD, V3.LP) dim(wordcount1) [1] 178 9 nwords - function(x){ + res - strsplit(as.character(x), [ \t]+) + res - lapply(res, length) + unlist(res) + } sapply(wc1, nwords) V3.PD V3.HD V3.LP 1 1 1 sapply(paste(wc1[,1], wc1[,2]), nwords) Error in wc1[, 1] : incorrect number of dimensions dim (wc1) NULL __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Maximum length of R GUI input line?
Hello, I'm using R 2.3.1 on Windows. I'm generating some very long SQL statements. I do this by using paste() which will contain many strings and variables. I'm getting an error when the the total line length is longer than about 1013 characters. For example, it works with the line containing 1013 characters and not when it is 1059. I've looked into adjusting the options(width) and a handful of other settings. I have a feeling there is some other setting i'm missing that i can adjust. Any ideas? Thanks! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fitting truncated normal distribution
Thank you Sundar, Yes, always integers. By demand data I meant the amount of ordered products in a certain period. Therefore, x is a vector of periods (i.e. Weeks in a year) In my example we could see an article, that has only been ordered in two weeks within one year. All the zeros show, that nobody has ordered the items in these periods. (First half of the year/first 24 weeks) Since the orders cannot be negative, some literature recommended to use a truncated normal distribution (Poisson and negative binomial are also recommended). My x is just a sample out of the dataset. There might be other time series with better attributes for a truncated normal distribution. My problem is simply, that I only get an error message when I use fitdistr. Error in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) nothing to replace. I hope, there is a way fitdistr can also compute difficult data. Best regards, markus -Original Message- From: Sundar Dorai-Raj [mailto:[EMAIL PROTECTED] Sent: Donnerstag, 17. August 2006 16:47 To: Schweitzer, Markus Cc: r-help@stat.math.ethz.ch Subject: Re: [R] fitting truncated normal distribution Hi, Markus, Are these always integers? Why do you think they should be normal or Weibull? Seems more like a mixture with a point mass at 0 and something else (e.g. Poisson, negative binomial, normal). Though it's hard to tell with what you have provided. If that's the case you'll have to write your own likelihood function or, if they are integers, use zip (zero-inflated Poisson) or zinb (zero-inflated negative binomial). Do an RSiteSearch to find many packages will do these fits. RSiteSearch(zero-inflated) Again, this is pure speculation based on your x below alone and no other information (I'm not sure what demand-data means). HTH, --sundar Schweitzer, Markus wrote: Sorry, that I forgot an example. I have demand-data which is either 0 or a positive value. When I have an article which is not ordered very often, it could look like this: x=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1280,0,0,0,0,640,0 ,0 ,0,0,0,0,0,0,0) library(MASS) ## for fitdistr library(msm) ## for dtnorm dtnorm0 - function(x, mean = 0, sd = 1, log = FALSE) { dtnorm(x, mean, sd, 0, Inf, log) } fitdistr(x,dtnorm0,start=list(mean=0,sd=1)) Unfortunately I get the same error message. I found a function, that works for a weibull distribution and tried to apply it but it didn't work neither # truncated weibull distribution #dweibull.trunc - #function(x, shape, scale=1, trunc.=Inf, log=FALSE){ #ln.dens - (dweibull(x, shape, scale, log=TRUE) #-pweibull(trunc., shape, scale = 1, lower.tail = TRUE, log.p = #TRUE)) #if(any(oops - (xtrunc.))) #ln.dens[oops] - (-Inf) #if(log)ln.dens else exp(ln.dens) #} # #x - rweibull(100, 1) #range(x) #x4 - x[x=4] #fitdistr(x4, dweibull.trunc, start=list(shape=1, scale=1), trunc=4) ## ## # truncated normal distribution dtnorm0 - function(x, mean, sd, a=0, log = FALSE) { ln.dens - (dnorm(x, mean, sd) - pnorm(a, mean, sd, lower.tail=TRUE, log.p =TRUE)) if(any(oops - (xa))) ln.dens[oops] - (-Inf) if(log)ln.dens else exp(ln.dens) } fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1)) Maybe, when I alter mean and sd, I get an answer, which is not really satisfactory. I hope, there is a solution possible And thank you in advance markus Sorry, didn't notice that you *did* mention dtnorm is part of msm. Ignore that part of the advice... --sundar Sundar Dorai-Raj wrote: [EMAIL PROTECTED] wrote: Hello, I am a new user of R and found the function dtnorm() in the package msm. My problem now is, that it is not possible for me to get the mean and sd out of a sample when I want a left-truncated normal distribution starting at 0. fitdistr(x,dtnorm, start=list(mean=0, sd=1)) returns the error message Fehler in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) :nichts zu ersetzen I don't know, where to enter the lower/upper value. Is there a possibility to program the dtnorm function by myself? Thank you very much in advance for your help, markus --- Versendet durch aonWebmail (webmail.aon.at) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Hi, Markus, You should always supply the package name where dtnorm is located. My guess is most don't know (as I didn't) it is part of the msm package. Also, you should supply a reproducible example so others may understand your particular problem. For example, when I ran your code on
Re: [R] Odd behaviour of R
On Fri, 18 Aug 2006, Hiroto Miyoshi wrote: Dear R-users I need your help. I am agonised by the odd behaviour of R described below In the following program, data.frame work contains no rows, when Pb set to 0.3 and 0.7 data-read.csv(output.csv,header=TRUE) for(N in c(20,40,80,160,320,640,1280)){ for(Pb in seq(0.1,0.9,0.1)){ work-data[((data$N==N) (data$Pb==Pb)),] print(work) } } That is, when Pb set to 0.3 and 0.7, print(work) prints out the message [1] NPb a bcdoutcomeA outcomeB 0 rows (or 0-length row.names) However, data does exist when Pb is 0.3 or 0.7. This looks suspiciously like FAQ 7.31: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f and suggests that all.equal() may be a better test than == for an appropriate value of tolerance: print(seq(0.1,0.9,0.1), 20) seq(0.1,0.9,0.1)[7]==0.7 all.equal(seq(0.1,0.9,0.1)[7], 0.7) And when line work-data[((data$N==N) (data$Pb==Pb)),] is placed outside the for loops after Pb is manually set to 0.3, print(work) successfully prints out the appropriate data. Namely, N-20 Pb-0.3 work-data[((data$N==N) (data$Pb==Pb)),] work N Pb a b c d outcomeA outcomeB 22 20 0.3 6 0 0 14FALSEFALSE 23 20 0.3 5 1 0 14FALSEFALSE 24 20 0.3 5 1 1 13FALSEFALSE ... Why is this happen? I am using R version 2.3.0. Any help is greatly appreciated. Thank you. Hiroto Miyoshi [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Maximum length of R GUI input line?
You should put your SQL query in a variable, and use this variable in your call. Something like: MyQuery - bla bla bla MyQuery - paste(MyQuery, more bla bla) # doMyRequest(MyQuery) Best, Philippe Grosjean Eric Fegraus wrote: Hello, I'm using R 2.3.1 on Windows. I'm generating some very long SQL statements. I do this by using paste() which will contain many strings and variables. I'm getting an error when the the total line length is longer than about 1013 characters. For example, it works with the line containing 1013 characters and not when it is 1059. I've looked into adjusting the options(width) and a handful of other settings. I have a feeling there is some other setting i'm missing that i can adjust. Any ideas? Thanks! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Maximum length of R GUI input line?
On Fri, 18 Aug 2006, Philippe Grosjean wrote: You should put your SQL query in a variable, and use this variable in your call. Something like: MyQuery - bla bla bla MyQuery - paste(MyQuery, more bla bla) # doMyRequest(MyQuery) Indeed. For the record, R has an limit of 1024 chars on input lines (from way back) and it cannot be altered. Best, Philippe Grosjean Eric Fegraus wrote: Hello, I'm using R 2.3.1 on Windows. I'm generating some very long SQL statements. I do this by using paste() which will contain many strings and variables. I'm getting an error when the the total line length is longer than about 1013 characters. For example, it works with the line containing 1013 characters and not when it is 1059. I've looked into adjusting the options(width) and a handful of other settings. I have a feeling there is some other setting i'm missing that i can adjust. Any ideas? Thanks! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] rotating axis labels in plot with multiple plots
I have a plot like this, consisting of 18 different vioplots: (monospaced font) - - - - - - lab |16 | |13 | |10 | | 7 | | 4 | | 1 | - - - - - - lab |17 | |14 | |11 | | 8 | | 5 | | 2 | - - - - - - lab |18 | |15 | |12 | | 9 | | 6 | | 3 | - - - - - - a b c d e f This I create in such a way that in the graph itself plot 1 appears in the top left corner, and plot 18 in the bottom right corner. I then flip it around when I show it in my paper (it was simpler to do it that way, this might change:)). I am now trying to make labels a to f, which are a set of numbers which are _local_ to each graph group. Now I would like these numbers to be either vertical to the axis (so that they are in normal text direction when the paper is rotated so that graphs 18-16 are on top), or possibly 45 degrees to the plot group. This is the way I create labels and such: plot.window(xlim = xlim, ylim = ylim) axis(2, at = at, labels=toptitle, tick=FALSE) if(!bottom) { if(!left){ # nothing ok axis(1, at = at, labels = label, tick=FALSE) } else{ # not bottom, but left axis(1, at = at, labels = label, las=2) } } else{ text(lognumbers, par(usr)[3] - 0.25, srt = 135, adj = 1,labels = loglabels, xpd = TRUE) if(!left){ # bottom, but not left # want to replace this one with the text # axis(4, at = lognumbers, labels=loglabels, las=2) } else{ # bottom and left not ok axis(1, at = at, labels = label, las=2) # want to replace this one with the text # axis(4, at = lognumbers, labels=loglabels, las=2) } } } In this sceme graphs 18-16 are defined as being left, whereas graphs 3, 6, 9, 12, 15, 18 are defined as bottom. My question relates to my attemt to set nice-looking axis labels using text. When I put them on as they are shown here, they show up on (relative to image above) the left side of the bottom graphs. How do I get them to show up on the side I would like them to? Hope this was somewhat understandable...:) Karin -- Karin Lagesen, PhD student [EMAIL PROTECTED] http://www.cmbn.no/rognes/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] ARMA(1,1) for panel data
For normal panel data, the standard R tool is the nlme package, documented in Pinheiro and Bates (2000) Mixed-Effects Models for S and S-Plus (Springer). See the examples in ?corARMA. I recommend you spend some quality time with Pinheiro and Bates (2000). If you do that, I suggest you start by looking at ch01.R, ch02.R, ..., ch06.R, ch08.R in ~library\nlme\scripts in your R installation directory. These files contain the R commands used in Ch. 1, Ch. 2, etc., of that book. Using them makes studying that book easier, more pleasant and productive for several reasons. First, they save you the work of typing in the commands yourself. Second, they save you the agony of wondering why you didn't get their answer when you have a typographical error. Third, there are a very few subtle syntax changes between the book and R that generate different answers for the unwary. Fourth, you can experiment with different alternatives to test your understanding, etc. If your data required non-normal models, I would recommend 'lmer' associated with the 'lme4' package. However, that's newer and does not have the same level of documentation, helper functions, etc. Hope this helps. Spencer Graves Tom Boonen wrote: Dear List, I am new to TS-Modeling in R. I would like to fit an ARMA(1,1) model for a balanced panel, running Y on a full set of unit and year dummies using an arma(1,1) for the disturbance: y_it=unit.dummies+yeardummies+e_it where: e_it=d*e_it-1+u_it+q*u_it-1 How can I fit this model in R? arma() does not seem to take covariates (or I don't understand how to specify the function so that it would). Thank you very much. Best, Tom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] NLS and IV
RSiteSearch(grogger) produced nothing, which suggests that the paper you cite is NOT cited in a help page in any package contributed to CRAN. However, RSiteSearch(instrumental variables) just produced 31 hits for me, among which #11 was for systemfit{systemfit}, which mentions instrumental variables and probits. I also got 6 hits for RSiteSearch(exogeneity) and 6 for RSiteSearch(endogeneity). You might also check the 'sem' package. If you don't find anything that does exactly what you want, I doubt if it would be too difficult to program it from scratch using something like optim if you couldn't find anything better using RSiteSearch or similar tools. If you would like further help from this listserve, please submit another post. In doing so, I suggest you include commented, minimal, self-contained, reproducible code illustrating something you've tried, as suggested in the final two lines of this email. Substantial anecdotal evidence suggests that posts that conform more closely to the style describe in the posting guide www.R-project.org/posting-guide.html (which recommends including commented, minimal, self-contained, reproducible code) tend to get better answers to their questions quicker than other posts. Hope this helps. Spencer Graves John Janmaat wrote: Hello All, I'm looking to test a variable in a logit model (glm(..., binomial(link=logit))) for exogeneity (endogeneity). At this point I am planning to try implementing Jeffery Grogger's A Simple Test for Exogeneity in Probit, Logit, and Poisson Regression Models, Economic Letters, 1990. To do this, I need to be able to do an instrumental variables NLS regression. Is there a simple way to do this? Alternatively, is there any other test for exogeneity (endogeneity) of a regressor that has been implemented in R, for binary models? Thanks, John. Dr. John Janmaat Tel: 902-585-1461 Department of EconomicsFax: 902-585-1461 Acadia University, Email: [EMAIL PROTECTED] Wolfville, Nova Scotia, Canada.Web: ace.acadiau.ca/~jjanmaat/ B4P 1H5 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] 4^2 factorial help
To whom it may concern: I am trying a factorial design a system of mine that has two factors. Each factor was set at four different levels, with one replication for each of the combinations. My data is as follows: A B Response 16002.5 0.0257 26002.5 0.0254 36005 0.0217 46005 0.0204 5600100.0191 6600100.0210 7600200.0133 8600200.0139 98002.5 0.0312 10 800 2.5 0.0317 11 800 5 0.0307 12 800 5 0.0309 13 800 100.0330 14 800 100.0318 15 800 200.0225 16 800 200.0234 17 1000 2.5 0.0350 18 1000 2.5 0.0352 19 1000 5 0.0373 20 1000 5 0.0361 21 1000 100.0432 22 1000 100.0402 23 1000 200.0297 24 1000 200.0306 25 1200 2.5 0.0324 26 1200 2.5 0.0326 27 1200 5 0.0353 28 1200 5 0.0353 29 1200 100.0453 30 1200 100.0436 31 1200 200.0348 32 1200 200.0357 I am able to enter my data into R and obtain an ANOVA table (which I have been able to verify as correct using an excel spreadsheet), using the following syntax: Factorial-data.frame(A=c(rep(c(600, 600, 600, 600, 800, 800, 800, 800, 1000, 1000, 1000, 1000, 1200, 1200, 1200, 1200), each=2)), B=c(rep(c(2.5, 5, 10, 20, 2.5, 5, 10, 20, 2.5, 5, 10, 20, 2.5, 5, 10, 20), each=2)), Response = c(0.0257, 0.0254, 0.0217, 0.0204, 0.0191, 0.021, 0.0133, 0.0139, 0.0312, 0.0317, 0.0307, 0.0309, 0.033, 0.0318, 0.0225, 0.0234, 0.035, 0.0352, 0.0373, 0.0361, 0.0432, 0.0402, 0.0297, 0.0306, 0.0324, 0.0326, 0.0353, 0.0353, 0.0453, 0.0436, 0.0348, 0.0357)) anova(aov(Response~A*B, data=Factorial)) However, this is as far as I am able to go. I would like to obtain the coefficients of my model, but am unable. I would also like to use other non-linear models as these factors are not linear. Also would like to add A^2 and B^2 into the ANOVA and modeling. Please can you help with regard and offer some advice. Your help is much appreciated. Yours sincerely, Leslie Correia Department of Process Engineering University of Stellenbosch Private Bag X1 Matieland, 7602 Stellenbosch Tel: 0837012017 E-mail: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using R to perform a word count - syntax refinement and incorrect number of dimensions error
'wc1' is a vector and not a matrix. The reference 'wc1[,1]' is not legal: wc1 -c(V3.PD, V3.HD, V3.LP) dim(wc1) NULL wc1[,1] Error in wc1[, 1] : incorrect number of dimensions What is it that you are trying to do? On 8/18/06, Bob Green [EMAIL PROTECTED] wrote: Hello, I am hoping someone can advise me regarding an error message I received and if needed, refine some syntax. I am wanting to calculate the word count for each row of a dataframe. Below, I have 3 variables (V3.PD, V3.HD, V3.LP) which I want to obtain a word count for, by each row which contains these variables. Any assistance is much appreciated, Bob Green wordcount1 - read.csv(c:\\newstext.csv,header=T) attach(wordcount1) names(wordcount1) [1] X i V3.PD V3.PG V3.HD V3.BY V3.SN V3.LP V3.TD wc1 -c(V3.PD, V3.HD, V3.LP) dim(wordcount1) [1] 178 9 nwords - function(x){ + res - strsplit(as.character(x), [ \t]+) + res - lapply(res, length) + unlist(res) + } sapply(wc1, nwords) V3.PD V3.HD V3.LP 1 1 1 sapply(paste(wc1[,1], wc1[,2]), nwords) Error in wc1[, 1] : incorrect number of dimensions dim (wc1) NULL __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] 4^2 factorial help
On 8/18/06, Correia, L, Mr [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: To whom it may concern: I am trying a factorial design a system of mine that has two factors. Each factor was set at four different levels, with one replication for each of the combinations. My data is as follows: A B Response 16002.5 0.0257 26002.5 0.0254 36005 0.0217 46005 0.0204 5600100.0191 6600100.0210 7600200.0133 8600200.0139 98002.5 0.0312 10 800 2.5 0.0317 11 800 5 0.0307 12 800 5 0.0309 13 800 100.0330 14 800 100.0318 15 800 200.0225 16 800 200.0234 17 1000 2.5 0.0350 18 1000 2.5 0.0352 19 1000 5 0.0373 20 1000 5 0.0361 21 1000 100.0432 22 1000 100.0402 23 1000 200.0297 24 1000 200.0306 25 1200 2.5 0.0324 26 1200 2.5 0.0326 27 1200 5 0.0353 28 1200 5 0.0353 29 1200 100.0453 30 1200 100.0436 31 1200 200.0348 32 1200 200.0357 I am able to enter my data into R and obtain an ANOVA table (which I have been able to verify as correct using an excel spreadsheet), using the following syntax: Factorial-data.frame(A=c(rep(c(600, 600, 600, 600, 800, 800, 800, 800, 1000, 1000, 1000, 1000, 1200, 1200, 1200, 1200), each=2)), B=c(rep(c(2.5, 5, 10, 20, 2.5, 5, 10, 20, 2.5, 5, 10, 20, 2.5, 5, 10, 20), each=2)), Response = c(0.0257, 0.0254, 0.0217, 0.0204, 0.0191, 0.021, 0.0133, 0.0139, 0.0312, 0.0317, 0.0307, 0.0309, 0.033, 0.0318, 0.0225, 0.0234, 0.035, 0.0352, 0.0373, 0.0361, 0.0432, 0.0402, 0.0297, 0.0306, 0.0324, 0.0326, 0.0353, 0.0353, 0.0453, 0.0436, 0.0348, 0.0357)) anova(aov(Response~A*B, data=Factorial)) However, this is as far as I am able to go. I would like to obtain the coefficients of my model, but am unable. I would also like to use other non-linear models as these factors are not linear. Also would like to add A^2 and B^2 into the ANOVA and modeling. Try: model - lm(Response~A*B, data=Factorial) anova(model) Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fitting truncated normal distribution
Hi, Markus, One other suggestion is to add the lower argument to fitdistr: fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1), lower = 0) where dtnorm0 is defined as before. This indicates to fitdistr that the optimization should be constrained. See ?optim for details. --sundar Schweitzer, Markus wrote: Thank you Sundar, Yes, always integers. By demand data I meant the amount of ordered products in a certain period. Therefore, x is a vector of periods (i.e. Weeks in a year) In my example we could see an article, that has only been ordered in two weeks within one year. All the zeros show, that nobody has ordered the items in these periods. (First half of the year/first 24 weeks) Since the orders cannot be negative, some literature recommended to use a truncated normal distribution (Poisson and negative binomial are also recommended). My x is just a sample out of the dataset. There might be other time series with better attributes for a truncated normal distribution. My problem is simply, that I only get an error message when I use fitdistr. Error in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) nothing to replace. I hope, there is a way fitdistr can also compute difficult data. Best regards, markus -Original Message- From: Sundar Dorai-Raj [mailto:[EMAIL PROTECTED] Sent: Donnerstag, 17. August 2006 16:47 To: Schweitzer, Markus Cc: r-help@stat.math.ethz.ch Subject: Re: [R] fitting truncated normal distribution Hi, Markus, Are these always integers? Why do you think they should be normal or Weibull? Seems more like a mixture with a point mass at 0 and something else (e.g. Poisson, negative binomial, normal). Though it's hard to tell with what you have provided. If that's the case you'll have to write your own likelihood function or, if they are integers, use zip (zero-inflated Poisson) or zinb (zero-inflated negative binomial). Do an RSiteSearch to find many packages will do these fits. RSiteSearch(zero-inflated) Again, this is pure speculation based on your x below alone and no other information (I'm not sure what demand-data means). HTH, --sundar Schweitzer, Markus wrote: Sorry, that I forgot an example. I have demand-data which is either 0 or a positive value. When I have an article which is not ordered very often, it could look like this: x=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1280,0,0,0,0,640,0 ,0 ,0,0,0,0,0,0,0) library(MASS) ## for fitdistr library(msm) ## for dtnorm dtnorm0 - function(x, mean = 0, sd = 1, log = FALSE) { dtnorm(x, mean, sd, 0, Inf, log) } fitdistr(x,dtnorm0,start=list(mean=0,sd=1)) Unfortunately I get the same error message. I found a function, that works for a weibull distribution and tried to apply it but it didn't work neither # truncated weibull distribution #dweibull.trunc - #function(x, shape, scale=1, trunc.=Inf, log=FALSE){ #ln.dens - (dweibull(x, shape, scale, log=TRUE) #-pweibull(trunc., shape, scale = 1, lower.tail = TRUE, log.p = #TRUE)) #if(any(oops - (xtrunc.))) #ln.dens[oops] - (-Inf) #if(log)ln.dens else exp(ln.dens) #} # #x - rweibull(100, 1) #range(x) #x4 - x[x=4] #fitdistr(x4, dweibull.trunc, start=list(shape=1, scale=1), trunc=4) ## ## # truncated normal distribution dtnorm0 - function(x, mean, sd, a=0, log = FALSE) { ln.dens - (dnorm(x, mean, sd) - pnorm(a, mean, sd, lower.tail=TRUE, log.p =TRUE)) if(any(oops - (xa))) ln.dens[oops] - (-Inf) if(log)ln.dens else exp(ln.dens) } fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1)) Maybe, when I alter mean and sd, I get an answer, which is not really satisfactory. I hope, there is a solution possible And thank you in advance markus Sorry, didn't notice that you *did* mention dtnorm is part of msm. Ignore that part of the advice... --sundar Sundar Dorai-Raj wrote: [EMAIL PROTECTED] wrote: Hello, I am a new user of R and found the function dtnorm() in the package msm. My problem now is, that it is not possible for me to get the mean and sd out of a sample when I want a left-truncated normal distribution starting at 0. fitdistr(x,dtnorm, start=list(mean=0, sd=1)) returns the error message Fehler in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) :nichts zu ersetzen I don't know, where to enter the lower/upper value. Is there a possibility to program the dtnorm function by myself? Thank you very much in advance for your help, markus --- Versendet durch aonWebmail (webmail.aon.at) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained,
[R] Insert rows - how can I accomplish this in R
Hi, I have following dataframe. Column A indicates months. DF - structure(list(A = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 7, 8, 11, 12, 1, 2, 3, 4, 5, 8), B = c(0, 0, 0, 8, 0, 19, 5, 19, 0, 0, 0, 11, 0, 8, 5, 11, 19, 8, 11, 10, 0, 8, 36, 10, 16, 10, 22)), .Names = c(A, B), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27)) There is some discontinuity in the data. For example month 6, 9,10 data (2nd year) and month 6 data (3rd year) are absent. I want to insert the rows in place of these missing months and set the corresponding B column to zero. i.e., the result should look like: DFNEW - structure(list(A = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8), B = c(0, 0, 0, 8, 0, 19, 5, 19, 0, 0, 0, 11, 0, 8, 5, 11, 19, 0, 8, 11, 0, 0, 10, 0, 8, 36, 10, 16, 10, 0, 0, 22)), .Names = c(A, B), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32)) Thanks in advance. Sachin - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] 4^2 factorial help
If you really want the quadratic terms, you need to keep those variables as numeric, instead of factors. (You might also want to look into something like the central composite designs.) summary() and coef() on the resulting fitted object should give you want you need. Things like these are covered in the An Introduction to R manual... Andy From: [EMAIL PROTECTED] To whom it may concern: I am trying a factorial design a system of mine that has two factors. Each factor was set at four different levels, with one replication for each of the combinations. My data is as follows: A B Response 16002.5 0.0257 26002.5 0.0254 36005 0.0217 46005 0.0204 5600100.0191 6600100.0210 7600200.0133 8600200.0139 98002.5 0.0312 10 800 2.5 0.0317 11 800 5 0.0307 12 800 5 0.0309 13 800 100.0330 14 800 100.0318 15 800 200.0225 16 800 200.0234 17 1000 2.5 0.0350 18 1000 2.5 0.0352 19 1000 5 0.0373 20 1000 5 0.0361 21 1000 100.0432 22 1000 100.0402 23 1000 200.0297 24 1000 200.0306 25 1200 2.5 0.0324 26 1200 2.5 0.0326 27 1200 5 0.0353 28 1200 5 0.0353 29 1200 100.0453 30 1200 100.0436 31 1200 200.0348 32 1200 200.0357 I am able to enter my data into R and obtain an ANOVA table (which I have been able to verify as correct using an excel spreadsheet), using the following syntax: Factorial-data.frame(A=c(rep(c(600, 600, 600, 600, 800, 800, 800, 800, 1000, 1000, 1000, 1000, 1200, 1200, 1200, 1200), each=2)), B=c(rep(c(2.5, 5, 10, 20, 2.5, 5, 10, 20, 2.5, 5, 10, 20, 2.5, 5, 10, 20), each=2)), Response = c(0.0257, 0.0254, 0.0217, 0.0204, 0.0191, 0.021, 0.0133, 0.0139, 0.0312, 0.0317, 0.0307, 0.0309, 0.033, 0.0318, 0.0225, 0.0234, 0.035, 0.0352, 0.0373, 0.0361, 0.0432, 0.0402, 0.0297, 0.0306, 0.0324, 0.0326, 0.0353, 0.0353, 0.0453, 0.0436, 0.0348, 0.0357)) anova(aov(Response~A*B, data=Factorial)) However, this is as far as I am able to go. I would like to obtain the coefficients of my model, but am unable. I would also like to use other non-linear models as these factors are not linear. Also would like to add A^2 and B^2 into the ANOVA and modeling. Please can you help with regard and offer some advice. Your help is much appreciated. Yours sincerely, Leslie Correia Department of Process Engineering University of Stellenbosch Private Bag X1 Matieland, 7602 Stellenbosch Tel: 0837012017 E-mail: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice package par.settings/trellis.par.settings questions
I am also trying to learn about lattice plots. To get a succinct listing of the names of the lists of default parameter settings, try: names(trellis.par.get()) To get a succinct listing of all the default parameter settings, try: str(trellis.par.get()) HTH, Maurice Haynes -Original Message- From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] Sent: Friday, August 18, 2006 12:36 AM To: Debarchana Ghosh Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Lattice package par.settings/trellis.par.settings questions The parameter names are axis.text$font and axis.text$cex . Try issuing the command: trellis.par.get() to get a complete list. Here is an example: histogram(1:10, par.settings = list(axis.text = list(font = 2, cex = 0.5))) On 8/17/06, Debarchana Ghosh [EMAIL PROTECTED] wrote: Hi All, I'm trying to modify some of the default graphic parameters in a conditional histogram. While I was able to change the default grey background to white, I couldn't change the axis.font or the xlab font. I used the following code: /histogram(~V751|V013+V025, finalbase, xlab=Heard of HIV/AIDS (No/Yes), col=c(cyan,magenta), par.settings=list(background=white)) /The arguments for example like /axis.font=2/, or /cex=2/ are not working in the /par.settings(). /I also tried to read the manual of /trellis.par.settings()/ but didn't understand how to use it and where exactly to put it. Any help with this will be appreciated. Thanks, Debarchana. -- Debarchana Ghosh Research Assistant Department of Geography University of Minnesota PH: 8143607580 email to: [EMAIL PROTECTED] www.tc.umn.edu/~ghos0033 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Variance Components in R
Harold, I don't have a grouping variable. And yes, persons can be an important source of variance, and they are the resp variable. rating is the response.variable in the model you specified below. aov perhaps could give me distorted results, because of unbalanced data (what estimation method it uses? ANOVA?): not all respondents evaluated all stores. I have five variables: resp (persons, the respondents), aspect (the construct), item (the question), chain (the store the person is rating) and sector (the economic sector where chain belongs, e.g. groceries). And one response, rating. The model would be? fm - lmer(rating ~ resp + aspect + item + chain + sector + sector*resp + sector*aspect + sector*item + chain*resp + chain*aspect + chain*item + resp*aspect + resp*item + sector*resp*aspect + sector*resp*item + chain*resp*aspect) Regards, Iuri. On 8/17/06, Doran, Harold [EMAIL PROTECTED] wrote: Iuri: Here is an example of how a model would be specified using lmer using a couple of your factors: fm - lmer(response.variable ~ chain*sector*resp +(chain*sector*resp|GroupingID), data) This will give you a main effect for each factor and all possible interactions. However, do you have a grouping variable? I wonder if aov might be the better tool for your G-study? As a side note, I don't see that you have a factor for persons. Isn't this also a variance component of interest for your study? -- *From:* [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] *On Behalf Of *Iuri Gavronski *Sent:* Thursday, August 17, 2006 1:26 PM *To:* Doran, Harold *Cc:* r-help@stat.math.ethz.ch *Subject:* Re: [R] Variance Components in R I am trying to replicate Finn and Kayandé (1997) study on G-theory application on Marketing. The idea is to have people evaluate some aspects of service quality for chains on different economy sectors. Then, conduct a G-study to identify the generalizability coefficient estimates for different D-study designs. I have persons rating 3 different items on 3 different aspects of service quality on 3 chains on 3 sectors. It is normally assumed on G-studies that the factors are random. So I have to specify a model to estimate the variance components of CHAIN SECTOR RESP ASPECT ITEM, and the interaction of SECTOR*RESP SECTOR*ASPECT SECTOR*ITEM CHAIN*RESP CHAIN*ASPECT CHAIN*ITEM RESP*ASPECT RESP*ITEM SECTOR*RESP*ASPECT SECTOR*RESP*ITEM CHAIN*RESP*ASPECT. '*' in VARCOMP means a crossed design. Evaluating only the two dimensions interactions (x*y) ran in few minutes with the full database. Including three interactions (x*y*z) didn't complete the execution at all. I have the data and script sent to a professor of the department of Statistics on my university and he could not run it on either SPSS or SAS (we don't have SAS licenses here at the business school, only SPSS). Nobody here at the business school has any experience with R, so I don't have anyone to ask for help. Ì am not sure if I have answered you question, but feel free to ask it again, and I will try to restate the problem. Best regards, Iuri On 8/17/06, Doran, Harold [EMAIL PROTECTED] wrote: This will (should) be a piece of cake for lmer. But, I don't speak SPSS. Can you write your model out as a linear model and give a brief description of the data and your problem? In addition to what Spencer noted as help below, you should also check out the vignette in the mlmRev package. This will give you many examples. vignette('MlmSoftRev') -- *From:* [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] *On Behalf Of *Iuri Gavronski *Sent:* Thursday, August 17, 2006 11:16 AM *To:* Doran, Harold *Subject:* Re: [R] Variance Components in R 9500 records. It didn`t run in SPSS or SAS on Windows machines, so I am trying to convert the SPSS script to R to run in a RISC station at the university. On 8/17/06, Doran, Harold [EMAIL PROTECTED] wrote: Iuri: The lmer function is optimal for large data with crossed random effects. How large are your data? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Iuri Gavronski Sent: Thursday, August 17, 2006 11:08 AM To: Spencer Graves Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Variance Components in R Thank you for your reply. VARCOMP is available at SPSS advanced models, I'm not sure for how long it exists... I only work with SPSS for the last 4 years... My model only has crossed random effects, what perhaps would drive me to lmer(). However, as I have unbalanced data (why it is normally called 'unbalanced design'? the data was not intended to be unbalanced, only I could not get responses for all cells...), I'm afraid that REML would take too much CPU, memory and time to execute, and MINQUE would be faster and provide similar variance estimates (please, correct me if I'm wrong on that point).
Re: [R] Insert rows - how can I accomplish this in R
Here are two solutions. In both we break up DF into rows which start with 1. In solution #1 we create a new data frame with the required sequence for A and zeros for B and then we fill it in. In solution #2 we convert each set of rows to a zoo object z where column A is the times and B is the data. We convert that zoo object to a ts object (which has the effect of filling in the missing times) and then create a zoo object with no data from its times merging that zoo object with z using a fill of 0. Finally in both solutions we reconstruct the rows from that by rbind'ing everything together. # 1 f - function(x) { DF - data.frame(A = 1:max(x$A), B = 0) DF[x$A,B] - x$B DF } do.call(rbind, by(DF, cumsum(DF$A == 1), f)) # 2 library(zoo) f - function(x) { z - zoo(x$B, x$A) ser - merge(zoo(,time(as.ts(z)), z, fill = 0) data.frame(A = time(ser), B = coredata(ser)) } do.call(rbind, by(DF, cumsum(DF$A == 1), f) On 8/18/06, Sachin J [EMAIL PROTECTED] wrote: Hi, I have following dataframe. Column A indicates months. DF - structure(list(A = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 7, 8, 11, 12, 1, 2, 3, 4, 5, 8), B = c(0, 0, 0, 8, 0, 19, 5, 19, 0, 0, 0, 11, 0, 8, 5, 11, 19, 8, 11, 10, 0, 8, 36, 10, 16, 10, 22)), .Names = c(A, B), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27)) There is some discontinuity in the data. For example month 6, 9,10 data (2nd year) and month 6 data (3rd year) are absent. I want to insert the rows in place of these missing months and set the corresponding B column to zero. i.e., the result should look like: DFNEW - structure(list(A = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8), B = c(0, 0, 0, 8, 0, 19, 5, 19, 0, 0, 0, 11, 0, 8, 5, 11, 19, 0, 8, 11, 0, 0, 10, 0, 8, 36, 10, 16, 10, 0, 0, 22)), .Names = c(A, B), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32)) Thanks in advance. Sachin - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Insert rows - how can I accomplish this in R
Gabor, Thanks a lot for the help. The 1st method works fine. In 2nd method I am getting following error. do.call(rbind, by(DF, cumsum(DF$A == 1), f)) Error in zoo(, time(as.ts(z)), z, fill = 0) : unused argument(s) (fill ...) Unable to figure out the cause. Thanks, Sachin Gabor Grothendieck [EMAIL PROTECTED] wrote: Here are two solutions. In both we break up DF into rows which start with 1. In solution #1 we create a new data frame with the required sequence for A and zeros for B and then we fill it in. In solution #2 we convert each set of rows to a zoo object z where column A is the times and B is the data. We convert that zoo object to a ts object (which has the effect of filling in the missing times) and then create a zoo object with no data from its times merging that zoo object with z using a fill of 0. Finally in both solutions we reconstruct the rows from that by rbind'ing everything together. # 1 f - function(x) { DF - data.frame(A = 1:max(x$A), B = 0) DF[x$A,B] - x$B DF } do.call(rbind, by(DF, cumsum(DF$A == 1), f)) # 2 library(zoo) f - function(x) { z - zoo(x$B, x$A) ser - merge(zoo(,time(as.ts(z)), z, fill = 0) data.frame(A = time(ser), B = coredata(ser)) } do.call(rbind, by(DF, cumsum(DF$A == 1), f) On 8/18/06, Sachin J wrote: Hi, I have following dataframe. Column A indicates months. DF - structure(list(A = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 7, 8, 11, 12, 1, 2, 3, 4, 5, 8), B = c(0, 0, 0, 8, 0, 19, 5, 19, 0, 0, 0, 11, 0, 8, 5, 11, 19, 8, 11, 10, 0, 8, 36, 10, 16, 10, 22)), .Names = c(A, B), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27)) There is some discontinuity in the data. For example month 6, 9,10 data (2nd year) and month 6 data (3rd year) are absent. I want to insert the rows in place of these missing months and set the corresponding B column to zero. i.e., the result should look like: DFNEW - structure(list(A = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8), B = c(0, 0, 0, 8, 0, 19, 5, 19, 0, 0, 0, 11, 0, 8, 5, 11, 19, 0, 8, 11, 0, 0, 10, 0, 8, 36, 10, 16, 10, 0, 0, 22)), .Names = c(A, B), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32)) Thanks in advance. Sachin - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Insert rows - how can I accomplish this in R
I did run it so I am not sure how the error crept in. Anyways, I have fixed it and a corrected version is below. --- Here are two solutions. In both we break up DF into rows which start with 1. In #1 we create a new data frame with the required sequence for A and zeros for B and then we fill it in. In #2 we convert each set of rows to a zoo object z where column A is the times and B is the data. We convert that zoo object to a ts object (which has the effect of filling in the missing times) and then create a zoo object with no data from that merging it with z using a fill of 0. Finally in both solutions we reconstruct the rows from that by rbind'ing everything together. # 1 f - function(x) { DF - data.frame(A = 1:max(x$A), B = 0) DF[x$A,B] - x$B DF } do.call(rbind, by(DF, cumsum(DF$A == 1), f)) # 2 library(zoo) f - function(x) { z - zoo(x$B, x$A) ser - merge(zoo(,time(as.ts(z))), z, fill = 0) data.frame(A = time(ser), B = coredata(ser)) } do.call(rbind, by(DF, cumsum(DF$A == 1), f)) On 8/18/06, Sachin J [EMAIL PROTECTED] wrote: Gabor, Thanks a lot for the help. The 1st method works fine. In 2nd method I am getting following error. do.call(rbind, by(DF, cumsum(DF$A == 1), f)) Error in zoo(, time(as.ts(z)), z, fill = 0) : unused argument(s) (fill ...) Unable to figure out the cause. Thanks, Sachin Gabor Grothendieck [EMAIL PROTECTED] wrote: Here are two solutions. In both we break up DF into rows which start with 1. In solution #1 we create a new data frame with the required sequence for A and zeros for B and then we fill it in. In solution #2 we convert each set of rows to a zoo object z where column A is the times and B is the data. We convert that zoo object to a ts object (which has the effect of filling in the missing times) and then create a zoo object with no data from its times merging that zoo object with z using a fill of 0. Finally in both solutions we reconstruct the rows from that by rbind'ing everything together. # 1 f - function(x) { DF - data.frame(A = 1:max(x$A), B = 0) DF[x$A,B] - x$B DF } do.call(rbind, by(DF, cumsum(DF$A == 1), f)) # 2 library(zoo) f - function(x) { z - zoo(x$B, x$A) ser - merge(zoo(,time(as.ts(z)), z, fill = 0) data.frame(A = time(ser), B = coredata(ser)) } do.call(rbind, by(DF, cumsum(DF$A == 1), f) On 8/18/06, Sachin J wrote: Hi, I have following dataframe. Column A indicates months. DF - structure(list(A = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 7, 8, 11, 12, 1, 2, 3, 4, 5, 8), B = c(0, 0, 0, 8, 0, 19, 5, 19, 0, 0, 0, 11, 0, 8, 5, 11, 19, 8, 11, 10, 0, 8, 36, 10, 16, 10, 22)), .Names = c(A, B), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27)) There is some discontinuity in the data. For example month 6, 9,10 data (2nd year) and month 6 data (3rd year) are absent. I want to insert the rows in place of these missing months and set the corresponding B column to zero. i.e., the result should look like: DFNEW - structure(list(A = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8), B = c(0, 0, 0, 8, 0, 19, 5, 19, 0, 0, 0, 11, 0, 8, 5, 11, 19, 0, 8, 11, 0, 0, 10, 0, 8, 36, 10, 16, 10, 0, 0, 22)), .Names = c(A, B), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32)) Thanks in advance. Sachin - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Do you Yahoo!? Next-gen email? Have it all with the all-new Yahoo! Mail Beta. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] lmList and missing values
Dear all, I have a question on handling of missing values in lmList. My data set have continuous predictor and response, x and y, and a grouping variable group.id. All these variables have NAs and the data set also has several other variables that also contains NAs. To create the lmList-object seems to work fine: y.list - lmList(y ~ x | group.id, data=mydata, na.action=na.omit) However, when I try to apply functions on the object such as coef or intervals it fails: coef(y.list) Error in !unlist(lapply(coefs, is.null)) : invalid argument type If I beforehand select only the variables (still including missing values) used as arguments in lmList... mydata2 - mydata[ , c(x, y, group)] ...and use mydata2 in lmList as above, coef and intervals works fine. In order to provide a reproducible example, I made a small test data set. This data set contained the same pattern of NAs as in my real data set, i.e. NAs in both used and unused variables. The example turned out to be not very illustrative though, because strange enough 'na.action=na.omit' works just fine on the small test data set so I don't bother to include it here... I have not encountered any problems to apply other functions, such as lm or lme, to my data set. Any idea what causes the error? A related problem seems to have occured before, although it is not clear if different na.action options was tried in this case: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/14293.html Thanks in advance for any help! Best regards, Henrik -- Henrik Pärn Department of Biology NTNU 7491 Trondheim Norway +47 735 96282 (office) +47 909 89 255 (mobile) +47 735 96100 (fax) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] as.data.frame(cbind()) transforming numeric to factor?
Dear List, why does as.data.frame(cbind()) transform numeric variables to factors, once one of the other variablesused is a character vector? # x.1 - rnorm(10) x.2 - c(rep(Test,10)) Foo - as.data.frame(cbind(x.1)) is.factor(Foo$x.1) Foo - as.data.frame(cbind(x.1,x.2)) is.factor(Foo$x.1) # I assume there is a good reason for this, can somebody explain? Thanks. Best, Tom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Query: how to modify the plot of acf
I need to modify the graph of the autocorrelation. I tried to do it through plot.acf but with no success. 1. I would like to get rid of the lag zero 2. I would like to have numbers on the x-axis only at lags 12, 24, 36, 48, 60, ... Could anybody help me in this? Any help will be appreciated Thank you for your attention Stefano [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice package par.settings/trellis.par.settings questions
On 8/17/06, Debarchana Ghosh [EMAIL PROTECTED] wrote: Hi All, I'm trying to modify some of the default graphic parameters in a conditional histogram. While I was able to change the default grey background to white, I couldn't change the axis.font or the xlab font. The default background is no longer grey in the latest release. I used the following code: /histogram(~V751|V013+V025, finalbase, xlab=Heard of HIV/AIDS (No/Yes), col=c(cyan,magenta), par.settings=list(background=white)) /The arguments for example like /axis.font=2/, or /cex=2/ are not working in the /par.settings(). /I also tried to read the manual of /trellis.par.settings()/ but didn't understand how to use it and where exactly to put it. The documentation is certainly lacking in this area (I hope to improve it in the coming months). Gabor mentioned the settings for axis labels. The xlab text is controlled by par.xlab.text, try: str(trellis.par.get(par.xlab.text)) Both can be controlled in the call directly, e.g. histogram(1:10, scales = list(font = 2, cex = 0.5), xlab = list(cex = 2, col = 'red')) Such use /is/ fairly well documented. Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R-update - what about packages and ESS?
Hi there, it seems that if I update R, it doesn't find previously installed packages anymore and is also not found by ESS. Actually the update has been done by our system administrator who assumed that there would be no problems with these things (I don't have root access to this system) and will perhaps not be too keen on installing everything else again. Is there any simple way how ESS and the packages can be connected to the new R? I remember that whenever I updated R on my private computers, I installed everything else again as well - but that's certainly not everybodies taste... Best, Christian *** --- *** Christian Hennig University College London, Department of Statistical Science Gower St., London WC1E 6BT, phone +44 207 679 1698 [EMAIL PROTECTED], www.homepages.ucl.ac.uk/~ucakche __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice package par.settings/trellis.par.settings questions
On 8/17/06, Anupam Tyagi [EMAIL PROTECTED] wrote: Please read about lattice.par.settings, and not trellis.par.settings. Trellis is in S/S-plus. As far as I know, there's no such thing as lattice.par.settings. ``Trellis''-compatible things in the lattice package have the same names as the original. Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] as.data.frame(cbind()) transforming numeric to factor?
On Fri, 2006-08-18 at 10:41 -0400, Tom Boonen wrote: Dear List, why does as.data.frame(cbind()) transform numeric variables to factors, once one of the other variablesused is a character vector? # x.1 - rnorm(10) x.2 - c(rep(Test,10)) Foo - as.data.frame(cbind(x.1)) is.factor(Foo$x.1) Foo - as.data.frame(cbind(x.1,x.2)) is.factor(Foo$x.1) # I assume there is a good reason for this, can somebody explain? Thanks. Best, Tom See the Note section of ?cbind, which states: The method dispatching is not done via UseMethod(), but by C-internal dispatching. Therefore, there is no need for, e.g., rbind.default. The dispatch algorithm is described in the source file (‘.../src/main/bind.c’) as 1. For each argument we get the list of possible class memberships from the class attribute. 2. We inspect each class in turn to see if there is an an applicable method. 3. If we find an applicable method we make sure that it is identical to any method determined for prior arguments. If it is identical, we proceed, otherwise we immediately drop through to the default code. If you want to combine other objects with data frames, it may be necessary to coerce them to data frames first. (Note that this algorithm can result in calling the data frame method if the arguments are all either data frames or vectors, and this will result in the coercion of character vectors to factors.) Thus, note the result of: str(cbind(x.1, x.2)) chr [1:10, 1:2] -0.265756038510064 2.13220714034528 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:2] x.1 x.2 Since a matrix can only contain a single data type, the numeric vector is coerced to character. Then using as.data.frame() coerces the character matrix to factors, which is the default behavior. If you want to create a data frame, do it this way: str(data.frame(x.1, x.2)) `data.frame': 10 obs. of 2 variables: $ x.1: num -0.266 2.132 2.096 -0.128 -0.466 ... $ x.2: Factor w/ 1 level Test: 1 1 1 1 1 1 1 1 1 1 or if you want to retain the character vector, use I(): str(data.frame(x.1, I(x.2))) `data.frame': 10 obs. of 2 variables: $ x.1: num -0.266 2.132 2.096 -0.128 -0.466 ... $ x.2:Class 'AsIs' chr [1:10] Test Test Test Test ... See ?data.frame for more information. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] as.data.frame(cbind()) transforming numeric to factor?
On Fri, 18 Aug 2006, Tom Boonen wrote: Dear List, why does as.data.frame(cbind()) transform numeric variables to factors, once one of the other variablesused is a character vector? # x.1 - rnorm(10) x.2 - c(rep(Test,10)) Foo - as.data.frame(cbind(x.1)) is.factor(Foo$x.1) Foo - as.data.frame(cbind(x.1,x.2)) is.factor(Foo$x.1) # I assume there is a good reason for this, can somebody explain? Thanks. Only if you can explain the good reason why you did not just use data.frame(x.1, x.2)! cbind() makes a matrix out of vectors, here a character matrix. And then as.data.frame() converts character columns to factors. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] as.data.frame(cbind()) transforming numeric to factor?
In R version 2.4.0 Under development (unstable) (2006-08-08 r38825) one can do this: as.data.frame(cbind(x.1,x.2),stringsAsFactors = FALSE) On 8/18/06, Tom Boonen [EMAIL PROTECTED] wrote: Dear List, why does as.data.frame(cbind()) transform numeric variables to factors, once one of the other variablesused is a character vector? # x.1 - rnorm(10) x.2 - c(rep(Test,10)) Foo - as.data.frame(cbind(x.1)) is.factor(Foo$x.1) Foo - as.data.frame(cbind(x.1,x.2)) is.factor(Foo$x.1) # I assume there is a good reason for this, can somebody explain? Thanks. Best, Tom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] as.data.frame(cbind()) transforming numeric to factor?
Thanks everybody. I recognize my mistake now. I think as.data.frame(cbind(x.1,x.2),stringsAsFactors = FALSE) would be a good idea. Tom On 8/18/06, Prof Brian Ripley [EMAIL PROTECTED] wrote: On Fri, 18 Aug 2006, Tom Boonen wrote: Dear List, why does as.data.frame(cbind()) transform numeric variables to factors, once one of the other variablesused is a character vector? # x.1 - rnorm(10) x.2 - c(rep(Test,10)) Foo - as.data.frame(cbind(x.1)) is.factor(Foo$x.1) Foo - as.data.frame(cbind(x.1,x.2)) is.factor(Foo$x.1) # I assume there is a good reason for this, can somebody explain? Thanks. Only if you can explain the good reason why you did not just use data.frame(x.1, x.2)! cbind() makes a matrix out of vectors, here a character matrix. And then as.data.frame() converts character columns to factors. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R-update - what about packages and ESS?
ESS finds R by one of two mechanisms. If R is in your PATH, then ESS will find it. Or, if you have explicitly set the emacs variable inferior-R-program-name, in .emacs, site-start.el, or ess-site.el, then ESS will find R. My guess is that you have explicitly set inferior-R-program-name to your previous version of R. Rich __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] apply least angle regression to generalized linear models
Hello list, I've been searching around trying to find whether somebody has written such a package of least angle regression on generalized linear models, like what Lasso2 package does. The extension to generalized linear models is briefly discussed in the comment by D. Madigan and G. Ridgeway. Is such a package available? Thanks, Mike [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R-update - what about packages and ESS?
Without knowing your OS this is hard to answer (and is the wrong list for the ESS question). For Windows users, the packages part is covered in the rw-FAQ. For Unix-alikes, it all depends how the update was done, but normal package update mechanisms (such as RPM) will not wipe out previously installed R packages: nor will 'make install'. In either case you don't need root access to install packages, as you can use a private library. We have things set up so a user's R_LIBS is something like R_LIBS=~/Rlibrary:/usr/local/Rlibs:/usr/local/BioC and then install.packages() automatically installs into the user's own library (if it has been created). On Fri, 18 Aug 2006, Christian Hennig wrote: Hi there, it seems that if I update R, it doesn't find previously installed packages anymore and is also not found by ESS. Actually the update has been done by our system administrator who assumed that there would be no problems with these things (I don't have root access to this system) and will perhaps not be too keen on installing everything else again. Is there any simple way how ESS and the packages can be connected to the new R? I remember that whenever I updated R on my private computers, I installed everything else again as well - but that's certainly not everybodies taste... Best, Christian *** --- *** Christian Hennig University College London, Department of Statistical Science Gower St., London WC1E 6BT, phone +44 207 679 1698 [EMAIL PROTECTED], www.homepages.ucl.ac.uk/~ucakche __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Boxplot Help
Hello R-users and developers, Once again, I'm asking for your help. I can identify outliers in boxplot with this instruction result - boxplot( Income ~ Sex, col = lightgray, data=dados) if (length(result$out)) text(result$group, result$out, result$out, pos = 4, col = red) But I can not identify the outlier's id (variable names) in the boxplot. Can anyone help me? Thanks in advance, Atenciosamente, Ana Patricia Martins --- Serviço Métodos Estatísticos Departamento de Metodologia Estatística INE - Portugal Telef: 218 426 100 - Ext: 3210 E-mail: mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] apply least angle regression to generalized linear models
On Fri, 2006-08-18 at 11:17 -0400, Mike Wolfgang wrote: Hello list, I've been searching around trying to find whether somebody has written such a package of least angle regression on generalized linear models, like what Lasso2 package does. The extension to generalized linear models is briefly discussed in the comment by D. Madigan and G. Ridgeway. Is such a package available? Thanks, Mike See the aptly named 'lars' package on CRAN and the attendant paper here: http://www-stat.stanford.edu/~hastie/Papers/LARS/LeastAngle_2002.pdf You might also want to review Professor Hastie's presentation at useR! 2006 this past spring: http://www.r-project.org/useR-2006/Slides/Hastie.pdf HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R-update - what about packages and ESS?
Thanks for the answers so far. I have to go through this with my system administrator. The system is slackware linux. For Unix-alikes, it all depends how the update was done, but normal package update mechanisms (such as RPM) will not wipe out previously installed R packages: nor will 'make install'. I don't really understand what does not wipe out means. Certainly, the packages are not deleted from the hard disk, but... Am I right that I should expect it as standard behaviour that all previously installed packages are found if R is updated in a straightforward manner (using make install, say)? Or is the opposite true that I definitely should not expect it? (And is there any standard solution for this else than installing all packages again?) In either case you don't need root access to install packages, as you can use a private library. That's not really enough because I want to have them accessible to students as well. Furthermore, the sysadmin may develop kind of a the whole R-thing is crap-attitude if I can't come up with a solution preventing new installation of all packages, and I don't really want that. So I'm rather not interested in discussing solutions which involve installing all packages again (I know that this is possible). Best, Christian *** --- *** Christian Hennig University College London, Department of Statistical Science Gower St., London WC1E 6BT, phone +44 207 679 1698 [EMAIL PROTECTED], www.homepages.ucl.ac.uk/~ucakche __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] dataframe of unequal rows
Hi, How can I read data of unequal number of observations (rows) as is (i.e. without introducing NA for columns of less observations than the maximum. Example: AB C D 110 1 12 210 3 12 310 4 12 410 510 Thanks in advance. Sachin - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] [Fwd: Trend test and test for homogeneity of odd-ratios]
I partly answered my question since independence_test() function in coin package apparently do Cochran-Armitage trend test just like Eric Lecoutre's function tabletrend() - slightly modified here: independence_test(pheno ~ geno, data = dat2, teststat = quad, scores = list(geno = c(0, 1, 2))) Asymptotic General Independence Test data: pheno by groups 1 2 3 chi-squared = 0.2268, df = 1, p-value = 0.6339 tabletrend(with(dat2, table(pheno, geno))) [1] 0.6338308 Message original Sujet: Trend test and test for homogeneity of odd-ratios Date: Wed, 16 Aug 2006 17:39:33 +0200 De: Jacques VESLOT [EMAIL PROTECTED] Pour: R-Help r-help@stat.math.ethz.ch Dear r-users, I am looking for some R functions to do Cochran-Armitage trend test for 2*3 tables (binary phenotype vs. genotypes) and for testing the homogeneity of odds ratios within 2*3*k tables (binary phenotype vs. genotypes vs. strata). In R-Help archives, I've found a 2003 script by Eric Lecoutre for Cochran-Armitage trend test and a script for Breslow-Day test for 2*2*k tables. Could someone please tell we if there were some functions available on CRAN to do such tests ? Thanks, jacques __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] dataframe of unequal rows
How do you indicate which fields are present in a record with less than the full number? Via known delimiters for all fields? Via the order of values (fields are filled in order and only the last fields in a record can therefore be missing)? If the former, see the sep parameter in read.table() and friends. If the latter, one way is to open the file as a connection and use readLines()(you would check how many values were present and fill in the NA's as needed).There may be better ways, though. ?connections will get you started. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA The business of the statistician is to catalyze the scientific learning process. - George E. P. Box -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sachin J Sent: Friday, August 18, 2006 9:14 AM To: R-help@stat.math.ethz.ch Subject: [R] dataframe of unequal rows Hi, How can I read data of unequal number of observations (rows) as is (i.e. without introducing NA for columns of less observations than the maximum. Example: AB C D 110 1 12 210 3 12 310 4 12 410 510 Thanks in advance. Sachin - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] apply least angle regression to generalized linear models
I believe `lars' does not currently fit glms. For that you'll probably need to look at `glar', at: http://www.insightful.com/Hesterberg/glars/default.asp HTH, Andy From: Marc Schwartz On Fri, 2006-08-18 at 11:17 -0400, Mike Wolfgang wrote: Hello list, I've been searching around trying to find whether somebody has written such a package of least angle regression on generalized linear models, like what Lasso2 package does. The extension to generalized linear models is briefly discussed in the comment by D. Madigan and G. Ridgeway. Is such a package available? Thanks, Mike See the aptly named 'lars' package on CRAN and the attendant paper here: http://www-stat.stanford.edu/~hastie/Papers/LARS/LeastAngle_2002.pdf You might also want to review Professor Hastie's presentation at useR! 2006 this past spring: http://www.r-project.org/useR-2006/Slides/Hastie.pdf HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] apply least angle regression to generalized linear models
Andy, Upon further review of the documentation for lars, you are correct. Thanks for the pointer to the work by Tim et al. Regards, Marc On Fri, 2006-08-18 at 12:48 -0400, Liaw, Andy wrote: I believe `lars' does not currently fit glms. For that you'll probably need to look at `glar', at: http://www.insightful.com/Hesterberg/glars/default.asp HTH, Andy From: Marc Schwartz On Fri, 2006-08-18 at 11:17 -0400, Mike Wolfgang wrote: Hello list, I've been searching around trying to find whether somebody has written such a package of least angle regression on generalized linear models, like what Lasso2 package does. The extension to generalized linear models is briefly discussed in the comment by D. Madigan and G. Ridgeway. Is such a package available? Thanks, Mike See the aptly named 'lars' package on CRAN and the attendant paper here: http://www-stat.stanford.edu/~hastie/Papers/LARS/LeastAngle_2002.pdf You might also want to review Professor Hastie's presentation at useR! 2006 this past spring: http://www.r-project.org/useR-2006/Slides/Hastie.pdf HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Notice: This e-mail message, together with any attachment...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] as.data.frame(cbind()) transforming numeric to factor?
Tom == Tom Boonen [EMAIL PROTECTED] on Fri, 18 Aug 2006 11:16:45 -0400 writes: Tom Thanks everybody. I recognize my mistake now. Tom I thinkas.data.frame(cbind(x.1,x.2),stringsAsFactors = FALSE) Tom would be a good idea. I think data.frame(x.1, x.2 = I(x.2)) would be a considerably better idea. [ The use of I(.) for preventing coercion to factors is a much older and S-like way ] Martin Tom Tom Tom On 8/18/06, Prof Brian Ripley [EMAIL PROTECTED] wrote: On Fri, 18 Aug 2006, Tom Boonen wrote: Dear List, why does as.data.frame(cbind()) transform numeric variables to factors, once one of the other variablesused is a character vector? # x.1 - rnorm(10) x.2 - c(rep(Test,10)) Foo - as.data.frame(cbind(x.1)) is.factor(Foo$x.1) Foo - as.data.frame(cbind(x.1,x.2)) is.factor(Foo$x.1) # I assume there is a good reason for this, can somebody explain? Thanks. Only if you can explain the good reason why you did not just use data.frame(x.1, x.2)! cbind() makes a matrix out of vectors, here a character matrix. And then as.data.frame() converts character columns to factors. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 Tom __ Tom R-help@stat.math.ethz.ch mailing list Tom https://stat.ethz.ch/mailman/listinfo/r-help Tom PLEASE do read the posting guide http://www.R-project.org/posting-guide.html Tom and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] dataframe of unequal rows
Bert, I tried readLines. It reads the data as is, but cant access individual columns. Still cant figure out how to accomplish this. An example would be of great help. PS: How do you indicate which fields are present in a record with less than the full number? - Via known delimiters for all fields. TIA Sachin Berton Gunter [EMAIL PROTECTED] wrote: How do you indicate which fields are present in a record with less than the full number? Via known delimiters for all fields? Via the order of values (fields are filled in order and only the last fields in a record can therefore be missing)? If the former, see the sep parameter in read.table() and friends. If the latter, one way is to open the file as a connection and use readLines()(you would check how many values were present and fill in the NA's as needed).There may be better ways, though. ?connections will get you started. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA The business of the statistician is to catalyze the scientific learning process. - George E. P. Box -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sachin J Sent: Friday, August 18, 2006 9:14 AM To: R-help@stat.math.ethz.ch Subject: [R] dataframe of unequal rows Hi, How can I read data of unequal number of observations (rows) as is (i.e. without introducing NA for columns of less observations than the maximum. Example: A B C D 1 10 1 12 2 10 3 12 3 10 4 12 4 10 5 10 Thanks in advance. Sachin - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] dataframe of unequal rows
test.txt: V1V2V3V4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 The fields are delimited by tab characters (\t) In R: read.table(choose.files(),sep='\t',head=TRUE) V1 V2 V3 V4 1 1 2 3 4 2 5 6 7 NA 3 NA NA 8 9 4 10 NA NA 11 5 12 13 14 15 (I use choose.files() on Windows to select the file via the standard file browser widget) -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA The business of the statistician is to catalyze the scientific learning process. - George E. P. Box -Original Message- From: Sachin J [mailto:[EMAIL PROTECTED] Sent: Friday, August 18, 2006 10:45 AM To: Berton Gunter; R-help@stat.math.ethz.ch Subject: RE: [R] dataframe of unequal rows Bert, I tried readLines. It reads the data as is, but cant access individual columns. Still cant figure out how to accomplish this. An example would be of great help. PS: How do you indicate which fields are present in a record with less than the full number? - Via known delimiters for all fields. TIA Sachin Berton Gunter [EMAIL PROTECTED] wrote: How do you indicate which fields are present in a record with less than the full number? Via known delimiters for all fields? Via the order of values (fields are filled in order and only the last fields in a record can therefore be missing)? If the former, see the sep parameter in read.table() and friends. If the latter, one way is to open the file as a connection and use readLines()(you would check how many values were present and fill in the NA's as needed).There may be better ways, though. ?connections will get you started. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA The business of the statistician is to catalyze the scientific learning process. - George E. P. Box -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sachin J Sent: Friday, August 18, 2006 9:14 AM To: R-help@stat.math.ethz.ch Subject: [R] dataframe of unequal rows Hi, How can I read data of unequal number of observations (rows) as is (i.e. without introducing NA for columns of less observations than the maximum. Example: A B C D 1 10 1 12 2 10 3 12 3 10 4 12 4 10 5 10 Thanks in advance. Sachin - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. How low will we go? Check out Yahoo! Messenger's low PC-to-Phone call rates. http://us.rd.yahoo.com/mail_us/taglines/postman8/*http://us.r d.yahoo.com/evt=39663/*http://voice.yahoo.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 Help
Try this: result - boxplot(Petal.Length ~ Species, iris) if (length(result$out)) text(result$group, result$out, match(result$out, iris$Petal.Length), pos = 4, col = red) If the outliers can be non-unique then match is not enough. In that case assume that the nth occurrence of any value in result$out is also the nth occurrence in the vector boxplotted. (Sort the data frame by group if that is not the case.) This assumption is sufficient to allow us to write posof which gives the index into the data frame of any value in out. # determine position of x in y # assuming that if there are duplicates in x that # they occur the same number of times and in # the same order so that the 2nd occurrence of 37 # in x would correspond to the 2nd occurrence of 37 in y posof - function(x, y) { n - sapply(seq(x), function(m) sum(x[m] == x[1:m])) mapply(function(x, n) which(y == x)[n], x, n) } result - boxplot(Petal.Length ~ Species, iris) if (length(result$out)) text(result$group, result$out, posof(result$out, iris$Petal.Length), pos = 4, col = red) On 8/18/06, Ana Patricia Martins [EMAIL PROTECTED] wrote: Hello R-users and developers, Once again, I'm asking for your help. I can identify outliers in boxplot with this instruction result - boxplot( Income ~ Sex, col = lightgray, data=dados) if (length(result$out)) text(result$group, result$out, result$out, pos = 4, col = red) But I can not identify the outlier's id (variable names) in the boxplot. Can anyone help me? Thanks in advance, Atenciosamente, Ana Patricia Martins --- Serviço Métodos Estatísticos Departamento de Metodologia Estatística INE - Portugal Telef: 218 426 100 - Ext: 3210 E-mail: mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Floating point imprecision in sum() under R-2.3.1?
After upgrading to R-2.3.1 on Linux Redhat, I was suprised by this: R x - c(721.077, 592.291, 372.208, 381.182) R sum(x) - 2066.758 [1] 4.547474e-13 Now I understand that floating point arithmetic is not precise, but 1) the result is exactly 0 in R-2.2.1 (patched) on the same machine, 2) .Machine$double.eps = 2.2e-16, so the error seems quite large. Also note I get the same result on R-2.3.1 under Windows, and that R (721.077 + 592.291 + 372.208 + 381.182) - 2066.758 [1] 0 Is this related to the (2.3.0) NEWS item: sum(), prod(), mean(), rowSums() and friends use a long double accumulator where available and so may be more accurate. and should I be concerned? Thanks. -- David Brahm ([EMAIL PROTECTED]) Version: platform = i686-pc-linux-gnu arch = i686 os = linux-gnu system = i686, linux-gnu status = major = 2 minor = 3.1 year = 2006 month = 06 day = 01 svn rev = 38247 language = R version.string = Version 2.3.1 (2006-06-01) Locale: C Search Path: .GlobalEnv, package:methods, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, Autoloads, package:base __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Query: how to modify the plot of acf
Hi Stefano, the manual tells us that we can access components of an acf object directly by acf.obj[.], but assignment ]- does not work this way. One way of doing what you want is to assign NA to x$acf[x$lag==0] like so: x - acf(runif(100)) x$acf[1] - NA plot(x) But I suppose what you actually want is to have a reasonable ylim to be in effect when plotting your acf. I have struggled with this myself and found the following solution: In plot.acf the formula for the white noise confidence interval is something along the lines of acf.clim - function(x=stop(your acf), n=x$n.used, CL=.95) { cl = qnorm((1+CL)/2)/sqrt(n) attr(cl,CL) - CL return( cl) } Using this function you can plot x - acf(runif(100),plot=F) plot(x, ylim=2*acf.clim(x)*c(-1,1)) # adjust magnification as needed As for your second question we first prevent plotting of x-axis and then add our custom axis: x - acf(runif(1000),100,plot=F) plot(x, ylim=2*acf.clim(x)*c(-1,1),xaxt='n')# note option 'xaxt'! axis(1,at=12*(0:8)) Hope that helps, Matthias NB: It would be a good idea to include the acf.clim(.) inside of the acf object... Now it is somewhat hidden inside of plot.acf x$clim - acf.clim(x) str(x) Stefano Sofia wrote: I need to modify the graph of the autocorrelation. I tried to do it through plot.acf but with no success. 1. I would like to get rid of the lag zero 2. I would like to have numbers on the x-axis only at lags 12, 24, 36, 48, 60, ... Could anybody help me in this? Any help will be appreciated Thank you for your attention Stefano [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Journalist: Mr. Gandhi, what do you think of Western civilization? Gandhi: I think it would be a good idea. ~ Matthias Braeunig, Dipl.Phys. ~University Medical Center Freiburg ~Institute of Environmental Medicine and Hospital Epidemiology ~ Department of Evaluation Research in Complementary Medicine ~ Hugstetter Str. 55, D - 79106 Freiburg, Germany ~ Phone: +49 (0)761 270-8306, Fax: -8343 ~ Web: http://kompmed.uniklinik-freiburg.de ~ Email: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Floating point imprecision in sum() under R-2.3.1?
I think you want to look at sum(x)/2066.758 - 1 which on my Linux box is 2.2e-16. -roger Brahm, David wrote: After upgrading to R-2.3.1 on Linux Redhat, I was suprised by this: R x - c(721.077, 592.291, 372.208, 381.182) R sum(x) - 2066.758 [1] 4.547474e-13 Now I understand that floating point arithmetic is not precise, but 1) the result is exactly 0 in R-2.2.1 (patched) on the same machine, 2) .Machine$double.eps = 2.2e-16, so the error seems quite large. Also note I get the same result on R-2.3.1 under Windows, and that R (721.077 + 592.291 + 372.208 + 381.182) - 2066.758 [1] 0 Is this related to the (2.3.0) NEWS item: sum(), prod(), mean(), rowSums() and friends use a long double accumulator where available and so may be more accurate. and should I be concerned? Thanks. -- David Brahm ([EMAIL PROTECTED]) Version: platform = i686-pc-linux-gnu arch = i686 os = linux-gnu system = i686, linux-gnu status = major = 2 minor = 3.1 year = 2006 month = 06 day = 01 svn rev = 38247 language = R version.string = Version 2.3.1 (2006-06-01) Locale: C Search Path: .GlobalEnv, package:methods, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, Autoloads, package:base __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Roger D. Peng | http://www.biostat.jhsph.edu/~rpeng/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Permutations with replacement
Is there a simple function or process that will create permutations with replacement? I know that using the combinat package ## begin R code ## library(combinat) m - t(array(unlist(permn(3)), dim = c(3, 6))) # we can get the permutations, for example 3!=6 # gives us m [,1] [,2] [,3] [1,]123 [2,]132 [3,]312 [4,]321 [5,]231 [6,]213 ## end R code ## I'd like to include the with replacement possibilities such as 1,1,3 1,1,2 2,3,3 and so on. This will eventually be done on 8!=40,320 rather than the development version using 3! as above. If no function exists (I've Googled on CRAN with no palpable luck), then perhaps this is more of a bootstrap type problem. Thanks for your help in advance, Jesse Canchola ___ The information contained in this e-mail is for the exclusive use of the intended recipient(s) and may be confidential, proprietary, and/or legally privileged. Inadvertent disclosure of this message does not constitute a waiver of any privilege. If you receive this message in error, please do not directly or indirectly use, print, copy, forward, or disclose any part of this message. Please also delete this e-mail and all copies and notify the sender. Thank you. For alternate languages please go to http://bayerdisclaimer.bayerweb.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Floating point imprecision in sum() under R-2.3.1?
I was concerned by this result (new in R-2.3.1): R x - c(721.077, 592.291, 372.208, 381.182) R sum(x) - 2066.758 [1] 4.547474e-13 But after Roger Peng's [EMAIL PROTECTED] insightful comment that the relative difference (sum(x)/2066.758 - 1) is exactly what is expected, I'm convinced that sum() is indeed really being more accurate than it was in 2.2.1, i.e. accurately preserving the numerical imprecision of the original inputs. Sorry for the distraction... -- David Brahm ([EMAIL PROTECTED]) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Permutations with replacement
Is there a simple function or process that will create a matrix of permutations with replacement? I know that using the combinat package ## begin R code ## library(combinat) m - t(array(unlist(permn(3)), dim = c(3, 6))) # we can get the permutations, for example 3!=6 # gives us m [,1] [,2] [,3] [1,]123 [2,]132 [3,]312 [4,]321 [5,]231 [6,]213 ## end R code ## I'd like to include the with replacement possibilities such as 1,1,3 1,1,2 2,3,3 and so on. This will eventually be done on 8!=40,320 rather than the development version using 3! as above. If no function exists (I've Googled on CRAN with no palpable luck), then perhaps this is more of a bootstrap type problem. Thanks for your help in advance, Jesse Canchola ___ The information contained in this e-mail is for the exclusive use of the intended recipient(s) and may be confidential, proprietary, and/or legally privileged. Inadvertent disclosure of this message does not constitute a waiver of any privilege. If you receive this message in error, please do not directly or indirectly use, print, copy, forward, or disclose any part of this message. Please also delete this e-mail and all copies and notify the sender. Thank you. For alternate languages please go to http://bayerdisclaimer.bayerweb.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] multivariate analysis by using lme
Dear R users, I have a data structure as follows: id two res1 res2 c1 c2 inter 1 -0.786093166 1 0 1 2 6 3 -0.308495749 1 0 0 1 2 5 -0.738033048 1 0 0 0 1 7 -0.52176252 1 0 1 0 4 9 -2.023641189 1 0 1 1 5 10 0.463469887 1 0 1 0 4 14 0.379364681 1 0 1 0 4 17 -1.422889721 1 0 0 0 1 19 -2.582340053 1 0 0 2 3 20 0.721793018 1 0 1 2 6 1 -0.867823661 0 1 1 2 6 3 -0.727418536 0 1 0 1 2 5 -0.331731368 0 1 0 0 1 7 -0.835913405 0 1 1 0 4 9 -0.612541616 0 1 1 1 5 10 -0.063685221 0 1 1 0 4 14 0.3511481 0 1 1 0 4 17 -1.38476980 1 0 0 1 19 -2.232306187 0 1 0 2 3 20 0.0014117 0 1 1 2 6 I would like to apply multivariate analysis and test interaction effect in the same model by using lme function. The 'two' variable is a bi-variate outcome by combining two continuous outcomes. The 'res1' and 'res2' are two dummy variables to flag these two outcome variables, separately. The interaction term for c1 and c2 is inter with 6 levels. What I have done are as follows: # capture clustering structure tmp - groupedData(two~res1+res2+inter|id,data=a); tmp - na.exclude(tmp); # treat 'inter' as a multi-level variable options(contrasts=c(factor=contr.treatment,ordered=contr.poly)); tmp$inter - factor(tmp$inter); contrasts(tmp$inter) # perform multivariate analysis and test interaction effect m1 - summary(lme(two~res1+res2+inter, random=~1|id, data=tmp)) ## Error in MEEM(object, conLin, control$niterEM) : ##Singularity in backsolve at level 0, block 1 Unfortunately, I have been unable to get it work. If I removed these two dummy variables like this: m2 - summary(lme(two~inter, random=~1|id, data=tmp)) I did get some outputs, but these outputs in the model m2 were wrong. Is there any way to perform multivariate analysis and test interaction effect (a multi-level factor) in the same model by lme? In addition, can lme be used for multivariate analyses of combining several binary outcome variables? Or it may be doable in some R function? Many thanks for your suggestions. Hui-Ju The contents of this e-mail message and any attachments are private and confidential communications intended solely for the addressee(s) named in this message. If you are not the intended recipient of this message, please 1) immediately notify the sender by reply e-mail and then delete this message and its attachments and 2) do not read, use, distribute disclose or copy this message and/or any attachments. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Permutations with replacement
If you also want 1,1,1 and so on, the number of these is n^n, (n choices for each of n slots.) In that case, you could use hcube from combinat. David L. Reiner Rho Trading Securities, LLC Chicago IL 60605 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jesse Albert Canchola Sent: Friday, August 18, 2006 3:26 PM To: r-help Subject: [R] Permutations with replacement Is there a simple function or process that will create a matrix of permutations with replacement? I know that using the combinat package ## begin R code ## library(combinat) m - t(array(unlist(permn(3)), dim = c(3, 6))) # we can get the permutations, for example 3!=6 # gives us m [,1] [,2] [,3] [1,]123 [2,]132 [3,]312 [4,]321 [5,]231 [6,]213 ## end R code ## I'd like to include the with replacement possibilities such as 1,1,3 1,1,2 2,3,3 and so on. This will eventually be done on 8!=40,320 rather than the development version using 3! as above. If no function exists (I've Googled on CRAN with no palpable luck), then perhaps this is more of a bootstrap type problem. Thanks for your help in advance, Jesse Canchola ___ The information contained in this e-mail is for the exclusive use of the intended recipient(s) and may be confidential, proprietary, and/or legally privileged. Inadvertent disclosure of this message does not constitute a waiver of any privilege. If you receive this message in error, please do not directly or indirectly use, print, copy, forward, or disclose any part of this message. Please also delete this e-mail and all copies and notify the sender. Thank you. For alternate languages please go to http://bayerdisclaimer.bayerweb.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Affy: problems using neweS
At least for R 2.3.1, neweS requires that all of the variables have names that correspond to the colnames of the matrix. That's fine, I know about that, and I use a modified version of neweS that puts the names in there. It works well with data from most sources. However, we tried reading in the matrix from a text file, and again get an error that says sampleNames differ from phenoData rows. What's going on? Modified neweS: neweS - function(mat, vlist, vlabel=as.list(names(vlist))){ names(vlabel)=names(vlist) #Must add appropriate names to the variables in vlist for R 2.3compatibility. for (i in 1:length(vlist)) { names(vlist[[i]]) - colnames(mat) } ### pdata - new(phenoData, pData=as.data.frame(vlist), varLabels=vlabel) eset - new(exprSet, exprs=as.matrix(mat), phenoData=pdata) return(eset) } I believe this is identical to the existing neweS except for the part between the #s. We're stumped here, I'm grateful for any ideas! Thanks John Tillinghast [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] list of lists to a data.frame
Hi, I have a situation where I have a list of lists. Each list can contain elements of different types (but each one will be a scalar) say of double, integer or character. However the elements of each list are always in the same order: x - list('a', 1, 2) y - list('b', 3, 4) z - list('c', 5, 6) a - list(x,y,z) What I'd like to do is to convert a to a data.frame. Currently I am doing: b - do.call(rbind, a) However, when I do b[,1] I get a list returned rather than a vector of characters and similarly for b[,2] and so on. I am clearly missing something, but how do I convert the list of lists to a data.frame where a column is represented as a vector rather than a list? Thanks, --- Rajarshi Guha [EMAIL PROTECTED] GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE --- All life evolves by the differential survival of replicating entities. -- Dawkins __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Floating point imprecision in sum() under R-2.3.1?
But after Roger Peng's [EMAIL PROTECTED] **insightful** comment that the ... but as we are not in that other S language dialect, maybe it should be his **peRceptive** comment. ;-) (Sorry -- it's Friday) -- Bert Gunter __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] list of lists to a data.frame
On Fri, 2006-08-18 at 16:44 -0400, Rajarshi Guha wrote: Hi, I have a situation where I have a list of lists. Each list can contain elements of different types (but each one will be a scalar) say of double, integer or character. However the elements of each list are always in the same order: x - list('a', 1, 2) y - list('b', 3, 4) z - list('c', 5, 6) a - list(x,y,z) What I'd like to do is to convert a to a data.frame. Currently I am doing: b - do.call(rbind, a) However, when I do b[,1] I get a list returned rather than a vector of characters and similarly for b[,2] and so on. I am clearly missing something, but how do I convert the list of lists to a data.frame where a column is represented as a vector rather than a list? Thanks, How about: as.data.frame(sapply(a, rbind)) V1 V2 V3 1 a b c 2 1 3 5 3 2 4 6 or: as.data.frame(t(sapply(a, rbind))) V1 V2 V3 1 a 1 2 2 b 3 4 3 c 5 6 depending upon how you wanted the columns versus rows to be structured. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Permutations with replacement
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jesse Albert Canchola Sent: Friday, August 18, 2006 1:02 PM To: r-help Subject: [R] Permutations with replacement Is there a simple function or process that will create permutations with replacement? I know that using the combinat package ## begin R code ## library(combinat) m - t(array(unlist(permn(3)), dim = c(3, 6))) # we can get the permutations, for example 3!=6 # gives us m [,1] [,2] [,3] [1,]123 [2,]132 [3,]312 [4,]321 [5,]231 [6,]213 ## end R code ## I'd like to include the with replacement possibilities such as 1,1,3 1,1,2 2,3,3 Isn't what you want just sampling with replacement? x - c(1,2,3) sample(x,3,replace=TRUE) Hope this is helpful, Dan Dan Nordlund Bothell, WA USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 Help
In reviewing this I found an error in the case that there is an outlier in one group with an equal value in another group that is not an outlier.Also the iris example does not have duplicate outliers so its not a very good test. Here is a much shorter version that does not have the cited problem. Also we use more suitable test data. For each group, g, we find the indices in x, idx, of the values corresponding to that group in out$out and then we use text() to display those indices. (Note that it will overprint indices if there are multiple outliers with the same value in a group. One could try jittering the x or y values in text to address this.) x - c(1:49, 100, 51:100, 101:148, 50, 50) grp - gl(3, 50) out - boxplot(x ~ grp) for(g in unique(out$group)) { idx - which(x %in% out$out[out$group == g] grp == g) text(g, x[idx], idx, pos = 4, col = 2, cex = .5) } On 8/18/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this: result - boxplot(Petal.Length ~ Species, iris) if (length(result$out)) text(result$group, result$out, match(result$out, iris$Petal.Length), pos = 4, col = red) If the outliers can be non-unique then match is not enough. In that case assume that the nth occurrence of any value in result$out is also the nth occurrence in the vector boxplotted. (Sort the data frame by group if that is not the case.) This assumption is sufficient to allow us to write posof which gives the index into the data frame of any value in out. # determine position of x in y # assuming that if there are duplicates in x that # they occur the same number of times and in # the same order so that the 2nd occurrence of 37 # in x would correspond to the 2nd occurrence of 37 in y posof - function(x, y) { n - sapply(seq(x), function(m) sum(x[m] == x[1:m])) mapply(function(x, n) which(y == x)[n], x, n) } result - boxplot(Petal.Length ~ Species, iris) if (length(result$out)) text(result$group, result$out, posof(result$out, iris$Petal.Length), pos = 4, col = red) On 8/18/06, Ana Patricia Martins [EMAIL PROTECTED] wrote: Hello R-users and developers, Once again, I'm asking for your help. I can identify outliers in boxplot with this instruction result - boxplot( Income ~ Sex, col = lightgray, data=dados) if (length(result$out)) text(result$group, result$out, result$out, pos = 4, col = red) But I can not identify the outlier's id (variable names) in the boxplot. Can anyone help me? Thanks in advance, Atenciosamente, Ana Patricia Martins --- Serviço Métodos Estatísticos Departamento de Metodologia Estatística INE - Portugal Telef: 218 426 100 - Ext: 3210 E-mail: mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.