Re: [R] OT: distribution of a pathological random variate

2007-08-29 Thread Horace Tso
Thank you Ted, Daniel, and Charles. I thought Cauchy distribution has to do 
with resonance. Didn't know this nice extension.

H.

>>> Ted Harding <[EMAIL PROTECTED]> 8/29/2007 11:02 AM >>>
On 29-Aug-07 17:39:17, Horace Tso wrote:
> Folks,
> 
> I wonder if anything could be said about the distribution of a random
> variate x, where
> 
> x = N(0,1)/N(0,1)
> 
> Obviously x is pathological because it could be 0/0. If we exclude this
> point, so the set is {x/(0/0)}, does x have a well defined
> distribution? or does it exist a distribution that approximates x. 
> 
> (The case could be generalized of course to N(mu1, sigma1)/N(mu2,
> sigma2) and one still couldn't get away from the singularity.)
> 
> Any insight or reference to related discussion is appreciated.
> 
> Horace Tso

A good question -- but it has a long-established answer. X has the
Cauchy distribution, whose density function is

  f(x) = 1/(pi*(1 + x^2))

Have a look at ?dcauchy

It is also the distribution of t with 1 degree of freedom.

See also ?dt

You don;t need to exclude the point (0,0) explicitly, since
it has zero probabilityof occurring. But the chance that the
denominator could be small enough to give a very large value
of X is quite perceptible.

Try

  X<-rcauchy(1000)
  max(X)

and similar. Play around!

Best wishes,
ted.


E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 29-Aug-07   Time: 19:02:32
-- XFMail --

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] OT: distribution of a pathological random variate

2007-08-29 Thread Horace Tso
Folks,

I wonder if anything could be said about the distribution of a random variate 
x, where

x = N(0,1)/N(0,1)

Obviously x is pathological because it could be 0/0. If we exclude this point, 
so the set is {x/(0/0)}, does x have a well defined distribution? or does it 
exist a distribution that approximates x. 

(The case could be generalized of course to N(mu1, sigma1)/N(mu2, sigma2) and 
one still couldn't get away from the singularity.)

Any insight or reference to related discussion is appreciated.

Horace Tso

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] small issue with densityplot

2007-08-21 Thread Horace Tso
Thank you Prof. Bates and Deepayan. As the title of this thread suggests, it is 
a minor issue once the user is familar with where to look for hints. But better 
documentation certainly won't hurt.

H.

>>> "Douglas Bates" <[EMAIL PROTECTED]> 8/21/2007 1:44:11 PM >>>
On 8/21/07, Horace Tso <[EMAIL PROTECTED]> wrote:
> Deepayan, you're right. Now I realize anyone could write a densityplot 
> function to apply on a different class of objects. I guess I should write to 
> the author of lme4 which from what I could see does not describe a 
> densityplot. By the way, it is used in Baayen, Davidson, and Bates (2006).

You're right.  It's my bad for not documenting that the coda package
is required for plots of the results of mcmcsamp.  I was trying to
piggy-back on the work that the authors of the coda package had done
on diagnostics, etc.  It was actually Deepayan and I who added the
lattice-based plots to the coda package for exactly this purpose (did
you remember that, Deepayan?).

In some ways it might be better to remove the dependence on coda and
write the classes and methods in the lme4 package.  That way I can use
S4 classes and irritate all those people who rail against S4 classes
and methods (and you know who you are).

> >>> "Deepayan Sarkar" <[EMAIL PROTECTED]> 8/21/2007 11:17:39 AM >>>
> On 8/21/07, Horace Tso <[EMAIL PROTECTED]> wrote:
> > Hi folks,
> >
> > This is really minor but to someone not familiar with the various tentacles 
> > of the lmer package it could be really annoying. I was trying to plot the 
> > posterior density of the fixed effect parameters of a lmer model,
> >
> > > hr.mcmc = mcmcsamp(hr.lmer, n=5)
> > > densityplot(hr.mcmc, plot.points=F)
> >
> > There is this error,
> >
> > "Error in densityplot(hr.mcmc, plot.points = F) :
> > no applicable method for "densityplot" "
> >
> > It kind of smells like something I've come across before. So I checked the 
> > mcmcsamp help page, and alas, the example suggests that the package coda is 
> > needed.
> >
> > >From the help page of densityplot alone, there is no way one could figure 
> > >out this dependency. It says, together with histogram, it is part of 
> > >lattice.
> >
> > Could the function author *please* make clarification in future editions of 
> > lattice.
>
> There is nothing to clarify. densityplot() is a generic function, and
> it is not possible for the author of the generic function to
> anticipate and document all possible methods, especially those in
> other packages. I would say that since you are using mcmcsamp(), it's
> perfectly reasonable to expect you to look at its help page to figure
> out what you can do with the results.
>
> What gave you the idea that densityplot would work on the result of
> mcmcsamp in the first place?
>
> -Deepayan
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] small issue with densityplot

2007-08-21 Thread Horace Tso
Deepayan, you're right. Now I realize anyone could write a densityplot function 
to apply on a different class of objects. I guess I should write to the author 
of lme4 which from what I could see does not describe a densityplot. By the 
way, it is used in Baayen, Davidson, and Bates (2006).

H.

>>> "Deepayan Sarkar" <[EMAIL PROTECTED]> 8/21/2007 11:17:39 AM >>>
On 8/21/07, Horace Tso <[EMAIL PROTECTED]> wrote:
> Hi folks,
>
> This is really minor but to someone not familiar with the various tentacles 
> of the lmer package it could be really annoying. I was trying to plot the 
> posterior density of the fixed effect parameters of a lmer model,
>
> > hr.mcmc = mcmcsamp(hr.lmer, n=5)
> > densityplot(hr.mcmc, plot.points=F)
>
> There is this error,
>
> "Error in densityplot(hr.mcmc, plot.points = F) :
> no applicable method for "densityplot" "
>
> It kind of smells like something I've come across before. So I checked the 
> mcmcsamp help page, and alas, the example suggests that the package coda is 
> needed.
>
> >From the help page of densityplot alone, there is no way one could figure 
> >out this dependency. It says, together with histogram, it is part of lattice.
>
> Could the function author *please* make clarification in future editions of 
> lattice.

There is nothing to clarify. densityplot() is a generic function, and
it is not possible for the author of the generic function to
anticipate and document all possible methods, especially those in
other packages. I would say that since you are using mcmcsamp(), it's
perfectly reasonable to expect you to look at its help page to figure
out what you can do with the results.

What gave you the idea that densityplot would work on the result of
mcmcsamp in the first place?

-Deepayan

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] small issue with densityplot

2007-08-21 Thread Horace Tso
Hi folks,

This is really minor but to someone not familiar with the various tentacles of 
the lmer package it could be really annoying. I was trying to plot the 
posterior density of the fixed effect parameters of a lmer model,

> hr.mcmc = mcmcsamp(hr.lmer, n=5)
> densityplot(hr.mcmc, plot.points=F)

There is this error,

"Error in densityplot(hr.mcmc, plot.points = F) : 
no applicable method for "densityplot" "

It kind of smells like something I've come across before. So I checked the 
mcmcsamp help page, and alas, the example suggests that the package coda is 
needed.  

>From the help page of densityplot alone, there is no way one could figure out 
>this dependency. It says, together with histogram, it is part of lattice.

Could the function author *please* make clarification in future editions of 
lattice.

Thanks.

Horace W. Tso

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] pvals.fnc unhappy about lmer objects

2007-08-21 Thread Horace Tso
Dear folks (or Dear Professor Bates),

I'm quite confused as to the current status of some of the available
functions applicable to lmer objects. Following the examples in Baayen,
Davidson, Bates (2006), my plan is to run mcmcsamp on a random effect
model created by lmer in package lme4, then use the (perhaps outdated)
pvals to estimate p-value. But then I couldn't find pvals anywhere. 

So question number one is : Has pvals been replaced? by pvals.fnc in
the package languageR perhaps?

>From the help page, it's stated that pvals.fnc takes a model fitted
with lmer, in contrast with the pvals I've read about in Baayen et al,
which takes an mcmc object. So I then tried,

 hr.lmer = lmer(hr ~ tg + spl + (1+tg|M), data=dat)
 pvals.fnc(hr.lmer)

An error is reported,

"Error in get(x, envir, mode, inherits) : variable "Gen.2001" of mode
"function" was not found"

First I suspected it must be my model, so I run through the example in
pvals.fnc help page, as follow,
> data(primingHeid) 
> primingHeid = primingHeid[primingHeid$RT < 7.1,]
> primingHeid = primingHeid[primingHeid$RT < 7.1,]
> primingHeid.lmer = lmer(RT ~ RTtoPrime * ResponseToPrime + 
+ Condition + (1|Subject) + (1|Word), data = primingHeid)
> primingHeid.pvals = pvals.fnc(primingHeid.lmer)

The same error is encountered,

"Error in get(x, envir, mode, inherits) : variable "Gen.2001" of mode
"function" was not found"

Thanks in advance.

Horace W. Tso

*-
PS: I'm on Windows XP,  with R2.5.1 (2007-06-27)

> sessionInfo()
R version 2.5.1 (2007-06-27) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] "splines"   "graphics"  "grDevices" "datasets"  "utils" "stats"
"methods"   "base" 

other attached packages:
   languageRrpart MASS   Design survival   
Hmisce1071class  cluster 
   "0.2" "3.1-37" "7.2-34"  "2.1-1"   "2.32" 
"3.4-2" "1.5-16" "7.2-34" "1.11.7" 
   zipfR coda xlsReadWrite lme4   Matrix 
lattice R.oo  zoo 
 "0.6-0" "0.12-1"  "1.3.2"  "0.99875-7" "0.999375-1"   
"0.15-11"  "1.2.7"  "1.2-2" 
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Constructing correlation matrices (follow up)

2007-07-30 Thread Horace Tso
Greg, in light of Doug Bates' question, what i have suggested a little early in 
response to your question is known as a Wishart matrix with n degree of 
freedom, which is guarenteed to be positive definite. If this is not what you 
want, you have to be more specific about the property of this correlation 
matrix you want to simulate.

H.




=
Greg,

I take it that you're trying to generate a random correlation matrix, so first 
create a covariance matrix,

p = 6
v = matrix(rnorm(p*p), ncol=p)
cov = t(v) %*% v

Then convert it to a correlation matrix,

cov2cor(cov)

HTH.

Horace


>>> Gregory Gentlemen <[EMAIL PROTECTED]> 7/29/2007 7:31:36 PM >>>
Greetings,

I have a seemingly simple task which I have not been able to solve today and I 
checked all of the help archives on this and have been unable to find anything 
useful. I want to construct a symmetric matrix of arbtriray size w/o using 
loops. The following I thought would do it:

p <- 6
Rmat <- diag(p)
dat.cor <- rnorm(p*(p-1)/2)
Rmat[outer(1:p, 1:p, "<")] <- Rmat[outer(1:p, 1:p, ">")] <- dat.cor

However, the problem is that the matrix is filled by column and so the 
resulting matrix is not symmetric.

I'd be grateful for any adive and/or solutions.

Gregory 
   
-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] getting the name of variables passed to a function

2007-07-30 Thread Horace Tso
Thanks to Prof. Brian Ripley, Marc, and Andy. match.call() is what i need. 
After spending a weekend away from email, I stumbled on a thread on exactly the 
same topic this morning, 

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/101445.html 

Horace

>>> "Liaw, Andy" <[EMAIL PROTECTED]> 7/30/2007 9:57:47 AM >>>
Here's one possibility:

R> f <- function(...) { call <- match.call(); sapply(as.list(call[-1]),
deparse) }
R> f(x, y)
[1] "x" "y"
R> f(x=x, y=y)
  x   y 
"x" "y" 

You basically need to know how to manipulate call objects.  The relevant
section in the R Language Definition should help.

Andy

 
From: Horace Tso
> 
> Folks,
> 
> I've entered into an R programming territory I'm not very 
> familiar with, thus this probably very elementary question 
> concerning the mechanic of a function call.
> 
> I want to know from within a function the name of the 
> variables I pass down. The function makes use of the "..." to 
> allow for multiple unknown arguments,
> 
> myfun = function(...) { do something }
> 
> In the body I put,
> 
> {
> nm <- names(list(...))
> nm
> }
> 
> When the function is called with two vectors x, and y
> 
> myfun(x, y)
> 
> It returns NULL. However, when the call made is,
> 
> >myfun(x=x, y=y)
> 
> The result is
> [1] "x" "y"
> 
> Question : how do i get the names of the unknown variables 
> without explicitly saying x=x...
> 
> Thanks in advance.
> 
> Horace
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 


--
Notice:  This e-mail message, together with any attachments,...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Constructing correlation matrices

2007-07-30 Thread Horace Tso
Greg,

I take it that you're trying to generate a random correlation matrix, so first 
create a covariance matrix,

p = 6
v = matrix(rnorm(p*p), ncol=p)
cov = t(v) %*% v

Then convert it to a correlation matrix,

cov2cor(cov)

HTH.

Horace


>>> Gregory Gentlemen <[EMAIL PROTECTED]> 7/29/2007 7:31:36 PM >>>
Greetings,

I have a seemingly simple task which I have not been able to solve today and I 
checked all of the help archives on this and have been unable to find anything 
useful. I want to construct a symmetric matrix of arbtriray size w/o using 
loops. The following I thought would do it:

p <- 6
Rmat <- diag(p)
dat.cor <- rnorm(p*(p-1)/2)
Rmat[outer(1:p, 1:p, "<")] <- Rmat[outer(1:p, 1:p, ">")] <- dat.cor

However, the problem is that the matrix is filled by column and so the 
resulting matrix is not symmetric.

I'd be grateful for any adive and/or solutions.

Gregory 
   
-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] getting the name of variables passed to a function

2007-07-30 Thread Horace Tso
Folks,

I've entered into an R programming territory I'm not very familiar with, thus 
this probably very elementary question concerning the mechanic of a function 
call.

I want to know from within a function the name of the variables I pass down. 
The function makes use of the "..." to allow for multiple unknown arguments,

myfun = function(...) { do something }

In the body I put,

{
nm <- names(list(...))
nm
}

When the function is called with two vectors x, and y

myfun(x, y)

It returns NULL. However, when the call made is,

>myfun(x=x, y=y)

The result is
[1] "x" "y"

Question : how do i get the names of the unknown variables without explicitly 
saying x=x...

Thanks in advance.

Horace

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] create matrix from comparing two vectors

2007-06-26 Thread Horace Tso
In case you really want to use the apply variety, here is another one,

 sapply(fac,function(x)ifelse(test/x<1, 1, 0))

H.

>>> "Van Campenhout Bjorn" <[EMAIL PROTECTED]> 6/26/2007 11:13:14 AM >>>
hi all, sorry for this basic question, I think I know I should use ?apply, but 
it is really confusing me...

I want to create a matrix by comparing two vectors.  Eg:

test<-seq(1:10)
fac<-c(3,6,9)

and i want to end up with a 10*3 matrix with a boolean that tests if testhttps://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Imputing missing values in time series

2007-06-22 Thread Horace Tso
Thanks to Mark and Erik for different versions of locf, also Erik's pointer to 
archive where I found another function due to Simon Fear. I haven't tested the 
zoo locf function. The following shows their performance. Interestingly, Erik's 
use of a while loop is the fastest. 

HT.

x = 1:1e5
x[sample(1:1e5, 1)] = NA

>system.time(z2<-locf.iverson2(x))
   user  system elapsed 
   0.070.000.06 
> system.time(z1<-locf.iverson(x))
   user  system elapsed 
   0.110.000.11 
> system.time(z3<-locf.sfear(x))
   user  system elapsed 
   1.130.001.12 

==
# Due to Erik Iverson
locf.iverson2 = function(x) {
  while(any(is.na(x))) {
x[is.na(x)] <- x[which(is.na(x))-1]
  }
  x
}

# Due to Simon Fear (Fri Nov 14 17:28:57 2003)
locf.sfear = function(x) { 
  assign("stored.value", x[1], envir=.GlobalEnv) 
  sapply(x, function(x) { 
if(is.na(x)) 
  stored.value 
else { 
  assign("stored.value", x, envir=.GlobalEnv) 
  x 
}}) 
} 

# Due to Erik Iverson 
locf.iverson = function(x, unkn=-1) {
  x[is.na(x)] = unkn  #something that is not a possible price
  run = rle(x)
  run$values[run$values==unkn] = run$values[which(run$values==unkn)-1]
  inverse.rle(run)
}


>>> "Horace Tso" <[EMAIL PROTECTED]> 6/22/2007 12:21 PM >>>
Mark, thanks for the tips. I thought you financial folks must have run into 
things like these before. Just wonder why this problem wasn't asked more often 
on this list.

H.


>>> "Leeds, Mark (IED)" <[EMAIL PROTECTED]> 6/22/2007 12:16 PM >>>
I have a function that does this type of thing but it works off a pure
vector so it wouldn have to be modified.
If you make your object a zoo object, the that object has many functions
associated with it and na.locf would
Do what you need, I think.


-Original Message-----
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of Erik Iverson
Sent: Friday, June 22, 2007 3:02 PM
To: Horace Tso
Cc: r-help@stat.math.ethz.ch 
Subject: Re: [R] Imputing missing values in time series

I think my example should work for you, but I couldn't think of a way to
do this without an interative while loop.

test <- c(1,2,3,NA,4,NA,NA,5,NA,6,7,NA)

while(any(is.na(test)))
test[is.na(test)] <- test[which(is.na(test))-1]

  test
  [1] 1 2 3 3 4 4 4 5 5 6 7 7

Horace Tso wrote:
> Folks,
> 
> This must be a rather common problem with real life time series data 
> but I don't see anything in the archive about how to deal with it. I 
> have a time series of natural gas prices by flow date. Since gas is 
> not traded on weekends and holidays, I have a lot of missing values,
> 
> FDate Price
> 11/1/2006 6.28
> 11/2/2006 6.58
> 11/3/2006 6.586
> 11/4/2006 6.716
> 11/5/2006 NA
> 11/6/2006 NA
> 11/7/2006 6.262
> 11/8/2006 6.27
> 11/9/2006 6.696
> 11/10/20066.729
> 11/11/20066.487
> 11/12/2006NA
> 11/13/2006NA
> 11/14/20066.725
> 11/15/20066.844
> 11/16/20066.907
>  
> What I would like to do is to fill the NAs with the price from the 
> previous date * gas used during holidays is purchased from the week 
> before. Though real simple, I wonder if there is a function to perform

> this task. Some of the imputation functions I'm aware of (eg. impute, 
> transcan in Hmisc) seem to deal with completely different problems.
> 
> 2.5.0/Windows XP
> 
> Thanks in advance.
> 
> HT
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.


This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Imputing missing values in time series

2007-06-22 Thread Horace Tso
Mark, thanks for the tips. I thought you financial folks must have run into 
things like these before. Just wonder why this problem wasn't asked more often 
on this list.

H.


>>> "Leeds, Mark (IED)" <[EMAIL PROTECTED]> 6/22/2007 12:16 PM >>>
I have a function that does this type of thing but it works off a pure
vector so it wouldn have to be modified.
If you make your object a zoo object, the that object has many functions
associated with it and na.locf would
Do what you need, I think.


-Original Message-
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of Erik Iverson
Sent: Friday, June 22, 2007 3:02 PM
To: Horace Tso
Cc: r-help@stat.math.ethz.ch 
Subject: Re: [R] Imputing missing values in time series

I think my example should work for you, but I couldn't think of a way to
do this without an interative while loop.

test <- c(1,2,3,NA,4,NA,NA,5,NA,6,7,NA)

while(any(is.na(test)))
test[is.na(test)] <- test[which(is.na(test))-1]

  test
  [1] 1 2 3 3 4 4 4 5 5 6 7 7

Horace Tso wrote:
> Folks,
> 
> This must be a rather common problem with real life time series data 
> but I don't see anything in the archive about how to deal with it. I 
> have a time series of natural gas prices by flow date. Since gas is 
> not traded on weekends and holidays, I have a lot of missing values,
> 
> FDate Price
> 11/1/2006 6.28
> 11/2/2006 6.58
> 11/3/2006 6.586
> 11/4/2006 6.716
> 11/5/2006 NA
> 11/6/2006 NA
> 11/7/2006 6.262
> 11/8/2006 6.27
> 11/9/2006 6.696
> 11/10/20066.729
> 11/11/20066.487
> 11/12/2006NA
> 11/13/2006NA
> 11/14/20066.725
> 11/15/20066.844
> 11/16/20066.907
>  
> What I would like to do is to fill the NAs with the price from the 
> previous date * gas used during holidays is purchased from the week 
> before. Though real simple, I wonder if there is a function to perform

> this task. Some of the imputation functions I'm aware of (eg. impute, 
> transcan in Hmisc) seem to deal with completely different problems.
> 
> 2.5.0/Windows XP
> 
> Thanks in advance.
> 
> HT
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.


This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Imputing missing values in time series

2007-06-22 Thread Horace Tso
Erik, indeed it gets the work done. I was hoping to avoid the dreaded looping, 
though.

Thanks.

Horace

>>> Erik Iverson <[EMAIL PROTECTED]> 6/22/2007 12:01 PM >>>
I think my example should work for you, but I couldn't think of a way to 
do this without an interative while loop.

test <- c(1,2,3,NA,4,NA,NA,5,NA,6,7,NA)

while(any(is.na(test)))
test[is.na(test)] <- test[which(is.na(test))-1]

  test
  [1] 1 2 3 3 4 4 4 5 5 6 7 7

Horace Tso wrote:
> Folks,
> 
> This must be a rather common problem with real life time series data
> but I don't see anything in the archive about how to deal with it. I
> have a time series of natural gas prices by flow date. Since gas is not
> traded on weekends and holidays, I have a lot of missing values,
> 
> FDate Price
> 11/1/2006 6.28
> 11/2/2006 6.58
> 11/3/2006 6.586
> 11/4/2006 6.716
> 11/5/2006 NA
> 11/6/2006 NA
> 11/7/2006 6.262
> 11/8/2006 6.27
> 11/9/2006 6.696
> 11/10/20066.729
> 11/11/20066.487
> 11/12/2006NA
> 11/13/2006NA
> 11/14/20066.725
> 11/15/20066.844
> 11/16/20066.907
>  
> What I would like to do is to fill the NAs with the price from the
> previous date * gas used during holidays is purchased from the week
> before. Though real simple, I wonder if there is a function to perform
> this task. Some of the imputation functions I'm aware of (eg. impute,
> transcan in Hmisc) seem to deal with completely different problems. 
> 
> 2.5.0/Windows XP
> 
> Thanks in advance.
> 
> HT
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Imputing missing values in time series

2007-06-22 Thread Horace Tso
Folks,

This must be a rather common problem with real life time series data
but I don't see anything in the archive about how to deal with it. I
have a time series of natural gas prices by flow date. Since gas is not
traded on weekends and holidays, I have a lot of missing values,

FDate   Price
11/1/2006   6.28
11/2/2006   6.58
11/3/2006   6.586
11/4/2006   6.716
11/5/2006   NA
11/6/2006   NA
11/7/2006   6.262
11/8/2006   6.27
11/9/2006   6.696
11/10/2006  6.729
11/11/2006  6.487
11/12/2006  NA
11/13/2006  NA
11/14/2006  6.725
11/15/2006  6.844
11/16/2006  6.907
 
What I would like to do is to fill the NAs with the price from the
previous date * gas used during holidays is purchased from the week
before. Though real simple, I wonder if there is a function to perform
this task. Some of the imputation functions I'm aware of (eg. impute,
transcan in Hmisc) seem to deal with completely different problems. 

2.5.0/Windows XP

Thanks in advance.

HT

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Viewing a data object

2007-06-13 Thread Horace Tso
Stephen and Christophe,

I'm aware of fix and edit and the few issues with fix. Thus my reluctance to 
use them. Emacs may be the way to go, but from what I heard here it has a steep 
learning curve. The autocompletion feature in 2.5.1 is great. Andy Liaw points 
me to JGR which I'm just about to jump in.

I was hoping something like the head/tail function with a little more 
flexibility may also be useful to a lot of folks here.

vw = function( , location, nlines=10 ) {
 #'...' gives the string fragments that identify an object
 # location : 0.5 = middle, 0.25 = the first quartile, etc
 # nlines : the number of lines to show
}

vw(Auro, 0.5)

returns the middle part of the first data frame it finds with name string 
starting with "Auro". This function should be easy to write with all thse 
regular expression functions.

Well, I'll save it for my Christmas wish list.

H.


>>> Stephen Tucker <[EMAIL PROTECTED]> 6/12/2007 11:25 PM >>>
Hi Horace,

I have also thought that it may be useful but I don't know of any Object
Explorer available for R.

However, (you may alread know this but) 
(1) you can view your list of objects in R with objects(), 
(2) view objects in a spreadsheet-like table (if they are matrices or data
frames) with invisible(edit(objectName)) [which isn't easy on the fingers].
fix(objectName) is also a shorter option but it has the side effect of
possibly changing your object when you close the viewing data. For instance,
this can happen if you mistakenly type something into a cell; it can also
change your column classes when you don't - for example:

> options(stringsAsFactors=TRUE)
> x <- data.frame(letters[1:5],1:5)
> sapply(x,class)
letters.1.5. X1.5 
"factor""integer" 
> fix(x) # no user-changes made
> sapply(x,class)
letters.1.5. X1.5 
"factor""numeric" 

(3) I believe Deepayan Sarkar contributed the tab-completion capability at
the command line. So unless you have a lot of objects beginning with
'AuroraStoch...' you should be able to type a few letters and let the
auto-completion handle the rest.

Best regards,

ST


--- Horace Tso <[EMAIL PROTECTED]> wrote:

> Dear list,
> 
> First apologize that this is trivial and just betrays my slothfulness at
> the keyboard. I'm sick of having to type a long name just to get a glimpse
> of something. For example, if my data frame is named
> 'AuroraStochasticRunsJune1.df" and I want to see what the middle looks
> like, I have to type
> 
> AuroraStochasticRunsJune1.df[ 400:500, ]
> 
> And often I'm not even sure rows 400 to 500 are what I want to see.  I
> might have to type the same line many times.
> 
> Is there sort of a R-equivalence of the Object Explorer, like in Splus,
> where I could mouse-click an object in a list and a window pops up?  Short
> of that, is there any trick of saving a couple of keystrokes here and
> there?
> 
> Thanks for tolerating this kind of annoying questions.
> 
> H.
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
> 



 

Sucker-punch spam with award-winning protection.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Viewing a data object

2007-06-12 Thread Horace Tso
Dear list,

First apologize that this is trivial and just betrays my slothfulness at the 
keyboard. I'm sick of having to type a long name just to get a glimpse of 
something. For example, if my data frame is named 
'AuroraStochasticRunsJune1.df" and I want to see what the middle looks like, I 
have to type

AuroraStochasticRunsJune1.df[ 400:500, ]

And often I'm not even sure rows 400 to 500 are what I want to see.  I might 
have to type the same line many times.

Is there sort of a R-equivalence of the Object Explorer, like in Splus, where I 
could mouse-click an object in a list and a window pops up?  Short of that, is 
there any trick of saving a couple of keystrokes here and there?

Thanks for tolerating this kind of annoying questions.

H.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Excel calling R functions

2007-06-01 Thread Horace Tso
Thanks to Marc, Duncan, Tobias, Alberto. I'm aware of rcom and have in fact 
downloaded it somewhere. But unfortunately it won't work for me as I'm in a 
corporate environment and don't have admin rights to set up the R(D)COM 
(background) server. If there is a way to work around it, pls let me know.

Horace

 

>>> Duncan Temple Lang <[EMAIL PROTECTED]> 6/1/2007 11:27:35 AM >>>
And just for completeness for the thread,
there is the RDCOMServer package which has
a more general mechanism for making R
functionality available to other applications
that does not require writing R commands
but uses the language independent spirit of
DCOM.  And it also allows event handlers
for things like Excel actions to be written as R functions

Tobias Verbeke wrote:
> Marc Schwartz wrote:
>> On Fri, 2007-06-01 at 08:50 -0700, Horace Tso wrote:
>>> Hi folks,
>>>
>>> Is it possible to have Excel call a R function. If not, how about
>>> making Excel send off a command to call a R script and then read the
>>> result back into Excel.
>>>
>>> I know, I know, this should belong to some Excel forum, but i just try
>>> my luck here.
>>>
>>> Thanks in advance.
>>>
>>> Horace W. Tso
>>
>> See the R-Excel add-in linked from here:
>>
>>   http://www.sciviews.org/_rgui/projects/RDcom.html 
>>
> 
> Some of the files listed in the link on that page appear
> to be quite outdated. The following link brings you to
> the current portal of the R(D)COM server and the
> rcom package.
> 
> http://sunsite.univie.ac.at/rcom/ 
> 
> See the Excel heading for your question. You might be
> interested as well by the recent OpenOffice.org plugin
> (heading OOo).
> 
> HTH,
> Tobias
> 

-- 
Duncan Temple Lang[EMAIL PROTECTED] 
Department of Statistics  work:  (530) 752-4782
4210 Mathematical Sciences Bldg.  fax:   (530) 752-7099
One Shields Ave.
University of California at Davis
Davis, CA 95616, USA

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Excel calling R functions

2007-06-01 Thread Horace Tso
Charles, thanks for the thought. In my case that's quite impractical/impossible 
because I'm working from a monstrous spreadsheet having dozens of sheets and 
numerous links. In some way that's the irreplaceable aspect of a spreadsheet 
program like Excel. 

H.

>>> "Charles Annis, P.E." <[EMAIL PROTECTED]> 6/1/2007 9:03:20 AM >>>
You might consider having R do everything:  R can read the Excel sheet, do
what needs to be done, and write the results to an Excel sheet.  



Charles Annis, P.E.

[EMAIL PROTECTED] 
phone: 561-352-9699
eFax:  614-455-3265
http://www.StatisticalEngineering.com 
 

-Original Message-
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of Horace Tso
Sent: Friday, June 01, 2007 11:51 AM
To: r-help@stat.math.ethz.ch 
Subject: [R] Excel calling R functions

Hi folks,

Is it possible to have Excel call a R function. If not, how about making
Excel send off a command to call a R script and then read the result back
into Excel.

I know, I know, this should belong to some Excel forum, but i just try my
luck here.

Thanks in advance.

Horace W. Tso

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Excel calling R functions

2007-06-01 Thread Horace Tso
Hi folks,

Is it possible to have Excel call a R function. If not, how about making Excel 
send off a command to call a R script and then read the result back into Excel.

I know, I know, this should belong to some Excel forum, but i just try my luck 
here.

Thanks in advance.

Horace W. Tso

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] converting a row of a data.frame to a vector

2007-05-15 Thread Horace Tso
probably something like,

unlist(x[1,])

HTH.

H.

>>> "Andrew Yee" <[EMAIL PROTECTED]> 5/15/2007 4:37 PM >>>
I've searched for the answer to this in the help list archive, but wasn't
able to get the answer to work.

I'm interested in converting a row of a data.frame into a vector.

However, when I use as.vector(x,[1,]) I get another data.frame, instead of a
vector.  (On the other hand, when I use as.vector(x,[,1]), I get a vector.)

Thanks,
Andrew

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] statistics/correlation question NOT R question

2007-05-08 Thread Horace Tso
Mark, I suppose you make the usual assumptions, ie. E[x]=0, E[x*epsilon]=0, the 
correlation is just simply,

corr(x,y) = beta * ( var(x) / var(y) )

And you could get var(y) from var(x) and var(epsilon).

HTH.

Horace



>>> "Leeds, Mark (IED)" <[EMAIL PROTECTED]> 5/8/2007 10:25:11 AM >>>
This is not an R question but if anyone can help me, it's much
appreciated.

Suppose I have a series ( stationary ) y_t and a series x_t ( stationary
)and x_t has variance sigma^2_x and epsilon is normal 
(0, sigma^2_epsilon )

and the two series have the relation

y_t = Beta*x_t + epsilon

My question is if there are particular values that sigma^2_x and
sigma^2_epsilon have to take in order for corr(x_t,y_t) to equal Beta ?

I attempted to figure this out using two different methods and in one
case I end up involving sigma^2_epsilon and in the other I don't
and I'm not sure if either method is correct. I think I need to use
results form the conditional bivariate normal but i'm really not sure.
Also, it's not a homework problem because I am too old to have homework.
Thanks for any insights/solutions.


This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to identify and exclude the outliers with R?

2007-04-25 Thread Horace Tso
It depends on the nature of your data set. There is a package simply called 
'outliers', which has the Grubbs/Dixon/Cochran tests. There is also the 
Bonferroni outlier test in 'car' package. I'm sure there are more in the 
hundreds of packages on CRAN.

HTH

Horace

>>> Shao <[EMAIL PROTECTED]> 4/25/2007 6:27:37 AM >>>
Hello, everyone,

I want to ask a simple question.
If I have a set  of data,and I want to identify how many outliers there are
in the data.Which packages and functions can I use?

Thanks.

Shao chunxuan.

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Log-Returns

2007-04-24 Thread Horace Tso
diff(log(x))

And this should be made into a function.

H.




>>> "Soare Marcian-Alin" <[EMAIL PROTECTED]> 4/24/2007 2:17 PM >>>
Hello,

I have a Problem to make Log-Returns of the dataset EuStockMarkets.
Is there any function which could calculate it for me?

data(EuStockMarkets)

Thanks!

Alin Soare

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Size of an object in workspace

2007-04-24 Thread Horace Tso
Aaaah, wonderful. Thanks Ben. lls appears below. Should these functions be a 
permanent part of R? Just a thought.

H.

> lls
function (pos = 1, pat = "") {
dimx <- function(dd) if (is.null(dim(dd)))
length(dd)
else dim(dd)
lll <- ls(pos = pos, pat = pat)
cat(formatC("mode", 1, 15), formatC("class", 1, 18), formatC("name",
1, max(nchar(lll)) + 1), 
"size\n-\n")
if (length(lll) > 0) {
for (i in 1:length(lll)) {
cat(formatC(eval(parse(t = paste("mode(", lll[i],
")"))), 1, 15), formatC(paste(eval(parse(t = paste("class(",
lll[i], ")"))), collapse = " "), 1, 18), formatC(lll[i],
1, max(nchar(lll)) + 1), " ", eval(parse(t = paste("dimx(",
lll[i], ")"))), "\n")
}
}
}


>>> "Ben Fairbank" <[EMAIL PROTECTED]> 4/24/2007 9:10:20 AM >>>
Here is a copy of a correspondence I had with Jim Holtman -- his
function, which I now use almost daily, does exactly what I think you
need.  Could you send me a copy of Bendix Carstensen's function>

Thanks,

Ben Fairbank

From: jim holtman <[EMAIL PROTECTED]> 
To: Ben Fairbank <[EMAIL PROTECTED]> 
Date: Sep 27 2006 - 4:42pm 

 

Thanks for the suggestion. I did.

On 9/27/06, Ben Fairbank <[EMAIL PROTECTED]> wrote:
> Nicely done. May I suggest you post it to the list? Others probably
> would benefit also. Or maybe I am the only user dense enough not to
see
> how to write it.
>
> Ben
>
> -Original Message-
> From: jim holtman [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, September 27, 2006 4:36 PM
> To: Ben Fairbank
> Subject: Re: [R] Space required by object?
>
> That was a function I wrote when I needed a similar thing.
>
> On 9/27/06, Ben Fairbank <[EMAIL PROTECTED]> wrote:
> > Thank you! Exactly what I needed!
> >
> > Is that something you wrote?
> >
> > Ben Fairbank
> >
> > -Original Message-
> > From: jim holtman [mailto:[EMAIL PROTECTED] 
> > Sent: Wednesday, September 27, 2006 4:23 PM
> > To: Ben Fairbank
> > Subject: Re: [R] Space required by object?
> >
> > try this one:
> >

Note --  Horace, the function starts here -- 

my.ls <- function(pos=1, sorted=F){
.result <- sapply(ls(pos=pos, all.names=TRUE),
function(..x)object.size(eval(as.symbol(..x
if (sorted){
.result <- rev(sort(.result))
}
.ls <-
as.data.frame(rbind(as.matrix(.result),"**Total"=sum(.result)))
names(.ls) <- "Size"
.ls$Size <- formatC(.ls$Size, big.mark=',', digits=0, format='f')
.ls$Mode <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
 function(x)mode(eval(as.symbol(x), '---')
.ls
}

And ends there

> >
> >
> > On 9/27/06, Ben Fairbank <[EMAIL PROTECTED]> wrote:
> > > Does R provide a function analogous to LS() or str() that reports
> the
> > > storage space, on disk or in memory, required by objects?
> > >
> > > Ben Fairbank
> > >
> > > __________
> > > R-help@stat.math.ethz.ch mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help 
> > > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html 
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> >
> >
> > --
> > Jim Holtman
> > Cincinnati, OH
> > +1 513 646 9390
> >
> > What is the problem you are trying to solve?
> >


-Original Message-
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of Horace Tso
Sent: Tuesday, April 24, 2007 10:59 AM
To: r-help@stat.math.ethz.ch 
Subject: [R] Size of an object in workspace

Hi folks,

Is there a function to show the size of an R object? eg. in Kbytes?

Couple months ago Bendix Carstensen posted this marvelous little
function lls(), which shows all objects in the current workspace by
mode, class and 'size'. This is a wonderful enhancement to the build-in
ls() already and I now have it sourced in my Rprofile.site at startup. 

The only drawback is, 'size' is just the length/dim of an object. For
matrices and data frames this is good enough. But for a list, knowing
how many elements in there doesn't help much. I need to know the
totality of the content in a common unit, eg. byte. 

Thanks in advance. 

Horace

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Size of an object in workspace

2007-04-24 Thread Horace Tso
Hi folks,

Is there a function to show the size of an R object? eg. in Kbytes?

Couple months ago Bendix Carstensen posted this marvelous little function 
lls(), which shows all objects in the current workspace by mode, class and 
'size'. This is a wonderful enhancement to the build-in ls() already and I now 
have it sourced in my Rprofile.site at startup. 

The only drawback is, 'size' is just the length/dim of an object. For matrices 
and data frames this is good enough. But for a list, knowing how many elements 
in there doesn't help much. I need to know the totality of the content in a 
common unit, eg. byte. 

Thanks in advance. 

Horace

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Bonferroni p-value greater than 1

2007-03-29 Thread Horace Tso
Thank you John and Peter.

Peter, yes I'm guilty of tacking onto a random mail. I thought you couldn't 
tell since I got ride of the text from the last mail. Apologize.

H.

>>> "John Fox" <[EMAIL PROTECTED]> 3/28/2007 5:37 PM >>>
Dear Horace,

The Bonferonni p-value is obtained from the "unadjusted" p-value by
multiplying the latter by the number of observations, and provides a
conservative (although usually quite accurate) outlier test. When the
adjusted p-value exceeds 1 you can take that as an indication that there are
no unusually large studentized residuals (and indeed that the largest
studentized residual is smaller than one would expect under the standard
linear-model assumptions). 

I hope this helps,
 John


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Horace Tso
> Sent: Wednesday, March 28, 2007 6:36 PM
> To: 'R R-help'
> Subject: [R] Bonferroni p-value greater than 1
> 
> Hi folks,
> 
> I use the outlier.test in package car to test a lm model and 
> the bonferroni p value returned is shown as NA. When the 
> object is typed it indicates the p value is greater than 1. 
> I'm not sure how to interpret it. 
> 
> Thanks in advance.
> 
> Horace W. Tso
> 
> 
> > outlier.test(mod)$test
> max|rstudent|df  unadjusted p  Bonferroni p
>2.04106376   18.0.05618628NA 
> 
> > outlier.test(mod)
> 
> max|rstudent| = 2.041064, degrees of freedom = 18,
> unadjusted p = 0.05618628, Bonferroni p > 1
> 
> Observation: 1 
> 
> The lm model looks fine to me,
> 
> > summary(mod)
> 
> Call:
> lm(formula = x ~ ind, na.action = na.fail)
> 
> Residuals:
> Min  1Q  Median  3Q Max 
> -1.2082 -0.5200  0.1309  0.5725  0.9593 
> 
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) 59.845860.31900   187.6  < 2e-16 ***
> ind -0.167680.02541-6.6 2.57e-06 ***
> ---
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
> 
> Residual standard error: 0.705 on 19 degrees of freedom
> Multiple R-Squared: 0.6963, Adjusted R-squared: 0.6803 
> F-statistic: 43.56 on 1 and 19 DF,  p-value: 2.57
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Bonferroni p-value greater than 1

2007-03-28 Thread Horace Tso
Hi folks,

I use the outlier.test in package car to test a lm model and the bonferroni p 
value returned is shown as NA. When the object is typed it indicates the p 
value is greater than 1. I'm not sure how to interpret it. 

Thanks in advance.

Horace W. Tso


> outlier.test(mod)$test
max|rstudent|df  unadjusted p  Bonferroni p 
   2.04106376   18.0.05618628NA 

> outlier.test(mod)

max|rstudent| = 2.041064, degrees of freedom = 18,
unadjusted p = 0.05618628, Bonferroni p > 1

Observation: 1 

The lm model looks fine to me,

> summary(mod)

Call:
lm(formula = x ~ ind, na.action = na.fail)

Residuals:
Min  1Q  Median  3Q Max 
-1.2082 -0.5200  0.1309  0.5725  0.9593 

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 59.845860.31900   187.6  < 2e-16 ***
ind -0.167680.02541-6.6 2.57e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 0.705 on 19 degrees of freedom
Multiple R-Squared: 0.6963, Adjusted R-squared: 0.6803 
F-statistic: 43.56 on 1 and 19 DF,  p-value: 2.57

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] qr decomposition issue inside lm (solved)

2007-03-06 Thread Horace Tso
Folks, apologize for such an obvious oversight on my part. The reason qr
fails is, one of the data points has value of -Inf (response is actually
the log of something, and I have a zero in the original set). That
explains the error message in call to dqrls. I should have taken the
mean of the response before proceeding and that would tell me right away
what's wrong. 

Thanks.

H.

>>> "Horace Tso" <[EMAIL PROTECTED]> 3/6/2007 1:45:28 PM >>>
Dear list,

It's never happened to me before in such a simple exercise but is not
going away and I've checked my data are good. I want a simple lm model
with one response and one predictor, where N is about 4,200 * data set
not exactly small. Both x and y are nice, continuous variables having NA
filtered out with a call to na.omit. So I did

mod = lm( y ~ x, data=x1)

Then the error,

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)
: 
NA/NaN/Inf in foreign function call (arg 4)

I did a trace back and it turned out it's an error thrown by the
Fortran subroutine that seems to be trying a QR decomposition,

traceback()
3: .Fortran("dqrls", qr = x, n = n, p = p, y = y, ny = ny, tol =
as.double(tol), 
   coefficients = mat.or.vec(p, ny), residuals = y, effects = y, 
   rank = integer(1), pivot = 1:p, qraux = double(p), work =
double(2 * 
   p), PACKAGE = "base")
2: lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)
1: lm(log.p.sales ~ log.mktcap, data = x1)

My question is why would QR fail since the default in lm.fit is
'singular.ok' ? Furthermore, is there a way to get around presumably a
singularity in my design matrix? 

Thanks in advance.

Horace W. Tso

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] qr decomposition issue inside lm

2007-03-06 Thread Horace Tso
Dear list,

It's never happened to me before in such a simple exercise but is not going 
away and I've checked my data are good. I want a simple lm model with one 
response and one predictor, where N is about 4,200 * data set not exactly 
small. Both x and y are nice, continuous variables having NA filtered out with 
a call to na.omit. So I did

mod = lm( y ~ x, data=x1)

Then the error,

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
NA/NaN/Inf in foreign function call (arg 4)

I did a trace back and it turned out it's an error thrown by the Fortran 
subroutine that seems to be trying a QR decomposition,

traceback()
3: .Fortran("dqrls", qr = x, n = n, p = p, y = y, ny = ny, tol = 
as.double(tol), 
   coefficients = mat.or.vec(p, ny), residuals = y, effects = y, 
   rank = integer(1), pivot = 1:p, qraux = double(p), work = double(2 * 
   p), PACKAGE = "base")
2: lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)
1: lm(log.p.sales ~ log.mktcap, data = x1)

My question is why would QR fail since the default in lm.fit is 'singular.ok' ? 
Furthermore, is there a way to get around presumably a singularity in my design 
matrix? 

Thanks in advance.

Horace W. Tso

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] putting a column name on a zoo object

2006-11-14 Thread Horace Tso
Mark, it's not the most elegant solution but here it is,

I have a zoo with a vector of numeric values,

> head(spc.z)
2000-01-03 2000-01-04 2000-01-05 2000-01-06 2000-01-07 2000-01-10 
   1455.221399.421402.111403.451441.471457.60 

> class(spc.z)
[1] "zoo"

Now I want to give it a name, 

z = zoo(data.frame(mydata=coredata(spc.z)), index(spc.z))

> head(z)
mydata
2000-01-03 1455.22
2000-01-04 1399.42
2000-01-05 1402.11
2000-01-06 1403.45
2000-01-07 1441.47
2000-01-10 1457.60

HTH

H.


>>> "Leeds, Mark (IED)" <[EMAIL PROTECTED]> 11/14/2006
1:49:24 PM >>>
I only have one column so when I try your suggestion, I get dsays,
"attempt to set colnames on object with less than two dimensions.
It is of class zoo but I guess something changes during that addition
that I am too much of a novice to understand.

This is what a dput gives. There is no dim in the dput which is
probably
what the problem is but I don't know how to fix it. Thanks.


structure(c(4.77126598671015, 4.7716359319335, 4.77176152623894, 
4.77196709472722, 4.77218067995761, 4.77213077515643, 4.77200790109121,

4.77203963822312, 4.7719973218234, 4.771903278968, 4.77183227075241, 
4.77182803831544, 4.77181216651724, 4.77182803831544, 4.77197193112401,

4.77198938729909, 4.77201612933324, 4.77202905929107, 4.7720184802471,

4.77188623275365, 4.77181745714463, 4.77187036187909, 4.77187036187909,

4.77187036187909, 4.77182803831544, 4.77182803831544, 4.77174338581391,

4.77179982161115, 4.77174338581391, 4.77182199194583, 4.77179417817475,

4.77174338581391, 4.77174338581391, 4.77179982161115, 4.77182803831544,

4.77182803831544, 4.77187036187909, 4.77191268365153, 4.7719338438661,

4.77191268365153, 4.77176690111649, 4.77188094249012, 4.77189857659306,

4.77212752040897, 4.77224143026734, 4.77240630536398), index =
structure(c(1144022520, 
1144022580, 1144022640, 1144022700, 1144022760, 1144022820, 1144022880,

1144022940, 1144023000, 1144023060, 1144023120, 1144023180, 1144023240,

1144023300, 1144023360, 1144023420, 1144023480, 1144023540, 1144023600,

1144023660, 1144023720, 1144023780, 1144023840, 1144023900, 1144023960,

1144024020, 1144024080, 1144024140, 1144024200, 1144024260, 1144024320,

1144024380, 1144024440, 1144024500, 1144024560, 1144024620, 1144024680,

1144024740, 1144024800, 1144024860, 1144024920, 1144024980, 1144025040,

1144025100, 1144025160, 1144025220), class = c("POSIXt", "POSIXct"
)), class = "zoo", .Names = c("1144022520", "1144022580", "1144022640",

"1144022700", "1144022760", "1144022820", "1144022880", "1144022940", 
"1144023000", "1144023060", "1144023120", "1144023180", "1144023240", 
"1144023300", "1144023360", "1144023420", "1144023480", "1144023540", 
"1144023600", "1144023660", "1144023720", "1144023780", "1144023840", 
"1144023900", "1144023960", "1144024020", "1144024080", "1144024140", 
"1144024200", "1144024260", "1144024320", "1144024380", "1144024440", 
"1144024500", "1144024560", "1144024620", "1144024680", "1144024740", 
"1144024800", "1144024860", "1144024920", "1144024980", "1144025040", 
"1144025100", "1144025160", "1144025220"))


-Original Message-
From: Leeds, Mark (IED) 
Sent: Tuesday, November 14, 2006 4:39 PM
To: 'Horace Tso'; r-help@stat.math.ethz.ch 
Subject: RE: [R] putting a column name on a zoo object

 let me try colnames. I thought I tried that earlier and got an error
but I've been wrong before.
 Thanks.


-Original Message-
From: Horace Tso [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, November 14, 2006 4:29 PM
To: Leeds, Mark (IED); r-help@stat.math.ethz.ch 
Subject: Re: [R] putting a column name on a zoo object

Mark,

What's wrong with the following,

> head(sp.z)
  OpenHigh Low   Close Volume Adj..Close.
2000-01-03 1469.25 1478.00 1438.36 1455.22  93180 1455.22
2000-01-04 1455.22 1455.22 1397.43 1399.42 100900 1399.42
2000-01-05 1399.42 1413.27 1377.68 1402.11 1085500032 1402.11
2000-01-06 1402.11 1411.90 1392.10 1403.45 1092300032 1403.45
2000-01-07 1403.45 1441.47 1400.73 1441.47 122520 1441.47
2000-01-10 1441.47 1464.36 1441.47 1457.60 106480 1457.60

 colnames(sp.z)
[1] "Open""High""Low" "Close"   "Volume"  

 
[6] "Adj..Close."

> colnames(sp.z)[1] = "OPEN"

> colnames(sp.z)
[1] "OPEN"

Re: [R] putting a column name on a zoo object

2006-11-14 Thread Horace Tso
Mark,

What's wrong with the following,

> head(sp.z)
  OpenHigh Low   Close Volume Adj..Close.
2000-01-03 1469.25 1478.00 1438.36 1455.22  93180 1455.22
2000-01-04 1455.22 1455.22 1397.43 1399.42 100900 1399.42
2000-01-05 1399.42 1413.27 1377.68 1402.11 1085500032 1402.11
2000-01-06 1402.11 1411.90 1392.10 1403.45 1092300032 1403.45
2000-01-07 1403.45 1441.47 1400.73 1441.47 122520 1441.47
2000-01-10 1441.47 1464.36 1441.47 1457.60 106480 1457.60

 colnames(sp.z)
[1] "Open""High""Low" "Close"   "Volume"   
 
[6] "Adj..Close."

> colnames(sp.z)[1] = "OPEN"

> colnames(sp.z)
[1] "OPEN""High""Low" "Close"   "Volume" 
[6] "Adj..Close."

HTH.

Horace W. Tso

 


>>> "Leeds, Mark (IED)" <[EMAIL PROTECTED]> 11/14/2006
1:21:33 PM >>>
does anyone know how to put a column name on a zoo object. I think
achim
and gabor are off line or they have gotten totally tired of me 
an decided to ignore me ( which is totalyy understandable ).

logbidask<-log((aggfxdata[,"bid"] + aggfxdata[,"ask"])/2.0)
logbidask doesn't have a name and I can't figure out how to get one on
it ?

aggfxdata is a zoo object.


This is not an offer (or solicitation of an offer) to
buy/se...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Including time in a zoo

2006-10-10 Thread Horace Tso
dear list,

I have these hourly price data over a 20 year period. Among other things, I 
want to plot them with time on the x-axis. The data is in a data frame,

> head(OWI.SE.all)
   Record_Number   Name Condition  Time_PeriodPrice
1312 WECC-OWI SouthEast   All 1/1/2012 Hour: 1 41.21383
2827 WECC-OWI SouthEast   All 1/1/2012 Hour: 2 38.38091
4342 WECC-OWI SouthEast   All 1/1/2012 Hour: 3 39.97879
5857 WECC-OWI SouthEast   All 1/1/2012 Hour: 4 40.14156
7372 WECC-OWI SouthEast   All 1/1/2012 Hour: 5 38.21092
8887 WECC-OWI SouthEast   All 1/1/2012 Hour: 6 40.09152

And the date-times are in a POSIX object dte1,

> class(dte1)
[1] "POSIXt"  "POSIXlt"

When I tried to create a zoo with dte1 as the index, I got an error,

> zoo(OWI.SE.all, dte1) 
Error in order(x, ..., na.last = na.last, decreasing = decreasing) : 
unimplemented type 'list' in 'orderVector1'

I guess that's saying the index of a zoo can't have a time component. Am I 
correct? If so, is there a way to include an hour component in a zoo object.

Second question: 

If I just attach this dte1 to my data frame as a column named Date and try 
plotting it as,

> plot(OWI.SE.all$Date, OWI.SE.all$Price, type="l")

I got non-sensical result. How do I plot hourly data in general? 

TIA.

Horace W. Tso

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] rolling around rollapply in a zoo

2006-10-03 Thread Horace Tso
Hi list,

I'm a little confused about rollapply in zoo. There is written that
rollapply has replaced rapply in version 1.2-0 which is what i have. But
when I tried, 

> rollapply(1:100, 10, mean)

I got,

Error in rollapply(1:100, 10, mean) : no applicable method for
"rollapply"

So I went back to the good old rapply

> rapply(1:100, 10, mean)
Error in rapply(1:100, 10, mean) : no applicable method for
"rollapply"
In addition: Warning message:
'rapply' is deprecated.
Use 'rollapply' instead.
See help("Deprecated") 

Is there a more updated version of zoo? 

Thanks.

Horace W. Tso

===
>sessionInfo()
Version 2.3.1 (2006-06-01) 
i386-pc-mingw32 

attached base packages:
[1] "splines"   "methods"   "datasets"  "stats" "tcltk" "utils"
   
[7] "graphics"  "grDevices" "base" 

other attached packages:
lmtest  Hmisctseries   quadprogzoo   MASS  
Rpad 
  "0.9-18"   "3.0-12"   "0.10-1""1.4-8""1.2-0" "7.2-27.1"   
"1.1.1"

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Issue with Data Editor and Date objects

2006-09-28 Thread Horace Tso
Dear list,

It's a minor issue but for someone who uses the Data Editor once in a
while this could be very annoying.

I have a dataframe with a Date column. When I bring it up with the
(gui) Data Editor (Edit -> Data editor...), do nothing and then close
it, the Date column turns into "numeric".

Before using Data Editor, 

>class(gas.gd$Flow.Date)
[1] "Date"

After Data Editor,

>class(gas.gd$Flow.Date)
[1] "numeric"

Any way to fix this?

TIA.

Horace W. Tso
Portland General Electric
Portland, Oregon

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Quickie : unload library

2006-08-25 Thread Horace Tso
Aah, that works. The missing "package:..."

H.

>>> Sachin J <[EMAIL PROTECTED]> 8/25/2006 1:16 PM >>>
try detach("package:zoo")
   
  Sachin

Horace Tso <[EMAIL PROTECTED]> wrote:
  Sachin,

I did try that, ex

detach(zoo)

Error in detach(zoo) : invalid name

detach("zoo")

Error in detach("zoo") : invalid name

But zoo has been loaded,

sessionInfo()
Version 2.3.1 (2006-06-01) 
i386-pc-mingw32 

attached base packages:
[1] "methods" "datasets" "stats" "tcltk" "utils" 
"graphics" 
[7] "grDevices" "base" 

other attached packages:
tseries quadprog zoo MASS Rpad 
"0.10-1" "1.4-8" "1.2-0" "7.2-27.1" "1.1.1" 

Thks,

H.


>>> Sachin J 8/25/2006 12:56 PM >>>
see ?detach 


Horace Tso wrote:
Dear list,

I know it must be obvious and I did my homework. (In fact I've
RSiteSearched with keyword "remove AND library" but got timed
out.(why?))

How do I unload a library? I don't mean getting ride of it permanently
but just to unload it for the time being.

A related problem : I have some libraries loaded at startup in
.First()
which I have in .Rprofile. Now, I exited R and commented out the lines
in .First(). Next time I launch R the same libraries are loaded again.
I.e. there seems to be a memory of the old .First() somewhere which
refuses to die.

Thanks in adv.

Horace

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.



-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.



-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Quickie : unload library

2006-08-25 Thread Horace Tso
Sachin,

I did try that, ex

detach(zoo)

Error in detach(zoo) : invalid name

detach("zoo")

Error in detach("zoo") : invalid name

But zoo has been loaded,

sessionInfo()
Version 2.3.1 (2006-06-01) 
i386-pc-mingw32 

attached base packages:
[1] "methods"   "datasets"  "stats" "tcltk" "utils"
"graphics" 
[7] "grDevices" "base" 

other attached packages:
   tseries   quadprogzoo   MASS   Rpad 
  "0.10-1""1.4-8"    "1.2-0" "7.2-27.1""1.1.1" 

Thks,

H.


>>> Sachin J <[EMAIL PROTECTED]> 8/25/2006 12:56 PM >>>
see ?detach 
  

Horace Tso <[EMAIL PROTECTED]> wrote:
  Dear list,

I know it must be obvious and I did my homework. (In fact I've
RSiteSearched with keyword "remove AND library" but got timed
out.(why?))

How do I unload a library? I don't mean getting ride of it permanently
but just to unload it for the time being.

A related problem : I have some libraries loaded at startup in
.First()
which I have in .Rprofile. Now, I exited R and commented out the lines
in .First(). Next time I launch R the same libraries are loaded again.
I.e. there seems to be a memory of the old .First() somewhere which
refuses to die.

Thanks in adv.

Horace

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.



-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Quickie : unload library

2006-08-25 Thread Horace Tso
Dear list,

I know it must be obvious and I did my homework. (In fact I've
RSiteSearched with keyword "remove AND library" but got timed
out.(why?))

How do I unload a library? I don't mean getting ride of it permanently
but just to unload it for the time being.

A related problem : I have some libraries loaded at startup in .First()
which I have in .Rprofile. Now, I exited R and commented out the lines
in .First(). Next time I launch R the same libraries are loaded again.
I.e. there seems to be a memory of the old .First() somewhere which
refuses to die.

Thanks in adv.

Horace

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] An apply and rep question

2006-08-11 Thread Horace Tso
Thanks Gabor, Andy, and Phil. I learn new trick, particularly the use of
gl().

H.

>>> "Gabor Grothendieck" <[EMAIL PROTECTED]> 8/11/2006 12:01 PM
>>>
The approach here is to perform the repetition on the indices (or
rownames)
rather than on the data frame directly.  Using the builtin data frame
BOD
any of the following would work:

BOD[gl(nrow(BOD), 2),]
BOD[rep(1:nrow(BOD), each = 2),]
BOD[rep(rownames(BOD), each = 2),]

On 8/11/06, Horace Tso <[EMAIL PROTECTED]> wrote:
> Hi list,
>
> I'm sure the explanation must be laughably simple to the experts out
> there, but I just could figure it out. I have a simple data frame
that
> looks like,
>
> >head(da.off)
>   DDate  OffP
> 1 2005-01-01 41.23
> 2 2005-01-02 44.86
> 3 2005-01-03 44.86
> 4 2005-01-04 43.01
> 5 2005-01-05 45.47
> 6 2005-01-06 48.62
>
> where the first column DDate currently is character, and OffP is
> numeric.
>
> I want to duplicate every row 2 times, so I thought I use apply(),
>
> x <- apply(da.off, 2, rep, each=2)
>
> The result is a matrix of all character,
>
>  head(x)
>  DDateOffP
> 1 "2005-01-01" " 41.23"
> 1 "2005-01-01" " 41.23"
> 2 "2005-01-02" " 44.86"
> 2 "2005-01-02" " 44.86"
> 3 "2005-01-03" " 44.86"
> 3 "2005-01-03" " 44.86"
>
> To convert it back to numeric, I did
>
> x <- as.data.frame(x)
> x$OffP <- as.numeric(x$OffP)
>
> However, the OffP column didn't convert correctly, a mystery since
they
> "look" quite alright above. (I know, I know, there seems to be a
space
> there. But why?)
>
> head(x)
> DDate OffP
> 1   2005-01-01  150
> 1.1 2005-01-01  150
> 2   2005-01-02  202
> 2.1 2005-01-02  202
> 3   2005-01-03  202
> 3.1 2005-01-03  202
>
> Is this the wrong way to use apply or rep?
>
> Horace
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] An apply and rep question

2006-08-11 Thread Horace Tso
Hi list,

I'm sure the explanation must be laughably simple to the experts out
there, but I just could figure it out. I have a simple data frame that
looks like,

>head(da.off)
   DDate  OffP
1 2005-01-01 41.23
2 2005-01-02 44.86
3 2005-01-03 44.86
4 2005-01-04 43.01
5 2005-01-05 45.47
6 2005-01-06 48.62

where the first column DDate currently is character, and OffP is
numeric. 

I want to duplicate every row 2 times, so I thought I use apply(),

x <- apply(da.off, 2, rep, each=2) 

The result is a matrix of all character,

 head(x)
  DDateOffP
1 "2005-01-01" " 41.23"
1 "2005-01-01" " 41.23"
2 "2005-01-02" " 44.86"
2 "2005-01-02" " 44.86"
3 "2005-01-03" " 44.86"
3 "2005-01-03" " 44.86"

To convert it back to numeric, I did

x <- as.data.frame(x)
x$OffP <- as.numeric(x$OffP)

However, the OffP column didn't convert correctly, a mystery since they
"look" quite alright above. (I know, I know, there seems to be a space
there. But why?)

head(x)
 DDate OffP
1   2005-01-01  150
1.1 2005-01-01  150
2   2005-01-02  202
2.1 2005-01-02  202
3   2005-01-03  202
3.1 2005-01-03  202

Is this the wrong way to use apply or rep? 

Horace

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] day, month, year functions

2006-08-10 Thread Horace Tso
Hi list, 

I'm trying to turn a date into something productive. (Not what you may be 
thinking) 

I want three functions so I could take a "date" object and get the day of week, 
month, and year from it.

xx <- as.Date("2006-01-05") 

month(xx) equal 1
day(xx) equal 5
year(xx) equal 2006

I'm aware of the weekdays() and months() functions in the base package. But 
they return a character object which requires some coding to convert into a 
numeric value.

I've also tried the sday.of.week() in fCalendar but it doesn't like my date,

> sday.of.week(xx)
Error in Ops.Date(sdates, 1) : %/% not defined for Date objects

Do these functions exist in some package I'm not aware of?

Thanks in adv.

Horace Tso

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Extracting from a matrix w/o for-loop

2006-07-28 Thread Horace Tso
Unless there is another level of complexity that i didn't see here,
wouldn't it be a simply application of sapply as follow,

sapply( 1:dim(M2)[[1]], function(x) M1[M2[x,1], M2[x,2]] )

Hope this helps.

Horace



>>> "Camarda, Carlo Giovanni" <[EMAIL PROTECTED]> 7/28/2006 9:40 AM
>>>
Dear R-users,

likely there is a simple solution for this problem, but I currently
cannot see it.

I basically would like to get from a matrix values in particular
positions which are the rows of another matrix, without using a
for-loop.

In other words: is there any way to avoid the for-loop in the
following
simple example:

M1 <- matrix(1:20, ncol=2)
M2 <- rbind(c(1,1), c(2,1), c(3,2), c(5,2), c(8,1))
v <- numeric(nrow(M2))
for(i in 1:length(v)){
v[i] <- M1[M2[i,1], M2[i,2]]
}

Any suggestion would be welcome,

Ciao,
Carlo Giovanni Camarda

===
Camarda Carlo Giovanni
PhD-Student
Max Planck Institute for Demographic Research
Konrad-Zuse-Strasse 1
18057 Rostock, Germany
Tel:  +49 (0)381 2081 172
Fax: +49 (0)381 2081 472
[EMAIL PROTECTED] 
===


--
This mail has been sent through the MPI for Demographic
Rese...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Converting data frame to zoo

2006-07-07 Thread Horace Tso
Thanks Gabor. I figured out what went wrong. The culprit turns out to be
the headers in my data. read.zoo doesn't recognize column headers and
complains 

Error in read.zoo("C:\\...\\table.csv",  : 
index contains NAs

Or is there an option as in read.table(x, header=...) ? 

After the header line is removed it works fine.

H.



>>> "Gabor Grothendieck" <[EMAIL PROTECTED]> 7/7/2006 10:22 AM
>>>
Check out read.zoo in the zoo package.

On 7/7/06, Horace Tso <[EMAIL PROTECTED]> wrote:
> Dear list,
>
> I know this is really basic question but I just couldn't get
anything
> to work. (I did a R site search with keywords "zoo" and "data frame"
but
> the server timed out on me.)
>
> I have a time series which has the following (typical) format,
>
> DATE   Open  High  Low  Close
>  Volume
> 01-JAN-2006 5.25   5.25  5.25  5.25
>  256
> 
>
> I read the data in from a csv file with read.csv() and it defaulted
to
> a data frame which I thought is fine. Now I want to convert it to zoo
so
> I did
>
> x <- zoo(my.df)
>
> which works just fine. But the Date column has been turned into a
> factor. Is there a way to make it into a Date. I've tried,
>
> x$Date <- as.Date(x$Date)
>
> but R complains that
>
> Error in fromchar(x) : character string is not in a standard
> unambiguous format
>
> Thanks in advance.
>
> Horace W. Tso
>
>
>
>
>
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html 
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help 
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html 
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Converting data frame to zoo

2006-07-07 Thread Horace Tso
Dear list,

I know this is really basic question but I just couldn't get anything
to work. (I did a R site search with keywords "zoo" and "data frame" but
the server timed out on me.)

I have a time series which has the following (typical) format,

DATE   Open  High  Low  Close  
  Volume
01-JAN-2006 5.25   5.25  5.25  5.25
  256


I read the data in from a csv file with read.csv() and it defaulted to
a data frame which I thought is fine. Now I want to convert it to zoo so
I did

x <- zoo(my.df)

which works just fine. But the Date column has been turned into a
factor. Is there a way to make it into a Date. I've tried,

x$Date <- as.Date(x$Date)  

but R complains that

Error in fromchar(x) : character string is not in a standard
unambiguous format

Thanks in advance.

Horace W. Tso






__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Biobass, SAGx, and Jonckheere-Terpstra test

2006-06-29 Thread Horace Tso
Hi list,

I tried to load the package SAGx and failed because it complains it's
looking for the Biobass which is not there. Then I looked up the package
list and Biobass is not found. 

I'm trying to run the Jonckheere-Terpstra test and from what I see in
the R archive, SAGx is the only place it's been implemented.

> library(SAGx)
Loading required package: multtest
Loading required package: survival
Loading required package: splines
Loading required package: sma
Error in loadNamespace(i, c(lib.loc, .libPaths())) : 
there is no package called 'Biobase'
Error: package/namespace load failed for 'SAGx'


Horace W. Tso

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Modeling inverse relationship with copula

2006-04-24 Thread Horace Tso
Dear r list,

I posted this on the S list last week since i'm using some of the
FinMetrics functions on copula. Knowing there is a copula package in R,
I figure this would be an appropriate forum to ask this question.

I want to model inverse relationship between two (non-normal,
non-symmetric) marginals with the gumbel copula, or with any copula.
Say, x is lognormal and y is norm. Since gumbel's delta must be greater
than one, how do I specify the equivalence of a negative correlation? 

If both are symmetric, I think I could get away by using a positive
delta, simulate the bivariate realizations and then flipping the sign on
one of them. Or am I completely off.

I did search through the archive but found no related posting. Thanks
in advance.

Horace W. Tso

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html