[R] plotting least-squares residuals against x-axis
Hi, I want to plot the residuals of a least-squares regression. plot(lm(y~x), which=1) does this, but it plots the y-axis of my data on the x-axis of the residuals plot. That is, it plots the residual for each y-value in the data. Can I instead use the x-axis of my data as the x-axis of the residuals plot, showing the residual for a given x? Thanks! Jason Priem University of North Carolina at Chapel Hill School of Information and Library Science __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Lattice: combine the same strip?
Hello R helpers, I am producing a figure with dual strips, i.e., x~y | S1 + S2, where S1 and S2 are two strips. For example, in figure 2.1 at http://lmdvr.r-forge.r-project.org/figures/figures.html. In this case, I would like to combine the the top strip, since all three pictures in the same row have the same level based on the first strip. In other words, instead of | -- S11 -- | -- S11 -- | -- S11 -- | | -- S21 -- | -- S22 -- | -- S23 -- | I would like my graph to look like | - S11 | | -- S21 -- | -- S22 -- | -- S23 -- | In there a way I can do it? Thanks! JD [[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] random selection from dataset and creating and graphing multiple means
I was wondering if anyone could help me with a problem. I need to randomly select, say 500 subjects from the 5000 cases I have and then need to run a test to create 500 sample means and graph the means in a histogram. Does anyone know how to do this. I'm not that familiar with R so please be patient with me. Thanks a lot! Mike Hollingsworth -- View this message in context: http://www.nabble.com/random-selection-from-dataset-and-creating-and-graphing-multiple-means-tp2552p2552.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 add tables of different dimensions
Hi all! I'm stuck with this easy problem. I have two tables (a and b) which i would like to add. table a looks like: a var1 var2 3 4 and table b looks like: b var1 10 I would like this result: c- a+b c var1 var2 134 Best regards Henrik Källberg __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] random selection from dataset and creating and graphing multiple means
Mike I split the answer into three parts: A. Random sampling To random select 500 from 5000, you can use: data5000 = rnorm(5000,200,10) # make some data s = sample(data5000,500) head(s) [1] 201.7548 167.5157 106.1064 194.6629 165.9758 187.1152 B. Repeated Random Sampling Its not clear with what you mean by creating 500 sample means, but if you meant (1) draw 500 samples from 5000 and (2) repeat step (1) 500 times, calculating the mean every time then you can do it like so means500 - replicate(500,mean(sample(data5000,500))) head(means500) [1] 200.9172 197.4371 199.9544 202.2562 197.8169 199.3558 C. Draw the histogram Drawing a histogram of means500 is achieved using the hist function hist(means500) HTH Schalk Heunis On Sat, Sep 19, 2009 at 11:24 PM, MikeH78 holli...@crimson.ua.edu wrote: I was wondering if anyone could help me with a problem. I need to randomly select, say 500 subjects from the 5000 cases I have and then need to run a test to create 500 sample means and graph the means in a histogram. Does anyone know how to do this. I'm not that familiar with R so please be patient with me. Thanks a lot! Mike Hollingsworth -- View this message in context: http://www.nabble.com/random-selection-from-dataset-and-creating-and-graphing-multiple-means-tp2552p2552.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. [[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] plotting least-squares residuals against x-axis
Jason Try this Residuals = residuals(lm(y~x)) plot(x,Residuals) Schalk Heunis On Sun, Sep 20, 2009 at 1:36 AM, Jason Priem ja...@jasonpriem.com wrote: Hi, I want to plot the residuals of a least-squares regression. plot(lm(y~x), which=1) does this, but it plots the y-axis of my data on the x-axis of the residuals plot. That is, it plots the residual for each y-value in the data. Can I instead use the x-axis of my data as the x-axis of the residuals plot, showing the residual for a given x? Thanks! Jason Priem University of North Carolina at Chapel Hill School of Information and Library Science __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Lattice: combine the same strip?
Hi, Not exactly answering your question, but latticeExtra provides a function useOuterStrips that you could use to have a single S11 strip on the left instead. HTH, baptiste 2009/9/20 di jianing jianin...@gmail.com: Hello R helpers, I am producing a figure with dual strips, i.e., x~y | S1 + S2, where S1 and S2 are two strips. For example, in figure 2.1 at http://lmdvr.r-forge.r-project.org/figures/figures.html. In this case, I would like to combine the the top strip, since all three pictures in the same row have the same level based on the first strip. In other words, instead of | -- S11 -- | -- S11 -- | -- S11 -- | | -- S21 -- | -- S22 -- | -- S23 -- | I would like my graph to look like | - S11 | | -- S21 -- | -- S22 -- | -- S23 -- | In there a way I can do it? Thanks! JD [[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] Quadratic Constraints
HI All, I am unable to solve a optimization Problem Please Help Me out of this to solve. The Optimization problem is as follows :- My objective function is linear and one of the constraint is quadratic. Min z = 5 * X1 + 9* X2 + 7.15 *X3 + 2 * X4 subject to X1 + X2 + X3 +X4 = 9 X1 + X4 = 6.55 X3(X3 - 3.5) =0 X1,X2,X3,X4 =0 Now the problem is how to solve this kind of problem. Which package should be used to handle such problems. Please explain with an example. Another problem is that I have to cases to be solve in this problem. case 1:-) If X3 = 0 case 2 :-) If X3 0 then X3 3.6 I want to handle both this case in one problem so the quadratic constraints is written The thing is that I want to evaluate my objective function for both cases and which ever is optimum that solution i need, Here I don't want to use the If Else condition and repeat the program. IS there any other better way in which i could solve this problem? If not please try to provide me the solution for my original problem having a quadratic constraint. -- View this message in context: http://www.nabble.com/Quadratic-Constraints-tp25528480p25528480.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] Regarding KS Test for Goodness-of-Fit
Manuj Your approach in (2) would work, looking at the source (just type ks.test) your function will be called with a sorted vector of data values, i.e. HED(sort(x), ...) where x is a a numeric vector of data values and ... is the parameters as passed to ks.test This means your function needs to be able to handle a vector of inputs. Look at sapply if this is an issue. HTH Schalk Heunis On Sun, Sep 20, 2009 at 4:21 AM, Manuj Sharma smanuj1...@yahoo.in wrote: I have fitted Hyperexponential distribution (HED) and Hypoexponential distribution (HoED) to two different data sets (of size 1000 numeric values each) using a software package called EMpht. I want to use R to perform goodness-of-fit test for the fitted distribution with respect to the empirical CDFs of the data sets using KS test (Kolmogorov-Smirnov test). ks.test() function in R takes the first argument as the data set, and the second argument as the name of the distribution, followed by the distribution parameter values. In case of the CDFs that are already supported by R, this is simple (for example: ks.test(data_set, pnorm, mean, sd)). 1. Can somebody please suggest whether R has in-built support for Hyperexponential and Hypoexponential CDFs (they do not appear in the list of distribution given in An Introduction to R))? 2. If I write an R function to compute HED (or HoED) CDF value, can I use that function name as second argument in ks.test()? For example, if I implement an R function named HED_CDF with parameters parameters..., will it be correct to use ks.test() as follows: ks.test(data_set, HED_CDF, parameters...) Will it give correct result? - Manuj Sharma From cricket scores to your friends. Try the Yahoo! India Homepage! http://in.yahoo.com/trynew [[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] axis: forcing last label to print
On 09/20/2009 02:12 PM, Shawn Polson wrote: Hello, I often use the axis command to add labels to axes with large numbers of consecutively numbered names: y- barplot (x, log=x) axis(1, at = y, labels = c(1:12345)) Since there are more labels than will fit in the space, the command only prints selected labels. This is what I want, except that it never actually prints a label for the final item. Thus I end up with labels something like this: 1 16 123 1432 2134 3235 6578 11385 when I really want the last label displayed to be the final category number (12345): 1 16 123 1432 2134 3235 6578 12345 Short of manually choosing the labels, does anyone know a way to force the last category to be among those printed when axis selects labels? Hi Shawn, You can get the first and last label with: axis(1,seq(1,12345,length.out=8) but you have to specify how many labels you want, and you will get non-integer labels unless the upper limit divides evenly. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Quadratic Constraints
The package lpSolve (that I have recommended before) supports so-called 'semi-continuous variables', that is Semi-continuous variables are variables that must take a value between their their minimum and maximum or zero. So these variables are treated the same as regular variables, except that a value of zero is also accepted, even if a minimum bigger than zero is set on the variable. which exactly how you want to handle your variable x3. For an example, see the documentation at lpsolve.sourceforge.net/5.5/. By the way, the minimum of your problem is 44.64 (manual calculation). vikrant S wrote: HI All, I am unable to solve a optimization Problem Please Help Me out of this to solve. The Optimization problem is as follows :- My objective function is linear and one of the constraint is quadratic. Min z = 5 * X1 + 9* X2 + 7.15 *X3 + 2 * X4 subject to X1 + X2 + X3 +X4 = 9 X1 + X4 = 6.55 X3(X3 - 3.5) =0 X1,X2,X3,X4 =0 Now the problem is how to solve this kind of problem. Which package should be used to handle such problems. Please explain with an example. Another problem is that I have to cases to be solve in this problem. case 1:-) If X3 = 0 case 2 :-) If X3 0 then X3 3.6 I want to handle both this case in one problem so the quadratic constraints is written The thing is that I want to evaluate my objective function for both cases and which ever is optimum that solution i need, Here I don't want to use the If Else condition and repeat the program. IS there any other better way in which i could solve this problem? If not please try to provide me the solution for my original problem having a quadratic constraint. -- View this message in context: http://www.nabble.com/Quadratic-Constraints-tp25528480p25529374.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] Plot factors with a loop
# I have a dataframe with a factor and data: a - rep(c(a, b), c(6,6)) df - data.frame(f=a, d=rnorm(12)) df # I want to make a single plot with boxplots of each factor. I need to do it via a loop as I would like to apply it to other dataframes with many factors. The following is a loop that produces a boxplot of the last factor, which overwrites the previous factor. for (i in levels(df$f)){ z - assign(as.character(i), as.vector(df[df$f==i,2], mode=numeric)) boxplot(z) } # How can I stop the first factor being overwritten so that two boxplots are displayed in the plot. The result I need is also produced by: boxplot(df[df$f==a,2], df[df$f==b,2]) # but I need it to be done through the loop. Thanks in advance! # Sam -- Sam Player, B.Sc.(Hons.) B.A. Ph.D. Candidate, Faculty of Agriculture, Food Natural Resources, University of Sydney Email: spla...@usyd.edu.au Agroecosystems Research Group Room 214 J.R.A. McMillan Building A05 University of Sydney NSW 2006, Australia Angkor Research Program Room 305 Old Teachers College A22 University of Sydney NSW 2006, Australia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plot factors with a loop
Why do you need to do this using loop? Is this what you want? a - rep(c(a, b, c), 6) df - data.frame(f=a, d=rnorm(18)) df boxplot(df$d ~ df$f) 2009/9/20 Sam Player samtpla...@gmail.com: # I have a dataframe with a factor and data: a - rep(c(a, b), c(6,6)) df - data.frame(f=a, d=rnorm(12)) df # I want to make a single plot with boxplots of each factor. I need to do it via a loop as I would like to apply it to other dataframes with many factors. The following is a loop that produces a boxplot of the last factor, which overwrites the previous factor. for (i in levels(df$f)){ z - assign(as.character(i), as.vector(df[df$f==i,2], mode=numeric)) boxplot(z) } # How can I stop the first factor being overwritten so that two boxplots are displayed in the plot. The result I need is also produced by: boxplot(df[df$f==a,2], df[df$f==b,2]) # but I need it to be done through the loop. Thanks in advance! # Sam -- Sam Player, B.Sc.(Hons.) B.A. Ph.D. Candidate, Faculty of Agriculture, Food Natural Resources, University of Sydney Email: spla...@usyd.edu.au Agroecosystems Research Group Room 214 J.R.A. McMillan Building A05 University of Sydney NSW 2006, Australia Angkor Research Program Room 305 Old Teachers College A22 University of Sydney NSW 2006, Australia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plot factors with a loop
Hi, From what I understand, I would suggest the following strategy, 1- combine all data in a single data.frame (see merge, rbind, reshape package, etc.) 2- plot all data at once using a formula like this, boxplot(d~f,data=df) HTH, baptiste 2009/9/20 Sam Player samtpla...@gmail.com: # I have a dataframe with a factor and data: a - rep(c(a, b), c(6,6)) df - data.frame(f=a, d=rnorm(12)) df # I want to make a single plot with boxplots of each factor. I need to do it via a loop as I would like to apply it to other dataframes with many factors. The following is a loop that produces a boxplot of the last factor, which overwrites the previous factor. for (i in levels(df$f)){ z - assign(as.character(i), as.vector(df[df$f==i,2], mode=numeric)) boxplot(z) } # How can I stop the first factor being overwritten so that two boxplots are displayed in the plot. The result I need is also produced by: boxplot(df[df$f==a,2], df[df$f==b,2]) # but I need it to be done through the loop. Thanks in advance! # Sam -- Sam Player, B.Sc.(Hons.) B.A. Ph.D. Candidate, Faculty of Agriculture, Food Natural Resources, University of Sydney Email: spla...@usyd.edu.au Agroecosystems Research Group Room 214 J.R.A. McMillan Building A05 University of Sydney NSW 2006, Australia Angkor Research Program Room 305 Old Teachers College A22 University of Sydney NSW 2006, Australia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] packGrob and dynamic resizing
Dear all, I'm trying to follow an old document to use Grid frames, Creating Tables of Text Using grid Paul Murrell July 9, 2003 As a minimal example, I wrote this, gf - grid.frame(layout = grid.layout(1, 1), draw = TRUE) label1 - textGrob(test, x = 0, just = left, name=test) gf=placeGrob(gf, rectGrob(), row = 1, col = 1) gf=packGrob(gf, label1, row = 1, col = 1) grid.draw(gf) grid.edit(test, label = longer text, grep=T) I'm a bit lost here, as I was expecting the frame to be automatically adjusted to fit the new text. Can anyone point me in the right direction? Best regards, 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] Truncated plot in the output file
Dear all, I made a large plot and wanted to save it as a tif file. I first opened and specified the size of the window. windows(12,17,rescale=fixed) Then I plot a heatmap using heatmap() when I saved the plot by using Save as in the file menu or savePlot(heatmap, type=tif), the plot in the output tif file is truncated. Only the upper part of the plot is shown. I did get a complete plot if I used savePlot(heatmap.tif) but the tif file then cannot be opened in Photoshop, saying it is not the right kind of document. Any ideas how I can solve the problem? Thanks in advance. Jimmy -- View this message in context: http://www.nabble.com/Truncated-plot-in-the-output-file-tp25529818p25529818.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] Truncated plot in the output file
On Sep 20, 2009, at 9:25 AM, J Chen wrote: Dear all, I made a large plot and wanted to save it as a tif file. I first opened and specified the size of the window. windows(12,17,rescale=fixed) Then I plot a heatmap using heatmap() when I saved the plot by using Save as in the file menu or savePlot(heatmap, type=tif), the plot in the output tif file is truncated. Only the upper part of the plot is shown. I did get a complete plot if I used savePlot(heatmap.tif) but the tif file then cannot be opened in Photoshop, saying it is not the right kind of document. Any ideas how I can solve the problem? ?tiff ?capabilities Use the tiff device and specify the size you want. I'm assuming that those units were in inches for your situation. Modified from the help page: tiff(file=myplot.tif, bg=transparent, width=12, height=17, units=in, res=150) plot(1:10); rect(1, 5, 3, 7, col=white) dev.off() (On my machine capabilities() tells me that I don't have a tiff device but experimentations suggests that information may not be entirely correct.) -- 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] axis: forcing last label to print
Thanks for the suggestion Jim, A good thought, but unfortunately this doesn't quite work either: -Since my example is log scale on that axis, the linearly spaced labels still become to numerous near the end forcing the last label not to print -Also, the labels don't print under the appropriate bars and since there are now fewer labels than bars using the at command doesn't work properly unless I specify a vector of locations which would essentially be manually placing the labels for each graph I have to make (which is what I was trying to get away from . . .) Thanks, Shawn Jim Lemon-2 wrote: On 09/20/2009 02:12 PM, Shawn Polson wrote: Hello, I often use the axis command to add labels to axes with large numbers of consecutively numbered names: y- barplot (x, log=x) axis(1, at = y, labels = c(1:12345)) Since there are more labels than will fit in the space, the command only prints selected labels. This is what I want, except that it never actually prints a label for the final item. Thus I end up with labels something like this: 1 16 123 1432 2134 3235 6578 11385 when I really want the last label displayed to be the final category number (12345): 1 16 123 1432 2134 3235 6578 12345 Short of manually choosing the labels, does anyone know a way to force the last category to be among those printed when axis selects labels? Hi Shawn, You can get the first and last label with: axis(1,seq(1,12345,length.out=8) but you have to specify how many labels you want, and you will get non-integer labels unless the upper limit divides evenly. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/axis%3A-forcing-last-label-to-print-tp25527633p25530067.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] Function output
Good afternoon, I know it is a simple question but I cannot figure out how to solve this issue. I have a function that calculate two objects. I would like to choose everytime about the tree object, with default to not show it. OP-function(S=100,X,sigma,mu=0,r=0,time=1,n) { value=(S) .. tree = matrix(rev(tree), byrow = FALSE, ncol = n + 1) return(value[1]) } Thanks -- View this message in context: http://www.nabble.com/Function-output-tp25530073p25530073.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] Function output
On Sep 20, 2009, at 10:59 AM, manta wrote: Good afternoon, I know it is a simple question but I cannot figure out how to solve this issue. I have a function that calculate two objects. I would like to choose everytime about the tree object, with default to not show it. I cannot understand that. Perhaps you can try again to tell us what you want to do with tree? OP-function(S=100,X,sigma,mu=0,r=0,time=1,n) { value=(S) .. tree = matrix(rev(tree), byrow = FALSE, ncol = n + 1) ... where did tree first get defined? return(value[1]) ... do you really want to return only value[1] _and_not_ tree? If you exit the function this way, tree will get lost. } 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] how to add tables of different dimensions
Try this: colSums(rbind(a, b[1:length(a)]), na.rm = TRUE) On Sat, Sep 19, 2009 at 8:30 PM, Henrik Kallberg henrik.kallb...@ki.se wrote: Hi all! I'm stuck with this easy problem. I have two tables (a and b) which i would like to add. table a looks like: a var1 var2 3 4 and table b looks like: b var1 10 I would like this result: c- a+b c var1 var2 13 4 Best regards Henrik Källberg __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 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] statistics
Ace2 wrote: The myoglobin sequence, with reference number NM_005368 in Gen bank, has the following frequencies of DNA nucleotides: ACGT 237 278 309 242 Do these data provide sufficient evidence, at the 1% level of significance, that the DNA nucleotides have an unequal distribution, that is the DNA nucleotides are not evenly utilised? Clearly state your hypothesis, test statistic and conclusion. Justify your conclusion and choice of test statistic. plz!!! Please note that the R-help list is not for homework problems. This looks like a homework problem. sincerely Ben Bolker -- View this message in context: http://www.nabble.com/statistics-tp25530074p25530076.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] Read time series
Hi R experts, How can I get a ts object from a data frame object which contains a daily time series in order to apply it time series functions? Tanks Aleto [[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] Function output
I think these examples will show what one can and cannot do with the invisible function. f2 - function(x,y) return(c(x, invisible(x^y)) ) f2(2,2) [1] 2 4 #so that not the right way to keep tree hidden f2 - function(x,y) invisible(c(print(x),(x^y)) ) f2(2,2) [1] 2 # success x^y is calculate but not made visible on return print(f2(2,2)) [1] 2 # that came from within the f2 function [1] 2 4# that is what the value returned by f2 On Sep 20, 2009, at 11:21 AM, David Winsemius wrote: On Sep 20, 2009, at 10:59 AM, manta wrote: Good afternoon, I know it is a simple question but I cannot figure out how to solve this issue. I have a function that calculate two objects. I would like to choose everytime about the tree object, with default to not show it. I cannot understand that. Perhaps you can try again to tell us what you want to do with tree? OP-function(S=100,X,sigma,mu=0,r=0,time=1,n) { value=(S) .. tree = matrix(rev(tree), byrow = FALSE, ncol = n + 1) ... where did tree first get defined? return(value[1]) ... do you really want to return only value[1] _and_not_ tree? If you exit the function this way, tree will get lost. } 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] Read time series
Please provide a minimal data object to clarify your question. In particular please read and follow the last line on every message to r-help and read the posting guide also mentioned there. On Sun, Sep 20, 2009 at 12:24 PM, Alexis Maluendas avmaluend...@gmail.com wrote: Hi R experts, How can I get a ts object from a data frame object which contains a daily time series in order to apply it time series functions? Tanks Aleto [[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] how to count occurrences of string?
Hi everyone, I have an array with a variable called comments. I wish to count the number of subjects whose post-experiment comments contain a string x and then cross tab this with other variables of interest, ex. age. Does anyone have any suggestions on how to count unique occurrences of a string embedded within a variable and cross-tab it with other variables? I've looked through the help files, etc. One method I tried was to use strsplit to split comments. I can use this with table to count the number of occurrences of x, but I can't cross tab this with other variables because comments is a ragged array after being split. Thanks in advance, Stephen -- View this message in context: http://www.nabble.com/how-to-count-occurrences-of-string--tp25530083p25530083.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] statistics
The myoglobin sequence, with reference number NM_005368 in Gen bank, has the following frequencies of DNA nucleotides: ACGT 237 278 309 242 Do these data provide sufficient evidence, at the 1% level of significance, that the DNA nucleotides have an unequal distribution, that is the DNA nucleotides are not evenly utilised? Clearly state your hypothesis, test statistic and conclusion. Justify your conclusion and choice of test statistic. plz!!! -- View this message in context: http://www.nabble.com/statistics-tp25530074p25530074.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] statistics
This is not a please solve my homework for me newsgroup. Hint: You may want to learn about chi-square tests. Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Anelle Gesendet: Sunday, September 20, 2009 11:07 AM An: r-help@r-project.org Betreff: [R] statistics The myoglobin sequence, with reference number NM_005368 in Gen bank, has the following frequencies of DNA nucleotides: ACGT 237 278 309 242 Do these data provide sufficient evidence, at the 1% level of significance, that the DNA nucleotides have an unequal distribution, that is the DNA nucleotides are not evenly utilised? Clearly state your hypothesis, test statistic and conclusion. Justify your conclusion and choice of test statistic. plz!!! -- View this message in context: http://www.nabble.com/statistics-tp25530074p25530074.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] statistics
btw., even with homework newsgroups it's typically a no-no if you haven't even tried and do not show that you have done anything by yourself. Basically you are saying, I haven't been to class, I did not read the book either, I haven't done and don't know anything; can somebody else do my work for me, please. I don't know if there is any newsgroup that finds this approach acceptable. Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Anelle Gesendet: Sunday, September 20, 2009 11:07 AM An: r-help@r-project.org Betreff: [R] statistics The myoglobin sequence, with reference number NM_005368 in Gen bank, has the following frequencies of DNA nucleotides: ACGT 237 278 309 242 Do these data provide sufficient evidence, at the 1% level of significance, that the DNA nucleotides have an unequal distribution, that is the DNA nucleotides are not evenly utilised? Clearly state your hypothesis, test statistic and conclusion. Justify your conclusion and choice of test statistic. plz!!! -- View this message in context: http://www.nabble.com/statistics-tp25530074p25530074.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Read time series
zoo() On Sun, Sep 20, 2009 at 12:24 PM, Alexis Maluendas avmaluend...@gmail.com wrote: Hi R experts, How can I get a ts object from a data frame object which contains a daily time series in order to apply it time series functions? Tanks Aleto [[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. -- == WenSui Liu Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller == __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] how to count occurrences of string?
Here is one approach: (Some steps are intermediary steps to illustrate what is going on) #create sample strings #repeat each of them 10 times string=rep(c( Lorem ipsum dolor sit amet, Lorem ipsum, and lorem ipsum something else, Foo, Bar, Foobar),10) ##Create a gender variable gender=rep(0:1,each=25) ##Create an index variable index=1:length(string) ##This is the string you want to look for i.am.looking.for=Lorem ipsum ##Return the indices of the strings ##in which lorem ipsum is found? grep(i.am.looking.for,string) ##Return a boolean for each index ##whether lorem ipsum is found or not? index%in%grep(i.am.looking.for,string) ##Finally, table the occurrence/absence of ##lorem ipsum by gender table(index%in%grep(i.am.looking.for,string),gender) Hope that helps, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von w_poet Gesendet: Sunday, September 20, 2009 11:58 AM An: r-help@r-project.org Betreff: [R] how to count occurrences of string? Hi everyone, I have an array with a variable called comments. I wish to count the number of subjects whose post-experiment comments contain a string x and then cross tab this with other variables of interest, ex. age. Does anyone have any suggestions on how to count unique occurrences of a string embedded within a variable and cross-tab it with other variables? I've looked through the help files, etc. One method I tried was to use strsplit to split comments. I can use this with table to count the number of occurrences of x, but I can't cross tab this with other variables because comments is a ragged array after being split. Thanks in advance, Stephen -- View this message in context: http://www.nabble.com/how-to-count-occurrences-of-string--tp25530083p2553008 3.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] running many different regressions
Dear R community, I have a dataframe with say 100 different variables. I wish to regress variable 1 separately on every other variable (2-100) in a linear regression using lm. There must be an easy way to do this without loops, but I have difficulties figuring this out... Can you please help? Thank you and best regards, Georg. * Georg Ehret Johns Hopkins University Institute of Genetic Medicine [[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] missing level of a nested factor results in an NA in lm output
Hello All, I have posted to this list before regarding the same issue so I apologize for the multiple e-mails. I am still struggling with this issue so I thought I'd give it another try. This time I have included reproducible code and a subset of the data I am analyzing. I am running an ANOVA with three factors: GROUP (5 levels), FEATURE (2 levels), and PATIENT (2 levels), where PATIENT is nested within GROUP. I am interested in estimating various linear functions of the model coefficients (which I sometimes refer to as 'contrasts' below). An example of the data can be set up using the following code: example - data.frame( ABUNDANCE = rnorm(30, 12), FEATURE = factor(rep(c(3218, 4227, 6374), 10)), GROUP = factor(rep(c(0, 1, 2, 3, 4), 6)), PATIENT = factor(rep(c(1, 2), 15)) ) I am using the lm function to run the model as shown. fit - lm(ABUNDANCE ~ FEATURE + GROUP + FEATURE:GROUP + GROUP/PATIENT, example) summary(fit) The output of this code is below. fit - lm(ABUNDANCE ~ FEATURE + GROUP + FEATURE:GROUP + GROUP/ PATIENT, example) summary(fit) Call: lm(formula = ABUNDANCE ~ FEATURE + GROUP + FEATURE:GROUP + GROUP/ PATIENT, data = example) Residuals: Min 1Q Median 3QMax -5.510e-01 -1.961e-01 3.469e-17 1.961e-01 5.510e-01 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 12.6487 0.4037 31.331 2.58e-11 *** FEATURE4227 -0.3271 0.4944 -0.661 0.52325 FEATURE6374 -1.0743 0.4944 -2.173 0.05492 . GROUP1 -1.2641 0.5709 -2.214 0.05120 . GROUP2 -0.2359 0.5709 -0.413 0.68825 GROUP3 -1.3081 0.5709 -2.291 0.04492 * GROUP4 -0.5867 0.5709 -1.028 0.32836 FEATURE4227:GROUP1 1.5651 0.6993 2.238 0.04915 * FEATURE6374:GROUP1 1.1435 0.6993 1.635 0.13302 FEATURE4227:GROUP2 0.4372 0.6993 0.625 0.54577 FEATURE6374:GROUP2 0.6728 0.6993 0.962 0.35867 FEATURE4227:GROUP3 1.0135 0.6993 1.449 0.17786 FEATURE6374:GROUP3 2.2665 0.6993 3.241 0.00885 ** FEATURE4227:GROUP4 1.3278 0.6993 1.899 0.08679 . FEATURE6374:GROUP4 0.5610 0.6993 0.802 0.44103 GROUP0:PATIENT2 -0.5569 0.4037 -1.379 0.19785 GROUP1:PATIENT2 -0.1104 0.4037 -0.273 0.79014 GROUP2:PATIENT2 -0.9702 0.4037 -2.403 0.03712 * GROUP3:PATIENT2 -0.1400 0.4037 -0.347 0.73586 GROUP4:PATIENT2 -0.5947 0.4037 -1.473 0.17147 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.4944 on 10 degrees of freedom Multiple R-squared: 0.8004, Adjusted R-squared: 0.4211 F-statistic: 2.11 on 19 and 10 DF, p-value: 0.1133 I then use the estimable function to estimate a linear combination of the parameter estimates. myEstimate - cbind( '(Intercept)' = 1, 'GROUP1' = 1, 'FEATURE4227:GROUP1' = 0.5, 'FEATURE6374:GROUP1' = 0.5, 'GROUP0:PATIENT2' = 1 ) rownames(myEstimate) - test estimable(fit, myEstimate) Estimate Std. Error t value DF Pr(|t|) test 12.18198 0.6694812 18.19615 10 5.395944e-09 I am able to get the t-statistic and associated p-value for the contrast as desired. However, I sometimes have a case where there is a missing patient within one of the groups. To give an example of this situation, I remove patient 2 from group 4 and perform the same analysis. example2 - example[!(example$GROUP == 4 example$PATIENT == 2),] fit - lm(ABUNDANCE ~ FEATURE + GROUP + FEATURE:GROUP + GROUP/ PATIENT, example2) summary(fit) Call: lm(formula = ABUNDANCE ~ FEATURE + GROUP + FEATURE:GROUP + GROUP/ PATIENT, data = example2) Residuals: Min 1Q Median 3QMax -5.510e-01 -2.084e-01 6.099e-20 2.084e-01 5.510e-01 Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(|t|) (Intercept) 12.6487 0.4442 28.475 2.5e-09 *** FEATURE4227 -0.3271 0.5440 -0.601 0.5644 FEATURE6374 -1.0743 0.5440 -1.975 0.0837 . GROUP1 -1.2641 0.6282 -2.012 0.0790 . GROUP2 -0.2359 0.6282 -0.375 0.7171 GROUP3 -1.3081 0.6282 -2.082 0.0709 . GROUP4 -0.4570 0.7023 -0.651 0.5335 FEATURE4227:GROUP1 1.5651 0.7694 2.034 0.0764 . FEATURE6374:GROUP1 1.1435 0.7694 1.486 0.1755 FEATURE4227:GROUP2 0.4372 0.7694 0.568 0.5854 FEATURE6374:GROUP2 0.6728 0.7694 0.874 0.4074 FEATURE4227:GROUP3 1.0135 0.7694 1.317 0.2242 FEATURE6374:GROUP3 2.2665 0.7694 2.946 0.0185 * FEATURE4227:GROUP4 1.2146 0.9423 1.289 0.2334 FEATURE6374:GROUP4 0.2850 0.9423 0.302 0.7700
Re: [R] running many different regressions
apologize, there is a typo in the glm() :-) On Sun, Sep 20, 2009 at 2:05 PM, Georg Ehret georgeh...@gmail.com wrote: Dear R community, I have a dataframe with say 100 different variables. I wish to regress variable 1 separately on every other variable (2-100) in a linear regression using lm. There must be an easy way to do this without loops, but I have difficulties figuring this out... Can you please help? Thank you and best regards, Georg. * Georg Ehret Johns Hopkins University Institute of Genetic Medicine [[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. -- == WenSui Liu Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller == __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] running many different regressions
On Sun, Sep 20, 2009 at 2:38 PM, Wensui Liu liuwen...@gmail.com wrote: I just quickly draft one with boston housing data. and it should be close to what you need. # REMOVE ALL OBJECTS rm... WARNING!!! Running the code in this post could wipe out your entire workspace Please do NOT post such 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] running many different regressions
well, i assume you understand what my code does. please don't use if you don't know what you are using. On Sun, Sep 20, 2009 at 2:44 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Sun, Sep 20, 2009 at 2:38 PM, Wensui Liu liuwen...@gmail.com wrote: I just quickly draft one with boston housing data. and it should be close to what you need. # REMOVE ALL OBJECTS rm... WARNING!!! Running the code in this post could wipe out your entire workspace Please do NOT post such code. -- == WenSui Liu Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] running many different regressions
Not everyone carefully examines the code from r-help posts prior to pasting it in. Posting code is very dangerous and should not be done. Quite the contrary they often try to understand the code by running it. Code like this should never be posted. On Sun, Sep 20, 2009 at 2:47 PM, Wensui Liu liuwen...@gmail.com wrote: well, i assume you understand what my code does. please don't use if you don't know what you are using. On Sun, Sep 20, 2009 at 2:44 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Sun, Sep 20, 2009 at 2:38 PM, Wensui Liu liuwen...@gmail.com wrote: I just quickly draft one with boston housing data. and it should be close to what you need. # REMOVE ALL OBJECTS rm... WARNING!!! Running the code in this post could wipe out your entire workspace Please do NOT post such code. -- == WenSui Liu Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller == __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] running many different regressions
should chicken be blamed by the people allergic by eggs? On Sun, Sep 20, 2009 at 3:00 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Not everyone carefully examines the code from r-help posts prior to pasting it in. Posting code is very dangerous and should not be done. Quite the contrary they often try to understand the code by running it. Code like this should never be posted. On Sun, Sep 20, 2009 at 2:47 PM, Wensui Liu liuwen...@gmail.com wrote: well, i assume you understand what my code does. please don't use if you don't know what you are using. On Sun, Sep 20, 2009 at 2:44 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Sun, Sep 20, 2009 at 2:38 PM, Wensui Liu liuwen...@gmail.com wrote: I just quickly draft one with boston housing data. and it should be close to what you need. # REMOVE ALL OBJECTS rm... WARNING!!! Running the code in this post could wipe out your entire workspace Please do NOT post such code. -- == WenSui Liu Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller == -- == WenSui Liu Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller == __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Within-group correlation confidence intervals
you should save your 3 variables into a new *dataframe* d-mydata[,c(iq,education,achievement)] and then the command would be by(d,d$sex,function(df) cor.test(df$educ,df$achiev)) but you could also just use by(mydata,mydata$sex,function(df) cor.test(df$educ,df$achiev)) david freedman jlwoodard wrote: I'm trying to obtain within-group correlations on a subset of variables. I first selected my variables using the following command: mydata$x-mydata[c(iq,education,achievement)] I'd like to look at correlations among those variables separately for men and women. My gender variable in mydata is coded 1 (women) and 0 (men). I have successfully used the following to get within group correlations and p values: by(x,gender,function(x) rcorr(as.matrix(x))) However, I'm also interested in getting confidence intervals for the correlations as well, using cor.test. I tried the following without success. by(x,gender,function(x) cor.test(as.matrix(x))) Even if I just use 2 variables (e.g., IQ and education), I get exactly the same output for men and women with this command: by(x,gender,function(x) cor.test(iq,education)) I'm still in the learning stages with the by and cor.test functions, so I assume I'm using it incorrectly. Is it possible to get the correlation confidence intervals for each group using this approach? Many thanks in advance! John -- View this message in context: http://www.nabble.com/Within-group-correlation-confidence-intervals-tp25509629p25530117.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] perl functions in R enviroment
dear all, I am trying to implement some perl scripting in R to improve the performance of some scripts. I found RSPerl library, but it seems to be quite tricky to import variables. this is a simple example. is there any simpler way to do it? furthermore is there any other available resource to interface the two language? RSPerl seems to be no longer supported and when I load it R complains about deprecated functions perl_script - function(x){ Pvar - @var = 1; PPvar - .PerlExpr(Pvar) i = 1 for(i in 1:length(x)){ Ppush - paste(push,(, @var, ,, x[i], ), ;, sep = ) .PerlExpr(Ppush) print(i) } Print - paste(print, \,@var, \n,\, ;, sep= ) .PerlExpr(Print) } aa = 1:10 out - perl_script(aa) thank you [[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] Date/Time to date time
Hi, Can strptime (or some other function) help me turn the following column of a data.frame into two new columns, one as date and the other as time, preserving the AM/PM value? Thanks, Mark B ENTRY DATE 1 3/23/2009 6:30:00 AM 2 3/23/2009 6:30:00 AM 3 3/23/2009 6:39:00 AM 4 3/23/2009 6:39:00 AM 5 3/23/2009 6:48:00 AM 6 3/23/2009 6:48:00 AM 7 3/23/2009 7:00:00 AM strftime(B, tz=, format=%m/%d/%Y %I:%M:%s %p) Error in as.POSIXlt.default(x, tz = tz) : do not know how to convert 'x' to class POSIXlt strptime(B, format=%m/%d/%Y %I:%M:%s %p) [1] NA mode(B) [1] list class(B) [1] data.frame __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Date/Time to date time
Here is one way to do it. Not sure why you want columns with either date or time since you already have them. This will create a POSIXct object you can use for processing and then two character columns with date and time. Exactly what are you going to do with the data. str(x) 'data.frame': 7 obs. of 4 variables: $ V1: int 1 2 3 4 5 6 7 $ V2: chr 3/23/2009 3/23/2009 3/23/2009 3/23/2009 ... $ V3: chr 6:30:00 6:30:00 6:39:00 6:39:00 ... $ V4: chr AM AM AM AM ... y - x # use temporary so we can try again y$dateTime - as.POSIXct(paste(y[[2]], y[[3]], y[[4]]), format=%m/%d/%Y %I:%M:%S %p) # add columns with only date and time y$date - format(y$dateTime, %m/%d/%Y) y$time - format(y$dateTime, %I:%M:%S %p) str(y) 'data.frame': 7 obs. of 7 variables: $ V1 : int 1 2 3 4 5 6 7 $ V2 : chr 3/23/2009 3/23/2009 3/23/2009 3/23/2009 ... $ V3 : chr 6:30:00 6:30:00 6:39:00 6:39:00 ... $ V4 : chr AM AM AM AM ... $ dateTime: POSIXct, format: 2009-03-23 06:30:00 2009-03-23 06:30:00 2009-03-23 06:39:00 2009-03-23 06:39:00 ... $ date: chr 03/23/2009 03/23/2009 03/23/2009 03/23/2009 ... $ time: chr 06:30:00 AM 06:30:00 AM 06:39:00 AM 06:39:00 AM ... y V1V2 V3 V4dateTime datetime 1 1 3/23/2009 6:30:00 AM 2009-03-23 06:30:00 03/23/2009 06:30:00 AM 2 2 3/23/2009 6:30:00 AM 2009-03-23 06:30:00 03/23/2009 06:30:00 AM 3 3 3/23/2009 6:39:00 AM 2009-03-23 06:39:00 03/23/2009 06:39:00 AM 4 4 3/23/2009 6:39:00 AM 2009-03-23 06:39:00 03/23/2009 06:39:00 AM 5 5 3/23/2009 6:48:00 AM 2009-03-23 06:48:00 03/23/2009 06:48:00 AM 6 6 3/23/2009 6:48:00 AM 2009-03-23 06:48:00 03/23/2009 06:48:00 AM 7 7 3/23/2009 7:00:00 AM 2009-03-23 07:00:00 03/23/2009 07:00:00 AM On Sun, Sep 20, 2009 at 4:11 PM, Mark Knecht markkne...@gmail.com wrote: Hi, Can strptime (or some other function) help me turn the following column of a data.frame into two new columns, one as date and the other as time, preserving the AM/PM value? Thanks, Mark B ENTRY DATE 1 3/23/2009 6:30:00 AM 2 3/23/2009 6:30:00 AM 3 3/23/2009 6:39:00 AM 4 3/23/2009 6:39:00 AM 5 3/23/2009 6:48:00 AM 6 3/23/2009 6:48:00 AM 7 3/23/2009 7:00:00 AM strftime(B, tz=, format=%m/%d/%Y %I:%M:%s %p) Error in as.POSIXlt.default(x, tz = tz) : do not know how to convert 'x' to class POSIXlt strptime(B, format=%m/%d/%Y %I:%M:%s %p) [1] NA mode(B) [1] list class(B) [1] data.frame __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Date/Time to date time
Note that your explanation refers to strptime but the code uses strftime which accounts for the error. Try this: Lines - ENTRY DATE + 3/23/2009 6:30:00 AM + 3/23/2009 6:30:00 AM + 3/23/2009 6:39:00 AM + 3/23/2009 6:39:00 AM + 3/23/2009 6:48:00 AM + 3/23/2009 6:48:00 AM + 3/23/2009 7:00:00 AM DF - read.csv(textConnection(Lines)) library(chron) ch - as.chron(as.character(DF[[1]]), %m/%d/%Y %I:%M:%S %p) dd - dates(ch) data.frame(Date = dd, Time = times(ch - dd)) Date Time 1 03/23/09 06:30:00 2 03/23/09 06:30:00 3 03/23/09 06:39:00 4 03/23/09 06:39:00 5 03/23/09 06:48:00 6 03/23/09 06:48:00 7 03/23/09 07:00:00 Try using dput next time to facilitate copying of your data into readers' sessions. dput(DF) structure(list(ENTRY.DATE = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L), .Label = c(3/23/2009 6:30:00 AM, 3/23/2009 6:39:00 AM, 3/23/2009 6:48:00 AM, 3/23/2009 7:00:00 AM), class = factor)), .Names = ENTRY.DATE, class = data.frame, row.names = c(NA, -7L)) In the above we used dates and times classes from chron. as.Date(x) will convert an object to Date class if you want that instead. See R News 4/1 for more on dates and times. On Sun, Sep 20, 2009 at 4:11 PM, Mark Knecht markkne...@gmail.com wrote: Hi, Can strptime (or some other function) help me turn the following column of a data.frame into two new columns, one as date and the other as time, preserving the AM/PM value? Thanks, Mark B ENTRY DATE 1 3/23/2009 6:30:00 AM 2 3/23/2009 6:30:00 AM 3 3/23/2009 6:39:00 AM 4 3/23/2009 6:39:00 AM 5 3/23/2009 6:48:00 AM 6 3/23/2009 6:48:00 AM 7 3/23/2009 7:00:00 AM strftime(B, tz=, format=%m/%d/%Y %I:%M:%s %p) Error in as.POSIXlt.default(x, tz = tz) : do not know how to convert 'x' to class POSIXlt strptime(B, format=%m/%d/%Y %I:%M:%s %p) [1] NA mode(B) [1] list class(B) [1] data.frame __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Date/Time to date time
Thanks Gabor, I did try to use dput but it wasn't cooperating and wanted to send FAR too much data. Your method works well for me but as I look at it I don't understand the use of double brackets - DF[[1]] - why do you do that? Anyway, thanks for the fast reponses from you and Jim. Both will allow me to make some headway today. Cheers, Mark On Sun, Sep 20, 2009 at 1:27 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Note that your explanation refers to strptime but the code uses strftime which accounts for the error. Try this: Lines - ENTRY DATE + 3/23/2009 6:30:00 AM + 3/23/2009 6:30:00 AM + 3/23/2009 6:39:00 AM + 3/23/2009 6:39:00 AM + 3/23/2009 6:48:00 AM + 3/23/2009 6:48:00 AM + 3/23/2009 7:00:00 AM DF - read.csv(textConnection(Lines)) library(chron) ch - as.chron(as.character(DF[[1]]), %m/%d/%Y %I:%M:%S %p) dd - dates(ch) data.frame(Date = dd, Time = times(ch - dd)) Date Time 1 03/23/09 06:30:00 2 03/23/09 06:30:00 3 03/23/09 06:39:00 4 03/23/09 06:39:00 5 03/23/09 06:48:00 6 03/23/09 06:48:00 7 03/23/09 07:00:00 Try using dput next time to facilitate copying of your data into readers' sessions. dput(DF) structure(list(ENTRY.DATE = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L), .Label = c(3/23/2009 6:30:00 AM, 3/23/2009 6:39:00 AM, 3/23/2009 6:48:00 AM, 3/23/2009 7:00:00 AM), class = factor)), .Names = ENTRY.DATE, class = data.frame, row.names = c(NA, -7L)) In the above we used dates and times classes from chron. as.Date(x) will convert an object to Date class if you want that instead. See R News 4/1 for more on dates and times. On Sun, Sep 20, 2009 at 4:11 PM, Mark Knecht markkne...@gmail.com wrote: Hi, Can strptime (or some other function) help me turn the following column of a data.frame into two new columns, one as date and the other as time, preserving the AM/PM value? Thanks, Mark B ENTRY DATE 1 3/23/2009 6:30:00 AM 2 3/23/2009 6:30:00 AM 3 3/23/2009 6:39:00 AM 4 3/23/2009 6:39:00 AM 5 3/23/2009 6:48:00 AM 6 3/23/2009 6:48:00 AM 7 3/23/2009 7:00:00 AM strftime(B, tz=, format=%m/%d/%Y %I:%M:%s %p) Error in as.POSIXlt.default(x, tz = tz) : do not know how to convert 'x' to class POSIXlt strptime(B, format=%m/%d/%Y %I:%M:%s %p) [1] NA mode(B) [1] list class(B) [1] data.frame __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Date/Time to date time
On Sun, Sep 20, 2009 at 4:52 PM, Mark Knecht markkne...@gmail.com wrote: Thanks Gabor, I did try to use dput but it wasn't cooperating and wanted to send FAR too much data. dput(head(x, 10)) Your method works well for me but as I look at it I don't understand the use of double brackets - DF[[1]] - why do you do that? DF[[1]] is contents of the first column whereas DF[1] is a data frame with one column -- not the same. Anyway, thanks for the fast reponses from you and Jim. Both will allow me to make some headway today. Cheers, Mark On Sun, Sep 20, 2009 at 1:27 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Note that your explanation refers to strptime but the code uses strftime which accounts for the error. Try this: Lines - ENTRY DATE + 3/23/2009 6:30:00 AM + 3/23/2009 6:30:00 AM + 3/23/2009 6:39:00 AM + 3/23/2009 6:39:00 AM + 3/23/2009 6:48:00 AM + 3/23/2009 6:48:00 AM + 3/23/2009 7:00:00 AM DF - read.csv(textConnection(Lines)) library(chron) ch - as.chron(as.character(DF[[1]]), %m/%d/%Y %I:%M:%S %p) dd - dates(ch) data.frame(Date = dd, Time = times(ch - dd)) Date Time 1 03/23/09 06:30:00 2 03/23/09 06:30:00 3 03/23/09 06:39:00 4 03/23/09 06:39:00 5 03/23/09 06:48:00 6 03/23/09 06:48:00 7 03/23/09 07:00:00 Try using dput next time to facilitate copying of your data into readers' sessions. dput(DF) structure(list(ENTRY.DATE = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L), .Label = c(3/23/2009 6:30:00 AM, 3/23/2009 6:39:00 AM, 3/23/2009 6:48:00 AM, 3/23/2009 7:00:00 AM), class = factor)), .Names = ENTRY.DATE, class = data.frame, row.names = c(NA, -7L)) In the above we used dates and times classes from chron. as.Date(x) will convert an object to Date class if you want that instead. See R News 4/1 for more on dates and times. On Sun, Sep 20, 2009 at 4:11 PM, Mark Knecht markkne...@gmail.com wrote: Hi, Can strptime (or some other function) help me turn the following column of a data.frame into two new columns, one as date and the other as time, preserving the AM/PM value? Thanks, Mark B ENTRY DATE 1 3/23/2009 6:30:00 AM 2 3/23/2009 6:30:00 AM 3 3/23/2009 6:39:00 AM 4 3/23/2009 6:39:00 AM 5 3/23/2009 6:48:00 AM 6 3/23/2009 6:48:00 AM 7 3/23/2009 7:00:00 AM strftime(B, tz=, format=%m/%d/%Y %I:%M:%s %p) Error in as.POSIXlt.default(x, tz = tz) : do not know how to convert 'x' to class POSIXlt strptime(B, format=%m/%d/%Y %I:%M:%s %p) [1] NA mode(B) [1] list class(B) [1] data.frame __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] How to choose knots for GAM?
Hi, all I want to choose same knots in GAM for 10 different studies so that they has the same basis function. Even though I choose same knots and same dimensions of basis smoothing, the basis representations are still not same. My command is as follows: data.gam-gam(y~s(age,bs='cr',k=10)+male,family=binomial,knots=list(age=seq(45,64,length=10))) What is my mistake for choice of knots and dimension? Thank you very much. Lee [[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] correlation help
Dear group, I have a matrix like the following: Name Sample1sample2sample3 sample4 . sample(n) nm110.5 13.5 30 31 nm2 8 1134 29 nm3 9 10.3 27.8 35 nm(j) I want to be able to calculate correlation between all pairs of names. For example (nm1,nm2), (nm1,nm3), (nm1,nmj), (nm2,nm3), (nm2,nmj) Then I want to calculate the significance of correlation using t-score or p-value. I can calculate correlation coeffecient in excel but not significance in both excel and R. I want to be able to do it in R, I appreciate your help. thank you. Ad. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] running many different regressions
--- On Sun, 9/20/09, Wensui Liu liuwen...@gmail.com wrote: From: Wensui Liu liuwen...@gmail.com Subject: Re: [R] running many different regressions To: Gabor Grothendieck ggrothendi...@gmail.com Cc: R-help@r-project.org Received: Sunday, September 20, 2009, 3:04 PM should chicken be blamed by the people allergic by eggs? It's more like : Don't give matches to a child. The problem that Gabor is pointing out is that a new R user may not recognize what that rm command was going to do and paste it into R to see what happens. And then KABLOOIE. It's particularly dangerous right now as schools in much of the Northern Hemisphere are starting up and we are likely be be getting a lot of very new 'new users'. On Sun, Sep 20, 2009 at 3:00 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Not everyone carefully examines the code from r-help posts prior to pasting it in. Posting code is very dangerous and should not be done. Quite the contrary they often try to understand the code by running it. Code like this should never be posted. On Sun, Sep 20, 2009 at 2:47 PM, Wensui Liu liuwen...@gmail.com wrote: well, i assume you understand what my code does. please don't use if you don't know what you are using. On Sun, Sep 20, 2009 at 2:44 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Sun, Sep 20, 2009 at 2:38 PM, Wensui Liu liuwen...@gmail.com wrote: I just quickly draft one with boston housing data. and it should be close to what you need. # REMOVE ALL OBJECTS rm... WARNING!!! Running the code in this post could wipe out your entire workspace Please do NOT post such code. -- == WenSui Liu Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller == -- == WenSui Liu Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller == __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ Looking for the perfect gift? Give the gift of Flickr! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Date/Time to date time
On Sun, Sep 20, 2009 at 1:55 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Sun, Sep 20, 2009 at 4:52 PM, Mark Knecht markkne...@gmail.com wrote: Thanks Gabor, I did try to use dput but it wasn't cooperating and wanted to send FAR too much data. dput(head(x, 10)) As I said, I tried almost exactly that. I didn't want to send all the data I'm sending this time. My input data.frame is moderately wide and I wanted to discuss the conversion of the first column so I used head(x[1]), which returns just a few lines, but dput(head(x[1])) outputs all the original data and not just the first few lines. Data is below. Your method works well for me but as I look at it I don't understand the use of double brackets - DF[[1]] - why do you do that? DF[[1]] is contents of the first column whereas DF[1] is a data frame with one column -- not the same. Very interesting. Thanks! Cheers, Mark head(x) ENTRY DATE ENTRY PRICE EXIT DATE EXIT PRICE STOP PRICE LONG/SHORT PROFIT/LOSS RISK SIZE 1 3/23/2009 6:30:00 AM 775.50 3/23/2009 6:30:00 AM 776.00 0 119.001 2 3/23/2009 6:30:00 AM 775.50 3/23/2009 6:31:00 AM 774.50 0 1 -56.001 3 3/23/2009 6:39:00 AM 776.25 3/23/2009 6:39:00 AM 776.75 0 119.001 4 3/23/2009 6:39:00 AM 776.25 3/23/2009 6:40:00 AM 775.25 0 1 -56.001 5 3/23/2009 6:48:00 AM 774.25 3/23/2009 6:49:00 AM 773.75 0 -119.001 6 3/23/2009 6:48:00 AM 774.25 3/23/2009 6:51:00 AM 772.50 0 -181.501 head(x[1]) ENTRY DATE 1 3/23/2009 6:30:00 AM 2 3/23/2009 6:30:00 AM 3 3/23/2009 6:39:00 AM 4 3/23/2009 6:39:00 AM 5 3/23/2009 6:48:00 AM 6 3/23/2009 6:48:00 AM dput(head(x[1])) structure(list(`ENTRY DATE` = structure(c(4L, 4L, 5L, 5L, 6L, 6L), .Label = c(3/23/2009 10:15:00 AM, 3/23/2009 10:48:00 AM, 3/23/2009 11:13:00 AM, 3/23/2009 6:30:00 AM , 3/23/2009 6:39:00 AM , 3/23/2009 6:48:00 AM , 3/23/2009 7:00:00 AM , 3/23/2009 7:49:00 AM , 3/23/2009 8:02:00 AM , 3/23/2009 8:27:00 AM , 3/23/2009 9:04:00 AM , 3/24/2009 10:36:00 AM, 3/24/2009 11:09:00 AM, 3/24/2009 6:49:00 AM , 3/24/2009 6:56:00 AM , 3/24/2009 7:15:00 AM , 3/24/2009 8:18:00 AM , 3/24/2009 9:13:00 AM , 3/24/2009 9:31:00 AM , 3/25/2009 10:57:00 AM, 3/25/2009 11:25:00 AM, 3/25/2009 5:31:00 AM , 3/25/2009 7:16:00 AM , 3/25/2009 7:42:00 AM , 3/25/2009 7:50:00 AM , 3/25/2009 8:15:00 AM , 3/25/2009 8:50:00 AM , 3/25/2009 9:21:00 AM , 3/26/2009 10:03:00 AM, 3/26/2009 10:37:00 AM, 3/26/2009 11:06:00 AM, 3/26/2009 11:25:00 AM, 3/26/2009 5:38:00 AM , 3/26/2009 6:25:00 AM , 3/26/2009 6:33:00 AM , 3/26/2009 6:48:00 AM , 3/26/2009 7:18:00 AM , 3/26/2009 7:29:00 AM , 3/26/2009 7:35:00 AM , 3/26/2009 8:01:00 AM , 3/26/2009 8:37:00 AM , 3/26/2009 8:53:00 AM , 3/26/2009 9:09:00 AM , 3/26/2009 9:36:00 AM , 3/27/2009 10:35:00 AM, 3/27/2009 10:44:00 AM, 3/27/2009 11:10:00 AM, 3/27/2009 6:55:00 AM , 3/27/2009 7:02:00 AM , 3/27/2009 7:26:00 AM , 3/27/2009 8:47:00 AM , 3/27/2009 9:00:00 AM , 3/27/2009 9:19:00 AM , 3/30/2009 10:02:00 AM, 3/30/2009 10:40:00 AM, 3/30/2009 11:16:00 AM, 3/30/2009 6:24:00 AM , 3/30/2009 7:01:00 AM , 3/30/2009 7:11:00 AM , 3/30/2009 7:22:00 AM , 3/30/2009 8:18:00 AM , 3/30/2009 8:35:00 AM , 3/30/2009 9:30:00 AM , 3/31/2009 6:37:00 AM , 3/31/2009 6:56:00 AM , 3/31/2009 7:05:00 AM , 3/31/2009 7:21:00 AM , 3/31/2009 7:33:00 AM , 3/31/2009 7:57:00 AM , 3/31/2009 8:10:00 AM , 3/31/2009 8:54:00 AM , 3/31/2009 9:03:00 AM , 4/1/2009 10:47:00 AM , 4/1/2009 7:47:00 AM , 4/1/2009 8:29:00 AM , 4/1/2009 9:40:00 AM , 4/13/2009 11:15:00 AM, 4/13/2009 7:08:00 AM , 4/13/2009 7:49:00 AM , 4/13/2009 8:29:00 AM , 4/13/2009 8:46:00 AM , 4/13/2009 9:09:00 AM , 4/14/2009 10:31:00 AM, 4/14/2009 10:49:00 AM, 4/14/2009 11:08:00 AM, 4/14/2009 11:20:00 AM, 4/14/2009 5:37:00 AM , 4/14/2009 6:52:00 AM , 4/14/2009 8:13:00 AM , 4/14/2009 9:04:00 AM , 4/15/2009 10:24:00 AM, 4/15/2009 11:04:00 AM, 4/15/2009 6:44:00 AM , 4/15/2009 7:32:00 AM , 4/15/2009 8:43:00 AM , 4/16/2009 10:10:00 AM, 4/16/2009 10:52:00 AM, 4/16/2009 11:08:00 AM, 4/16/2009 6:55:00 AM , 4/16/2009 7:01:00 AM , 4/16/2009 7:21:00 AM , 4/16/2009 7:43:00 AM , 4/16/2009 8:13:00 AM , 4/17/2009 6:00:00 AM , 4/17/2009 6:30:00 AM , 4/17/2009 6:43:00 AM , 4/17/2009 6:56:00 AM , 4/17/2009 7:06:00 AM , 4/17/2009 7:16:00 AM , 4/17/2009 7:27:00 AM , 4/17/2009 8:09:00 AM , 4/17/2009 8:14:00 AM , 4/17/2009 8:30:00 AM , 4/17/2009 9:49:00 AM , 4/2/2009 11:05:00 AM , 4/2/2009 11:22:00 AM , 4/2/2009 5:32:00 AM , 4/2/2009 5:46:00 AM , 4/2/2009 5:51:00 AM , 4/2/2009 6:30:00 AM , 4/2/2009 6:38:00 AM , 4/2/2009 6:49:00 AM , 4/2/2009 7:19:00 AM , 4/2/2009 7:24:00 AM , 4/2/2009 7:55:00 AM , 4/2/2009 8:45:00 AM , 4/2/2009 9:52:00 AM , 4/20/2009 10:00:00 AM, 4/20/2009 10:47:00 AM, 4/20/2009 11:03:00 AM, 4/20/2009 8:26:00 AM , 4/20/2009 9:06:00 AM ,
Re: [R] correlation help
?cor ?cor.test --- On Sun, 9/20/09, Adrian Johnson oriolebaltim...@gmail.com wrote: From: Adrian Johnson oriolebaltim...@gmail.com Subject: [R] correlation help To: r-help@r-project.org Received: Sunday, September 20, 2009, 5:00 PM Dear group, I have a matrix like the following: Name Sample1 sample2 sample3 sample4 . sample(n) nm1 10.5 13.5 30 31 nm2 8 11 34 29 nm3 9 10.3 27.8 35 nm(j) I want to be able to calculate correlation between all pairs of names. For example (nm1,nm2), (nm1,nm3), (nm1,nmj), (nm2,nm3), (nm2,nmj) Then I want to calculate the significance of correlation using t-score or p-value. I can calculate correlation coeffecient in excel but not significance in both excel and R. I want to be able to do it in R, I appreciate your help. thank you. Ad. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 ju __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] running many different regressions
Georg for example: data(swiss) data=swiss lapply(2:length(data),function(x) lm(data[,1]~data[,x])) HTH Schalk Heunis On Sun, Sep 20, 2009 at 2:05 PM, Georg Ehret georgeh...@gmail.com wrote: Dear R community, I have a dataframe with say 100 different variables. I wish to regress variable 1 separately on every other variable (2-100) in a linear regression using lm. There must be an easy way to do this without loops, but I have difficulties figuring this out... Can you please help? Thank you and best regards, Georg. * Georg Ehret Johns Hopkins University Institute of Genetic Medicine [[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] eval(expr) without printing to screen?
baptiste auguie wrote: Hi, What about this, eval(parse(text=expr)) (no print) HTH, baptiste Thanks. For some reason I couldn't think of that, for some reason I had a dim memory in my head that that wouldn't work, but it does. Thanks! Cheers, Nick 2009/9/19 Nick Matzke mat...@berkeley.edu: Hi, I have a script which I source, which evaluates a changing expression call hundreds of times. It works, but it prints to screen each time, which is annoying. There must be simple way to suppress this, or to use a slightly different set of commands, which will be obvious to those wiser than I... Here is a simpler mockup which shows the issue: x = data.frame(rbind(c(1,2,3),c(1,2,3))) xnames = c(a, b, c) names(x) = xnames for(i in 1:length(x)) { # Create a varying string expression expr = paste(y = x$, xnames[i], [1], sep=) # evaluate expression eval(parse(text=print(expr))) # This command prints the expression to screen even when embedded in a function in a sourced script. I would prefer it didn't! } PS: I have to go through this rigamarole: expr = y1 = x$c[1] eval(parse(text=print(expr))) Because the following doesn't work, even though it seems like it should: expr = y = x$c[2] eval(expr) -- Nicholas J. Matzke Ph.D. Candidate, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: mat...@berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 - [W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together. Isaac Asimov (1989). The Relativity of Wrong. The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Nicholas J. Matzke Ph.D. Candidate, Graduate Student Researcher Huelsenbeck Lab Center for Theoretical Evolutionary Genomics 4151 VLSB (Valley Life Sciences Building) Department of Integrative Biology University of California, Berkeley Lab websites: http://ib.berkeley.edu/people/lab_detail.php?lab=54 http://fisher.berkeley.edu/cteg/hlab.html Dept. personal page: http://ib.berkeley.edu/people/students/person_detail.php?person=370 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html Lab phone: 510-643-6299 Dept. fax: 510-643-6264 Cell phone: 510-301-0179 Email: mat...@berkeley.edu Mailing address: Department of Integrative Biology 3060 VLSB #3140 Berkeley, CA 94720-3140 - [W]hen people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together. Isaac Asimov (1989). The Relativity of Wrong. The Skeptical Inquirer, 14(1), 35-44. Fall 1989. http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] correlation help
thank you john. however, I am finding it difficult to automate on a matrix. Pardon my ignorance in R computing: I do not know how to automate on a matrix. If I do the following it works: x = cor.test(d6[1,],d6[2,]) x Pearson's product-moment correlation data: d6[1, ] and d6[2, ] t = 10.5196, df = 10, p-value = 9.973e-07 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.8520623 0.9883592 sample estimates: cor 0.9576655 If I want to run it on all rows, I do not know how to do it. I tried following, lapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) sapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) for(i in 1:14659){ + k = i+1 + cor.test(d6[i,],d6[k,]) + x = cor.test(d6[i,],d6[k,]) + return(x)} Error: no function to return from, jumping to top level I appreciate your help. thank you. Adrian On Sun, Sep 20, 2009 at 6:17 PM, Adrian Johnson oriolebaltim...@gmail.com wrote: thank you john. however, I am finding it difficult to automate on a matrix. Pardon my ignorance in R computing: I do not know how to automate on a matrix. If I do the following it works: x = cor.test(d6[1,],d6[2,]) x Pearson's product-moment correlation data: d6[1, ] and d6[2, ] t = 10.5196, df = 10, p-value = 9.973e-07 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.8520623 0.9883592 sample estimates: cor 0.9576655 If I want to run it on all rows, I do not know how to do it. I tried following, lapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) sapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) for(i in 1:14659){ + k = i+1 + cor.test(d6[i,],d6[k,]) + x = cor.test(d6[i,],d6[k,]) + return(x)} Error: no function to return from, jumping to top level I appreciate your help. thank you. Adrian On Sun, Sep 20, 2009 at 5:13 PM, John Kane jrkrid...@yahoo.ca wrote: ?cor ?cor.test --- On Sun, 9/20/09, Adrian Johnson oriolebaltim...@gmail.com wrote: From: Adrian Johnson oriolebaltim...@gmail.com Subject: [R] correlation help To: r-help@r-project.org Received: Sunday, September 20, 2009, 5:00 PM Dear group, I have a matrix like the following: Name Sample1 sample2 sample3 sample4 . sample(n) nm1 10.5 13.5 30 31 nm2 8 11 34 29 nm3 9 10.3 27.8 35 nm(j) I want to be able to calculate correlation between all pairs of names. For example (nm1,nm2), (nm1,nm3), (nm1,nmj), (nm2,nm3), (nm2,nmj) Then I want to calculate the significance of correlation using t-score or p-value. I can calculate correlation coeffecient in excel but not significance in both excel and R. I want to be able to do it in R, I appreciate your help. thank you. Ad. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Yahoo! Mail. Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.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.
[R] help with SAV file
Hi, I am trying to do a statistical analysis of a SPSS data set, which has 7 different parameters, 4 of which are Yes/No. When I try to select in one of the parameters all the rows with a Yes it always gives me the same error : object 'Yes' not found although: suburban [1] No No Yes No No Yes No Yes No No No No No No No No No No [19] No No Yes No Yes Yes No No No No Yes No Yes No No Yes Yes Yes [37] Yes No No No No Yes Yes No No No Yes No No Yes Yes Yes Yes Yes [55] Yes Yes No No No Yes No Yes Yes No No No No Yes No No No Yes [73] Yes Yes No No No No Yes No Yes No No No No No Yes No Yes Yes [91] Yes Yes No No Yes No Yes No No Yes Yes Yes No Yes No No No Yes it has a bunch of Yes/No how can I select these Yes? _ Bing brings you health info from trusted sources. http://www.bing.com/search?q=pet+allergyform=MHEINApubl=WLHMTAGcrea=TXT_MHEINA_Health_Health_PetAllergy_1x1 [[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] eval(expr) without printing to screen?
Here is a simpler mockup which shows the issue: x = data.frame(rbind(c(1,2,3),c(1,2,3))) xnames = c(a, b, c) names(x) = xnames for(i in 1:length(x)) { # Create a varying string expression expr = paste(y = x$, xnames[i], [1], sep=) # evaluate expression eval(parse(text=print(expr))) # This command prints the expression to screen even when embedded in a function in a sourced script. I would prefer it didn't! } Why are you using eval? The following is equivalent: for(name in names(x)) { y - x[[name]][1] } Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] xtable + print (html)
hi, I want html code via the xtable package. I have a data.frame and tried to use the print()-function. But I only get the data.frame printed - no html arround it. what do I have to change? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with SAV file
On Sep 20, 2009, at 6:23 PM, Rogerio Costa wrote: Hi, I am trying to do a statistical analysis of a SPSS data set, which has 7 different parameters, 4 of which are Yes/No. When I try to select in one of the parameters all the rows with a Yes it always gives me the same error HOW? (did you try?) : object 'Yes' not found although: suburban [1] No No Yes No No Yes No Yes No No No No No No No No No No [19] No No Yes No Yes Yes No No No No Yes No Yes No No Yes Yes Yes [37] Yes No No No No Yes Yes No No No Yes No No Yes Yes Yes Yes Yes [55] Yes Yes No No No Yes No Yes Yes No No No No Yes No No No Yes [73] Yes Yes No No No No Yes No Yes No No No No No Yes No Yes Yes [91] Yes Yes No No Yes No Yes No No Yes Yes Yes No Yes No No No Yes it has a bunch of Yes/No how can I select these Yes? 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] problems with Stackpoly, package Plotrix
Dear all, I am fairly new to package Plotrix and I would like to ask you, if any of you could help me with following. a) I don't know how to set up border line width in the Stackpoly function (seems that lwd from par doesn't work, or at least not in the way I have written) b) I don't know, how to rotate the x axis labels (I used srt=45, but same problem as before). c) Could anyone clarify to me, what does e.g. col= par(col) stand for in the usage explanation? Does it somehow change the way I should call such parameter? d) the three dots in stackpoly usage are calling other parameters from plot, however if in plot there are the three dots calling parameters from par, am I able to call parameters from par directly in stackpoly? Could anyone please help me? Thank you, best regards, Vaclav [[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] xtable + print (html)
On Sep 20, 2009, at 6:40 PM, Martin Batholdy wrote: hi, I want html code via the xtable package. I have a data.frame and tried to use the print()-function. But I only get the data.frame printed - no html arround it. what do I have to change? That, my son, is extremely hard to tell since knowing what you _have_ done would require superhuman powers (or I suppose extreme hacking.) This seems to work on a simple dataframe that is just lying around: print(xtable(x), type=html) !-- html table generated in R 2.9.2 by xtable 1.5-5 package -- !-- Sun Sep 20 19:17:53 2009 -- TABLE border=1 TR TH /TH TH a /TH TH b /TH TH c /TH /TR TR TD align=right 1 /TD TD align=right 1.00 /TD TD align=right 2.00 /TD TD align=right 3.00 /TD /TR TR TD align=right 2 /TD TD align=right 1.00 /TD TD align=right 2.00 /TD TD align=right 3.00 /TD /TR /TABLE thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. 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] problems with Stackpoly, package Plotrix
sorry forgot to attach reproducible code: -- Forwarded message -- Date: 2009/9/21 Subject: problems with Stackpoly, package Plotrix To: r-help@r-project.org Dear all, I am fairly new to package Plotrix and I would like to ask you, if any of you could help me with following. a) I don't know how to set up border line width in the Stackpoly function (seems that lwd from par doesn't work, or at least not in the way I have written) b) I don't know, how to rotate the x axis labels (I used srt=45, but same problem as before). c) Could anyone clarify to me, what does e.g. col= par(col) stand for in the usage explanation? Does it somehow change the way I should call such parameter? d) the three dots in stackpoly usage are calling other parameters from plot, however if in plot there are the three dots calling parameters from par, am I able to call parameters from par directly in stackpoly? Could anyone please help me? library(plotrix) xpopis-c(0.9,0.99,0.999) paste(1 in,round(1/(1-xpopis),1),sep= ) #n as number of subjects is 4 result-c(0.3,0.15,0.4,0.15,0.5,0.1,0.12,0.28,0.45,0.25,0.2,0.1) stackpoly(x=matrix(nrow=3,ncol=4,xpopis),y=matrix(nrow=3,ncol=4,result,byrow=T), xlim=c(0.85,1),ylim=c(0,1), xaxlab=paste(1 in,round(1/(1-xpopis),1),sep= ),xat=xpopis, col=c(blue,red,green,cyan), border=gray(0.4),lty=dotted,lwd=0.1,stack=T,srt=45) #lwd not working, how to make the border lines smaller? #how to add srt of the x axis labels to be = 45? i.e. to rotate x axis labels by 45 degrees? Thank you, best regards, Vaclav [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A stat related question
On 18/09/2009, at 9:23 PM, RON70 wrote: Can I ask a small stat. related question here? Suppose I have two predictors for a time series processes and accuracy of predictor is measured from MSEs. My question is, if two predictors give same MSE then, necessarily they have to be identical? Can anyone provide me any counter example? Counter example: xmpl.df - structure(list(y = c(-0.367234642740975, 0.185230564865609, 0.581823727365507, 1.39973682729268, -0.727292059474465, 1.30254263204414, 0.335848119752074, 1.03850609869762, 0.920728568290646, 0.720878162866862, -1.04311893856785, -0.0901863866107067, 0.623518161999544, -0.953523357772344, -0.542828814573857, 0.580996497681682, 0.768178737834591, 0.463767588540167, -0.88577629740968, -1.09978089864786), x1 = c(0.206067430466075, -0.132238579133420, 0.0299230903476012, 0.0770661103560109, 0.0371133529511250, -0.0520909837658339, 0.230634542906874, -0.0500870952845974, 0.319228715708252, -0.0445038917047473, 0.194516706231773, 0.366107384673495, -0.276282276770058, -0.0822685230586955, -0.0568443308533714, 0.0776057819874248, -0.0832235252633287, -0.497827207484688, -0.460077637514818, 0.197180935204927), x2 = c (0.0933724365258708, 0.290885869560421, -0.0537456615562362, -0.245617952924438, -0.375140161451431, -0.0161691421541291, 0.156173578334144, 0.216101027538157, 0.0175689640482125, 0.0199243858378162, -0.0866770708194298, 0.00756428018151888, -0.514631477389958, -0.00411244710635592, -0.203127938586995, 0.337864750427246, 0.0317949224635923, -0.115158146496248, 0.434123920996512, 0.00900586257173104)), .Names = c(y, x1, x2), row.names = c(NA, -20L), class = data.frame) The predictors x1 and x2 are *orthogonal* to each other, yet yield exactly the same model when y is regressed on each of them. To construct such an example think in terms of geometry and linear algebra. Let ``o'' be the constant n-vector all of whose entries are 1. Take an n-vector y and a unit n-vector x1 which is orthogonal to ``o'' (i.e. which has mean 0). Construct a unit vector x2 which is in the othocomplement of V_1 = o,x1 = the span of o and x1, and which has the same inner product with y as has x1. To do the latter --- choose any two unit vectors, u1 and u2 in the orthocomplement of V_1, let x2 = a*u1 + b*u2 and choose a and b so that a^2 + b^2 = 1 and (y,x2) = (y,x1). Note that ``(v1,v2)'' means the inner (dot) product of v1 and v2. ``Choosing'' a and b involves solving a quadratic equation. To get things in orthocomplements of things, use the Gramm-Schmidt orthonormalization algorithm. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] correlation help
Adrian, See http://www.nabble.com/Re:-applying-cor.test-to-a-(m,-n)-matrix---SUMMARY-to17150239.html#a17150239 http://www.nabble.com/Re:-applying-cor.test-to-a-(m,-n)-matrix---SUMMARY-to17150239.html#a17150239 HTH, Jorge On Sun, Sep 20, 2009 at 5:00 PM, Adrian Johnson oriolebaltim...@gmail.comwrote: Dear group, I have a matrix like the following: Name Sample1sample2sample3 sample4 . sample(n) nm110.5 13.5 30 31 nm2 8 1134 29 nm3 9 10.3 27.8 35 nm(j) I want to be able to calculate correlation between all pairs of names. For example (nm1,nm2), (nm1,nm3), (nm1,nmj), (nm2,nm3), (nm2,nmj) Then I want to calculate the significance of correlation using t-score or p-value. I can calculate correlation coeffecient in excel but not significance in both excel and R. I want to be able to do it in R, I appreciate your help. thank you. Ad. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.
[R] Post-Hoc tests for Friedman Test?
Hi there all, This is my first post to the list and I'll first say a few things: - R is great! - The archives of this list have helped me solve all of my problems/questions so far - I only know enough statistics to be dangerous I'm looking for a way to do post-hoc tests for the Friedman test. I have a dataset from a within-subjects design with 5 conditions where some of the dependent variables are ordinal, resulting from (summed) likert-scaled questionnaire data. From what I've read, I could use a wilcox.test on pairs of conditions and adjust the p level, but is there something in R that does a better job/automates this. I've seen references to the npmc package but that doesn't seem to do what I'm looking for, because it only accepts a data frame with two columns - i.e. there's no way to specify grouping/subject identifiers. Thanks, Jon Marbach PhD Student, Computer Science Department University of Colorado __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Post-Hoc tests for Friedman Test?
On Sep 20, 2009, at 9:05 PM, j...@terraspark.com wrote: Hi there all, This is my first post to the list and I'll first say a few things: - R is great! - The archives of this list have helped me solve all of my problems/ questions so far - I only know enough statistics to be dangerous I'm looking for a way to do post-hoc tests for the Friedman test. I have a dataset from a within-subjects design with 5 conditions where some of the dependent variables are ordinal, resulting from (summed) likert-scaled questionnaire data. From what I've read, I could use a wilcox.test on pairs of conditions and adjust the p level, but is there something in R that does a better job/automates this. I've seen references to the npmc package but that doesn't seem to do what I'm looking for, because it only accepts a data frame with two columns - i.e. there's no way to specify grouping/subject identifiers. Thanks, There is a worked example in the coin package for using a permutation test to examine differences after a Friedman test. The authors, Hothorn , Hornik , van de Wiel, and Zeileis, call this method the Wilcoxon-Nemenyi-McDonald-Thompson test and cite: Hollander Wolfe (1999), page 295 http://finzi.psych.upenn.edu/R/library/coin/html/SymmetryTests.html -- 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] Amazon SimpleDB and R
Hi Tim Since we have a package to interface to Amazon's S3 storage system (http://www.omegahat.org/RAmazonS3), I put together an RAmazonDBREST package that uses the REST interface. It is available at http://www.omegahat.org/RAmazonDBREST/ and installable from source via install.packages(RAmazonDBREST, repos = http://www.omegahat.org/R;) As you might infer, at some point we might create a SOAP-based interface. The intent of doing this is to get the infrastructure in place and allow others to play with the interface and add higher-levels to make it more R-esque. It was developed reasonably hastily so there may be issues and it could handle more documentation, but it works for me. D. Tim Shephard wrote: As far as I know there isn't anything available for this, but I thought I'd check before working up something of my own. Is there a way to query Amazon SimpleDB and import the data results directly into R? Cheers, Tim. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] correlation help
Adrian, To find all the correlations between columns of a matrix and to find their individual significance levels (questionable given that you are doing many correlations) use either the rcorr function in the Hmisc package or the corr.test function in the psych package. Bill \At 6:19 PM -0400 9/20/09, Adrian Johnson wrote: thank you john. however, I am finding it difficult to automate on a matrix. Pardon my ignorance in R computing: I do not know how to automate on a matrix. If I do the following it works: x = cor.test(d6[1,],d6[2,]) x Pearson's product-moment correlation data: d6[1, ] and d6[2, ] t = 10.5196, df = 10, p-value = 9.973e-07 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.8520623 0.9883592 sample estimates: cor 0.9576655 If I want to run it on all rows, I do not know how to do it. I tried following, lapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) sapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) for(i in 1:14659){ + k = i+1 + cor.test(d6[i,],d6[k,]) + x = cor.test(d6[i,],d6[k,]) + return(x)} Error: no function to return from, jumping to top level I appreciate your help. thank you. Adrian On Sun, Sep 20, 2009 at 6:17 PM, Adrian Johnson oriolebaltim...@gmail.com wrote: thank you john. however, I am finding it difficult to automate on a matrix. Pardon my ignorance in R computing: I do not know how to automate on a matrix. If I do the following it works: x = cor.test(d6[1,],d6[2,]) x Pearson's product-moment correlation data: d6[1, ] and d6[2, ] t = 10.5196, df = 10, p-value = 9.973e-07 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.8520623 0.9883592 sample estimates: cor 0.9576655 If I want to run it on all rows, I do not know how to do it. I tried following, lapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) sapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) for(i in 1:14659){ + k = i+1 + cor.test(d6[i,],d6[k,]) + x = cor.test(d6[i,],d6[k,]) + return(x)} Error: no function to return from, jumping to top level I appreciate your help. thank you. Adrian On Sun, Sep 20, 2009 at 5:13 PM, John Kane jrkrid...@yahoo.ca wrote: ?cor ?cor.test --- On Sun, 9/20/09, Adrian Johnson oriolebaltim...@gmail.com wrote: From: Adrian Johnson oriolebaltim...@gmail.com Subject: [R] correlation help To: r-help@r-project.org Received: Sunday, September 20, 2009, 5:00 PM Dear group, I have a matrix like the following: Name Sample1 sample2sample3 sample4 . sample(n) nm110.5 13.5 30 31 nm2 8 11 34 29 nm3 9 10.3 27.8 35 nm(j) I want to be able to calculate correlation between all pairs of names. For example (nm1,nm2), (nm1,nm3), (nm1,nmj), (nm2,nm3), (nm2,nmj) Then I want to calculate the significance of correlation using t-score or p-value. I can calculate correlation coeffecient in excel but not significance in both excel and R. I want to be able to do it in R, I appreciate your help. thank you. Ad. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Yahoo! Mail. Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnight http://www.thebulletin.org __ R-help@r-project.org mailing list
[R] Skipping missing files when importing data
Trying to import a bunch of data files named like f001, f002, f999. Some of the files may be missing and the missing files vary from time to time. Used for loop and read.table. When it reaches the missing file (say f100), it shows: Error in file(file, r) : cannot open the connection In addition: Warning message: In file(file, r) : cannot open file 'f100': No such file or directory and the program stops. How can I skip the missing ones and keep the program running? Guess either checking the validity of filenames, or ignore the error message may work. Which functions should be used or any better ideas? -RJ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Skipping missing files when importing data
Try ?file.exists. if (file.exists(fxxx)) { read.table(fxxx) } else { cat(\, fxxx, \ is missing\n, sep = ) } HTH, --sundar On Sun, Sep 20, 2009 at 9:28 PM, jiangrm jian...@gmail.com wrote: Trying to import a bunch of data files named like f001, f002, f999. Some of the files may be missing and the missing files vary from time to time. Used for loop and read.table. When it reaches the missing file (say f100), it shows: Error in file(file, r) : cannot open the connection In addition: Warning message: In file(file, r) : cannot open file 'f100': No such file or directory and the program stops. How can I skip the missing ones and keep the program running? Guess either checking the validity of filenames, or ignore the error message may work. Which functions should be used or any better ideas? -RJ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.