[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. Ka

[R] do.call or something instead of for

2012-06-25 Thread Kathie
quot; are too big. So, my question 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

[R] Counting the number of integers at one swoop

2011-10-13 Thread Kathie
=5) -> 2 sum(y==6) -> 1 However, 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 maili

[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] 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. > optim

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] 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] 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. __

[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: http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-co

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. ___

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: http://r.789695.n4.nabble.com/on-do-c

[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,

[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

[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] 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 1

[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 t

[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){

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.com > wrote: > Try this: > > sweep(a, 1, b, '/') > > On Fri, Apr 16, 2010 at 2:30 PM, Kathie <[hidden > email]<

[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 <- matrix(c(1/1,1/2,1/3,1/4,2/1,

[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) + gamma(x2+x3-1)/{gamma(x2)*gamma(x3)

[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 co

[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, the

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

2009-08-22 Thread kathie
ason "Reduce" doesn't work is that it has multi-dimentional list.. Gabor Grothendieck wrote: > > See this: > > https://stat.ethz.ch/pipermail/r-help/2009-August/208002.html > > On Sat, Aug 22, 2009 at 11:41 AM, kathie > wr

[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) #-

[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] make one matirx in list after removing duplicated rows

2009-07-28 Thread kathie
Dear R users... I have a list, "z", below. z<-list(matrix(c(11,11,9,0,0,0),3,2),matrix(c(10,10,10,1,1,1),3,2), matrix(c(7,10,1,1),2,2)) > z [[1]] [,1] [,2] [1,] 110 [2,] 110 [3,]90 [[2]] [,1] [,2] [1,] 101 [2,] 101 [3,] 101 [[3]]

[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

[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.1 x [1] 0

[R] "assign" statement in S-Plus

2008-12-23 Thread kathie
Dear R users... I need to change the S+ code below to R code. I am wondering if there is a R statement equivalent for "assign" statement in S-plus. prime <- function(x) { 1*(abs(x) < chuber) } assign("prime",prime,frame=

[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) ) resu

[R] make a triple summation more efficient

2008-11-15 Thread kathie
Dear R users... I made the R-code for this triple summation computation http://www.nabble.com/file/p20517134/a.jpg - Here is my code.. x=seq(.1,1,.1); l=10 y=seq(1,10); m=10 z=seq(.1,1,.1); n=10 sum(sapply(1:l, function(i) {sum(sapply(1:m,

[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] "CON

[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, function(j){x[k]*x[j]*dnorm((mu[j]+mu[k])/sqrt(sig[k]+si

[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, function(j){x[k]*x[j]*dnorm((mu[j]+mu[k])/sqrt(sig[k]+sig

[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]))) * dnorm((z-mu[2])/sqrt(exp(g[2])))/sqrt(exp(g

[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
;optimMLE' that would automate > some of this and package it with common 'methods' that would assume that > sum(fn(...)) was either a log(likelihood) or the negative of a > log(likelihood), etc. However, before I do, I need to make more > progress on some of my oth

[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

[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 functio