Re: [R] Fortran and long integers
Tsjerk Wassenaar wrote: Yes, thnx... Typo :$ On Mon, Feb 7, 2011 at 8:23 AM, Berend Hasselman b...@xs4all.nl wrote: Tsjerk Wassenaar wrote: Hi, Does it alleviate things if you rewrite the sums to avoid large products? For I even: J+I*(N-I/2)-(N-I/2) Shouldn't that be J+I*(N-I/2)-(N+I/2) ? This only helps to some extent. If you set I=N and J=N then with N somewhere between 113000 and 114000 ioffset will turn negative. Berend -- View this message in context: http://r.789695.n4.nabble.com/Fortran-and-long-integers-tp3263054p3263668.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] Fortran and long integers
This only helps to some extent. If you set I=N and J=N then with N somewhere between 113000 and 114000 ioffset will turn negative. Thanks to all for suggestions. N=113000 is by far out of range since (as far as I can tell) the distance structure would be longer than R can presently handle, but please correct me if I'm wrong. Peter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mle question
Hello, is there somebody who can help me with my question (see below)? Antje On 1 February 2011 09:09, Antje Niederlein niederlein-rs...@yahoo.de wrote: Hello, I tried to use mle to fit a distribution(zero-inflated negbin for count data). My call is very simple: mle(ll) ll() takes the three parameters, I'd like to be estimated (size, mu and prob). But within the ll() function I have to judge if the current parameter-set gives a nice fit or not. So I have to apply them to observation data. But how does the method know about my observed data? The mle()-examples define this data outside of this method and it works. For a simple example, it was fine but when it comes to a loop (tapply) providing different sets of observation data, it doesn't work anymore. I'm confused - is there any way to do better? Here is a little example which show my problem: # R-code - lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle(ll) coef(fit) }) Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Confused
Hi Im confused by one thing, and if someone can explain it I would be a happy rev(strsplit(hej,NULL)) [[1]] [1] h e j lapply(strsplit(hej,NULL),rev) [[1]] [1] j e h Why dossent the first one work? What is it in R that fails so to say that you need to use lapply for it to get the correct output. -- View this message in context: http://r.789695.n4.nabble.com/Confused-tp3263700p3263700.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] Giving vector of colors to line in plots
On 2011-02-06 22:15, statmobile wrote: Hey all, I can't for the life of me figure out what I'm missing here. I'm trying to change the color of the line in a time series type plot. I can change the point colors and symbols no problem, but for some reason the colors do not get passed to the lines, regardless of if I do type=b or type=l. The sample code I'm using is below. Because lines are not segments. For what you want to do, you'll have to use the segments() function. Perhaps there's something in the plotrix package. Peter Ehlers Any help would be greatly appreciated. Also, please CC me, as I only get daily summaries of the mailing list. Thanks, Brian ## Changing plot attributes through the plot set.seed(33) x- rpois(7,lambda=7) y- rpois(7,lambda=5) cols.x- c(rep(black,2),rep(red,3),rep(black,2)) cols.y- c(rep(blue,3),rep(yellow,2),rep(blue,2)) points.x- c(rep(x,2),rep(O,3),rep(x,2)) points.y- c(rep(8,3),rep(17,2),rep(8,2)) plot(x,col=cols.x,pch=points.x,type=b,ylim=c(0,15)) points(y,col=cols.y,pch=points.y,type=b) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Confused
On 2011-02-07 00:18, Joel wrote: Hi Im confused by one thing, and if someone can explain it I would be a happy rev(strsplit(hej,NULL)) [[1]] [1] h e j lapply(strsplit(hej,NULL),rev) [[1]] [1] j e h Why dossent the first one work? What is it in R that fails so to say that you need to use lapply for it to get the correct output. See if this helps to see what's happening in the first case: L - list(fruit=c(apple, orange)) L rev(L) L - list(fruit=c(apple, orange), nuts=c(pecan, almond)) L rev(L) lapply(L, rev) For your second case, lapply() applies FUN to the pieces of the list. Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Confused
On 07-Feb-11 08:18:49, Joel wrote: Hi Im confused by one thing, and if someone can explain it I would be a happy rev(strsplit(hej,NULL)) [[1]] [1] h e j lapply(strsplit(hej,NULL),rev) [[1]] [1] j e h Why dossent the first one work? What is it in R that fails so to say that you need to use lapply for it to get the correct output. -- WHat's causing the confusion in your example is that the result of strsplit(hej,NULL) consists of only one element. This is because (see ?strsplit) the value of strsplit is a *list*. For example, if you submit a character *vector* (with 2 elements hej and nej) to your rev(strsplit(...)): strsplit(c(hej,nej),NULL) # [[1]] # [1] h e j # # [[2]] # [1] n e j rev(strsplit(c(hej,nej),NULL)) # [[1]] # [1] n e j # # [[2]] # [1] h e j you now get a list with 2 elements [[1]]and [[2]], and rev() now outputs these in reverse order. With your character vector hej which has only one element, you get a list with only one element, and the rev() of this is exactly the same. Your lapply(strsplit(hej,NULL),rev) applies rev() to each element of the list returned by strsplit, so even if it only has one element that element gets its contents reversed. lapply(strsplit(c(hej,nej),NULL),rev) # [[1]] # [1] j e h # # [[2]] # [1] j e n Hoping this helps! Ted. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 07-Feb-11 Time: 08:56:55 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: multivariate regression
Hi: You don't state the test for which you want the p-value, and to reiterate what Dr. Ligges asked in response to your earlier post, how do you propose to define a single R^2 measure? One may be able to answer your question re an overall significance test using the anova() function: Y-matrix(c(3,5,6,3,4,2,4,5,3,2,3,5,6,3,4,2,4,5,3,2,3,5,6,3,4,2,4,5,3,2), nrow = 10, ncol=3, byrow=TRUE) X-matrix(c(42,54,67,76,45,76,54,87,34,65), nrow = 10, ncol=1, byrow=TRUE) m - lm(Y~X) anova(m) # Default is Pillai's trace Analysis of Variance Table Df Pillai approx F num Df den DfPr(F) (Intercept) 1 0.97219 69.917 3 6 4.656e-05 *** X1 0.364151.145 3 60.4041 Residuals8 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 anova(m, test = 'Wilks')# Wilks' lambda Analysis of Variance Table Df Wilks approx F num Df den DfPr(F) (Intercept) 1 0.02781 69.917 3 6 4.656e-05 *** X1 0.635851.145 3 60.4041 Residuals8 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Roy's maximum root test and the Lawley-Hotelling statistic can also be applied by using 'Roy' or 'Hotelling' as the value of the test = argument of anova.lm(). HTH, Dennis On Sun, Feb 6, 2011 at 11:08 PM, Deniz SIGIRLI denizsigi...@hotmail.comwrote: #I have got 3 dependent variables: Y-matrix(c(3,5,6,3,4,2,4,5,3,2,3,5,6,3,4,2,4,5,3,2,3,5,6,3,4,2,4,5,3,2), nrow = 10, ncol=3, byrow=TRUE) #I've got one independent variable: X-matrix(c(42,54,67,76,45,76,54,87,34,65), nrow = 10, ncol=1, byrow=TRUE) summary(lm(Y~X)) and the result is as below: Response Y1 : Call: lm(formula = Y1 ~ X) Residuals: Min 1Q Median 3Q Max -1.5040 -0.8838 -0.3960 1.1174 2.1162 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 4.435071.70369 2.603 0.0315 * X -0.012250.02742 -0.447 0.6668 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Residual standard error: 1.401 on 8 degrees of freedom Multiple R-squared: 0.02435,Adjusted R-squared: -0.09761 F-statistic: 0.1997 on 1 and 8 DF, p-value: 0.6668 Response Y2 : Call: lm(formula = Y2 ~ X) Residuals: Min 1Q Median 3Q Max -1.4680 -0.8437 -0.2193 0.9050 1.9960 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 1.379941.50111 0.9190.385 X0.038670.02416 1.6010.148 Residual standard error: 1.235 on 8 degrees of freedom Multiple R-squared: 0.2426, Adjusted R-squared: 0.1479 F-statistic: 2.562 on 1 and 8 DF, p-value: 0.1481 Response Y3 : Call: lm(formula = Y3 ~ X) Residuals: Min 1Q Median 3Q Max -1.7689 -0.7316 -0.1943 1.1448 2.0933 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 4.389131.70626 2.5720.033 * X -0.011490.02746 -0.4180.687 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Residual standard error: 1.403 on 8 degrees of freedom Multiple R-squared: 0.0214, Adjusted R-squared: -0.1009 F-statistic: 0.175 on 1 and 8 DF, p-value: 0.6867 There are 3 F statistics, R2 and p-values. But I want just one R2 and pvalue for my multivariate regression model. Date: Fri, 4 Feb 2011 08:23:39 -0500 From: jsor...@grecc.umaryland.edu To: denizsigi...@hotmail.com; r-help@r-project.org Subject: Re: [R] multivariate regression Please help us help you. Follow the posting rules and send us a copy of your code and output. John John Sorkin Chief Biostatistics and Informatics Univ. of Maryland School of Medicine Division of Gerontology and Geriatric Medicine jsor...@grecc.umaryland.edu -Original Message- From: Deniz SIGIRLI denizsigi...@hotmail.com To: r-help@r-project.org Sent: 2/4/2011 7:54:56 AM Subject: [R] multivariate regression How can I run multivariate linear regression in R (I have got 3 dependent variables and only 1 independent variable)? I tried lm function, but it gave different R2 and p values for every dependent variable. I need one R2 and p value for the model. [[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. Confidentiality Statement: This email message, including any attachments, is for ...{{dropped:5}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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
[R] [R-pkgs] R package hypred: Simulation of genomic data in applied genetics
Dear useRs, I am glad to announce that the new R package hypred, initial version 0.1, is now available on CRAN. hypred is a package for simulating high-density SNP data. Its main function, hypredRecombine is intended to be used as a Software tool in larger programs that simulate complex populations. The focus of the package is on producing data for genomic applications in applied genetics (such as genomic selection/prediction), but I expect that it can be useful in related fields as well. Please see the included vignette and the manual for more details. Don't hesitate sending bug reports; and I would appreciate receiving some comments and feedback from users. Best regards Frank. -- Frank Technow University of Hohenheim 350 Institute of Plant Breeding, Seed Sciences, and Population Genetics 70593 Stuttgart/Germany Phone: 0049 711 459 23544 e-mail: frank.tech...@uni-hohenheim.de or frank.tech...@gmx.net ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] FW: multivariate regression
Deniz, There are 3 F statistics, R2 and p-values. But I want just one R2 and pvalue for my multivariate regression model. Which is as it should. Maybe the following will help, but we are making the dependent variables the independent variables, which may or may not be what you really have in mind. (Otherwise, as Uwe has said, you need to specify how this one R^2 / p-value should be defined from your point of view.) summary(lm(X~Y)) Call: lm(formula = X ~ Y) Residuals: Min 1Q Median 3Q Max -20.329 -9.770 0.271 11.167 18.986 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 65.663 31.464 2.0870.082 . Y1-4.232 4.616 -0.9170.395 Y2 6.846 4.181 1.6370.153 Y3-4.145 4.616 -0.8980.404 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 16.64 on 6 degrees of freedom Multiple R-squared: 0.3641, Adjusted R-squared: 0.04622 F-statistic: 1.145 on 3 and 6 DF, p-value: 0.4041 -- View this message in context: http://r.789695.n4.nabble.com/multivariate-regression-tp3260141p3263712.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] multiple imputation manually
Hi, I want to impute the missing values in my data set multiple times, and then combine the results (like multiple imputation, but manually) to get a mean of the parameter(s) from the multiple imputations. Does anyone know how to do this? I have the following script: y1 - rnorm(20,0,3) y2 - rnorm(20,3,3) y3 - rnorm(20,3,3) y4 - rnorm(20,6,3) y - c(y1,y2,y3,y4) x1 - 1+2*y1+ rnorm(20,0,8) x2 - 1+2*y2+ rnorm(20,0,8) x3 - 1+2*y3+ rnorm(20,0,8) x4 - 1+2*y4+ rnorm(20,0,8) x - c(x1,x2,x3,x4) mcar.y - rep(NA,80) y.mis - rep(NA,80) df - data.frame(y=y, y.mis=y.mis, mcar.y=mcar.y, x=x) df$y.mis - df$y for (j in 1:80) { df$mcar.y - rbinom(80,1,0.15) } ind0 - which(df$mcar.y==0) ind1 - which(df$mcar.y==1) if (length(ind0) 68) { df$mcar.y[sample(ind0, length(ind0) - 68)] - 1 } else { df$mcar.y[sample(ind1, 68 - length(ind0))] - 0 } df$y.mis[df$mcar.y==1] - NA This gives me data sets with missing values completely at random. Now I would like to apply single imputation: library(Hmisc) lm.y - lm(df$y.mis~df$x,data=df); lm.y library(arm) pred.y - rnorm(length(df$y), predict (lm.y, df), sigma.hat(lm.y)) y.imp- df$y.mis impute - function (y, y.impute) { ifelse (is.na(y), y.impute, y) } y.imp - impute (y.imp, pred.y) df - data.frame(df$y, df$y.mis, pred.y, y.imp, x) and repeat this imputation process a couple of times (say, 5 times) for each data set. If I, however, have run this imputation-script (for 1 incomplete data set), my data set is already complete. I would like to get back to the incompleted data set used before, and repeat the single imputation process four times with the same incomplete data set (so I can calculate some mean of parameters from the 5 imputed data sets later on). But how? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/multiple-imputation-manually-tp3263786p3263786.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] Giving vector of colors to line in plots
On 02/07/2011 05:15 PM, statmobile wrote: Hey all, I can't for the life of me figure out what I'm missing here. I'm trying to change the color of the line in a time series type plot. I can change the point colors and symbols no problem, but for some reason the colors do not get passed to the lines, regardless of if I do type=b or type=l. The sample code I'm using is below. Hi Brian, Have a look at the color.scale.lines function (plotrix). This may allow you to do what you want. 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] Image to plot
On 02/07/2011 06:37 PM, Alaios wrote: Dear all I would like to plot the contents of a matrix as an Image. I found this code here http://www.phaget4.org/R/image_matrix.html but this is not only what I want. Instead of having inside every cell the color of the cell it would be nice to have also the arithmetic value over the background color. Having only the color sometimes does not make it clear to understand what is the value each cell has .. so I was thinking to combine colors and text inside every cell. Hi Alex, Check out color2D.matplot (plotrix) in particular the show.values argument. 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.
[R] mle question
Hello, is there somebody who can help me with my question (see below)? Antje On 1 February 2011 09:09, Antje Niederlein niederlein-rs...@yahoo.de wrote: Hello, I tried to use mle to fit a distribution(zero-inflated negbin for count data). My call is very simple: mle(ll) ll() takes the three parameters, I'd like to be estimated (size, mu and prob). But within the ll() function I have to judge if the current parameter-set gives a nice fit or not. So I have to apply them to observation data. But how does the method know about my observed data? The mle()-examples define this data outside of this method and it works. For a simple example, it was fine but when it comes to a loop (tapply) providing different sets of observation data, it doesn't work anymore. I'm confused - is there any way to do better? Here is a little example which show my problem: # R-code - lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle(ll) coef(fit) }) Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] different results in MASS's mca and SAS's corresp
On Sat, 2011-02-05 at 23:39 -0600, Paul Johnson wrote: On Sat, Feb 5, 2011 at 9:19 AM, David Winsemius dwinsem...@comcast.net wrote: snip / cbind(scalermca[,1] * 0.827094, scalermca[,2] * -0.7644828) [,1][,2] 1 1.06070017 -0.8154 2 0.77057891 0.63456780 3 1.07031764 -1.30675217 4 1.07031764 -1.30675217 5 0.23075886 0.90002547 6 0.6943 0.60993995 7 0.10530240 0.78445402 8 -0.27026650 0.44225049 9 0.13426089 1.15670532 10 0.11861965 0.64778456 11 0.23807570 1.21775202 12 1.01156703 -0.01927226 13 0.28051938 -0.59805897 14 -1.17343686 -0.27122981 15 -0.83838041 -0.64003061 16 -0.05453708 -0.22925816 17 -0.91732401 -0.49899374 18 -0.92694148 -0.00774156 19 -1.30251038 -0.34994509 20 -1.30251038 -0.34994509 So, that does reproduce SAS exactly. And I'm a little frustrated I can't remember the matrix command to get that multiplication done without cbinding the 2 columns together that way. You might have been thinking of sweep(): sweep(scalermca[,1:2], 2, c(0.827094,-0.7644828), *) snip/ HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] series of boxplots
hi group, imagine the following data frame df: 1 2 3 4 ... A 5 1 .. A 4 3 .. A 3 4 .. B 7 9 .. B 8 1 .. B 6 8 .. I tried the following and some variations to plot this matrix as boxplots: boxplot(df[1:3,2]~df[1:3,1], xlim=c(1,10)) par(new=TRUE) boxplot(cpd12[4:6,2]~df[1:3,1], xlim=c(2,10)) par(new=TRUE) boxplot(df[1:3,3]~df[1:3,1], xlim=c(1,10)) par(new=TRUE) boxplot(cpd12[4:6,3]~df[1:3,1], xlim=c(2,10)) can anybody help? Cheers -- View this message in context: http://r.789695.n4.nabble.com/series-of-boxplots-tp3263938p3263938.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] aggregate function - na.action
Looking at the timings by each stage may help : system.time(dt - data.table(dat)) user system elapsed 1.200.281.48 system.time(setkey(dt, x1, x2, x3, x4, x5, x6, x7, x8)) # sort by the 8 columns (one-off) user system elapsed 4.720.945.67 system.time(udt - dt[, list(y = sum(y, na.rm = TRUE)), by = 'x1, x2, x3, x4, x5, x6, x7, x8']) user system elapsed 2.000.212.20 # compared to 11.07s data.table doesn't have a custom data structure, so it can't be that. data.table's structure is the same as data.frame i.e. a list of vectors. data.table inherits from data.frame. It *is* a data.frame, too. The reasons it is faster in this example include : 1. Memory is only allocated for the largest group. 2. That memory is re-used for each group. 3. Since the data is ordered contiguously in RAM, the memory is copied over in bulk for each group using memcpy in C, which is faster than a for loop in C. Page fetches are expensive; they are minimised. This is explained in the documentation, in particular the FAQs. This example is quite small, but the concept scales to larger sizes i.e. the difference widens further as n increases. http://datatable.r-forge.r-project.org/ Matthew Hadley Wickham had...@rice.edu wrote in message news:aanlktim6drfjxqrsqlxof1ut6xr_bshqdbgpktmed...@mail.gmail.com... There's definitely something amiss with aggregate() here since similar functions from other packages can reproduce your 'control' sum. I expect ddply() will have some timing issues because of all the subgrouping in your data frame, but data.table did very well and the summaryBy() function in the doBy package did OK: Well, if you use the right plyr function, it works just fine: system.time(count(dat, c(x1, x2, x3, x4, x4, x5, x6, x7, x8), y)) # user system elapsed # 9.754 1.314 11.073 Which illustrates something that I've believed for a while about data.table - it's not the indexing that speed things up, it's the custom data structure. If you use ddply with data frames, it's slow because data frames are slow. I think the right way to resolve this is to to make data frames more efficient, perhaps using some kind of mutable interface where necessary for high-performance operations. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University 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.
Re: [R] Image to plot
Thanks a lot. That did the trick :) --- On Mon, 2/7/11, Jim Lemon j...@bitwrit.com.au wrote: From: Jim Lemon j...@bitwrit.com.au Subject: Re: [R] Image to plot To: Alaios ala...@yahoo.com Cc: R-help@r-project.org Date: Monday, February 7, 2011, 9:39 AM On 02/07/2011 06:37 PM, Alaios wrote: Dear all I would like to plot the contents of a matrix as an Image. I found this code here http://www.phaget4.org/R/image_matrix.html but this is not only what I want. Instead of having inside every cell the color of the cell it would be nice to have also the arithmetic value over the background color. Having only the color sometimes does not make it clear to understand what is the value each cell has .. so I was thinking to combine colors and text inside every cell. Hi Alex, Check out color2D.matplot (plotrix) in particular the show.values argument. 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] using character vector as input argument to setkey (data.tablepakcage)
Hi Sean, Try : key(test.dt) = c(a,b) Btw, the posting guide asks you to contact the maintainer of the package before r-help. Otherwise r-help would fill up with posts about 2000+ packages (I guess is the reason). In this case maintainer(data.table) returns datatable-h...@lists.r-forge.r-project.org (cc'd) where you will be very welcome. Matthew __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fortran and long integers
On Mon, 7 Feb 2011, Berend Hasselman b...@xs4all.nl wrote: The overflow is not caused by 16 bits integers. I'm quite sure the OP is using 32 bit integers. The overflow is caused by the multiplication N*(i-1) and/or i*(i+1). In Fortran there's not much you can do about this unless your compiler supports larger integers. Most modern Fortran compilers offer larger integers. The selected_int_kind() function can be used to find the appropriate integer KIND for your compiler. Most, like gfortran, use kind=8 for long integer integer (kind=8) :: i16 write(*,*) huge(i16) 9223372036854775807 -- | David Duffy (MBBS PhD) ,-_|\ | email: dav...@qimr.edu.au ph: INT+61+7+3362-0217 fax: -0101 / * | Epidemiology Unit, Queensland Institute of Medical Research \_,-._/ | 300 Herston Rd, Brisbane, Queensland 4029, Australia GPG 4D0B994A v __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] matrix is not of full rank error in package tgp
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi I want to use the package tgp with its sens() function to cunduct a sensitivity analysis of an ecological simulation model and six independent input parameter. I conducted 10.000 simulations based on a Latin Hypercube design to sample the whole parameter range. Now I want to use the sens function to conduct the sensitivity analysis. I use the following call: SA - sens(X = X, Z = Z, nn.lhs = 600, model = bgpllm, verb = 2) where X are my 6 input parameter, and Z is the response variable. My problem is, that I get a X[,1:6]-matrix is not of full rank error. I must admit ignorance, as I neither know what a matrix of full rank is, and how I can fix this so that I can conduct a sensitivity analysis by using sens(). Any help is appreciated, Thanks, Rainer - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel:+33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1P7Q4ACgkQoYgNqgF2egohzgCfYCHjcjsQz/v9KrJAr63etgGZ IdUAn0I1CdV0cLis4a4zqGmHjnm6lzwJ =bFUt -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] can I use the output of a neural network as the fitness function of genetic algorithm?
Hi Everyone, I need to use genetic algorithm to find the minimum. The problem is, I cannot define the fitness function, but I can build a neural network from the input data and use the output as a fitness function. Can this be done? The other problem is, I know there are a few package in R related to GA. So far I know all of them take a specific function as fitness function, is there any package can Solve my problem? Many thanks Ying [[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] Image to plot
Hello again, actually I am trying to store many files to hard disk and thus I want to 1.create new plot 2.save it 3. close it I have successfuly completed 1 and 2 but when I try to close it color2D.matplot(tespa,redrange=c(0,1),greenrange=c(0,.5),bluerange=c(0,.5),xlab=x,ylab=y,main=sprintf(TestTitlos %d,2),show.legend=TRUE,show.values=TRUE) dev.off(dev.cur()) it doesnot. it seems for me that it takes some time until color2D.matplot is printed out and thus when dev.off(dev.cur()) is issued has nothing to close. What should I try to do for that? Best Regards Alex --- On Mon, 2/7/11, Jim Lemon j...@bitwrit.com.au wrote: From: Jim Lemon j...@bitwrit.com.au Subject: Re: [R] Image to plot To: Alaios ala...@yahoo.com Cc: R-help@r-project.org Date: Monday, February 7, 2011, 9:39 AM On 02/07/2011 06:37 PM, Alaios wrote: Dear all I would like to plot the contents of a matrix as an Image. I found this code here http://www.phaget4.org/R/image_matrix.html but this is not only what I want. Instead of having inside every cell the color of the cell it would be nice to have also the arithmetic value over the background color. Having only the color sometimes does not make it clear to understand what is the value each cell has .. so I was thinking to combine colors and text inside every cell. Hi Alex, Check out color2D.matplot (plotrix) in particular the show.values argument. 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] aggregate function - na.action
On Mon, Feb 7, 2011 at 5:54 AM, Matthew Dowle mdo...@mdowle.plus.com wrote: Looking at the timings by each stage may help : system.time(dt - data.table(dat)) user system elapsed 1.20 0.28 1.48 system.time(setkey(dt, x1, x2, x3, x4, x5, x6, x7, x8)) # sort by the 8 columns (one-off) user system elapsed 4.72 0.94 5.67 system.time(udt - dt[, list(y = sum(y, na.rm = TRUE)), by = 'x1, x2, x3, x4, x5, x6, x7, x8']) user system elapsed 2.00 0.21 2.20 # compared to 11.07s data.table doesn't have a custom data structure, so it can't be that. data.table's structure is the same as data.frame i.e. a list of vectors. data.table inherits from data.frame. It *is* a data.frame, too. The reasons it is faster in this example include : 1. Memory is only allocated for the largest group. 2. That memory is re-used for each group. 3. Since the data is ordered contiguously in RAM, the memory is copied over in bulk for each group using memcpy in C, which is faster than a for loop in C. Page fetches are expensive; they are minimised. But this is exactly what I mean by a custom data structure - you're not using the usual data frame API. Wouldn't it be better to implement these changes to data frame so that everyone can benefit? Or is it just too specialised to this particular case (where I guess you're using that the return data structure of the summary function is consistent)? Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University 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.
Re: [R] Confidence interval based on MLE
On 2011-2-6 22:56, Ben Bolker wrote: Jinsong Zhaojszhaoat yeah.net writes: Hi there, I have fitted a sample (with size 20) to a normal and/or logistic distribution using fitdistr() in MASS or fitdist() in fitdistrplus package. It's easy to get the parameter estimates. Now, I hope to report the confidence interval for those parameter estimates. However, I don't find a function that could give the confidence interval in R. I hope to write a function, however, I don't find some detailed information on the CI based on MLE. Would you please to give me some hints on the CI calculation based on MLE? Well, for the normal distribution I believe that the standard-error- based confidence intervals are the same as those based on the MLE, but in general I would suggest something along these lines: library(bbmle) z- rnorm(20) m- mle2(z~dnorm(mean=mu,sd=sd),start=list(mu=0,sd=1),data=data.frame(z)) Warning message: In dnorm(x, mean, sd, log) : NaNs produced confint(m) Profiling... 2.5 % 97.5 % mu -0.07880835 0.985382 sd 0.87314467 1.633600 Thank you very much for your kindly help and the way to get MLE through bbmle package. It works well. I have a interval related question. I have a sample data set, with size 20 or less. And I fit it to a three parameter distribution, e.g., a triangular distribution (oops, it cannot fitted by mle2 :-(). I get the quantile, q, for a given probability, p. Then, I hope to get the confidence (or prediction?) interval for the quantile, q. However, I don't know how to do. I refer to some books on ecological data analysis. There's a explicit formula for CI to the normal distribution's q, based on delta method or Fieller's theorem. (And I think they should work for logistic distribution). But I don't find any thing that for other distribution. BTW, is it possible to get a interval of p for a given q? Although, it's not a normal way in the view of statistics, it has a lot applications. Any suggestions or comments will be really appreciated. Thanks in advance. Regards, Jinsong __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] tri-cube and gaussian weights in loess
From what I understand, loess in R uses the standard tri-cube function. SAS/INSIGHT offers loess with Gaussian weights. Is there a function in R that does the same? Also, can anyone offer any references comparing properties between tri-cube and Gaussian weights in LOESS? Thanks. - André -- View this message in context: http://r.789695.n4.nabble.com/tri-cube-and-gaussian-weights-in-loess-tp3263934p3263934.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] Subsampling out of site*abundance matrix
Also, I really appreciate you explaining why you used factor. I'm still not quite sure what set.seed does (i read ?set.seed) or why you chose 123... but it and the function below work, so that is all that matters. :) randSub - function(L1, s.size) { set.seed(123) samptbl - apply(L1, 1, function(x) sample(colnames(L1), s.size, prob=x, replace=TRUE) ) sampdf - as.data.frame(samptbl) sampdf1 -vector(list) for(i in 1:nrow(L1)) { sampdf1[[i]] - factor(sampdf[[i]], levels= colnames(L1)) } out - t(sapply(sampdf1, table)) } -- View this message in context: http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3264251.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] uniroot
Thanks for your advice. There was an error in the equation that is was copying. Doug -- View this message in context: http://r.789695.n4.nabble.com/uniroot-tp3260090p3264288.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 efficiently extract elements of a list?
Dear R helper, I wonder whether there is a quick way to extract some elements for a list. for a vector we can do the following vec - seq(3) names(vec) - LETTERS[1:3] vec[c(1,3)] vec[c('A','C')] But for a list, test.l - list(c(1,3),array(NA,c(1,2)),array(0,c(2,3))) names(test.l)-LETTERS[1:3] The following does not work. is there some command (I was thinking of do.call) that can do the job? test.l[[c('A','B')]] test.l[[c(1,3)]] do.call('[',c(test.l,c(1,3))) do.call('[[',c(test.l,c(1,3))) do.call('[',c(test.l,c('A','C'))) do.call('[[',c(test.l,c('A','C'))) Thanks in advance. -Sean [[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] waveThresh plot axis
Dear, I am using WaveTresh for Haar Wavelets. It works all fine exept when I want to adjust the axis on the wavelet coefficient plot: input:wlh_ponds-wd(input_waves[,1], family=DaubExPhase,filter.number=1) plot: plot(wlh_ponds,scaling=by.level) My problem is twofold= -I want the original x-axis of the data on that plot, not 1/2 of the axis. This would make my plot more clear for comparison with the original data series. -I want to cut of a part of the graph because I added columns with 0's to make my series 2^n. Now I want to cut them of again. It may look like a simple problem, but things like xlim don't work with this kind of plot. Thank you, Best wishes Eva Ampe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] FW: multivariate regression
The test is manova. I tried to use manova() function, I used the code below:fit - manova(Y ~ X)summary(fit, test=Wilks)but I get p values for intercept and regression coefficient as in anova() function, not for the hull model. Date: Mon, 7 Feb 2011 00:57:43 -0800 Subject: Re: [R] FW: multivariate regression From: djmu...@gmail.com To: denizsigi...@hotmail.com CC: r-help@r-project.org Hi: You don't state the test for which you want the p-value, and to reiterate what Dr. Ligges asked in response to your earlier post, how do you propose to define a single R^2 measure? One may be able to answer your question re an overall significance test using the anova() function: Y-matrix(c(3,5,6,3,4,2,4,5,3,2,3,5,6,3,4,2,4,5,3,2,3,5,6,3,4,2,4,5,3,2), nrow = 10, ncol=3, byrow=TRUE) X1-matrix(c(42,54,67,76,45,76,54,87,34,65), nrow = 10, ncol=1, byrow=TRUE)X2-matrix(c(38,21,67,76,45,76,54,87,34,65), nrow = 10, ncol=1, byrow=TRUE) m - lm(Y~X) anova(m) # Default is Pillai's trace Analysis of Variance Table Df Pillai approx F num Df den DfPr(F) (Intercept) 1 0.97219 69.917 3 6 4.656e-05 *** X1 0.364151.145 3 60.4041 Residuals8 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 anova(m, test = 'Wilks')# Wilks' lambda Analysis of Variance Table Df Wilks approx F num Df den DfPr(F) (Intercept) 1 0.02781 69.917 3 6 4.656e-05 *** X1 0.635851.145 3 60.4041 Residuals8 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Roy's maximum root test and the Lawley-Hotelling statistic can also be applied by using 'Roy' or 'Hotelling' as the value of the test = argument of anova.lm(). HTH, Dennis On Sun, Feb 6, 2011 at 11:08 PM, Deniz SIGIRLI denizsigi...@hotmail.com wrote: #I have got 3 dependent variables: Y-matrix(c(3,5,6,3,4,2,4,5,3,2,3,5,6,3,4,2,4,5,3,2,3,5,6,3,4,2,4,5,3,2), nrow = 10, ncol=3, byrow=TRUE) #I've got one independent variable: X-matrix(c(42,54,67,76,45,76,54,87,34,65), nrow = 10, ncol=1, byrow=TRUE) summary(lm(Y~X)) and the result is as below: Response Y1 : Call: lm(formula = Y1 ~ X) Residuals: Min 1Q Median 3Q Max -1.5040 -0.8838 -0.3960 1.1174 2.1162 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 4.435071.70369 2.603 0.0315 * X -0.012250.02742 -0.447 0.6668 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Residual standard error: 1.401 on 8 degrees of freedom Multiple R-squared: 0.02435,Adjusted R-squared: -0.09761 F-statistic: 0.1997 on 1 and 8 DF, p-value: 0.6668 Response Y2 : Call: lm(formula = Y2 ~ X) Residuals: Min 1Q Median 3Q Max -1.4680 -0.8437 -0.2193 0.9050 1.9960 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 1.379941.50111 0.9190.385 X0.038670.02416 1.6010.148 Residual standard error: 1.235 on 8 degrees of freedom Multiple R-squared: 0.2426, Adjusted R-squared: 0.1479 F-statistic: 2.562 on 1 and 8 DF, p-value: 0.1481 Response Y3 : Call: lm(formula = Y3 ~ X) Residuals: Min 1Q Median 3Q Max -1.7689 -0.7316 -0.1943 1.1448 2.0933 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 4.389131.70626 2.5720.033 * X -0.011490.02746 -0.4180.687 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Residual standard error: 1.403 on 8 degrees of freedom Multiple R-squared: 0.0214, Adjusted R-squared: -0.1009 F-statistic: 0.175 on 1 and 8 DF, p-value: 0.6867 There are 3 F statistics, R2 and p-values. But I want just one R2 and pvalue for my multivariate regression model. Date: Fri, 4 Feb 2011 08:23:39 -0500 From: jsor...@grecc.umaryland.edu To: denizsigi...@hotmail.com; r-help@r-project.org Subject: Re: [R] multivariate regression Please help us help you. Follow the posting rules and send us a copy of your code and output. John John Sorkin Chief Biostatistics and Informatics Univ. of Maryland School of Medicine Division of Gerontology and Geriatric Medicine jsor...@grecc.umaryland.edu -Original Message- From: Deniz SIGIRLI denizsigi...@hotmail.com To: r-help@r-project.org Sent: 2/4/2011 7:54:56 AM Subject: [R] multivariate regression How can I run multivariate linear regression in R (I have got 3 dependent variables and only 1 independent variable)? I tried lm function, but it gave different R2 and p values for every dependent variable. I need one R2 and p value for the model. [[alternative HTML version deleted]] __
[R] How to mix copulas in R
Hello, I would like to compute a Gumbel-Clayton mix copula in R. Does anyone know how to do it? I use the package copula and fcopulae but I don't find any function to mix different copulas. If anyone could give me some advices or know how to compute a mix of copulas in R, that would be great. Thank you. Best, R [[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] Unbalanced Mixed Linear Models With Nested Stratum
Hi folks, I have a dataset from a trial measuring the subjects' pupils. There are many measurements, all of which must be analysed in a similar fashion; so if I get the analysis right for one of them, I've got them all. For simplicity, let us call any measurement we may be interested as response. The study design is an unbalanced latin square, with 5 periods, 5 treatments and 6 subjects. Each subject has two measurements: left and right eyes. The model is as follows, with : denoting interaction... Fixed Effects = (Subject + Period + Dose):Eye Random Effects = Subject:Period + Subject:Period:Eye My main question is how to make this happen in R. I know that aov is not suitable. If you need any more information, I will do my best to provide it to the best of my knowledge. I'm sort of a new user to statistical software - I've only used R for 3 months so far. So any additional tips would be greatly appreciated. Thanks. :) -- View this message in context: http://r.789695.n4.nabble.com/Unbalanced-Mixed-Linear-Models-With-Nested-Stratum-tp3263969p3263969.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] overlapping moving windows
Dear all, I have a systematic and spatial organized matrix like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 in which every number is a species. I would create a moving overlapping window to resample, at different scale, my plants species data matrix with every possible combination. In short, I would obtain an output matrix like this: resample species 1 1 1 11 1 2 1 12 2 2 2 12 2 3 2 13 3 3 3 13 3 4 3 14 etc can anybody help? Cheers -- View this message in context: http://r.789695.n4.nabble.com/overlapping-moving-windows-tp3264076p3264076.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] Where command in ctree (party)
Hello, I need to classify (i.e., export a vector with terminal node id's) new cases using a ctree (party package) model based on different cases (learning sample). I tried the where command with the following syntax: where(tree, newdata=data2) expecting to get terminal nodes of data2 cases based on rules of tree model (data1 as learning sample). However it returned the following error message: Error in checkData(oldData, RET) : Classes of new data do not match original data Party documentation states that I can use this command both for learning sample (newdata=NULL) or new observations. What am I doing wrong? Best wishes Joao Daniel -- View this message in context: http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p3264187.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] Extract number from string
Dear R Users, if I have a string as follows x-jsda23tth How can I extract out 23 as a numeral? I found substr(x,5,6) but, this doesnt work if the number of alphabets differ. This is another example where the numbers need to be extracted. x-c(jsda23tth,fgd54fgd,j3ngh,gfdjh564) any ideas? This didnt work. grep([/d],x) Thanks, Roy [[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] [Rd] print(...,digits=2) behavior
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 11-02-07 03:56 AM, Martin Maechler wrote: Ben Bolker bbol...@gmail.com on Sat, 5 Feb 2011 15:58:09 -0500 writes: A bug was recently posted to the R bug database (which probably would better have been posted as a query here) as to why this happens: Just a quick clarification: credit for submitting the bug report goes to ansa.a...@gmx.net, not me ... Ben -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1QDBQACgkQc5UpGjwzenMpjgCfZzVfPhVcelZexlV2EQvVJMR4 PFkAn1em/tU+P+kPGgiD29scWsElt0pv =K5GC -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] aggregate function - na.action
Hi Hadley, Does FAQ 1.8 answer that ok ? Ok, I'm starting to see what data.table is about, but why didn't you enhance data.frame in R? Why does it have to be a new package? http://datatable.r-forge.r-project.org/datatable-faq.pdf Matthew Hadley Wickham had...@rice.edu wrote in message news:AANLkTik180p4YmBtR3QUCW7r=fdefxzbxsy3zwtik...@mail.gmail.com... On Mon, Feb 7, 2011 at 5:54 AM, Matthew Dowle mdo...@mdowle.plus.com wrote: Looking at the timings by each stage may help : system.time(dt - data.table(dat)) user system elapsed 1.20 0.28 1.48 system.time(setkey(dt, x1, x2, x3, x4, x5, x6, x7, x8)) # sort by the 8 columns (one-off) user system elapsed 4.72 0.94 5.67 system.time(udt - dt[, list(y = sum(y, na.rm = TRUE)), by = 'x1, x2, x3, x4, x5, x6, x7, x8']) user system elapsed 2.00 0.21 2.20 # compared to 11.07s data.table doesn't have a custom data structure, so it can't be that. data.table's structure is the same as data.frame i.e. a list of vectors. data.table inherits from data.frame. It *is* a data.frame, too. The reasons it is faster in this example include : 1. Memory is only allocated for the largest group. 2. That memory is re-used for each group. 3. Since the data is ordered contiguously in RAM, the memory is copied over in bulk for each group using memcpy in C, which is faster than a for loop in C. Page fetches are expensive; they are minimised. But this is exactly what I mean by a custom data structure - you're not using the usual data frame API. Wouldn't it be better to implement these changes to data frame so that everyone can benefit? Or is it just too specialised to this particular case (where I guess you're using that the return data structure of the summary function is consistent)? Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University 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] Loop to find dates whithin dates
Hello to all, I have two dataframes, the first with two columns sunrise and sunset (for 10 years). Each of these columns is formatted for date time (ex: 01-Jan-2010 15:37:00) In the second data frame I have GPS information and also a date time column (same format ). What I would like to do is a subset of all the rows from the second dataframe that occurred in day time only so between sunrise and sunset. There are thousands of lines from multiple GPS so date time might be repeated in some rows. Any ideas how to accomplish this? Thanks in advance Patrao -- View this message in context: http://r.789695.n4.nabble.com/Loop-to-find-dates-whithin-dates-tp3264180p3264180.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] how to efficiently extract elements of a list?
On 07/02/2011 10:13 AM, Sean Zhang wrote: Dear R helper, I wonder whether there is a quick way to extract some elements for a list. for a vector we can do the following vec- seq(3) names(vec)- LETTERS[1:3] vec[c(1,3)] vec[c('A','C')] But for a list, test.l- list(c(1,3),array(NA,c(1,2)),array(0,c(2,3))) names(test.l)-LETTERS[1:3] The following does not work. is there some command (I was thinking of do.call) that can do the job? test.l[[c('A','B')]] test.l[[c(1,3)]] Use single brackets, i.e. test.l[c('A', 'B')] test.l[c(1,3)] The single bracket is the subsetting operator, which is what you're doing here, since you want a list as the result. Double brackets extract single elements and return whatever type the element is. Duncan Murdoch do.call('[',c(test.l,c(1,3))) do.call('[[',c(test.l,c(1,3))) do.call('[',c(test.l,c('A','C'))) do.call('[[',c(test.l,c('A','C'))) Thanks in advance. -Sean [[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] Extract number from string
On Mon, Feb 7, 2011 at 9:37 AM, Roy Mathew roymathe...@gmail.com wrote: Dear R Users, if I have a string as follows x-jsda23tth How can I extract out 23 as a numeral? I found substr(x,5,6) but, this doesnt work if the number of alphabets differ. This is another example where the numbers need to be extracted. x-c(jsda23tth,fgd54fgd,j3ngh,gfdjh564) any ideas? This didnt work. grep([/d],x) Here are a couple of solutions: as.numeric(gsub(\\D, , x)) [1] 23 54 3 564 library(gsubfn) strapply(x, \\d+, as.numeric, simplify = TRUE) [1] 23 54 3 564 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] can I use the output of a neural network as the fitness function of genetic algorithm?
In SAS, you can output the parameter estimation related to fitness function, I dont know this in R. Once you have output from SAS, you can write down your function and feed them into optim in R to solve your problem. On Mon, Feb 7, 2011 at 5:00 AM, ying zhang ying.zh...@struq.com wrote: Hi Everyone, I need to use genetic algorithm to find the minimum. The problem is, I cannot define the fitness function, but I can build a neural network from the input data and use the output as a fitness function. Can this be done? The other problem is, I know there are a few package in R related to GA. So far I know all of them take a specific function as fitness function, is there any package can Solve my problem? Many thanks Ying [[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. -- Sincerely, Changbin -- Changbin Du DOE Joint Genome Institute Bldg 400 Rm 457 2800 Mitchell Dr Walnut Creet, CA 94598 Phone: 925-927-2856 [[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] Subsampling out of site*abundance matrix
set.seed sets the (pseudo-)random number generator in a predictable state so that you get the same table as I do when running the code, assuming you don't do any other calls to the RNG in the interim. 123 is kind of traditional as a seed for demonstration purposes, but in real analyses you could choose any seed favorite number. -- David. On Feb 7, 2011, at 9:51 AM, B77S wrote: Also, I really appreciate you explaining why you used factor. I'm still not quite sure what set.seed does (i read ?set.seed) or why you chose 123... but it and the function below work, so that is all that matters. :) randSub - function(L1, s.size) { set.seed(123) samptbl - apply(L1, 1, function(x) sample(colnames(L1), s.size, prob=x, replace=TRUE) ) sampdf - as.data.frame(samptbl) sampdf1 -vector(list) for(i in 1:nrow(L1)) { sampdf1[[i]] - factor(sampdf[[i]], levels= colnames(L1)) } out - t(sapply(sampdf1, table)) } -- View this message in context: http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3264251.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. David Winsemius, MD 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] problem in merging
Hi all, I am having this error while trying to merge about 2 dataframes m_merge = merge(m_accts,m_op, by.y=CUST_ID,by.x=FORACID,all.y=TRUE,all.x=TRUE) Error: cannot allocate vector of size 10.0 Mb Taby [[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] Creating a list of lists / hclust elements
Dear group, I am currently struggling with the following problem for a while: I want to create a list whose elements consists of lists themselves. More concise: The list elements are HCLUST objects. However, when I try to append the HCLUST objects to my list via: cluster_list - append(cluster_list, HCLUSTobject) the HCLUST object is appended - but not as an object but as its components. So cluster_list[[1]] will not return the HCLUST object, but the first element of the first cluster object. So the list is appended to the list, but instead of appending the object, its individual components are added... Does anybody have an idea how I can solve this? Thanks! Lui __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] waveThresh plot axis
Date: Mon, 7 Feb 2011 10:49:54 +0100 From: eva.a...@gmail.com To: r-help@r-project.org Subject: [R] waveThresh plot axis Dear, I am using WaveTresh for Haar Wavelets. It works all fine exept when I want to adjust the axis on the wavelet coefficient plot: input: wlh_ponds-wd(input_waves[,1], family=DaubExPhase,filter.number=1) plot: plot(wlh_ponds,scaling=by.level) My problem is twofold= -I want the original x-axis of the data on that plot, not 1/2 of the axis. This would make my plot more clear for comparison with the original data series. -I want to cut of a part of the graph because I added columns with 0's to make my series 2^n. Now I want to cut them of again. It may look like a simple problem, but things like xlim don't work with this kind of plot. I just ran into this with dates and I finally had to just use which on the input data with an expression for the xlim values, d[which( dxi)(dxf)) ] for example. The plot documentation seems to refer to use of raw data range instead of xlim for figuring label params. Is there an implemented option to change this? Thank you, Best wishes Eva Ampe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Creating a list of lists / hclust elements
On Feb 7, 2011, at 10:45 AM, Lui ## wrote: Dear group, I am currently struggling with the following problem for a while: I want to create a list whose elements consists of lists themselves. More concise: The list elements are HCLUST objects. However, when I try to append the HCLUST objects to my list via: cluster_list - append(cluster_list, HCLUSTobject) Why not?: cluster_list - c(cluster_list, HCLUSTobject) -- David Winsemius, MD 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] question mle again
A few day ago, I was looking for an answer to my question but didn't get one. Anybody who can help now? Hello, I tried to use mle to fit a distribution(zero-inflated negbin for count data). My call is very simple: mle(ll) ll() takes the three parameters, I'd like to be estimated (size, mu and prob). But within the ll() function I have to judge if the current parameter-set gives a nice fit or not. So I have to apply them to observation data. But how does the method know about my observed data? The mle()-examples define this data outside of this method and it works. For a simple example, it was fine but when it comes to a loop (tapply) providing different sets of observation data, it doesn't work anymore. I'm confused - is there any way to do better? Here is a little example which show my problem: # R-code - lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle(ll) coef(fit) }) Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] color2d.maplot error
Dear all I am using color2D.maplot to map some matrixes to plot. everything works fine. It seems that when my matrix contains only the same value color2D.maplot returns the following error: color2D.matplot(estimatedsr,redrange=c(0,1),greenrange=c(0,.5),bluerange=c(0,.5),xlab=x,ylab=y,main=sprintf('Estimated'),show.legend=TRUE,show.values=TRUE) Error in rgb(reds, greens, blues) : color intensity 18.5, not in [0,1] Calls: color2D.matplot - color.scale - rgb if you want to generate the error above try the following: require('plotrix') estimatedsr-matrix(data=18.5,ncol=6,nrow=6) color2D.matplot(estimatedsr,redrange=c(0,1),greenrange=c(0,.5),bluerange=c(0,.5),xlab=x,ylab=y,main=sprintf('Estimated'),show.legend=TRUE,show.values=TRUE) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] aggregate function - na.action
Does FAQ 1.8 answer that ok ? Ok, I'm starting to see what data.table is about, but why didn't you enhance data.frame in R? Why does it have to be a new package? http://datatable.r-forge.r-project.org/datatable-faq.pdf Kind of. I think there are two sets of features data.table provides: * a compact syntax for expressing many common data manipulations * high performance data manipulation FAQ 1.8 answers the question for the syntax, but not for the performance related features. Basically, I'd love to be able to use the high performance components of data table in plyr, but keep using my existing syntax. Currently the only way to do that is for me to dig into your C code to understand why it's fast, and then implement those ideas in plyr. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University 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.
Re: [R] Loop to find dates whithin dates
?subset Daniel Nordlund Bothell, WA USA -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of patraopedro Sent: Monday, February 07, 2011 6:11 AM To: r-help@r-project.org Subject: [R] Loop to find dates whithin dates Hello to all, I have two dataframes, the first with two columns sunrise and sunset (for 10 years). Each of these columns is formatted for date time (ex: 01-Jan-2010 15:37:00) In the second data frame I have GPS information and also a date time column (same format ). What I would like to do is a subset of all the rows from the second dataframe that occurred in day time only so between sunrise and sunset. There are thousands of lines from multiple GPS so date time might be repeated in some rows. Any ideas how to accomplish this? Thanks in advance Patrao -- View this message in context: http://r.789695.n4.nabble.com/Loop-to-find- dates-whithin-dates-tp3264180p3264180.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] Seeking help to define s4 method for 'print'
I have got another question on defining a method for print() function for my s4 class. Here is my class definition as well as what I have done till now: setClass(Me, representation(x1 = numeric, x2 = numeric, y1 = character)) [1] Me setMethod(print, Me, definition=function(x) { + cat(Values of x1 x2 are:, c(x@x1, x@x2), \n) + }) [1] print new1 = new(Me, x1=rnorm(2), x2=rt(2, 1), y1=normal) print(new1) Values of x1 x2 are: -2.139669 -0.2102133 -0.6293572 -26.96205 However what I wanted to have that, user should have some option to print the underlying object with as much accuracy as he wants, in terms of displaying the significant digits, for example prints number of user defined precision: print(rnorm(2), 10) [1] -0.39146522347 -0.05624702385 print(rnorm(2), 5) [1] 0.34575 0.87486 Can somebody help me how can I get such options for my class? Additionally I want to have 2 different additional arguments for print() function of my class, so that x1 and x2 will be displayed in different significant digits. Thanks and regards, [[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] aggregate function - na.action/ performance issues re structs and algorithms
From: had...@rice.edu Date: Mon, 7 Feb 2011 11:00:59 -0600 To: mdo...@mdowle.plus.com CC: r-h...@stat.math.ethz.ch Subject: Re: [R] aggregate function - na.action Does FAQ 1.8 answer that ok ? Ok, I'm starting to see what data.table is about, but why didn't you enhance data.frame in R? Why does it have to be a new package? http://datatable.r-forge.r-project.org/datatable-faq.pdf Kind of. I think there are two sets of features data.table provides: * a compact syntax for expressing many common data manipulations * high performance data manipulation FAQ 1.8 answers the question for the syntax, but not for the performance related features. Basically, I'd love to be able to use the high performance components of data table in plyr, but keep using my existing syntax. Currently the only way to do that is for me to dig into your C code to understand why it's fast, and then implement those ideas in plyr. Without looking ( theo original subj would have caused me to miss most of this thread), usually the problems are with data strcutures that don't know about algorithm access patterns or are not characterized beyond things like order to operate on a collection of some kind( O(n) for example to access). I think the author suggested page loading time as a contributing factor IIRC and this would be great news since that is one of my personal rants:) People complain about running out of memory but it is unlikely you have an algorithm that just randomly picks one of those billions and billions of bits after the prior memory operation. Cache aware structures and algorothms can be a big deal, see for example many good white papers on intel site. Tables generally connote random access but usually you just want to stream the data or hopefully operate on local blocks. Long before VM thrashing, low level cache pollution can become a problem etc. Personally I've always thought a streaming source would be nice. Not sure if you want a prefetch() or similar interface signatures to let your algorithm prepare your stucts etc. Hadley __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] question mle again
Hi, On Mon, Feb 7, 2011 at 8:15 AM, Antje Niederlein niederlein-rs...@yahoo.de wrote: A few day ago, I was looking for an answer to my question but didn't get one. Anybody who can help now? Hello, I tried to use mle to fit a distribution(zero-inflated negbin for count data). My call is very simple: mle(ll) ll() takes the three parameters, I'd like to be estimated (size, mu and prob). But within the ll() function I have to judge if the current parameter-set gives a nice fit or not. So I have to apply them to observation data. But how does the method know about my observed data? The mle()-examples define this data outside of this method and it works. For a simple example, it was fine but when it comes to a loop (tapply) providing different sets of observation data, it doesn't work anymore. I'm confused - is there any way to do better? When a function cannot find a variable inside its own environment, it will look to its parent environment. If you define a function in the global environment, the global environment is its parent environment. However, if you define a function in the global environment, but then proceed to use lapply() with another function, the actual variable ll() needs to access is neither passed to II (so it is not in its environment) nor is it in the global environment (II's parent environment). It is in the function in lapply's environment, which is inaccessible to II. I have made some small changes to your code that gets around this, but I am still not convinced this is really doing what you want, but that is a whole other question/problem. Also, for future reference, you are more likely to get a response/help if you mention the required packages. I made educated guesses, that you are using mle() from stats4 and count() from plyr (I realize you may not even be aware that those functions came from non-default loading packages). HTH, Josh Here are my edits to your code: foo - function(x) { ## load required packages (guessing here) require(stats4) require(plyr) ## define ll function _inside_ foo ## this is important if you want it to have access ## to arguments in foo ll - function(lambda = 1) { cat(x in ll(), x, \n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } ## Your calculations ## (though I'm not convinced this is what you really want) raw.data - rpois(100, lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x, \n) fit - mle(ll) coef(fit) } ## Data lambda.data - runif(10, 0.5, 10) ## Run it through lapply for x = 1:10 lapply(1:10, FUN = foo) Here is a little example which show my problem: # R-code - lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle(ll) coef(fit) }) Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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] Loop to find dates whithin dates
Hi Patrao, you can 'merge' both datasets using the (extracted) day as indicator, see ?merge. Then use subset. hth. Am 07.02.2011 15:10, schrieb patraopedro: Hello to all, I have two dataframes, the first with two columns sunrise and sunset (for 10 years). Each of these columns is formatted for date time (ex: 01-Jan-2010 15:37:00) In the second data frame I have GPS information and also a date time column (same format ). What I would like to do is a subset of all the rows from the second dataframe that occurred in day time only so between sunrise and sunset. There are thousands of lines from multiple GPS so date time might be repeated in some rows. Any ideas how to accomplish this? Thanks in advance Patrao -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Question about checkTmvArgs function in rtmvnorm (package tmvtnorm)
Hello! I was wondering if it's possible to see the actual code of checkTmvArgs function that is part of the code for rtmvnorm (which is below - I just typed rtmvnorm on the prompt). I get an error: Error in checkTmvArgs(mean, sigma, lower, upper) : sigma must be a symmetric matrix At the same time I am pretty sure that the matrix I am passing as sigma is a var-covar matrix (however, it is NOT a correlation matrix). Thanks a lot! Dimitri function (n, mean = rep(0, nrow(sigma)), sigma = diag(length(mean)), lower = rep(-Inf, length = length(mean)), upper = rep(Inf, length = length(mean)), algorithm = c(rejection, gibbs, gibbsR), ...) { algorithm - match.arg(algorithm) cargs - checkTmvArgs(mean, sigma, lower, upper) mean - cargs$mean sigma - cargs$sigma lower - cargs$lower upper - cargs$upper if (n 1 || !is.numeric(n) || n != as.integer(n) || length(n) 1) { stop(n must be a integer scalar 0) } if (algorithm == rejection) { retval - rtmvnorm.rejection(n, mean, sigma, lower, upper, ...) } else if (algorithm == gibbs) { retval - rtmvnorm.gibbs.Fortran(n, mean, sigma, lower, upper, ...) } else if (algorithm == gibbsR) { retval - rtmvnorm.gibbs(n, mean, sigma, lower, upper, ...) } return(retval) } -- Dimitri Liakhovitski Ninah Consulting www.ninah.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] Seeking help to define s4 method for 'print'
Hi Christofer, I think this might not be the best use of S4 methods (I am still at the constantly rereading the R extensions manual and John Chambers' book stage), but since you are just printing numeric class data, I would be tempted to use set it up so your method just passes it on to the default. Of course, this does not allow for different number of digits for x1 and x2, but is that really necessary anyways? People can always delete a couple if its too precise from one. If you really want to tweak both, I think you'd need to add digits1 and digits2 arguments or something, and maybe use round or some other method to edit those values _before_ you cat() them. I'd love to hear alternative suggestions! Cheers, Josh (code follows) ## setClass(Me, representation( x1 = numeric, x2 = numeric, y1 = character) ) setMethod(print, Me, definition = function (x, ...) { cat(Values of x1 x2 are: \n) callNextMethod(x = c(x@x1, x@x2), ...) }) new1 = new(Me, x1=rnorm(2), x2=rt(2, 1), y1=normal) print(new1, digits = 10) print(new1, digits = 2) ## On Mon, Feb 7, 2011 at 9:36 AM, Bogaso Christofer bogaso.christo...@gmail.com wrote: I have got another question on defining a method for print() function for my s4 class. Here is my class definition as well as what I have done till now: setClass(Me, representation(x1 = numeric, x2 = numeric, y1 = character)) [1] Me setMethod(print, Me, definition=function(x) { + cat(Values of x1 x2 are:, c(x@x1, x@x2), \n) + }) [1] print new1 = new(Me, x1=rnorm(2), x2=rt(2, 1), y1=normal) print(new1) Values of x1 x2 are: -2.139669 -0.2102133 -0.6293572 -26.96205 However what I wanted to have that, user should have some option to print the underlying object with as much accuracy as he wants, in terms of displaying the significant digits, for example prints number of user defined precision: print(rnorm(2), 10) [1] -0.39146522347 -0.05624702385 print(rnorm(2), 5) [1] 0.34575 0.87486 Can somebody help me how can I get such options for my class? Additionally I want to have 2 different additional arguments for print() function of my class, so that x1 and x2 will be displayed in different significant digits. Thanks and regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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] question mle again
On Mon, Feb 7, 2011 at 9:21 AM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi, When a function cannot find a variable inside its own environment, it will look to its parent environment. This is false. It will look to its **enclosing environment / enclosure . See ?environment (Note: This is fundamental to R scoping) -- Bert If you define a function in the global environment, the global environment is its parent environment. However, if you define a function in the global environment, but then proceed to use lapply() with another function, the actual variable ll() needs to access is neither passed to II (so it is not in its environment) nor is it in the global environment (II's parent environment). It is in the function in lapply's environment, which is inaccessible to II. I have made some small changes to your code that gets around this, but I am still not convinced this is really doing what you want, but that is a whole other question/problem. Also, for future reference, you are more likely to get a response/help if you mention the required packages. I made educated guesses, that you are using mle() from stats4 and count() from plyr (I realize you may not even be aware that those functions came from non-default loading packages). HTH, Josh Here are my edits to your code: foo - function(x) { ## load required packages (guessing here) require(stats4) require(plyr) ## define ll function _inside_ foo ## this is important if you want it to have access ## to arguments in foo ll - function(lambda = 1) { cat(x in ll(), x, \n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } ## Your calculations ## (though I'm not convinced this is what you really want) raw.data - rpois(100, lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x, \n) fit - mle(ll) coef(fit) } ## Data lambda.data - runif(10, 0.5, 10) ## Run it through lapply for x = 1:10 lapply(1:10, FUN = foo) Here is a little example which show my problem: # R-code - lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle(ll) coef(fit) }) Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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. -- Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loop to find dates whithin dates
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Eik Vettorazzi Sent: Monday, February 07, 2011 9:26 AM To: patraopedro Cc: r-help@r-project.org Subject: Re: [R] Loop to find dates whithin dates Hi Patrao, you can 'merge' both datasets using the (extracted) day as indicator, see ?merge. Then use subset. hth. That approach may work well for this example (outside of the polar regions), where there is exactly one sunrise and sunset per day. When the intervals of interest are more sporadic (say we have start and stop times for fishing openings) you can use findInterval(times, rbind(startTimes,endTimes)), as in: # make fake datasets nDays - 1000 nSightings - 1200 set.seed(1) dayNumber - seq_len(nDays) - 1 secondsPerDay - 60 * 60 * 24 sunTimes - data.frame(Rise= as.POSIXct(2010-03-21 05:45) + dayNumber*secondsPerDay - 3 * 60 * 60 * sin(dayNumber / 365.25 * 2 * pi), Set = as.POSIXct(2010-03-21 17:45) + dayNumber*secondsPerDay + 3 * 60 * 60 * sin(dayNumber / 365.25 * 2 * pi)) sightings - data.frame(Time=as.POSIXct(2010-03-21 00:00) + sort(runif(nSightings, 0, nDays * secondsPerDay)), GPS.x = seq_len(nSightings), GPS.y = -seq_len(nSightings)) # map times to daylight or not i - findInterval(sightings$Time, rbind(sunTimes$Rise, sunTimes$Set)) isDuringDaylight - i%%2 == 1 # even intervals at night, odd in daylight # plot results to see if we are right with(sunTimes, { plot(trunc(Rise, units=days), rep(0, length(Rise)), type=n, ylim=c(0,24), ylab=Hour of Day, xlab=Date) points(pch=., trunc(Rise, units=days), as.numeric(Rise-trunc(Rise, units=days), units=hours)) points(pch=., trunc(Rise, units=days), as.numeric(Set-trunc(Set, units=days), units=hours)) }) with(sightings, points(trunc(Time,days), as.numeric(Time - trunc(Time,days), units=hours), col=ifelse(isDuringDaylight,red,gray))) Use sightings[isDuringDaylight,,drop=FALSE] to extract the daylight entries in the sightings data.frame. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com Am 07.02.2011 15:10, schrieb patraopedro: Hello to all, I have two dataframes, the first with two columns sunrise and sunset (for 10 years). Each of these columns is formatted for date time (ex: 01-Jan-2010 15:37:00) In the second data frame I have GPS information and also a date time column (same format ). What I would like to do is a subset of all the rows from the second dataframe that occurred in day time only so between sunrise and sunset. There are thousands of lines from multiple GPS so date time might be repeated in some rows. Any ideas how to accomplish this? Thanks in advance Patrao -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] tri-cube and gaussian weights in loess
Locfit() in the locfit package has a slightly more modern implementation of loess, and is much more flexible in that it has a lot of options to tweak. One such option is the kernel. There are seven to choose from. Andy From: wisdomtooth From what I understand, loess in R uses the standard tri-cube function. SAS/INSIGHT offers loess with Gaussian weights. Is there a function in R that does the same? Also, can anyone offer any references comparing properties between tri-cube and Gaussian weights in LOESS? Thanks. - André -- View this message in context: http://r.789695.n4.nabble.com/tri-cube-and-gaussian-weights-in -loess-tp3263934p3263934.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. Notice: This e-mail message, together with any attachme...{{dropped:11}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] question mle again
On Mon, Feb 7, 2011 at 9:40 AM, Bert Gunter gunter.ber...@gene.com wrote: On Mon, Feb 7, 2011 at 9:21 AM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi, When a function cannot find a variable inside its own environment, it will look to its parent environment. This is false. It will look to its **enclosing environment / enclosure . See ?environment Thank you for the correction, Bert. I had always interpreted: If one follows the 'parent.env()' chain of enclosures back far enough from any environment, eventually one reaches the empty environment. to mean the parent environment was basically synonymous with the enclosure. I re-read ?environment, but I think I am still missing something, so if I may ask a follow up question, would you explain or suggest additional places to look for when/how is the the parent environment distinct from the enclosing environment? Thanks, Josh (Note: This is fundamental to R scoping) -- Bert -- Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] problem in merging
A little more information would be of use; e.g. str(m_accts) str(m_op) gc() # how much memory is currently being used Message indicates you may have fragmented memory and it can not find enough contigious space. Also do you have duplicates in the ID you are merging by so that you wind up with a much larger resulting structure? On Mon, Feb 7, 2011 at 11:05 AM, taby gathoni tab...@yahoo.com wrote: Hi all, I am having this error while trying to merge about 2 dataframes m_merge = merge(m_accts,m_op, by.y=CUST_ID,by.x=FORACID,all.y=TRUE,all.x=TRUE) Error: cannot allocate vector of size 10.0 Mb Taby [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru 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] problem in merging
simple example of what I was talking about; dataframe only size 5 but result is length 44 x1 - data.frame(a=sample(c(A, B), 5, TRUE), b=1:10) x2 - data.frame(a=sample(c(A, B), 5, TRUE), b=1:10) x1 a b 1 A 1 2 B 2 3 A 3 4 A 4 5 B 5 6 A 6 7 B 7 8 A 8 9 A 9 10 B 10 x2 a b 1 B 1 2 B 2 3 B 3 4 B 4 5 A 5 6 B 6 7 B 7 8 B 8 9 B 9 10 A 10 merge(x1, x2, by = 'a', all=TRUE) a b.x b.y 1 A 1 5 2 A 1 10 3 A 6 5 4 A 6 10 5 A 3 5 6 A 3 10 7 A 4 5 8 A 4 10 9 A 9 5 10 A 9 10 11 A 8 5 12 A 8 10 13 B 2 3 14 B 2 4 15 B 2 1 16 B 2 2 17 B 2 7 18 B 2 8 19 B 2 9 20 B 2 6 21 B 7 3 22 B 7 4 23 B 7 1 24 B 7 2 25 B 7 7 26 B 7 8 27 B 7 9 28 B 7 6 29 B 5 3 30 B 5 4 31 B 5 1 32 B 5 2 33 B 5 7 34 B 5 8 35 B 5 9 36 B 5 6 37 B 10 3 38 B 10 4 39 B 10 1 40 B 10 2 41 B 10 7 42 B 10 8 43 B 10 9 44 B 10 6 On Mon, Feb 7, 2011 at 11:05 AM, taby gathoni tab...@yahoo.com wrote: Hi all, I am having this error while trying to merge about 2 dataframes m_merge = merge(m_accts,m_op, by.y=CUST_ID,by.x=FORACID,all.y=TRUE,all.x=TRUE) Error: cannot allocate vector of size 10.0 Mb Taby [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru 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] question mle again
On Mon, Feb 7, 2011 at 1:01 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: On Mon, Feb 7, 2011 at 9:40 AM, Bert Gunter gunter.ber...@gene.com wrote: On Mon, Feb 7, 2011 at 9:21 AM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi, When a function cannot find a variable inside its own environment, it will look to its parent environment. This is false. It will look to its **enclosing environment / enclosure . See ?environment Thank you for the correction, Bert. I had always interpreted: If one follows the 'parent.env()' chain of enclosures back far enough from any environment, eventually one reaches the empty environment. to mean the parent environment was basically synonymous with the enclosure. I re-read ?environment, but I think I am still missing something, so if I may ask a follow up question, would you explain or suggest additional places to look for when/how is the the parent environment distinct from the enclosing environment? I am not so sure that there really is uniform usage here although specific people may have specific preferences. Because R uses parent.env and parent.frame functions many people use the term parent environment to refer to the what parent.env returns and parent frame to refer to what parent.frame returns and that seems reasonable usage as well. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] question mle again
Because, as that help page makes clear, the 'parent environment' is easily confused with the 'parent frame', we tend not to use the former. So the main answer to when/how is the the parent environment distinct from the enclosing environment? is 'when the writer meant the parent frame'. On Mon, 7 Feb 2011, Joshua Wiley wrote: On Mon, Feb 7, 2011 at 9:40 AM, Bert Gunter gunter.ber...@gene.com wrote: On Mon, Feb 7, 2011 at 9:21 AM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi, When a function cannot find a variable inside its own environment, it will look to its parent environment. This is false. It will look to its **enclosing environment / enclosure . See ?environment Thank you for the correction, Bert. I had always interpreted: If one follows the 'parent.env()' chain of enclosures back far enough from any environment, eventually one reaches the empty environment. to mean the parent environment was basically synonymous with the enclosure. I re-read ?environment, but I think I am still missing something, so if I may ask a follow up question, would you explain or suggest additional places to look for when/how is the the parent environment distinct from the enclosing environment? Thanks, Josh (Note: This is fundamental to R scoping) -- Bert -- Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] p-value for y in non-parametric distribution, Y
Hello, knowing that some index y, with y(341)=2, SE=3, is t-distributed, I (think I) can find an appropriate (left/one-sided) p-value with R: y - 2 R: yse - 3 R: (p - 1-pt(y/yse, df=341)) Now, some simulation resulted in the non-parametric distribution, Y, of my index, y: R: Y - rnorm(21277) How can I find the p-value of y then? Simply counting? Thanks, *S* -- Sascha Vieweg, saschav...@gmail.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] Unusual slowing of R matrix multiplication version 2.12.1 (2010-10-15) vs 2.12.0
R Version 2.12.1 (2010-10-15) vs 2.12.0 has slowed down 8 fold for dual core and 17 fold for dual-core-dual-processor Macs. I have checked this result on 3 different macs using the following R-script: Using Version 2.12.0 on a dual core dual processor Mac: source(http://www.bio.umass.edu/biology/kunkel/pub/R/CuriousResult.R;) matrix multiplication 43.543 1.308 14.788 tcrossprod 41.147 1.286 11.9 transposition and reuse40.407 3.525 43.606 elementwise after reshape 21.474 1.828 23.124 columnwise sapply 34.695 32.35 66.592 for loop over columns 37.237 29.471 67.2 On the same day upgrading to 2.12.1 on the same dual core dual processor Mac: source(http://www.bio.umass.edu/biology/kunkel/pub/R/CuriousResult.R;) matrix multiplication 256.775 2.178 256.919 tcrossprod246.609 1.987 247.075 transposition and reuse39.622 4.602 43.883 elementwise after reshape 21.017 2.343 23.258 columnwise sapply39.393 37.069 75.834 for loop over columns 35.461 33.155 68.165 It seems clear that the upgrade to 2.12.1 has resulted in matrix multiplication using only one core. Notice that the other techniques that avoid matrix multiplication seem to stay the same but the two approaches that use matrix multiply have degraded worse than the expected loss of just 4 fold. Is it possible that a different matrix multiply library was used in changing from version 2.12.0 to 2.12.1? Joe Kunkel __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loop to find dates whithin dates
If you are looking to find out if a given GPS time is between sunrise/sunset, then here is what I would do given the quantity of data. I would encode the sunrise/sunset times in a character vector of length 10 years * 365 days/year * 1440 minutes/day = 5M character vector. Set the vector to '1' if between the times. Now all you have to do is convert you GPS times to an index into this vector and if it is '1' then you know that you are between sunrist/sunset. Saves having to compare each GPS time to the 3650 entries in you database. On Mon, Feb 7, 2011 at 9:10 AM, patraopedro patraope...@yahoo.com.br wrote: Hello to all, I have two dataframes, the first with two columns sunrise and sunset (for 10 years). Each of these columns is formatted for date time (ex: 01-Jan-2010 15:37:00) In the second data frame I have GPS information and also a date time column (same format ). What I would like to do is a subset of all the rows from the second dataframe that occurred in day time only so between sunrise and sunset. There are thousands of lines from multiple GPS so date time might be repeated in some rows. Any ideas how to accomplish this? Thanks in advance Patrao -- View this message in context: http://r.789695.n4.nabble.com/Loop-to-find-dates-whithin-dates-tp3264180p3264180.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. -- Jim Holtman Data Munger Guru 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.
[R] how to return multipy matrix in a function
Hello I have a 100*100 matrix which is from a intensive computation, e.g. mat. Is there any method/function that return the max of every row and the subscript of maximum value simultaneously #define the function returnfunction-function(x){ + value-apply(x,1,max) + index-apply(x,1,which.max) + } mat-matrix(c(3,5,7,2,1,10,4,3,2),3)#initilize the matrix for test mat [,1] [,2] [,3] [1,]324 [2,]513 [3,]7 102 returnfunction(mat)$value Error in returnfunction(mat)$value : $ operator is invalid for atomic vectors returnfunction(mat)$index Error in returnfunction(mat)$index : $ operator is invalid for atomic vectors the returnfunction(mat)$value should be 4,5,10 the returnfunction(mat)$index should be 3,1,2 Thank you in advance ZhaoXing Department of Health Statistics West China School of Public Health Sichuan University No.17 Section 3, South Renmin Road Chengdu, Sichuan 610041 P.R.China __ ¸Ï¿ì×¢²áÑÅ»¢³¬´óÈÝÁ¿Ãâ·ÑÓÊÏä? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loop to find dates whithin dates
Thank you for your responses but I think whith some examples the problem will be better understated. Ok, here it is an example of how the data looks like to allow a better understanding of the problem. Dframe1 - data.frame(sunrise = seq(as.POSIXct(2010-07-14 06:05:25),as.POSIXct(2010-07-20 06:05:25),by=day),sunset= seq(as.POSIXct(2010-07-14 18:00:00),as.POSIXct(2010-07-20 18:00:00),by=day)) Dframe2 - data.frame(Logtime = seq(as.POSIXct(2010-07-14 06:05:25),as.POSIXct(2010-07-20 06:05:25),by=hour), temp = runif(145, -5, 15)) What I’m interested on is rows from the Dframe2 during the day, and for that I need (I think) a loop to see if each Logtime occurred during the day or night. Cheers Patrao -- View this message in context: http://r.789695.n4.nabble.com/Loop-to-find-dates-whithin-dates-tp3264180p3264540.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] Question about checkTmvArgs function in rtmvnorm (package tmvtnorm)
I found a reason why I was getting the error that my var-covar matrix was not symmetric: because my column names and row names were different! Dimitri On Mon, Feb 7, 2011 at 12:39 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! I was wondering if it's possible to see the actual code of checkTmvArgs function that is part of the code for rtmvnorm (which is below - I just typed rtmvnorm on the prompt). I get an error: Error in checkTmvArgs(mean, sigma, lower, upper) : sigma must be a symmetric matrix At the same time I am pretty sure that the matrix I am passing as sigma is a var-covar matrix (however, it is NOT a correlation matrix). Thanks a lot! Dimitri function (n, mean = rep(0, nrow(sigma)), sigma = diag(length(mean)), lower = rep(-Inf, length = length(mean)), upper = rep(Inf, length = length(mean)), algorithm = c(rejection, gibbs, gibbsR), ...) { algorithm - match.arg(algorithm) cargs - checkTmvArgs(mean, sigma, lower, upper) mean - cargs$mean sigma - cargs$sigma lower - cargs$lower upper - cargs$upper if (n 1 || !is.numeric(n) || n != as.integer(n) || length(n) 1) { stop(n must be a integer scalar 0) } if (algorithm == rejection) { retval - rtmvnorm.rejection(n, mean, sigma, lower, upper, ...) } else if (algorithm == gibbs) { retval - rtmvnorm.gibbs.Fortran(n, mean, sigma, lower, upper, ...) } else if (algorithm == gibbsR) { retval - rtmvnorm.gibbs(n, mean, sigma, lower, upper, ...) } return(retval) } -- Dimitri Liakhovitski Ninah Consulting www.ninah.com -- Dimitri Liakhovitski Ninah Consulting www.ninah.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] Loop to find dates whithin dates
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of patraopedro Sent: Monday, February 07, 2011 9:36 AM To: r-help@r-project.org Subject: Re: [R] Loop to find dates whithin dates Thank you for your responses but I think whith some examples the problem will be better understated. Ok, here it is an example of how the data looks like to allow a better understanding of the problem. Dframe1 - data.frame(sunrise = seq(as.POSIXct(2010-07-14 06:05:25),as.POSIXct(2010-07-20 06:05:25),by=day),sunset= seq(as.POSIXct(2010-07-14 18:00:00),as.POSIXct(2010-07-20 18:00:00),by=day)) Dframe2 - data.frame(Logtime = seq(as.POSIXct(2010-07-14 06:05:25),as.POSIXct(2010-07-20 06:05:25),by=hour), temp = runif(145, -5, 15)) What I'm interested on is rows from the Dframe2 during the day, and for that I need (I think) a loop to see if each Logtime occurred during the day or night. That data is very similar to what I showed in my example. With your data (temp is random): isDuringDaylight - findInterval(Dframe2$Logtime, with(Dframe1, rbind(sunrise, sunset))) %% 2 == 1 Dframe2[isDuringDaylight,,drop=FALSE] Logtime temp 1 2010-07-14 06:05:25 0.360302776 2 2010-07-14 07:05:25 -2.964403196 3 2010-07-14 08:05:25 -2.327518053 4 2010-07-14 09:05:25 10.987051544 5 2010-07-14 10:05:25 -4.700185475 6 2010-07-14 11:05:25 9.108118797 7 2010-07-14 12:05:25 4.750278350 8 2010-07-14 13:05:25 14.382293951 9 2010-07-14 14:05:25 2.945564128 10 2010-07-14 15:05:25 8.433319060 11 2010-07-14 16:05:25 9.069562554 12 2010-07-14 17:05:25 -0.437336382 25 2010-07-15 06:05:25 -3.314539269 26 2010-07-15 07:05:25 13.032594020 ... Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com Cheers Patrao -- View this message in context: http://r.789695.n4.nabble.com/Loop-to-find-dates-whithin-dates -tp3264180p3264540.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] aggregate function - na.action
Hadley, That's fine; please do. I'm happy to explain it offline where the documentation or comments in the code aren't sufficient. It's GPL code so you can take it and improve it, or depend on it. Whatever works for you. As long as (of course) you don't stand on it's shoulders and then restrict users' freedoms (not that I'd ever think you'd do that). One thing that did make it into R was the improvement to unique.c in R 2.12.0. Another that we hope happens one day is changing duplicate.c to use memcpy. That would automatically benefit all users anywhere R copies data (including data.frame). That wasn't our idea; that's been a FIXME in the R source for many years. See thread on r-devel a while back (search for duplicate.c in subject). It probably just needs someone to send a working patch file that passes checks. That's an example of something in the data.table C code that (hopefully) will make it into base R. Matthew Hadley Wickham had...@rice.edu wrote in message news:AANLkTi=setpquiyr1+avb4-ga1-fyh9uffa6mskk+...@mail.gmail.com... Does FAQ 1.8 answer that ok ? Ok, I'm starting to see what data.table is about, but why didn't you enhance data.frame in R? Why does it have to be a new package? http://datatable.r-forge.r-project.org/datatable-faq.pdf Kind of. I think there are two sets of features data.table provides: * a compact syntax for expressing many common data manipulations * high performance data manipulation FAQ 1.8 answers the question for the syntax, but not for the performance related features. Basically, I'd love to be able to use the high performance components of data table in plyr, but keep using my existing syntax. Currently the only way to do that is for me to dig into your C code to understand why it's fast, and then implement those ideas in plyr. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University 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.
Re: [R] how to return multipy matrix in a function
On Feb 7, 2011, at 12:30 PM, zhaoxing731 wrote: Hello I have a 100*100 matrix which is from a intensive computation, e.g. mat. Is there any method/function that return the max of every row and the subscript of maximum value simultaneously #define the function returnfunction-function(x){ + value-apply(x,1,max) + index-apply(x,1,which.max) + } That would only return an index value You only get a vector (about which the error message seems somewhat on point, but a bit tangential since you did not return a named list either so the $ extraction will not succeed) , not a matrix in the x value passed from the apply call. Try: returnfunction-function(x){ value - max(x) index - which.max(x) return( c(value, index) ) } apply(mat,1, returnfunction) [,1] [,2] [,3] [1,]45 10 [2,]312 Note no row names or col names. Could get rownames with: returnfunction-function(x){ +value - max(x) +index - which.max(x) +return( c(val=value, ind=index) )} apply(mat,1, returnfunction) [,1] [,2] [,3] val45 10 ind312 -- David. mat-matrix(c(3,5,7,2,1,10,4,3,2),3)#initilize the matrix for test mat [,1] [,2] [,3] [1,]324 [2,]513 [3,]7 102 returnfunction(mat)$value Error in returnfunction(mat)$value : $ operator is invalid for atomic vectors returnfunction(mat)$index Error in returnfunction(mat)$index : $ operator is invalid for atomic vectors the returnfunction(mat)$value should be 4,5,10 the returnfunction(mat)$index should be 3,1,2 Thank you in advance ZhaoXing Department of Health Statistics West China School of Public Health Sichuan University No.17 Section 3, South Renmin Road Chengdu, Sichuan 610041 P.R.China __ ¸Ï¿ì×¢²áÑÅ»¢³¬´óÈÝÁ¿Ãâ·ÑÓÊÏä? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 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] under what conditions would rtmvnorm (from package tmvtnorm) produce all NaNs
Hello! I am trying to generate a sample from a truncated multivariate normal distribution using rtmvnorm. I am using Gibbs because my alpha (line below) is teeny-tiny ( 4.083475e-64 ) alpha = pmvnorm(lower=lower, upper=upper, mean=btilde, sigma=MyVarCovar). When I try my Gibbs run, it takes quite a long time (with 10,000 iterations and 5,000 iterations burn-in) ~ 22 sec. And then what I get is all NaNs. To add: -I have 67 (!) variables and for a few of them some of my lower and upper bounds are quite close to each other. -In my vector of means some of the values are below respective lower bounds and some are above respective upper bounds. Are the facts above the rasons that my run below returns all NaNs? library(tmvtnorm) myVector = colMeans(rtmvnorm(n=1, mean = as.vector(btilde), sigma=MyVarCovar, lower=lower, upper=upper, algorithm=gibbs, burn.in.samples=5000)) If one really needs to see the data to answer my question, I'll be happy to provide btilde and my bounds. -- Dimitri Liakhovitski Ninah Consulting www.ninah.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] package ChemometricsWithR
Dear all; Does anyone knows where can I find the package ChemometricsWithR mentioned in http://www.springer.com/life+sciences/bioinformatics/book/978-3-642-17840-5? Thanks for any hint PM [[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] package ChemometricsWithR
On Feb 7, 2011, at 2:31 PM, Pedro Mardones wrote: Dear all; Does anyone knows where can I find the package ChemometricsWithR mentioned in http://www.springer.com/life+sciences/bioinformatics/book/978-3-642-17840-5? Thanks for any hint The preface says: With the book comes a package, too: ChemometricsWithR contains all data sets and functions used in this book. So it appears the answer is ... buy the book. -- David Winsemius, MD 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] Giving vector of colors to line in plots
On 02/07/2011 02:15 AM, Jinsong Zhao wrote: On 2011-2-7 14:15, statmobile wrote: set.seed(33) x - rpois(7,lambda=7) y - rpois(7,lambda=5) cols.x - c(rep(black,2),rep(red,3),rep(black,2)) cols.y - c(rep(blue,3),rep(yellow,2),rep(blue,2)) points.x - c(rep(x,2),rep(O,3),rep(x,2)) points.y - c(rep(8,3),rep(17,2),rep(8,2)) plot(x,col=cols.x,pch=points.x,type=b,ylim=c(0,15)) points(y,col=cols.y,pch=points.y,type=b) the following code may give hints... segments(1:6,x[-7],2:7,x[-1], col = cols.x) segments(1:6,y[-7],2:7,y[-1], col = cols.y) regards, Jinsong Thanks Jinsong, this works like a charm. I'll need to dive deeper into the segments function. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] delete rows
Assuming your data is in a dataframe called df: # make fake df df = data.frame(a=1:472, b=1001:1472) df[416:472, ] # check the rows you want to remove df[-(416:472), ] # remove them df # see what's left -- From: Christopher Porter cpor...@clemson.edu Sent: Sunday, February 06, 2011 8:16 PM To: r-h...@stat.math.ethz.ch Subject: [R] delete rows Hello. I came across your response in an R forum and could use your help. I have a data set with 472 rows. I want to delete rows 416 through 472. The name of my data set is MERGE. I am an extreme R novice. How do I write a script to accomplish this? Thank you. --- Christopher H. Porter, M.A., M.Ed. Director, Undergraduate Recruitment College of Engineering and Science Clemson University 106B Holtzendorff Hall (864) 656-7870 (864) 656-1327 - Fax AIM: ClemsonCES http://www.clemson.edu/ces/psu/ [[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] question mle again
Antje Niederlein niederlein-rstat at yahoo.de writes: A few day ago, I was looking for an answer to my question but didn't get one. Anybody who can help now? Hello, I tried to use mle to fit a distribution(zero-inflated negbin for count data). My call is very simple: I will point out that this is one of the reasons I wrote mle2 (in the bbmle package), which differs from mle in taking an explicit 'data' argument. I *think* the following does what you want (although I admit I haven't looked at the output closely): library(plyr) library(bbmle) lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle2(ll,data=data.frame(x,y)) coef(fit) }) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Unbalanced Mixed Linear Models With Nested Stratum
JaFF el.romaro at gmail.com writes: Hi folks, I have a dataset from a trial measuring the subjects' pupils. There are many measurements, all of which must be analysed in a similar fashion; so if I get the analysis right for one of them, I've got them all. For simplicity, let us call any measurement we may be interested as response. The study design is an unbalanced latin square, with 5 periods, 5 treatments and 6 subjects. Each subject has two measurements: left and right eyes. The model is as follows, with : denoting interaction... Fixed Effects = (Subject + Period + Dose):Eye Random Effects = Subject:Period + Subject:Period:Eye My main question is how to make this happen in R. I know that aov is not suitable. If you need any more information, I will do my best to provide it to the best of my knowledge. Doesn't treatment appear in fixed effects somewhere? Perhaps you mean (Treatment+Period+Dose):Eye? Translating your specification directly (substituting 'treatment' for 'subject' in the fixed effects) I would say lmer(response~(Treatment+Period+Dose):Eye + (Eye|Subject:Period), data=...) should be OK. Do you really want interactions only (:) rather than crossing (*) for the fixed effects? You will get a model with the same number of parameters either way, but parcelled out among effects differently. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Combining the results from two simple linear regression models
Hi all. This is more of a stats question, I suppose. Let's say I have two separate simple regressions of weight on year from two different datasets. I want to combine the regressions so that I can come up with a single equation for the total weight regressed on year. In reality, there is missing data, so I can't just sum the data across datasets and come up with a regression on the summed data. Below is a program to reproduce what I am trying to figure out. ### aslp=50 bslp=-50 sda=20 sdb=100 yrs=0:10 a= rnorm(11,100,sda)+aslp*yrs b= rnorm (11,1000,sdb)+bslp*yrs ma=lm(a~yrs) mb=lm(b~yrs) pra=predict(ma,data.frame(yrs=yrs),interval='confidence') prb=predict(mb,data.frame(yrs=yrs),interval='confidence') ##combine the two regressions for a single equation with confidence intervals pr=pra+prb###it couldn't be this simple, could it? #by hand co=coef(ma)+coef(mb) new.sigma=sqrt(summary(ma)$sigma^2+summary(mb)$sigma^2) fit=co[1]+co[2]*yrs lwr= fit - qt(.975,9)*sqrt( new.sigma^2 * ( (1/11) + ( (yrs-mean(yrs))^2)/sum((yrs-mean(yrs))^2) ) )#the df are probably wrong (the 9 in the qt upr= fit + qt(.975,9)*sqrt( new.sigma^2 * ( (1/11) + ( (yrs-mean(yrs))^2)/sum((yrs-mean(yrs))^2) ) )# statement) I can't print the graph here, so here's code for it... #graph plot(a,ylim=c(0,1500)) points(b) lines(ma$fit) lines(mb$fit) lines(pra[,'lwr'],lty=2);lines(pra[,'upr'],lty=2) lines(prb[,'lwr'],lty=2);lines(prb[,'upr'],lty=2) lines(pr[,'fit'],col='grey') lines(pr[,'upr'],lty=2,col='grey') lines(pr[,'lwr'],lty=2,col='grey') lines(fit,col='grey',lty=3) lines(lwr,col='grey',lty=3) lines(upr,col='grey',lty=3) legend(1,1500,lty=c(2,3),legend=c('adding using predict','adding by hand'),col='grey') As you can see, the plots of the two different methods for producing the confidence intervals don't match. What I suspect is wrong in my by-hand formula is the degrees of freedom (and n (the 11)), but if anything I think those would increase, which would make the confidence intervals even smaller than plainly summing the confidence intervals provided by the predict function at each x. I'm just wondering how to do this correctly, and am not sure if either approach is correct. If anybody would like to weigh in, I would appreciate it. Please feel free to point out the obvious. Thanks, Patrick [[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] fast optimization routines in R
Dear R help archive group, I am looking for a maximization routine that I can use to maximize a large variety of relatively complex likelihoods. I undertand (from previous posts) that coding the objective function more efficiently can help. However, the optimization routine employed seems important too. So far, I have tried the optimization routines optim, maxlik, trust and nlminb. The latter two are much faster than the first ones but nevertheless, it seems to me as if these routines were rather slow, when compared to some of the optimizers in MATLAB. Is there any general advice you can give about which optimization routines in R tend to be particularly fast? Thank you very much, Pia -- View this message in context: http://r.789695.n4.nabble.com/fast-optimization-routines-in-R-tp3265071p3265071.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] circular
Hi, I'm new to R. I'm trying to plot my data into a circle. my data sort of looks like 12,12,4,5,6,5,11,10,3,9,9,9,12,12,2 total of 15 numbers. I'm trying to add all the same numbers, such that, there are 4 of 12s,1 of 11, 1 of 10, 3 of 9s, and such so the circle plot would have 4 parts of 12, 1 part of 11, 1 part of 10, 3 part of 9, and such... I tried plot(circular(maxday[,2]*2*pi/12)) ##where maxday[,2] looks like the data above. but the only thing came out was dots, and they over wrote on each other. basically I would like to plot a pizza shape circle, where some of the slices are bigger than others. Thank you very much. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a list of lists / hclust elements
Hi David, I tried this one, but unfortunately it didn't solve the problem (same result as append). Thank you very much for your suggestion! Lui On Mon, Feb 7, 2011 at 5:14 PM, David Winsemius dwinsem...@comcast.net wrote: On Feb 7, 2011, at 10:45 AM, Lui ## wrote: Dear group, I am currently struggling with the following problem for a while: I want to create a list whose elements consists of lists themselves. More concise: The list elements are HCLUST objects. However, when I try to append the HCLUST objects to my list via: cluster_list - append(cluster_list, HCLUSTobject) Why not?: cluster_list - c(cluster_list, HCLUSTobject) -- David Winsemius, MD 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] circular
Hi, does y-c(12,12,4,5,6,5,11,10,3,9,9,9,12,12,2) pie(table(y)) suits you? Where does circular come from? Am 07.02.2011 21:20, schrieb Bobby Lee: Hi, I'm new to R. I'm trying to plot my data into a circle. my data sort of looks like 12,12,4,5,6,5,11,10,3,9,9,9,12,12,2 total of 15 numbers. I'm trying to add all the same numbers, such that, there are 4 of 12s,1 of 11, 1 of 10, 3 of 9s, and such so the circle plot would have 4 parts of 12, 1 part of 11, 1 part of 10, 3 part of 9, and such... I tried plot(circular(maxday[,2]*2*pi/12)) ##where maxday[,2] looks like the data above. but the only thing came out was dots, and they over wrote on each other. basically I would like to plot a pizza shape circle, where some of the slices are bigger than others. Thank you very much. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] rjava does not install
I am on a fedora server on which I am not root privileges. I am trying to locally install rJava... Here are my steps : $uname -a Linux 2.6.18-194.17.4.el5 #1 SMP Mon Oct 25 15:50:53 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux $ java -version java version 1.6.0_22 Java(TM) SE Runtime Environment (build 1.6.0_22-b04) Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode) $ echo $JAVA_HOME /opt/jdk1.6.0_22/ $ R CMD javareconf -e Java interpreter : /opt/jdk1.6.0_22//jre/bin/java Java version : 1.6.0_22 Java home path : /opt/jdk1.6.0_22/ Java compiler : /opt/jdk1.6.0_22//bin/javac Java headers gen.: /opt/jdk1.6.0_22//bin/javah Java archive tool: /opt/jdk1.6.0_22//bin/jar Java library path: $(JAVA_HOME)jre/lib/amd64/server:$(JAVA_HOME)jre/lib/amd64:$(JAVA_HOME)jre/../lib/amd64::/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)jre/lib/amd64/server -L$(JAVA_HOME)jre/lib/amd64 -L$(JAVA_HOME)jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm JNI cpp flags : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux The following Java variables have been exported: JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH And the installation halts with the following error (please see below for the details): rJava.h:19:17: error: jni.h: No such file or directory I would appreciate very much your kindly help Servet install.packages(rJava,dep=T) Installing package(s) into ‘/home/acizmeli/R/x86_64-redhat-linux-gnu-library/2.12’ (as ‘lib’ is unspecified) --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done trying URL 'http://cran.skazkaforyou.com/src/contrib/rJava_0.8-8.tar.gz' Content type 'application/x-gzip' length 522057 bytes (509 Kb) opened URL == downloaded 509 Kb * installing *source* package ‘rJava’ ... checking for gcc... gcc -m64 -std=gnu99 checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc -m64 -std=gnu99 accepts -g... yes checking for gcc -m64 -std=gnu99 option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -m64 -std=gnu99 -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/wait.h that is POSIX.1 compatible... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for string.h... (cached) yes checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking for unistd.h... (cached) yes checking for an ANSI C-conforming const... yes checking whether time.h and sys/time.h may both be included... yes configure: checking whether gcc -m64 -std=gnu99 supports static inline... yes checking whether setjmp.h is POSIX.1 compatible... yes checking whether sigsetjmp is declared... yes checking whether siglongjmp is declared... yes checking Java support in R... present: interpreter : '/opt/jdk1.6.0_22//jre/bin/java' archiver : '/opt/jdk1.6.0_22//bin/jar' compiler : '/opt/jdk1.6.0_22//bin/javac' header prep.: '/opt/jdk1.6.0_22//bin/javah' cpp flags : '-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux' java libs : '-L$(JAVA_HOME)jre/lib/amd64/server -L$(JAVA_HOME)jre/lib/amd64 -L$(JAVA_HOME)jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm' checking whether JNI programs can be compiled... yes checking JNI data types... ok checking whether JRI should be compiled (autodetect)... yes checking whether debugging output should be enabled... no checking whether memory profiling is desired... no checking whether threads support is requested... no checking whether callbacks support is requested... no checking whether JNI cache support is requested... no checking whether JRI is requested... yes configure: creating ./config.status config.status: creating src/Makevars config.status: creating R/zzz.R config.status: creating src/config.h === configuring in jri (/tmp/RtmpUH5YdX/R.INSTALL3e0ff145/rJava/jri) configure: running /bin/sh ./configure '--prefix=/usr/local' --cache-file=/dev/null --srcdir=. checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for gcc... gcc -m64 -std=gnu99 checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of
[R] 3D plots
Hi, Which package is your favorite one to create 3D bar plots? Which package is the easiest and fastest to use to your mind? I tried to download the R.basic package that has plot3d integrated. Unfortunately the installation from Henrik's webpage doesn't work. Do you know where else to get it from? Is there an update? Or maybe an even better package for plotting in 3D? 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] kernel density
Hi all (again), many thanks for the answer to the optimization problem. All is fine now. The problem now is with kernel estimators in sm. package. I do all the work and the graphics good, but I need the density function data for each point, and I don't know how to get it. The only thing I get is the table at the end of the following sequence: Kernel-sm.density(Kernel,model=Normal) Loading required package: rpanel Loading required package: tcltk Loading Tcl/Tk interface ... done Package `rpanel', version 1.0-6 type help(rpanel) for summary information Loading required package: rgl Loading required package: misc3d summary(Kernel) Length Class Mode eval.points 60 -none- numeric h 3 -none- numeric h.weights 38 -none- numeric weights 38 -none- numeric scaling1 -none- function estimate8000 -none- numeric surf.ids 3 -none- numeric data 3 -none- list call 3 -none- call Please can anyone help me again? Thanks Pablo -- View this message in context: http://r.789695.n4.nabble.com/kernel-density-tp3265332p3265332.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] Four paramete logistics.
Hi, I have to do a four point logistics for a dataset. All I have is the absorbance value for different proteins and need to get the four Point values. I have no idea where to start. Any suggestions would be much helpful. Thanks Ramya -- View this message in context: http://r.789695.n4.nabble.com/Four-paramete-logistics-tp3265251p3265251.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] Weighted Curve fitting - esp. logarithmic
I am trying to run a curve fit on a regression. The problem is I need to do a weighted curve fitting. Also I believe the best fitting curve is likely to be a logarithmic one, but I also need to figure out how to adjust the properties of different logarithmic curves (different bases, rates of decline. I have only seen weighted curve fitting of any type done in mathworks, any ideas? Many thanks [[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] Creating a list of lists / hclust elements
On Feb 7, 2011, at 4:13 PM, Lui ## wrote: Hi David, I tried this one, but unfortunately it didn't solve the problem (same result as append). Thank you very much for your suggestion! Then give you elements names: cluster_list - list( cl.lst=cluster_list, Hcobj=HCLUSTobject) Lui On Mon, Feb 7, 2011 at 5:14 PM, David Winsemius dwinsem...@comcast.net wrote: On Feb 7, 2011, at 10:45 AM, Lui ## wrote: Dear group, I am currently struggling with the following problem for a while: I want to create a list whose elements consists of lists themselves. More concise: The list elements are HCLUST objects. However, when I try to append the HCLUST objects to my list via: cluster_list - append(cluster_list, HCLUSTobject) Why not?: cluster_list - c(cluster_list, HCLUSTobject) -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD 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] package ChemometricsWithR
That's true but also says: The corresponding R code is provided for all the examples in the book; scripts, functions and data are available in a separate, publicly available R packageso I was assuming that the package was available in CRAN. Thanks anyway. PM On Mon, Feb 7, 2011 at 4:55 PM, David Winsemius dwinsem...@comcast.netwrote: On Feb 7, 2011, at 2:31 PM, Pedro Mardones wrote: Dear all; Does anyone knows where can I find the package ChemometricsWithR mentioned in http://www.springer.com/life+sciences/bioinformatics/book/978-3-642-17840-5 ? Thanks for any hint The preface says: With the book comes a package, too: ChemometricsWithR contains all data sets and functions used in this book. So it appears the answer is ... buy the book. -- David Winsemius, MD West Hartford, CT [[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] fast optimization routines in R
Try the optimx package. It is ideal for doing comparative performance evaluations of different optimizers for box-constrained problems. It unifies about a dozen algorithms under a single function call that is almost identical to that of `optim'. You need to set the control option as `all.methods=TRUE' to get all the algorithms. Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of ppinger Sent: Monday, February 07, 2011 3:45 PM To: r-help@r-project.org Subject: [R] fast optimization routines in R Dear R help archive group, I am looking for a maximization routine that I can use to maximize a large variety of relatively complex likelihoods. I undertand (from previous posts) that coding the objective function more efficiently can help. However, the optimization routine employed seems important too. So far, I have tried the optimization routines optim, maxlik, trust and nlminb. The latter two are much faster than the first ones but nevertheless, it seems to me as if these routines were rather slow, when compared to some of the optimizers in MATLAB. Is there any general advice you can give about which optimization routines in R tend to be particularly fast? Thank you very much, Pia -- View this message in context: http://r.789695.n4.nabble.com/fast-optimization-routines-in-R-tp3265071p3265 071.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 3D plots
On 11-02-07 5:31 PM, danieladna wrote: Hi, Which package is your favorite one to create 3D bar plots? Which package is the easiest and fastest to use to your mind? I tried to download the R.basic package that has plot3d integrated. Unfortunately the installation from Henrik's webpage doesn't work. Do you know where else to get it from? Is there an update? Or maybe an even better package for plotting in 3D? Thank you! plot3d is a function in the rgl package, but that package doesn't do 3d bar plots. It does have the lower level things to put together your own, and others have probably done that. The way I'd do it would be to take the cube3d() object and transform it to draw each bar. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Subsampling out of site*abundance matrix
So, after thinking about this a bit, I realized that the previous solution wasn't exactly what I needed. I really needed replacement=F and to be able to choose any sample size (n.sample) less than or equal to the site (row) with the lowest total abundance. Anyway, I think this works. Forgive me if I have misunderstood something regarding the previous solutions output. I do not pretend to be intelligent.Cheers! ### start function ### RAND_L - function(L.matrix, n.sample){ mainout - vector(list) for(i in 1:nrow(L.matrix)){ ## decomposes species (1:ncol(L.matrix)) into a list of counts per each out- vector(list) for(j in 1:length(L.matrix[i,])){ out[[j]] - rep(names(L.matrix[i,])[j], L.matrix[i,j]) } ## puts previous loop products (counts) in a row out2 - vector() for(k in 1:length(out)){ out2 - append(out2, as.character(unlist(out[k]))) } out3- sample(out2, n.sample, replace=F) mainout[[i]] - out3 mainout[[i]] - factor(mainout[[i]], levels= colnames(L.matrix)) } finalout - t(sapply(mainout, table)) rownames(finalout)-rownames(L.matrix) return(finalout) } ### end function ## RAND_L(abund2, 100) spA spB spC spD spa spF spG site1 11 12 18 8 0 24 27 site2 24 24 0 0 27 25 0 site3 0 0 6 38 0 0 56 site4 27 20 0 0 16 37 0 -- View this message in context: http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3265402.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] package ChemometricsWithR
On Feb 7, 2011, at 6:26 PM, Pedro Mardones wrote: That's true but also says: The corresponding R code is provided for all the examples in the book; scripts, functions and data are available in a separate, publicly available R packageso I was assuming that the package was available in CRAN. Thanks anyway. I looked at CRAN and the Task View and did a search in RSiteSearch, and no, it's not on CRAN. I didn't search on BioConductor. when I concluded it was being published only with the book, but I did just now and it's not there either. I think you should have emailed the author, as your first effort. -- David. PM On Mon, Feb 7, 2011 at 4:55 PM, David Winsemius dwinsem...@comcast.net wrote: On Feb 7, 2011, at 2:31 PM, Pedro Mardones wrote: Dear all; Does anyone knows where can I find the package ChemometricsWithR mentioned in http://www.springer.com/life+sciences/bioinformatics/book/978-3-642-17840-5? Thanks for any hint The preface says: With the book comes a package, too: ChemometricsWithR contains all data sets and functions used in this book. So it appears the answer is ... buy the book. -- David Winsemius, MD West Hartford, CT David Winsemius, MD West Hartford, CT [[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] Using Aggregate for Date
Hi, I am trying to find the min of day for each student in each year. Here is the dataset: date studentid year 1/1/05 6:07 AM 236 20082009 3/27/09 9:45 AM 236 20082009 4/29/09 8:44 AM 236 20082009 3/27/09 11:36 AM310 20082009 4/1/09 10:43 AM 310 20082009 10/15/09 8:54 AM310 20092010 10/22/09 8:54 AM310 20092010 10/28/09 8:06 AM310 20092010 11/19/09 9:06 AM310 20092010 10/24/07 9:22 AM335 20072008 12/13/07 9:26 AM335 20072008 2/25/09 1:49 PM 335 20082009 3/5/09 2:13 PM 335 20082009 4/15/09 1:53 PM 33520082009 10/24/07 12:14 PM 126 20072008 11/7/07 12:21 PM126 20072008 3/19/09 8:45 AM 177 20082009 4/2/09 8:54 AM 177 20082009 4/16/09 9:57 AM 177 20082009 day_min - aggregate(mydata$date, by=list(mydata$schoolid, mydata$year), FUN=min) However, the result shows the date is in format as: 1193242974 instead of mm/dd/yy HH:MM AM. Is there anyway that I can show original date in the result? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Using-Aggregate-for-Date-tp3265417p3265417.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] Using Aggregate for Date
Belle - Assuming that by=list(mydata$schoolid, mydata$year) was a typo and should have been by=list(mydata$studentid, mydata$year), setting class(day_min$x) = 'POSIXct' day_min$x = format(day_min$x,'%m/%d/%y %l:%M %p') should make the mininum days display in the format you want. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Mon, 7 Feb 2011, Belle wrote: Hi, I am trying to find the min of day for each student in each year. Here is the dataset: date studentid year 1/1/05 6:07 AM 236 20082009 3/27/09 9:45 AM 236 20082009 4/29/09 8:44 AM 236 20082009 3/27/09 11:36 AM310 20082009 4/1/09 10:43 AM 310 20082009 10/15/09 8:54 AM310 20092010 10/22/09 8:54 AM310 20092010 10/28/09 8:06 AM310 20092010 11/19/09 9:06 AM310 20092010 10/24/07 9:22 AM335 20072008 12/13/07 9:26 AM335 20072008 2/25/09 1:49 PM 335 20082009 3/5/09 2:13 PM 335 20082009 4/15/09 1:53 PM 33520082009 10/24/07 12:14 PM 126 20072008 11/7/07 12:21 PM126 20072008 3/19/09 8:45 AM 177 20082009 4/2/09 8:54 AM 177 20082009 4/16/09 9:57 AM 177 20082009 day_min - aggregate(mydata$date, by=list(mydata$schoolid, mydata$year), FUN=min) However, the result shows the date is in format as: 1193242974 instead of mm/dd/yy HH:MM AM. Is there anyway that I can show original date in the result? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Using-Aggregate-for-Date-tp3265417p3265417.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using Aggregate for Date
Phil, Thanks a lot, it works well. -- View this message in context: http://r.789695.n4.nabble.com/Using-Aggregate-for-Date-tp3265417p3265469.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.