Re: [R] Need help putting histograms on the diagonal of a splom plot
Hello, I think the histograms may have been unintentionally omitted from the examples below. Borrowing from a couple of sources, here's a function to get the histograms instead of the density plot: panel.hist.splom-function(x, ...) { yrng - current.panel.limits()$ylim h - hist(x, plot = FALSE) breaks - h$breaks; nB - length(breaks) y - h$counts; y - yrng[1] + 0.95 * diff(yrng) * y / max(y) panel.rect(breaks[-nB], yrng[1], breaks[-1], y, col=cyan, ...) } -Ben From: Deepayan Sarkar deepayan.sarkar_at_gmail.com mailto:deepayan.sarkar_at_gmail.com?Subject=Re:%20%5BR%5D%20Need%20help%20putting%20histograms%20on%20the%20diagonal%20of%20a%20splom%20plot Date: Fri, 31 Aug 2007 14:02:27 -0700 On 8/30/07, Marc Paterno paterno_at_fnal.gov wrote: Hello, http://tolstoy.newcastle.edu.au/R/e2/help/07/08/24539.html#24614qlink1 / / / I am in need of help in putting histograms on the diagonal of a plot / / produced with splom(). / / / / The plot matrix I am trying to produce is to have standard scatterplots / / in the upper-left triangle, contour plots in the lower-right triangle, / / and histograms on the diagonal. I have a function that does the first / / two, but the histograms on the diagonal has been beyond my ability. / / / / Here is my function: / / / / require(lattice) / / require(MASS) / / my.plot = function(data) / / { / / splom( ~data / / , lower.panel=function(x,y, ...) / / { / / xy=kde2d(x,y) / / xy.tr=con2tr(xy) / / panel.contourplot( xy.tr$x / / , xy.tr$y / / , xy.tr$z / / , subscripts=seq(nrow(xy.tr)) / / , contour=TRUE / / , region=TRUE / / , labels = FALSE / / , col.regions = terrain.colors / / ) / / } / / , upper.panel=function(x,y, ...) / / { / / panel.grid(-1,-1) / / panel.xyplot(x,y, cex=0.5) / / } / / #, diag.panel=function(x, ...) / / # { / / # panel.histogram(x, ...) / / # } / / ) / / } / / / / It can be called, for example, with: / / / / my.plot(subset(iris, select = Sepal.Length:Petal.Width)) / / / / (the subset is necessary to get rid of a variable that is a factor; my / / function can not deal with factors). / / / / I have commented out my best guess at the code needed to produce the / / histograms along the diagonal, which fails. / Well, basically the y-axis range of the diagonal panels are not right. What you want is simpler if you are happy with a density estimate: my.plot = function(data) { splom( ~data #, lower.panel=... #, upper.panel=... , diag.panel = function(x, ...) { yrng - current.panel.limits()$ylim d - density(x) d$y - with(d, yrng[1] + 0.95 * diff(yrng) * y / max(y) ) panel.lines(d) }) } my.plot(iris[1:4]) For a histogram, things are a bit more complicated, but still easy enough: my.plot = function(data) { splom( ~data #, lower.panel=... #, upper.panel=... , diag.panel = function(x, ...) { yrng - current.panel.limits()$ylim d - density(x) d$y - with(d, yrng[1] + 0.95 * diff(yrng) * y / max(y) ) panel.lines(d) }) } -Deepayan -- Benjamin Barnes, MEM Doctoral Student Department of Environmental Epidemiology German Cancer Research Center Im Neuenheimer Feld 280 D-69120 Heidelberg __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cutting pasting help examples into script window
On 9/21/07, Muenchen, Robert A (Bob) [EMAIL PROTECTED] wrote: Now I'm working in 2.5.1 on a home machine also running XP. It has the same problem, and I think I finally figured it out. I've noticed that if the cursor is directly over the text, it becomes an I-beam. When hovering over the blank space around the text, the cursor becomes an arrow. Selections via the arrow almost always paste properly into a script window. Copies made while selecting with the I-beam cursor almost always fail. Regardless of how the selection is done, a paste into Notepad never fails. Copying from Notepad to a script window never fails, regardless of how the paste into Notepad was selected. Very strange! Bob P.S. almost the testing has been with the ?data.frame and ?summary examples. -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: Thursday, September 20, 2007 7:59 PM To: Muenchen, Robert A (Bob) Cc: [EMAIL PROTECTED] Subject: Re: [R] Cutting pasting help examples into script window On 20/09/2007 1:49 PM, Muenchen, Robert A (Bob) wrote: Does this look like a bug? If so, is there a different way to report it? It sounds like a bug, but I can't reproduce it. You said it is intermittent on your system. Can you try to work out the conditions that reliably trigger it? It might be something specific to your system; does anyone else see this? Duncan Murdoch I notice the same thing, (R 2.5.0), except I can't get the example to paste correctly at all- The cursor never turns into I-beam. /Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Building packages including Java files
Hello all, Can someone please point me in the right direction to find the documentation that explains how to build packages that include java code. Thank you. I'm sorry if this is entirely obvious! Best regards, Mark -- Mark Collins [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Building packages including Java files
I think you have to visit the following website to get information about java packages: http://www.rforge.net/rJava/ http://www.rforge.net/rJava/ Then of course the official R documentation which describes how to build packages for R. With kind regards Marcel -- View this message in context: http://www.nabble.com/Building-packages-including-Java-files-tf4492509.html#a12814486 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] Plotmath issue superscript -
On Thu, 2007-09-20 at 18:19 +0200, Peter Dalgaard wrote: Gavin Simpson wrote: Dear List, I'm trying to typeset some chemical ions in axis labels. These have both super and subscript components, and for some, I need a superscript -. In LaTeX I might use $NO_3^-$ to do the typesetting, but I'm having a problem getting the correct invocation for expression: snip / It's an operator, it needs something to operate on. Try plot(0,main=quote(NO^-{})) Thanks, Peter, for this solution, and also to Peter Ehlers and ScionForbai for theirs. All the best, G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 making a function of scatter plot with multiple variables
Thanks Jim for the excellent solution. Can I make this function more flexible for the usage of different numbers of parameters? Tom jim holtman [EMAIL PROTECTED] skrev: The simple way is to enclose it in a 'function' and pass parameters. Assuming that you have the same number of parameters, then the following will do: my.func - function(x,y,d1,v1,s1,t1,s2,t2,s3,t3,s4,t4,s5,t5) { op - par(bg = grey97) par(mfrow=c(1,2)) plot(d1,v1, pch=v, col=orange,cex=0.6, lwd=2, xlab=day, ylab=resp,cex.main =1,font.main= 1,main= Surv data,ylim=y,xlim=x, col.main=navyblue,col.lab=navyblue,cex.lab=0.7) points(s1,t1, pch=A, col=green4, cex=1) points(s2,t2, pch=B,col=navyblue, cex=1) points(s3,t3, pch=C,col=red, cex=1) points(s4,t4, pch=D,col=darkviolet, cex=1) points(s5,t5, pch=E,col=blue, cex=1) legend(topright,lbels,col=c(orange,green4,navyblue,red,darkviolet,blue), text.col=c(orange,green4,navyblue,red,darkviolet,steelblue), pch=c(v,A,B,C,D,E),bg='gray100',cex=0.7,box.lty=1,box.lwd=1) abline(h = -1:9, v = 0:8, col = lightgray, lty=3) par(op) } # call it with my.func(x,y,d1,v1,s1,t1,s2,t2,s3,t3,s4,t4,s5,t5) You might also include the data in a list to make it easier On 9/20/07, Tom Cohen wrote: Dear list, I have done a scatter plot of multiple variables in the same graph, with different col and pch. I managed to do it with the following code but not know how to make a function of these so that next time if I want to do similar graph but with new variables, I dont have to copy the code and then change the old variables with the new ones but just call a function with the new variables. I dont have any experience in making a function and would be very grateful if you can help me. A function will shorten my prog dramatically, since I repeat tthis type of graph alots in my analysis. Thanks in advance, Tom op - par(bg = grey97) par(mfrow=c(1,2)) plot(d1,v1, pch=v, col=orange,cex=0.6, lwd=2, xlab=day, ylab=resp,cex.main =1,font.main= 1,main= Surv data,ylim=y,xlim=x, col.main=navyblue,col.lab=navyblue,cex.lab=0.7) points(s1,t1, pch=A, col=green4, cex=1) points(s2,t2, pch=B,col=navyblue, cex=1) points(s3,t3, pch=C,col=red, cex=1) points(s4,t4, pch=D,col=darkviolet, cex=1) points(s5,t5, pch=E,col=blue, cex=1) legend(topright,lbels,col=c(orange,green4,navyblue,red,darkviolet,blue), text.col=c(orange,green4,navyblue,red,darkviolet,steelblue), pch=c(v,A,B,C,D,E),bg='gray100',cex=0.7,box.lty=1,box.lwd=1) abline(h = -1:9, v = 0:8, col = lightgray, lty=3) par(op) - Jämför pris på flygbiljetter och hotellrum: http://shopping.yahoo.se/c-169901-resor-biljetter.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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? - Låna pengar utan säkerhet. [[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] Would you please tell me about Parallel Markov Chains ?
Hi, I am a master student of statistics and already working on my thesis, which is related to Markov Chains. In one of the papers I have studied there is an expression of Parallel Markov Chains, please tell me about it, Thanks in advance Elaheh __ =listsid=396545469 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cutting pasting help examples into script window
On 9/20/2007 9:23 PM, Muenchen, Robert A (Bob) wrote: Now I'm working in 2.5.1 on a home machine also running XP. It has the same problem, and I think I finally figured it out. I've noticed that if the cursor is directly over the text, it becomes an I-beam. When hovering over the blank space around the text, the cursor becomes an arrow. Selections via the arrow almost always paste properly into a script window. Copies made while selecting with the I-beam cursor almost always fail. Regardless of how the selection is done, a paste into Notepad never fails. Copying from Notepad to a script window never fails, regardless of how the paste into Notepad was selected. I believe this is fixed now. The problem was that some of the rich text formatting was being pasted into the script window; it didn't reformat everything to fixed text. I'm not sure why this resulted in loss of line feeds, but fixing it seems to have fixed that too. This change should make it into 2.6.0. If you take a look at builds starting tomorrow you can test it out. Duncan Murdoch Very strange! Bob P.S. almost the testing has been with the ?data.frame and ?summary examples. -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: Thursday, September 20, 2007 7:59 PM To: Muenchen, Robert A (Bob) Cc: [EMAIL PROTECTED] Subject: Re: [R] Cutting pasting help examples into script window On 20/09/2007 1:49 PM, Muenchen, Robert A (Bob) wrote: Does this look like a bug? If so, is there a different way to report it? It sounds like a bug, but I can't reproduce it. You said it is intermittent on your system. Can you try to work out the conditions that reliably trigger it? It might be something specific to your system; does anyone else see this? Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error using nls()
Hallo HelpeRs, I try to reconstruct some results from an econometric text book (Heij et al. (2004), pp. 218-20). For the data x - structure(list(q1 = c(345, 331, 320, 314, 299, 395, 415, 490, 547, 656, 628, 627), d1 = c(1, 1, 1, 1, 1, 1, 1.05, 1.05, 1.05, 1.15, 1.15, 1.15)), .Names = c(q1, d1), row.names = as.integer(c(NA, 12)), class = data.frame) I tried to estimate a nonlinear regression model using nls(). I get nls(log(q1)~b1+(b2/b3)*(d1^b3-1),data=x,start=list(b1=0,b2=1,b3=1),trace=TRUE) 246.132 : 0. 1. 1. 51.0907 Error in qr.solve(QR.B, cc) : singular matrix 'a' in solve However, using: jjf - function(x){z - log(q1)-x[1]+(x[2]/x[3])*(d1^x[3]-1);sum(z*z)} optim(c(0,1,1),jjf) rendered (some of) the results desired in a jiffy. What am I doing wrong? Dietrich -- Dietrich Trenkler c/o Universitaet Osnabrueck Rolandstr. 8; D-49069 Osnabrueck, Germany email: [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ambiguities in vector
First of all thanks a lot for your answer. Now I will try to realize your suggestion. Greetings B Am 21.09.2007 um 11:38 schrieb James Reilly: If I understand you right, you have several multiple response variables (with the responses encoded in numeric strings) and you want to see whether these are associated with sex. To tabulate the data, I would convert your variables into collections of dummy variables using regexpr(), then use table(). You can use a modified chi-squared test with a Rao-Scott correction on the resulting tables; see Thomas and Decady (2004). Bootstrapping is another possible approach. @article{, Author = {Thomas, D. Roland and Decady, Yves J.}, Journal = {International Journal of Testing}, Number = {1}, Pages = {43 - 59}, Title = {Testing for Association Using Multiple Response Survey Data: Approximate Procedures Based on the Rao-Scott Approach.}, Volume = {4}, Year = {2004}, Url=http://search.ebscohost.com/login.aspx? direct=truedb=pbhAN=13663214site=ehost-live } Hope this helps, James -- James Reilly Department of Statistics, University of Auckland Private Bag 92019, Auckland, New Zealand On 21/9/07 7:14 AM, Birgit Lemcke wrote: First thanks for your answer. Now I try to explain better: I have species in the rows and morphological attributes in the columns coded by numbers (qualitative variables; nominal and ordinal). In one table for the male plants of every species and in the other table for the female plants of every species. The variables contain every possible occurrence in this species and this gender. I would like to compare every variable between male and female plants for example using a ChiSquare Test. The Null-hypothesis could be: Variable male is equal to variable Female. The question behind all is, if male and female plants in this species are significantly different and which attributes are responsible for this difference. I really hope that this is better understandable. If not please ask. Thanks a million in advance. Greetings Birgit Birgit Lemcke Institut für Systematische Botanik Zollikerstrasse 107 CH-8008 Zürich Switzerland Ph: +41 (0)44 634 8351 [EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] A reproducibility puzzle with NORM
Hi Folks, I'm using the 'norm' package (based on Shafer's NORM) on some data. In outline, (X,Y) are bivariate normal, var(X)=0.29, var(Y)=24.4, cov(X,Y)=-0.277, there are some 900 cases, and some 170 values of Y have been set missing (NA). The puzzle is that, repeating the multiple imputation starting from the same random seed, I get different answers from the repeats depending if I do an odd number of imputations, but the same answer on the repeats if I do en even number (which includes the second repeat of an odd number). It may possibly have something to do with how I've written the code for the loop, but if so then I'm not seeing it! CODE: ## Set up the situation: Data-read.csv(MyData.csv) X-Data$X; Y-Data$Y ##(If you want to try it, set your own data here) Raw-cbind(X,Y) library(norm) ## Initialise stuff s-prelim.norm(Raw) t0-em.norm(s) ## ## Set the Random Seed rngseed(31425) ## Do the first imputation: t - da.norm(s,t0,steps=20) Imp - imp.norm(s,t, Raw) X.Imp - Imp[,1]; Y.Imp-Imp[,2] ## Now do the rest, and accumulate lists of the results ## Est.Imp = list of estimated coeffs ## SE.Imp = list of SEs of estimated coeffs: Est.Imp - list(summary(lm(Y.Imp~X.Imp))$coef[,1]) SE.Imp - list(summary(lm(Y.Imp~X.Imp))$coef[,2]) N=4 for(i in (2:N)){ t-da.norm(s,t,steps=20) Imp-imp.norm(s,t,Raw) X.Imp-Imp[,1]; Y.Imp-Imp[,2] Est.Imp-c(Est.Imp,list(summary(lm(Y.Imp~X.Imp))$coef[,1])) SE.Imp -c( SE.Imp,list(summary(lm(Y.Imp~X.Imp))$coef[,2])) } ## Finally, combine the imputations: mi.inference(Est.Imp,SE.Imp) I've illustrated N=4 (even) above, for 4 imputations. Now, I run the code repeatedly from ## Set the Random Seed down to mi.inference(Est.Imp,SE.Imp) With N=4, I always get the same result. If I set N=5, I alternately get different results: The second run is different from the first, but the third is the same as the first, and the fourth is the same as the second, ... In general, for even N, it is as for N=4, and for odd N it is as for N=5. Any ideas??? Thanks, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 21-Sep-07 Time: 14:13:27 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error using nls()
You need better starting values. Try setting b3=1 and solving using lm using that result as your starting values in nls: cc - coef(lm(log(q1)~d1,data=x)) cc - c(cc, 1) names(cc) - c(b1, b2, b3) nls(log(q1)~b1+(b2/b3)*(d1^b3-1),data=x,start=cc,trace=TRUE) 225.0784 : 1.515604 4.329543 1.00 0.1243237 :5.807118 8.966687 -13.977948 0.08707836 :5.807118 10.295483 -13.329564 0.08704864 :5.807118 10.298223 -13.430181 0.08704864 :5.807118 10.298319 -13.430735 Nonlinear regression model model: log(q1) ~ b1 + (b2/b3) * (d1^b3 - 1) data: x b1 b2 b3 5.807 10.298 -13.431 residual sum-of-squares: 0.08705 Number of iterations to convergence: 4 Achieved convergence tolerance: 1.27e-09 On 9/21/07, Dietrich Trenkler [EMAIL PROTECTED] wrote: Hallo HelpeRs, I try to reconstruct some results from an econometric text book (Heij et al. (2004), pp. 218-20). For the data x - structure(list(q1 = c(345, 331, 320, 314, 299, 395, 415, 490, 547, 656, 628, 627), d1 = c(1, 1, 1, 1, 1, 1, 1.05, 1.05, 1.05, 1.15, 1.15, 1.15)), .Names = c(q1, d1), row.names = as.integer(c(NA, 12)), class = data.frame) I tried to estimate a nonlinear regression model using nls(). I get nls(log(q1)~b1+(b2/b3)*(d1^b3-1),data=x,start=list(b1=0,b2=1,b3=1),trace=TRUE) 246.132 : 0. 1. 1. 51.0907 Error in qr.solve(QR.B, cc) : singular matrix 'a' in solve However, using: jjf - function(x){z - log(q1)-x[1]+(x[2]/x[3])*(d1^x[3]-1);sum(z*z)} optim(c(0,1,1),jjf) rendered (some of) the results desired in a jiffy. What am I doing wrong? Dietrich -- Dietrich Trenkler c/o Universitaet Osnabrueck Rolandstr. 8; D-49069 Osnabrueck, Germany email: [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A reproducibility puzzle with NORM
Norm uses a Box-Muller normal RNG, and rngseed does not reset its state (it has some Fortran save variables). So if you ask for an odd number of normals and call rngseed, the next normal 'generated' is the second half of the last pair with the previous seed. Ideally packages should be converted to use R's number generators which do not have such quirks. On Fri, 21 Sep 2007, [EMAIL PROTECTED] wrote: Hi Folks, I'm using the 'norm' package (based on Shafer's NORM) on some data. In outline, (X,Y) are bivariate normal, var(X)=0.29, var(Y)=24.4, cov(X,Y)=-0.277, there are some 900 cases, and some 170 values of Y have been set missing (NA). The puzzle is that, repeating the multiple imputation starting from the same random seed, I get different answers from the repeats depending if I do an odd number of imputations, but the same answer on the repeats if I do en even number (which includes the second repeat of an odd number). It may possibly have something to do with how I've written the code for the loop, but if so then I'm not seeing it! CODE: ## Set up the situation: Data-read.csv(MyData.csv) X-Data$X; Y-Data$Y ##(If you want to try it, set your own data here) Raw-cbind(X,Y) library(norm) ## Initialise stuff s-prelim.norm(Raw) t0-em.norm(s) ## ## Set the Random Seed rngseed(31425) ## Do the first imputation: t - da.norm(s,t0,steps=20) Imp - imp.norm(s,t, Raw) X.Imp - Imp[,1]; Y.Imp-Imp[,2] ## Now do the rest, and accumulate lists of the results ## Est.Imp = list of estimated coeffs ## SE.Imp = list of SEs of estimated coeffs: Est.Imp - list(summary(lm(Y.Imp~X.Imp))$coef[,1]) SE.Imp - list(summary(lm(Y.Imp~X.Imp))$coef[,2]) N=4 for(i in (2:N)){ t-da.norm(s,t,steps=20) Imp-imp.norm(s,t,Raw) X.Imp-Imp[,1]; Y.Imp-Imp[,2] Est.Imp-c(Est.Imp,list(summary(lm(Y.Imp~X.Imp))$coef[,1])) SE.Imp -c( SE.Imp,list(summary(lm(Y.Imp~X.Imp))$coef[,2])) } ## Finally, combine the imputations: mi.inference(Est.Imp,SE.Imp) I've illustrated N=4 (even) above, for 4 imputations. Now, I run the code repeatedly from ## Set the Random Seed down to mi.inference(Est.Imp,SE.Imp) With N=4, I always get the same result. If I set N=5, I alternately get different results: The second run is different from the first, but the third is the same as the first, and the fourth is the same as the second, ... In general, for even N, it is as for N=4, and for odd N it is as for N=5. Any ideas??? Thanks, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 21-Sep-07 Time: 14:13:27 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Importing a dataset
I don't know a way of loading parts of an .RData file either, but another solution is to use the envir argument of load to load the data into a new environment: x - 1 y - rnorm(3) save.image(tmp.RData) rm(x) rm(y) load(tmp.RData, env - new.env()) get(x, env) [1] 1 get(y, env) [1] -0.1105102 0.6923334 1.5506114 rm(env) Gabor On Fri, Sep 21, 2007 at 02:52:21PM +0100, S Ellison wrote: I don't know a short way, but this worked when I tried it. Maybe there's a clue in there somewhere? get1-function(fname, varname) { load(fname) get(varname) } x-1 y-rnorm(3) save.image(temp.RData) rm(x) rm(y) get1(temp.Rdata,x) get1(temp.Rdata,y) Steve E Marco Venanzi [EMAIL PROTECTED] 17/09/2007 12:38:24 Hi,how can I load a dataset from another file R.Data,without importing all the objects (functions and other datasets) contained in that file?Thanks, Marco [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. *** This email contains information which may be confidential and/or privileged, and is intended only for the individual(s) or organisation(s) named above. If you are not the intended recipient, then please note that any disclosure, copying, distribution or use of the contents of this email is prohibited. Internet communications are not 100% secure and therefore we ask that you acknowledge this. If you have received this email in error, please notify the sender or contact +44(0)20 8943 7000 or [EMAIL PROTECTED] immediately, and delete this email and any attachments and copies from your system. Thank you. LGC Limited. Registered in England 2991879. Registered office: Queens Road, Teddington, Middlesex TW11 0LY, UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Csardi Gabor [EMAIL PROTECTED]MTA RMKI, ELTE TTK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Likelihood ration test on glm
I would like to try a likelihood ratio test in place of waldtest. Ideally I'd like to provide two glm models, the second a submodel of the first, in the style of lrt (http://www.pik-potsdam.de/~hrust/tools/farismahelp/lrt.html). [lrt takes farimsa objects] Does anyone know of such a likelihood ratio test? Chris Elsaesser, PhD Principal Scientist, Machine Learning SPADAC Inc. 7921 Jones Branch Dr. Suite 600 McLean, VA 22102 703.371.7301 (m) 703.637.9421 (o) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Likelihood ration test on glm
Chris Elsaesser wrote: I would like to try a likelihood ratio test in place of waldtest. Ideally I'd like to provide two glm models, the second a submodel of the first, in the style of lrt (http://www.pik-potsdam.de/~hrust/tools/farismahelp/lrt.html). [lrt takes farimsa objects] Does anyone know of such a likelihood ratio test? I think anova(model1,model2,test=Chi) will do what you want. -- Kevin E. Thorpe Biostatistician/Trialist, Knowledge Translation Program Assistant Professor, Department of Public Health Sciences Faculty of Medicine, University of Toronto email: [EMAIL PROTECTED] Tel: 416.864.5776 Fax: 416.864.6057 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] truncating a data frame based on a function
Hi, Consider the following example. a = c(1,2,3); b = c(4,5,6); c = cbind(a,b); c[(2 c[,1]) (c[,1] 4),] a b 3 6 So, the idea is to select rows for which the value in the first column is between 2 and 4. This works, however, I don't like having to reference a explicitly in this fashion, and just wondered if there was a preferred way to accomplish the same thing. Ideally, I'd like to make use of a function. Thanks, Faheem. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Estimate correlation with bootstrap
Try this: a - c(1,2,3,4,5,6,7,8,9,10) b - c(1,1,56,3,6,6,6,7,2,10) n - length(a) boot.cor.a.b - replicate( 1000, {tmp - sample(n, replace=TRUE); cor(a[tmp],b[tmp]) } ) hist(boot.cor.a.b) abline( v=c( mean(boot.cor.a.b), median(boot.cor.a.b) ), col=c('blue','green')) Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andreas Klein Sent: Thursday, September 20, 2007 11:59 PM To: r-help@r-project.org Subject: [R] Estimate correlation with bootstrap Hello. I would like to estimate the correlation coefficient from two samples with Bootstrapping using the R-function sample(). The problem is, that I have to sample pairwise. For example if I have got two time series and I draw from the first series the value from 1912 I need the value from 1912 from the second sample, too. Example: Imagine that a and b are two time series with returns for example: a - c(1,2,3,4,5,6,7,8,9,10) b - c(1,1,56,3,6,6,6,7,2,10) a.sample - numeric(10) b.sample - numeric(10) boot.cor.a.b - numeric(1000) for (i in 1:1000) { for (j in 1:10) { a.sample[j] - sample(a,1,replace=TRUE) b.sample[j] - sample(b,1,replace=TRUE) } boot.cor.a.b[i] - cor(a,b) } The problem here is, that the sampling is independent from each other. So how do I have to change the R-code to get the pairwise sampling mentioned above? I hope you can help me. Sincerely Klein. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] really dumb question | loop counters in
Hi, This works: for(i in seq(1,100,5)) { print(i) } Very similar to the way python does this kind of loop. Paul Evan Cooch schreef: Basically new to [R] - as a programming environment at least (had lots of recent experience compiling it on our Opteron-based servers). Was trying to write some simple little scripts (in advance of porting over some bigger things from other environments - like MATLAB), when I realized that handling counters in loop constructs in [R] is not patently obvious (at least, IMO, compared to other languages). Suppose I want to iterate something from 1 to 100, using a step size of (say) 5. Trying the obvious for(x in 1:5:100) { print(x) } (Perhaps obviously, I've borrowed the MATLAB convention to some degree). Or, looping from 0 - 1 by 0.01? I've dug through what [R] documentation I have, and all I can find is the somewhat obtuse. For example, I can use x - seq(0,1, by=.01) But not for(x in (0,1,by=0.01)) { print(x) } What about things that are slickly handled in C++, like for (node=start; valuethreshold node!=end; node=node-next) { ... } OK - I'm stumped (and happy to humiliate myself with what has surely got to be trivial). I'm happy with a simple basic counter at this point. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +31302535773 Fax:+31302531145 http://intamap.geo.uu.nl/~paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Likelihood ration test on glm
chris, as long as you know the log likelihood functions and the # of parameters in both models, a pencil and a piece of paper should be enough to calculate LR test. On 9/21/07, Chris Elsaesser [EMAIL PROTECTED] wrote: I would like to try a likelihood ratio test in place of waldtest. Ideally I'd like to provide two glm models, the second a submodel of the first, in the style of lrt (http://www.pik-potsdam.de/~hrust/tools/farismahelp/lrt.html). [lrt takes farimsa objects] Does anyone know of such a likelihood ratio test? Chris Elsaesser, PhD Principal Scientist, Machine Learning SPADAC Inc. 7921 Jones Branch Dr. Suite 600 McLean, VA 22102 703.371.7301 (m) 703.637.9421 (o) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- === I am dying with the help of too many physicians. - Alexander the Great, on his deathbed === WenSui Liu (http://spaces.msn.com/statcompute/blog) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] getAnywhere
On 9/21/2007 12:16 PM, Giovanni Petris wrote: Hello, How can I see a function called +.dlm? methods(+) [1] +.Date +.dlm* +.POSIXt Non-visible functions are asterisked getAnywhere(+.dlm) Error in grep(pattern, x, ignore.case, extended, value, fixed, useBytes) : invalid regular expression '+\.dlm' Thanks in advance, Giovanni This looks like a bug in getS3method. Since + has special meaning in the regular expression, it should be escaped, and it wasn't. I'll fix it. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Q: appending to non-existent vector?
This is a real newbie question. What makes it worse is that I know I've seen the answer somewhere, but I can no longer find it. If I have a loop that is supposed to generate a vector piecemeal, adding an element each time through the loop, what do I do to stop it failing the first time around the loop, when the vector doesn't yet exist (so I can't use the append() function)? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Q: appending to non-existent vector?
Something like this: myvec - NULL while( condition ) { myvec - c(myvec, additional stuff) } However, if you know ahead of time how long the vector will be (you are adding 1 element at a time), then it is best to initialize the vector to the correct length: myvec - numeric(1000) for (i in 1:1000) { myvec[i] - additional stuff } In the second case you create a vector of length 1000 then insert numbers into it. In the first case you first create a vector of length 1, then next time through you create a new vector of length 2, copy a value into position 1 then insert the new value into position 2 then give it the same name as the previous vector (allowing the previous version to be garbage collected at some point), on the 3rd iteration you create a new vector of length 3, copy 2 values and insert 1, etc. You can see that that can fragment memory and take unneeded time which is why the second method is prefered. The only time to use the first method is if you don't know how long each piece of 'additional stuff' is and you know that you will only be doing the loop a few times. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of D. R. Evans Sent: Friday, September 21, 2007 11:15 AM To: [EMAIL PROTECTED] Subject: [R] Q: appending to non-existent vector? This is a real newbie question. What makes it worse is that I know I've seen the answer somewhere, but I can no longer find it. If I have a loop that is supposed to generate a vector piecemeal, adding an element each time through the loop, what do I do to stop it failing the first time around the loop, when the vector doesn't yet exist (so I can't use the append() function)? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Q: appending to non-existent vector?
On 9/21/2007 1:15 PM, D. R. Evans wrote: This is a real newbie question. What makes it worse is that I know I've seen the answer somewhere, but I can no longer find it. If I have a loop that is supposed to generate a vector piecemeal, adding an element each time through the loop, what do I do to stop it failing the first time around the loop, when the vector doesn't yet exist (so I can't use the append() function)? You can create an empty vector to start. Exactly how depends on what you're putting in it, but something like numeric(0) or list() should do what you want. Of course, this is a very slow way to build results: your code will run much faster if you allocate all the space you need at the beginning, and just fill in the values as you go, e.g. x - numeric(100) i - 0 while (more stuff) { i - i+1 x[i] - stuff } Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Q: appending to non-existent vector?
On 9/21/07, Duncan Murdoch [EMAIL PROTECTED] wrote: On 9/21/2007 1:15 PM, D. R. Evans wrote: This is a real newbie question. What makes it worse is that I know I've seen the answer somewhere, but I can no longer find it. If I have a loop that is supposed to generate a vector piecemeal, adding an element each time through the loop, what do I do to stop it failing the first time around the loop, when the vector doesn't yet exist (so I can't use the append() function)? You can create an empty vector to start. Exactly how depends on what you're putting in it, but something like numeric(0) or list() should do what you want. Of course, this is a very slow way to build results: your code will run much faster if you allocate all the space you need at the beginning, and just fill in the values as you go, e.g. x - numeric(100) i - 0 while (more stuff) { i - i+1 x[i] - stuff } Or if you wanted to be really fancy: while (more stuff) { i - i+1 if (i length(x)) length(x) - 2 * length(x) x[i] - stuff } which should be O(log n). Hadley __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Likelihood ration test on glm
On Fri, 21 Sep 2007, Wensui Liu wrote: chris, as long as you know the log likelihood functions and the # of parameters in both models, a pencil and a piece of paper should be enough to calculate LR test. True enough for the LR statistic. Or follow the instructions in the _posting guide_ and try RSiteSearch(glm likelihood) and page thru the results looking for entries like this one: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/76603.html Chuck On 9/21/07, Chris Elsaesser [EMAIL PROTECTED] wrote: I would like to try a likelihood ratio test in place of waldtest. Ideally I'd like to provide two glm models, the second a submodel of the first, in the style of lrt (http://www.pik-potsdam.de/~hrust/tools/farismahelp/lrt.html). [lrt takes farimsa objects] Does anyone know of such a likelihood ratio test? Chris Elsaesser, PhD Principal Scientist, Machine Learning SPADAC Inc. 7921 Jones Branch Dr. Suite 600 McLean, VA 22102 703.371.7301 (m) 703.637.9421 (o) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- === I am dying with the help of too many physicians. - Alexander the Great, on his deathbed === WenSui Liu (http://spaces.msn.com/statcompute/blog) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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:[EMAIL PROTECTED] 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] Is it solve.QP or is it me?
G'day Talbot, regarding the subject line, perhaps neither, it may be your OS, chip or maths library. :) On my Intel Core2 Duo machine running under linux all your examples work without error message. What kind of machine are you using? On Fri, 21 Sep 2007 12:38:05 -0400 Talbot Katz [EMAIL PROTECTED] wrote: [..] I was wondering whether anyone has any tricks to share for mitigating these kind of problems and still generating feasible solutions. I believe that one of the recommendations in the numerical literature is to try to keep the norms of the columns of the matrix A on similar scales. Try to divide the first two columns of A (and the first two entries in the vector b) by the square root of n. Hope that helps. Cheers, Berwin === Full address = Berwin A TurlachTel.: +65 6515 4416 (secr) Dept of Statistics and Applied Probability+65 6515 6650 (self) Faculty of Science FAX : +65 6872 3919 National University of Singapore 6 Science Drive 2, Blk S16, Level 7 e-mail: [EMAIL PROTECTED] Singapore 117546http://www.stat.nus.edu.sg/~statba __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] truncating a data frame based on a function
On Fri, 21 Sep 2007, Greg Snow wrote: Look at the subset function (?subset), it may do what you want. This looks useful. Thanks. However, how can I write an expression selecting certain rows (subset argument) in the case of a matrix? when it does not have named columns? The documentation does not have examples of this. Faheem. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] really dumb question | loop counters in
Thanks. And thanks for the C-style tip. Greg Snow wrote: Try: for(x in seq(0,1,by=0.01)) { print(x) } The for loop in S/R is what some languages call a foreach loop, you need to provide a vector of the values to loop over. If you really want a C style for loop, then just realize that the for loop is a shorthand while loop: x - 0 while( x 1 ) { print(x) x - x + 0.01 } Hope this helps, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] duplicated names and values
Dear list, I am sorry about this simple question, but somehow I can not figure out how to solve my problem, may be you could help? I have a vector mir3: length(mir3) [1] 220671 head(mir3) rno-miR-30c rno-miR-30c rno-miR-30d rno-miR-30e ENSRNOT0049288ENSRNOT0049288 ENSRNOT0049288ENSRNOT0049288 rno-miR-145 rno-miR-145 rno-miR-379 ENSRNOT0049288 ENSRNOT0049288 ENSRNOT0061859 The names there (such as rno-miR-30c,rno-miR-30d...) can be duplicated, as well as the values (e.g ENSRNOT0049288) I need the vector were unique names have always different values. That is, all entries like: rno-miR-30c rno-miR-30c ENSRNOT0049288ENSRNOT0049288 I have to change into single entry: rno-miR-30c ENSRNOT0049288 .. Thank you! Best regards Galina [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] duplicated names and values
Galina, It is not clear to me. Are the names and the values always the same or are there different values for some of the names Example same name same value A B B C B A 3 2 2 1 2 3 or same names but different values A B B C B A 3 2 1 1 2 3 --- Glazko, Galina [EMAIL PROTECTED] wrote: Dear list, I am sorry about this simple question, but somehow I can not figure out how to solve my problem, may be you could help? I have a vector mir3: length(mir3) [1] 220671 head(mir3) rno-miR-30c rno-miR-30c rno-miR-30d rno-miR-30e ENSRNOT0049288 ENSRNOT0049288 ENSRNOT0049288ENSRNOT0049288 rno-miR-145 rno-miR-145 rno-miR-379 ENSRNOT0049288 ENSRNOT0049288 ENSRNOT0061859 The names there (such as rno-miR-30c,rno-miR-30d...) can be duplicated, as well as the values (e.g ENSRNOT0049288) I need the vector were unique names have always different values. That is, all entries like: rno-miR-30c rno-miR-30c ENSRNOT0049288ENSRNOT0049288 I have to change into single entry: rno-miR-30c ENSRNOT0049288 .. Thank you! Best regards Galina [[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] Adding a table to a plot area
Is there a command to insert a table into the plot area other that using text? Thank you. Luggage? GPS? Comic books? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 101 : lm with/without intercept
On 21/09/2007 4:47 PM, Yves Moisan wrote: I am puzzled at the use of regression. I have a categorical variable ClassePop33000 which factors a Population variable into 3 levels. I want to investigate whether that categorical variable has some relation with my dependent variable, so I go : lm(Cout.ton ~ ClassePop33000, data=ech2) Call: lm(formula = Cout.ton ~ ClassePop33000, data = ech2) Residuals: Min 1Q Median 3Q Max -182.24 -62.91 -22.76 66.38 277.39 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 231.66 11.50 20.141 2e-16 *** ClassePop33000[T.[3000,25000)] -72.91 16.70 -4.366 2.19e-05 *** ClassePop33000[T.[25000,1000)] -95.17 19.92 -4.777 3.82e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 97.6 on 170 degrees of freedom Multiple R-Squared: 0.1502, Adjusted R-squared: 0.1402 F-statistic: 15.02 on 2 and 170 DF, p-value: 9.818e-07 Now I discovered one could omit the intercept and therefore have coefficients for the N levels of the categorical variable. So I went : lm(Cout.ton ~ ClassePop33000 + 0, data=ech2) Call: lm(formula = Cout.ton ~ ClassePop33000 + 0, data = ech2) Residuals: Min 1Q Median 3Q Max -182.24 -62.91 -22.76 66.38 277.39 Coefficients: Estimate Std. Error t value Pr(|t|) ClassePop33000[1,3000) 231.66 11.50 20.141 2e-16 *** ClassePop33000[3000,25000) 158.75 12.11 13.114 2e-16 *** ClassePop33000[25000,1000) 136.49 16.27 8.391 1.8e-14 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 97.6 on 170 degrees of freedom Multiple R-Squared: 0.7922, Adjusted R-squared: 0.7885 F-statistic: 216 on 3 and 170 DF, p-value: 2.2e-16 I tried the very pedagogical examples at http://www.stat.umn.edu/geyer/5102/examp/dummy.html and plotting the regression lines with abline gives me the exact same lines whether I use with or without intercept. Now why do R squared differ then ? At least the p-values are of the same order of magnitude, but I don't understand the drastic difference in R squared. Pointers to stats 101 anyone ? The standard definition of R-squared assumes there's an intercept present. If you suppress it, you need to come up with a new definition. So those values aren't comparable. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] duplicated names and values
I was afraid of that. I am a newbie at R and while there probably is some easy way to do this I don't see it This example will, at least, show you a way to get the actual duplicate names. However I don't see any easy way without all kinds of subsetting to get what you need. nas - c(A, B , B ,C ,B, A ) nums - c(3, 2, 1, 1, 2, 3) names(nums) - nas nums dups - duplicated(names(nums)) mydata - data.frame(nas , nums, dups) mydups - unique(subset(mydata[,1], mydata$dups==TRUE)) --- Glazko, Galina [EMAIL PROTECTED] wrote: John, one name can have multiple values, and different names can have the same single value, I only need to eliminate cases when the same names have same values... unique gives me really 'unique' set, whithout duplicates thank you! best regards Galina From: John Kane [mailto:[EMAIL PROTECTED] Sent: Fri 9/21/2007 4:34 PM To: Glazko, Galina; [EMAIL PROTECTED] Subject: Re: [R] duplicated names and values Galina, It is not clear to me. Are the names and the values always the same or are there different values for some of the names Example same name same value A B B C B A 3 2 2 1 2 3 or same names but different values A B B C B A 3 2 1 1 2 3 --- Glazko, Galina [EMAIL PROTECTED] wrote: Dear list, I am sorry about this simple question, but somehow I can not figure out how to solve my problem, may be you could help? I have a vector mir3: length(mir3) [1] 220671 head(mir3) rno-miR-30c rno-miR-30c rno-miR-30d rno-miR-30e ENSRNOT0049288 ENSRNOT0049288 ENSRNOT0049288ENSRNOT0049288 rno-miR-145 rno-miR-145 rno-miR-379 ENSRNOT0049288 ENSRNOT0049288 ENSRNOT0061859 The names there (such as rno-miR-30c,rno-miR-30d...) can be duplicated, as well as the values (e.g ENSRNOT0049288) I need the vector were unique names have always different values. That is, all entries like: rno-miR-30c rno-miR-30c ENSRNOT0049288ENSRNOT0049288 I have to change into single entry: rno-miR-30c ENSRNOT0049288 .. Thank you! Best regards Galina [[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. Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new http://mrd.mail.yahoo.com/try_beta?.intl=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.