Re: [R] strange behavior of names<-
Remember tapply with a single factor in R returns a 1D array. What you are seeing are the dimnames, not the names: look at attributes() on your return value (or even name() or str() on it). I suspect you intended an as.vector() call in the formation of m. Brian On Sun, 9 May 2004, Liaw, Andy wrote: > I've encounter what seems to me a strange problem with "names<-". Suppose I > define the function: > > fun <- function(x, f) { > m <- tapply(x, f, mean) > ans <- x - m[match(f, unique(f))] > names(ans) <- names(x) > ans > } > > which subtract out the means of `x' grouped by `f' (which is the same as, > e.g., resid(lm(x~f)) if `f' is a factor). If `x' does not have names, then > I'd expect the output of the function not to have names, as names(x) would > be NULL, and assigning NULL to names(ans) should wipe out the names of > `ans'. However, I get: > > > x = rnorm(20) > > f = factor(sample(rep(letters[1:4], 5))) > > fun(x, f) > a b c b c c > d > -0.53791639 1.03704065 0.95727411 0.89219177 -0.04218746 0.57976675 > -2.15799919 > a c d a d b > d > 1.28422452 -0.92881186 0.40526262 -0.13471983 -0.72599709 1.68726680 > -0.95420354 > a c a b b d > -2.28013373 1.02522037 0.07728352 0.54321899 0.95742354 -1.68420455 > > What am I missing? -- 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 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] strange behavior of names<-
Execute these two commands: ans <- fun(x,f) attributes(ans) and you get this: $dim [1] 20 $dimnames $dimnames[[1]] [1] "a" "a" "b" "c" "a" "d" "a" "b" "d" "d" "a" "b" "d" "c" "c" "c" "b" "c" "b" [20] "d" so ans does not have names, it has dimnames. If you try dimnames(ans) <- NULL then its dimnames do get nulled out. Liaw, Andy merck.com> writes: : : Dear R-help, : : I've encounter what seems to me a strange problem with "names<-". Suppose I : define the function: : : fun <- function(x, f) { : m <- tapply(x, f, mean) : ans <- x - m[match(f, unique(f))] : names(ans) <- names(x) : ans : } : : which subtract out the means of `x' grouped by `f' (which is the same as, : e.g., resid(lm(x~f)) if `f' is a factor). If `x' does not have names, then : I'd expect the output of the function not to have names, as names(x) would : be NULL, and assigning NULL to names(ans) should wipe out the names of : `ans'. However, I get: : : > x = rnorm(20) : > f = factor(sample(rep(letters[1:4], 5))) : > fun(x, f) : a b c b c c : d : -0.53791639 1.03704065 0.95727411 0.89219177 -0.04218746 0.57976675 : -2.15799919 : a c d a d b : d : 1.28422452 -0.92881186 0.40526262 -0.13471983 -0.72599709 1.68726680 : -0.95420354 : a c a b b d : -2.28013373 1.02522037 0.07728352 0.54321899 0.95742354 -1.68420455 : : What am I missing? : : [BTW, this is using the tip that Thomas Lumley posted about forming the : group means. I've wanted to write a `tsweep' function that's sort of the : cross of tapply() and sweep().] : : Best, : Andy Liaw, PhD : Biometrics Research PO Box 2000, RY33-300 : Merck Research Labs Rahway, NJ 07065 : mailto:andy_liaw merck.com732-594-0820 : : __ : R-help stat.math.ethz.ch mailing list : https://www.stat.math.ethz.ch/mailman/listinfo/r-help : PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html : : __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Modalwert
It was a proxy settings problem. All fixed now. Sorry to disturb the list. Murray Jorgensen Murray Jorgensen wrote: Off-topic, I know, but when I try to follow secure links like this in Mozilla, I always get a message "The connection was refused when trying to contact www.stat.math.ethz.ch" and I am forced to use Internet Explorer instead. This is under Windows XP. Is this because www.stat.math.ethz.ch is using some non-standard Microsoft extensions of html? Or is it because my Mozilla 1.6 browser is wrongly configured? Why are the mail archives on secure pages anyway? Murray Jorgensen Thomas Petzoldt wrote: Sonja Dornieden wrote: Hai - kann mir jemand sagen, wie ich den Modalwert in R berechne?! IRgendwie finde ich den Befehl nicht greetz und herzlichen Dank Sonja Hi, there was already a thread in this list about this question with subject "Computing the mode" on 24.02.2004. You will find several answers in the R-Help archive: https://www.stat.math.ethz.ch/pipermail/r-help/2004-February/ Thomas P. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: [EMAIL PROTECTED]Fax 7 838 4155 Phone +64 7 838 4773 wk+64 7 849 6486 homeMobile 021 1395 862 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Colouring hclust() trees
I have a data set with 6 variables and 251 cases. The people who supplied me with this data set believe that it falls naturally into three groups, and have given me a rule for determining group number from these 6 variables. If I do scaled.stuff <- scale(stuff, TRUE, c(...the design ranges...)) stuff.dist <- dist(scaled.stuff) stuff.hc <- hclust(stuff.dist) plot(stuff.hc) I get a dendrogram which looks sort of plausible, but (a) with this many leaves, the leaf labels really aren't legible at any plausible scaling, and would be best omitted. I could figure out which point was which if there were some way to use identify(), but I'm justnot seeing it. (b) what I'd really like to do is to colour the leaves according to the predicted group, or some other variable. The obvious thing to try is plot(stuff.hc, col=c("red","green","blue")[stuff.predicted.group]) but that doesn't work. I read everything that seemed plausible, and came across nodePar, but col <- c("red","green","blue")[stuff.predicted.group] plot(stuff.hc, nodePar=list(col=list("black",col))) tells me repeatedly that parameter "nodePar" couldn't be set in high-level plot() function while plot(as.dendrogram(hc), nodePar=list(col=list("black",col))) draws the dendrogram (_much_ slower than plot() does) and still gives me no colouring at all. Clearly I have misunderstood how to use nodePar. (c) The obvious fall-back is to use points() to draw the nodes again in the colours I want, but if I could do that, I could use identify(). The frustrating thing is that when I do d <- dim(stuff))[1] plot(1:d, 1:d, col=col[stuff.hc$order]) shows me that there _is_ a strong connection between the groups found by hclust() and the predicted groups, albeit not a simple one. I have looked at plot.dendrogram() and plotNode() -- using getAnywhere() -- and it looks to me as though what I want *should* be doable, but I've clearly misunderstood the details of how to do it. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] strange behavior of names<-
Dear R-help, I've encounter what seems to me a strange problem with "names<-". Suppose I define the function: fun <- function(x, f) { m <- tapply(x, f, mean) ans <- x - m[match(f, unique(f))] names(ans) <- names(x) ans } which subtract out the means of `x' grouped by `f' (which is the same as, e.g., resid(lm(x~f)) if `f' is a factor). If `x' does not have names, then I'd expect the output of the function not to have names, as names(x) would be NULL, and assigning NULL to names(ans) should wipe out the names of `ans'. However, I get: > x = rnorm(20) > f = factor(sample(rep(letters[1:4], 5))) > fun(x, f) a b c b c c d -0.53791639 1.03704065 0.95727411 0.89219177 -0.04218746 0.57976675 -2.15799919 a c d a d b d 1.28422452 -0.92881186 0.40526262 -0.13471983 -0.72599709 1.68726680 -0.95420354 a c a b b d -2.28013373 1.02522037 0.07728352 0.54321899 0.95742354 -1.68420455 What am I missing? [BTW, this is using the tip that Thomas Lumley posted about forming the group means. I've wanted to write a `tsweep' function that's sort of the cross of tapply() and sweep().] Best, Andy Liaw, PhD Biometrics Research PO Box 2000, RY33-300 Merck Research Labs Rahway, NJ 07065 mailto:[EMAIL PROTECTED]732-594-0820 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Modalwert
Off-topic, I know, but when I try to follow secure links like this in Mozilla, I always get a message "The connection was refused when trying to contact www.stat.math.ethz.ch" and I am forced to use Internet Explorer instead. This is under Windows XP. Is this because www.stat.math.ethz.ch is using some non-standard Microsoft extensions of html? Or is it because my Mozilla 1.6 browser is wrongly configured? Why are the mail archives on secure pages anyway? Murray Jorgensen Thomas Petzoldt wrote: Sonja Dornieden wrote: Hai - kann mir jemand sagen, wie ich den Modalwert in R berechne?! IRgendwie finde ich den Befehl nicht greetz und herzlichen Dank Sonja Hi, there was already a thread in this list about this question with subject "Computing the mode" on 24.02.2004. You will find several answers in the R-Help archive: https://www.stat.math.ethz.ch/pipermail/r-help/2004-February/ Thomas P. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: [EMAIL PROTECTED]Fax 7 838 4155 Phone +64 7 838 4773 wk+64 7 849 6486 homeMobile 021 1395 862 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Getting the groupmean for each person
On Sat, 8 May 2004, Gabor Grothendieck wrote: > > predict(lm(AV~as.factor(GROUP))) If Felix actually has a "huge" data frame this will be slow. Instead try groupmeans<-rowsum(AV,GROUP,reorder=FALSE) individual.means<- groupmeans[match(GROUP, unique(GROUP)] It uses hashing and takes roughly O(MGlogG) time for M measurements on G groups, whereas the lm solution takes O(MG^3) [and the space requirements are O(MG) and O(MG^2)] Admittedly, with only 3000 observations either one will be fast enough. -thomas > > > > Felix Eschenburg t-online.de> writes: > > : > : Hello list ! > : > : I have a huge data.frame with several variables observed on about 3000 > : persons. For every person (row) there is variable called GROUP which indices > : the group the person belongs to. There is also another variable AV for each > : person. Now i want to create a new variable which holds the group mean of AV > : as a value for each person. > : With tapply(AV,GROUP,mean) i get the means for each level of GROUP, but i > : cannot find out, how to give every person the groupmean as a value (every > : person should have the same value as every other person in the same group). > : > : Has anybody any ideas how to do that ? > : > : Yours sincerly > : Felix Eschenburg > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Using known errors and error bars
What do you actually know? You don't have `known errors', as if you did you could correct the values. I doubt if you actually have a known range, more likely a standard error or a confidence interval. (If you think you do have a known range, how do you know?) And if A is not known exactly, linear regression is not fully appropriate. If you know standard errors, then you need a homoscedastic errors-in-variables formulation. One early account is Ripley, B. D. and Thompson, M.(1987) Regression techniques for the detection of analytical bias. Analyst 112, 177-183. and its Fortran program is still available, and although I have never coded it in R, I believe others have. On Sun, 9 May 2004, Sebastian Schubert wrote: > I'm now to R and hope (actually, I'm quite sure) you can help me. I made > an experiment and measured two values. As I know the errors of these > values I want to use them with the linear regression, > eg > Value A > 1.1+-0.02 > 1.9+-0.05 > 3.05+-0.03 > 4.0+-0.01 > 5.1+-0.06 > > Value B > 4.2+-0.14 > 5.3+-0.05 > 6.8+-0.11 > 7.9+-0.01 > 8.5+-0.02 > > lm(B~A) does the linear regression but how can I use the fact that 1.1 is > between 1.12 and 1.08? > How can I put error bars for A and B in the plot (like Excel is capable > of)? Many ways, for example using arrows() or plotCI in package gregmisc. > I hope I made myself understandable, > thanks > Sebastian -- 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 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Using known errors and error bars
See plotCI in package gregmisc. Sebastian Schubert gmx.de> writes: : : Hi, : : I'm now to R and hope (actually, I'm quite sure) you can help me. I made : an experiment and measured two values. As I know the errors of these : values I want to use them with the linear regression, : eg : Value A : 1.1+-0.02 : 1.9+-0.05 : 3.05+-0.03 : 4.0+-0.01 : 5.1+-0.06 : : Value B : 4.2+-0.14 : 5.3+-0.05 : 6.8+-0.11 : 7.9+-0.01 : 8.5+-0.02 : : lm(B~A) does the linear regression but how can I use the fact that 1.1 is : between 1.12 and 1.08? : How can I put error bars for A and B in the plot (like Excel is capable : of)? : : I hope I made myself understandable, : thanks : Sebastian : : -- : : __ : R-help stat.math.ethz.ch mailing list : https://www.stat.math.ethz.ch/mailman/listinfo/r-help : PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html : : __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Modalwert
Sonja Dornieden wrote: Hai - kann mir jemand sagen, wie ich den Modalwert in R berechne?! IRgendwie finde ich den Befehl nicht greetz und herzlichen Dank Sonja Hi, there was already a thread in this list about this question with subject "Computing the mode" on 24.02.2004. You will find several answers in the R-Help archive: https://www.stat.math.ethz.ch/pipermail/r-help/2004-February/ Thomas P. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Using known errors and error bars
Hi, I'm now to R and hope (actually, I'm quite sure) you can help me. I made an experiment and measured two values. As I know the errors of these values I want to use them with the linear regression, eg Value A 1.1+-0.02 1.9+-0.05 3.05+-0.03 4.0+-0.01 5.1+-0.06 Value B 4.2+-0.14 5.3+-0.05 6.8+-0.11 7.9+-0.01 8.5+-0.02 lm(B~A) does the linear regression but how can I use the fact that 1.1 is between 1.12 and 1.08? How can I put error bars for A and B in the plot (like Excel is capable of)? I hope I made myself understandable, thanks Sebastian -- __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Creating and editing networks
Or graph, RBGL and Rgraphviz from www.bioconductor.org On Sun, May 09, 2004 at 02:35:02PM +0200, Uwe Ligges wrote: > Gabor Grothendieck wrote: > > I want to draw and edit networks. Currently I will do something like this -- > > my actual networks are larger and more complex: > > > > 1. Plot network > > > > # use polygon with nodes as example network > > N <- 20 > > t. <- 2*pi*seq(N+1)/N > > plot(cos(t.), sin(t.), type="b", pch=19, cex=5, col="blue", axes=F, ann=F) > > > > 2. copy and paste the graphic as a metafile into Word. > > > > 3. edit the network > > there. The editing typically just involves moving nodes and the attached > > edges. Of course, Word does not know the edges are attached to the nodes so I > > have to move the nodes and then move the attached edges, as well. > > > > The networks are too complex to create the diagrams by hand which is why > > I want to create them in R and then edit them by hand. > > > > The above strategy is marginally acceptable but > > I was wondering if anyone had a better strategy which retains the > > simplicity of the present approach but gives me the capability to > > have the edges move along with attached nodes when editing them. > > > > (Note that the strategy must consist of generating the network under program > > control, preferably in R, and then editing it afterwards. I am not looking > > to create the entire network by hand since the networks are too complex for > > that. I had tried specifying the networks in dot from Bell Labs but 1. its > > still more work than generating the network in R 2. the automatic > > layout it chooses is so far from what I need that its a lot of work to > > fix it up by hand in dotty and 3. I could never get them to look just how > > I like. I have also tried Excel and Powerpoint, both > > of which support connectors, which are edges that move along with attached > > nodes, but to use them I have to create the entire network by hand and > > the networks have grown too complex to do that.) > > > > __ > > [EMAIL PROTECTED] mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > Have you tried the CRAN package "dynamicGraph" by Jens Henrik Badsberg? > > Uwe Ligges > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- +---+ | Robert Gentleman phone : (617) 632-5250 | | Associate Professor fax: (617) 632-2444 | | Department of Biostatistics office: M1B20| | Harvard School of Public Health email: [EMAIL PROTECTED]| +---+ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Creating and editing networks
Gabor Grothendieck wrote: I want to draw and edit networks. Currently I will do something like this -- my actual networks are larger and more complex: 1. Plot network # use polygon with nodes as example network N <- 20 t. <- 2*pi*seq(N+1)/N plot(cos(t.), sin(t.), type="b", pch=19, cex=5, col="blue", axes=F, ann=F) 2. copy and paste the graphic as a metafile into Word. 3. edit the network there. The editing typically just involves moving nodes and the attached edges. Of course, Word does not know the edges are attached to the nodes so I have to move the nodes and then move the attached edges, as well. The networks are too complex to create the diagrams by hand which is why I want to create them in R and then edit them by hand. The above strategy is marginally acceptable but I was wondering if anyone had a better strategy which retains the simplicity of the present approach but gives me the capability to have the edges move along with attached nodes when editing them. (Note that the strategy must consist of generating the network under program control, preferably in R, and then editing it afterwards. I am not looking to create the entire network by hand since the networks are too complex for that. I had tried specifying the networks in dot from Bell Labs but 1. its still more work than generating the network in R 2. the automatic layout it chooses is so far from what I need that its a lot of work to fix it up by hand in dotty and 3. I could never get them to look just how I like. I have also tried Excel and Powerpoint, both of which support connectors, which are edges that move along with attached nodes, but to use them I have to create the entire network by hand and the networks have grown too complex to do that.) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Have you tried the CRAN package "dynamicGraph" by Jens Henrik Badsberg? Uwe Ligges __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Creating and editing networks
I want to draw and edit networks. Currently I will do something like this -- my actual networks are larger and more complex: 1. Plot network # use polygon with nodes as example network N <- 20 t. <- 2*pi*seq(N+1)/N plot(cos(t.), sin(t.), type="b", pch=19, cex=5, col="blue", axes=F, ann=F) 2. copy and paste the graphic as a metafile into Word. 3. edit the network there. The editing typically just involves moving nodes and the attached edges. Of course, Word does not know the edges are attached to the nodes so I have to move the nodes and then move the attached edges, as well. The networks are too complex to create the diagrams by hand which is why I want to create them in R and then edit them by hand. The above strategy is marginally acceptable but I was wondering if anyone had a better strategy which retains the simplicity of the present approach but gives me the capability to have the edges move along with attached nodes when editing them. (Note that the strategy must consist of generating the network under program control, preferably in R, and then editing it afterwards. I am not looking to create the entire network by hand since the networks are too complex for that. I had tried specifying the networks in dot from Bell Labs but 1. its still more work than generating the network in R 2. the automatic layout it chooses is so far from what I need that its a lot of work to fix it up by hand in dotty and 3. I could never get them to look just how I like. I have also tried Excel and Powerpoint, both of which support connectors, which are edges that move along with attached nodes, but to use them I have to create the entire network by hand and the networks have grown too complex to do that.) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html