Re: [R] Merging two data frames, but keeping NAs

2013-12-06 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/05/13, 16:11 , Sarah Goslee wrote: Adding the argument all.x=TRUE to merge() will retain the NA values, but the only reliable way I've found to preserve order with NA values in a merge is to add an index column to x, merge the data, sort on

Re: [R] Merging two data frames, but keeping NAs

2013-12-06 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/05/13, 16:37 , arun wrote: Hi, Try ?join() library(plyr) Well - what would we do without Hadley ... He solved many problems we didn't know we would have soon... Cheers, Rainer y$ref - y$id join(x,y,by=ref) ref id val 1 NA NA NA

[R] How to concatenate the results from parallelized nested foreach loops

2013-12-06 Thread Jairaj Sathyanarayana
Hi all, I am working with data.table objects within nested foreach loops and I am having trouble creating the results object the way I would prefer. Code below with sample data: library(iterators) library(data.table) library(foreach) #generate dummy data set.seed(1212) sample1 -

Re: [R] How to generate a smoothed surface for a three dimensional dataset?

2013-12-06 Thread A Xi Ma
The following question is inspired by Jun's problem, which resembles some of my own problems, but goes off on a tangent about applying plot3D from Karline Soetart. On Thu, Dec 5, 2013 at 11:52 PM, Bert Gunter gunter.ber...@gene.com wrote: Your comment that: I can see the critical point

[R] Generating restricted numbers

2013-12-06 Thread gncl dzgn
Hello everyone, I'm trying to generate a sequence that consists of random numbers and the following algorithm works well ### a - 0.08 b - 0.01 T - 90 t - 0:T alpha - 1 e - rnorm(T, mean = 0, sd = 0.1) d - c( runif(1,0, a*T), rep(0, T-1) ) for (i in 2:T) { d[i] - alpha * d[i-1] + e[i] }

[R] model selection with step()

2013-12-06 Thread Karen Keating
I am using the step() function to select a model using backward elimination, with AIC as the selection criterion. The full regression model contains three predictors, plus all the second order terms and two-way interactions. The full model is fit via lm() using two different model formulae. One

Re: [R] Simple Error Bar

2013-12-06 Thread Rolf Turner
Uh, no. You are forgetting to take the square root of 10, and to divide by the square root of 12. The variance of Y is (exactly) (56^2 - 1)/12, so the variance of Y-bar is this quantity over 10, so the standard deviation of Y-bar is sqrt((56^2 - 1)/12)/sqrt(10). Which is approximately

Re: [R] Simple Error Bar

2013-12-06 Thread mohan . radhakrishnan
The latest code I have put together is this. Could you point out what is missing here ? #Reference values plotted on x-axis. These are constant. #These values could be time of day. So every day at the same #time we could collect other measurements referenceset -

Re: [R] How do I print predicted effect sizes in forest plot?

2013-12-06 Thread Viechtbauer Wolfgang (STAT)
The model you are fitting is a random-effects model and does not include any potential moderators/covariates. Therefore, the estimated intercept of that model is *the* estimated/predicted (average) effect and it applies to each study. That is why the predict function also just gives you that

Re: [R] How do I print predicted effect sizes in forest plot?

2013-12-06 Thread Viechtbauer Wolfgang (STAT)
One more thing ... You used the command: iat_result = rma(yi=Mean, vi=Variance_rounded, ni=N, sei=Std_error, slab=Study_Name, subset=(Country == AUT), data=cma_iat, method=HS) This probably does not do what you want it to do. First of all, if you specify vi, there is no need to specify sei (or

[R] tune an support vector machine

2013-12-06 Thread Uwe Bohne
Hej all, actually i try to tune a SVM in R and use the package e1071 wich works pretty well. I do some gridsearch in the parameters and get the best possible parameters for classification. Here is my sample code type-sample(c(-1,1) , 20, replace = TRUE )

Re: [R] Generating restricted numbers

2013-12-06 Thread Adams, Jean
What value do you want d to take on if it is outside that interval? Here is an example where if d is outside the interval, it is assigned to be one of the interval endpoints. minx - 0 for(i in 2:T) { x - alpha * d[i-1] + e[i] maxx - a*(T-i) if(x minx) { d[i] - minx } else { if(x maxx) {

Re: [R] How do I print predicted effect sizes in forest plot?

2013-12-06 Thread Michael Dewey
At 21:05 05/12/2013, Alma Wilflinger wrote: Hi, I am struggling a bit with creating a forest plot containing the predicted effect size. As seen in other studies these effect sizes are shown per study usually as a light grey diamond - which is what I want to achieve. The calls I use are:

Re: [R] Double Infinite Integration

2013-12-06 Thread Hans W Borchers
Aya Anas aanas at feps.edu.eg writes: Hello all, I need to perform the following integration where the integrand is the product of three functions: f(x)g(y)z(x,y) the limits of x are(0,inf) and the limits of y are(-inf,inf). Could this be done using R? There is a saying: Don't ask

Re: [R] Merging different columns in one matrix

2013-12-06 Thread arun
Hi, May be this helps: dat1 - read.table(text= a a b b c c x y x y x y 12   34   256  25    5   32 5    45    23   452   21   45,sep=,header=TRUE,stringsAsFactors=FALSE,check.names=FALSE)  mat1 - matrix(0,5,5,dimnames=list(NULL,c(x,letters[1:4])))  

[R] Need help figuring out sapply (and similar functions) with multiple parameter user defined function

2013-12-06 Thread Walter Anderson
I am having trouble understanding how to use sapply (or similar functions) with a user defined function with multiple parameters. I have the following functions defined q1.ans - function(x) { retVal = 0 if (x == 1) { retVal = 1 } else if (x ==2) {

Re: [R] Need help figuring out sapply (and similar functions) with multiple parameter user defined function

2013-12-06 Thread PIKAL Petr
Hi The warning is due to fact that if takes only single scalar value not an entire vector. Maybe you shall explain more clearly what result do you expect. I bet that there is vectorised solution to your problem but I am lost in your ifs and cannot follow what shall be the output. Please use

Re: [R] Need help figuring out sapply (and similar functions) with multiple parameter user defined function

2013-12-06 Thread Walter Anderson
Thank you for your response! I am attempting to determine a preference from the answers to three binomial questions; q.1) 1 or 2q.2) 1 or 3q.3) 2 or 3 However, the questions are coded with either a 1 or 2 (though no answer is also possible) and the first three functions (q#.ans)

Re: [R] Need help figuring out sapply (and similar functions) with multiple parameter user defined function

2013-12-06 Thread PIKAL Petr
Hi So first step is over. Anyway, is there any problem with using dput as I suggested? Instead of using your date I need to generate my own. A-sample(0:2, 10, replace=T) B-sample(0:2, 10, replace=T) C-sample(0:2, 10, replace=T) df-data.frame(A,B,C) df[df[,2]==2,2]-3

Re: [R] Need help figuring out sapply (and similar functions) with multiple parameter user defined function

2013-12-06 Thread William Dunlap
I have been researching and it appears that I should be using the sapply function to apply the evaluate.question function above to each row in the data frame like this Read the documentation more closely: sapply(dataFrame, func) applies func() to each column, not row, of dataFrame.

[R] Gene Ontology Profiling on Single Data Set with Different Species?

2013-12-06 Thread Sarah Pohl
Hey everyone, I have a list of genes for which I would like to get Gene Ontology profiles (i.e. what are the most common GO terms). First I had a look at topGO, but since that compares two data sets, which I don’t have, it wasn’t right for this purpose. I then found goProfiles, which seems to

[R] mixed model ANCOVA

2013-12-06 Thread laurie bayet
Hi, I want to set up a mixed model ANCOVA but cannot find a way to do it. There is: * 1 subject factor (random, between subjects) called Subject * 3 categorical within subjects factors called Emotion, Sex, Race * 1 continuous covariate (**WITHIN subjects**) called Score and * a continuous

[R] Help - Trace of matrices

2013-12-06 Thread Wagner Bonat
Dear, I need to calculate the following equation tr(Sigma^-1 %*% D.Sigma) I know only Sigma (positive definite) and D.Sigma (derivative of Sigma), a naive code is sum(diag(solve(Sigma,D.Sigma))) but these matrices are dense and big dimension (1 x 1), and I need to evaluate this

[R] Easy Uplift Tree Classify Error

2013-12-06 Thread Brian
Does anyone know if the error being generated when trying to predict test set data in the Easy Uplift Tree package is something fixable by the user or is this a bug in the program making the package essentially non-operable? This is from the package documentation and fails on the last step of

Re: [R] Help - Trace of matrices

2013-12-06 Thread Doran, Harold
A fast computation I use is based on the following: A - matrix(rnorm(16), ncol = 4) B - matrix(rnorm(16), ncol = 4) C - A %*% B sum(diag(C)) ### This is less expensive to compute when the matrix multiplication is expensive sum(A * t(B)) So, it just uses the elementwise calculations and sums

Re: [R] Need help figuring out sapply (and similar functions) with multiple parameter user defined function

2013-12-06 Thread Walter Anderson
On 12/06/2013 10:43 AM, William Dunlap wrote: I have been researching and it appears that I should be using the sapply function to apply the evaluate.question function above to each row in the data frame like this Read the documentation more closely: sapply(dataFrame, func) applies func() to

Re: [R] mixed model ANCOVA

2013-12-06 Thread Ben Bolker
laurie bayet lauriebayet at gmail.com writes: Hi, I want to set up a mixed model ANCOVA but cannot find a way to do it. There is: * 1 subject factor (random, between subjects) called Subject * 3 categorical within subjects factors called Emotion, Sex, Race * 1 continuous covariate

Re: [R] Open multiple files using a loop

2013-12-06 Thread arun
Hi Chris, May be this helps. #Suppose the working directory is `FirstLevel` D - dir(recursive=TRUE)  D #[1] S1/S1data.txt S2/S2data.txt S3/S3data.txt sapply(D,function(x) nrow(read.table(x,sep=,header=TRUE))) #S1/S1data.txt S2/S2data.txt S3/S3data.txt #   20    20    20

Re: [R] help with the nested anova formulas

2013-12-06 Thread Ben Bolker
Robert Lynch robert.b.lynch at gmail.com writes: I am modeling grade as a function of membership in various cohorts. There are four cohorts. (NONE, ISE07,ISE08,ISE09) and two times of cohorts coded as ISE = TRUE (ISE0#) or FALSE (NONE). There is clear co-linearity but that is to be

Re: [R] p value for mu: anova()

2013-12-06 Thread Ben Bolker
Rosario Garcia Gil M.Rosario.Garcia at slu.se writes: Hello I have run an anova analysis for the fallowing model: H_obs=mu+REGION+MANAGEMENT + e When I run it in ASRelm I get the p-value for mu, and, of course also for the two dependent variables (REGION and MANAGEMENT) When I run

Re: [R] Need help figuring out sapply (and similar functions) with multiple parameter user defined function

2013-12-06 Thread William Dunlap
I understand that such for loops aren't 'best practice' in R and am trying to learn its approach. sapply() is an encapsulated loop and loops have their place in R. 'Best practice' is a nebulous term, but explicit loops can make code that is hard to understand (by a compiler or by a human) and

Re: [R] model selection with step()

2013-12-06 Thread Adams, Jean
Karen, Look at the help for the drop1() function. ?drop1 There you will see, The hierarchy is respected when considering terms to be added or dropped: all main effects contained in a second-order interaction must remain, and so on. So, for fit2, the step() function will only consider

[R] quantiles with approximately the same number of data points within each quantile?

2013-12-06 Thread Anika Masters
What is a good way to create quantiles with approximately the same number of data points within each quantile? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] Need help figuring out sapply (and similar functions) with multiple parameter user defined function

2013-12-06 Thread Walter Anderson
Thanks again! Can the ifelse statement be nested like ifelse(condition1, ifelse(condition2,yes,no) ifelse(condition3,yes,no) ) ? On 12/06/2013 12:23 PM, William Dunlap wrote: I understand that such for loops aren't 'best practice' in R and am trying to learn its approach. sapply() is

Re: [R] quantiles with approximately the same number of data points within each quantile?

2013-12-06 Thread Don McKenzie
By default I believe. See http://en.wikipedia.org/wiki/Quantile Others more erudite may correct me. On Dec 6, 2013, at 11:47 AM, Anika Masters anika.mast...@gmail.com wrote: What is a good way to create quantiles with approximately the same number of data points within each quantile?

Re: [R] quantiles with approximately the same number of data points within each quantile?

2013-12-06 Thread Rui Barradas
Hello, Use function ?quantile. See this example, each group has exactly, not approximately, 25 elements. x - rnorm(100) qnt - quantile(x) tapply(x, findInterval(x, qnt, rightmost.closed = TRUE), length) Hope this helps, Rui Barradas Em 06-12-2013 19:47, Anika Masters escreveu: What is a

Re: [R] How to generate a smoothed surface for a three dimensional dataset?

2013-12-06 Thread David Winsemius
On Dec 5, 2013, at 9:46 PM, A Xi Ma wrote: The following question is inspired by Jun's problem, which resembles some of my own problems, but goes off on a tangent about applying plot3D from Karline Soetart. On Thu, Dec 5, 2013 at 11:52 PM, Bert Gunter gunter.ber...@gene.com wrote:

[R] [R-pkgs] rms 4.1-0

2013-12-06 Thread Frank Harrell
The rms package has had several updates in version 4.1-0: * Fixed orm.fit to not create penalty matrix if not needed (penalties are not yet implemented anyway) * Added yscale argument to plot.Predict * Added Wald test simulation to orm help file * Added example in help file for

Re: [R] R survAUC Package

2013-12-06 Thread David Winsemius
On Dec 4, 2013, at 7:49 AM, kevinod wrote: I have a concern about the survAUC package option AUC.cd. So shouldn't you be sending this to the package authors? They may or may not be regular readers of R help. It's apackage I have never heard of. I am exploring package functionality,

[R] Using assign with mapply

2013-12-06 Thread Julio Sergio Santana
I have a data frame whose first colum contains the names of the variables and whose second colum contains the values to assign to them: : kkk - data.frame(vars=c(var1, var2, var3), vals=c(10, 20, 30), stringsAsFactors=F) If I do : assign(kkk$vars[1], kkk$vals[1])

Re: [R] Wrong date fromat?

2013-12-06 Thread arun
Hi, Try vec1 - 10958:10963  as.Date(vec1,origin=1960-01-01) #[1] 1990-01-01 1990-01-02 1990-01-03 1990-01-04 1990-01-05 #[6] 1990-01-06 A.K. I have imported a stata data into R and wanted to convert the date.  The format went OK, but the output doesn't represent my data. The head of the

Re: [R] Using assign with mapply

2013-12-06 Thread David Winsemius
On Dec 6, 2013, at 11:27 AM, Julio Sergio Santana wrote: I have a data frame whose first colum contains the names of the variables and whose second colum contains the values to assign to them: : kkk - data.frame(vars=c(var1, var2, var3), vals=c(10, 20, 30),

Re: [R] Wrong date fromat?

2013-12-06 Thread Daniel Nordlund
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of arun Sent: Friday, December 06, 2013 3:11 PM To: R help Subject: Re: [R] Wrong date fromat? Hi, Try vec1 - 10958:10963 as.Date(vec1,origin=1960-01-01) #[1] 1990-01-01

Re: [R] kmeans clustering on large but sparse matrix

2013-12-06 Thread Wuming Gong
Hi Lishu, I run into the similar large-scale problems recently. I used a parallel SGD k-means described in this paper for my problem: http://www.eecs.tufts.edu/~dsculley/papers/fastkmeans.pdf Let n be the samples, k be the number of clusters, and m be the number of nodes, 1. First, each node

Re: [R] tune an support vector machine

2013-12-06 Thread Wuming Gong
Hi Uwe, It looks SVM in e1071 and Kernlab does not support feature selection, but you can take a look at package penalizedSVM ( http://cran.r-project.org/web/packages/penalizedSVM/penalizedSVM.pdf). Or you can implement a SVM-RFE (