[R] A problem with using the "outer" function
Ravi Varadhan
rvaradha at jhsph.edu
Wed Jul 9 21:33:11 CEST 2003
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)
}
More information about the R-help
mailing list