[R] Using R for large econometric models

2007-11-07 Thread Dietrich Trenkler
Dear helpeRs,

a colleague of mine would like to give R a try.  He uses econometric
models which typically involve a large number of variables, esp. time
series.  Having no experience with handling very large data sets myself
I turn to you.

1. Could you please describe your experiences to cope with these
   situations?

2. What kind of difficulties will he have to face? Are there special
   tricks (packages) he might try?

3. Can you recommend to use R?


Sorry, if my question is a bit vague but at this point I'm not able to
give any further details.

Any help is very much appreciated.

D. Trenkler 

-- 
Dietrich Trenkler c/o Universitaet Osnabrueck 
Rolandstr. 8; D-49069 Osnabrueck, Germany
email: [EMAIL PROTECTED]

__
R-help@r-project.org 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] Using R for large econometric models

2007-11-07 Thread Pfaff, Bernhard Dr.
Dear Dietrich,

in the first place, it would have been helpful to know which kind of 
econometric models your colleague wants to utilise. With respect to econometric 
methods you might want to have a look at the CRAN Task Views for econometrics 
and finance, to see what is already available:

http://cran.at.r-project.org/src/contrib/Views/Econometrics.html

http://cran.at.r-project.org/src/contrib/Views/Finance.html


>From a practical point of view, I have by now not encountered any size 
>limitations; these experiences are gained from working with high frequency 
>multivariate data in the finance context as well as simultaneous multiple 
>equation models that are solved on a per period basis by applying the 
>Gauß-Seidel algorithm; my colleagues are using R in the context of stock 
>selection where on a daily basis multivariate time series data of more than 
>3,000 strocks are processed. We have not encountered any problems so far. 
>Basically, the maximal data handling size is determined by your computer's 
>memory and the style of your coding.

Best,
Bernhard




>
>Dear helpeRs,
>
>a colleague of mine would like to give R a try.  He uses econometric
>models which typically involve a large number of variables, esp. time
>series.  Having no experience with handling very large data sets myself
>I turn to you.
>
>1. Could you please describe your experiences to cope with these
>   situations?
>
>2. What kind of difficulties will he have to face? Are there special
>   tricks (packages) he might try?
>
>3. Can you recommend to use R?
>
>
>Sorry, if my question is a bit vague but at this point I'm not able to
>give any further details.
>
>Any help is very much appreciated.
>
>D. Trenkler 
>
>-- 
>Dietrich Trenkler c/o Universitaet Osnabrueck 
>Rolandstr. 8; D-49069 Osnabrueck, Germany
>email: [EMAIL PROTECTED]
>
>__
>R-help@r-project.org 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.
>
*
Confidentiality Note: The information contained in this ...{{dropped:10}}

__
R-help@r-project.org 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] Is it possible to modify the position of the graphic window ?

2007-11-07 Thread Martin Maechler
> "RT" == Rolf Turner <[EMAIL PROTECTED]>
> on Wed, 7 Nov 2007 09:57:12 +1300 writes:

RT> On 7/11/2007, at 9:12 AM, Prof Brian Ripley wrote:

>> 1) Did you merge the resources or restart X?  You need to
>> in order to get new resources to be recognized.
>> 
>> xrdb -merge ~/.Xresources would be needed to merge
>> resources into the current X session.

RT> No I didn't.  Didn't know or didn't remember
RT> about the merge business.  Dang!  That works.  But only
RT> for the auto-start device, not for x11().

Really?  It should influence all instances of x11(), not only
the "auto-start device" --- which, BTW, is identical to
getOption("device") as has been mentioned here ---
and it does so for me {on Linux}.

BTW: For testing,  you can use xrdb directly, i.e., in a shell:

   echo 'R_x11*geometry: 500x700-0-0' | xrdb -merge

The above option looking useful for my typical use with ESS.
Martin

>> I don't know if MacOS X11 is standard enough to support
>> this, but it is a very long-standing basic part of X11.
>> 
>> 2)
>> options(device=function() x11(xpos=-1)) plot(1:10)
>> 
>> should work (does for me): it does not affect x11() in
>> any way, just the auto-start graphics device.

RT> Right.  That works too.  Missed the distinction
RT> between x11() and the auto-start device.

RT> Thanks very much.

RT> cheers,

RT> Rolf

RT> ##
RT> Attention:\ This e-mail message is privileged and
RT> confid...{{dropped:9}}

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

__
R-help@r-project.org 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] Is it possible to modify the position of the graphic window ?

2007-11-07 Thread 8rino-Luca Pantani
I would like to improve my knowledge on the matter, but I cannot find 
url in your posts.
Did I miss something ?
Or you mean that you have added the url in the help page ?
Thanks
8rino

Prof Brian Ripley ha scritto:
>
> I added an example (and a reference url) to ?X11 yesterday, since it 
> seems knowledge of X11 resources is scarcer than it used to be.

__
R-help@r-project.org 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] strwidth and strheight for rotated text

2007-11-07 Thread Stéphane Dray
Dear All,
I would like to plot text with a box around it. I used strwidth and 
strheight to compute the size of the box which is plotted with rect:

z <- rnorm(10)

# horizontal text works
plot(rnorm(10))
x1 <- 5
y1 <- 0
label <- "Label"
cha <- paste(" ", label, " ", sep = "")
xh <- strwidth(cha, cex = par("cex"))
yh <- strheight(cha, cex = par("cex")) * 5/3
rect(x1 - xh/2, y1 - yh/2, x1 + xh/2, y1 + yh/2, col = "white")
text(x1, y1, cha, cex = par("cex"))

Now I would like to do the same with rotated text. I found two solutions:
-  modify the par("usr")
-  compute ratio to transform width and height computed on the unrotated 
text.

These two solutions work for square graphic window (e.g. X11(), 
X11(width=3, height=3)..)

But the two solutions does not work for rectangular windows:

# does not works for rotated text using modif of par("usr")
X11(height=4)
plot(z)
x1 <- 5
y1 <- 0
xusr <- par("usr")
par("usr"=xusr[c(3,4,1,2)])
yh <- strwidth(cha, cex = par("cex"))
xh <- strheight(cha, cex = par("cex")) * 5/3
par("usr"=xusr)
rect(x1 - xh/2, y1 - yh/2, x1 + xh/2, y1 + yh/2, col = "white")
text(x1, y1, cha, cex = par("cex"), srt = 90)

# does not works for rotated text using manual modification of xh and yh
X11(height=4)
plot(z)
x1 <- 5
y1 <- 0
xusr <- par("usr")
xh <- strwidth(cha, cex = par("cex"))
yh <- strheight(cha, cex = par("cex")) * 5/3
tmp <- yh
yh <- xh/(xusr[2]-xusr[1])*(xusr[4]-xusr[3])
xh <- tmp/(xusr[4]-xusr[3])*(xusr[2]-xusr[1])
rect(x1 - xh/2, y1 - yh/2, x1 + xh/2, y1 + yh/2, col = "white")
text(x1, y1, cha, cex = par("cex"), srt = 90)



I can not understand why it does not work. Any help would be very 
appreciated.

 > sessionInfo()
R version 2.6.0 (2007-10-03)
i686-pc-linux-gnu

locale:
LC_CTYPE=fr_FR.UTF-8;LC_NUMERIC=C;LC_TIME=fr_FR.UTF-8;LC_COLLATE=fr_FR.UTF-8;LC_MONETARY=fr_FR.UTF-8;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=C



Thanks in Advance,
Cheers.


-- 
Stéphane DRAY ([EMAIL PROTECTED] )
Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - Lyon I
43, Bd du 11 Novembre 1918, 69622 Villeurbanne Cedex, France
Tel: 33 4 72 43 27 57   Fax: 33 4 72 43 13 88
http://biomserv.univ-lyon1.fr/~dray/

__
R-help@r-project.org 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] dates

2007-11-07 Thread marciarr

Dear R users,
I am just starting with R  and am currently needing a lot of help! Sorry if
I disturb you and thank you for your answers!!! 
Here goes my question: How do I make R reconize my date columns as dates?
When I "summary"  my table, the levels of my date column are completely out
of order.
Thank you again for this tip,
Marcia
-- 
View this message in context: 
http://www.nabble.com/dates-tf4764010.html#a13625194
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] dates

2007-11-07 Thread Henrique Dallazuanna
See:

?DateTimeClasses
?as.Date


On 07/11/2007, marciarr <[EMAIL PROTECTED]> wrote:
>
>
> Dear R users,
> I am just starting with R  and am currently needing a lot of help! Sorry
> if
> I disturb you and thank you for your answers!!!
> Here goes my question: How do I make R reconize my date columns as dates?
> When I "summary"  my table, the levels of my date column are completely
> out
> of order.
> Thank you again for this tip,
> Marcia
> --
> View this message in context:
> http://www.nabble.com/dates-tf4764010.html#a13625194
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] strwidth and strheight for rotated text

2007-11-07 Thread Prof Brian Ripley
See ?par, 'cxy' for how to go from width/heights in inches to user 
coordinates and vice versa.  You appear to have overlooked 'pin'.


On Wed, 7 Nov 2007, Stéphane Dray wrote:


Dear All,
I would like to plot text with a box around it. I used strwidth and
strheight to compute the size of the box which is plotted with rect:

z <- rnorm(10)

# horizontal text works
plot(rnorm(10))
x1 <- 5
y1 <- 0
label <- "Label"
cha <- paste(" ", label, " ", sep = "")
xh <- strwidth(cha, cex = par("cex"))
yh <- strheight(cha, cex = par("cex")) * 5/3
rect(x1 - xh/2, y1 - yh/2, x1 + xh/2, y1 + yh/2, col = "white")
text(x1, y1, cha, cex = par("cex"))

Now I would like to do the same with rotated text. I found two solutions:
-  modify the par("usr")
-  compute ratio to transform width and height computed on the unrotated
text.

These two solutions work for square graphic window (e.g. X11(),
X11(width=3, height=3)..)

But the two solutions does not work for rectangular windows:

# does not works for rotated text using modif of par("usr")
X11(height=4)
plot(z)
x1 <- 5
y1 <- 0
xusr <- par("usr")
par("usr"=xusr[c(3,4,1,2)])
yh <- strwidth(cha, cex = par("cex"))
xh <- strheight(cha, cex = par("cex")) * 5/3
par("usr"=xusr)
rect(x1 - xh/2, y1 - yh/2, x1 + xh/2, y1 + yh/2, col = "white")
text(x1, y1, cha, cex = par("cex"), srt = 90)

# does not works for rotated text using manual modification of xh and yh
X11(height=4)
plot(z)
x1 <- 5
y1 <- 0
xusr <- par("usr")
xh <- strwidth(cha, cex = par("cex"))
yh <- strheight(cha, cex = par("cex")) * 5/3
tmp <- yh
yh <- xh/(xusr[2]-xusr[1])*(xusr[4]-xusr[3])
xh <- tmp/(xusr[4]-xusr[3])*(xusr[2]-xusr[1])
rect(x1 - xh/2, y1 - yh/2, x1 + xh/2, y1 + yh/2, col = "white")
text(x1, y1, cha, cex = par("cex"), srt = 90)



I can not understand why it does not work. Any help would be very
appreciated.

> sessionInfo()
R version 2.6.0 (2007-10-03)
i686-pc-linux-gnu

locale:
LC_CTYPE=fr_FR.UTF-8;LC_NUMERIC=C;LC_TIME=fr_FR.UTF-8;LC_COLLATE=fr_FR.UTF-8;LC_MONETARY=fr_FR.UTF-8;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=C



Thanks in Advance,
Cheers.





--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org 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] strwidth and strheight for rotated text

2007-11-07 Thread Stéphane Dray
Thanks a lot Brian,
you were completely correct. The good way to do it :


z <- rnorm(10)
x1 <- 5
y1 <- 0
label <- "Label"
cha <- paste(" ", label, " ", sep = "")
X11(height=4)
plot(z)
xusr <- par("usr")
xh <- strwidth(cha, cex = par("cex"))
yh <- strheight(cha, cex = par("cex")) * 5/3
tmp <- xh
xh <- yh/(xusr[4]-xusr[3])*par("pin")[2]
xh <- xh/ par("pin")[1] * (xusr[2]-xusr[1])
yh <- tmp/(xusr[2]-xusr[1])* par("pin")[1]
yh <- yh/ par("pin")[2] * (xusr[4]-xusr[3])
rect(x1 - xh/2, y1 - yh/2, x1 + xh/2, y1 + yh/2, col = "white")
text(x1, y1, cha, cex = par("cex"), srt = 90)


Prof Brian Ripley wrote:
> See ?par, 'cxy' for how to go from width/heights in inches to user 
> coordinates and vice versa.  You appear to have overlooked 'pin'.
>
> On Wed, 7 Nov 2007, Stéphane Dray wrote:
>
>> Dear All,
>> I would like to plot text with a box around it. I used strwidth and
>> strheight to compute the size of the box which is plotted with rect:
>>
>> z <- rnorm(10)
>>
>> # horizontal text works
>> plot(rnorm(10))
>> x1 <- 5
>> y1 <- 0
>> label <- "Label"
>> cha <- paste(" ", label, " ", sep = "")
>> xh <- strwidth(cha, cex = par("cex"))
>> yh <- strheight(cha, cex = par("cex")) * 5/3
>> rect(x1 - xh/2, y1 - yh/2, x1 + xh/2, y1 + yh/2, col = "white")
>> text(x1, y1, cha, cex = par("cex"))
>>
>> Now I would like to do the same with rotated text. I found two 
>> solutions:
>> -  modify the par("usr")
>> -  compute ratio to transform width and height computed on the unrotated
>> text.
>>
>> These two solutions work for square graphic window (e.g. X11(),
>> X11(width=3, height=3)..)
>>
>> But the two solutions does not work for rectangular windows:
>>
>> # does not works for rotated text using modif of par("usr")
>> X11(height=4)
>> plot(z)
>> x1 <- 5
>> y1 <- 0
>> xusr <- par("usr")
>> par("usr"=xusr[c(3,4,1,2)])
>> yh <- strwidth(cha, cex = par("cex"))
>> xh <- strheight(cha, cex = par("cex")) * 5/3
>> par("usr"=xusr)
>> rect(x1 - xh/2, y1 - yh/2, x1 + xh/2, y1 + yh/2, col = "white")
>> text(x1, y1, cha, cex = par("cex"), srt = 90)
>>
>> # does not works for rotated text using manual modification of xh and yh
>> X11(height=4)
>> plot(z)
>> x1 <- 5
>> y1 <- 0
>> xusr <- par("usr")
>> xh <- strwidth(cha, cex = par("cex"))
>> yh <- strheight(cha, cex = par("cex")) * 5/3
>> tmp <- yh
>> yh <- xh/(xusr[2]-xusr[1])*(xusr[4]-xusr[3])
>> xh <- tmp/(xusr[4]-xusr[3])*(xusr[2]-xusr[1])
>> rect(x1 - xh/2, y1 - yh/2, x1 + xh/2, y1 + yh/2, col = "white")
>> text(x1, y1, cha, cex = par("cex"), srt = 90)
>>
>>
>>
>> I can not understand why it does not work. Any help would be very
>> appreciated.
>>
>> > sessionInfo()
>> R version 2.6.0 (2007-10-03)
>> i686-pc-linux-gnu
>>
>> locale:
>> LC_CTYPE=fr_FR.UTF-8;LC_NUMERIC=C;LC_TIME=fr_FR.UTF-8;LC_COLLATE=fr_FR.UTF-8;LC_MONETARY=fr_FR.UTF-8;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=C
>>  
>>
>>
>>
>>
>> Thanks in Advance,
>> Cheers.
>>
>>
>>
>


-- 
Stéphane DRAY ([EMAIL PROTECTED] )
Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - Lyon I
43, Bd du 11 Novembre 1918, 69622 Villeurbanne Cedex, France
Tel: 33 4 72 43 27 57   Fax: 33 4 72 43 13 88
http://biomserv.univ-lyon1.fr/~dray/

__
R-help@r-project.org 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] Linear Regression

2007-11-07 Thread livia

Hello everyone,

I would like to a linear regression with the following code. 
 lm(a[,"fquamsci"]~., data=a)

a is a list with class "mts" "ts" , and  "fquamsci" is the name of the
response variable in a. I would like to do a linear regression of "fquamsci"
to the rest of the variables. But it turns out the "fquamsci" is also
included in the explanatory variables. I tried the following, it is quite
strange that it does not work as well.

 lm(a[,"fquamsci"]~.-a[,"fquamsci"], data=a)

Could anyone give me some advice?
Many thanks

-- 
View this message in context: 
http://www.nabble.com/Linear-Regression-tf4764346.html#a13626039
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] PVM error message

2007-11-07 Thread Lenzo, Antonino
Hello R enthusiasts,

I am working with a Fedora Core 6 OS and R 2.5.  I have just finished
loading PVM on my test cluster and this is working properly.  Also, rpvm
has been loaded in R.  However, when I try to load my test program, I
receive this error:

Loading required package: rpvm
Error in dyn.load(x, as.logical(local), as.logical(now)) ;
unable to load shared library
'/usr/local/lib/R/library/rpvm/libs/rpvm.so':
  /usr/local/lib/R/library/rpvm/libs/rpvm.so: cannot restore segment
prot after relocL Permission denied
Error in makePVMcluster(spec, ...) : the 'rpvm' package is needed for
PVM clusters.

I need to mention that this is a known working program.  This sort of
error happens whether I am logged into root or not, so I don't think it
is a permissions issue.

I am using PVM3.4.5+6-WIN32.tar.gz

Has anyone seen this error message before?  Any insight?

Thanks everyone!
A Lenzo

__
R-help@r-project.org 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-11-07 Thread Joao Santos

Hello,


I have a similar problem but in my case I have a seasonal time series and
the gaps are bigger.
Like I said the TS as a seasonality to the week and some gaps are so big
that seasonality is broken. 
I need a process to predict this values and keep the seasonality.
From the search that I made I don't found any process to do this.

Any ideas are welcome!

Thanks in advance,

João Santos   



Horace Tso wrote:
> 
> 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,
>> 
>> FDatePrice
>> 11/1/20066.28
>> 11/2/20066.58
>> 11/3/20066.586
>> 11/4/20066.716
>> 11/5/2006NA
>> 11/6/2006NA
>> 11/7/20066.262
>> 11/8/20066.27
>> 11/9/20066.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
>> 
>> __
>> [EMAIL PROTECTED] 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.
> 
> __
> [EMAIL PROTECTED] 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Imputing-missing-values-in-time-series-tf3966333.html#a13632881
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Trouble in creating a list

2007-11-07 Thread Gang Chen

I want to create a list based on the information from a data.frame,  
Model. So I tried the following:

MyList <- list(colnames(Model)[2] = levels(Model$(colnames(Model)[2])))

but it failed with an error:

Error: unexpected '=' in "list(colnames(Model)[2] ="

I have the following problems with this command line:

(1) I wanted to use colnames(Model)[2] as a tag for the list:

 > colnames(Model)[2]
[1] "gender"

but it is not working as I intended. How to make colnames(Model)[2] a  
legitimate tag?

(2) Model$gender is a column in the data.frame. However Model$ 
(colnames(Model)[2]) seems not recognizable in the command line. How  
to correct this?

(3) How to add more tagged items to an existing list? cbind or rbind?

Thanks in advance,
Gang

__
R-help@r-project.org 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] partially sum variable of a dataframe

2007-11-07 Thread Julian Burgos
I'm assuming that you want to add b if 33 & a<5.25])

This is very simple R coding.  I recommend you spend some time learning 
the basics.  There are very good tutorials at the R website.

Julian

[EMAIL PROTECTED] wrote:
> Hello,
> 
> A stupid question:
> 
> I have an array with two columns, the first "a" acting as my index in 0.25 
> steps, the second one "b" the column of interest. How can i sum up "b" only 
> for a specified window in "a" (as the window command for time series)
> 
> a=seq(0,10,0.25)
> b=runif(41)
> c=data.frame(a,b)
> 
> Sum up c if 3 
> How to do that? thanks
> 
> marc

__
R-help@r-project.org 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] partially sum variable of a dataframe

2007-11-07 Thread Bert Gunter
 
Or even simpler (when cc is a data frame), instead of

sum(cc[cc[,"a"] <= 5.25 & cc[,"a"] >= 3, "b"])

##

with(cc, sum(b[a <= 5.25 & a >= 3]))



Bert Gunter
Genentech Nonclinical Statistics

__
R-help@r-project.org 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] bug in multcomp?

2007-11-07 Thread Robert Cribbie
I am running a linear model with achiev as the outcome and major as my 
iv (5 levels). The lm statement runs fine, but for the glht command I 
get the following error. I noted that someone else asked the same 
question a while back but received no reply. I am hoping someone might 
know what is happening.

 anovaf2<-lm(achiev ~ major, data=data_mcp)
 > pairwise<- glht(anovaf2,linfct = mcp(major = "tukey"))
Error in mcp2matrix(model, linfct = linfct) :
Factor(s) major have been specified in 'linfct' but cannot be 
found in 'model'!


Any help would be much appreciated.

Rob.


-- 
Robert A. Cribbie, PhD
Department of Psychology
York University
Toronto, ONM3J 1P3
Phone: 416-736-2100 x88615
Email: [EMAIL PROTECTED]
Fax: 416-736-5814
Website: http://www.psych.yorku.ca/cribbie

__
R-help@r-project.org 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] Simple Umacs example help..

2007-11-07 Thread Adam Wilson
Greetings,

I've been playing with the umacs package for a few days and have worked out
an example of a simple linear regression using gibbs samplers (included
below).  While extremely basic, I hope this might be helpful.  I would love
to see more examples of MH sampling as well.

##

## Simple linear regression using UMacs package

##load libraries
library(Umacs);library(rv);library(MASS);library(mvtnorm)

##simulate data
 n=500
 b1 = 10
 b2 = 6
 beta = matrix(c(b1,b2),2,1)
 sig = 4
 x=cbind(1,rnorm(n,seq(1,20,length=n),sd=1))
 y=matrix(rnorm(n,x%*%beta,sqrt(sig)),n,1)

#priors on beta and beta variance
b.prior = as.matrix(ncol=1,nrow=2,c(0,0))
v.prior = solve(diag(1000,2))
s1.prior = .1 # gamma prior
s2.prior = .1

#set up the initial values and define the dimension of each variable
b.init <- function () as.matrix(rnorm(2,0,1))   # b[1] is
intercept, b[2] is slope
v.init <- function () rnorm(1,0,1)^2# error

#define the conditional probabilities for the gibbs sampler for the betas
and sigma

b.update <- function (){
 #From Clark text "Models for Ecological Data" ISBN 0-691-12178-8 (page
192) and Clark workbook (pg 81)
 # the If() statements allows this function to be used for a full
covariance matrix or just a single variance parameter
 if(length(v) == 1) {
  sx = crossprod(x) * 1/v
  sy = crossprod(x,y) * 1/v
  }
 if(length(v) > 1) {
  ss = t(x) %*% 1/v
  sx = ss %*% x
  sy = ss %*% y
 }
 bigv = solve(sx + v.prior)
 smallv = sy + v.prior %*% b.prior
 b = t(rmvnorm(1,bigv%*%smallv,bigv))
 return(b)
}
v.update <- function () {
 sx = crossprod((y - x%*%b))
 u1 = s1.prior + 0.5*n
 u2 = s2.prior + 0.5*sx
 return(1/rgamma(1,u1,u2))
}

s <- Sampler(
 .title = "Linear Regression",
 x = x,
 y = y,
 b = Gibbs (b.update, b.init),
  v = Gibbs (v.update, v.init),
  Trace("b[1]"),
  Trace("b[2]"),
  Trace("v")
 )
s(n.iter=2000)
#note original values are (approximately) returned

##
Message: 48
Date: Wed, 31 Oct 2007 12:15:51 -0400
From: Ted Hart <[EMAIL PROTECTED]>
Subject: [R] Simple Umacs example help..
To: r-help@r-project.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain

Hello all...

I am just starting to teach myself Bayesian methods, and am
interested in learning how to use UMacs.  I've read the
documentation, but the single example is a bit over my head at the
level I am at right now.  I was wondering if anyone has any simple
examples they'd like to share.  I've successfully done a couple of
simple gibbs examples, but have had a hard time modifying some of the
home written metropolis hastings samplers I've made to work with
Umacs.  Does anyone have any pointers or simple 2 parameter
examples?  Thanks.

Here is one of my simple MH samplers using a simple linear regression
with a Cauchy error term.

x <- c(1.808,1.799,1.179,0.574,3.727,0.946,3.719,1.566,3.596,3.253)
y <- c(1.816,1.281,-1.382,0.573,3.793,0.935,1.775,1.474,3.679,3.889)

fn = function(x,a=0,b=1){
   a+b*x
}


sample.ab <-function(x,y,a,b,s,da,db){
bstar = runif(1,b-db,b+db)
astar = runif(1,a-da,a+da)

logalpha = sum(dcauchy(y,location=fn(x,astar,bstar),scale=s,log=T) -
dcauchy(y,location=fn(x,a,b),scale=s,log=T))
logu = log(runif(1,0,1))
acc = (logu < logalpha)
b = acc*bstar + (1-acc)*b
a = acc*astar + (1-acc)*a
list(b=b,a=a,acc=acc)
}


samples = function(x,y,a,b,s,ds){

   sstar = runif(1,s-ds,s+ds)
   while(sstar <= 0){
   sstar = runif(1,s-ds,s+ds)
   }
   logalpha = sum( dcauchy(y,location=fn(x,a,b),scale=sstar,log=T) -
dcauchy(y,location=fn(x,a,b),scale=s,log=T)) - log(sstar/s)
   logu = log(runif(1,0,1))
   acc = (logu < logalpha)
   s = acc*sstar + (1-acc)*s
   list(s=s,accs=acc)
}
sample.abs<-function(n=1,x,y,a=0,b=1,s=2,da=.2,db =.2,ds=1)
{

accab  <- 0
accs <- 0
A = B = S = rep(NaN,n)
for(i in 1:n){
z = sampleab(x,y,a,b,s,da,db)
q <- samples(x,y,a,b,s,ds)
A[i] = a = z$a
B[i] = b = z$b
S[i]=s=q$s
accab = accab + z$acc
accs <- accs +q$accs


}
invisible(list(a=A, b=B, s=S, accab=accab/n,accs=accs/n))
}



Cheers,
Ted

Dept. of Biology,
University of Vermont



   [[alternative HTML version deleted]]





-- 
Adam Wilson
http://hydrodictyon.eeb.uconn.edu/people/wilson/
Department of Ecology and Evolutionary Biology
BioPharm 223
University of Connecticut
Tel: 860.486.4157
[EMAIL PROTECTED]

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] normalizing data for low kurtosis

2007-11-07 Thread Kat Willmore
To run my data in another program my data cannot exceed a kurtosis of 0.8.  I'm
wondering if there is a package that can determine if the kurtosis for a trait
is equal to or greater than 0.8 and then determine the appropriate normalizing
methods to reduce the kurtosis to less than 0.8.  I would also need to have
record of what normalizing procedures were done for each trait

Katherine Willmore
Postdoctoral Research Associate
Pennsylvania State University
409 Carpenter Bldg
University Park, 16802
[EMAIL PROTECTED]



[[alternative HTML version deleted]]

__
R-help@r-project.org 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] partially sum variable of a dataframe

2007-11-07 Thread markleeds
There's probably a shorter way but below works
and doesn't require the starting points to be in
the a column.

startindex<-3
endindex<-5.25

start<-tail(which(c$a<=startindex),1)
end<-tail(which(c$a<=endindex),1)

sum(c$b[start:end])


>Hello,
>
>A stupid question:
>
>I have an array with two columns, the first "a" acting as my index in 0.25 
>steps, the second one "b" the column of interest. How can i sum up "b" only 
>for a specified window in "a" (as the window command for time series)
>
>a=seq(0,10,0.25)
>b=runif(41)
>c=data.frame(a,b)
>
>Sum up c if 3
>How to do that? thanks
>
>marc
>-- 
>Pt! Schon vom neuen GMX MultiMessenger gehört?
>Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
>
>__
>R-help@r-project.org 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@r-project.org 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] Graphics devices: windows() and x11() vs default

2007-11-07 Thread Martin Maechler
> "WS" == Wollkind, Steven <[EMAIL PROTECTED]>
> on Wed, 7 Nov 2007 09:01:24 -0500 writes:

WS> I'm noticing some differences between making an explicit
WS> call to windows() to generate a graphics device and
WS> going with whatever R gives you when you just start
WS> plotting, which raises the question of just what the
WS> nature of the default device is.  I've had a hard time
WS> researching this so far, so I'm asking the list.

getOption("device")

  {the one you set by  options(device = ...)

is your current default graphics device.
That is platform dependent, and from what you say below,
I assume you have to use MS Windows, where typically
this default device *is* equivalent to windows().

However, there are many ways to change this default,
by initialization code, or loading other packages which change
it or ...

Before you can get more help,
we need to see your

   getOption("device")
and probably also
   sessionInfo()

Martin Maechler, ETH Zurich



WS> Here are two code snippets:

WS> ###
WS> ## Snippet 1
WS> ###
WS> windows()
WS> layout(matrix(c(1,2,3,4,5,6,7,8,9),3,3,byrow=T))
WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)

WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)

WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)




WS> ###
WS> ## Snippet 2
WS> ###
WS> layout(matrix(c(1,2,3,4,5,6,7,8,9),3,3,byrow=T))
WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)

WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)

WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)



WS> Run snippet 1, then resize the device.  If your system is like mine the
WS> redrawing after resizing will be quick and nice.  Then run snippet 2 and
WS> try the same thing.  On my system I have to wait ~1 second per plot as
WS> they each get redrawn.  My question boils down to "What is the nature of
WS> the default device you get without an explicit device generating call
WS> and why does it behave differently?"

WS> Now, this is obviously not that important in most cases, but I've been
WS> working with the cairoDevice package (and will be emailing its
WS> maintainer soon) and the graphics devices that it produces behave like
WS> snippet 2 and not snippet 1.  As a first step to trying to correct this
WS> I'm simply trying to understand the differences between the devices you
WS> get with both methods.

WS> Thanks
WS> Steve Wollkind

WS> Steve Wollkind
WS> Associate Analyst
WS> Geode Capital Management, LLC
WS> 1 Post Office Square / 28th Floor / Boston, MA 02109
WS> [EMAIL PROTECTED]
WS> Tel:   (617) 392-8991
WS> Fax:  (617) 476-6389

__
R-help@r-project.org 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] Algorithms for coincidences

2007-11-07 Thread Thomas Lumley
On Tue, 6 Nov 2007, Greg Snow wrote:

> A paper that may help you:
>
> "Methods for Studying Coincidences", Persi Diaconis; Frederick
> Mosteller.  Journal of the American Statistical Association, vol 84, no.
> 408 (Dec., 1989), 853-861.

The pbirthday()/qbirthday() functions use the approximations in this paper 
and the help page references it, so it may not be much further assistance.

If the problem is parameter values that the functions don't handle, rather 
than insufficient precision, I would suggest simulation.

-thomas

Thomas Lumley   Assoc. Professor, Biostatistics
[EMAIL PROTECTED]   University of Washington, Seattle

__
R-help@r-project.org 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] dates

2007-11-07 Thread John Kane
http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html
might help as a start.  
--- marciarr <[EMAIL PROTECTED]> wrote:

> 
> Dear R users,
> I am just starting with R  and am currently needing
> a lot of help! Sorry if
> I disturb you and thank you for your answers!!! 
> Here goes my question: How do I make R reconize my
> date columns as dates?
> When I "summary"  my table, the levels of my date
> column are completely out
> of order.
> Thank you again for this tip,
> Marcia
> -- 
> View this message in context:
> http://www.nabble.com/dates-tf4764010.html#a13625194
> Sent from the R help mailing list archive at
> Nabble.com.
> 
> __
> R-help@r-project.org 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@r-project.org 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] mixed model testing

2007-11-07 Thread Irene Mantzouni
Is there a formal way to prove the need of a mixed model, apart from e.g. 
comparing the intervals estimated by lmList fit? 
For example, should I compare (with AIC ML?) a model with seperately (unpooled) 
estimated fixed slopes (i.e.using an index for each group) with a model that 
treats this parameter as a random effect (both models treat the remaining 
parameters as random)?
 
Thank you!

__
R-help@r-project.org 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] vectorize a list

2007-11-07 Thread Frank Schmid
Dear R user

Suppose I have the following list:

 > f <- rnorm(2)
 > s <- rnorm(3)
 > l <- list(f,s)
 > l
[[1]]
[1] 0.31784399 0.08575421

[[2]]
[1] -0.6191679  0.7615479 -1.0087659


Can I stack the entries of this list in 1 vector with the first list 
entry followed by the second? The reference manual says that I can use 
the command /stack/, which can take as arguments either a list or a data 
frame. But taking simply /stack(l)/ does not work, although it is a list.

Many thanks for your hint

Frank Schmid

__
R-help@r-project.org 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] PVM error message

2007-11-07 Thread elw

> I am working with a Fedora Core 6 OS and R 2.5.  I have just finished

> I am using PVM3.4.5+6-WIN32.tar.gz

Isn't that supposed to be the wad of files for Windows machines?

there's a different link on the PVM homepage to the source for unices...

--elijah

__
R-help@r-project.org 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] R as a programming language

2007-11-07 Thread Duncan Murdoch
On 11/7/2007 8:17 AM, Alexy Khrabrov wrote:
> On Nov 7, 2007, at 4:13 PM, Duncan Murdoch wrote:
> 
>>> And, still no option processing as in GNU long options, or python  
>>> or  ruby's optparse.
>>> What's the semantics of parameter passing -- by value or by  
>>> reference?
>>
>> By value.
> 
> Thanks Duncan!  So if I have a huge table t, and the idea was to  
> write a function t.xy(t, ...) to select slices of it, will parameter  
> passing copying waste forfeit all aesthetic savings from  
> refactoring?  What I'm dreading is having to explicitly select x and  
> y from t,
> 
> if () {
>   plot(t$this, t$that, ...)
> } else if () {
>   plot(t$smth_else, ...)
> }
> 
> -- that way I do refer to parts of t and there's no copying except to  
> plot (?), yet if indeed passing parameters by value copies them, one  
> would have to refrain from writing functions!  Is that the state of  
> things?

As long as your function doesn't modify t, no actual copy will be made. 
   My previous message explained it like this:

> Semantically it acts as a full copy, though there is some internal 
> optimization that means the copy won't be made until necessary, i.e. one 
> of r or t changes.

This applies to argument passing as well as assignments.  Argument 
passing is very much like an assignment to a new variable in the local 
frame.  The only difference is the lazy evaluation:  the assignment 
won't take place until you use the value of that local variable, and if 
you never use it, it won't take place at all.

Selecting slices will create new copies of the slices, but you won't get 
a new copy of the full table.

Duncan Murdoch

__
R-help@r-project.org 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] partially sum variable of a dataframe

2007-11-07 Thread jim holtman
sum(c$b[(c$a > 3) & (c$a < 5.25)])

On 11/7/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello,
>
> A stupid question:
>
> I have an array with two columns, the first "a" acting as my index in 0.25 
> steps, the second one "b" the column of interest. How can i sum up "b" only 
> for a specified window in "a" (as the window command for time series)
>
> a=seq(0,10,0.25)
> b=runif(41)
> c=data.frame(a,b)
>
> Sum up c if 3
> How to do that? thanks
>
> marc
> --
> Pt! Schon vom neuen GMX MultiMessenger gehört?
> Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
>
> __
> R-help@r-project.org 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?

__
R-help@r-project.org 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] R as a programming language

2007-11-07 Thread Alexy Khrabrov
On Nov 7, 2007, at 4:13 PM, Duncan Murdoch wrote:

>> And, still no option processing as in GNU long options, or python  
>> or  ruby's optparse.
>> What's the semantics of parameter passing -- by value or by  
>> reference?
>
> By value.

Thanks Duncan!  So if I have a huge table t, and the idea was to  
write a function t.xy(t, ...) to select slices of it, will parameter  
passing copying waste forfeit all aesthetic savings from  
refactoring?  What I'm dreading is having to explicitly select x and  
y from t,

if () {
plot(t$this, t$that, ...)
} else if () {
plot(t$smth_else, ...)
}

-- that way I do refer to parts of t and there's no copying except to  
plot (?), yet if indeed passing parameters by value copies them, one  
would have to refrain from writing functions!  Is that the state of  
things?

Cheers,
Alexy

__
R-help@r-project.org 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] its does not recognize POSIXct w/ both time and Date?

2007-11-07 Thread B. Bogart
Hello all,

Please disregard this thread, turns out I was not dealing with properly 
formated POSIXct data  actually. I'm writing only for the archives in 
case someone else has a similar problem.

I had loaded the file with read.table using colClasses to use POSIXct as 
the class for the first column. This did work, meaning class() returned 
the proper class, but only the date (not the time) was automatically 
interpreted.

This was easily solved by using "character" for the column class of the 
dates and using a separate time vector:

times = as.POSIXct(strptime(data$Time,format="%Y-%m-%d_%H:%M:%S"))

And now all is well.

Thanks for your help.
B. Bogart

Gabor Grothendieck wrote:
> On Nov 5, 2007 3:50 PM, B. Bogart <[EMAIL PROTECTED]> wrote:
>   
>> Hello all,
>>
>> I'm getting much further with my time-series work, but still getting
>> into some problems.
>>
>> I'm using POSIXct time format with both date and time.
>>
>> I'd like to use that in an its object but It seems its only processes
>> the date part of the POSIX time stamps:
>>
>> BMU_its_data <-  its(data[BMUindex,2-4],dates=data[BMUindex,1])
>> Error in `row.names<-.data.frame`(`*tmp*`, value = c("2007-10-31",
>> "2007-10-31",  :
>>
>>
>> The first column of the data is certainly correct, with both date and time:
>>
>>  > summary(data[BMUindex,1])
>> Min.   1st Qu.
>> Median
>> "2007-10-31 07:00:00 UTC" "2007-11-01 07:00:00 UTC" "2007-11-03 07:00:00
>> UTC"
>> Mean   3rd Qu.
>> Max.
>> "2007-11-02 21:44:12 UTC" "2007-11-04 07:00:00 UTC" "2007-11-05 08:00:00
>> UTC"
>>
>> Perhaps the functions used in its are unable to see the time field. I
>> noticed that using unique() on the same data gives me only 6 different
>> values, one for each day, with the times ignored.
>>
>> Is there any time format I can use in R (through its or zoo or fCalendar
>> or anything) that allows me to use tools such as unique() and so on and
>> have the times (not only dates) considered?
>>
>> I've chosen its because it seems to have pretty good ts specific
>> plotting stuff in there, but I'd be willing to use anything that allows
>> me to work with my POSIX dates down to the second. (or even msec)
>>
>> 
>
> Please provide reproducible examples as asked in last line on every
> message to r-help.
>
> Its unlikely that 'its' ignores date fields but perhaps this will get
> you going.
> Each of these gives the first value and its time for each value that occurs
> in the series:
>
>   
>> # its
>> library(its)
>> ii <- its(rep(1:2, 5), Sys.time() + 1:10)
>> ii[!duplicated(ii)]
>> 
> An object of class "its"
>  1
> 20071105 1
> 20071105 2
> Slot "dates":
> [1] "2007-11-05 16:03:09 Eastern Standard Time"
> [2] "2007-11-05 16:03:10 Eastern Standard Time"
>
>   
>> # zoo
>> library(zoo)
>> z <- zoo(rep(1:2, 5), Sys.time() + 1:10)
>> z[!duplicated(z)]
>> 
> 2007-11-05 16:03:10 2007-11-05 16:03:11
>   1   2
>

__
R-help@r-project.org 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] R as a programming language

2007-11-07 Thread Gabor Grothendieck
Most of these have been answered but here are a few
additional options.

On Nov 7, 2007 7:46 AM, Alexy Khrabrov <[EMAIL PROTECTED]> wrote:
>
> Is there anything less ugly than
>
> print(paste("x=",x,"y=",y))
>

> library(gsubfn)
> a <- 1; b <- 2
> fn$cat("a = $a b = $b\n")
a = 1 b = 2

See gsubfn home page at htp://gsubfn.googlecode.com

> -- for routine printing?  Can [1] be eliminated from such simple
> printing?  What about formatted printing?
>

?format, ?formatC, ?prettyNum, ?sprintf

> Is there a way to assign all of
>
> a <- args[1]
> b <- args[2]
> c <- args[3]
>
> in one fell swoop, a lá Python's
>
> a,b,c = args
>

See:

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

__
R-help@r-project.org 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] Using R for large econometric models

2007-11-07 Thread Doran, Harold
One approach econometricians use with linear models is to demean the
data in order to reduce the computational burden. This can be done using
the ave() function. But, this is still difficult because, in my
experience, you still need to build a model matrix that must be demeaned
and that model matrix may be big. On the other hand, if you're dealing
with large sparse data sets, you may find either the sparseM and Matrix
packages useful as they are designed to handle large sparse matrices.

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Dietrich Trenkler
> Sent: Wednesday, November 07, 2007 3:05 AM
> To: R-help
> Subject: [R] Using R for large econometric models
> 
> Dear helpeRs,
> 
> a colleague of mine would like to give R a try.  He uses 
> econometric models which typically involve a large number of 
> variables, esp. time series.  Having no experience with 
> handling very large data sets myself I turn to you.
> 
> 1. Could you please describe your experiences to cope with these
>situations?
> 
> 2. What kind of difficulties will he have to face? Are there special
>tricks (packages) he might try?
> 
> 3. Can you recommend to use R?
> 
> 
> Sorry, if my question is a bit vague but at this point I'm 
> not able to give any further details.
> 
> Any help is very much appreciated.
> 
> D. Trenkler 
> 
> --
> Dietrich Trenkler c/o Universitaet Osnabrueck 
> Rolandstr. 8; D-49069 Osnabrueck, Germany
> email: [EMAIL PROTECTED]
> 
> __
> R-help@r-project.org 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@r-project.org 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] Linear Regression

2007-11-07 Thread Prof Brian Ripley
Doesn't

lm(fquamsci ~ ., data=a)

work?  It normally does for a list a, so there would seem to be something 
special about your example if it does not.  E.g.

library(MASS)
attach(hills)
a <- list(dist=dist, climb=climb, time=time)
detach()
lm(time ~ ., data=a)

(Maybe 'a' is not actually a list but a matrix?  In which case try 
as.data.frame(a).)


On Wed, 7 Nov 2007, livia wrote:

>
> Hello everyone,
>
> I would like to a linear regression with the following code.
> lm(a[,"fquamsci"]~., data=a)
>
> a is a list with class "mts" "ts" , and  "fquamsci" is the name of the
> response variable in a. I would like to do a linear regression of "fquamsci"
> to the rest of the variables. But it turns out the "fquamsci" is also
> included in the explanatory variables. I tried the following, it is quite
> strange that it does not work as well.
>
> lm(a[,"fquamsci"]~.-a[,"fquamsci"], data=a)
>
> Could anyone give me some advice?
> Many thanks
>
>

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org 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] color2D.matplot

2007-11-07 Thread Phillip Aldridge
Hi Jim,

Thanks for the suggestion I will try it as I do find color2D.matplot  
is a bit more versatile.

I have however, since pasting my message, carried on playing and  
found out that that doing the following actually works as well:

 > fg = read.table("flagenes.txt", row.names=1)
 > fg1=as.matrix(fg)
 > palette=c 
("white","black","red","orange","cyan","green3","yellow","blue")
 > image(fg1, col=palette)

The only annoying thing there is that image seems to turn my data  
upside down. As yet I have not figured out how to get a legend, get  
the right types f axis labels or get the plot shown to be the correct  
orientation. This just means when I get it into Canvas for my  
presentation all I have to do is rotate it a few times and fiddle  
with it a bit more than necessary.

All the best

Phil (wragbag)

On 7 Nov 2007, at 12:13, Jim Lemon wrote:

> wragbag wrote:
>> I am a true R novice aonly using it for this function ;)
>> I am trying to use color2D.matplot to form a image of my data  
>> using the
>> following conditions
>> color2D.matplot(fi1, c(dr), c(dg), c(db), nslices=7, ylab='Species',
>> xlab="gene", show.legend=TRUE) where fi1 is my matrix.
>> I have a matrix with 36 columns and 130 rows. most entries are 1  
>> or 0 and I
>> am trying to get this function to plot these as either 0 = white  
>> or 1 =
>> black. This is fine but one column contains entries between 0 and  
>> 7. I would
>> entries between 2 and 7 to be different colors (as this is what I  
>> am trying
>> to show although I also need to see the black and white areas)  
>> using the
>> following:
>>> dr = c(1,0,1,0,0)
>>> dg = c(1,0,0,1,0)
>>> db = c(1,0,0,0,1)
>> I can get some color to work but I cannot get them all as if I but  
>> in a c()
>> range equalling 0-7 (i.e. one color for each number I get the  
>> following. I
>> cannot figure out from the documentation why it will not let me do  
>> what I
>> want :(
>> Error in rescale(x[segindex], redrange[c(seg, seg + 1)]) :
>> rescale: can't rescale a constant vector!
> Hi wragbag,
> This is a situation that I had not envisaged in the design of  
> color2D.matplot. However, I think there is a workaround.
>
> fi1<-matrix(c(0,1),nrow=130,ncol=36)
> fi1[sample(1:3000,100)]<-sample(2:7,100,TRUE)
> color2D.matplot(fi1,
>  c(1,0,0.2,0.3,0.4,0.5,0.6,0.7),
>  c(1,0,0.2,0.3,0.4,0.5,0.6,0.7),
>  c(1,0,0.9,0.8,0.7,0.6,0.5,0.4),
>  ylab="Species",xlab="gene")
> color.legend(0,-15,7,-10,0:7,
>  color.scale(0:7,c(1,0,0.2,0.3,0.4,0.5,0.6,0.7),
>  c(1,0,0.2,0.3,0.4,0.5,0.6,0.7),
>  c(1,0,0.9,0.8,0.7,0.6,0.5,0.4))
>
> Because of the unusual way of specifying the color ranges to
> get white, black and then six colors, the rescale function
> throws an error on the constant vectors it is asked to rescale.
> I may have to think whether I can make it deal with this
> situation more gracefully. However, the above will get your
> plot and you can specify whatever colors you wish for the last
> six values in each primary color range. (What I have done is to
> specify as many color ranges as there are values).
>
> Jim

**

Dr. Phillip Aldridge PhD.
Lecturer
Institute for Cell and Molecular Biosciences
The Medical School
Newcastle University
Framlington Place
Newcastle upon Tyne
NE2 4HH

Tel: +44-191-222-7704
Fax: +44-191-222-7424
email: [EMAIL PROTECTED]

webpage: http://www.ncl.ac.uk/camb/staff/profile/p.d.aldridge

***



[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Trouble in creating a list

2007-11-07 Thread Henrique Dallazuanna
Try this:

1)eval(parse(text=paste("MyList<-list(", colnames(Model)[2], "=",
Model[,colnames(Model)[2]], ")")))

2)Model[,colnames(Model)[2]]

3)MyList[[3]] <- "Teste"
   MyList[[4]] <- "Teste1"


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

On 07/11/2007, Gang Chen <[EMAIL PROTECTED]> wrote:
>
>
> I want to create a list based on the information from a data.frame,
> Model. So I tried the following:
>
> MyList <- list(colnames(Model)[2] = levels(Model$(colnames(Model)[2])))
>
> but it failed with an error:
>
> Error: unexpected '=' in "list(colnames(Model)[2] ="
>
> I have the following problems with this command line:
>
> (1) I wanted to use colnames(Model)[2] as a tag for the list:
>
> > colnames(Model)[2]
> [1] "gender"
>
> but it is not working as I intended. How to make colnames(Model)[2] a
> legitimate tag?
>
> (2) Model$gender is a column in the data.frame. However Model$
> (colnames(Model)[2]) seems not recognizable in the command line. How
> to correct this?
>
> (3) How to add more tagged items to an existing list? cbind or rbind?
>
> Thanks in advance,
> Gang
>
> __
> R-help@r-project.org 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@r-project.org 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] Linear Regression

2007-11-07 Thread Henrique Dallazuanna
Try this:

data(tcm, package="tseries")
mod <- lm(tcm[,"tcm1y"]~., data=tcm[,- which(dimnames(tcm)[[2]]=="tcm1y")])


On 07/11/2007, livia <[EMAIL PROTECTED]> wrote:
>
>
> Hello everyone,
>
> I would like to a linear regression with the following code.
> lm(a[,"fquamsci"]~., data=a)
>
> a is a list with class "mts" "ts" , and  "fquamsci" is the name of the
> response variable in a. I would like to do a linear regression of
> "fquamsci"
> to the rest of the variables. But it turns out the "fquamsci" is also
> included in the explanatory variables. I tried the following, it is quite
> strange that it does not work as well.
>
> lm(a[,"fquamsci"]~.-a[,"fquamsci"], data=a)
>
> Could anyone give me some advice?
> Many thanks
>
> --
> View this message in context:
> http://www.nabble.com/Linear-Regression-tf4764346.html#a13626039
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Daily announcements of changes (was: Save as postScrips latest R version)

2007-11-07 Thread Duncan Murdoch
It seems people are unaware of the daily announcements of R changes.  If 
a change is significant enough to warrant mention in the NEWS file, it 
will be announced on one of the lists described here:

http://developer.r-project.org/RSSfeeds.html

These are available as RSS feeds, as the URL suggests.

For changes to R that would show up in R-patched, you would look at one 
of the R-2-6-branch listings.

For example, the bug report below is about a bug that was fixed around 
October 5, as could be seen here:

http://developer.r-project.org/blosxom.cgi/R-2-6-branch/2007/10/05

Once a fix is announced on that page, it should be available in 
R-patched, which can be downloaded from CRAN.  In this case it's a 
Windows bug, so you would get R-patched from

cran.r-project.org/bin/windows/base/rpatched.html

(There may be occasional delays in availability, but usually if the 
announcements are working, the nightly builds are working.)

Duncan Murdoch

On 11/7/2007 11:43 AM, Camila Estevam wrote:
> Hi,
> 
> I was using the 2.4.1 R version and I had no problem
> saving my plots as postScript. Now that I have
> installed the latest version 2.6.0 I can not save any
> plot as postScript. When I try the following message
> appears:
> 
> Erro: Invalid font type
> Além disso: Warning messages:
> 1: font family not found in PostScript font database 
> 2: font family not found in PostScript font database 
> 
> What should I do?
> 
> Thank you in advance,
> 
> Camila
> 
> Camila Pedroso Estevam de Souza
>   Mestrado em Estatística - UNICAMP
>   Master's Degree Student in Statistics - State University of Campinas
> 
> ___
> R-sig-gR mailing list
> [EMAIL PROTECTED]
> https://stat.ethz.ch/mailman/listinfo/r-sig-gr

__
R-help@r-project.org 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] Algorithms for coincidences

2007-11-07 Thread Doran, Harold
Thank you, Greg. In part, that's what I'm poking around for. I'm
wondering if there are any adaptations to clustered situations. I have
that paper below since it is the reference in qbirthday(), but haven't
found anything that has adapted this further. 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Greg Snow
> Sent: Tuesday, November 06, 2007 4:23 PM
> To: Doran, Harold; r-help
> Subject: Re: [R] Algorithms for coincidences
> 
> A paper that may help you:
> 
> "Methods for Studying Coincidences", Persi Diaconis; 
> Frederick Mosteller.  Journal of the American Statistical 
> Association, vol 84, no.
> 408 (Dec., 1989), 853-861.
> 
> And remember that the birthday problem assumes independence, 
> but if you have 2 students that studied together 
> (legitimately) then we would not expect their scores to be 
> independent.
> 
> Hope this helps,
> 
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> [EMAIL PROTECTED]
> (801) 408-8111
>  
>  
> 
> > -Original Message-
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Doran, Harold
> > Sent: Tuesday, November 06, 2007 12:10 PM
> > To: r-help
> > Subject: [R] Algorithms for coincidences
> > 
> > I'm looking at algorithms for determining coincidences. In 
> educational 
> > testing, it is interesting to look at cheating via the birthday 
> > problem where I can assess the probability of n students having the 
> > same test score in a class of size k.
> > 
> > I was writing my own code for the b-day problem until I ran into the
> > qbirthday() function, which has solutions for the overflow 
> problems I 
> > kept running into. There is no "see also" part of this man 
> page which 
> > would reference me to other functions which may prove 
> useful for such 
> > problems. But, that doesn't mean they don't exist.
> > 
> > I am just not familiar enough with this branch of 
> mathematics to know 
> > exactly what else I might look for. Does anyone know of any other R 
> > functions that may be useful for me to look at in thinking 
> about this 
> > kind of problem?
> > 
> > Harold
> > 
> > [[alternative HTML version deleted]]
> > 
> > __
> > R-help@r-project.org 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@r-project.org 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@r-project.org 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] Shortcut to refer to an attached dataframe?

2007-11-07 Thread Gabor Grothendieck
Here is one possibility:

> gets <- function(pos) get(search()[pos])
> attach(iris)
> summary(gets(2))
  Sepal.LengthSepal.Width Petal.LengthPetal.Width
 Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100
 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300
 Median :5.800   Median :3.000   Median :4.350   Median :1.300
 Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199
 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800
 Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500
   Species
 setosa:50
 versicolor:50
 virginica :50




On Nov 7, 2007 2:27 PM, Jeff Marcus <[EMAIL PROTECTED]> wrote:
> When I attach data frames I often want to be able to refer to the whole
> data frame rather then one of its components. For example:
>
>
>
> attach (my.data.frame)
>
> summary(my.data.frame)
>
>
>
> That's fine but often the frame has a very long name so I'd prefer some
> shorthand way of referring to it by its position on the search list.
> This applies especially to cases where I have a nested data frame so I
> might do
>
>
>
> attach(my.data.frame$mycomponent)
>
> summary(my.data.frame$mycomponent)
>
>
>
>  I have a recollection that there was a way of doing this with S-Plus
> but I haven't been able to figure out how to do it in R (I have looked
> at attach, get, sys.frame, etc. to no avail).
>
>
>
> Is there a built-in way of doing this? Thanks.
>
>
>
>  Jeff
>
>
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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@r-project.org 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] Homework help: t test hypothesis testing with summarized data?

2007-11-07 Thread Zembower, Kevin
Is this how a t hypothesis test is done when I don't have the actual
data, but just the summarized statistics: 
> #Homework 9.2.6 [1]
> n<-31
> xbar<-3.10
> s_x<-1.469
> m<-57
> ybar<-2.43
> s_y<-1.35
> s_pooled<- (((n-1)*s_x^2) + ((m-1)*s_y^2)) / (n + m - 2)
> s_pooled
[1] 1.939521
> t_obs <- (xbar -  ybar) / (s_pooled * (sqrt(1/n + 1/m)))
> t_obs
[1] 1.547951
> qt(c(.025, .975), n+m-2)
[1] -1.987934  1.987934
> # Therefore, fail to reject H0 at the 0.05 level of significance
>

Or am I again overlooking a canned procedure or an easier calculation
using the t distribution.

Thank you for your continued advice and help.

-Kevin

[1] An Introduction to Mathematical Statistics and its Applications,
fourth ed., Larsen and Marx.

Kevin Zembower
Internet Services Group manager
Center for Communication Programs
Bloomberg School of Public Health
Johns Hopkins University
111 Market Place, Suite 310
Baltimore, Maryland  21202
410-659-6139 

__
R-help@r-project.org 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] partially sum variable of a dataframe

2007-11-07 Thread Bert Gunter
In R "array" would mean a matrix, not a data frame. Also, let's name the
frame "cc" as "c" is the name of a commonly used function, and so should be
avoided as the name for an object. In any case, a straightforward
translation using indexing seems simplest:

sum(cc[cc[,"a"] <= 5.25 & cc[,"a"] >= 3, "b"])

Why pursue complexity when the straightforward approach is transparent?

Bert Gunter
Genentech Nonclinical Statistics


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: Wednesday, November 07, 2007 9:02 AM
To: [EMAIL PROTECTED]
Cc: r-help@r-project.org
Subject: Re: [R] partially sum variable of a dataframe

There's probably a shorter way but below works
and doesn't require the starting points to be in
the a column.

startindex<-3
endindex<-5.25

start<-tail(which(c$a<=startindex),1)
end<-tail(which(c$a<=endindex),1)

sum(c$b[start:end])


>Hello,
>
>A stupid question:
>
>I have an array with two columns, the first "a" acting as my index in 0.25
steps, the second one "b" the column of interest. How can i sum up "b" only
for a specified window in "a" (as the window command for time series)
>
>a=seq(0,10,0.25)
>b=runif(41)
>c=data.frame(a,b)
>
>Sum up c if 3
>How to do that? thanks
>
>marc
>-- 
>Pt! Schon vom neuen GMX MultiMessenger gehört?
>Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
>
>__
>R-help@r-project.org 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@r-project.org 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@r-project.org 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] Can I replace NA by 0 (if yes, how) ?

2007-11-07 Thread Wollkind, Steven
You don't need to loop.  You can just do

pfit$coefficients[is.na(pfit$coefficients)] <- 0 



Steve Wollkind
Associate Analyst
Geode Capital Management, LLC
1 Post Office Square / 28th Floor / Boston, MA 02109
[EMAIL PROTECTED]
Tel:   (617) 392-8991
Fax:  (617) 476-6389

This e-mail, and any attachments hereto, are intended for use by the
addressee(s) only and may contain information that is (i) confidential
information of Geode Capital Management, LLC and/or its affiliates,
and/or (ii) proprietary information of Geode Capital Management, LLC
and/or its affiliates. If you are not the intended recipient of this
e-mail, or if you have otherwise received this e-mail in error, please
immediately notify me by telephone (you may call collect), or by e-mail,
and please permanently delete the original, any print outs and any
copies of the foregoing. Any dissemination, distribution or copying of
this e-mail is strictly prohibited. 


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Ptit_Bleu
Sent: Wednesday, November 07, 2007 11:28 AM
To: r-help@r-project.org
Subject: Re: [R] Can I replace NA by 0 (if yes, how) ?


I found this solution but it must another one much more "R-friendly" ?

for (a in 1:9) {
if (is.na(pfit$coefficients[[a]])) (pfit$coefficients[[a]]<-0)
}

Again thank you in advance for explainations concerning NA,
Ptit Bleu.
-- 
View this message in context:
http://www.nabble.com/Can-I-replace-NA-by-0-%28if-yes%2C-how%29---tf4765
597.html#a13630590
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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@r-project.org 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] Can I replace NA by 0 (if yes, how) ?

2007-11-07 Thread Ptit_Bleu

I found this solution but it must another one much more "R-friendly" ?

for (a in 1:9) {
if (is.na(pfit$coefficients[[a]])) (pfit$coefficients[[a]]<-0)
}

Again thank you in advance for explainations concerning NA,
Ptit Bleu.
-- 
View this message in context: 
http://www.nabble.com/Can-I-replace-NA-by-0-%28if-yes%2C-how%29---tf4765597.html#a13630590
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Can I replace NA by 0 (if yes, how) ?

2007-11-07 Thread Ptit_Bleu

Hello,

I'm trying to fit some points with a 8-degrees polynom (result of lm is
stored in pfit).
In most of the case, it is ok but for some others, some coefficients are
"NA".
I don't really understand the meaning of these "NA".

And the problem is that I can't perform a derivation
(pderiv<-as.function((deriv(polynomial(pfit$coefficients) on pfit due to
the presence of these "NA".

I tried the functions na.omit and na.exclude but "NA" are still there.
I tried to replace manually "NA" by 0. The fit seems ok and then I can
derive the polynom.

But can I do this and, if yes, how can I detect and automatically replace
these "NA" ?

To conclude, I must say that I read some posts on NA but I must confess that
it is still not clear to me (maybe because I'm french and R-newbie ...)

Thanks in advance for your help,
Ptit Bleu.


pfit

Call:
lm(formula = pfitmax ~ poly(vfitmax, 8, raw = T))

Coefficients:
   (Intercept)  poly(vfitmax, 8, raw = T)1  poly(vfitmax, 8, raw
= T)2  poly(vfitmax, 8, raw = T)3  poly(vfitmax, 8, raw = T)4  
-2.790e+04   6.276e+03 
-5.645e+02   2.591e+01  -6.241e-01  
poly(vfitmax, 8, raw = T)5  poly(vfitmax, 8, raw = T)6  poly(vfitmax, 8, raw
= T)7  poly(vfitmax, 8, raw = T)8  
 6.681e-03  NA 
-3.942e-07  NA  


>pderiv<-as.function((deriv(polynomial(pfit$coefficients
Erreur dans while ((la <- length(a)) > 1 && a[la] == 0) a <- a[-la] : 
valeur manquante là où TRUE / FALSE est requis

-- 
View this message in context: 
http://www.nabble.com/Can-I-replace-NA-by-0-%28if-yes%2C-how%29---tf4765598.html#a13629976
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Graphics devices: windows() and x11() vs default

2007-11-07 Thread Wollkind, Steven
Ah ha!  I wasn't aware of the getOption("device") call before.  It
appears that as soon as I load the cairoDevice library my default device
gets set to Cairo, which explains why the Cairo device behavior matches
what I was seeing before.

This is now purely a cairo device issue, so I will pursue it with that
package's maintainer.

Thanks for your quick reply.
Steve 


Steve Wollkind
Associate Analyst
Geode Capital Management, LLC
1 Post Office Square / 28th Floor / Boston, MA 02109
[EMAIL PROTECTED]
Tel:   (617) 392-8991
Fax:  (617) 476-6389

This e-mail, and any attachments hereto, are intended for use by the
addressee(s) only and may contain information that is (i) confidential
information of Geode Capital Management, LLC and/or its affiliates,
and/or (ii) proprietary information of Geode Capital Management, LLC
and/or its affiliates. If you are not the intended recipient of this
e-mail, or if you have otherwise received this e-mail in error, please
immediately notify me by telephone (you may call collect), or by e-mail,
and please permanently delete the original, any print outs and any
copies of the foregoing. Any dissemination, distribution or copying of
this e-mail is strictly prohibited. 


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Martin Maechler
Sent: Wednesday, November 07, 2007 10:24 AM
To: Wollkind, Steven
Cc: r-help@r-project.org
Subject: Re: [R] Graphics devices: windows() and x11() vs default

> "WS" == Wollkind, Steven <[EMAIL PROTECTED]>
> on Wed, 7 Nov 2007 09:01:24 -0500 writes:

WS> I'm noticing some differences between making an explicit
WS> call to windows() to generate a graphics device and
WS> going with whatever R gives you when you just start
WS> plotting, which raises the question of just what the
WS> nature of the default device is.  I've had a hard time
WS> researching this so far, so I'm asking the list.

getOption("device")

  {the one you set by  options(device = ...)

is your current default graphics device.
That is platform dependent, and from what you say below,
I assume you have to use MS Windows, where typically
this default device *is* equivalent to windows().

However, there are many ways to change this default,
by initialization code, or loading other packages which change
it or ...

Before you can get more help,
we need to see your

   getOption("device")
and probably also
   sessionInfo()

Martin Maechler, ETH Zurich



WS> Here are two code snippets:

WS> ###
WS> ## Snippet 1
WS> ###
WS> windows()
WS> layout(matrix(c(1,2,3,4,5,6,7,8,9),3,3,byrow=T))
WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)

WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)

WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)




WS> ###
WS> ## Snippet 2
WS> ###
WS> layout(matrix(c(1,2,3,4,5,6,7,8,9),3,3,byrow=T))
WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)

WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)

WS> plot(1:10)
WS> plot(1:10)
WS> plot(1:10)



WS> Run snippet 1, then resize the device.  If your system is like
mine the
WS> redrawing after resizing will be quick and nice.  Then run
snippet 2 and
WS> try the same thing.  On my system I have to wait ~1 second per
plot as
WS> they each get redrawn.  My question boils down to "What is the
nature of
WS> the default device you get without an explicit device generating
call
WS> and why does it behave differently?"

WS> Now, this is obviously not that important in most cases, but
I've been
WS> working with the cairoDevice package (and will be emailing its
WS> maintainer soon) and the graphics devices that it produces
behave like
WS> snippet 2 and not snippet 1.  As a first step to trying to
correct this
WS> I'm simply trying to understand the differences between the
devices you
WS> get with both methods.

WS> Thanks
WS> Steve Wollkind

WS> Steve Wollkind
WS> Associate Analyst
WS> Geode Capital Management, LLC
WS> 1 Post Office Square / 28th Floor / Boston, MA 02109
WS> [EMAIL PROTECTED]
WS> Tel:   (617) 392-8991
WS> Fax:  (617) 476-6389

__
R-help@r-project.org 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@r-project.org 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] partially sum variable of a dataframe

2007-11-07 Thread John Kane
d <- subset(c, c$a > 3 & c$a < 5.25 )
sum(d[,2])

--- [EMAIL PROTECTED] wrote:

> Hello,
> 
> A stupid question:
> 
> I have an array with two columns, the first "a"
> acting as my index in 0.25 steps, the second one "b"
> the column of interest. How can i sum up "b" only
> for a specified window in "a" (as the window command
> for time series)
> 
> a=seq(0,10,0.25)
> b=runif(41)
> c=data.frame(a,b)
> 
> Sum up c if 3 
> How to do that? thanks
> 
> marc
> -- 
> Pt! Schon vom neuen GMX MultiMessenger gehört?
> Der kann`s mit allen:
> http://www.gmx.net/de/go/multimessenger
> 
> __
> R-help@r-project.org 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@r-project.org 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] Shortcut to refer to an attached dataframe?

2007-11-07 Thread Jeff Marcus
When I attach data frames I often want to be able to refer to the whole
data frame rather then one of its components. For example:

 

attach (my.data.frame)

summary(my.data.frame)

 

That's fine but often the frame has a very long name so I'd prefer some
shorthand way of referring to it by its position on the search list.
This applies especially to cases where I have a nested data frame so I
might do 

 

attach(my.data.frame$mycomponent)

summary(my.data.frame$mycomponent)

 

 I have a recollection that there was a way of doing this with S-Plus
but I haven't been able to figure out how to do it in R (I have looked
at attach, get, sys.frame, etc. to no avail). 

 

Is there a built-in way of doing this? Thanks. 

 

 Jeff

 


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Indexing, and using an empty string as a name

2007-11-07 Thread Prof Brian Ripley
[Adding R-help back, as you did later.]

On Wed, 7 Nov 2007, Charilaos Skiadas wrote:

> On Nov 7, 2007, at 2:51 AM, Prof Brian Ripley wrote:
>
>> On Tue, 6 Nov 2007, Charilaos Skiadas wrote:
>> 
>>> Hello all,
>>> 
>>> I ran into the following, to me unexpected, behavior. I have (for
>>> reasons that don't necessarily pertain to the question at hand, hence
>>> I won't go into them) the need/desire to use an empty string for the
>>> name of a vector entry.
>> 
>> The 'R Languge Definition' says
>>
>>  The string "" is treated specially: it indicates `no name' and matches
>>  no element (not even those without a name).
>> 
>> and from ?names
>>
>>  The name \code{""} is special: it is used to indicate that there is no
>>  name associated with an element of a (atomic or generic) vector.
>>  Subscripting by \code{""} will match nothing (not even elements which
>>  have no name).
>> 
>> so it should perhaps have been expected.
>
> It should indeed, if I had looked at ?names, which I should have thought of 
> doing. I wonder why ?"[" doesn't mention it though, especially the part 
> about: "Subscripting by "" will match nothing (not even elements which have 
> no name)."

Well, the help page of `[` is complex enough already, there was a link to 
the page for names, and this doesn't seem to have bitten many people. 
However, I have already added the information for the next version since 
there were other facts about character indexing that were not there and I 
created a new section for them.  However we try to organize it, 
information overload seems to be a problem for that help page.

I suspect that not everyone who has worked on the code/documentation was 
aware of the special status of "" 

> What are the reasons for treating "" in a special way, btw? i.e. can't we use 
> NA to indicate "no name"? (Hm, come to think of it, NA means more that we 
> don't know the name, not that there isn't a name. So perhaps it makes sense 
> after all.)

It long predates the availability of character NAs (which S did not have), 
and as you say, it is not quite the same.

[...]

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org 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] color2D.matplot

2007-11-07 Thread Jim Lemon
wragbag wrote:
> I am a true R novice aonly using it for this function ;)
> 
> I am trying to use color2D.matplot to form a image of my data using the
> following conditions
> 
> color2D.matplot(fi1, c(dr), c(dg), c(db), nslices=7, ylab='Species',
> xlab="gene", show.legend=TRUE) where fi1 is my matrix.
> 
> I have a matrix with 36 columns and 130 rows. most entries are 1 or 0 and I
> am trying to get this function to plot these as either 0 = white or 1 =
> black. This is fine but one column contains entries between 0 and 7. I would
> entries between 2 and 7 to be different colors (as this is what I am trying
> to show although I also need to see the black and white areas) using the
> following:
> 
> 
>>dr = c(1,0,1,0,0)
>>dg = c(1,0,0,1,0)
>>db = c(1,0,0,0,1)
> 
> 
> I can get some color to work but I cannot get them all as if I but in a c()
> range equalling 0-7 (i.e. one color for each number I get the following. I
> cannot figure out from the documentation why it will not let me do what I
> want :(
> 
> Error in rescale(x[segindex], redrange[c(seg, seg + 1)]) : 
>   rescale: can't rescale a constant vector!
> 
Hi wragbag,
This is a situation that I had not envisaged in the design of 
color2D.matplot. However, I think there is a workaround.

fi1<-matrix(c(0,1),nrow=130,ncol=36)
fi1[sample(1:3000,100)]<-sample(2:7,100,TRUE)
color2D.matplot(fi1,
  c(1,0,0.2,0.3,0.4,0.5,0.6,0.7),
  c(1,0,0.2,0.3,0.4,0.5,0.6,0.7),
  c(1,0,0.9,0.8,0.7,0.6,0.5,0.4),
  ylab="Species",xlab="gene")
color.legend(0,-15,7,-10,0:7,
  color.scale(0:7,c(1,0,0.2,0.3,0.4,0.5,0.6,0.7),
  c(1,0,0.2,0.3,0.4,0.5,0.6,0.7),
  c(1,0,0.9,0.8,0.7,0.6,0.5,0.4))

Because of the unusual way of specifying the color ranges to
get white, black and then six colors, the rescale function
throws an error on the constant vectors it is asked to rescale.
I may have to think whether I can make it deal with this
situation more gracefully. However, the above will get your
plot and you can specify whatever colors you wish for the last
six values in each primary color range. (What I have done is to
specify as many color ranges as there are values).

Jim

__
R-help@r-project.org 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] vectorize a list

2007-11-07 Thread Henrique Dallazuanna
try this:

unlist(l)

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

On 08/11/2007, Frank Schmid <[EMAIL PROTECTED]> wrote:
>
> Dear R user
>
> Suppose I have the following list:
>
> > f <- rnorm(2)
> > s <- rnorm(3)
> > l <- list(f,s)
> > l
> [[1]]
> [1] 0.31784399 0.08575421
>
> [[2]]
> [1] -0.6191679  0.7615479 -1.0087659
>
>
> Can I stack the entries of this list in 1 vector with the first list
> entry followed by the second? The reference manual says that I can use
> the command /stack/, which can take as arguments either a list or a data
> frame. But taking simply /stack(l)/ does not work, although it is a list.
>
> Many thanks for your hint
>
> Frank Schmid
>
> __
> R-help@r-project.org 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@r-project.org 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] Kolmogorov-Smirnoff test

2007-11-07 Thread Jasjeet Singh Sekhon

A bootstrap Kolmogorov-Smirnoff test will have the correct test level
even if there are ties---i.e., even if non-continuous distributions
are being compared.  See Abadie, Alberto. 2002. ``Bootstrap Tests for
Distributional Treatment Effects in Instrumental Variable Models.'' 
Journal of the American Statistical Association, 97:457 (March)
284-292.

The algorithm is implemented in the ks.boot function of the Matching
package: http://sekhon.berkeley.edu/matching/ks.boot.html

Cheers,
Jas.

===
Jasjeet S. Sekhon

Associate Professor
Travers Department of Political Science
Survey Research Center
UC Berkeley

http://sekhon.berkeley.edu/
V: 510-642-9974  F: 617-507-5524
===


Oarabile Molaodi writes:
 > I am trying to determine whether two samples are identical or not. I'm 
 > aware that somebody can use the Kolmogorov-Smirnoff test to compare 
 > empirical distributions, but since my samples have ties I'm not sure if 
 > I'm getting the right p-values for the comparison. Can the 
 > Kolmogorov-Smirnoff test be adjusted for the case when ties exists and 
 > are there any functions that already exists in R ( Kolmogorov-Smirnoff 
 > test )performing  that can be used in the case of the existance of ties?
 > 
 > Thank you in advance for your help.
 > 
 > Oarabile
 > 
 >

__
R-help@r-project.org 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] function

2007-11-07 Thread Bill Hunsicker

Rhelp,

I have a collection of data that I would like to perform some simple
functions on like mean, stdev  I would like to write a function that
I sent data set to and have mean, and other calculations derived from
data set returned. 

Can you help me?

Regards,
Bill



Bill Hunsicker
RF Micro Devices
7625 Thorndike Road
Greensboro, NC 27409-9421
[EMAIL PROTECTED]
336-678-5260(w)
336-207-3895(m)
336-678-5088(lab)
610-298-2988(h)

__
R-help@r-project.org 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] question about running out of memory on R -- memory.limit change in R 2.6.0?

2007-11-07 Thread kees
Earl,

Reported memory sizes work ok on Vista 64. If I ask for 3.5M it will give  
it, even though I have only 2Mb of RAM.
It devaults to 2Mb as expected.

Op Tue, 06 Nov 2007 19:38:07 +0100 schreef Earl F. Glynn  
<[EMAIL PROTECTED]>:

> "jim holtman" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> --max-mem-size=N
>> (Windows only) Specify a limit for the amount of memory to be used
>> both for R objects and working areas. This is set by default to the
>> smaller of 1.5Gb24 and the amount of physical RAM in the machine, and
>> must be between 32Mb and 3Gb.
>
> Something seems to have changed in R 2.6.0 -- the limit is no longer 3  
> GB.
>
> On a PC with 3.5 GB with R 2.5.1 using default command line:
>
> Default
>
>> memory.limit()
>
> [1] 1610612736
>
>
>
> With --max-mem-size=3000M on the command line:
>
>
>
>> memory.limit()
>
> [1] 3145728000
>
>
>
>
>
>
> Let's see what happens with R 2.6.0 on the same 3.5 GB PC (Windows XP):
>
>
>
> Default command line:
>
>
>> memory.limit()
>
> [1] 1535.875
>
>
>
> Note:  The format of the return value is now in MB instead of bytes.
>
>
>
> With --max-mem-size=3000M on the command line:
>
>
>
> Error message:  WARNING: --max-mem-size=3000M: too large and taken as  
> 2047M
>
>
>
>> memory.limit()
>
> [1] 2047.875
>
>
>
> This value is less than the value shown in R 2.5.1 (after converting  
> both to
> the same basis).
>
>
>
> But was this change a "fix" to report that a Windows process only has a  
> 2 GB
> address space?  That is, the value returned by R 2.5.1 of 3145728000  
> wasn't
> strictly correct?
>
>
>
> efg
>
>
>
> Earl F. Glynn
>
> Scientific Programmer
>
> Stowers Institute
>
> __
> R-help@r-project.org 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.
>
>



-- 
Gemaakt met Opera's revolutionaire e-mailprogramma:  
http://www.opera.com/mail/

__
R-help@r-project.org 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] partially sum variable of a dataframe

2007-11-07 Thread mdgi
Hello,

A stupid question:

I have an array with two columns, the first "a" acting as my index in 0.25 
steps, the second one "b" the column of interest. How can i sum up "b" only for 
a specified window in "a" (as the window command for time series)

a=seq(0,10,0.25)
b=runif(41)
c=data.frame(a,b)

Sum up c if 3http://www.gmx.net/de/go/multimessenger

__
R-help@r-project.org 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] Graphics devices: windows() and x11() vs default

2007-11-07 Thread Wollkind, Steven
I'm noticing some differences between making an explicit call to
windows() to generate a graphics device and going with whatever R gives
you when you just start plotting, which raises the question of just what
the nature of the default device is.  I've had a hard time researching
this so far, so I'm asking the list.

Here are two code snippets:

###
## Snippet 1
###
windows()
layout(matrix(c(1,2,3,4,5,6,7,8,9),3,3,byrow=T))
plot(1:10)
plot(1:10)
plot(1:10)

plot(1:10)
plot(1:10)
plot(1:10)

plot(1:10)
plot(1:10)
plot(1:10)




###
## Snippet 2
###
layout(matrix(c(1,2,3,4,5,6,7,8,9),3,3,byrow=T))
plot(1:10)
plot(1:10)
plot(1:10)

plot(1:10)
plot(1:10)
plot(1:10)

plot(1:10)
plot(1:10)
plot(1:10)



Run snippet 1, then resize the device.  If your system is like mine the
redrawing after resizing will be quick and nice.  Then run snippet 2 and
try the same thing.  On my system I have to wait ~1 second per plot as
they each get redrawn.  My question boils down to "What is the nature of
the default device you get without an explicit device generating call
and why does it behave differently?"

Now, this is obviously not that important in most cases, but I've been
working with the cairoDevice package (and will be emailing its
maintainer soon) and the graphics devices that it produces behave like
snippet 2 and not snippet 1.  As a first step to trying to correct this
I'm simply trying to understand the differences between the devices you
get with both methods.

Thanks
Steve Wollkind

Steve Wollkind
Associate Analyst
Geode Capital Management, LLC
1 Post Office Square / 28th Floor / Boston, MA 02109
[EMAIL PROTECTED]
Tel:   (617) 392-8991
Fax:  (617) 476-6389

This e-mail, and any attachments hereto, are intended fo...{{dropped:11}}

__
R-help@r-project.org 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] R as a programming language

2007-11-07 Thread Alexy Khrabrov
Greetings -- coming from Python/Ruby perspective, I'm wondering about  
certain features of R as a programming language.

Say I have a huge table t of the form

run ord unitwords   new
1   1   69391013641
1   2   275 1001518
1   3   33141008488
1   4   14154   1018463
1   5   29821006421

Alternatively, it may have a part column in front.  For each run (in  
a part if present), I select ord and new columns as x and y and plot  
their functions in various ways.  t is huge.  So I want to select the  
subset to plot, as follows:

t.xy <- function(t,part=NA,run=NA) {
if (is.na(run)) {
# TODO does this entail a full copy -- or how do we do 
references  
in R?
r <- t
} else if (is.na(part)) {
r <- t[t$run == run,]
} else { # part present too
r <- t[t$part == part & t$run == run,]
}
x <- r$ord
y <- r$new
xy.coords(x,y)
}

What I'm wondering about is whether r <-t will copy the complete t,  
and how do I minimize copying in R.  I heard it's a functional  
language -- is there lazy evaluation in place here?

Additionally, tried to use --args command line arguments, and found a  
way only due to David Brahm -- who helped with several important R  
points (thanks Dave!):

#!/bin/sh
# graph a fertility run
tail --lines=+4 "$0" | R --vanilla --slave --args $*; exit
args <- commandArgs()[-(1:4)]
...

And, still no option processing as in GNU long options, or python or  
ruby's optparse.

What's the semantics of parameter passing -- by value or by reference?

Is there anything less ugly than

print(paste("x=",x,"y=",y))

-- for routine printing?  Can [1] be eliminated from such simple  
printing?  What about formatted printing?

Is there a way to assign all of

a <- args[1]
b <- args[2]
c <- args[3]

in one fell swoop, a lá Python's

a,b,c = args

What's the simplest way to check whether a filename ends in ".rda"?

Will ask more as I go programming...

(Will someone here please write an O'Reilly's "Programming in R"?  :)

Cheers,
Alexy
__
R-help@r-project.org 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] Indexing, and using an empty string as a name

2007-11-07 Thread Charilaos Skiadas
Sorry, I meant to reply to the whole list.

I can totally understand the list's policy of not defaulting to  
"reply to the list", but I keep forgetting it in practice (since I am  
in a couple of other lists with less traffic, where the default is to  
reply to the list.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

My off-list reply follows.
On Nov 7, 2007, at 7:35 AM, Charilaos Skiadas wrote:

> On Nov 7, 2007, at 2:51 AM, Prof Brian Ripley wrote:
>
>> On Tue, 6 Nov 2007, Charilaos Skiadas wrote:
>>
>>> Hello all,
>>>
>>> I ran into the following, to me unexpected, behavior. I have (for
>>> reasons that don't necessarily pertain to the question at hand,  
>>> hence
>>> I won't go into them) the need/desire to use an empty string for the
>>> name of a vector entry.
>>
>> The 'R Languge Definition' says
>>
>>   The string "" is treated specially: it indicates `no name' and  
>> matches
>>   no element (not even those without a name).
>>
>> and from ?names
>>
>>   The name \code{""} is special: it is used to indicate that there  
>> is no
>>   name associated with an element of a (atomic or generic) vector.
>>   Subscripting by \code{""} will match nothing (not even elements  
>> which
>>   have no name).
>>
>> so it should perhaps have been expected.
>
> It should indeed, if I had looked at ?names, which I should have  
> thought of doing. I wonder why ?"[" doesn't mention it though,  
> especially the part about: "Subscripting by "" will match nothing  
> (not even elements which have no name)."
>
> What are the reasons for treating "" in a special way, btw? i.e.  
> can't we use NA to indicate "no name"? (Hm, come to think of it, NA  
> means more that we don't know the name, not that there isn't a  
> name. So perhaps it makes sense after all.)
>
> Actually the interpretation as "no name" is rather appropriate in  
> my case, in a way. The reason I have empty names is that I wanted  
> to "fake the presence of a grouping variable". I.e. I have code  
> that expect a factor, and uses that factor to split the data and  
> compute summaries. Providing a "trivial" factor would allow the  
> same code to handle the case where there is no factor at all.
>
>>> Perhaps I did not read ?"[" very carefully,
>>> but it seems to me that he following lines should return "1" at  
>>> the end:
>>>
>>> x<-1:4
>>> names(x) <- c("","a","b","c")
>>> x[""]
>>>
>>>
>>> Instead, they return NA. Could anyone provide an explanation for  
>>> this
>>> behavior?
>>
>> You can do
>>
>>> x[[""]]
>> [1] 1
>>
>> (which is arguably a bug given the quotes above) or
>>
>> x[match("", names(x))]
>
> I like this second approach more. I had to use dimnames(table)[3]  
> instead of names(x) (and a couple more commas), since in my actual  
> case those names are in an array, but the idea is the same and it  
> worked beautifully. Thanks!
>
>>
>> -- 
>> Brian D. Ripley,  [EMAIL PROTECTED]
>> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>> University of Oxford, Tel:  +44 1865 272861 (self)
>> 1 South Parks Road, +44 1865 272866 (PA)
>> Oxford OX1 3TG, UKFax:  +44 1865 272595
>
> Haris Skiadas

__
R-help@r-project.org 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-11-07 Thread Gabor Grothendieck
Here is na.locf both operating on x and on a zoo variable
compared to the others:

> set.seed(1)
> x = 1:1e5
> x[sample(1:1e5, 1)] = NA
> system.time(z2<-locf.iverson2(x))
   user  system elapsed
   0.050.000.05
> system.time(z1<-locf.iverson(x))
   user  system elapsed
   0.110.000.11
> system.time(z3<-locf.sfear(x))
   user  system elapsed
   1.310.001.33
>
> library(zoo)
> system.time(z4 <- na.locf(x))
   user  system elapsed
   0.030.000.03
>
> z <- zoo(x)
> system.time(z5 <- na.locf(z))
   user  system elapsed
   0.040.000.05
>


On Jun 22, 2007 4:29 PM, Horace Tso <[EMAIL PROTECTED]> wrote:
> 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: [EMAIL PROTECTED]
> 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
> >
> > __
> > [EMAIL PROTECTED] 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.
>
> __
> [EMAIL PROTECTED] 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}}
>
> __
> [EMA

Re: [R] vectorize a list

2007-11-07 Thread Thibaut Jombart
Frank Schmid wrote:

>Dear R user
>
>Suppose I have the following list:
>
> > f <- rnorm(2)
> > s <- rnorm(3)
> > l <- list(f,s)
> > l
>[[1]]
>[1] 0.31784399 0.08575421
>
>[[2]]
>[1] -0.6191679  0.7615479 -1.0087659
>
>
>Can I stack the entries of this list in 1 vector with the first list 
>entry followed by the second? The reference manual says that I can use 
>the command /stack/, which can take as arguments either a list or a data 
>frame. But taking simply /stack(l)/ does not work, although it is a list.
>
>Many thanks for your hint
>
>Frank Schmid
>
>__
>R-help@r-project.org 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.
>
>
>  
>
Hi,
no need to use stack here:

 > l=list(a=1:4,b=5:8)
 > l
$a
[1] 1 2 3 4

$b
[1] 5 6 7 8

 > unlist(l)
a1 a2 a3 a4 b1 b2 b3 b4
 1  2  3  4  5  6  7  8

Regards,

Thibaut.

-- 
##
Thibaut JOMBART
CNRS UMR 5558 - Laboratoire de Biométrie et Biologie Evolutive
Universite Lyon 1
43 bd du 11 novembre 1918
69622 Villeurbanne Cedex
Tél. : 04.72.43.29.35
Fax : 04.72.43.13.88
[EMAIL PROTECTED]
http://lbbe.univ-lyon1.fr/-Jombart-Thibaut-.html?lang=en
http://pbil.univ-lyon1.fr/software/adegenet/

__
R-help@r-project.org 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] Daily announcements of changes (was: Save as postScrips latest R version)

2007-11-07 Thread Camila Estevam
Hi Professor Murdoch

Thank you very much for your reply,

I really did not know about the daily announcements.
Next time I will check them. I will install the
R-patched and let you know if it works.

Thanks again,

Camila


--- Duncan Murdoch <[EMAIL PROTECTED]> escreveu:

> It seems people are unaware of the daily
> announcements of R changes.  If 
> a change is significant enough to warrant mention in
> the NEWS file, it 
> will be announced on one of the lists described
> here:
> 
> http://developer.r-project.org/RSSfeeds.html
> 
> These are available as RSS feeds, as the URL
> suggests.
> 
> For changes to R that would show up in R-patched,
> you would look at one 
> of the R-2-6-branch listings.
> 
> For example, the bug report below is about a bug
> that was fixed around 
> October 5, as could be seen here:
> 
>
http://developer.r-project.org/blosxom.cgi/R-2-6-branch/2007/10/05
> 
> Once a fix is announced on that page, it should be
> available in 
> R-patched, which can be downloaded from CRAN.  In
> this case it's a 
> Windows bug, so you would get R-patched from
> 
> cran.r-project.org/bin/windows/base/rpatched.html
> 
> (There may be occasional delays in availability, but
> usually if the 
> announcements are working, the nightly builds are
> working.)
> 
> Duncan Murdoch
> 
> On 11/7/2007 11:43 AM, Camila Estevam wrote:
> > Hi,
> > 
> > I was using the 2.4.1 R version and I had no
> problem
> > saving my plots as postScript. Now that I have
> > installed the latest version 2.6.0 I can not save
> any
> > plot as postScript. When I try the following
> message
> > appears:
> > 
> > Erro: Invalid font type
> > Além disso: Warning messages:
> > 1: font family not found in PostScript font
> database 
> > 2: font family not found in PostScript font
> database 
> > 
> > What should I do?
> > 
> > Thank you in advance,
> > 
> > Camila
> > 
> > Camila Pedroso Estevam de Souza
> >   Mestrado em Estatística - UNICAMP
> >   Master's Degree Student in Statistics - State
> University of Campinas
> > 
> > ___
> > R-sig-gR mailing list
> > [EMAIL PROTECTED]
> > https://stat.ethz.ch/mailman/listinfo/r-sig-gr
> 
> 


Camila Pedroso Estevam de Souza
  Mestrado em Estatística - UNICAMP
  Master's Degree Student in Statistics - State University of Campinas

__
R-help@r-project.org 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] Aggregate with non-scalar function

2007-11-07 Thread Mike Nielsen
R-Helpers,

I'm sorry to have to ask this -- I've not used R very much in the last
8 or 10 months, and I've gotten rusty.

I have the following (ff2 is a subset of a much, much larger dataset):

> ff2
  hostName user sys idle obsTime
10142 fred  0.4 0.5 98.0 2007-11-01 02:02:18
16886   barney  0.5 0.2 94.6 2007-10-25 19:12:12
8795  fred  0.0 0.1 99.8 2007-10-30 05:08:22
5261  fred  0.1 0.2 99.7 2007-10-25 07:20:32
12427   barney  0.1 0.2 93.2 2007-10-19 14:34:10
18067   barney  0.1 0.2 99.4 2007-10-27 10:34:08
973   fred  0.0 0.2 99.8 2007-10-19 08:24:22
5426  fred  0.2 0.3 99.5 2007-10-25 12:50:33
7067  fred  0.1 0.2 99.4 2007-10-27 19:32:27
13159   barney  0.1 0.4 84.3 2007-10-20 14:58:11
17481   barney  1.2 2.0 92.6 2007-10-26 15:02:11
21632   barney  0.1 0.1 99.6 2007-11-01 09:24:09
206   fred 19.4 4.8 53.7 2007-10-18 06:50:34
18151   barney  0.1 0.2 94.9 2007-10-27 13:22:09
10662 fred  0.1 0.2 99.6 2007-11-01 19:22:27
10376 fred  0.0 0.2 99.7 2007-11-01 09:50:24
3630  fred 43.7 7.0 33.0 2007-10-23 00:58:27
1118  fred  0.6 0.4 98.9 2007-10-19 13:14:23
5122  fred  0.1 0.2 99.6 2007-10-25 02:42:21
22117   barney  0.0 0.2 99.4 2007-11-02 01:34:04

> doit(ff2)
   hostName hour user.mean sys.mean idle.mean user.max sys.max idle.max
1barney   01  0.00 0.20 99.40  0.0 0.2 99.4
2barney   09  0.10 0.10 99.60  0.1 0.1 99.6
3barney   10  0.10 0.20 99.40  0.1 0.2 99.4
4barney   13  0.10 0.20 94.90  0.1 0.2 94.9
5barney   14  0.10 0.30 88.75  0.1 0.4 93.2
6barney   15  1.20 2.00 92.60  1.2 2.0 92.6
7barney   19  0.50 0.20 94.60  0.5 0.2 94.6
8  fred   00 43.70 7.00 33.00 43.7 7.0 33.0
9  fred   02  0.25 0.35 98.80  0.4 0.5 99.6
10 fred   05  0.00 0.10 99.80  0.0 0.1 99.8
11 fred   06 19.40 4.80 53.70 19.4 4.8 53.7
12 fred   07  0.10 0.20 99.70  0.1 0.2 99.7
13 fred   08  0.00 0.20 99.80  0.0 0.2 99.8
14 fred   09  0.00 0.20 99.70  0.0 0.2 99.7
15 fred   12  0.20 0.30 99.50  0.2 0.3 99.5
16 fred   13  0.60 0.40 98.90  0.6 0.4 98.9
17 fred   19  0.10 0.20 99.50  0.1 0.2 99.6
> doit
function(x){
x.mean<-aggregate(x[,c("user","sys","idle")],
 by=list(hostName=x$hostName,

hour=strftime(as.POSIXlt(x$obsTime),"%H")),
 mean)

x.max<-aggregate(x[,c("user","sys","idle")],
   by=list(hostName=x$hostName,

hour=strftime(as.POSIXlt(x$obsTime),"%H")),
   max)

t1<-merge(x.mean,x.max,by=c("hostName","hour"),suffixes=c(".mean",".max"))
return(t1)
}

The point of the "doit" function is to make a new dataframe in which
the columns are summary statistics of certain columns in the argument.

Is there a function similar to:

magic.function(ff2[,c("user","system","idle")],
  
by=list(hostName=ff2$hostName,hour=strftime(as.POSIXlt(ff2$obsTime),"%H")),
  function(x){c(mean.user=mean(x$user),
mean.system=mean(x$system),
mean.idle=mean(x$idle),
max.user=max(x$user),
max.system=max(x$system),
max.idle=max(x$idle))})

ie. an "aggregate" that can cope with a non-scalar function and "do
what I mean"?  My doit function gets more and more ugly the more
summary statistics I add, and I worry about the "merge" with hundreds
of thousands of rows.

I'm almost sure I've seen a solution to what I know is a simple
problem, but I guess my search skills are as bad as my "R": I've
rummaged around the r-help archives and came up with nothing to show
for it.


Pointers would be gratefully received.

Many thanks.
-- 
Regards,

Mike Nielsen

__
R-help@r-project.org 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] Save as postScrips latest R version

2007-11-07 Thread Camila Estevam
Hi,

I was using the 2.4.1 R version and I had no problem
saving my plots as postScript. Now that I have
installed the latest version 2.6.0 I can not save any
plot as postScript. When I try the following message
appears:

Erro: Invalid font type
Além disso: Warning messages:
1: font family not found in PostScript font database 
2: font family not found in PostScript font database 

What should I do?

Thank you in advance,

Camila

Camila Pedroso Estevam de Souza
  Mestrado em Estatística - UNICAMP
  Master's Degree Student in Statistics - State University of Campinas

__
R-help@r-project.org 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] SE of mean using subsampling bootstrap

2007-11-07 Thread Anil
I have been trying to get an example of R statements for estimating SE of mean 
using Subsampling bootstrap. Could someone help me?

Thanks

Anil
[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Can I replace NA by 0 (if yes, how) ?

2007-11-07 Thread Ptit_Bleu

Hello,

I'm trying to fit some points with a 8-degrees polynom (result of lm is
stored in pfit).
In most of the case, it is ok but for some others, some coefficients are
"NA".
I don't really understand the meaning of these "NA".

And the problem is that I can't perform a derivation
(pderiv<-as.function((deriv(polynomial(pfit$coefficients) on pfit due to
the presence of these "NA".

I tried the functions na.omit and na.exclude but "NA" are still there.
I tried to replace manually "NA" by 0. The fit seems ok and then I can
derive the polynom.

But can I do this and, if yes, how can I detect and automatically replace
these "NA" ?

To conclude, I must say that I read some posts on NA but I must confess that
it is still not clear to me (maybe because I'm french and R-newbie ...)

Thanks in advance for your help,
Ptit Bleu.


pfit

Call:
lm(formula = pfitmax ~ poly(vfitmax, 8, raw = T))

Coefficients:
   (Intercept)  poly(vfitmax, 8, raw = T)1  poly(vfitmax, 8, raw
= T)2  poly(vfitmax, 8, raw = T)3  poly(vfitmax, 8, raw = T)4  
-2.790e+04   6.276e+03 
-5.645e+02   2.591e+01  -6.241e-01  
poly(vfitmax, 8, raw = T)5  poly(vfitmax, 8, raw = T)6  poly(vfitmax, 8, raw
= T)7  poly(vfitmax, 8, raw = T)8  
 6.681e-03  NA 
-3.942e-07  NA  


>pderiv<-as.function((deriv(polynomial(pfit$coefficients
Erreur dans while ((la <- length(a)) > 1 && a[la] == 0) a <- a[-la] : 
valeur manquante là où TRUE / FALSE est requis

-- 
View this message in context: 
http://www.nabble.com/Can-I-replace-NA-by-0-%28if-yes%2C-how%29---tf4765597.html#a13629975
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] histogramme

2007-11-07 Thread Henrique Dallazuanna
Hi,

Perhaps:

par(mfrow=c(2,2))
hist(as.numeric(as.character(B[,1])),col="lightblue", border="pink")
hist(as.numeric(as.character(A[,1])),col="yellow", border="pink")

or

hist(as.numeric(as.character(B[,1])),col="lightblue", border="pink")
par(new=T)
hist(as.numeric(as.character(A[,1])),col="yellow", border="pink")



On 07/11/2007, elyakhlifi mustapha <[EMAIL PROTECTED]> wrote:
>
> Hello,
> I can plot histogrammes but I want to know how can I do to plot 2
> histogrammes at the same time (in the same window).
> hist(as.numeric(as.character(B[,1])),col="lightblue", border="pink")
> hist(as.numeric(as.character(A[,1])),col="yellow", border="pink")
> thanks.
>
>
>
> _
>
> l
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] histogramme

2007-11-07 Thread elyakhlifi mustapha
Hello,
I can plot histogrammes but I want to know how can I do to plot 2 histogrammes 
at the same time (in the same window).
hist(as.numeric(as.character(B[,1])),col="lightblue", border="pink")
hist(as.numeric(as.character(A[,1])),col="yellow", border="pink")
thanks.


  
_ 

l 
[[alternative HTML version deleted]]

__
R-help@r-project.org 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] function

2007-11-07 Thread jim holtman
Does this do what you want?

> x <- 1:10
> x.f <- function(dat){
+ c(mean=mean(dat), median=median(dat), sd=sd(dat))
+ }
> x.f(x)
mean   median   sd
5.50 5.50 3.027650
>


On 11/7/07, Bill Hunsicker <[EMAIL PROTECTED]> wrote:
>
> Rhelp,
>
> I have a collection of data that I would like to perform some simple
> functions on like mean, stdev  I would like to write a function that
> I sent data set to and have mean, and other calculations derived from
> data set returned.
>
> Can you help me?
>
> Regards,
> Bill
>
>
>
> Bill Hunsicker
> RF Micro Devices
> 7625 Thorndike Road
> Greensboro, NC 27409-9421
> [EMAIL PROTECTED]
> 336-678-5260(w)
> 336-207-3895(m)
> 336-678-5088(lab)
> 610-298-2988(h)
>
> __
> R-help@r-project.org 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?

__
R-help@r-project.org 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] Estimate a logit of shares

2007-11-07 Thread Trevor Marcel
Hello,

I would like to estimate a logit with aggregated data. Each line 
describes an observation with the following fields :
- share of choice A
- share of choice B
- share of choice C
- Var.A1 (specific to choice A)
- Var.A2 (specific to choice A)
- Var.B1 (specific to choice B)
- Var.B2 (specific to choice B)
- Var.C1 (specific to choice C)
- Var.C2 (specific to choice C)

The sum of shares is equal to 1.

Var.A1 and Var.A2 are specific only for the choice A. These variables 
have no potential explanation of the choice B or C.

Is there any function to estime this LOGIT in R?

Thanks for any help.

Pierre-Olivier Chasset



 
-

 
-

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Aggregate with non-scalar function

2007-11-07 Thread jim holtman
Is this closer to what you would like?

> x <- textConnection(" hostName user sys idle date time
+ 10142 fred  0.4 0.5 98.0 2007-11-01 02:02:18
+ 16886   barney  0.5 0.2 94.6 2007-10-25 19:12:12
+ 8795  fred  0.0 0.1 99.8 2007-10-30 05:08:22
+ 5261  fred  0.1 0.2 99.7 2007-10-25 07:20:32
+ 12427   barney  0.1 0.2 93.2 2007-10-19 14:34:10
+ 18067   barney  0.1 0.2 99.4 2007-10-27 10:34:08
+ 973   fred  0.0 0.2 99.8 2007-10-19 08:24:22
+ 5426  fred  0.2 0.3 99.5 2007-10-25 12:50:33
+ 7067  fred  0.1 0.2 99.4 2007-10-27 19:32:27
+ 13159   barney  0.1 0.4 84.3 2007-10-20 14:58:11
+ 17481   barney  1.2 2.0 92.6 2007-10-26 15:02:11
+ 21632   barney  0.1 0.1 99.6 2007-11-01 09:24:09
+ 206   fred 19.4 4.8 53.7 2007-10-18 06:50:34
+ 18151   barney  0.1 0.2 94.9 2007-10-27 13:22:09
+ 10662 fred  0.1 0.2 99.6 2007-11-01 19:22:27
+ 10376 fred  0.0 0.2 99.7 2007-11-01 09:50:24
+ 3630  fred 43.7 7.0 33.0 2007-10-23 00:58:27
+ 1118  fred  0.6 0.4 98.9 2007-10-19 13:14:23
+ 5122  fred  0.1 0.2 99.6 2007-10-25 02:42:21
+ 22117   barney  0.0 0.2 99.4 2007-11-02 01:34:04")
> x.in <- read.table(x, header=TRUE, as.is=TRUE)
> x.in$hour <- sapply(strsplit(x.in$time, ":"), '[', 1) # pick off the hour
> x.by <- by(x.in, list(x.in$hour, x.in$hostName), function(.host){
+ data.frame(hostName=.host$hostName[1], hour=.host$hour[1],
+   user.mean=mean(.host$user),
+   sys.mean=mean(.host$sys),
+   idle.mean=mean(.host$idle),
+   user.max=max(.host$user),
+   sys.max=max(.host$sys),
+   idle.max=max(.host$idle))
+ })
> do.call('rbind', x.by)
   hostName hour user.mean sys.mean idle.mean user.max sys.max idle.max
1barney   01  0.00 0.20 99.40  0.0 0.2 99.4
2barney   09  0.10 0.10 99.60  0.1 0.1 99.6
3barney   10  0.10 0.20 99.40  0.1 0.2 99.4
4barney   13  0.10 0.20 94.90  0.1 0.2 94.9
5barney   14  0.10 0.30 88.75  0.1 0.4 93.2
6barney   15  1.20 2.00 92.60  1.2 2.0 92.6
7barney   19  0.50 0.20 94.60  0.5 0.2 94.6
8  fred   00 43.70 7.00 33.00 43.7 7.0 33.0
9  fred   02  0.25 0.35 98.80  0.4 0.5 99.6
10 fred   05  0.00 0.10 99.80  0.0 0.1 99.8
11 fred   06 19.40 4.80 53.70 19.4 4.8 53.7
12 fred   07  0.10 0.20 99.70  0.1 0.2 99.7
13 fred   08  0.00 0.20 99.80  0.0 0.2 99.8
14 fred   09  0.00 0.20 99.70  0.0 0.2 99.7
15 fred   12  0.20 0.30 99.50  0.2 0.3 99.5
16 fred   13  0.60 0.40 98.90  0.6 0.4 98.9
17 fred   19  0.10 0.20 99.50  0.1 0.2 99.6
>


On 11/7/07, Mike Nielsen <[EMAIL PROTECTED]> wrote:
> R-Helpers,
>
> I'm sorry to have to ask this -- I've not used R very much in the last
> 8 or 10 months, and I've gotten rusty.
>
> I have the following (ff2 is a subset of a much, much larger dataset):
>
> > ff2
>  hostName user sys idle obsTime
> 10142 fred  0.4 0.5 98.0 2007-11-01 02:02:18
> 16886   barney  0.5 0.2 94.6 2007-10-25 19:12:12
> 8795  fred  0.0 0.1 99.8 2007-10-30 05:08:22
> 5261  fred  0.1 0.2 99.7 2007-10-25 07:20:32
> 12427   barney  0.1 0.2 93.2 2007-10-19 14:34:10
> 18067   barney  0.1 0.2 99.4 2007-10-27 10:34:08
> 973   fred  0.0 0.2 99.8 2007-10-19 08:24:22
> 5426  fred  0.2 0.3 99.5 2007-10-25 12:50:33
> 7067  fred  0.1 0.2 99.4 2007-10-27 19:32:27
> 13159   barney  0.1 0.4 84.3 2007-10-20 14:58:11
> 17481   barney  1.2 2.0 92.6 2007-10-26 15:02:11
> 21632   barney  0.1 0.1 99.6 2007-11-01 09:24:09
> 206   fred 19.4 4.8 53.7 2007-10-18 06:50:34
> 18151   barney  0.1 0.2 94.9 2007-10-27 13:22:09
> 10662 fred  0.1 0.2 99.6 2007-11-01 19:22:27
> 10376 fred  0.0 0.2 99.7 2007-11-01 09:50:24
> 3630  fred 43.7 7.0 33.0 2007-10-23 00:58:27
> 1118  fred  0.6 0.4 98.9 2007-10-19 13:14:23
> 5122  fred  0.1 0.2 99.6 2007-10-25 02:42:21
> 22117   barney  0.0 0.2 99.4 2007-11-02 01:34:04
>
> > doit(ff2)
>   hostName hour user.mean sys.mean idle.mean user.max sys.max idle.max
> 1barney   01  0.00 0.20 99.40  0.0 0.2 99.4
> 2barney   09  0.10 0.10 99.60  0.1 0.1 99.6
> 3barney   10  0.10 0.20 99.40  0.1 0.2 99.4
> 4barney   13  0.10 0.20 94.90  0.1 0.2 94.9
> 5barney   14  0.10 0.30 88.75  0.1 0.4 93.2
> 6barney   15  1.20 2.00 92.60  1.2 2.0 92.6
> 7barney   19  0.50 0.20 94.60  0.5 0.2 94.6
> 8  fred   00 43.70 7.00 33.00 43.7 7.0 33.0
> 9  fred   02  0.25 0.35 98.80  

[R] (no subject)

2007-11-07 Thread andrew collier
hello,

i am a bit of a statistical neophyte and currently trying to make some sense of 
confidence intervals for correlation coefficients. i am using the cor.test() 
function. the documentation is quite terse and i am having trouble tieing up 
the output from this function with stuff that i have read in the literature. 
so, for example, i make two sequences and calculate the correlation coefficient:

> x <- runif(20)
> y <- jitter(x, amount = 0.7)
> cor(x, y)
[1] 0.5198252

now i want to establish that confidence i can attach to this value. from the 
table i retrieved from the article "Understanding Correlation" by r. j. rummel 
[online] i get that the probability of a correlation coefficient of 0.5198252 
arising by chance from two sequences of length 20 is less than 0.01. so this 
seems like i can attach some significance to the result. i still don't 
understand where the table comes from and it only goes up as far as sequences 
of length 1000. the data i am wanting to analyse has length of more than 7, 
so i need to calculate these confidence levels myself. i assume that cor.test() 
is the way to do this. so i tried:

> cor.test(x, y, "greater", conf.level = 0.95)

Pearson's product-moment correlation

data:  x and y 
t = 2.5816, df = 18, p-value = 0.009405
alternative hypothesis: true correlation is greater than 0 
95 percent confidence interval:
 0.1753340 1.000 
sample estimates:
  cor 
0.5198252 

> cor.test(x, y, "less", conf.level = 0.95)

Pearson's product-moment correlation

data:  x and y 
t = 2.5816, df = 18, p-value = 0.9906
alternative hypothesis: true correlation is less than 0 
95 percent confidence interval:
 -1.000  0.7509089 
sample estimates:
  cor 
0.5198252 

> cor.test(x, y, "two.sided", conf.level = 0.95)

Pearson's product-moment correlation

data:  x and y 
t = 2.5816, df = 18, p-value = 0.01881
alternative hypothesis: true correlation is not equal to 0 
95 percent confidence interval:
 0.1003997 0.7823738 
sample estimates:
  cor 
0.5198252

i reckon that the first invocation of the function is closest to what i am 
looking for. now the rest of the output from the function is a total mystery to 
me. could anyone please tell me:

o what is a p-value?
o how to interpret the quoted confidence interval?

i do see that as i increase the conf.level input parameter to cov.test() the 
lower bound of the confidence interval gets lower:

0.95->  0.1753340 1.000
0.975   ->  0.1003997 1.000
0.995   ->  -0.04859184  1.

does this mean that with 99.5% certainty the correlation coefficient should lie 
in the range -0.04859184 to 1.? hmmm. i am doubtful. plus this doesn't 
really answer my question, which is more about what confidence i can assign to 
the measured correlation coefficient (0.5198252).

an alternative question would be: given two sequences and a calculated 
correlation coefficient, with what probability could i assert that the 
underlying processes are indeed correlated and that the calculated correlation 
coefficient does not simply arise by chance.

please forgive my ignorance. any help will be vastly appreciated. thanks!

best regards,
andrew.

--
Get a free email account with anti spam protection.
http://www.bluebottle.com/tag/2

__
R-help@r-project.org 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] R as a programming language

2007-11-07 Thread Bert Gunter
>> (Will someone here please write an O'Reilly's "Programming in R"?  :)

Someone already has ... see Venable and Ripley's S PROGRAMMING.

**However** R is more than a general purpose programming language: it is a
programming language specifically designed for data analysis -- including
statistical graphics -- and statistics. So, IMHO anyway, it's really
impossible to discuss it without reference to the data structures and
procedures underlying such tasks. Because it is targeted to do those sorts
of things well, it may handle poorly some things that general purpose
languages do well (minimizing storage with the use of references, for
example).

My own experience is that one appreciates the power and beauty of the
language and the wisdom of the designers the more one uses it in real
applications. But I am not a computer scientist and have only a limited
exposure to standard CS concepts and algorithms, to say nothing of "real"
programming experience. So just my $.02.

Best regards,

Bert Gunter
Genentech Nonclinical Statistics

__
R-help@r-project.org 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] Using R for large econometric models

2007-11-07 Thread John C Frain
I take it your friend is interested in large scale macro econometric
models involving perhaps more than a thousand equations.   The
software one would like to use might involve managing the model
database, estimating the model and simulating the model.  If the model
involves rational expectations these simulations will be very
demanding.  R would probably handle a lot of the estimation
requirements and probably most of the data management.  I do not know
of anyone that has handled the more elaborate RE simulations in R.  It
would involve considerable programming.  The only free software that
does this kind of work is the Fair-Parke program available from
http://fairmodel.econ.yale.edu/.

If the model has been set up by another person you might be advised to
use the software that the maintainers of the model use.  TROLL is
widely used in Central Banks and organisations such as the IMF ECB
etc.  It would be a fairly big job to translate a large scale macro
model from a system such as TROLL or MODELEASY or similar to another
language.

If the model is relatively small then any statistical system that can
store data, estimate structural equations and simulate them is ideal.
R would be suitable in this case.  If RE are involved you may need
special software or some programming.

Best Regards

John

On 07/11/2007, Dietrich Trenkler <[EMAIL PROTECTED]> wrote:
> Dear helpeRs,
>
> a colleague of mine would like to give R a try.  He uses econometric
> models which typically involve a large number of variables, esp. time
> series.  Having no experience with handling very large data sets myself
> I turn to you.
>
> 1. Could you please describe your experiences to cope with these
>   situations?
>
> 2. What kind of difficulties will he have to face? Are there special
>   tricks (packages) he might try?
>
> 3. Can you recommend to use R?
>
>
> Sorry, if my question is a bit vague but at this point I'm not able to
> give any further details.
>
> Any help is very much appreciated.
>
> D. Trenkler
>
> --
> Dietrich Trenkler c/o Universitaet Osnabrueck
> Rolandstr. 8; D-49069 Osnabrueck, Germany
> email: [EMAIL PROTECTED]
>
> __
> R-help@r-project.org 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.
>


-- 
John C Frain
Trinity College Dublin
Dublin 2
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]

__
R-help@r-project.org 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 please with predict.lme from nlme with nested random effects

2007-11-07 Thread Tom Cameron
Apologies for long posting but with this one I thought you would want all the 
details.
I have tried all the usual books and searched internet and R pages but I cant 
find an example of an analysis with this problem and no examples of the predict 
function being used with lme models that have nested random terms.
 
I am trying to predict the average size at maturation of the average individual 
from a random family within a 
random population that has matured at a random density. These predictions are 
based on a model that is tested against data from a an experiment looking at 
the age and size at maturation of individuals receiving different rearing food  
(food = 1 or 2), from populations of different backgrounds (env = C(constant) 
or P(periodic), har = o (unharvested) or 1(harvested)). Data copied below.
 
To do this I have built the following model using the nlme library
 
lmeS<-lme(log(size)~log(age)+env*har*food, random=~1|pop/family/density)
 
with 

pop<-as.factor(data1$pop)
family<-as.factor(data1$family)
har<-as.factor(data1$har)
env<-as.factor(data1$env)
age<-as.numeric(data1$age)
food<-as.factor(data1$food)
density<-as.numeric(data1$density)
 
There are two replicate populations for each env/har/food combination, 7 
randomaly chosen families from each and the density of the tube on the day that 
an individual matures is dependent on mortality and previous maturations( 
individuals are removed upon mauration).
This would appear to be the minimal and correct model
I then built a new data set as follows
 
envn<-rep(c("C","P"),1,each=560)
harn<-rep(c(0,1),2,each=280)
popn<-rep(c(5, 6, 11, 12, 41, 42, 47, 48),each=140)
repn<-rep(c(1,2,3,4,5,6,7),40,each=4)
foodn<-rep(c(2,1,1,1,1),8,each=28)
densn<-rep(c(5,10,15,20),280)
agen<-rep(c(5,10,15,20,25),8,each=28)
 
NB:food and age are not balanced as when food = 2(high), individuals mature 
early, when food = 1(low) they have a minimum maturation age of about 8-10 days)
I then used predict to try and capture what the expected size at maturity is 
for a given age in the two food groups, based on past evolutionary environment 
(i.e. env*har), when controlling for the random terms.
 
If I build a model with density as a fixed effect it is very significant, or if 
I just build a linear model then I get 
different size predictions at the different densities.
However, I have tried predict.lme for the same aim (see below) but density 
makes no difference to the predictions
I can either get a single output that does not vary with densities from 
"lmeSpred" or two columns of output which give me the fitted fixed effects and 
separately the fitted effects of pop, but they are identcal with lmeSpred2 or 3.
 
 
lmeSnew<-data.frame(env=factor(envn), har=factor(harn), 
pop=factor(popn),family=factor(repn),food=factor(foodn),density=densn, age=agen)
 
lmeSpred<-predict(lmeS,lmeSnew, level= 1:1,na.action=na.omit)
#or
lmeSpred2<-predict(lmeS,lmeSnew, level= 0:1,na.action=na.omit)
#or
lmeSpred3<-predict(lmeS,lmeSnew, level= 0:1/1/1,na.action=na.omit)
x<-data.frame(lmeSpred)
x

Can anyone tell me what I am doing wrong, and how I can get the predicts to 
tell me the effect of random density on size, or to give me the predicts for a 
specified control density?

data1
pop env har food family sex density size age  
5 C 0 2 1 1 18 0.823 5  
5 C 0 2 1 1 14 0.966 6  
5 C 0 2 1 1 14 0.983 6  
5 C 0 2 1 1 14 1.021 6  
5 C 0 2 1 1 14 0.776 6  
5 C 0 2 1 1 14 0.843 6  
5 C 0 2 1 1 14 0.798 6  
5 C 0 2 1 1 14 0.921 6  
5 C 0 2 2 1 20 0.821 5  
5 C 0 2 2 1 20 0.859 5  
5 C 0 2 2 1 17 0.783 6  
5 C 0 2 2 1 17 1.049 6  
5 C 0 2 2 1 17 0.930 6  
5 C 0 2 2 1 17 0.848 6  
5 C 0 2 2 1 17 0.933 6  
5 C 0 2 2 1 17 0.866 6  
5 C 0 2 2 1 1 0.938 7  
5 C 0 2 3 1 20 0.838 5  
5 C 0 2 3 1 16 0.876 6  
5 C 0 2 3 1 16 0.749 6  
5 C 0 2 3 1 16 0.932 6  
5 C 0 2 3 1 16 0.976 6  
5 C 0 2 3 1 16 0.848 6  
5 C 0 2 3 1 16 0.948 6  
5 C 0 2 3 1 16 0.849 6  
5 C 0 2 3 1 16 0.824 6  
5 C 0 2 3 1 16 0.921 6  
5 C 0 2 3 1 16 0.917 6  
5 C 0 2 4 1 20 0.996 5  
5 C 0 2 4 1 20 0.891 5  
5 C 0 2 4 1 20 1.014 5  
5 C 0 2 4 1 20 0.883 5  
5 C 0 2 4 1 20 0.883 5  
5 C 0 2 4 1 10 1.178 6  
5 C 0 2 4 1 10 1.067 6  
5 C 0 2 5 1 18 0.969 5  
5 C 0 2 5 1 18 0.892 5  
5 C 0 2 5 1 18 0.911 5  
5 C 0 2 5 1 18 0.826 5  
5 C 0 2 5 1 18 0.840 5  
5 C 0 2 5 1 9 0.958 6  
5 C 0 2 5 1 9 1.077 6  
5 C 0 2 5 1 9 1.015 6  
5 C 0 2 6 1 19 0.816 5  
5 C 0 2 6 1 19 0.925 5  
5 C 0 2 6 1 19 0.910 5  
5 C 0 2 6 1 19 0.909 5  
5 C 0 2 6 1 19 0.875 5  
5 C 0 2 6 1 19 0.910 5  
5 C 0 2 6 1 7 1.015 6  
5 C 0 2 6 1 7 0.937 6  
5 C 0 2 6 1 7 0.985 6  
5 C 0 2 7 1 14 0.922 5  
5 C 0 2 7 1 12 0.764 6  
5 C 0 2 7 1 12 0.997 6  
5 C 0 2 7 1 12 0.998 6  
5 C 0 2 7 1 12 0.870 6  
5 C 0 2 7 1 12 0.928 6  
5 C 0 2 7 1 12

Re: [R] Trouble in creating a list

2007-11-07 Thread Henrique Dallazuanna
Hi, i think that is more easy

MyList <- list(levels(Model[,colnames(Model)[2]]))
names(MyList) <- colnames(Model)[2]


On 07/11/2007, Gang Chen <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I really appreciate your help! As I'm still learning basics in R, please
> pardon my simple questions.
>
> It seems
>
> eval(parse(text=paste("MyList<-list(", colnames(Model)[2], "=",
> levels(Model[,colnames(Model)[2]]), ")")))
>
>
> is almost what I want except the following error:
> Error in eval(expr, envir, enclos) : object "M" not found
>
> Well, I tried
>
> > parse(text=paste("MyList<-list(", colnames(Model)[2], "=",
> levels(Model[,colnames(Model)[2]]), ")"))
> expression(MyList<-list( Trust = F ), MyList<-list( Trust = M ))
> attr(,"srcfile")
> 
>
> > levels(Model[,colnames(Model)[2]])
> [1] "F" "M"
>
> Is it because we need quotes around F and M for eval the command? If so,
> how can I make it work?
>
> Thanks a million,
> Gang
>
>
>
>
> On Nov 7, 2007, at 2:18 PM, Henrique Dallazuanna wrote:
>
> Try this:
>
> 1)eval(parse(text=paste("MyList<-list(", colnames(Model)[2], "=",
> Model[,colnames(Model)[2]], ")")))
>
> 2)Model[,colnames(Model)[2]]
>
> 3)MyList[[3]] <- "Teste"
>MyList[[4]] <- "Teste1"
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
> On 07/11/2007, Gang Chen <[EMAIL PROTECTED]> wrote:
> >
> >
> > I want to create a list based on the information from a data.frame,
> > Model. So I tried the following:
> >
> > MyList <- list(colnames(Model)[2] = levels(Model$(colnames(Model)[2])))
> >
> > but it failed with an error:
> >
> > Error: unexpected '=' in "list(colnames(Model)[2] ="
> >
> > I have the following problems with this command line:
> >
> > (1) I wanted to use colnames(Model)[2] as a tag for the list:
> >
> > > colnames(Model)[2]
> > [1] "gender"
> >
> > but it is not working as I intended. How to make colnames(Model)[2] a
> > legitimate tag?
> >
> > (2) Model$gender is a column in the data.frame. However Model$
> > (colnames(Model)[2]) seems not recognizable in the command line. How
> > to correct this?
> >
> > (3) How to add more tagged items to an existing list? cbind or rbind?
> >
> > Thanks in advance,
> > Gang
> >
> > __
> > R-help@r-project.org 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.
> >
>
>
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] bug in multcomp?

2007-11-07 Thread Richard M. Heiberger
The only obvious typo is the misspelling of "Tukey".  Uppercase is
necessary.
But that is not the cause of the current error.  I can't duplicate the
problem
from your description.  Look at the data.frame data_mcp.  If that doesn't
give
you the hint, then you will need to send the data to the list, the standard
"commented, minimal, self-contained, reproducible code."

Rich

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Robert Cribbie
Sent: Wednesday, November 07, 2007 12:27 PM
To: r-help@r-project.org
Subject: [R] bug in multcomp?

I am running a linear model with achiev as the outcome and major as my 
iv (5 levels). The lm statement runs fine, but for the glht command I 
get the following error. I noted that someone else asked the same 
question a while back but received no reply. I am hoping someone might 
know what is happening.

 anovaf2<-lm(achiev ~ major, data=data_mcp)
 > pairwise<- glht(anovaf2,linfct = mcp(major = "tukey"))
Error in mcp2matrix(model, linfct = linfct) :
Factor(s) major have been specified in 'linfct' but cannot be 
found in 'model'!


Any help would be much appreciated.

Rob.


-- 
Robert A. Cribbie, PhD
Department of Psychology
York University
Toronto, ONM3J 1P3
Phone: 416-736-2100 x88615
Email: [EMAIL PROTECTED]
Fax: 416-736-5814
Website: http://www.psych.yorku.ca/cribbie

__
R-help@r-project.org 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@r-project.org 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] [R-sig-ME] mixed model testing

2007-11-07 Thread John Maindonald
Whether or not you need a mixed model, e.g. random versus
fixed slopes, depends on how you intend to use results.

Suppose you have lines of depression vs lawn roller weight
calculated for a number of lawns. If the data will always be
used to make predictions for one of those same lawns, a
fixed slopes model is fine.

If you want to use the data to make a prediction for another
lawn from the same "population" (the population from which
this lawn is a random sample, right?), you need to model
the slope as a random effect.

Now for a more subtle point:

In the prediction for another lawn situation, it is possible that
the slope random effect can be zero, and analysts do very
commonly make this sort of assumption, maybe without
realizing that this is what they are doing.  You can test whether
the slope random effect is zero but, especially if you have data
from a few lawns only, failure to reject the null (zero random
effect) is not a secure basis for inferences that assume that
the slope is indeed zero. The "test for zero random effect, then
infer" is open to Box's pithy objection that
"... to make preliminary tests on variances is rather like putting to
sea in a rowing boat to find out whether conditions are sufficiently
calm for an ocean liner to leave port".


John Maindonald email: [EMAIL PROTECTED]
phone : +61 2 (6125)3473fax  : +61 2(6125)5549
Centre for Mathematics & Its Applications, Room 1194,
John Dedman Mathematical Sciences Building (Building 27)
Australian National University, Canberra ACT 0200.


On 8 Nov 2007, at 1:55 AM, Irene Mantzouni wrote:

> Is there a formal way to prove the need of a mixed model, apart from  
> e.g. comparing the intervals estimated by lmList fit?
> For example, should I compare (with AIC ML?) a model with seperately  
> (unpooled) estimated fixed slopes (i.e.using an index for each  
> group) with a model that treats this parameter as a random effect  
> (both models treat the remaining parameters as random)?
>
> Thank you!
>
> ___
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models

__
R-help@r-project.org 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] Adding submenus to existing consol GUI menu

2007-11-07 Thread simon gatehouse
If possible I would like to add two sub-menus to the R Console under 
Windows.

For example, I would like to add:
winMenuAddItem("File", "Load CSV...", "loadCSV()")
winMenuAddItem("File", "Save CSV...", "saveCSV()")

and have them appear under the initial 'File' item rather than add a new 
'File' menu item. I seem to recall from somewhere that this is 
inadvisable, however is it possible from within R and if so what might 
be the consequences of  such additions?


*Simon Gatehouse*


*Hellman & Schofield Pty Ltd*

6/3 Trelawney St., Eastwood, NSW, 2122

P.O. Box 599, Beecroft, NSW, 2119

Ph: (02) 9858 3863  Fax: (02) 9858 4057

Mb 0407 130 635  Skype s.gatehouse

__
R-help@r-project.org 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] Dealing with schema in RODBC

2007-11-07 Thread Mark Lyman
Is there a way to get a table in a certain schema? The Oracle database I am 
using has a table by the same name in two different schemas. This creates 
problems in sqlUpdate because to sqlUpdate there are duplicate columns. The 
following is part of the output of sqlColumns:

sqlColumns(eids, "TEST_ARTCL_INST")[,1:4]
   TABLE_CAT TABLE_SCHEM  TABLE_NAMECOLUMN_NAME
1   EIDS TEST_ARTCL_INST CHANNEL_ID
2   EIDS TEST_ARTCL_INSTARTICLE_TEST_ID
3   EIDS TEST_ARTCL_INST CHANNEL_OLD_ID
4   EIDS TEST_ARTCL_INSTFREQ_FM_CNT
5   EIDS TEST_ARTCL_INST  RANGE_MAX_CNT
6   EIDS TEST_ARTCL_INST  RANGE_MIN_CNT
7   EIDS TEST_ARTCL_INST   TYPE_GAGE_ID
8   EIDS TEST_ARTCL_INSTDRAWING_TYPE_ID
9   EIDS TEST_ARTCL_INST DRAWING_ID
10  EIDS TEST_ARTCL_INST RATE_SPECIFIED_CNT
11  EIDS TEST_ARTCL_INST  ACCURACY_RQRD_CNT
12  EIDS TEST_ARTCL_INSTUNIT_MSR_ID
13  EIDS_APP TEST_ARTCL_INST CHANNEL_ID
14  EIDS_APP TEST_ARTCL_INSTARTICLE_TEST_ID
15  EIDS_APP TEST_ARTCL_INST CHANNEL_OLD_ID
16  EIDS_APP TEST_ARTCL_INSTFREQ_FM_CNT
17  EIDS_APP TEST_ARTCL_INST  RANGE_MAX_CNT
18  EIDS_APP TEST_ARTCL_INST  RANGE_MIN_CNT
19  EIDS_APP TEST_ARTCL_INST   TYPE_GAGE_ID
20  EIDS_APP TEST_ARTCL_INSTDRAWING_TYPE_ID
21  EIDS_APP TEST_ARTCL_INST DRAWING_ID
22  EIDS_APP TEST_ARTCL_INST RATE_SPECIFIED_CNT
23  EIDS_APP TEST_ARTCL_INST  ACCURACY_RQRD_CNT
24  EIDS_APP TEST_ARTCL_INSTUNIT_MSR_ID

Mark Lyman

__
R-help@r-project.org 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] creating a dynamic output vector

2007-11-07 Thread Steve Powers
Let's say I have a program that returns variables whose names may be any 
string within the vector 
NAMES=c("varA","varB","varC","varD","varE","varF"..."varZ"), but I do 
not ever know which ones have actually been created. So in one example 
output, "varA", "varC", and "varD" could exist, but in another example 
output "varA", "varD", "varE",and "varF" exist, with no pattern or 
predictability (different combinations can come out, as well as 
different numbers of variables).

How do assign the output values, in pre-arranged order, into an output 
vector? The output vector for the first example would be OUTPUTS=c(varA, 
NA, varC, varD...) and the output vector for the second example would be 
OUTPUTS=c(varA, NA, NA, varD, varE, varF...).  In other words, the rows 
for all potential returned values need to be retained in the order set 
by NAMES, and the values all need to be plugged into their respective 
spot in that order if they exist. Otherwise NA is plugged in.

One other factor is that some outputs are values, but others are text. Tips?


Using R version 2.4 on Windows XP

__
R-help@r-project.org 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] R as a programming language

2007-11-07 Thread Duncan Murdoch
On 11/7/2007 7:46 AM, Alexy Khrabrov wrote:
> Greetings -- coming from Python/Ruby perspective, I'm wondering about  
> certain features of R as a programming language.

Lots of question, I'll intersperse some answers.
> 
> Say I have a huge table t of the form
> 
> run ord unitwords   new
> 1   1   69391013641
> 1   2   275 1001518
> 1   3   33141008488
> 1   4   14154   1018463
> 1   5   29821006421
> 
> Alternatively, it may have a part column in front.  For each run (in  
> a part if present), I select ord and new columns as x and y and plot  
> their functions in various ways.  t is huge.  So I want to select the  
> subset to plot, as follows:
> 
> t.xy <- function(t,part=NA,run=NA) {
>   if (is.na(run)) {
>   # TODO does this entail a full copy -- or how do we do 
> references  
> in R?
>   r <- t

Semantically it acts as a full copy, though there is some internal 
optimization that means the copy won't be made until necessary, i.e. one 
of r or t changes.

There are some kinds of objects in R that are handled as references: 
environments, external pointers, names, NULL. (I may have missed some.) 
There are various kludges to expand this list to other kinds of objects, 
the most common way being to wrap an object in an environment.  But 
there is a fond wish that people use R as a functional language and 
avoid doing this.

>   } else if (is.na(part)) {
>   r <- t[t$run == run,]
>   } else { # part present too
>   r <- t[t$part == part & t$run == run,]
>   }
>   x <- r$ord
>   y <- r$new
>   xy.coords(x,y)
> }
> 
> What I'm wondering about is whether r <-t will copy the complete t,  
> and how do I minimize copying in R.  I heard it's a functional  
> language -- is there lazy evaluation in place here?

There is lazy evaluation of function arguments, but assignments trigger 
evaluation of their RHS.

> 
> Additionally, tried to use --args command line arguments, and found a  
> way only due to David Brahm -- who helped with several important R  
> points (thanks Dave!):
> 
> #!/bin/sh
> # graph a fertility run
> tail --lines=+4 "$0" | R --vanilla --slave --args $*; exit
> args <- commandArgs()[-(1:4)]
> ...
> 
> And, still no option processing as in GNU long options, or python or  
> ruby's optparse.
> 
> What's the semantics of parameter passing -- by value or by reference?

By value.

> Is there anything less ugly than
> 
> print(paste("x=",x,"y=",y))
> 
> -- for routine printing?  Can [1] be eliminated from such simple  
> printing?  What about formatted printing?

You can use cat() instead of print(), and avoid the numbering and 
quoting.  Remember to explicitly specify a "\n" newline at the end.

At first I thought you were complaining about the syntax, which I find 
ugly.  There was a proposal last year to overload + to do concatenation 
of strings, so you'd type cat("x=" + x + "y=" + y + "\n"), but there was 
substantial resistance, on the grounds that + should be commutative.

> Is there a way to assign all of
> 
> a <- args[1]
> b <- args[2]
> c <- args[3]
> 
> in one fell swoop, a lá Python's
> 
> a,b,c = args

No, but you can do

abc <- args[1:3]
names(abc) <- c('a', 'b', 'c')

and refer to the components as abc$a, etc.

> What's the simplest way to check whether a filename ends in ".rda"?

Probably something like

if (regexpr("\\.rda$", filename) > 0) ...

You double the escape char to get it entered into the RE, and then the 
regexpr function uses it to escape the dot in the RE.

Duncan Murdoch

> Will ask more as I go programming...
> 
> (Will someone here please write an O'Reilly's "Programming in R"?  :)
> 
> Cheers,
> Alexy
> __
> R-help@r-project.org 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@r-project.org 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] Dealing with schema in RODBC

2007-11-07 Thread Marc Schwartz
On Wed, 2007-11-07 at 22:15 +, Mark Lyman wrote:
> Is there a way to get a table in a certain schema? The Oracle database I am 
> using has a table by the same name in two different schemas. This creates 
> problems in sqlUpdate because to sqlUpdate there are duplicate columns. The 
> following is part of the output of sqlColumns:
> 
> sqlColumns(eids, "TEST_ARTCL_INST")[,1:4]
>TABLE_CAT TABLE_SCHEM  TABLE_NAMECOLUMN_NAME
> 1   EIDS TEST_ARTCL_INST CHANNEL_ID
> 2   EIDS TEST_ARTCL_INSTARTICLE_TEST_ID
> 3   EIDS TEST_ARTCL_INST CHANNEL_OLD_ID
> 4   EIDS TEST_ARTCL_INSTFREQ_FM_CNT
> 5   EIDS TEST_ARTCL_INST  RANGE_MAX_CNT
> 6   EIDS TEST_ARTCL_INST  RANGE_MIN_CNT
> 7   EIDS TEST_ARTCL_INST   TYPE_GAGE_ID
> 8   EIDS TEST_ARTCL_INSTDRAWING_TYPE_ID
> 9   EIDS TEST_ARTCL_INST DRAWING_ID
> 10  EIDS TEST_ARTCL_INST RATE_SPECIFIED_CNT
> 11  EIDS TEST_ARTCL_INST  ACCURACY_RQRD_CNT
> 12  EIDS TEST_ARTCL_INSTUNIT_MSR_ID
> 13  EIDS_APP TEST_ARTCL_INST CHANNEL_ID
> 14  EIDS_APP TEST_ARTCL_INSTARTICLE_TEST_ID
> 15  EIDS_APP TEST_ARTCL_INST CHANNEL_OLD_ID
> 16  EIDS_APP TEST_ARTCL_INSTFREQ_FM_CNT
> 17  EIDS_APP TEST_ARTCL_INST  RANGE_MAX_CNT
> 18  EIDS_APP TEST_ARTCL_INST  RANGE_MIN_CNT
> 19  EIDS_APP TEST_ARTCL_INST   TYPE_GAGE_ID
> 20  EIDS_APP TEST_ARTCL_INSTDRAWING_TYPE_ID
> 21  EIDS_APP TEST_ARTCL_INST DRAWING_ID
> 22  EIDS_APP TEST_ARTCL_INST RATE_SPECIFIED_CNT
> 23  EIDS_APP TEST_ARTCL_INST  ACCURACY_RQRD_CNT
> 24  EIDS_APP TEST_ARTCL_INSTUNIT_MSR_ID
> 
> Mark Lyman

Typically, with a schema in Oracle, you use:

  schema.object

syntax. So something like (in SQL):

  select * from EIDS.TEST_ARTCL_INST;

would be different than:

  select * from EIDS_APP.TEST_ARTCL_INST;


So in RODBC, prefix any occurrence of a table name with 'SchemaName.' as
may be appropriate. The same syntax is used for views.

The nuance is that in Oracle, all users typically have a schema that is
their UserID. When you login to Oracle and just use the table name, your
current UserID schema prefix is 'implied'. 

However, if you want to access other objects within schema created by
other users, you need to explicitly use the schema prefix. You of course
also need appropriate access privileges for other schema that you have
not created.

HTH,

Marc Schwartz

__
R-help@r-project.org 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] running sum of a vector

2007-11-07 Thread Alexy Khrabrov
I need a vector with sums of vectors up to each position in the  
original.  The imperative version is simple:

# running sum: the traditional imperative way
sumr.1 <- function(x) {
   s <- c()
   ss <- 0
   for (i in 1:length(x)) {
  ss <- ss + x[i]
  s[i] <- ss
   }
   s
}

Yet I want a functional way, which is shorter:

# running sum: functional way, but inefficient one!
sumr.2 <- function(x) {
sapply(1:length(x), function(i) sum(x[1:i]))
}

-- the problem with the latter is, we need to create indices to run  
over them, and the sum is recomputed anew for each position, while  
the imperative version iterates without recomputing.  Is there a  
better functional solution?

Cheers,
Alexy

__
R-help@r-project.org 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] R as a programming language

2007-11-07 Thread Alexy Khrabrov
With all due respect to the great book -- of which I own 2 copies I  
bought new -- it's not an "O'Reilly Programming in " book.  The  
idea of a programming book like that is to thoroughly treat the  
language from a programmer's standpoint, in a fairly standard way,  
such as Ruby or Python.

As I'm learning more of statistics with R, I prefer to do it with the  
book by Crawley.  Looks like most of R books are written by  
statisticians who became programmers, not the other way.  Through all  
those years I periodically follow R, I forget its programming spirit  
in between, and there's no "Programming ..." book to help.   
Statistics is hard to forget once you master it; syntax sugar melts  
away...

"Programming with Data" is the closest to an O'Reilly, but more  
advanced and esoteric than that.

Since R became a bona fide Open Source language with CRAN and all, an  
O'Reilly book by a [Python and Ruby] programmer-turn-statistician is  
long overdue!  If it systematically compares R with Ruby and Python,  
its closest Open Source cousins, it would help even more.  RPy and  
RRb are there to help, too.  Just my $0.01...

Cheers,
Alexy

On Nov 7, 2007, at 7:46 PM, Bert Gunter wrote:

>>> (Will someone here please write an O'Reilly's "Programming in  
>>> R"?  :)
>
> Someone already has ... see Venable and Ripley's S PROGRAMMING.
>
> **However** R is more than a general purpose programming language:  
> it is a
> programming language specifically designed for data analysis --  
> including
> statistical graphics -- and statistics. So, IMHO anyway, it's really
> impossible to discuss it without reference to the data structures and
> procedures underlying such tasks. Because it is targeted to do  
> those sorts
> of things well, it may handle poorly some things that general purpose
> languages do well (minimizing storage with the use of references, for
> example).
>
> My own experience is that one appreciates the power and beauty of the
> language and the wisdom of the designers the more one uses it in real
> applications. But I am not a computer scientist and have only a  
> limited
> exposure to standard CS concepts and algorithms, to say nothing of  
> "real"
> programming experience. So just my $.02.
>
> Best regards,
>
> Bert Gunter
> Genentech Nonclinical Statistics
>

__
R-help@r-project.org 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] creating a dynamic output vector

2007-11-07 Thread Peter Alspach
Steve

Is this the sort of thing you mean?

output <- character(26)
names(output) <- paste('var', LETTERS[1:26], sep='')
output
output[paste('var', LETTERS[c(2,4,6,7,16)], sep='')] <- c(1, pi,
letters[1:3])
output 

Peter Alspach

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Steve Powers
> Sent: Thursday, 8 November 2007 11:27 a.m.
> To: r-help@r-project.org
> Subject: [R] creating a dynamic output vector
> 
> Let's say I have a program that returns variables whose names 
> may be any string within the vector 
> NAMES=c("varA","varB","varC","varD","varE","varF"..."varZ"), 
> but I do not ever know which ones have actually been created. 
> So in one example output, "varA", "varC", and "varD" could 
> exist, but in another example output "varA", "varD", 
> "varE",and "varF" exist, with no pattern or predictability 
> (different combinations can come out, as well as different 
> numbers of variables).
> 
> How do assign the output values, in pre-arranged order, into 
> an output vector? The output vector for the first example 
> would be OUTPUTS=c(varA, NA, varC, varD...) and the output 
> vector for the second example would be OUTPUTS=c(varA, NA, 
> NA, varD, varE, varF...).  In other words, the rows for all 
> potential returned values need to be retained in the order 
> set by NAMES, and the values all need to be plugged into 
> their respective spot in that order if they exist. Otherwise 
> NA is plugged in.
> 
> One other factor is that some outputs are values, but others 
> are text. Tips?
> 
> 
> Using R version 2.4 on Windows XP
> 
> __
> R-help@r-project.org 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@r-project.org 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] running sum of a vector

2007-11-07 Thread Chuck Cleland
Alexy Khrabrov wrote:
> I need a vector with sums of vectors up to each position in the  
> original.  The imperative version is simple:
> 
> # running sum: the traditional imperative way
> sumr.1 <- function(x) {
>s <- c()
>ss <- 0
>for (i in 1:length(x)) {
>   ss <- ss + x[i]
>   s[i] <- ss
>}
>s
> }
> 
> Yet I want a functional way, which is shorter:
> 
> # running sum: functional way, but inefficient one!
> sumr.2 <- function(x) {
>   sapply(1:length(x), function(i) sum(x[1:i]))
> }
> 
> -- the problem with the latter is, we need to create indices to run  
> over them, and the sum is recomputed anew for each position, while  
> the imperative version iterates without recomputing.  Is there a  
> better functional solution?

?cumsum

X <- runif(20)

sumr.1(X)
 [1] 0.6359909 0.9435293 1.2167988 1.6229179
 [5] 2.2816672 3.2687057 4.1973724 4.4421475
 [9] 4.5601287 4.7500524 5.0639924 5.5831643
[13] 6.5071247 6.9861566 7.0352500 7.6723079
[17] 7.8560394 7.9281423 8.4757938 8.9985340

sumr.2(X)
 [1] 0.6359909 0.9435293 1.2167988 1.6229179
 [5] 2.2816672 3.2687057 4.1973724 4.4421475
 [9] 4.5601287 4.7500524 5.0639924 5.5831643
[13] 6.5071247 6.9861566 7.0352500 7.6723079
[17] 7.8560394 7.9281423 8.4757938 8.9985340

cumsum(X)
 [1] 0.6359909 0.9435293 1.2167988 1.6229179
 [5] 2.2816672 3.2687057 4.1973724 4.4421475
 [9] 4.5601287 4.7500524 5.0639924 5.5831643
[13] 6.5071247 6.9861566 7.0352500 7.6723079
[17] 7.8560394 7.9281423 8.4757938 8.9985340

all(cumsum(X) == sumr.1(X))
[1] TRUE

> Cheers,
> Alexy
> 
> __
> R-help@r-project.org 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. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@r-project.org 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] running sum of a vector

2007-11-07 Thread Benilton Carvalho
x <- 1:10
cumsum(x)

b

On Nov 7, 2007, at 5:59 PM, Alexy Khrabrov wrote:

> I need a vector with sums of vectors up to each position in the
> original.  The imperative version is simple:
>
> # running sum: the traditional imperative way
> sumr.1 <- function(x) {
>   s <- c()
>   ss <- 0
>   for (i in 1:length(x)) {
>  ss <- ss + x[i]
>  s[i] <- ss
>   }
>   s
> }
>
> Yet I want a functional way, which is shorter:
>
> # running sum: functional way, but inefficient one!
> sumr.2 <- function(x) {
>   sapply(1:length(x), function(i) sum(x[1:i]))
> }
>
> -- the problem with the latter is, we need to create indices to run  
> over them, and the sum is recomputed anew for each position, while
> the imperative version iterates without recomputing.  Is there a
> better functional solution?
>
> Cheers,
> Alexy
>
> __
> R-help@r-project.org 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@r-project.org 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] R as a programming language

2007-11-07 Thread Duncan Murdoch
On 11/7/2007 8:13 AM, Duncan Murdoch wrote:
> On 11/7/2007 7:46 AM, Alexy Khrabrov wrote:
>> Greetings -- coming from Python/Ruby perspective, I'm wondering about  
>> certain features of R as a programming language.
> 
> Lots of question, I'll intersperse some answers.
>> 
>> Say I have a huge table t of the form
>> 
>> run ord unitwords   new
>> 1   1   69391013641
>> 1   2   275 1001518
>> 1   3   33141008488
>> 1   4   14154   1018463
>> 1   5   29821006421
>> 
>> Alternatively, it may have a part column in front.  For each run (in  
>> a part if present), I select ord and new columns as x and y and plot  
>> their functions in various ways.  t is huge.  So I want to select the  
>> subset to plot, as follows:
>> 
>> t.xy <- function(t,part=NA,run=NA) {
>>  if (is.na(run)) {
>>  # TODO does this entail a full copy -- or how do we do 
>> references  
>> in R?
>>  r <- t
> 
> Semantically it acts as a full copy, though there is some internal 
> optimization that means the copy won't be made until necessary, i.e. one 
> of r or t changes.
> 
> There are some kinds of objects in R that are handled as references: 
> environments, external pointers, names, NULL. (I may have missed some.) 
> There are various kludges to expand this list to other kinds of objects, 
> the most common way being to wrap an object in an environment.  But 
> there is a fond wish that people use R as a functional language and 
> avoid doing this.
> 
>>  } else if (is.na(part)) {
>>  r <- t[t$run == run,]
>>  } else { # part present too
>>  r <- t[t$part == part & t$run == run,]
>>  }
>>  x <- r$ord
>>  y <- r$new
>>  xy.coords(x,y)
>> }
>> 
>> What I'm wondering about is whether r <-t will copy the complete t,  
>> and how do I minimize copying in R.  I heard it's a functional  
>> language -- is there lazy evaluation in place here?
> 
> There is lazy evaluation of function arguments, but assignments trigger 
> evaluation of their RHS.
> 
>> 
>> Additionally, tried to use --args command line arguments, and found a  
>> way only due to David Brahm -- who helped with several important R  
>> points (thanks Dave!):
>> 
>> #!/bin/sh
>> # graph a fertility run
>> tail --lines=+4 "$0" | R --vanilla --slave --args $*; exit
>> args <- commandArgs()[-(1:4)]
>> ...
>> 
>> And, still no option processing as in GNU long options, or python or  
>> ruby's optparse.
>> 
>> What's the semantics of parameter passing -- by value or by reference?
> 
> By value.
> 
>> Is there anything less ugly than
>> 
>> print(paste("x=",x,"y=",y))
>> 
>> -- for routine printing?  Can [1] be eliminated from such simple  
>> printing?  What about formatted printing?
> 
> You can use cat() instead of print(), and avoid the numbering and 
> quoting.  Remember to explicitly specify a "\n" newline at the end.
> 
> At first I thought you were complaining about the syntax, which I find 
> ugly.  There was a proposal last year to overload + to do concatenation 
> of strings, so you'd type cat("x=" + x + "y=" + y + "\n"), but there was 
> substantial resistance, on the grounds that + should be commutative.
> 
>> Is there a way to assign all of
>> 
>> a <- args[1]
>> b <- args[2]
>> c <- args[3]
>> 
>> in one fell swoop, a lá Python's
>> 
>> a,b,c = args
> 
> No, but you can do
> 
> abc <- args[1:3]
> names(abc) <- c('a', 'b', 'c')

Oops, this code assumed that args was a list already, and I think yours 
was a character vector.  In that case you'd need

abc <- as.list(args[1:3])

on the first line.

> 
> and refer to the components as abc$a, etc.
> 
>> What's the simplest way to check whether a filename ends in ".rda"?
> 
> Probably something like
> 
> if (regexpr("\\.rda$", filename) > 0) ...
> 
> You double the escape char to get it entered into the RE, and then the 
> regexpr function uses it to escape the dot in the RE.
> 
> Duncan Murdoch
> 
>> Will ask more as I go programming...
>> 
>> (Will someone here please write an O'Reilly's "Programming in R"?  :)
>> 
>> Cheers,
>> Alexy
>> __
>> R-help@r-project.org 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@r-project.org 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] vectorize a list

2007-11-07 Thread Moshe Olshansky
Stack does not work for me either, but unlist works,
i.e.
unlist(l)

--- Frank Schmid <[EMAIL PROTECTED]> wrote:

> Dear R user
> 
> Suppose I have the following list:
> 
>  > f <- rnorm(2)
>  > s <- rnorm(3)
>  > l <- list(f,s)
>  > l
> [[1]]
> [1] 0.31784399 0.08575421
> 
> [[2]]
> [1] -0.6191679  0.7615479 -1.0087659
> 
> 
> Can I stack the entries of this list in 1 vector
> with the first list 
> entry followed by the second? The reference manual
> says that I can use 
> the command /stack/, which can take as arguments
> either a list or a data 
> frame. But taking simply /stack(l)/ does not work,
> although it is a list.
> 
> Many thanks for your hint
> 
> Frank Schmid
> 
> __
> R-help@r-project.org 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@r-project.org 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] R as a programming language

2007-11-07 Thread Simon Blomberg
Although Crawley is an ecologist, not a programmer or statistician. But
he is an FRS. Maybe that counts for something. ;-)

Simon.

On Thu, 2007-11-08 at 01:56 +0300, Alexy Khrabrov wrote:
> With all due respect to the great book -- of which I own 2 copies I  
> bought new -- it's not an "O'Reilly Programming in " book.  The  
> idea of a programming book like that is to thoroughly treat the  
> language from a programmer's standpoint, in a fairly standard way,  
> such as Ruby or Python.
> 
> As I'm learning more of statistics with R, I prefer to do it with the  
> book by Crawley.  Looks like most of R books are written by  
> statisticians who became programmers, not the other way.  Through all  
> those years I periodically follow R, I forget its programming spirit  
> in between, and there's no "Programming ..." book to help.   
> Statistics is hard to forget once you master it; syntax sugar melts  
> away...
> 
> "Programming with Data" is the closest to an O'Reilly, but more  
> advanced and esoteric than that.
> 
> Since R became a bona fide Open Source language with CRAN and all, an  
> O'Reilly book by a [Python and Ruby] programmer-turn-statistician is  
> long overdue!  If it systematically compares R with Ruby and Python,  
> its closest Open Source cousins, it would help even more.  RPy and  
> RRb are there to help, too.  Just my $0.01...
> 
> Cheers,
> Alexy
> 
> On Nov 7, 2007, at 7:46 PM, Bert Gunter wrote:
> 
> >>> (Will someone here please write an O'Reilly's "Programming in  
> >>> R"?  :)
> >
> > Someone already has ... see Venable and Ripley's S PROGRAMMING.
> >
> > **However** R is more than a general purpose programming language:  
> > it is a
> > programming language specifically designed for data analysis --  
> > including
> > statistical graphics -- and statistics. So, IMHO anyway, it's really
> > impossible to discuss it without reference to the data structures and
> > procedures underlying such tasks. Because it is targeted to do  
> > those sorts
> > of things well, it may handle poorly some things that general purpose
> > languages do well (minimizing storage with the use of references, for
> > example).
> >
> > My own experience is that one appreciates the power and beauty of the
> > language and the wisdom of the designers the more one uses it in real
> > applications. But I am not a computer scientist and have only a  
> > limited
> > exposure to standard CS concepts and algorithms, to say nothing of  
> > "real"
> > programming experience. So just my $.02.
> >
> > Best regards,
> >
> > Bert Gunter
> > Genentech Nonclinical Statistics
> >
> 
> __
> R-help@r-project.org 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.
-- 
Simon Blomberg, BSc (Hons), PhD, MAppStat. 
Lecturer and Consultant Statistician 
Faculty of Biological and Chemical Sciences 
The University of Queensland 
St. Lucia Queensland 4072 
Australia
Room 320 Goddard Building (8)
T: +61 7 3365 2506 
email: S.Blomberg1_at_uq.edu.au

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

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.

__
R-help@r-project.org 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] R as a programming language

2007-11-07 Thread Dale Steele
I'm anxiously awaiting my copy of the soon to be published  "A First
Course in Statistical Programming with R"  by
W. John Braun
University of Western Ontario
Duncan J. Murdoch
University of Western Ontario
Paperback
 (ISBN-13: 9780521694247)

http://www.cambridge.org/catalogue/catalogue.asp?isbn=9780521694247

On 11/7/07, Alexy Khrabrov <[EMAIL PROTECTED]> wrote:
> With all due respect to the great book -- of which I own 2 copies I

__
R-help@r-project.org 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] creating a dynamic output vector

2007-11-07 Thread Steve Powers
Not exactly. That doesn't work for me. Because I don't actually know 
what variables are created each time I run the program, I don't have an 
easy way to call all the ones I need at once (which your suggestion 
appears to require). But I do have a list of names for all the variables 
I want. We need to match based on variable names I think.

Note that elements of NAMES correspond to exact variables, but with 
quotes around them.

If I just knew how to tell R to call NAMES[1], NAMES[2], NAMES[3] etc., 
but without quotes (so that the variable itself is called, rather than 
the header string), that might work. But when NAMES[1]="varA," the code
/
noquote(NAMES[1])/

literally returns /varA/, rather than the desired value/string that 
comes out when I manually type the code varA. Weird.---steve




Peter Alspach wrote:
> Steve
>
> Is this the sort of thing you mean?
>
> output <- character(26)
> names(output) <- paste('var', LETTERS[1:26], sep='')
> output
> output[paste('var', LETTERS[c(2,4,6,7,16)], sep='')] <- c(1, pi,
> letters[1:3])
> output 
>
> Peter Alspach
>
>   
>> -Original Message-
>> From: [EMAIL PROTECTED] 
>> [mailto:[EMAIL PROTECTED] On Behalf Of Steve Powers
>> Sent: Thursday, 8 November 2007 11:27 a.m.
>> To: r-help@r-project.org
>> Subject: [R] creating a dynamic output vector
>>
>> Let's say I have a program that returns variables whose names 
>> may be any string within the vector 
>> NAMES=c("varA","varB","varC","varD","varE","varF"..."varZ"), 
>> but I do not ever know which ones have actually been created. 
>> So in one example output, "varA", "varC", and "varD" could 
>> exist, but in another example output "varA", "varD", 
>> "varE",and "varF" exist, with no pattern or predictability 
>> (different combinations can come out, as well as different 
>> numbers of variables).
>>
>> How do assign the output values, in pre-arranged order, into 
>> an output vector? The output vector for the first example 
>> would be OUTPUTS=c(varA, NA, varC, varD...) and the output 
>> vector for the second example would be OUTPUTS=c(varA, NA, 
>> NA, varD, varE, varF...).  In other words, the rows for all 
>> potential returned values need to be retained in the order 
>> set by NAMES, and the values all need to be plugged into 
>> their respective spot in that order if they exist. Otherwise 
>> NA is plugged in.
>>
>> One other factor is that some outputs are values, but others 
>> are text. Tips?
>>
>>
>> Using R version 2.4 on Windows XP
>>
>> __
>> R-help@r-project.org 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@r-project.org 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] Mixing lty specifications in legend

2007-11-07 Thread Peter Dunn
Hi all

I have a plot with lines, one specified as (say) lty=1, 
using standard line types, and another as (say) my
own spec: lty="51".

I can't get  legend  to display both.  Toy example:


> plot(1~1)
> legend("topright", lty=c("51",1), legend=c("My own","Standard"))
Error in segments(x1, y1, x2, y2, ...) : invalid line type: must be
length 2, 4, 6 or 8
>


Any ideas?

P.

> sessionInfo()
R version 2.5.0 (2007-04-23) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MON
ETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252

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

other attached packages:
car  xtable statmod 
"1.2-2" "1.5-1" "1.3.1" 





Dr Peter Dunn  (USQ CRICOS No. 00244B)
  Web:http://www.sci.usq.edu.au/staff/dunn
  Email:  dunn @ usq.edu.au
  ACSC:  http://www.usq.edu.au/acsc

This email (including any attached files) is confidentia...{{dropped:15}}

__
R-help@r-project.org 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] Homework help: t test hypothesis testing with summarized data?

2007-11-07 Thread Peter Dalgaard
Zembower, Kevin wrote:
> Is this how a t hypothesis test is done when I don't have the actual
> data, but just the summarized statistics: 
>   
>> #Homework 9.2.6 [1]
>> n<-31
>> xbar<-3.10
>> s_x<-1.469
>> m<-57
>> ybar<-2.43
>> s_y<-1.35
>> s_pooled<- (((n-1)*s_x^2) + ((m-1)*s_y^2)) / (n + m - 2)
>> s_pooled
>> 
> [1] 1.939521
>   
>> t_obs <- (xbar -  ybar) / (s_pooled * (sqrt(1/n + 1/m)))
>> t_obs
>> 
> [1] 1.547951
>   
>> qt(c(.025, .975), n+m-2)
>> 
> [1] -1.987934  1.987934
>   
>> # Therefore, fail to reject H0 at the 0.05 level of significance
>>
>> 
>
> Or am I again overlooking a canned procedure or an easier calculation
> using the t distribution.
>   
I don't know if someone told you last time, but there's an Internet code 
of honor about helping with homework Don't expect more than hints.

You're on track but there's a mistake.

Here's a way of testing your result:

 > x <- scale(rnorm(31))*1.469+3.10
 > y <- scale(rnorm(57))*1.35+2.43
 > t.test(x,y, var.equal=TRUE)




> Thank you for your continued advice and help.
>
> -Kevin
>
> [1] An Introduction to Mathematical Statistics and its Applications,
> fourth ed., Larsen and Marx.
>
> Kevin Zembower
> Internet Services Group manager
> Center for Communication Programs
> Bloomberg School of Public Health
> Johns Hopkins University
> 111 Market Place, Suite 310
> Baltimore, Maryland  21202
> 410-659-6139 
>
> __
> R-help@r-project.org 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.
>   


-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@r-project.org 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] analysis of 2x2 tables of various designs

2007-11-07 Thread Max Moldovan
Dear Colleagues,

 

Could you recommend a package of combination of functions in R for
analysis of 2x2 tables of various designs. Preferably it should include
tests and confidence limits (both exact and approximate) for alternative
designs, such as independent proportions (e.g. parallel group clinical
trials) and correlated proportions (matched pairs and crossover
studies).

 

Many thanks

 

MM

 


--
___



Notice from Melbourne Business School Ltd 


The information contained in this e-mail is confidential...{{dropped:27}}

__
R-help@r-project.org 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] a newbie question about "data"

2007-11-07 Thread Bill.Venables
The book came out in 2002 and a lot has happened with R in the time since then. 
 In particular it is now possible for R to have 'lazy loading' of objects.  If 
the person setting up the package has used this option (as they all now 
should), when the package is loaded R essentially is made aware that the data 
(and other) objects are there, so it is visible, but it is only read into 
memory if it is used.  The little tag that alerts R to the existence of the 
object and triggers the automatic loading on demand is called a 'promise' and 
the action itself is called a 'delayed assign'.

Previously this all had to be done manually.  data() could be used either to 
discover what data objects were available in packages, or to load them in to 
memory.  Many old-style packages still require you to do this.  There are cases 
where it is justified, I suppose, but they are quite hard to think of...
 
With R you have to keep abreast of developments, and it's all happening pretty 
fast.
 
Bill Venables.
 
PS Since you are new to R, it is not considered very friendly to send messages 
to the R groups anonymously.  


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile: +61 4 8819 4402
Home Phone: +61 7 3286 7700
mailto:[EMAIL PROTECTED]  
http://www.cmis.csiro.au/bill.venables/ 
 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]  ] 
On Behalf Of envisage
Sent: Thursday, 8 November 2007 1:27 PM
To: r-help@r-project.org
Subject: [R] a newbie question about "data"

hi, I am reading Modern Applied Statistics with S 4th ed。
page4 have these two lines:
> library(MASS)
> data(chem) # needed in R only
 but I find withou the line " data(chem)"
I can still access chem, isn't it?
is it unnecessary or something i missed here?
thanks for the replay in advance.

__
R-help@r-project.org 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] creating a dynamic output vector

2007-11-07 Thread Ben Bolker



Steve Powers wrote:
> 
> Not exactly. That doesn't work for me. Because I don't actually know 
> what variables are created each time I run the program, I don't have an 
> easy way to call all the ones I need at once (which your suggestion 
> appears to require). But I do have a list of names for all the variables 
> I want. We need to match based on variable names I think.
> 
> Note that elements of NAMES correspond to exact variables, but with 
> quotes around them.
> 
> If I just knew how to tell R to call NAMES[1], NAMES[2], NAMES[3] etc., 
> but without quotes (so that the variable itself is called, rather than 
> the header string), that might work. But when NAMES[1]="varA," the code
> /
> noquote(NAMES[1])/
> 
> literally returns /varA/, rather than the desired value/string that 
> comes out when I manually type the code varA. Weird.---steve
> 
> 
> 
> 
> Peter Alspach wrote:
>> Steve
>>
>> Is this the sort of thing you mean?
>>
>> output <- character(26)
>> names(output) <- paste('var', LETTERS[1:26], sep='')
>> output
>> output[paste('var', LETTERS[c(2,4,6,7,16)], sep='')] <- c(1, pi,
>> letters[1:3])
>> output 
>>
>> Peter Alspach
>>
>>   
>>> -Original Message-
>>> From: [EMAIL PROTECTED] 
>>> [mailto:[EMAIL PROTECTED] On Behalf Of Steve Powers
>>> Sent: Thursday, 8 November 2007 11:27 a.m.
>>> To: r-help@r-project.org
>>> Subject: [R] creating a dynamic output vector
>>>
>>> Let's say I have a program that returns variables whose names 
>>> may be any string within the vector 
>>> NAMES=c("varA","varB","varC","varD","varE","varF"..."varZ"), 
>>> but I do not ever know which ones have actually been created. 
>>> So in one example output, "varA", "varC", and "varD" could 
>>> exist, but in another example output "varA", "varD", 
>>> "varE",and "varF" exist, with no pattern or predictability 
>>> (different combinations can come out, as well as different 
>>> numbers of variables).
>>>
>>> How do assign the output values, in pre-arranged order, into 
>>> an output vector? The output vector for the first example 
>>> would be OUTPUTS=c(varA, NA, varC, varD...) and the output 
>>> vector for the second example would be OUTPUTS=c(varA, NA, 
>>> NA, varD, varE, varF...).  In other words, the rows for all 
>>> potential returned values need to be retained in the order 
>>> set by NAMES, and the values all need to be plugged into 
>>> their respective spot in that order if they exist. Otherwise 
>>> NA is plugged in.
>>>
>>> One other factor is that some outputs are values, but others 
>>> are text. Tips?
>>>
>>>
>>> Using R version 2.4 on Windows XP
>>>
>>> __
>>> R-help@r-project.org 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@r-project.org 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.
> 
> 

?get

-- 
View this message in context: 
http://www.nabble.com/creating-a-dynamic-output-vector-tf4767812.html#a13641002
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] creating a dynamic output vector

2007-11-07 Thread Rolf Turner

On 8/11/2007, at 3:00 PM, Steve Powers wrote:

> Everyone is assuming I know what the output data are, or that they  
> come
> out from my model in some easily called vector. But I don't, and  
> they do
> not. The outputs are hidden, and all are separate variables that  
> need to
> be called. Also which ones come out after a given run will vary each
> time. All I have to reference the desired output variables are the  
> names
> of every POTENTIAL output in character format, all in one vector.

This doesn't make a lot of sense.  What does ``The outputs are
hidden'' mean?  What does ``all are separate variables'' mean?
What does ``that need to be *called*'' (emphasis mine) mean?

It sounds as if you have software (a script?) that is creating global
variables in your workspace rather than a function returning a list.
This is bad practice and makes it hard to use the beautiful  
facilities of R.

BTW you cannot mix types in a single *vector*; if you have scalars
of different types (numeric and character) and you want to store
them in a single object, you have to use a *list* rather than a
vector.

If you have a subset of varA, ..., varZ as global variables in your
workspace, you can put them into a *list* of length 26, in the
proper slots as follows:

nms <- paste("var",LETTERS,sep="")
res <- lapply(nms,function(x){if(exists(x)) get(x) else NA})

I emphasize however that if this is indeed your approach it is bad
and dangerous programming.

> In any event, if anyone knows how to simply put all workspace variable
> names into one character vector, and their values/strings in another
> vector, that should work and I could take it from there (all I need  
> are
> the one element variables, not vectors or data frames). Initially I
> messed around for awhile with ls() and ls.str() with no luck. Can't  
> get
> those data into a useful format.

To put ***all*** the names of all variables in a workspace into
a character vector, you use ls()!!! (Like, I mean, huh?)

You ***cannot*** put ``their values'' into another ***vector***
unless they are all scalars of the same type.  You can (easily)
put their values into a list:

all.nms <- ls()
all.res <- lapply(all.nms,get)

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org 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] Adding submenus to existing consol GUI menu

2007-11-07 Thread Gabor Grothendieck
You could try deleting all the existing menus and then recreating them in
the way you want.  I believe that once worked although I haven't tried it
recently.

On Nov 7, 2007 4:14 PM, simon gatehouse <[EMAIL PROTECTED]> wrote:
> If possible I would like to add two sub-menus to the R Console under
> Windows.
>
> For example, I would like to add:
> winMenuAddItem("File", "Load CSV...", "loadCSV()")
> winMenuAddItem("File", "Save CSV...", "saveCSV()")
>
> and have them appear under the initial 'File' item rather than add a new
> 'File' menu item. I seem to recall from somewhere that this is
> inadvisable, however is it possible from within R and if so what might
> be the consequences of  such additions?
>
>
>*Simon Gatehouse*
>
>
>*Hellman & Schofield Pty Ltd*
>
> 6/3 Trelawney St., Eastwood, NSW, 2122
>
> P.O. Box 599, Beecroft, NSW, 2119
>
> Ph: (02) 9858 3863  Fax: (02) 9858 4057
>
> Mb 0407 130 635  Skype s.gatehouse
>
> __
> R-help@r-project.org 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@r-project.org 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] a newbie question about "data"

2007-11-07 Thread Prof Brian Ripley

A lot of those changes are of course in the on-line Errata at
http://www.stats.ox.ac.uk/pub/MASS4/Errata4.1 . E.g.

R Changes
=

p.12  As from R 1.7.0 data() is not needed for our datasets, but it
  is needed for R's own datasets  ability.cov, iris3  and swiss
  prior to R 2.0.0.


On Thu, 8 Nov 2007, [EMAIL PROTECTED] wrote:


The book came out in 2002 and a lot has happened with R in the time since then. 
 In particular it is now possible for R to have 'lazy loading' of objects.  If 
the person setting up the package has used this option (as they all now 
should), when the package is loaded R essentially is made aware that the data 
(and other) objects are there, so it is visible, but it is only read into 
memory if it is used.  The little tag that alerts R to the existence of the 
object and triggers the automatic loading on demand is called a 'promise' and 
the action itself is called a 'delayed assign'.

Previously this all had to be done manually.  data() could be used either to 
discover what data objects were available in packages, or to load them in to 
memory.  Many old-style packages still require you to do this.  There are cases 
where it is justified, I suppose, but they are quite hard to think of...

With R you have to keep abreast of developments, and it's all happening pretty 
fast.

Bill Venables.

PS Since you are new to R, it is not considered very friendly to send messages 
to the R groups anonymously.


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile: +61 4 8819 4402
Home Phone: +61 7 3286 7700
mailto:[EMAIL PROTECTED] 
http://www.cmis.csiro.au/bill.venables/ 


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]  ] 
On Behalf Of envisage
Sent: Thursday, 8 November 2007 1:27 PM
To: r-help@r-project.org
Subject: [R] a newbie question about "data"

hi, I am reading Modern Applied Statistics with S 4th ed¡£
page4 have these two lines:

library(MASS)
data(chem) # needed in R only

but I find withou the line " data(chem)"
I can still access chem, isn't it?
is it unnecessary or something i missed here?
thanks for the replay in advance.




--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org 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] a newbie question about "data"

2007-11-07 Thread envisage
thanks for the detailed info.
and sorry for the anonymously posting(may be subscripted with another
email account, i can't specify which one is, now i subscript r-help
mail list with this mail account).
On Nov 8, 2007 12:48 PM,  <[EMAIL PROTECTED]> wrote:
> The book came out in 2002 and a lot has happened with R in the time since 
> then.  In particular it is now possible for R to have 'lazy loading' of 
> objects.  If the person setting up the package has used this option (as they 
> all now should), when the package is loaded R essentially is made aware that 
> the data (and other) objects are there, so it is visible, but it is only read 
> into memory if it is used.  The little tag that alerts R to the existence of 
> the object and triggers the automatic loading on demand is called a 'promise' 
> and the action itself is called a 'delayed assign'.
>
> Previously this all had to be done manually.  data() could be used either to 
> discover what data objects were available in packages, or to load them in to 
> memory.  Many old-style packages still require you to do this.  There are 
> cases where it is justified, I suppose, but they are quite hard to think of...
>
> With R you have to keep abreast of developments, and it's all happening 
> pretty fast.
>
> Bill Venables.
>
> PS Since you are new to R, it is not considered very friendly to send 
> messages to the R groups anonymously.
>
>
> Bill Venables
> CSIRO Laboratories
> PO Box 120, Cleveland, 4163
> AUSTRALIA
> Office Phone (email preferred): +61 7 3826 7251
> Fax (if absolutely necessary):  +61 7 3826 7304
> Mobile: +61 4 8819 4402
> Home Phone: +61 7 3286 7700
> mailto:[EMAIL PROTECTED] 
> http://www.cmis.csiro.au/bill.venables/ 
> 
>
>
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]  
> ] On Behalf Of envisage
> Sent: Thursday, 8 November 2007 1:27 PM
> To: r-help@r-project.org
> Subject: [R] a newbie question about "data"
>
> hi, I am reading Modern Applied Statistics with S 4th ed。
> page4 have these two lines:
> > library(MASS)
> > data(chem) # needed in R only
>  but I find withou the line " data(chem)"
> I can still access chem, isn't it?
> is it unnecessary or something i missed here?
> thanks for the replay in advance.
>
>
> __
> R-help@r-project.org 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@r-project.org 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] creating a dynamic output vector

2007-11-07 Thread Bert Gunter
?match  I think is what you're after. e.g.

x <- letters[1:10]
y <- c("b","f")

x[match(x,y)]

 


Bert Gunter
Genentech Nonclinical Statistics


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Peter Alspach
Sent: Wednesday, November 07, 2007 2:41 PM
To: Steve Powers; r-help@r-project.org
Subject: Re: [R] creating a dynamic output vector

Steve

Is this the sort of thing you mean?

output <- character(26)
names(output) <- paste('var', LETTERS[1:26], sep='')
output
output[paste('var', LETTERS[c(2,4,6,7,16)], sep='')] <- c(1, pi,
letters[1:3])
output 

Peter Alspach

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Steve Powers
> Sent: Thursday, 8 November 2007 11:27 a.m.
> To: r-help@r-project.org
> Subject: [R] creating a dynamic output vector
> 
> Let's say I have a program that returns variables whose names 
> may be any string within the vector 
> NAMES=c("varA","varB","varC","varD","varE","varF"..."varZ"), 
> but I do not ever know which ones have actually been created. 
> So in one example output, "varA", "varC", and "varD" could 
> exist, but in another example output "varA", "varD", 
> "varE",and "varF" exist, with no pattern or predictability 
> (different combinations can come out, as well as different 
> numbers of variables).
> 
> How do assign the output values, in pre-arranged order, into 
> an output vector? The output vector for the first example 
> would be OUTPUTS=c(varA, NA, varC, varD...) and the output 
> vector for the second example would be OUTPUTS=c(varA, NA, 
> NA, varD, varE, varF...).  In other words, the rows for all 
> potential returned values need to be retained in the order 
> set by NAMES, and the values all need to be plugged into 
> their respective spot in that order if they exist. Otherwise 
> NA is plugged in.
> 
> One other factor is that some outputs are values, but others 
> are text. Tips?
> 
> 
> Using R version 2.4 on Windows XP
> 
> __
> R-help@r-project.org 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@r-project.org 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@r-project.org 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.


  1   2   >