[R] MANOVA
Hi All, I have questions about MANOVA which I am still not sure if appropriately I should use it. For example I have a data set like this: BloodPressure (BP) Weight Height 120115165 125145198 15699 176 I know that BloodPressure is correlated with both Weight and Height, however colinearity exists between Weight and Height. When I use BP = Weight + Height as the model, one is got to be insignificant. I was trying to use a BP + Weight = Height model, but not sure how to use it. Should I use MANOVA? or I just have to do two equations as BP = Weight Weight = Height Any suggestions and answers are greatly appreciated! Ding [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] MANOVA
You only have one response variable, so MANOVA is not appropriate. One option would be to compare BP ~ Weight + Height with BP ~ 1. That would give you a joint test of weight and height together. Since they are collinear, that should tell you the overall effect of size. There are other options, most of which involve discarding some of the data. Frank Harrell's book is a font of wisdom on this sort of thing. Harrell, F. E., Jr. (2001). Regression Modeling Strategies. Springer. Simon. On Thu, 2009-03-12 at 00:20 -0600, Ding Xiao wrote: Hi All, I have questions about MANOVA which I am still not sure if appropriately I should use it. For example I have a data set like this: BloodPressure (BP) Weight Height 120115165 125145198 15699 176 I know that BloodPressure is correlated with both Weight and Height, however colinearity exists between Weight and Height. When I use BP = Weight + Height as the model, one is got to be insignificant. I was trying to use a BP + Weight = Height model, but not sure how to use it. Should I use MANOVA? or I just have to do two equations as BP = Weight Weight = Height Any suggestions and answers are greatly appreciated! Ding [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician School of Biological Sciences The University of Queensland St. Lucia Queensland 4072 Australia Room 320 Goddard Building (8) T: +61 7 3365 2506 http://www.uq.edu.au/~uqsblomb email: S.Blomberg1_at_uq.edu.au Policies: 1. I will NOT analyse your data for you. 2. Your deadline is your problem. The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ggplot2: saving a grid with multiple plots
ONKELINX, Thierry Thierry.ONKELINX at inbo.be writes: I have managed to create a figure on the screen with multiple plots in it. Something like the example below. When I save that with ggsave(), only the last plot gets saved (pPath in the example) instead of the entire figure. Any suggestions how I can save this kind of figures automated? No idea what the easiest way would be if you want both window and pdf. Dieter library(ggplot2) pPoint - qplot(unemploy/pop, psavert, data=economics) pPath - qplot(unemploy/pop, psavert, data=economics, geom=path) pdf(file=test.pdf) pushViewport(viewport(layout = grid.layout(2, 1))) print(pPoint, vp = viewport(layout.pos.row = 1, layout.pos.col = 1)) print(pPath, vp = viewport(layout.pos.row = 2, layout.pos.col = 1)) dev.off() __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] e1071 SVM one-classification tune problem
Hello all, I am using the e1071 SVM with the tune options for classification, which work pretty well, given the examples of using tune.svm function for classification. But I have not found any example to tune the SVM novelty detection (one-classification) parameters (gamma, cost, nu), for example this are some of the options I have tried with no success: obj-tune(svm, x,y, type =one-classification, gamma=2^(-1:1), cost=2^(1:3), nu=2^(-3:-1)) obj-tune(svm, x,y, type =one-classification, cost=2^(1:3), nu=2^(-3:-1)) obj-tune(svm, x,y, type =one-classification, gamma=2^(-1:1), nu=2^(-3:-1)) obj-tune(svm, x,y, type =one-classification, nu=2^(-3:-1)) obj-tune(svm, x,y, type =one-classification, gamma=2^(-1:1), cost=2^(1:3)) y is expressed as factor of [ 1,-1] values also I tried: obj-tune(svm, x,y, type =one-classification, ranges = list(gamma=2^(-1:1), cost=2^(1:3), nu=2^(-3:-1))) and all the parameters combination showed above, but always the same message: Error in tune(svm, x, y, ranges = .., type = one-classification) : Dependent variable has wrong type! But if I try: svm.model -svm(x,y,type = one-classification,gamma=2, cost =3, nu=0.001) it runs without problems. Please, let me know whether what I should change in my code or the e1071 tune function does not work with SVM one-classification Alfonso Torres [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Removing
Hi All, act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[j]==act_2$Rep[i]){ act_2-act_2[-j,] }else{ act_2-act_2 } } return(act_2) } But it only remove one row..whats the problem? How should i modify it? Thanks alot. Tammy _ Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! http://spaces.live.com/spacesapi.aspx?wx_action=createwx_url=/friends.aspxmkt=en-us [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ggplot2: saving a grid with multiple plots
Dear all, Thanks for all your responses. It looks like I was misinterpreting the capabilities of ggsave(). That can only handle the basic ggplot2 plots (which can be very elaborate). This behaviour is decribed at the end of chapter 8 in the ggplot2 book, but I missed that. Opening and closing a device works well. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Dieter Menne Verzonden: donderdag 12 maart 2009 9:04 Aan: r-h...@stat.math.ethz.ch Onderwerp: Re: [R] Ggplot2: saving a grid with multiple plots ONKELINX, Thierry Thierry.ONKELINX at inbo.be writes: I have managed to create a figure on the screen with multiple plots in it. Something like the example below. When I save that with ggsave(), only the last plot gets saved (pPath in the example) instead of the entire figure. Any suggestions how I can save this kind of figures automated? No idea what the easiest way would be if you want both window and pdf. Dieter library(ggplot2) pPoint - qplot(unemploy/pop, psavert, data=economics) pPath - qplot(unemploy/pop, psavert, data=economics, geom=path) pdf(file=test.pdf) pushViewport(viewport(layout = grid.layout(2, 1))) print(pPoint, vp = viewport(layout.pos.row = 1, layout.pos.col = 1)) print(pPath, vp = viewport(layout.pos.row = 2, layout.pos.col = 1)) dev.off() __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Removing rows
Hi All, act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[i+1]==act_2$Rep[i]){ act_2-act_2[-(i+1),] }else{ act_2-act_2 } } return(act_2) } when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i-i-1, then i go to 1 seems not reasonbale. How should I modify it`? Tammy _ News, entertainment and everything you care about at Live.com. Get it now! http://www.live.com/getstarted.aspx [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R library help files
Dajiang Liu wrote: Dear All, I am writing an R library myself. The package build ok, and can be installed. But when I load the library into R using library('xyz'), then I type ?xyz for help in one of the functions named xyz as well, the following error occured, No documentation for 'xyz' in specified packages and libraries: I do put the .Rd files into the man folder, and the html help files are all well generated. Have you specified \alias{xyz} in the Rd file? Also, run R CMD check on your package which will tell you about such problems. Uwe Ligges Does anyone encounter this before or have any clue about what might cause this? Thanks a lot! Regards, Dajiang _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] who can give me some hint?
Hi All, act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: Not sure what you mean here, can you describe this more fully? It seems that you might be able to avoid using loops if all you want to do is select only the rows where column x is less than a threshold value. e.g. a-a[a$columnx1000,] Hope this helps Simon. rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[i+1]==act_2$Rep[i]){ act_2-act_2[-(i+1),] }else{ act_2-act_2 } } return(act_2) } when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i-i-1, then i go to 1 seems not reasonbale. How should I modify it`? Tammy _ Drag n' drop-Get easy photo sharing with Windows LiveT Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] who can give me some hint?
Hi All, act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[i+1]==act_2$Rep[i]){ act_2-act_2[-(i+1),] }else{ act_2-act_2 } } return(act_2) } when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i-i-1, then i go to 1 seems not reasonbale. How should I modify it`? Please don't repeatedly post the same question - it is irritating, and you're not likely to get a favourable response. Try explaining your problem more clearly. What is the condition that you want to use to keep rows? (In your example, each of the rows is different, yet you kept some and discarded others.) If you just want to discard some rows form a data frame, you don't need a loop, e.g. dfr - data.frame(x=1:10, y=runif(10)) dfr[c(1,3,5,5),] Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] who can give me some hint?
Hi All, act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[i+1]==act_2$Rep[i]){ act_2-act_2[-(i+1),] }else{ act_2-act_2 } } return(act_2) } when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i-i-1, then i go to 1 seems not reasonbale. How should I modify it`? Tammy _ Drag n dropGet easy photo sharing with Windows Live Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] can I draw 3D plot like this using R?
On 11/03/2009 11:35 PM, Oliver wrote: hi, all I am looking at R package RGL to draw a colored mesh/surface plot like this one (from matlab). http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/cbar.gif The key features I am looking for is surfaced with grid and color, but not the terrain-like gradient. but I didn't come even close to it after browsing through rgl help file. It is a little tricky to draw both lines and solid colours on a surface in rgl, because one will hide the other: there's no way to turn off the hidden object removal in rgl. The easiest way to do it would be to draw the grid slightly above the surface. For example, x - seq(-2, 2, len=17) y - seq(-2, 2, len=17) z - outer(x,y, function(x,y) exp(-y^2)*sin(1.5*x)) color - rainbow(41)[1+round(10*outer(x,y, function(x,y) x^2 + y^2))] persp3d(x,y,z, color=color, smooth=FALSE) surface3d(x,y,z+0.001, front=lines, back=culled) (Fiddle with the 0.001 value if the grid disappears behind the surface, or floats too high above it.) Another way would be to draw the grid (and maybe the colour) as a texture. Duncan Murdoch have anyone drawn something like this before, is this doable afterall? thanks Oliver __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problem with 'abline' in a regression with repeated measures
Hi everybody. I'm just learning to use R. I've got a strange problem and I couldn't find any answer to my problem. So here am I. I want to visualize a model of regression on repeated measures : 5 measures (y) by x-value (lx for log10(x) ; lxf colonn is for as.factor) ; 5 x-values. I fail to use 'abline' command (regression's line don't display) in this particular context, on a 'stripchart' display. Any idea ? Here are the few commands that I execute, the lattest being my problem : tab - read.csv2(ex3.csv) sapply(tab,data.class) sujet x xf lx lxf y numeric numeric numeric numeric numeric numeric attach(tab) lxf - as.factor(lxf) model1 - lm(y~lx) model2 - lm(y~lxf) model3 - lm(y~lx+lxf) ym - tapply(y,lxf,mean) ym -0.9 -0.6 -0.3 0 0.3 43.0 60.6 77.2 92.2 109.4 stripchart(y~lx, method=jitter, jitter=.1, vertical=T, pch=20) lines (1:5, ym, type=b, pch=4, cex=2, lty=2) abline(model1) ## I don't understand why it doesn't work ; neither do abline(coef(model1) or abline(92,45) ## It usually works on any regression, but stripchart maybe is a special plot ; I suspect an absciss misunderstanding by abline... Thanks for any help. I simulated this data set : lx lxf y -0,9 -0,9 47 -0,9 -0,9 41 -0,9 -0,9 44 -0,9 -0,9 38 -0,9 -0,9 45 -0,6 -0,6 58 -0,6 -0,6 63 -0,6 -0,6 58 -0,6 -0,6 58 -0,6 -0,6 66 -0,3 -0,3 78 -0,3 -0,3 79 -0,3 -0,3 78 -0,3 -0,3 77 -0,3 -0,3 74 0 0 96 0 0 91 0 0 97 0 0 85 0 0 92 0,3 0,3 109 0,3 0,3 114 0,3 0,3 111 0,3 0,3 104 0,3 0,3 109 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Hi, I'm working with custom slides(Cy5) and worki...
Hi, I'm working with custom slides(Cy5) and working in the normalization of the arrays. I have three arrays (technical replicates). I have sucesfully normalized the data using vsn, however i would like to compare it to the normalization using spike in controls. My controls are annotated as control-1 to x and i would like to do etiher a normalization by block per array or the mean of all the controls per array. Here is the code: library(limma) library(RColorBrewer) library(vsn) Cy5 - F635 Mean Cy5b - B635 Mean targets - readTargets(targets.txt) #My gpr files do only contain 1 channel (Cy5) RG - read.maimages( targets$FileName,source=genepix,columns=list(R=Cy5,G=Cy5, Rb=Cy5b, Gb=Cy5b)) RG$G - NULL RG$Gb - NULL #Here are my spike in controls for normalization isSpikeIn - grep(CTL, RG$genes$Name) #The vsn normalization works fine mat - vsnMatrix(RG$R) However i would like to normaliza using my spikein controls by block or by using the mean of all controls. Could you help on that ?? thanks, david _ Découvrez toutes les possibilités de communication avec vos proches __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RES: Removing rows
Hi Tammy, You can do: act_2temp - act_2[which(!duplicated(act_2[,c(1:5)])),] act_2temp[1:5,] act_2 - act_2temp rm(act_2temp) Atenciosamente, Leandro Lins Marino Centro de Avaliação Fundação CESGRANRIO Rua Santa Alexandrina, 1011 - 2º andar Rio de Janeiro, RJ - CEP: 20261-903 R (21) 2103-9600 R.:236 ( (21) 8777-7907 ( lean...@cesgranrio.org.br Aquele que suporta o peso da sociedade é precisamente aquele que obtém as menores vantagens. (SMITH, Adam) Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO AMBIENTE -Mensagem original- De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Em nome de Tammy Ma Enviada em: quinta-feira, 12 de março de 2009 06:49 Para: r-help@r-project.org Assunto: [R] Removing rows Hi All, act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[i+1]==act_2$Rep[i]){ act_2-act_2[-(i+1),] }else{ act_2-act_2 } } return(act_2) } when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i-i-1, then i go to 1 seems not reasonbale. How should I modify it`? Tammy _ News, entertainment and everything you care about at Live.com. Get it now! http://www.live.com/getstarted.aspx [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] who can give me some hint?
I assume the problem is to only keep those rows whose Rep value is not equal to the Rep value in the prior row. In that case just compare c(, Rep[-nr]) to Rep and use the resulting vector, ix, to select out rows. Rep - as.character(act_2$Rep) could be simplified to Rep - act_2$Rep if Rep is already known to be character. Lines - DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle act_2 - read.table(textConnection(Lines), header = TRUE, as.is = TRUE) nr - nrow(act_2) Rep - as.character(act_2$Rep) ix - Rep != c(, Rep[-nr]) act_2[ix] On Thu, Mar 12, 2009 at 6:25 AM, Tammy Ma metal_lical...@live.com wrote: Hi All, act_2 Date Dtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to Date Dtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[i+1]==act_2$Rep[i]){ act_2-act_2[-(i+1),] }else{ act_2-act_2 } } return(act_2) } when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i-i-1, then i go to 1 seems not reasonbale. How should I modify it`? Tammy _ Drag n’ drop—Get easy photo sharing with Windows Live™ Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] who can give me some hint?
Thanks a lot for your reply. I expect a more flexible solution. Because I couldn't check that column one by one. If another Rep colum is: useractivity_act 2 2 3 3 3 4 5 5 6 useractivity_idle i should be able to write a program to make it as: useractivity_act 2 3 4 5 6 useractivity_idle Only keep 1st value of repeated values. I have been working no it for a whileStill didnt get solution. Thanks for your concentration. Tammy Date: Thu, 12 Mar 2009 08:03:11 -0400 Subject: Re: [R] who can give me some hint? From: ggrothendi...@gmail.com To: metal_lical...@live.com CC: r-help@r-project.org I assume the problem is to only keep those rows whose Rep value is not equal to the Rep value in the prior row. In that case just compare c(, Rep[-nr]) to Rep and use the resulting vector, ix, to select out rows. Rep - as.character(act_2$Rep) could be simplified to Rep - act_2$Rep if Rep is already known to be character. Lines - DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle act_2 - read.table(textConnection(Lines), header = TRUE, as.is = TRUE) nr - nrow(act_2) Rep - as.character(act_2$Rep) ix - Rep != c(, Rep[-nr]) act_2[ix] On Thu, Mar 12, 2009 at 6:25 AM, Tammy Ma metal_lical...@live.com wrote: Hi All, act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[i+1]==act_2$Rep[i]){ act_2-act_2[-(i+1),] }else{ act_2-act_2 } } return(act_2) } when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i-i-1, then i go to 1 seems not reasonbale. How should I modify it`? Tammy _ Drag n dropGet easy photo sharing with Windows Live Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ News, entertainment and everything you care about at Live.com. Get it now! http://www.live.com/getstarted.aspx [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] regsubsets() [leaps package] - please share some good examples of use
Hello dear R-help members, I recently became interested in using biglm with leaps, and found myself somewhat confused as to how to use the two together, in different settings. I couldn't find any example codes for the leaps() package (except for in the help file, and the examples there are not as rich as they could be). That is why I turn to you in case you could share some good tips and examples of code on how to use the leaps package (especially the regsubsets command) The problem that drives me to ask this is: how to use the regsubsets() command to immulate a forward model selection procedure on a regressions problem ? I attach below a few direction dear Thomas has already wrote to me on the subject, and any help would be very welcomed: *me:* I feel I am missing a big something here, so please help me here - Let's say we have a dataset with an X matrix of 10 variables, and all we want to perform is forward variable selection with AIC, starting from the minimal model that includes the intercept only, and with the maximum model of all variable and their interaction up to the second order. In that range, we wish to find the best model, based on forward selection. *Thomas:* Use biglm() to fit the model with all main effects and all second order interactions. This model will be the maximum model for selection. The minimum model, by default, is the model with only an intercept, so you don't need to specify anything. If the minimum model is more complicated, the vector force.in specifies which terms are in the minimum model (a logical vector with TRUE for variables in the minimum model and FALSE for variables not in the minimum model). regsubsets() will give you the best model with one variable, the best with two variables, and so on. The object produced by summary() of the regsubsets() has a component $cp that gives Mallows' Cp for each of the best models. This is equivalent to AIC, or you can compute AIC from the residual sum of squares in the $rss component of the object. regsubsets() doesn't actually fit the models, it just works out the residual sum of squares. You need to take the output of regsubsets() and then fit which ever of the best models you want coefficients for. summary(regsubsets.object)$which is a logical matrix indicating which variables are in each of the best models. This may seem unnecessarily complicated, but regsubsets() was designed for situations where you want lots of best models rather than just one, since there are often lots of models that are about equally good. That's the point of the plot() method, where you can look at hundreds of best models from 30 or so variables and see which variables are in most of the good models, and which variables tend to occur together or separately -- for example, if you have two related variables such as systolic blood pressure and diastolic blood pressure do they substitute for each other or do they tend to occur in the same model. Thanks all (and again - thanks Thomas for all your patient answers so far) Tal p.s: I already sent this e-mail once, but couldn't seem to see it on the list, so I resent it again - sorry if any of you got it twice. -- My contact information: Tal Galili Phone number: 972-50-3373767 FaceBook: Tal Galili My Blogs: www.talgalili.com www.biostatistics.co.il [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RES: RES: Removing rows
Sorry, act_2temp - act_2[which(!duplicated(act_2[,c(1: 6 )])),] # not 5 Atenciosamente, Leandro Lins Marino Centro de Avaliação Fundação CESGRANRIO Rua Santa Alexandrina, 1011 - 2º andar Rio de Janeiro, RJ - CEP: 20261-903 R (21) 2103-9600 R.:236 ( (21) 8777-7907 ( lean...@cesgranrio.org.br Aquele que suporta o peso da sociedade é precisamente aquele que obtém as menores vantagens. (SMITH, Adam) Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO AMBIENTE -Mensagem original- De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Em nome de Leandro Marino Enviada em: quinta-feira, 12 de março de 2009 08:55 Para: 'Tammy Ma'; r-help@r-project.org Assunto: [R] RES: Removing rows Hi Tammy, You can do: act_2temp - act_2[which(!duplicated(act_2[,c(1:5)])),] act_2temp[1:5,] act_2 - act_2temp rm(act_2temp) Atenciosamente, Leandro Lins Marino Centro de Avaliação Fundação CESGRANRIO Rua Santa Alexandrina, 1011 - 2º andar Rio de Janeiro, RJ - CEP: 20261-903 R (21) 2103-9600 R.:236 ( (21) 8777-7907 ( lean...@cesgranrio.org.br Aquele que suporta o peso da sociedade é precisamente aquele que obtém as menores vantagens. (SMITH, Adam) Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO AMBIENTE -Mensagem original- De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Em nome de Tammy Ma Enviada em: quinta-feira, 12 de março de 2009 06:49 Para: r-help@r-project.org Assunto: [R] Removing rows Hi All, act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[i+1]==act_2$Rep[i]){ act_2-act_2[-(i+1),] }else{ act_2-act_2 } } return(act_2) } when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i-i-1, then i go to 1 seems not reasonbale. How should I modify it`? Tammy _ News, entertainment and everything you care about at Live.com. Get it now! http://www.live.com/getstarted.aspx [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] who can give me some hint?
Its not clear what more flexible refers to. The posted solution already produces the sample output you showed. What else should it do? On Thu, Mar 12, 2009 at 8:15 AM, Tammy Ma metal_lical...@live.com wrote: Thanks a lot for your reply. I expect a more flexible solution. Because I couldn't check that column one by one. If another Rep colum is: useractivity_act 2 2 3 3 3 4 5 5 6 useractivity_idle i should be able to write a program to make it as: useractivity_act 2 3 4 5 6 useractivity_idle Only keep 1st value of repeated values. I have been working no it for a whileStill didnt get solution. Thanks for your concentration. Tammy Date: Thu, 12 Mar 2009 08:03:11 -0400 Subject: Re: [R] who can give me some hint? From: ggrothendi...@gmail.com To: metal_lical...@live.com CC: r-help@r-project.org I assume the problem is to only keep those rows whose Rep value is not equal to the Rep value in the prior row. In that case just compare c(, Rep[-nr]) to Rep and use the resulting vector, ix, to select out rows. Rep - as.character(act_2$Rep) could be simplified to Rep - act_2$Rep if Rep is already known to be character. Lines - Date Dtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle act_2 - read.table(textConnection(Lines), header = TRUE, as.is = TRUE) nr - nrow(act_2) Rep - as.character(act_2$Rep) ix - Rep != c(, Rep[-nr]) act_2[ix] On Thu, Mar 12, 2009 at 6:25 AM, Tammy Ma metal_lical...@live.com wrote: Hi All, act_2 Date Dtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to Date Dtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[i+1]==act_2$Rep[i]){ act_2-act_2[-(i+1),] }else{ act_2-act_2 } } return(act_2) } when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i-i-1, then i go to 1 seems not reasonbale. How should I modify it`? Tammy _ Drag n’ drop—Get easy photo sharing with Windows Live™ Photos. http://www.microsoft.com/windows/windowslive/products/photos.aspx [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Get news, entertainment and everything you care about at Live.com. Check it out! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 with loop
Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this: c - list() for(i in 1:ncol(mydata)) { for(j in 2:nrow(mydata)) { c[[i]] - sum(yc[j,i] - yc[(j-1),i]) }}} As for the columns it works pretty fine, but it only returns the last subtraction, however, I need the sum of all subtractions. Any ideas? Regards, Rafael. Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with loop
Why use a loop? Try using diff() x - c(4, 19, 21, 45, 50, 73, 78, 83, 87, 94) sum(diff(x)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Rafael Moral Sent: Thursday, March 12, 2009 9:04 AM To: r-help@r-project.org Subject: [R] help with loop Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this: c - list() for(i in 1:ncol(mydata)) { for(j in 2:nrow(mydata)) { c[[i]] - sum(yc[j,i] - yc[(j-1),i]) }}} As for the columns it works pretty fine, but it only returns the last subtraction, however, I need the sum of all subtractions. Any ideas? Regards, Rafael. Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] === P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S. News World Report (2008). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with loop
is your data a data frame or a matrix? do you want to compute the differences columnwise, i.e., for each column independently? consider this example: # generate and display dummy data (d = as.data.frame(replicate(3, sample(5 # compute successive differences columnwise as.data.frame(apply(d, 2, diff)) apply(as.matrix(d), 2, diff) see ?apply and ?diff for details. note that apply will return a matrix both when given a data frame and when given a matrix. vQ Rafael Moral wrote: Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this: c - list() for(i in 1:ncol(mydata)) { for(j in 2:nrow(mydata)) { c[[i]] - sum(yc[j,i] - yc[(j-1),i]) }}} As for the columns it works pretty fine, but it only returns the last subtraction, however, I need the sum of all subtractions. Any ideas? Regards, Rafael. Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with loop
Hi, Try this; lapply( mydata, function(x){ sum( diff( x ) ) } ) Romain Rafael Moral wrote: Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this: c - list() for(i in 1:ncol(mydata)) { for(j in 2:nrow(mydata)) { c[[i]] - sum(yc[j,i] - yc[(j-1),i]) }}} As for the columns it works pretty fine, but it only returns the last subtraction, however, I need the sum of all subtractions. Any ideas? Regards, Rafael. Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Romain Francois Independent R Consultant +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with loop
I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. This is just sum(diff(x)), or even x[length(x)] - x[1]. Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with loop
Well actually, what about that (Assuming mydata is a data frame) tail( mydata, 1 ) - head( mydata, 1) since: (the second - the first) + (the third - the second) + (the fourth - the third) = the last - the first Romain Rafael Moral wrote: Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this: c - list() for(i in 1:ncol(mydata)) { for(j in 2:nrow(mydata)) { c[[i]] - sum(yc[j,i] - yc[(j-1),i]) }}} As for the columns it works pretty fine, but it only returns the last subtraction, however, I need the sum of all subtractions. Any ideas? Regards, Rafael. -- Romain Francois Independent R Consultant +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with loop
This is a telescoping sum that can be calculated analytically as: (a[2] - a[1]) + ... + (a[n] - a[n-1]) = a[n] - a[1] On Thu, Mar 12, 2009 at 9:04 AM, Rafael Moral rafa_moral2...@yahoo.com.br wrote: Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this: c - list() for(i in 1:ncol(mydata)) { for(j in 2:nrow(mydata)) { c[[i]] - sum(yc[j,i] - yc[(j-1),i]) }}} As for the columns it works pretty fine, but it only returns the last subtraction, however, I need the sum of all subtractions. Any ideas? Regards, Rafael. Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with loop
Dear Rafael, Perhaps: sum(diff(x)) where x is your vector. To apply above to your data set (by rows), you could use apply(mydata,1,function(x) sum(diff(x))) See ?diff, ?sum and ?apply for more information. HTH, Jorge On Thu, Mar 12, 2009 at 9:04 AM, Rafael Moral rafa_moral2...@yahoo.com.brwrote: Dear useRs, I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. So, I wrote something like this: c - list() for(i in 1:ncol(mydata)) { for(j in 2:nrow(mydata)) { c[[i]] - sum(yc[j,i] - yc[(j-1),i]) }}} As for the columns it works pretty fine, but it only returns the last subtraction, however, I need the sum of all subtractions. Any ideas? Regards, Rafael. Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with loop
On 12 Mar 2009, at 13:22, richard.cot...@hsl.gov.uk wrote: I'm trying to write a loop to sum my data in the following way: (the second - the first) + (the third - the second) + (the fourth - the third) + ... for each column. This is just sum(diff(x)), or even x[length(x)] - x[1]. I think rowSums gives what's intended, rowSums(diff( matrix(c(1,2,3,4,5,6),ncol=2) )) (but i'd give heads or tails as to whether this was an oversimplification of the real problem ) baptiste _ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] batch process file in R
Dear R experts, I have a folder names 200209 and in this folder there are many data files, such as: BA020902.txt,BA020903.txt,BA020904.txt, BA020905.txt,BA020906.txt,BA020909.txt, BA020910.txt,BA020911.txt,BA020912.txt, BA020913.txt,BA020916.txt,BA020917.txt, BA020918.txt,BA020919.txt,BA020920.txt, BA020923.txt,BA020924.txt,BA020925.txt, BA020926.txt,BA020927.txt,BA020930.txt, GMAS0209.txt,MAST0209.txt I want to imort all these data files into R at once without typing tedious a-read.table(BA020902.txt), b-read.table(BA020903.txt). Thanks Ted -- View this message in context: http://www.nabble.com/batch-process-file-in-R-tp22474751p22474751.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Randomization, line and spatial coordinates
Hi all, I would like to know how to create n equidistant random points along a multisegment line/object of class psp and to retrieve the coordinates of those generated random points. thanks P.L. -- View this message in context: http://www.nabble.com/Randomization%2C-line-and-spatial-coordinates-tp22471453p22471453.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to install R-2.8.1 on AIX
Hi: I can't install the R-2.8.1 on the machine IBM AIX according the instruction configuratioin(OBJECT_MODE=64). I can successfully ./configure ***, and get a Makefile. But during compiling the source code, there is some problem I can't fix it. Please tell me some tips about how to install the R on my AIX. thankx very much. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] zooreg and lmrob problem (bug?)
Hi all and thanks for your time in advance, I can't figure out why summary.lmrob complains when lmrob is used on a zooreg object. If the zooreg object is converted to vector before calling lmrob, no problems appear. Let me clarify this with an example: library(robustbase) library(zoo) dad-c(801.4625,527.2062,545.2250,608.2313,633.8875,575.9500,797.0500,706.4188, 816.7000,619.1187,430.6188,852.1750,574.9937,528.1250,376.6187,507.7437, 443.0813,463.6250,716.1063,529.1250,705.7437,959.2937,653.0187,717.4438, 644.3125,718.1000,620.5187,759.3312,712.9750,606.6688,451.9250,560.2313, 308.1875,551.7687,615.3312,673.1250,678.4562,485.5312,491.8875,568.5688, 689.5750,507.0875,467.9125,539.4875,461.8625,827.3750,507.9250,526.5688, 363.9625,355.8813,585.9750,792.8438,698.6250,625.1063,463.4875,619.4688, 684.9438,815.3438) mod1-lmrob(dad~seq(58)) summary(mod1) Call: lmrob(formula = dad ~ seq(58)) Weighted Residuals: Min 1Q Median 3Q Max -291.106 -98.0830.912 102.219 349.697 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 630.202138.5583 16.344 2e-16 *** seq(58) -0.9366 1.1639 -0.8050.424 --- Signif. codes: 0 â***â 0.001 â**â 0.01 â*â 0.05 â.â 0.1 â â 1 Robust residual standard error: 147.3 Convergence in 8 IRWLS iterations Robustness weights: 4 weights are ~= 1. The remaining 54 ones are summarized as Min. 1st Qu. MedianMean 3rd Qu.Max. 0.5522 0.8858 0.9537 0.9212 0.9831 0.9990 Algorithmic parameters: tuning.chi bb tuning.psi refine.tolrel.tol 1.5476400 0.500 4.6850610 0.001 0.001 nResample max.it groupsn.group best.r.s k.fast.s k.max 500 50 5400 2 1 200 trace.lev compute.rd 0 0 seed : int(0) mod1-lmrob(as.zooreg(dad)~seq(58)) summary(mod1) Call: lmrob(formula = as.zooreg(dad) ~ seq(58)) Weighted Residuals: Error in if (xi == xj) 0L else if (xi xj) 1L else -1L : argument is of length zero My problem is I typically work with zooreg objects and summary.lmrob complains unless I convert them to vector in the lmrob call. Any idea what is going wrong? Thanks a lot, VÃctor. -- VÃctor Homar Santaner Grup de Meteorologia Edif. Mateu Orfila Tel: +34 971 17 1376 Universitat de les Illes BalearsFax: +34 971 17 3426 07122 Palma de Mallorca (SPAIN) Email: victor.ho...@uib.es Knowledge is contagious. Infect truth. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Partial function application in R
Sorry for not answering long. After working a lot with new version of bind function I find it actually really useful. Just to avoid any possible hard-to-debug errors I try to stick to some good practices, like always specifying default values for formal parameters and calling bind with named arguments only. And actually this feature reinvents http://www.nabble.com/Curry%3A-proposed-new-functional-rogramming%2C-er%2C-function.-td13535544.html#a13535544 :) I find myself operating a lot with list-of-lists-like structures, so this facility helps me really a lot. What about this one: combine - function( ... ) { funs - list( ... ) head - funs[[1]] NULL - funs[[1]] if( length(funs) 0 ) function( ... ) do.call( combine, funs ) ( head( ... ) ) else head } It helps me to avoid lapplying multiple functions one after another, which was not really readable. Thus I came to writing code like this: sorting.predicate - combine( pure.perf, bind( [[, i=V11), bind( quantile, 0.25 ) ) I wonder how bad is it? :) Regards, nosek Wacek Kusnierczyk wrote: nosek wrote: Hello, soon after my last posting to this thread I stumbled upon the do.call function and came to the very much the same version as yours. It is good! at least for the sort of tasks as in the examples below. but i haven't tested it beyond those, and in r you shouldn't rely on intuition. However, it looks that both name clashes and mixing keyword and positional styles in argument binding and function calls may lead to very drastic and cryptic errors. Therefore I find this functional style of programming not too reliable yet. would be interesting to see what sorts of very drastic and cryptic errors you get. not that i would be surprised if something intuitively correct does not if fact work. it might be a semantic weirdo, but it might be that you use the solution in a way obviously destined to failure. vQ Wacek Kusnierczyk wrote: czesc, looks like you want some sort of currying, or maybe partial currying, right? anyway, here's a quick guess at how you can modify your bind, and it seems to work, as far as i get your intentions, with the plot example you gave: bind = function(f, ...) { args = list(...) function(...) do.call(f, c(list(...), args)) } plotlines = bind(plot, type='l') plotlines(1:10, runif(10)) plotredlines = bind(plotlines, col=red) plotredlines(runif(10)) # careful about not overriding a named argument plotredpoints = bind(plotredlines, type=p) plotredpoints(runif(10)) you may want to figure out how to get rid of the smart y-axis title. is this what you wanted? pzdr, vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Partial-function-application-in-R-tp21487269p22474710.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] alternative to EMV?
I need a package that can compute missing values of n-dimensional vectors for n 2. This is a kind of interpolation, complicated in dimensions higher than 2. The idea is that I have a set of fully specified vectors (i.e., with no missing values) and I get a new vector that has one or more missing attributes; I need to fill in the missing values with values that are, based on the 'training set', representative. EMV appeared to be the solution but it has been taken off CRAN and I can't seem to install the archived version by hand on my Windoz machine. Does anyone know of an alternative to EMV? Thanks, Chris Elsaesser, PhD 703.371.7301 (m) Principal Engineer 703.983.4116 (o) Information Discovery Understanding The MITRE Corporation McLean, VA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 'netalg' and 'netlab' packages neural networks
Dear List, I have just started to familiarize with artificial neural networks and I find two names of packages by chance using R search. But unfortunately I can not find these packages on the CRAN. Is it possible that they were renamed? The names of the packages in question are: netalg netlab. Thank you very much for any kind of help! Cheers, Peter SALY [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] zooreg and lmrob problem (bug?)
One can't assume an arbitrary function necessarily works with zoo objects although many do; however, for functions that are sufficiently similar to lm, like lmrob, dyn in the dyn package can transform it to work with zoo (as well as with ts and a number of other time series classes). Just preface lmrob with dyn$ like this: library(dyn) mod1-dyn$lmrob(as.zooreg(dad)~seq(58)) summary(mod1) On Thu, Mar 12, 2009 at 6:13 AM, Víctor Homar victor.ho...@uib.cat wrote: Hi all and thanks for your time in advance, I can't figure out why summary.lmrob complains when lmrob is used on a zooreg object. If the zooreg object is converted to vector before calling lmrob, no problems appear. Let me clarify this with an example: library(robustbase) library(zoo) dad-c(801.4625,527.2062,545.2250,608.2313,633.8875,575.9500,797.0500,706.4188, 816.7000,619.1187,430.6188,852.1750,574.9937,528.1250,376.6187,507.7437, 443.0813,463.6250,716.1063,529.1250,705.7437,959.2937,653.0187,717.4438, 644.3125,718.1000,620.5187,759.3312,712.9750,606.6688,451.9250,560.2313, 308.1875,551.7687,615.3312,673.1250,678.4562,485.5312,491.8875,568.5688, 689.5750,507.0875,467.9125,539.4875,461.8625,827.3750,507.9250,526.5688, 363.9625,355.8813,585.9750,792.8438,698.6250,625.1063,463.4875,619.4688, 684.9438,815.3438) mod1-lmrob(dad~seq(58)) summary(mod1) Call: lmrob(formula = dad ~ seq(58)) Weighted Residuals: Min 1Q Median 3Q Max -291.106 -98.083 0.912 102.219 349.697 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 630.2021 38.5583 16.344 2e-16 *** seq(58) -0.9366 1.1639 -0.805 0.424 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Robust residual standard error: 147.3 Convergence in 8 IRWLS iterations Robustness weights: 4 weights are ~= 1. The remaining 54 ones are summarized as Min. 1st Qu. Median Mean 3rd Qu. Max. 0.5522 0.8858 0.9537 0.9212 0.9831 0.9990 Algorithmic parameters: tuning.chi bb tuning.psi refine.tol rel.tol 1.5476400 0.500 4.6850610 0.001 0.001 nResample max.it groups n.group best.r.s k.fast.s k.max 500 50 5 400 2 1 200 trace.lev compute.rd 0 0 seed : int(0) mod1-lmrob(as.zooreg(dad)~seq(58)) summary(mod1) Call: lmrob(formula = as.zooreg(dad) ~ seq(58)) Weighted Residuals: Error in if (xi == xj) 0L else if (xi xj) 1L else -1L : argument is of length zero My problem is I typically work with zooreg objects and summary.lmrob complains unless I convert them to vector in the lmrob call. Any idea what is going wrong? Thanks a lot, Víctor. -- Víctor Homar Santaner Grup de Meteorologia Edif. Mateu Orfila Tel: +34 971 17 1376 Universitat de les Illes Balears Fax: +34 971 17 3426 07122 Palma de Mallorca (SPAIN) Email: victor.ho...@uib.es Knowledge is contagious. Infect truth. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] set size of a plot
Hi, I have the following R-code: pdf(file=test.pdf) hist(rcauchy(100)) dev.off() How can I set the size of the histogram in my pdf? I tried to do with par(...) but I didn't find the right parameter yet. Thanks, Max -- View this message in context: http://www.nabble.com/set-size-of-a-plot-tp22477083p22477083.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] GARCH variance equation with dummy variables
I am estimating daily electricity prices using GARCH (1,1). What I would like to see is whether there is some kind of daily or seasonal effect in variance of the price series. For instance, variance of electricity prices might be different (higher) during weekdays as opposed to during weekend. Thus, I would like to include some dummy variables in variance equation -but I don't know how to program that in R (I use fGArch package). Could someone help, please? Many tanks, Jurica Brajkovic Economics Division University of Southampton __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] CI from svyquantile in survey package
This is a consequence of changes made to support multiple imputation, where extracting the standard errors was needed. I will try to fix it. A work-around is to use lapply() and subset() lapply(c(E,M,H), function(s) svyquantile(~api99,subset(dclus1, stype==s), ci=TRUE,quantiles=0.5)) Thanks for reporting the problem. -thomas On Wed, 11 Mar 2009, Ron Burns wrote: I am having trouble understanding (i.e. getting) confidence intervals from the survey package. I am using R version 2.8.1 (2008-12-22) and survey package (3.11-2) on FC7 linux. To simplify my question I use an example from that package: R data(api) R dclus1-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc) R(tst-svyby(~api99,~stype,dclus1, svyquantile, quantiles=0.5,ci=TRUE)) stype api99se E E 615 37.89 H H 593 69.52 M M 611 37.67 R str(tst) Classes âsvybyâ and 'data.frame':3 obs. of 3 variables: $ stype: Factor w/ 3 levels E,H,M: 1 2 3 $ api99: num 615 593 611 $ se : num 37.9 69.5 37.7 - attr(*, svyby)=List of 7 ..$ margins : int 1 ..$ nstats : num 1 ..$ vars : int 1 ..$ deffs: logi FALSE ..$ statistic: chr svyquantile ..$ variables: chr api99 ..$ vartype : chr se - attr(*, call)= language svyby.default(~api99, ~stype, dclus1, svyquantile, quantiles = 0.5, ci = TRUE) R I do not see the CI in this structure. Specifically, this problem came up when I was working through an example where after a similar set up information was extracted using R tst$statistics.quantiles NULL R tst$statistics.CIs NULL where of course the NULLs I get are due, in my case, to the absences of the $statistics.XXXs. The example did not display the structure so I could not compare my output with their output. (The example warns that these objects need to be unlisted which is not relevant here) Thanks in advance for any help Ron -- R. R. Burns Oceanside, CA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] set size of a plot
?pdf reads: width, height the width and height of the graphics region in inches. The default values are 7. ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Maxl18 Verzonden: donderdag 12 maart 2009 15:05 Aan: r-help@r-project.org Onderwerp: [R] set size of a plot Hi, I have the following R-code: pdf(file=test.pdf) hist(rcauchy(100)) dev.off() How can I set the size of the histogram in my pdf? I tried to do with par(...) but I didn't find the right parameter yet. Thanks, Max -- View this message in context: http://www.nabble.com/set-size-of-a-plot-tp22477083p22477083.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] regsubsets() [leaps package] - please share some good examples of use
If you run the example from ?biglm data(trees) ff-log(Volume)~log(Girth)+log(Height) chunk1-trees[1:10,] chunk2-trees[11:20,] chunk3-trees[21:31,] a - biglm(ff,chunk1) a - update(a,chunk2) a - update(a,chunk3) summary(a) you can then do b -regsubsets(a, method=forward) summary(b) to get the results of forward selection. In general, the biglm fit is the `maximum' model for the forward selection: all the variables that you want to consider for inclusion. -thomas On Thu, 12 Mar 2009, Tal Galili wrote: Hello dear R-help members, I recently became interested in using biglm with leaps, and found myself somewhat confused as to how to use the two together, in different settings. I couldn't find any example codes for the leaps() package (except for in the help file, and the examples there are not as rich as they could be). That is why I turn to you in case you could share some good tips and examples of code on how to use the leaps package (especially the regsubsets command) The problem that drives me to ask this is: how to use the regsubsets() command to immulate a forward model selection procedure on a regressions problem ? I attach below a few direction dear Thomas has already wrote to me on the subject, and any help would be very welcomed: *me:* I feel I am missing a big something here, so please help me here - Let's say we have a dataset with an X matrix of 10 variables, and all we want to perform is forward variable selection with AIC, starting from the minimal model that includes the intercept only, and with the maximum model of all variable and their interaction up to the second order. In that range, we wish to find the best model, based on forward selection. *Thomas:* Use biglm() to fit the model with all main effects and all second order interactions. This model will be the maximum model for selection. The minimum model, by default, is the model with only an intercept, so you don't need to specify anything. If the minimum model is more complicated, the vector force.in specifies which terms are in the minimum model (a logical vector with TRUE for variables in the minimum model and FALSE for variables not in the minimum model). regsubsets() will give you the best model with one variable, the best with two variables, and so on. The object produced by summary() of the regsubsets() has a component $cp that gives Mallows' Cp for each of the best models. This is equivalent to AIC, or you can compute AIC from the residual sum of squares in the $rss component of the object. regsubsets() doesn't actually fit the models, it just works out the residual sum of squares. You need to take the output of regsubsets() and then fit which ever of the best models you want coefficients for. summary(regsubsets.object)$which is a logical matrix indicating which variables are in each of the best models. This may seem unnecessarily complicated, but regsubsets() was designed for situations where you want lots of best models rather than just one, since there are often lots of models that are about equally good. That's the point of the plot() method, where you can look at hundreds of best models from 30 or so variables and see which variables are in most of the good models, and which variables tend to occur together or separately -- for example, if you have two related variables such as systolic blood pressure and diastolic blood pressure do they substitute for each other or do they tend to occur in the same model. Thanks all (and again - thanks Thomas for all your patient answers so far) Tal p.s: I already sent this e-mail once, but couldn't seem to see it on the list, so I resent it again - sorry if any of you got it twice. -- My contact information: Tal Galili Phone number: 972-50-3373767 FaceBook: Tal Galili My Blogs: www.talgalili.com www.biostatistics.co.il [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] set size of a plot
Set which size? Of the page? - then you need to specify in pdf(). Of the plot margins? - then par$mai Of something else? Then you need to be more specific about your intention. Sarah On Thu, Mar 12, 2009 at 10:05 AM, Maxl18 maximilianwoe...@hotmail.com wrote: Hi, I have the following R-code: pdf(file=test.pdf) hist(rcauchy(100)) dev.off() How can I set the size of the histogram in my pdf? I tried to do with par(...) but I didn't find the right parameter yet. Thanks, Max -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] MANOVA
Another method would be to use a summary that incorporates both as a measure of obesity, In medical investigations it is common to use the BMI which is the ratio of (weight in Kg) to (height in meters squared). Yet a third method would be to investigate for nonlinearity on the response function using splines in the model. I have not yet seen evidence of collinearity offered, so creating the full model as Simon suggests might be a first step. Much will depend on the quantity of data. If you only have 100 observations there will be severe limitations on the options. -- David Winsemius On Mar 12, 2009, at 2:37 AM, Simon Blomberg wrote: You only have one response variable, so MANOVA is not appropriate. One option would be to compare BP ~ Weight + Height with BP ~ 1. That would give you a joint test of weight and height together. Since they are collinear, that should tell you the overall effect of size. There are other options, most of which involve discarding some of the data. Frank Harrell's book is a font of wisdom on this sort of thing. Harrell, F. E., Jr. (2001). Regression Modeling Strategies. Springer. Simon. On Thu, 2009-03-12 at 00:20 -0600, Ding Xiao wrote: Hi All, I have questions about MANOVA which I am still not sure if appropriately I should use it. For example I have a data set like this: BloodPressure (BP) Weight Height 120115165 125145198 15699 176 I know that BloodPressure is correlated with both Weight and Height, however colinearity exists between Weight and Height. When I use BP = Weight + Height as the model, one is got to be insignificant. I was trying to use a BP + Weight = Height model, but not sure how to use it. Should I use MANOVA? or I just have to do two equations as BP = Weight Weight = Height Any suggestions and answers are greatly appreciated! Ding [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician School of Biological Sciences The University of Queensland St. Lucia Queensland 4072 Australia Room 320 Goddard Building (8) T: +61 7 3365 2506 http://www.uq.edu.au/~uqsblomb email: S.Blomberg1_at_uq.edu.au Policies: 1. I will NOT analyse your data for you. 2. Your deadline is your problem. The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing
Much simpler would be: act2[!duplicated(act2$Rep),] #use the negation of the duplicated function on $Rep and indexing DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle Cannot reproduce the blank line though. -- David Winsemius On Mar 12, 2009, at 5:02 AM, Tammy Ma wrote: Hi All, act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[j]==act_2$Rep[i]){ act_2-act_2[-j,] }else{ act_2-act_2 } } return(act_2) } But it only remove one row..whats the problem? How should i modify it? Thanks alot. Tammy _ Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! http://spaces.live.com/spacesapi.aspx?wx_action=createwx_url=/friends.aspxmkt=en-us [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] set size of a plot
See ?pdf and its width and height arguments. Also if you want to have the graph centered on a standard page, there are additional arguments to help you achieve that effect: pdf(test.pdf, height=5, width=5, paper=letter, pagecentre=TRUE) hist(rcauchy(100)) dev.off() -Christos -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Maxl18 Sent: Thursday, March 12, 2009 10:05 AM To: r-help@r-project.org Subject: [R] set size of a plot Hi, I have the following R-code: pdf(file=test.pdf) hist(rcauchy(100)) dev.off() How can I set the size of the histogram in my pdf? I tried to do with par(...) but I didn't find the right parameter yet. Thanks, Max -- View this message in context: http://www.nabble.com/set-size-of-a-plot-tp22477083p22477083.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] full screen graph, and close x11
Hi, see ?dev.off but I think (guessing you use a windows system), you would be better of in using win.metafile() instead of x11() in initiating the graph, see ?win.metafile There is no need to show all 100+ graphs on your display if you actually want them in files. hth. BaKaLeGuM schrieb: Hi everybody! I'm looking for a function or option to make a full screen plot.. can you help me? and I would like to know if it's possible to automaticaly close a x11 windows.. because i have more than 100 graph to generate and what i want is: 1 - make a full screen graph 2 - save this plot in emf format 3 - close the plot (goto 1) thanks for your advices [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] model simplification in lme
Model simplification in lme Pinheiro and Bates suggest that model simplification of fixed effects in lme with anova (model,model2) is anticonservative. What is the best way to simplify a model in lme? Testing the p value for each fixed factor with anova (model, type=marginal) and removing it if it is not significant? I know this in not a valid approach in lm but I am not sure about lme. Thanks to Kingsford for pointing out the section in Pinheiro and Bates about model simplification. Thanks, Mel -- Menelaos Stavrinides Ph.D. Candidate Environmental Science, Policy and Management 137 Mulford Hall MC #3114 University of California Berkeley, CA 94720-3114 USA Tel: 510 717 5249 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] read.xls and name of worksheet
Hi, I would like to some excel files with some worksheets. I tried this with the following R script: library(gdata) i-1 rc-0 while(rc != try-error) { wksh-try(read.xls(cluster-microarray-FW.xls,sheet=i,verbose=TRUE,perl=perl)) rc-class(wksh) print(sprintf(--- i=%2d rc=%s ---,i,rc)) if (rc != try-error) { print(--- summary(wksh)= -); print(summary(wksh)) i - i+1 } } At first I found the problem that xls2csv adds one space to the every item in the last column. The second problem is, that I could not found an a possibility to save the name of the worksheet. It is shown on the screen, if I use the last script. I see something like Writing Sheet number 1 ('strenger') to file '/tmp/RtmpFpSkBB/file327b23c6.csv' The word in the single quotes is the name of the worksheet. Therefore I tried to redirect the standard output to a file library(gdata) i-1 rc-0 while(rc != try-error) { log=paste(text.log,i,sep=) print(log=); print(log) #con-file(log,open=wt) #sink(con, type=c(output,message)) #sink(con, type=output) #sink(con, type=message) sink(log) wksh-try(read.xls(cluster-microarray-FW.xls,sheet=i,verbose=TRUE,perl=perl)) sink() rc-class(wksh) print(sprintf(--- i=%2d rc=%s ---,i,rc)) if (rc != try-error) { cmd-paste(sed -n \s/.*[(](.*)[)].*/\1/p\ ,log, text.log) system(cmd) #unlink(log) print(--- summary(wksh)= -); print(summary(wksh)) i - i+1 } } But now I don't find the information about Writing Sheet number in text.log*. Any hint appreciated. Regards -- Juergen Rose r...@rz.uni-potsdam.de Uni-Potsdam __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read.xls and name of worksheet
Here is a program that will get a list of the sheet names and then read in the indicated name. Modify to suit. library(rcom) xls - C:\\test.xls oxl - comCreateObject('Excel.Application') comSetProperty(oxl, Visible, TRUE) owb - comGetProperty(oxl, Workbooks) ob - comInvoke(owb, Open, xls) osheets - comGetProperty(ob, Worksheets) n - comGetProperty(osheets, Count) ithSheetName - function(i) comGetProperty(comGetProperty(osheets, Item, i), Name) sheetNames - sapply(1:n, ithSheetName) comInvoke(oxl, Quit) library(gdata) read.xls(xls, match(xyz, sheetNames), na.strings = na ) On Thu, Mar 12, 2009 at 10:46 AM, Juergen Rose r...@rz.uni-potsdam.de wrote: Hi, I would like to some excel files with some worksheets. I tried this with the following R script: library(gdata) i-1 rc-0 while(rc != try-error) { wksh-try(read.xls(cluster-microarray-FW.xls,sheet=i,verbose=TRUE,perl=perl)) rc-class(wksh) print(sprintf(--- i=%2d rc=%s ---,i,rc)) if (rc != try-error) { print(--- summary(wksh)= -); print(summary(wksh)) i - i+1 } } At first I found the problem that xls2csv adds one space to the every item in the last column. The second problem is, that I could not found an a possibility to save the name of the worksheet. It is shown on the screen, if I use the last script. I see something like Writing Sheet number 1 ('strenger') to file '/tmp/RtmpFpSkBB/file327b23c6.csv' The word in the single quotes is the name of the worksheet. Therefore I tried to redirect the standard output to a file library(gdata) i-1 rc-0 while(rc != try-error) { log=paste(text.log,i,sep=) print(log=); print(log) #con-file(log,open=wt) #sink(con, type=c(output,message)) #sink(con, type=output) #sink(con, type=message) sink(log) wksh-try(read.xls(cluster-microarray-FW.xls,sheet=i,verbose=TRUE,perl=perl)) sink() rc-class(wksh) print(sprintf(--- i=%2d rc=%s ---,i,rc)) if (rc != try-error) { cmd-paste(sed -n \s/.*[(](.*)[)].*/\1/p\ ,log, text.log) system(cmd) #unlink(log) print(--- summary(wksh)= -); print(summary(wksh)) i - i+1 } } But now I don't find the information about Writing Sheet number in text.log*. Any hint appreciated. Regards -- Juergen Rose r...@rz.uni-potsdam.de Uni-Potsdam __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] alternative to EMV?
If I understand your question and if I understood Dr Harrell's description of the Hmisc/Design packages capabilities, this should all be available. I have been blessed with a dataset so large and with so relatively few missing values that I have not yet needed to put his methods into practice, but you should consider his function transcan in Hmisc. On Mar 12, 2009, at 8:44 AM, Elsaesser, Chris wrote: I need a package that can compute missing values of n-dimensional vectors for n 2. This is a kind of interpolation, complicated in dimensions higher than 2. The idea is that I have a set of fully specified vectors (i.e., with no missing values) and I get a new vector that has one or more missing attributes; I need to fill in the missing values with values that are, based on the 'training set', representative. EMV appeared to be the solution but it has been taken off CRAN and I can't seem to install the archived version by hand on my Windoz machine. Does anyone know of an alternative to EMV? Thanks, Chris Elsaesser, PhD 703.371.7301 (m) Principal Engineer 703.983.4116 (o) Information Discovery Understanding The MITRE Corporation McLean, VA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] eps/pdf write help
I am trying to print graphs as pdf's or eps in a for loop, but I can't seem to get it right Either it prints only a single eps graph (overwrites) or when I use #pdf(paste(i,.pdf, sep=)) .. it prints all pdf's but they are empty Can someone suggest which method shud I use for such. Thanks Mohan Code: for(i in 1:19) { query - d$V1[i]; print(query) #pdf(paste(i,.pdf, sep=)); x11(); plot(c2data[start1:count,],c3data[start1:count,],xlab=Buildings, ylab=Sky, sub=i); points(c2data[query,],c3data[query,], pch=20, col='blue'); grid(); dev.print() dev.copy2eps(); dev.copy() start1 - count + 2; #print(start1) val - val-1; #print(val) count - count + val; #print(count) } [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Easy Recall to get ls(..., all.names=TRUE)?
-Original Message- From: Rolf Turner [mailto:r.tur...@auckland.ac.nz] Sent: Wednesday, 11 March, 2009 5:09 PM To: Szumiloski, John Cc: r-help@r-project.org Subject: Re: [R] Easy Recall to get ls(..., all.names=TRUE)? On 12/03/2009, at 3:16 AM, Szumiloski, John wrote: Dear useRs, I have a utility function which is meant to be a clone of ls(), except with the option all.names=TRUE. Currently however, the function merely consists of a copy of the source code of ls(), except the default value of all.names is different. That approach has the drawback of future inconsistency if the code for ls() ever changes. No comment on whether that is likely or not; I would and do object to the current construction in principle. What I would like to do is rewrite the new function so that it does very minimal processing of its arguments, and then calls ls() with the new arguments, somewhat in the same spirit of the Recall() function. A challenge to me has been twofold, that this new ls() call has a different search path, and that ls() itself has a good deal of lazy evaluation (including possibly twice in one line, around line 11) in it. Getting my new function to work with all permutations of arguments, without merely copying the code from ls(), has been futile. I am sure I could manually enumerate the behavior for all permutations of all the arguments to ls(), and code each case individually. I am also sure I will not waste my time doing that. I was hoping, however, that there was some simple trick to allow this easily, one that I have missed. Even an explanation of why this might be a fool's errand would be quite helpful to my understanding of the intricacies of R evaluation. Does the following do what you want? myls - function (all.names=TRUE,pos=-1,...) { xxx - pmatch(names(list(...)),envir,nomatch=0) if(length(xxx) xxx0) return(ls(all.names=all.names,pos=pos,...)) eee - if(pos==-1) parent.frame() else as.environment(pos) ls(all.names=all.names,envir=eee,...) } cheers, Rolf Turner [snip legalese] Rolf, as written that doesn't work: myls(3) just returned everything in the top level workspace, .GlobalEnv, and not (in my case) everything in package:graphics. However, I switched the order of the first two arguments, and now it does the right thing in that case. I will still need to test it further. Thanks for the suggestion. -John Notice: This e-mail message, together with any attachme...{{dropped:12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 with predict and plotting confidence intervals
Dear R help, This seems to be a commonly asked question and I am able to run examples that have been proposed, but I can't seems to get this to work with my own data. Reproducible code is below. Thank you in advance for any help you can provide. The main problem is that I can not get the confidence lines to plot correctly. The secondary problem is that predict is not able to find my object when I include a model object. ## THE DATA wt.data - data.frame(code = factor(LETTERS[1:24]), area = c(60865,480,656792,92298,1200,1490,8202,4000,220,245,4000,390,325, 16,162911,20235,68800,3389,7,696,4050,1498,1214,99460), species = c(673,650,1353,1026,549,536,782,734,516,580,673,560,641,443,1105, 871,789,575,216,407,942,655,582,1018)) # TRANSFORM AND ADD TO DATAFRAME wt.data$logA - log10(wt.data$area) wt.data$logS - log10(wt.data$species) wt.mod - lm(logS~logA, data = wt.data) # PLOT THE DATA with(wt.data,plot(logA,logS, ylim = c(2.3,3.2),xlim = c(0,6))) abline(wt.mod, lwd = 2) # create a prediction dataframe the same length as data pred.frame - data.frame(a = seq(0,6, length.out = 24)) # error ' object logA not found' # I am not sure why object is not found, I assume this has to do with # the way I added the transformed variables to the dataframe pp - predict(wt.mod, int = p, newdata=pred.frame) # runs ok? pp - predict(lm(wt.data$logS~wt.data$logA), int = p, newdata=pred.frame) # lines are jagged?? # I am not sure how to get the lines to draw correctly here matlines(pred.frame$a,pp, lty=c(1,2,2),col=black) sessionInfo() R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.8.1 Michael Denslow Graduate Student I.W. Carpenter Jr. Herbarium [BOON] Department of Biology Appalachian State University Boone, North Carolina U.S.A. -- AND -- Communications Manager Southeast Regional Network of Expertise and Collections sernec.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix multiplication, tensor product, block-diagonal and fast computation
On Wed, 11 Mar 2009, Camarda, Carlo Giovanni wrote: Dear R-users, I am searching to the best way to compute a series of n matrix multiplications between each matrix (mXm) in an array (mXmXn), and each column of a matrix (mXn). Please find below an example with four possible solutions. The first is a simple for-loop which one might avoid; the second solution employs the tensor product but then manually selects the right outcomes. The third solution uses too many (and too time-consuming) functions in order to profit of mapply. The last solution creates a block-diagonal from the array and multiply such matrix by the vectorized version of the first matrix. Here, often, the block-diagonal matrix may be too large and a specific list is needed (at least AFAIK). Does anyone have a further and possibly more effective way of computing such operation? This is fairly quick: rowSums( aperm(A * as.vector( M[ rep(1:ncol(A),each=nrow(A)),]),c(1,3,2)), dims = 2 ) But my advice is to code this in C along the lines of your first solution (using the BLAS routines to carry it out in the inner products). Your code will be easier to read and debug and will probably be faster and easier on memory, too. Years ago I wrote a lot of stuff like this in native S. I 'optimized' the heck out of it using tricks like the one above as I was debugging the code. I had to rewrite the bulk of it in C anyway. The S code was so hard to read that I could not migrate it to C bit by bit. I had to start over and the effort spent debugging it in S was lost. As an alternative you might try the 'jit' package on your first solution. HTH, Chuck Thanks in advance for any suggestion, Carlo Giovanni Camarda library(tensor) library(Matrix) A - array(seq(0,1,length=48), dim=c(4,4,3)) M - matrix(1:12, nrow=4, ncol=3) # first solution (avoid the for-loop) M1 - matrix(nrow=4, ncol=3) for(i in 1:3){ M1[,i] - A[,,i] %*% M[,i] } # second solution (direct picking of the right cols) A1 - tensor(A, M, 2, 1) M2 - cbind(A1[,1,1],A1[,2,2],A1[,3,3]) # third solution (avoid as.data.frame and as.matrix) Adf0 - apply(A, 3, as.data.frame) Adf1 - lapply(X=Adf0, FUN=as.matrix, nrow=4, ncol=4) M3 - mapply(FUN=%*%, Adf1, as.data.frame(M)) # fourth solution (often too large block-diagonal matrix) Alist - NULL for(i in 1:3){ # better way to create such list for bdiag Alist[[i]] - A[,,i] } Abd - bdiag(Alist) M4 - matrix(as.matrix(Abd %*% c(M)), nrow=4, ncol=3) -- This mail has been sent through the MPI for Demographic ...{{dropped:10}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R-help: grep in for loop using index - doesn't work
Hi, your example is quite messy (neither reproducible or minimal). I think you could try the following, mdf - data.frame(1:3) names(mdf) - 147 i - 147 mdf[ as.character(i) ] Hope this helps, baptiste On 11 Mar 2009, at 22:34, Mohan Singh wrote: Hi everyone I am trying to use grep in a for loop to compare a string value. It works if I use the actual index value but when I use the for loop index, it doesn't work. Any suggestions plz. Here is the code: data - read.table(file=Sigmoid.csv, head=FALSE, sep=,); c1 - data$V1 c2 - data$V2 c3 - data$V3 c1data - data.frame(c1); c2data - data.frame(c2); c3data - data.frame(c3); #this works p - grep(QueryItem,c1data[147,],value=FALSE,fixed=FALSE) print(p) # print 1 #doesn't work i-147 p1 - grep(QueryItem,c1data[i,],value=FALSE,fixed=FALSE) print(p1) # prints 0 for(i in 137:270) { print(i) p - grep(QueryItem,c1data[i,],value=FALSE,fixed=FALSE) p2 - p print(p2) if(length(p)0) { print(p) } } [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Is there any difference between - and =
Sean, would like to receive expert opinion to avoid potential trouble [..] i think the following is the most secure way if one really really has to do assignment in a function call f({a=3}) and if one keeps this convention, - can be dropped altogether. secure is relative, since due to R's lazy evaluation you never know whether a function's argument is being evalutated, look at: f- function(x)TRUE x - 1 f((x=2)) # obscured attempt to assign in a function call [1] TRUE x [1] 1 Thus there is dangerous advice in the referenced blog which reads: f(x - 3) which means assign 3 to x, and call f with the first argument set to the value 3 This might be the case in C but not in R. Actually in R f(x - 3) means: call f with a first unevaluated argument x - 3, and if and only if f decides to evaluate its first argument, then the assignment is done. To make this very clear: f - function(x)if(runif(1)0.5) TRUE else x x - 1 print(f(x - x + 1)) [1] TRUE print(f(x - x + 1)) [1] 2 print(f(x - x + 1)) [1] 3 print(f(x - x + 1)) [1] TRUE print(f(x - x + 1)) [1] 4 print(f(x - x + 1)) [1] 5 print(f(x - x + 1)) [1] TRUE print(f(x - x + 1)) [1] 6 print(f(x - x + 1)) [1] TRUE Here it is unpredictable whether your assignment takes place. Thus assigning like f({x=1}) or f((x=1))is the maximum dangerous thing to do: even if you have a code-reviewer and the guy is aware of the danger of f(x-1) he will probably miss it because f((x=1)) does look too similar to a standard call f(x=1). According to help(-), R's assignment operator is rather - than =: The operators - and = assign into the environment in which they are evaluated. The operator - can be used anywhere, whereas the operator = is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions. So my recommendation is 1) use R's assignment operator with two spaces around (or assign()) and don't obscure assignments by using C's assignment operator (or other languages equality operator) 2) do not assign in function arguments unless you have good reasons like in system.time(x - something) HTH Jens Oehlschlägel P.S. Disclaimer: you can consider me biased towards -, never trust experts, whether experienced or not. P.P.S. a puzzle, following an old tradition: What is going on here? (and what would you need to do to prove it?) search() [1] .GlobalEnvpackage:stats package:graphics package:grDevices package:utils package:datasets package:methods [8] Autoloads package:base ls(all.names = TRUE) [1] y y [1] 1 2 3 identical(y, 1:3) [1] TRUE y[] - 1 # assigning 1 fails y [1] 1 2 3 y[] - 2 # assigning 2 works y [1] 2 2 2 # Tip: no standard packages modified, no extra packages loaded, neither classes nor methods defined, no print methods hiding anything, if you would investigate my R you would not find any false bottom anymore version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 8.1 year 2008 month 12 day22 svn rev47281 language R version.string R version 2.8.1 (2008-12-22) -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with predict and plotting confidence intervals
On Mar 12, 2009, at 11:14 AM, Michael Denslow wrote: Dear R help, This seems to be a commonly asked question and I am able to run examples that have been proposed, but I can't seems to get this to work with my own data. Reproducible code is below. Thank you in advance for any help you can provide. It is commonly asked ... and commonly answered. The main problem is that I can not get the confidence lines to plot correctly. The secondary problem is that predict is not able to find my object when I include a model object. ## THE DATA wt.data - data.frame(code = factor(LETTERS[1:24]), area = c(60865,480,656792,92298,1200,1490,8202,4000,220,245,4000,390,325, 16,162911,20235,68800,3389,7,696,4050,1498,1214,99460), species = c(673,650,1353,1026,549,536,782,734,516,580,673,560,641,443,1105, 871,789,575,216,407,942,655,582,1018)) # TRANSFORM AND ADD TO DATAFRAME wt.data$logA - log10(wt.data$area) wt.data$logS - log10(wt.data$species) wt.mod - lm(logS~logA, data = wt.data) # PLOT THE DATA with(wt.data,plot(logA,logS, ylim = c(2.3,3.2),xlim = c(0,6))) abline(wt.mod, lwd = 2) # create a prediction dataframe the same length as data pred.frame - data.frame(a = seq(0,6, length.out = 24)) # error ' object logA not found' I suspect you omitted the actual call that produced this error. I suspect it was something along the lines of: predwt - predict(wt.mod, newdata=pred.frame) Error in eval(expr, envir, enclos) : object logA not found # I am not sure why object is not found, I assume this has to do with # the way I added the transformed variables to the dataframe Because you didn't give the arguments the same name(s) as were used in the model formula. pp - predict(wt.mod, int = p, newdata=pred.frame) # runs ok? pp - predict(lm(wt.data$logS~wt.data$logA), int = p, newdata=pred.frame) # lines are jagged?? Lines? What lines? If predict does not find a newdata object that satisfies its requirements, it uses the original data. # I am not sure how to get the lines to draw correctly here matlines(pred.frame$a,pp, lty=c(1,2,2),col=black) The x values are your sequence whereas the y values are in the sequence from the original data. They are not correctly associated with each other. Try: pp - predict(lm(wt.data$logS~wt.data$logA), int = p, newdata= data.frame(logA=seq(0,6, length.out = 24)) ) plot(pp) -- david winsemius __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] eps/pdf write help
On Thu, Mar 12, 2009 at 03:06:30PM +, Mohan Singh wrote: I am trying to print graphs as pdf's or eps in a for loop, but I can't seem to get it right Either it prints only a single eps graph (overwrites) or when I use #pdf(paste(i,.pdf, sep=)) .. it prints all pdf's but they are empty Did you remember to close the pdf files? Something like the following should work: x - seq(0, 10, 0.01) for (i in 1:5) { pdf(paste('plot', i, '.pdf', sep='')) plot(x, x^i) dev.off() } cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] runs.test question
Hi everyone, I have data from an experiment in which human participants were instructed to generate a random sequence of yes/no answers under 4 different conditions. I want to test how successful they were in doing this. More specifically, I want to test the null hypothesis that the 4 conditions come from a single population with a given level of randomness. Some searching turned up the runs.test() function in the tseries package. This looks promising, but I'm not sure how to proceed. A simplified version of the data structure is Data - data.frame(participant=c(rep(1,4),rep(2,4), rep(3,4), rep(4,4)), question = factor(rep(c(one, two, three, four), 4)), condition = factor(c(rep(1,8), rep(2,8))), answer=(factor(sign(rnorm(16)), labels=c(yes, no Data participant question condition answer 11 one 1 no 21 two 1yes 31three 1yes 41 four 1 no 52 one 1yes 62 two 1yes 72three 1 no 82 four 1yes 93 one 2yes 10 3 two 2 no 11 3three 2yes 12 3 four 2yes 13 4 one 2 no 14 4 two 2 no 15 4three 2 no 16 4 four 2 no My questions are: 1) Can I test my hypothesis using the runs.test() function? If no, is there a better approach? 2) Does it make sense to do a runs.test() for each condition, ignoring the participant variable? Or do I need to do a runs.test() separately for each participant? If the latter, how can I combine the information to test for differences across conditions? Thanks, Ista __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with predict and plotting confidence intervals
On Mar 12, 2009, at 11:45 AM, David Winsemius wrote: On Mar 12, 2009, at 11:14 AM, Michael Denslow wrote: # I am not sure how to get the lines to draw correctly here matlines(pred.frame$a,pp, lty=c(1,2,2),col=black) The x values are your sequence whereas the y values are in the sequence from the original data. They are not correctly associated with each other. Try: pp - predict(lm(wt.data$logS~wt.data$logA), int = p, newdata= data.frame(logA=seq(0,6, length.out = 24)) ) plot(pp) At this point I should not have accepted your starting point. A better starting point would be to use the wt.mod model: pp - predict(wt.mod, int = p, newdata= list(logA=seq(0,6, length.out = 24)) ) # Followed by: plot( seq(0,6, length.out = 24), pp[ ,fit] ) lines(seq(0,6, length.out = 24), pp[ ,lwr], lty=2) lines(seq(0,6, length.out = 24), pp[ ,upr], lty=2) -- david winsemius __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Seemingly unrelated model with spatial processes
Hello everyone, Do we have package in R which will estimates the parameter in Seemingly Unrelated Spatial Regression Model? Any help would be appreciated. Thanks Arun -- View this message in context: http://www.nabble.com/Seemingly-unrelated-model-with-spatial-processes-tp22478913p22478913.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] batch process file in R
If these are the only files in the directory, then you might try... (File paths will need to change if the folder 200209 isn't in the working directory) fpath - ./200209 a - list.files(fpath) for(i in 1:length(a)){ assign(paste(y,i,sep=),read.table(paste(fpath,a[i],sep=/))) } Another option is to put them in a list... for(i in 1:length(a)){ y[[i]] - read.table(paste(fpath,a[i],sep=/) } or with lapply... y - lapply(1:length(a), function(i) read.table(paste(fpath,a [i],sep=/)) Hope this helps. Cheers, Derek On Mar 12, 7:52 am, tedzzx zengzhenx...@gmail.com wrote: Dear R experts, I have a folder names 200209 and in this folder there are many data files, such as: BA020902.txt,BA020903.txt,BA020904.txt, BA020905.txt,BA020906.txt,BA020909.txt, BA020910.txt,BA020911.txt,BA020912.txt, BA020913.txt,BA020916.txt,BA020917.txt, BA020918.txt,BA020919.txt,BA020920.txt, BA020923.txt,BA020924.txt,BA020925.txt, BA020926.txt,BA020927.txt,BA020930.txt, GMAS0209.txt,MAST0209.txt I want to imort all these data files into R at once without typing tedious a-read.table(BA020902.txt), b-read.table(BA020903.txt). Thanks Ted -- View this message in context:http://www.nabble.com/batch-process-file-in-R-tp22474751p22474751.html Sent from the R help mailing list archive at Nabble.com. __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to replace a pair of observations in a matrix?
Dear all, I did this replacement below and its work for the first case but not in the second case! Please tell me what's wrong with the second case. Case 1: m [,1] [,2] [1,]14 [2,]25 [3,]36 l [,1] [,2] [1,]9 10 matric1-replace(m,m[3,],l) matric1 [,1] [,2] [1,]14 [2,]25 [3,]9 10 matric2-replace(m,m[3,],xy[50,]) matric2 [,1] [,2] [1,] 1.00 4.00 [2,] 2.00 5.00 [3,] 1.855060 -1.865495 (for matric2 xy[50,] is [1.855060, -1.865495] Case 2: xy-cbind(x,y) xy x y [1,] -1.2138881 1.0270690 [2,] 0.5167578 -0.5793451 [3,] 1.3342747 -1.2561305 [4,] 0.3047976 -0.3411616 [5,] 1.7300424 -1.9266858 [6,] 1.6171193 -1.7818126 [7,] -0.3296678 0.5010075 [8,] 0.9840971 -0.8801955 [9,] -0.5187400 0.4149603 [10,] 1.7179670 -1.6482844 m1-replace(xy,xy[2,],l) m1 x y [1,] -1.2138881 1.0270690 [2,] 0.5167578 -0.5793451 [3,] 1.3342747 -1.2561305 [4,] 0.3047976 -0.3411616 [5,] 1.7300424 -1.9266858 [6,] 1.6171193 -1.7818126 [7,] -0.3296678 0.5010075 [8,] 0.9840971 -0.8801955 [9,] -0.5187400 0.4149603 [10,] 1.7179670 -1.6482844 l doesn't replace xy[2,](why??) Best regards -- View this message in context: http://www.nabble.com/How-to-replace-a-pair-of-observations-in-a-matrix--tp22478918p22478918.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] debug
Hi, All I have so many files in my directory. I got the following error. At this time, I couldn't use debug() to check error one by one because so many files getting invloved. How can I get some idea about my error?? . Skipping book_log-20060222T143612.txt Skipping book_log-20060222T162828.txt Skipping book_log-20060222T162833.txt Skipping book_log-20060222T183742.txt Skipping book_log-20060222T201442.txt Skipping book_log-20060224T153841.txt Skipping book_log-20060224T184225.txt Skipping book_log-20060224T193621.txt Skipping book_log-20060224T193957.txt Skipping book_log-20060225T110011.txt Skipping book_log-20060225T125836.txt Skipping book_log-20060225T131002.txt Processing book_log-20060225T165935.txt Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format Thanks a lot. Tammy _ More than messagescheck out the rest of the Windows Live. http://www.microsoft.com/windows/windowslive/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] can I draw 3D plot like this using R?
Thank you all for the suggestions and answers. Oliver On Mar 12, 6:51 am, Duncan Murdoch murd...@stats.uwo.ca wrote: On 11/03/2009 11:35 PM, Oliver wrote: hi, all I am looking at R package RGL to draw a colored mesh/surface plot like this one (from matlab). http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/cbar.gif The key features I am looking for is surfaced with grid and color, but not the terrain-like gradient. but I didn't come even close to it after browsing through rgl help file. It is a little tricky to draw both lines and solid colours on a surface in rgl, because one will hide the other: there's no way to turn off the hidden object removal in rgl. The easiest way to do it would be to draw the grid slightly above the surface. For example, x - seq(-2, 2, len=17) y - seq(-2, 2, len=17) z - outer(x,y, function(x,y) exp(-y^2)*sin(1.5*x)) color - rainbow(41)[1+round(10*outer(x,y, function(x,y) x^2 + y^2))] persp3d(x,y,z, color=color, smooth=FALSE) surface3d(x,y,z+0.001, front=lines, back=culled) (Fiddle with the 0.001 value if the grid disappears behind the surface, or floats too high above it.) Another way would be to draw the grid (and maybe the colour) as a texture. Duncan Murdoch have anyone drawn something like this before, is this doable afterall? thanks Oliver __ r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] debug
Tammy Ma wrote: Hi, All I have so many files in my directory. I got the following error. At this time, I couldn't use debug() to check error one by one because so many files getting invloved. How can I get some idea about my error?? The usual advice: simplify the problem until it's obvious. I don't know if you consider the skipping messages to be a problem, but if not, it sure looks as though the problem is in book_log-20060225T165935.txt so you can simplify things a lot by creating a copy of that file in a separate directory, and using debug or other techniques (e.g. options(error=recover) ) to diagnose it. Duncan Murdoch . Skipping book_log-20060222T143612.txt Skipping book_log-20060222T162828.txt Skipping book_log-20060222T162833.txt Skipping book_log-20060222T183742.txt Skipping book_log-20060222T201442.txt Skipping book_log-20060224T153841.txt Skipping book_log-20060224T184225.txt Skipping book_log-20060224T193621.txt Skipping book_log-20060224T193957.txt Skipping book_log-20060225T110011.txt Skipping book_log-20060225T125836.txt Skipping book_log-20060225T131002.txt Processing book_log-20060225T165935.txt Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format Thanks a lot. Tammy _ More than messages–check out the rest of the Windows Live™. http://www.microsoft.com/windows/windowslive/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] nested logit estimation
Dear all, Is there a function to fit nested logit available somewhere ? Sincerly Justin BEM BP 1917 Yaoundé Tél (237) 99597295 (237) 22040246 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] avoiding termination of nls given convergence failure
Hello. I have a script in which I repeatedly fit a nonlinear regression to a series of data sets using nls and the port algorithm from within a loop. The general structure of the loop is: for(i in 1:n){ extract relevant vectors of dependent and independent variables estimate starting values for Amax and Q.LCP fit-nls(photosynthesis~fit.Mitcherlich(irradiance,Amax,LCP,Q.LCP),data=temp , start=list(Amax=Astart,Q.LCP=x,LCP=33),control=list(maxiter=100,tol=5e-4), na.action=na.omit,trace=T,algorithm=port,lower=c(0,0,0)) } Despite trying to estimate good starting values, the nls function occasionally experiences problems with convergence. When this happens the function stops and prints an error message, thus preventing the loop from continuing. Is there some what of detecting the convergence problem while preventing the nls function from stopping when this happens, so that the loop can continue? Bill Shipley North American Editor, Annals of Botany Département de biologie Université de Sherbrooke Sherbrooke (Québec) J1K 2R1 Canada (819) 821-8000, poste 62079 (819) 821-8049 FAX http://pages.usherbrooke.ca/jshipley/recherche/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] avoiding termination of nls given convergence failure
Hi Bill, You should have a look at the try() function that lets you enclose an expression and handle failure in a way that prevents the entire execution from halting. Josh On Thu, Mar 12, 2009 at 1:13 PM, Bill Shipley bill.ship...@usherbrooke.cawrote: Hello. I have a script in which I repeatedly fit a nonlinear regression to a series of data sets using nls and the port algorithm from within a loop. The general structure of the loop is: for(i in 1:n){ extract relevant vectors of dependent and independent variables estimate starting values for Amax and Q.LCP fit-nls(photosynthesis~fit.Mitcherlich(irradiance,Amax,LCP,Q.LCP),data=temp , start=list(Amax=Astart,Q.LCP=x,LCP=33),control=list(maxiter=100,tol=5e-4), na.action=na.omit,trace=T,algorithm=port,lower=c(0,0,0)) } Despite trying to estimate good starting values, the nls function occasionally experiences problems with convergence. When this happens the function stops and prints an error message, thus preventing the loop from continuing. Is there some what of detecting the convergence problem while preventing the nls function from stopping when this happens, so that the loop can continue? Bill Shipley North American Editor, Annals of Botany Département de biologie Université de Sherbrooke Sherbrooke (Québec) J1K 2R1 Canada (819) 821-8000, poste 62079 (819) 821-8049 FAX http://pages.usherbrooke.ca/jshipley/recherche/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Reich 646 256 4763 i2pi simplicity . depth . scalability [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] avoiding termination of nls given convergence failure
If the goal here is to repeatedly run a particular model from different starting values then the nls2 package will do that for you. On Thu, Mar 12, 2009 at 2:13 PM, Bill Shipley bill.ship...@usherbrooke.ca wrote: Hello. I have a script in which I repeatedly fit a nonlinear regression to a series of data sets using nls and the port algorithm from within a loop. The general structure of the loop is: for(i in 1:n){ … extract relevant vectors of dependent and independent variables … … estimate starting values for Amax and Q.LCP… fit-nls(photosynthesis~fit.Mitcherlich(irradiance,Amax,LCP,Q.LCP),data=temp , start=list(Amax=Astart,Q.LCP=x,LCP=33),control=list(maxiter=100,tol=5e-4), na.action=na.omit,trace=T,algorithm=port,lower=c(0,0,0)) … } Despite trying to estimate good starting values, the nls function occasionally experiences problems with convergence. When this happens the function stops and prints an error message, thus preventing the loop from continuing. Is there some what of detecting the convergence problem while preventing the nls function from stopping when this happens, so that the loop can continue? Bill Shipley North American Editor, Annals of Botany Département de biologie Université de Sherbrooke Sherbrooke (Québec) J1K 2R1 Canada (819) 821-8000, poste 62079 (819) 821-8049 FAX http://pages.usherbrooke.ca/jshipley/recherche/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] avoiding termination of nls given convergence failure
?try For example, for (i in 1:n) { try (fit - nls(...), silent=TRUE) if (class(fit) != try-error) dowhateverthatneedstobedonewiththeresults else fit - NA } Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bill Shipley Sent: Thursday, March 12, 2009 2:13 PM To: R-help Subject: [R] avoiding termination of nls given convergence failure Hello. I have a script in which I repeatedly fit a nonlinear regression to a series of data sets using nls and the port algorithm from within a loop. The general structure of the loop is: for(i in 1:n){ extract relevant vectors of dependent and independent variables estimate starting values for Amax and Q.LCP fit-nls(photosynthesis~fit.Mitcherlich(irradiance,Amax,LCP,Q.LCP),data=temp , start=list(Amax=Astart,Q.LCP=x,LCP=33),control=list(maxiter=100,tol=5e-4), na.action=na.omit,trace=T,algorithm=port,lower=c(0,0,0)) } Despite trying to estimate good starting values, the nls function occasionally experiences problems with convergence. When this happens the function stops and prints an error message, thus preventing the loop from continuing. Is there some what of detecting the convergence problem while preventing the nls function from stopping when this happens, so that the loop can continue? Bill Shipley North American Editor, Annals of Botany Dipartement de biologie Universiti de Sherbrooke Sherbrooke (Quibec) J1K 2R1 Canada (819) 821-8000, poste 62079 (819) 821-8049 FAX http://pages.usherbrooke.ca/jshipley/recherche/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Cross-validation - lift curve
Hi all, I'd like to do cross-validation on lm and get the resulting lift curve/table (or, alternatively, the estimates on 100% of my data with which I can get lift). If such a thing doesn't exist, could it be derived using cv.lm, or would we need to start from scratch? Thanks! -- Eric Siegel, Ph.D. President Prediction Impact, Inc. Predictive Analytics World Conference More info: www.predictiveanalyticsworld.com LinkedIn Group: www.linkedin.com/e/gis/1005097 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] who can give me some hint?
I think I answered a very similar question from you yesterday but perhaps the mail went astray. The subject line is not informative. It may make it easier to think about if you use a function like isFirstInRun - function(x) c(TRUE, x[-1]!=x[-length(x)] Given a vector x (without NA's in it) it tells you if a given element of x is the first in a run of identical values. E.g., x - c(1,2,2,1,1,3) isFirstInRun(x) [1] TRUE TRUE FALSE TRUE FALSE TRUE You don't have to understand why this works or why it works quickly or have this idiom in your working set yet. You do need to know how to use logical values as subscripts to extract elements of interest from vectors or rows of interest from data frames. E.g., act_2[ with(act_2, isFirstInRun(Rep)), ] should returns row 51, 52, 58, and 60 of your example. If you want to only return the first of each Hour/Min combinary you could use either isFirstInRun(interaction(Hour,Min)) or isFirstInRun(Hour)|isFirstInRun(Min) as the row subscript to act_2 to pull out rows 51 and 60. If this were to become a standard function it could be modified to handle NA's, 0-long arguments, and multiple arguments. (If it accepted multiple arguments then rle() ought to be modified in the same way, as they are closely related.) Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com -- Tammy Ma metal_licaling at live.com Thu Mar 12 11:25:56 CET 2009 act_2 DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 55 2006-02-22 14:52:49 14 52 49 4 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle I want to change act_2 to DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle in other word, I want to keep 1st if there are many repeated value, I made the program as: rm_r-function(act_2){ dm-dim(act_2)[1]-1 for(i in 2:dm){ if(act_2$Rep[i+1]==act_2$Rep[i]){ act_2-act_2[-(i+1),] }else{ act_2-act_2 } } return(act_2) } when it moved one row on 1st loop, i should still start 2 but it become 3 at 2nd loop, if I add i-i-1, then i go to 1 seems not reasonbale. How should I modify it`? Tammy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Removing
Simpler, but maybe wrong. Not duplicated was my first response as well, but then I began wondering if the question implied globally duplicated or duplicated within subgroups. Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of The R Inferno and A Guide for the Unwilling S User) David Winsemius wrote: Much simpler would be: act2[!duplicated(act2$Rep),] #use the negation of the duplicated function on $Rep and indexing DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle Cannot reproduce the blank line though. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with predict and plotting confidence intervals
Thank you for you help Dr. Winsemius. The problem seems to stem from the fact that I have used the incorrect name in the prediction dataframe. The following code seems to work correctly. Thank you again, Michael wt.data - data.frame(code = factor(LETTERS[1:24]), area = c(60865,480,656792,92298,1200,1490,8202,4000,220,245,4000,390,325, 16,162911,20235,68800,3389,7,696,4050,1498,1214,99460), species = c(673,650,1353,1026,549,536,782,734,516,580,673,560,641,443,1105, 871,789,575,216,407,942,655,582,1018)) wt.data$logA - log10(wt.data$area) wt.data$logS - log10(wt.data$species) wt.mod - lm(logS~logA, data = wt.data) with(wt.data,plot(logA,logS, ylim = c(2.0,3.5),xlim = c(0,6))) pred.frame - data.frame(logA = seq(0,6, length.out = 24)) pp - predict(wt.mod, int = p, newdata=pred.frame) matlines(pred.frame$logA,pp, lty=c(1,2,2),col=red) Michael Denslow Graduate Student I.W. Carpenter Jr. Herbarium [BOON] Department of Biology Appalachian State University Boone, North Carolina U.S.A. -- AND -- Communications Manager Southeast Regional Network of Expertise and Collections sernec.org # I am not sure how to get the lines to draw correctly here matlines(pred.frame$a,pp, lty=c(1,2,2),col=black) The x values are your sequence whereas the y values are in the sequence from the original data. They are not correctly associated with each other. Try: pp - predict(lm(wt.data$logS~wt.data$logA), int = p, newdata= data.frame(logA=seq(0,6, length.out = 24)) ) plot(pp) At this point I should not have accepted your starting point. A better starting point would be to use the wt.mod model: pp - predict(wt.mod, int = p, newdata= list(logA=seq(0,6, length.out = 24)) ) # Followed by: plot( seq(0,6, length.out = 24), pp[ ,fit] ) lines(seq(0,6, length.out = 24), pp[ ,lwr], lty=2) lines(seq(0,6, length.out = 24), pp[ ,upr], lty=2) --david winsemius __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R grep gsub issue - sign seems to be causing an issue...
I would like to use grep and gsub to manipulate a vector to make the names used consistent, i.e. reduce a level or two. However, here is what I found when I attempted to use grep and gsub: tmp_test-c(House 1 Plot Plus +100,House 2 Plot Plus +100,House 3 Plot Plus -100,House 4 Plot Plus -100,House 1 Plus +100,House 2 Plus +100,House 3 Plus -100,House 4 Plus -100) gsub(tmp_test[2], tmp_test[1], tmp_test) [1] House 1 Plot Plus +100 House 2 Plot Plus +100 House 3 Plot Plus -100 House 4 Plot Plus -100 House 1 Plus +100 House 2 Plus +100 [7] House 3 Plus -100 House 4 Plus -100 grep(tmp_test[1],tmp_test) integer(0) However, gsub(tmp_test[3], tmp_test[1], tmp_test) [1] House 1 Plot Plus +100 House 2 Plot Plus +100 House 1 Plot Plus +100 House 4 Plot Plus -100 House 1 Plus +100 House 2 Plus +100 [7] House 3 Plus -100 House 4 Plus -100 Thanks for any feedback that can be provided. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Removing
True, I suppose. The specification from Ma could have been more explicit. Should she want to only have duplicates in sequence, then perhaps the use of construction within the rle function would be useful. act2[ act2$Rep[-1] != act2$Rep[-length(act2$Rep)], ] DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle Which turns out on examination to be isomorphic to Gabor's earlier efforts. -- David Winsemius On Mar 12, 2009, at 2:31 PM, Patrick Burns wrote: Simpler, but maybe wrong. Not duplicated was my first response as well, but then I began wondering if the question implied globally duplicated or duplicated within subgroups. Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of The R Inferno and A Guide for the Unwilling S User) David Winsemius wrote: Much simpler would be: act2[!duplicated(act2$Rep),] #use the negation of the duplicated function on $Rep and indexing DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle Cannot reproduce the blank line though. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] New York R Meetup
Hi, After hearing good things about the R community over on the west coast, I have started a New York based R meetup group. We intend to have our first get together on Thursday April 2nd, at 7pm. For more details pop on over to http://meetup.com/nyhackr Regards, Josh -- Joshua Reich 646 256 4763 i2pi simplicity . depth . scalability [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] stats lm() function
Hi, Im using the lm() function where the formula is quite big (300 arguments) and the data is a frame of 3000 values. This is running in a loop where in each step the formula is reduced by one argument, and the lm command is called again (to check which arguments are useful) . This takes 1-2 minutes. Is there a way to speed this up? i checked the code of the lm function and its seems that its preparing the data and then calls lm.Fit(). i thought about just doing this praparing stuff first and only call lm.fit() 300 times. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] stats lm() function
Hi, Im using the lm() function where the formula is quite big (300 arguments) and the data is a frame of 3000 values. This is running in a loop where in each step the formula is reduced by one argument, and the lm command is called again (to check which arguments are useful) . This takes 1-2 minutes. Is there a way to speed this up? i checked the code of the lm function and its seems that its preparing the data and then calls lm.Fit(). i thought about just doing this praparing stuff first and only call lm.fit() 300 times. -- View this message in context: http://www.nabble.com/stats-lm%28%29-function-tp22482054p22482054.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R grep gsub issue - sign seems to be causing an issue...
Jason Rupert wrote: I would like to use grep and gsub to manipulate a vector to make the names used consistent, i.e. reduce a level or two. This is dangerous: grep and gsub use regular expressions, so a lot of characters (see ?regexp for the list) have special meanings. For the kind of substitutions you want, just do things like newlist - tmp_test newlist[newlist == tmp_test[2]] - tmp_test[1] Duncan Murdoch However, here is what I found when I attempted to use grep and gsub: tmp_test-c(House 1 Plot Plus +100,House 2 Plot Plus +100,House 3 Plot Plus -100,House 4 Plot Plus -100,House 1 Plus +100,House 2 Plus +100,House 3 Plus -100,House 4 Plus -100) gsub(tmp_test[2], tmp_test[1], tmp_test) [1] House 1 Plot Plus +100 House 2 Plot Plus +100 House 3 Plot Plus -100 House 4 Plot Plus -100 House 1 Plus +100 House 2 Plus +100 [7] House 3 Plus -100 House 4 Plus -100 grep(tmp_test[1],tmp_test) integer(0) However, gsub(tmp_test[3], tmp_test[1], tmp_test) [1] House 1 Plot Plus +100 House 2 Plot Plus +100 House 1 Plot Plus +100 House 4 Plot Plus -100 House 1 Plus +100 House 2 Plus +100 [7] House 3 Plus -100 House 4 Plus -100 Thanks for any feedback that can be provided. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] GARCH SIMULATION
You should try installing fGarch package. Then you can simulate various garch models using garchsim command. Hope it help. jurica SUMANTA BASAK-4 wrote: Hi All, I,m trying to do a GARCH simulation in R 2.3.0 release in Windows XP. I've seen garchsim function but that is for garch (1,1) and ?garch gives an example for ARCH simulation. Can anyone help me how can i extend the help shown in ?garch to GARCH simulation? Please help me in this regard. Thanks, Sumanta Basak. __ r-h...@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 -- View this message in context: http://www.nabble.com/GARCH-SIMULATION-tp4277917p22482421.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stats lm() function
yes, indeed, you can certainly speed things up, by just changing the design matrix X and feeding it back to lm.fit(). In addition, if you just need the least squares estimates, then you gain a bit more by using constructs of the form: XtX - crossprod(X) Xty - crossprod(X, y) betas - solve(XtX, Xty) I hope it helps. Best, Dimitris Paul Hermes wrote: Hi, Im using the lm() function where the formula is quite big (300 arguments) and the data is a frame of 3000 values. This is running in a loop where in each step the formula is reduced by one argument, and the lm command is called again (to check which arguments are useful) . This takes 1-2 minutes. Is there a way to speed this up? i checked the code of the lm function and its seems that its preparing the data and then calls lm.Fit(). i thought about just doing this praparing stuff first and only call lm.fit() 300 times. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] stats lm() function
Look at: ?update For example: lm.obj - lm (y ~ x1 + ... + x300) lm.obj1 - update(lm.obj, . ~ . - x1) lm.obj2 - update(lm.obj1, . ~ . - x2) Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: ph84 masterods...@gmx.de Date: Thursday, March 12, 2009 3:28 pm Subject: [R] stats lm() function To: r-help@r-project.org Hi, Im using the lm() function where the formula is quite big (300 arguments) and the data is a frame of 3000 values. This is running in a loop where in each step the formula is reduced by one argument, and the lm command is called again (to check which arguments are useful) . This takes 1-2 minutes. Is there a way to speed this up? i checked the code of the lm function and its seems that its preparing the data and then calls lm.Fit(). i thought about just doing this praparing stuff first and only call lm.fit() 300 times. -- View this message in context: Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing
On Mar 12, 2009, at 3:02 PM, David Winsemius wrote: True, I suppose. The specification from Ma could have been more explicit. Should she want to only have duplicates in sequence, then perhaps the use of construction within the rle function would be useful. act2[ act2$Rep[-1] != act2$Rep[-length(act2$Rep)], ] DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 57 2006-02-22 14:52:51 14 52 51 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle Which turns out on examination to be isomorphic to Gabor's earlier efforts. Almost ... but not quite. The addition of a TRUE to that logical vecor (as in Bill Dunap's posting as well as Gabor's solution) is needed to keep this from failing in some instances, although this test case did not expose the flaw. act2[c(TRUE, act2$Rep[-1] != act2$Rep[-length(act2$Rep)]), ] -- David Winsemius On Mar 12, 2009, at 2:31 PM, Patrick Burns wrote: Simpler, but maybe wrong. Not duplicated was my first response as well, but then I began wondering if the question implied globally duplicated or duplicated within subgroups. Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of The R Inferno and A Guide for the Unwilling S User) David Winsemius wrote: Much simpler would be: act2[!duplicated(act2$Rep),] #use the negation of the duplicated function on $Rep and indexing DateDtime Hour Min Second Rep 51 2006-02-22 14:52:18 14 52 18 useractivity_act 52 2006-02-22 14:52:18 14 52 18 4 58 2006-02-22 14:52:52 14 52 52 3 60 2006-02-22 14:54:42 14 54 42 useractivity_idle Cannot reproduce the blank line though. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stats lm() function
I think you will find that many readers of this list would rather try to dissuade you from this misguided strategy. You are unlikely to get to a sensible solution in using step-down procedures with this sort of situation (large number of predictors with modest size of data). -- David Winsemius On Mar 12, 2009, at 1:59 PM, Paul Hermes wrote: Hi, Im using the lm() function where the formula is quite big (300 arguments) and the data is a frame of 3000 values. This is running in a loop where in each step the formula is reduced by one argument, and the lm command is called again (to check which arguments are useful) . This takes 1-2 minutes. Is there a way to speed this up? i checked the code of the lm function and its seems that its preparing the data and then calls lm.Fit(). i thought about just doing this praparing stuff first and only call lm.fit() 300 times. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R grep gsub issue - sign seems to be causing an issue...
On Thu, 12 Mar 2009, Duncan Murdoch wrote: Jason Rupert wrote: I would like to use grep and gsub to manipulate a vector to make the names used consistent, i.e. reduce a level or two. This is dangerous: grep and gsub use regular expressions, so a lot of characters (see ?regexp for the list) have special meanings. Unless argument fixed=TRUE which is often useful. For the kind of substitutions you want, just do things like newlist - tmp_test newlist[newlist == tmp_test[2]] - tmp_test[1] Duncan Murdoch However, here is what I found when I attempted to use grep and gsub: tmp_test-c(House 1 Plot Plus +100,House 2 Plot Plus +100,House 3 Plot Plus -100,House 4 Plot Plus -100,House 1 Plus +100,House 2 Plus +100,House 3 Plus -100,House 4 Plus -100) gsub(tmp_test[2], tmp_test[1], tmp_test) [1] House 1 Plot Plus +100 House 2 Plot Plus +100 House 3 Plot Plus -100 House 4 Plot Plus -100 House 1 Plus +100 House 2 Plus +100 [7] House 3 Plus -100 House 4 Plus -100 grep(tmp_test[1],tmp_test) integer(0) However, gsub(tmp_test[3], tmp_test[1], tmp_test) [1] House 1 Plot Plus +100 House 2 Plot Plus +100 House 1 Plot Plus +100 House 4 Plot Plus -100 House 1 Plus +100 House 2 Plus +100 [7] House 3 Plus -100 House 4 Plus -100 Thanks for any feedback that can be provided. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Writing xls - multiple sheets
Hi, Is there a package I can use to write to multiple sheets on xls file, other than using the paid version of xlsReadWrite package (xlsReadWritePro)? Thank you, Ferry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] portable R editor
Unfortunately, the suggested way with JauntePE does not work completely. Maybe I have found a better alternative now: There is a little free application by Sysinternals (now owned by MS) which can create junction points, i.e. a system link to a directory under Windows. It is available here: http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx In my setup, I have under the root directory of the USB stick one dir called Programs and one called Application Data. I have copied the Tinn-R folder to Programs and the ini files from the user profile into Application Data. In Programs\Tinn-R I have created a batch file startTinn-R.bat with this content: REM START junction %APPDATA%\Tinn-R %CD%\..\..\..\Application Data\Tinn-R @start .\bin\Tinn-R REM END and copied the junction.exe into this dir as well. When I double click this bat file, a link to the ini files on the USB stick is created in the user's application data directory in the local harddrive of the PC used. But note that this does not work if there exists a Tinn-R directory already in the user's application data dir in local harddrive. All the best, Werner Werner W. wrote: JauntePE is really easy to use. It does not take any particular skill. Just launch the main application, click on the Lauch JPE Quickie Button and it will guide you through the process. I left everything with the default settings. In brief, one starts the Tinn-R installer once from within JPE probably to check which folders, files, and registry entries are generated. Then, again from within JPE, one starts the now on the portable media installed Tinn-R application and finally the entire application can be packaged up which probably generates the starter and virtualization files within the Tinn-R folder. I realized that startup of Tinn-R is now slower and I haven't worked with that installation seriously yet but everything seems all right so far. Regards, Werner -- View this message in context: http://www.nabble.com/portable-R-editor-tp22291017p22484751.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there any difference between - and =
Jens Oehlschlägel wrote: Sean, would like to receive expert opinion to avoid potential trouble [..] i think the following is the most secure way if one really really has to do assignment in a function call f({a=3}) and if one keeps this convention, - can be dropped altogether. secure is relative, since due to R's lazy evaluation you never know whether a function's argument is being evalutated, for sure, but that's not different between - and {=}. in both cases, if the argument is not used, assignment will not be made. f- function(x)TRUE x - 1 f((x=2)) # obscured attempt to assign in a function call [1] TRUE x [1] 1 same with f(x-2) Thus there is dangerous advice in the referenced blog which reads: f(x - 3) which means assign 3 to x, and call f with the first argument set to the value 3 This might be the case in C but not in R. Actually in R f(x - 3) means: call f with a first unevaluated argument x - 3, and if and only if f decides to evaluate its first argument, then the assignment is done. indeed. i have already argued that using assignment within function calls is not a good idea; but pick any book on r, you likely to find numerous examples of it, without an appropriate warning. snip Here it is unpredictable whether your assignment takes place. Thus assigning like f({x=1}) or f((x=1)) or f(x-1) is the maximum dangerous thing to do: even if you have a code-reviewer and the guy is aware of the danger of f(x-1) he will probably miss it because f((x=1)) does look too similar to a standard call f(x=1). sorry, to me f({x=1}) looks pretty much unlike f(x=1). if someone uses assignments in function calls and does not know what he's doing, it's his fault. According to help(-), R's assignment operator is rather - than =: The operators - and = assign into the environment in which they are evaluated. The operator - can be used anywhere, whereas the operator = is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions. to me, it doesn't say anything like that R's assignment operator is rather - than =. So my recommendation is 1) use R's assignment operator with two spaces around (or assign()) and don't obscure ... but do beautify ... assignments by using C's don't acknowledge c for it assignment operator (or other languages equality operator) 2) do not assign in function arguments unless you have good reasons like in system.time(x - something) certainly good advice. P.P.S. a puzzle, following an old tradition: What is going on here? (and what would you need to do to prove it?) complete mystery to me. cheers, vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to find maximum values on the density function of a random variable
I would like to find the maximum values on the density function of a random variable. For example, I have a random variable rv - rbinom(1,1,0.1) + rnorm(1) Its density function is given by density(rv) and can be displayed by plot(density(rv)). How to calculate its maximum values? A density function may have a few (global and local) maximum values. Please help. Thanks, -james __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Writing xls - multiple sheets
I think that Gabor sent something earlier today ( or atleast something related ) so check the archives for his solution. On Thu, Mar 12, 2009 at 4:29 PM, Ferry wrote: Hi, Is there a package I can use to write to multiple sheets on xls file, other than using the paid version of xlsReadWrite package (xlsReadWritePro)? Thank you, Ferry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error.bars
Sueli Rodrigues wrote: Hi, I'm studying the Michael J. Crawley book (Statistics An Introduction using R)and I'm trying to reproduce one example (page 168) for plot a barplot with error bars, but when I put the function I receive the following message. Please, could someone told me what's wrong? error.bars=function(yv,z,nn){xv=barplot(yv,ylim=c(0,(max(yv)+max(z))),names=nn,ylab=deparse(substitute(yv)))g=(max(xv)-min(xv))/50 for(i in 1:length(xv)){lines(c(xv[i],xv[i]),c(yv[i]+z[i],yv[i]-z[i]))lines(c(xv[i]-g,xv[i]+g),c(yv[i]+z[i],yv[i]+z[i]))lines(c(xv[i]-g,xv[i]+g),c(yv[i]-z[i],yv[i]-z[i]))}} Erro: unexpected symbol in error.bars=function(yv,z,nn){xv=barplot(yv,ylim=c(0,(max(yv)+max(z))),names=nn,ylab=deparse(substitute(yv)))g Sueli Rodrigues Eng. Agrônoma - UNESP Mestranda - USP/ESALQ PPG-Solos e Nutrição de Plantas Fones (19)93442981 (19)33719762 This is the notorious dynamite plot which causes distorted perceptions, has an arbitrary base, and other problems. See http://biostat.mc.vanderbilt.edu/DynamitePlots for more information. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] setdiff for data.frames?
I have two data.frames. One is the subset of the other. I need to determine what rows were removed from the superset data.frame to form the subset data.frame. I was hoping to turn up functionality similar to setdiff for data.frames, but did not have any luck. It seems I need to find a function that performs the oposite as merge. dim(superset_dataframe) [1] 248 31 dim(subset_dataframe) [1] 214 31 Thank you for any suggestions of functions that might exist that might help. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] FW: Re: Writing xls - multiple sheets
Jorge was kind enough to point out that I made a mistake in referencing gabor's solution. See below. Thanks Jorge. Begin forwarded message Subject: Re: [R] Writing xls - multiple sheets Date: 3/12/2009 6:03:13 PM From: Jorge Ivan Velez To: markle...@verizon.net Hi Mark, Yes, he did (as always), but it is not what Ferry needed. Here is Gabor's post: http://www.nabble.com/read.xls-and-name-of-worksheet-to22477965.html#a22477965 http://www.nabble.com/read.xls-and-name-of-worksheet-to22477965.html#a22477965 http://www.nabble.com/read.xls-and-name-of-worksheet-to22477965.html#a22477965 http://www.nabble.com/read.xls-and-name-of-worksheet-to22477965.html#a22477965 and here what I think Ferry wants to be able to do: http://www.nabble.com/read.xls-and-name-of-worksheet-to22477965.html#a22477965 http://www.nabble.com/read.xls-and-name-of-worksheet-to22477965.html#a22477965 http://www.nabble.com/Creating-an-Excel-file-with-multiple-spreadsheets-td22419398.html http://www.nabble.com/Creating-an-Excel-file-with-multiple-spreadsheets-td22419398.html http://www.nabble.com/Creating-an-Excel-file-with-multiple-spreadsheets-td22419398.html http://www.nabble.com/Creating-an-Excel-file-with-multiple-spreadsheets-td22419398.html Regards, http://www.nabble.com/Creating-an-Excel-file-with-multiple-spreadsheets-td22419398.html http://www.nabble.com/Creating-an-Excel-file-with-multiple-spreadsheets-td22419398.html Jorge http://www.nabble.com/Creating-an-Excel-file-with-multiple-spreadsheets-td22419398.html http://www.nabble.com/Creating-an-Excel-file-with-multiple-spreadsheets-td22419398.html On Thu, Mar 12, 2009 at 5:52 PM, markle...@verizon.net mailto:markle...@verizon.net wrote:  I think that Gabor sent something earlier today ( or atleast something related ) so check the archives for his solution. mailto:markle...@verizon.net On Thu, Mar 12, 2009 at  4:29 PM, Ferry wrote: Hi, Is there a package I can use to write to multiple sheets on xls file, other than using the paid version of xlsReadWrite package (xlsReadWritePro)? Thank you, Ferry __ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. http://www.R-project.org/posting-guide.html [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] setdiff for data.frames?
Try this: library(sqldf) BODsub - BOD[1:3,] sqldf(select * from BOD except select * from BODsub) For more see: http://sqldf.googlecode.com On Thu, Mar 12, 2009 at 5:58 PM, Jason Rupert jasonkrup...@yahoo.com wrote: I have two data.frames. One is the subset of the other. I need to determine what rows were removed from the superset data.frame to form the subset data.frame. I was hoping to turn up functionality similar to setdiff for data.frames, but did not have any luck. It seems I need to find a function that performs the oposite as merge. dim(superset_dataframe) [1] 248 31 dim(subset_dataframe) [1] 214 31 Thank you for any suggestions of functions that might exist that might help. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Writing xls - multiple sheets
That was to read worksheet names but its true that the same packages rcom and rdcom can control Excel and therefore write spreadsheets. On Thu, Mar 12, 2009 at 5:52 PM, markle...@verizon.net wrote: I think that Gabor sent something earlier today ( or atleast something related ) so check the archives for his solution. On Thu, Mar 12, 2009 at 4:29 PM, Ferry wrote: Hi, Is there a package I can use to write to multiple sheets on xls file, other than using the paid version of xlsReadWrite package (xlsReadWritePro)? Thank you, Ferry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Unable to run smoother in qplot() or ggplot() - complains about knots
I get the following error when I run qplot() qplot(grade, read,data = hhm.long.m, geom = c(point, smooth)) Error in smooth.construct.cr.smooth.spec(object, data, knots) : x has insufficient unique values to support 10 knots: reduce k. I am not sure how to tackle this problem. When I take a subsample ( 1000) than I am able to run that function but with my sample of ~ 40,000 qplot gives me that error. I have 6 grades. Please cc me on reply. Thanks! Chris __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Time-Ordered Clustering
Hello All, Does anyone know of a package that performs constraint-based clusters? Ideally the package could perform Time-Ordered Clustering, a technique applied in a recent journal article by Runger, Nelson, Harnish (using MS Excel). Quote, in our specific implementation of constrained clustering, the clustering algorithm remains agglomerative and hierarchical, but observations or clusters are constrained to only join if they are adjacent in time. CRAN searches using variants of cluster and/or constraint and/or time etc. didn't yield anything I could recognize. Thank you, Paul Paul Prew Ecolab Eagan, MN paul.p...@ecolab.com CONFIDENTIALITY NOTICE: =\ \ This e-mail communication a...{{dropped:12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.