[R] legend position in "barplot"

2011-03-20 Thread Hongwei Dong
Hi, R users, I there a way that I can control the position of the legend while using "barplot" function? For example: a<-matrix(c(0,0,0.5,0.8,0.9,0.9),2,3) colnames(a)<-c("X","Y","Z") rownames(a)<-c("A","B") a barplot(a,width = 0.2,legend = TRUE,axes=FALSE,col=c("coral3","steelblue3"),beside=TRU

[R] "aggregate" in R

2011-02-22 Thread Hongwei Dong
Hi, R users, I'm wondering how I can aggregate data in R with different functions for different columns. For example: x<-rep(1:5,3) y<-cbind(x,a=1:15,b=21:35) y<-data.frame(y) I want to aggregate "a" and "b" in y by "x". With "a", I want to use function "mean"; with "b", I want to use function "

[R] identify an element in a column

2011-02-22 Thread Hongwei Dong
Hi, R users, I'm wondering if I can identify an element in a column by an element in another column. For example: x<-1:10 y<-11:20 z<-cbind(x,y) z x y [1,] 1 11 [2,] 2 12 [3,] 3 13 [4,] 4 14 [5,] 5 15 [6,] 6 16 [7,] 7 17 [8,] 8 18 [9,] 9 19 [10,] 10 20 What I want to do i

[R] Sample function in R???

2011-02-19 Thread Hongwei Dong
Hi, R users, I'm wondering if there a way in R I can select cases based on a probability vector. if a case is selected, that case is marked as 1, otherwise, 0. For example: x<-12:18 y<-1:7 sample(x,2,replace=FALSE,y) I got: [1] 15 17 What I want to see is: [1] 0 0 0 1 0 1 0 Thanks. Gary

[R] use "summary"

2011-02-03 Thread Hongwei Dong
Hi, dear R users, I'm running a Tobit regression and using "summary" to display model results. It used to work. But this time, I kept getting this: > summary(RES_TOBIT) Length Class Mode 1 vglm S4 Could anyone tell me how to solve this problem, and why I got this problem? Thanks.

[R] Maxiter specification in R

2011-01-21 Thread Hongwei Dong
Dear R users, I'm having a problem with maxiter specification in VGLM function. I tried to increase the number of iteration to 100, but it still stopped at 30, which is the default. Here is my script: FIT <- vglm(SFH_PCT ~ RD_DEN + CAR_HH + TRS + RES_L, tobit(Lower=0), maxiter = 100) Thanks Gar

[R] number of iterations in a Tobit model

2011-01-20 Thread Hongwei Dong
Hi, R users, I'm running a Tobit model but convergence can not be reached within 30 iterations. Is there anyway I can change the max number of iterations? Thanks. Gary [[alternative HTML version deleted]] __ R-help@r-project.org mailing list h

[R] reduce the size of points in plot???

2010-10-16 Thread Hongwei Dong
Hi, R users, Can anyone tell me how I can change the size of points in my plot? For example: x <- c(1,3,6,9,12) y <- c(1.5,2,7,8,15) plot(x,y,pch=20) How do I reduce the size of those points? Thanks. Gary [[alternative HTML version deleted]]

[R] how to change the font size of x and y axis labels?

2010-10-06 Thread Hongwei Dong
Dear R users, Anyone can tell me how to change the font size of X and Y axis labels in "plot" function? Thanks. Gary [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE

[R] with data in the form of an R data objecte: Monte Carlo simulation in R

2010-03-23 Thread Hongwei Dong
Hi, please use the following the matrix z as the example: x<-c(2,4,5,7,6,9,8,2,0) y<-matrix(x,3,3) z<-apply(y,2,function(x)x/sum(x)) z On Tue, Mar 23, 2010 at 6:59 PM, David Winsemius wrote: > > On Mar 23, 2010, at 9:05 PM, Hongwei Dong wrote: > > Hi, R-helpers, >

[R] Monte Carlo simulation in R

2010-03-23 Thread Hongwei Dong
Hi, R-helpers, I'm trying to use R to do a Monte Carlo simulation and need the help. What I have is a matrix that consists of the probabilities for the persons to choose zones. For example, in the matrix shown below, each column represents a person, and each row represents a zone. So, the probabil

[R] set condition in R

2009-11-26 Thread Hongwei Dong
Hi, R users, I'm using while() in R to set a condition. My condition is: i<523 or i>535. How should I write this in R? I try "while (i<523 or i>535)" and it does not work. Thanks. Garry On Tue, Nov 10, 2009 at 11:26 AM, Hongwei Dong wrote: > Exactly! Thanks, D

Re: [R] Generate Random Draw from Gamma Distribution Re: Monte Carlo Simulation in R...

2009-11-10 Thread Hongwei Dong
By the way, maybe the number of groups can be determined endogenously. It will be better if I do not have to set the total number of groups exogenously. Thanks Garry On Tue, Nov 10, 2009 at 1:29 PM, Hongwei Dong wrote: > Sorry for the confusion. > > Let me put it in this way. Here we

Re: [R] Generate Random Draw from Gamma Distribution Re: Monte Carlo Simulation in R...

2009-11-10 Thread Hongwei Dong
jhmi.edu > > Webpage: > > http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h > tml > > > > > > > > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help

Re: [R] Generate Random Draw from Gamma Distribution Re: Monte Carlo Simulation in R...

2009-11-10 Thread Hongwei Dong
Thanks. I tried the rgamma function too. But I'm still wondering how I can set the min, max, and sum of the variates created by the random draws. Anyone has a clue? Thanks. Garry On Tue, Nov 10, 2009 at 11:47 AM, David Winsemius wrote: > > On Nov 10, 2009, at 2:26 PM, Hongwei

[R] Generate Random Draw from Gamma Distribution Re: Monte Carlo Simulation in R...

2009-11-10 Thread Hongwei Dong
generate random draw. I'm wondering how I can do this in R. Thanks. Garry On Tue, Nov 10, 2009 at 11:17 AM, Duncan Murdoch wrote: > On 11/10/2009 1:25 PM, Hongwei Dong wrote: > >> Hi, Dear R users, >> >> I'm wondering if I can do Monte Carlo Simulation in R.

[R] Monte Carlo Simulation in R...

2009-11-10 Thread Hongwei Dong
Hi, Dear R users, I'm wondering if I can do Monte Carlo Simulation in R. My problem is like this: I know variable X follows Gamma distribution with shape parameter 0.067 and scale parameter 0.008. The sum of the X is 2000. I need R help me to simulate a vector of X that satisfies both the probabil

[R] How to transform the Matrix into the way I want it ???

2009-11-09 Thread Hongwei Dong
Hi, R users, I'm trying to transform a matrix A into B (see below). Anyone knows how to do it in R? Thanks. Matrix A (zone to zone travel time) zone z1 z2 z3 z1 0 2.9 4.3 z2 2.9 0 2.5 z3 4.3 2.5 0 B: from to time z1 z1 0 z1 z2 2.9 z1 z3 4.3 z2 z1 2.9 z2 z2 0 z2 z3 2.5 z3 z1 4.3 z3 z2 2.5 z

Re: [R] memory limit in R

2009-08-18 Thread Hongwei Dong
ving the portion you need. Try to run with a smaller sample. > > On Mon, Aug 17, 2009 at 2:43 PM, Hongwei Dong wrote: > > Hi, all, I'm doing a discrete choice model in R and kept getting this > error: > > Error: cannot allocate vector of size 198.6 Mb. > > >

[R] memory limit in R

2009-08-18 Thread Hongwei Dong
Hi, all, I'm doing a discrete choice model in R and kept getting this error: Error: cannot allocate vector of size 198.6 Mb. Does this mean the memory limit in R has been reached? > memory.size() [1] 1326.89 > memory.size(TRUE) [1] 1336 > memory.limit() [1] 1535 My laptop has a 4G memory with Wi

Re: [R] why summary() does not work here???

2009-08-16 Thread Hongwei Dong
On Sun, Aug 16, 2009 at 12:34 PM, Gavin Simpson wrote: > On Sun, 2009-08-16 at 10:48 -0700, Hongwei Dong wrote: > > I'm quite sure the VGAM package has been installed because I used it to > > estimate the model before I use summary(). One reason I can guess is that > > th

Re: [R] why summary() does not work here???

2009-08-16 Thread Hongwei Dong
loading VGAM package. > > > 2009/8/16 Hongwei Dong : > > Hi, R users, > > I'm using the function "vglm" to estimate a multinomial logit model. > Every > > time I use "summary()" to ask for the coefficients and std error, I got > > this:

[R] why summary() does not work here???

2009-08-15 Thread Hongwei Dong
Hi, R users, I'm using the function "vglm" to estimate a multinomial logit model. Every time I use "summary()" to ask for the coefficients and std error, I got this: Length Class Mode 1 vglm S4 Anyone know what's wrong here? Thanks. Harry [[alternative HTML version delet

Re: [R] Estimate Discrete Choice Models with R

2009-08-15 Thread Hongwei Dong
vices? Thanks. Harry On Fri, Aug 14, 2009 at 3:49 PM, Hongwei Dong wrote: > Hi, R users, > Does anyone know whether there are any Discrete Choice Modeling modules > for R? Any books or websites discussing this? > > Thanks > > Harry > > >

[R] Estimate Discrete Choice Models with R

2009-08-14 Thread Hongwei Dong
Hi, R users, Does anyone know whether there are any Discrete Choice Modeling modules for R? Any books or websites discussing this? Thanks Harry [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/ma

Re: [R] lme funcion in R

2009-08-05 Thread Hongwei Dong
> > The combination of some data and an aching desire for an answer does not > ensure that a reasonable answer can be extracted from a given body of > data. > ~ John Tukey > > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-projec

Re: [R] lme funcion in R

2009-08-04 Thread Hongwei Dong
7:11 PM, David Winsemius wrote: > > On Aug 4, 2009, at 9:06 PM, Hongwei Dong wrote: > > Thanks, David, you are right. If I use continuous data such as 1, 2, ...6 > to represent those 6 housing types, the model works with the lme function in > R. The problem is, the relationship

Re: [R] lme funcion in R

2009-08-04 Thread Hongwei Dong
In addition, it seems the lme function in R are very troubled with the dummy variables used at the first (random) level. Harry On Tue, Aug 4, 2009 at 6:06 PM, Hongwei Dong wrote: > Thanks, David, you are right. If I use continuous data such as 1, 2, ...6 > to represent those 6 housing

Re: [R] lme funcion in R

2009-08-04 Thread Hongwei Dong
On Tue, Aug 4, 2009 at 5:47 PM, David Winsemius wrote: > > On Aug 4, 2009, at 7:48 PM, Hongwei Dong wrote: > > Yeah, I have a very large sample size, about 60,000 observations. >> Multicollinearity should not be a problem here. The weird thing is that >> SPSS >> can c

Re: [R] lme funcion in R

2009-08-04 Thread Hongwei Dong
5.8 ... > $ pct_vacant : num 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 ... $ > transit_D : > num 0 0 0 0 0 0 0 0 0 0 ... $ park_dum : num 0 0 0 0 0 0 0 0 0 0 ... > > > Thanks. > > Harry > > > > On Mon, Aug 3, 2009 at 10:36 AM, Jason Morgan > wrote: > > > O

Re: [R] lme funcion in R

2009-08-03 Thread Hongwei Dong
Thanks. I tried to set a higher tolerance for the convergence, such as changing tolerance from 1e-6 to 1e-5, msTol from 1e-7 to 1e-6, but R still does not converge. Any more suggestions? Harry On Mon, Aug 3, 2009 at 10:36 AM, Jason Morgan wrote: > On 2009.08.03 10:15:46, Hongwei Dong wr

[R] What does this error message mean?

2009-08-03 Thread Hongwei Dong
Hi, I used R to run a linear regression and keep getting the following error message. I do not understand it very well. Anyone can help out? Thanks. Error in storage.mode(y) <- "double" : invalid to change the storage mode of a factor In addition: Warning message: In model.response(mf, "numeric"

Re: [R] lme funcion in R

2009-08-03 Thread Hongwei Dong
num 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 ... $ transit_D : num 0 0 0 0 0 0 0 0 0 0 ... $ park_dum : num 0 0 0 0 0 0 0 0 0 0 ... Thanks. Harry On Mon, Aug 3, 2009 at 10:36 AM, Jason Morgan wrote: > On 2009.08.03 10:15:46, Hongwei Dong wrote: > > Hi, R users, > > I'm u

[R] lme funcion in R

2009-08-03 Thread Hongwei Dong
Hi, R users, I'm using the "lme" function in R to estimate a 2 level mixed effects model, in which the size of the subject groups are different. It turned out that It takes forever for R to converge. I also tried the same thing in SPSS and SPSS can give the results out within 20 minutes. Anyone c

Re: [R] principal component analysis for class variables

2009-08-03 Thread Hongwei Dong
Hi, R users, I'm using the "lme" function in R to estimate a 2 level mixed effects model, in which the size of the groups are different. It turned out that It takes forever for R to converge. I also tried the same thing in SPSS and SPSS can give the results out within 20 minutes. Anyone can give

Re: [R] how to predict dynamic model in R

2009-07-23 Thread Hongwei Dong
# predict 1 ahead each iteration > for(i in 7:10) { ># fit based on first i-1 values >fit <- dyn$lm(Y ~ L(Y) + z + L(x, 0:1), tz, subset = seq_len(i-1)) ># get prediction for ith value >tz[i, "Y"] <- tail(predict(fit, tz[1:i,]), 1) > } > cbind(

Re: [R] how to predict dynamic model in R

2009-07-23 Thread Hongwei Dong
. Thanks for you patience. I appreciate it. Harry On Thu, Jul 23, 2009 at 5:44 PM, Gabor Grothendieck wrote: > You can't remove Y since its in the rhs of your model. > > On Thu, Jul 23, 2009 at 8:25 PM, Hongwei Dong wrote: > > Thanks, Gabor. Here are the problems I'm tryi

Re: [R] how to predict dynamic model in R

2009-07-23 Thread Hongwei Dong
(1:5) > > mod <- dyn$lm(y ~ lag(x, -1)) > > predict(mod, list(x = zoo(6:10, 6:10))) > 7 8 9 10 > 7 8 9 10 > > > On Thu, Jul 23, 2009 at 12:54 AM, Hongwei Dong wrote: > > I have a dynamic time series model like this: > > dyn$lm( y ~ lag(y,-1) + x + lag(x,-1)

Re: [R] how to predict dynamic model in R

2009-07-23 Thread Hongwei Dong
10))) > > L <- function(x, k = 1) lag(x, -k) > > tt.zoo <- as.zoo(tt) > > fit <- dyn$lm(Y ~ L(Y) + L(x, 0:2) + z, tt.zoo[-10, ]) > > predict(fit, tt.zoo) > 1 2 3 4 5 6 7 8 9 10 11 12 > NA NA 3 4 5 6 7 8 9 10 NA NA > > > > > On Thu, Jul

Re: [R] how to predict dynamic model in R

2009-07-23 Thread Hongwei Dong
t; a minimal amount of data so we can get exactly what you > are getting. > > On Thu, Jul 23, 2009 at 4:48 AM, Hongwei Dong wrote: > > Thanks, Gabor. This is really helpful. > > When the regressive part, lag(Y,-1), is not included, my sytax works > well. > > However, wh

[R] how to predict dynamic model in R

2009-07-22 Thread Hongwei Dong
I have a dynamic time series model like this: dyn$lm( y ~ lag(y,-1) + x + lag(x,-1)+lag(x,-2) ) I need to do an out of sample forecast with this model. Is there any way I can do this with R? It would be greatly appreciated if some one can give me an example. Thanks. Harry [[alternative

[R] Plot two graphs with different ranges in one

2009-07-02 Thread Hongwei Dong
Hi, I'm trying to plot two variables in one graph. One ranges between 0 and 1, while the other ranges between 50 and 500. Can I plot them in one graph with similar scale? Thanks Harry [[alternative HTML version deleted]] __ R-help@r-project.o

[R] How to use "subset" in lm function

2009-06-29 Thread Hongwei Dong
Hi, I'm using R to do a time series analysis. In the model, I use the lags of some variables. such the lags of the variables have different length, I just can't use them directly in the lm function. Intuitively, I feel that "subset" might be useful, but I do not know how to use it. Anyone can give

[R] select number of lags in ADF.test

2009-06-25 Thread Hongwei Dong
Hi, all, According to the ADF.test help,""Singf" removes the non-significant lags at the 10% level of significance until all the selected lags are significant." However, when I use "singf", it still give me the lags that are not significant at 10% level. Anyone knows why? Thanks. Harry