Re: [R] A problem with using the "outer" function
On Wed, 9 Jul 2003, Duncan Murdoch wrote: > On Wed, 09 Jul 2003 15:33:11 -0400, Ravi Varadhan <[EMAIL PROTECTED]> > wrote : > > >Hi: > > > >I am using R 1.7.0 on Windows. I am having trouble getting "outer" to > >work on one of my functions. > > Most likely the problem is that the function you give doesn't work on > array arguments. Your function needs to take two arrays of the same > shape as the first two arguments, and return an array of answers. > outer() doesn't work by looping, it works by constructing big arrays > of inputs and making just one function call. Two further notes: 1/ This is in the FAQ. 2/ It is possible to use mapply() to vectorise an arbitrary function. There isn't any speed advantage in doing so, but it will then work with outer(). -thomas Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] A problem with using the "outer" function
On Wed, 09 Jul 2003 15:33:11 -0400, Ravi Varadhan <[EMAIL PROTECTED]> wrote : >Hi: > >I am using R 1.7.0 on Windows. I am having trouble getting "outer" to >work on one of my functions. Most likely the problem is that the function you give doesn't work on array arguments. Your function needs to take two arrays of the same shape as the first two arguments, and return an array of answers. outer() doesn't work by looping, it works by constructing big arrays of inputs and making just one function call. Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] A problem with using the "outer" function
Have you tried: outer(b1,b2,FUN=bpllkd,x=x,y=y,n=n) I don't think "outer" quite knows what to do with "x, y, n)". However, "x=x1, y=y1, n=n1") clearly tells outer to pass the object x1 to the argument x of function bpllkd, etc. hope this helps. spencer graves p.s. I was just bitten by that snake last week. Ravi Varadhan wrote: Hi: I am using R 1.7.0 on Windows. I am having trouble getting "outer" to work on one of my functions. Here is a simple example illustrating my problem: b1 <- c(1.2,2.3) b2 <- c(0.5,0.6) x <- c(3e+01, 1e+02, 3e+02, 5e+02, 1e+03, 1e+04, 1e+05, 1e+06) y <- c(2,4,2,5,2,3,1,1) n <- c(5,8,3,6,2,3,1,1) outer(b1,b2,FUN=bpllkd,x,y,n) [,1] [,2] [1,] 17.78031 17.78031 [2,] 17.78031 17.78031 These values should all be different. What is the problem here? The function "bpllkd" is given below: thanks for any help, Ravi. bpllkd function(t1,t2,x,y,n){ p <- 1 - (1+x/10^t1)^(-t2) keep <- !((p==0 & y==0) | (p==1 & n==y)) llk <- sum(y[keep]*log(p[keep])+(n-y)[keep]* log(1-p[keep])) return(-llk) } __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help