[R] remove descriptions from output

2012-06-28 Thread Kathie
Dear R users, I'd like to remove some descriptions when I use filter. filter(1:10, rep(1, 3)) Time Series: Start = 1 End = 10 Frequency = 1 [1] NA 6 9 12 15 18 21 24 27 NA That is, I want only this [1] NA 6 9 12 15 18 21 24 27 NA Thank you in advance. Kathie -- View this message

[R] do.call or something instead of for

2012-06-25 Thread Kathie
is that Is there any better idea to avoid for statement for this problem? Thank you in advance. Kathie -- View this message in context: http://r.789695.n4.nabble.com/do-call-or-something-instead-of-for-tp4634421.html Sent from the R help mailing list archive at Nabble.com

[R] Counting the number of integers at one swoop

2011-10-13 Thread Kathie
, in one computation I want to get this vector [1,2,0,3,0,2,1]. Thank you in advance. Kathie -- View this message in context: http://r.789695.n4.nabble.com/Counting-the-number-of-integers-at-one-swoop-tp3901215p3901215.html Sent from the R help mailing list archive at Nabble.com

[R] gradient function in OPTIMX

2011-08-29 Thread Kathie
Dear R users When I use OPTIM with BFGS, I've got a significant result without an error message. However, when I use OPTIMX with BFGS( or spg), I've got the following an error message.

[R] Error: Gradient function might be wrong ----- in OPTIMX

2011-08-29 Thread Kathie
Dear R users When I use OPTIMX with BFGS, I've got the following error message. - optimx(par=theta0, fn=obj.fy, gr=gr.fy, method=BFGS) Error: Gradient function might be wrong - check it!

[R] optimization problems

2011-08-13 Thread Kathie
Dear R users I am trying to use OPTIMX(OPTIM) for nonlinear optimization. There is no error in my code but the results are so weird (see below). When I ran via OPTIM, the results are that Initial values are that theta0 = 0.6 1.6 0.6 1.6 0.7. (In fact true vales are 0.5,1.0,0.8,1.2, 0.6.)

Re: [R] optimization problems

2011-08-13 Thread Kathie
To be honest, The first derivative of my objective function is very complicated so I ignore this. Could it lead to this sort of problem? Kathie -- View this message in context: http://r.789695.n4.nabble.com/optimization-problems-tp3741005p3741010.html Sent from the R help mailing list archive

[R] generate two sets of random numbers that are correlated

2011-08-11 Thread Kathie
Dear R users I'd like to generate two sets of random numbers with a fixed correlation coefficient, say .4, using R. Any suggestion will be greatly appreciated. Regards, Kathryn Lord -- View this message in context:

Re: [R] generate two sets of random numbers that are correlated

2011-08-11 Thread Kathie
almost forgot. In fact, I want to generate correlated Poisson random vectors. Thank you anyway -- View this message in context: http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-correlated-tp3736161p3736287.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] on do.call function

2011-08-09 Thread Kathie
I understood that the function has to be vectorized. I was just wondering which one is faster. Thanks -- View this message in context: http://r.789695.n4.nabble.com/on-do-call-function-tp3727262p3729234.html Sent from the R help mailing list archive at Nabble.com.

[R] problem in do.call function

2011-08-08 Thread Kathie
Dear all, I am trying to use do.call, but I don't think I totally understand this function. Here is an simple example. B - matrix(c(.5,.1,.2,.3),2,2) B [,1] [,2] [1,] 0.5 0.2 [2,] 0.1 0.3 x - c(.1,.2) X - cbind(1,x) X x [1,] 1

[R] on do.call function

2011-08-08 Thread Kathie
Dear all, Even though one of R users answered my question, I cannot understand, so I re-ask this question. I am trying to use do.call, but I don't think I totally understand this function. Here is an simple example. B - matrix(c(.5,.1,.2,.3),2,2)

Re: [R] on do.call function

2011-08-08 Thread Kathie
Thanks a lot all of you Yes, you're right. However, as i know, do.call calls its function once, but apply(or sapply etc) not. So, I think do.call is faster than apply. That's why i am trying to use do.call. Am I right?? -- View this message in context:

[R] efficient way to reduce running time

2011-08-02 Thread Kathie
Dear R users, Would you plz tell me how to avoid this for loop blow?? I think there might be a better way to reduce running time. -- ## y1 and y2 are n*1 vectors for (k in 1:n){

[R] My R code is not efficient

2011-08-02 Thread Kathie
Dear R users, I have two n*1 integer vectors, y1 and y2, where n is very very large. I'd like to compute elbp = 4^(y1) * 5^(y2) * sum_{i=0}^{max(y1, y2)} [{ (y1-i)! * (i)! * (y2-i)! }^(-1)]; that is, I need to compute elbp for each (y1, y2) pair. So I made R code like below, but I don't

[R] create a list under constraints

2011-08-02 Thread Kathie
Hi, R users, Here is an example. k - c(1,2,3,4,5) i - c(0,1,3,2,1) if k=1, then i=0 if k=2, then i=0, 1 if k=3, then i=0, 1, 2, 3 if k=4, then i=0, 1, 2 if k=5, then i=0, 1 so i'd like to create a list like below. list k i 1 1 0 2 2 0 3 2 1 4 3 0 5 3 1 6 3 2 7 3 3 8 4 0 9 4 1 10

[R] expand.gird with constraints?

2011-08-02 Thread Kathie
Hi, R users, Here is an example. k - c(1,2,3,4,5) i - c(0,1,3,2,1) if k=1, then j=0 from i if k=2, then j=0, 1 from i if k=3, then j=0, 1, 2, 3 from i if k=4, then j=0, 1, 2 from i if k=5, then j=0, 1 from i so i'd like to create a list like below. list k j 1 1 0 2 2 0 3 2 1 4 3 0 5

[R] VERY SIMPLE QUESTION

2010-04-16 Thread Kathie
Dear R users, I am looking for more efficient way to compute the followings -- a - matrix(c(1,1,1,1,2,2,2,2),4,2) b - matrix(c(1,2,3,4),4,1) Eventually, I want to get this matrix, `c`. c -

Re: [R] VERY SIMPLE QUESTION

2010-04-16 Thread Kathie
thanks a lot. good day. Kathie On Fri, Apr 16, 2010 at 1:43 PM, Henrique Dallazuanna [via R] ml-node+2013302-929204043-67...@n4.nabble.comml-node%2b2013302-929204043-67...@n4.nabble.com wrote: Try this: sweep(a, 1, b, '/') On Fri, Apr 16, 2010 at 2:30 PM, Kathie [hidden email]http

[R] optimization problem with linear constraints

2010-02-14 Thread Kathie
Dear R users, I need some advises on how to use R to optimize this function with the following constraints. f(x1,x2,x3,y1,y2,y3,) = gamma(x1+x2-1)/{gamma(x1)*gamma(x2)} * y1^(x2-1) * y2^(x1-1) + gamma(x1+x3-1)/{gamma(x1)*gamma(x3)} * y1^(x3-1) * y3^(x1-1) +

[R] optimization problem with constraints...

2009-10-17 Thread kathie
Dear R users, I need some advises on how to use R to optimize a nonlinear function with the following constraints. f(x1,x2,x3,x4,x5,x6) s.t 0 x1 1 0 x2 1 0 x1+x2 1 -inf x3 inf -inf x4 inf 0 x5 inf 0 x6 inf Is there any built-in function or something for these constraint??

[R] ignore an error and go back to ....

2009-08-27 Thread kathie
Dear R users, is there way to ignore an error and go back to 1st line? I mean, #--- while (or repeat) { 1 2 . . . 6 } #- For example, if I have an error in the 6th line,

[R] computation of matrices in list of list

2009-08-22 Thread kathie
Dear R users, I have the list as follows; #-- z [[1]] [[1]][[1]] matrix(A) [[1]][[2]] matrix(B) [[1]][[3]] matrix(C) [[2]] [[2]][[1]] matrix(D) [[2]][[2]] matrix(E) [[2]][[3]] matrix(F)

Re: [R] computation of matrices in list of list

2009-08-22 Thread kathie
Dear Gabor Grothendieck, thank you for your comments. Ive already tried that. but I've got this error message. Reduce(+,z) Error in f(init, x[[i]]) : non-numeric argument to binary operator anyway, thanks ps. is.matrix(z[[1]][[1]]) [1] TRUE I guess the reason Reduce doesn't work is

[R] how to compute this summation...

2009-08-19 Thread kathie
Dear R users, I try to compute this summation, http://www.nabble.com/file/p25054272/dd.jpg where f(y|x) = Negative Binomial(y, mu=exp(x' beta), size=1/alp) http://www.nabble.com/file/p25054272/aa.jpg http://www.nabble.com/file/p25054272/cc.jpg In fact, I tried to use do.call function

[R] character vector - numeric matrix ??

2009-07-28 Thread kathie
Dear R users... I'd like to change this character vector, zz, zz - c(12,56,89) to the following numeric matrix. [,1] [,2] [1,]12 [2,]56 [3,]89 Actually, zz vector has a long length. Any comments will be greatly appreciated. Kathryn Lord -- View this

[R] Splitting matrix into several small matrices

2009-07-27 Thread kathie
Dear R users... I need to split this matrix(or dataframe), for example, z - matrix(c(13,1,1,1,1,12,0,0,0,0,8,1,0,1,1,8,0,1,0,0, 10,1,1,1,1,3,0,1,0,0,3,1,0,1,1,6,1,1,1,1),8,5,byrow = T) z [,1] [,2] [,3] [,4] [,5] [1,] 131111 [2,] 12000

[R] several ifelse problems...

2009-02-13 Thread kathie
Dear R users, From the code below, I try to compute y value. (In fact, y looks like a trapezoid) -- x - seq(0,1,.01) y - ifelse(abs(x-.5)=0.3,0, ifelse(abs(w-.5)=0.4,-1, ifelse((0.1w

[R] re sults from do.call function

2008-11-16 Thread kathie
Dear R users... I made this by help of one of R users. _ X=matrix(seq(1,4), 2 , 2) B=matrix(c(0.6,1.0,2.5,1.5) , 2 , 2) func - function(i,y0,j) { y0*exp(X[i,]%*%B[,j]) } list1 - expand.grid( i=c(1,2) , y0=c(1,2) , j=c(1,2) )

[R] Re move repeated values

2008-10-08 Thread kathie
Dear R users, I'd like to make this data rem.y = c(-1,0,2,4,5) from y = c(-1,-1,0,2,2,2,2,4,4,5,5,5,5,5). That is, I need to remove repeated values. Here is my code, but I don't think it is efficient. How could I improve this?

[R] In the OPTIM message....

2008-10-02 Thread kathie
Dear all When I used the method, L-BFGS-B, in OPTIM, I've got the following message. - $par [1] 0.176166426835580 $value [1] 1322.17600079332 $counts function gradient 88 $convergence [1] 0 $message [1]

[R] more efficient double summation...

2008-08-29 Thread kathie
Dear R users... I made the R-code for this double summation computation http://www.nabble.com/file/p19213599/doublesum.jpg - Here is my code.. sum(sapply(1:m, function(k){sum(sapply(1:m,

[R] more efficient double sum computation ...

2008-08-29 Thread kathie
Dear R users... I made the R-code for this double summation computation http://www.nabble.com/file/p19213463/doublesum.jpg - Here is my code.. sum(sapply(1:m, function(k){sum(sapply(1:m,

[R] integration error when I use optim and integrate simultaneously

2008-04-26 Thread kathie
Dear R users, When I use two functions, 'optim' and 'integrate', simultaneously, I always get an error like this -- numint = function(z) { dlnorm(z,mu[1],sqrt(exp(g[1]))) *

[R] means and variances of several groups in the matrix

2008-04-21 Thread kathie
Dear R users, I have 32 observations in data x. After sorting this, I want to compute means and variances of 3 groups divided by nr. Actually, the number of groups is flexible. Any suggestion will be greatly appreciated. Kathryn Lord

Re: [R] How to improve the OPTIM results

2008-04-06 Thread kathie
exists, etc. If anyone is interested in collaborating on this, please contact me off-line. Hope this helps. Spencer kathie wrote: Dear R users, I used to OPTIM to minimize the obj. function below. Even though I used the true parameter values as initial values

[R] How to improve the OPTIM results

2008-04-05 Thread kathie
Dear R users, I used to OPTIM to minimize the obj. function below. Even though I used the true parameter values as initial values, the results are not very good. How could I improve my results? Any suggestion will be greatly appreciated. Regards, Kathryn Lord

[R] scaling problems in optim

2008-03-23 Thread kathie
Dear R users, I am trying to figure out the control parameter in optim, especially, fnscale and parscale. In the R docu., -- fnscale An overall scaling to be applied to the value of fn and gr during optimization. If negative, turns the

[R] problem with optim and integrate

2008-03-19 Thread kathie
Dear all, I want to min integrate( (p1*dnorm+p2*dnorm+p3*dnorm)^(1.3)) for p, mu, and sigma. So, I have to estimate 8 parameters(p3=1-p1-p2). Sometimes I got some results, but it was bad, sometimes, I got this warning-Error in integrate(numint, lower = -Inf, upper = Inf) : non-finite function