search for: ans2

Displaying 20 results from an estimated 24 matches for "ans2".

Did you mean: ans
2006 Mar 09
0
When calling external C-function repeatedly I get different results; can't figure out why..
...uot;N", *transb = "N"; double one = 1.0, zero = 0.0; F77_CALL(dgemm)(transa, transb, &nrx, &ncy, &ncx, &one, x, &nrx, y, &nry, &zero, z, &nrx); } SEXP trProd2(SEXP x, SEXP y) { int nrx, ncx, nry, ncy, mode, i; SEXP xdims, ydims, ans, ans2, tr; xdims = getAttrib(x, R_DimSymbol); ydims = getAttrib(y, R_DimSymbol); mode = REALSXP; nrx = INTEGER(xdims)[0]; ncx = INTEGER(xdims)[1]; nry = INTEGER(ydims)[0]; ncy = INTEGER(ydims)[1]; PROTECT(ans = allocMatrix(mode, nrx, ncy)); PROTECT(ans2 = allocMatrix(mode, nrx, ncy));...
2006 Mar 09
0
When calling external C-function repeatedly I get differentresults; can't figure out why..
...t; double one = 1.0, zero = 0.0; > F77_CALL(dgemm)(transa, transb, &nrx, &ncy, &ncx, &one, > x, &nrx, y, &nry, &zero, z, &nrx); } > > SEXP trProd2(SEXP x, SEXP y) > { > int nrx, ncx, nry, ncy, mode, i; > SEXP xdims, ydims, ans, ans2, tr; > xdims = getAttrib(x, R_DimSymbol); > ydims = getAttrib(y, R_DimSymbol); > mode = REALSXP; > nrx = INTEGER(xdims)[0]; > ncx = INTEGER(xdims)[1]; > nry = INTEGER(ydims)[0]; > ncy = INTEGER(ydims)[1]; > PROTECT(ans = allocMatrix(mode, nrx, ncy)); >...
2011 Apr 26
7
Second largest element from each matrix row
Hi, I need to extract the second largest element from each row of a matrix. Below is my solution, but I think there should be a more efficient way to accomplish the same, or not? set.seed(1) a <- matrix(rnorm(9), 3 ,3) sec.large <- as.vector(apply(a, 1, order, decreasing=T)[2,]) ans <- sapply(1:length(sec.large), function(i) a[i, sec.large[i]]) ans Thanks in advance for your
2004 Jul 03
4
counting the occurrences of vectors
Hi: I have two matrices, A and B, where A is n x k, and B is m x k, where n >> m >> k. Is there a computationally fast way to count the number of times each row (a k-vector) of B occurs in A? Thanks for any suggestions. Best, Ravi. [[alternative HTML version deleted]]
2012 Aug 04
3
Head or Tails game
Hi, Reading about a "Heads and Tails" game in http://www.dartmouth.edu/~chance/teaching_aids/books_articles/probability_book/amsbook.mac.pdf Introduction to Probability (Example 1.4, pp. 5-8). You toss a coin 40 times. If heads, Peter wins $1, tails, he loses $1. I think I can do that ok with: winnings <- sum(sample(c(-1,1), 40, replace=TRUE)) But I have to do it 10,000 times
2007 Jul 19
0
a type of generalized inner product
...instead of two. Although, the above is what I want to do for my application, in fact it would be nice to be able to do this for three (or more) arrays in three (or more) specified slots. We should also be able do it with outer and apply: y <- outer(outer(x,mat1),mat2) len <- length(dim(y)) ans2 <- apply(y,c(1:len)[-c(r,len-3,len-1)],FUN=sum) But for some reason I can't get this to give the same answer as above even though dim(ans)=dim(ans2). I think apply is not doing what I think it is doing. Taking the double outer is bad news efficiency wise anyway. Any help, ideas, or directi...
2009 Aug 25
0
analysis of categorical data
...t how can I mix these methods? Also, I need to be able to do post-hoc comparisons in all dimensions. Any ideas or references? I'd be happy to share more details as needed. Here is a sample from the data. All together, there are 366 subjects. There are 4 levels of Test_no (1,2,3,4), Ans1 and Ans2 are the within subject measures, and there are 8 levels of Ans* (cor, SE, CP, CPSE, FoM, FoMSE, zero, other). Thanks, again! SID Test_No Ans1 Ans2 1 1 other other 2 1 CPSE CP 3 1 other other 4 1 SE SE 5 1 FoM CP 6 1 FoM CPSE 7 2 cor cor 8 2 cor cor 9 2 cor cor 10 2 CPSE CPSE 11 2 cor cor 12 2 CPS...
2010 Feb 17
2
Trouble with optim function
Hi all, I'm trying to make a little script to determine an "unknown" rate for a number of known exponential trials. My Code: #Set Trials and generate number trials=100 rand<-runif(1,0,1) vector=0 #Generate vector of 100 random exponentials and sum them for (i in 1:100) { vector<-rexp(trials,rate=rand) } sumvect=sum(vector) #Create the log likelihood function
2010 Jun 29
1
Performance enhancement for ave
library(plyr) n<-100000 grp1<-sample(1:750, n, replace=T) grp2<-sample(1:750, n, replace=T) d<-data.frame(x=rnorm(n), y=rnorm(n), grp1=grp1, grp2=grp2) system.time({ d$avx1 <- ave(d$x, list(d$grp1, d$grp2)) d$avy1 <- ave(d$y, list(d$grp1, d$grp2)) }) # user system elapsed # 39.300 0.279 40.809 system.time({ d$avx2 <- ave(d$x, interaction(d$grp1, d$grp2, drop =
2010 Dec 15
3
Applying function to a TABLE and also "apply, tapply, sapply etc"
...   30         3                          11 I need to run the function 'fun' for each pair of values taken by variable_1 and variable_2 separately. Also, the results (= 30, 70 and 14) obtained for each of above pairs should be stored in different csv files, say "ans1.csv", "ans2.csv" and "ans3.csv" respectively which I can use for further analysis. (In reality each of these output files will consists of 1000 records). As I had mentioned in my earlier mail, I am new to R and I think I should be using apply or sapply or tapply etc., which I have tried but I...
2010 Feb 12
1
paired wilcox test on each row of a large dataframe
hI I have to calculate V statistic for each row of a large dataframe (28000). I can not use multtest package for paired wilcox test. I have been using for loop which are. Is there a way to speed the computation with another method like using apply or tapply? My data set looks like this: 11573_MB 11911_MB 11966_MB 12091_MB 12168_MB 12420_MB................ cg00000292
2012 Aug 04
1
how to coerce the result of sweep to be an array if result of FUN is a string?
Hi, I would like to use sweep to "sweep out" proportions and confidence intervals for an array, however when I supply a function which returns a string (containing something like "9% (3-18%)") I get back a list instead of an array, here is a simplified example: # example showing that sweep does not return an array with same dimensions as STATS as advertised
2012 Sep 02
0
most efficient plyr solution
...no progress update sol2 <- function() { tmp.list <- as.data.frame(rbind(as.numeric(Ax), as.numeric(Ay), as.numeric(Bx), as.numeric(By))) # determine fisher.test p-values as list res2 <- lapply(tmp.list, function(x) { fisher.test( matrix(unlist(x), ncol=2), conf.int=F)$p.value }) ans2 <- matrix(unlist(res2),ncol=4) return(ans2) } s2 <- sol2() ### solution 3 using mclapply # proper answer using input transform, output transform, parallelization, no progress update library(multicore) sol3 <- function() { tmp.list <- as.data.frame(rbind(as.numeric(Ax), as.numeric(Ay...
2004 Jul 01
3
list structure question
Hi, I have a list in which element is a vector (all of the same length and all numeric). I want to find the mean of the first elements of the vectors, the mean of the second elements of the vectors and so on. Currently I convert the list to a data.frame and apply rowMeans(). But is there a way to to do this directly on the list? I seem to recall a post in which there was such a function (or
2013 Feb 14
0
Building a Package & using gWidgets
...s, does some action in simulation. int.func <- function(x){ out <- x*2 return(out) } # Abstract representation of second usable function, takes settings & invokes internal functions generates results & saves as R object files. sim.func <- function(x){ ans <- int.func(x) ans2 <- ans-2 save(ans2, file="outtest") } With my package so far, using it is done like so after loading and attaching the package with library(): INPUT <- settings() fix(settings) # If you want to change from the defaults. sim.func(INPUT) Nothing needs returning from the simulatio...
2008 Aug 27
5
Integrate a 1-variable function with 1 parameter (Jose L. Romero)
Hey fellas: I would like to integrate the following function: integrand <- function (x,t) { exp(-2*t)*(2*t)^x/(10*factorial(x)) } with respect to the t variable, from 0 to 10. The variable x here works as a parameter: I would like to integrate the said function for each value of x in 0,1,..,44. I have tried Vectorize to no avail. Thanks in advance, jose romero
2004 Dec 16
8
counting numbers without replicates in a vector
Hi, I am just wondering if there is an easy way to count in a numeric vector how many numbers don't have replicates. For example, a=c(1,1,2,2,3,4,5), how can I know there are three numbers (3, 4 and 5) without replicates? Thank you! Jun =====
2010 Sep 21
2
Trouble with Optimization in "Alabama" Package
...[6])))))) } hin=function(x,...){ h=rep(NA,2) h[1]=((x[1]^y[5])*(x[3]^(1-y[5])))-((y[1]^y[5])*(y[3]^(1-y[5]))) h[2]=((x[2]^y[6])*(x[4]^(1-y[6])))-((y[2]^y[6])*(y[4]^(1-y[6]))) return(h) } heq=function(x,...){ h=rep(NA,2) h[1]=x[1]+x[2]-y[1]-y[2] h[2]=x[3]+x[4]-y[3]-y[4] return(h) } ans2=constrOptim.nl(par=p1,fn=fn,hin=hin,heq=heq,control.outer=list(itmax= 1000,mu0=.00001),list(y,y,y)) Any advice or explanation of my errors would be greatly appreciated! -- Erik O. Kimbrough Department of Economics (AE1) School of Business and Economics Maastricht University [[alternative HTML...
2007 Feb 08
2
Timings of function execution in R [was Re: R in Industry]
On 2/8/07, Albrecht, Dr. Stefan (AZ Private Equity Partner) <stefan.albrecht at apep.com> wrote: > Dear all, > > Thanks a lot for your comments. > > I very well agree with you that writing efficient code is about optimisation. The most important rules I know would be: > - vectorization > - pre-definition of vectors, etc. > - use matrix instead of data.frame > - do
2009 Dec 08
4
lower.tail option in pnorm
Hi, I would have thought that these two constructions would produce the same result but they do not. Resp <- rbinom(10, 1, 0.5) Stim <- rep(0:1, 5) mm <- model.matrix(~ Stim) Xb <- mm %*% c(0, 1) ifelse(Resp, log(pnorm(Xb)), log(1 - pnorm(Xb))) pnorm(as.vector(Xb), lower.tail = Resp, log.p = TRUE) > ifelse(Resp, log(pnorm(Xb)), log(1 - pnorm(Xb))) [1] -0.6931472 -1.8410216