[R] Page's trend test?

2004-05-26 Thread Vaclav Petricek

Hello

Is there an R implementation of the "Page's trend test" as described
in http://en.wikipedia.org/wiki/Page%27s_trend_test or something
equivalent?

Thanks for your help,

Vaclav

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


[R] xyplot inside a for loop problem

2004-03-25 Thread Vaclav Petricek

Hello everyone

Could someone please explain me why are xyplot() calls inside a for loop
unsuccessful?

Calling plot() is OK but xyplot() just opens the graphics window and that
is all. No error, no warning :-( The same xyplot() outside for loop works
fine.

-
library(lattice)

# OK:
plot(1,2,type='p',main='standalone plot')
# OK:
for (name in 1) plot(1,2,type='p',main='plot in for')

# OK:
xyplot(1~2,type='p',main='standalone xyplot')
# This does not plot anything:
for (name in 1) xyplot(1~2,type='p',main='xyplot in for')
-

Thank you very much for your help

Vaclav

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


Re: [R] how to fix a factor

2004-03-19 Thread Vaclav Petricek
On Fri, 19 Mar 2004, Giampiero Salvi wrote:

> Hi all,
> I created a data frame with three factors, plus the response that
> looks like this:
>
> x1x2  x3  y
> a 1   1   0.3
> a 2   1   0.1
> b 1   1   0.4
> c 4   3   0.1
> ...
>
> I would like to analise the effect of two of them, keeping the third fixed
> (I already know the effect of the last). The reason why I don't create several
> data frames for each value of the thirs factor is simply convenience (I'd like
> to be able to decide which factor I want to rule out)
>
> for example I'd like to write something like
>
> boxplot(y ~ x1 + x2, x3 == 1)
>
> which of course doesn't work, otherwise I wouldn't write :-)
>
> Is this possible and how?

?boxplot

The subset parameter of boxplot might be what you are looking for.

Vaclav

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


Re: [R] Draw abbreviated key (lattice, xyplot)

2004-03-19 Thread Vaclav Petricek

Deepayan,

> Both auto.key and simpleKey are convenience tools to make key drawing
> easy in 'typical' cases. For more flexibility, define the key as a list
> (the structure is described under 'key' in ?xyplot). You may want to
> look at ?Rows as well, in conjunction with trellis.par.get().
> See ?splom and ?cloud for examples.
>
> You are not very explicit in your description, but perhaps your only
> problem with your second solution is that the first 5 levels are in
> alphabetical order (but you haven't said what order you want them to be
> in). This is an artifact of R's factor() function, where the levels are
> by default
>
>  factor(x, levels = sort(unique.default(x), na.last = TRUE), ...
>
> So your problem may be solved simply by redefining your country variable
> appropriately:
>
> yourdata$country <-
> factor(as.character(yourdata$country),
>levels = c('USA', 'Germany', < ... >))
>
> (the as.character() is probably redundant)

Thank you very much - this solves my problem. Putting the countries of
interest first has two benefits
  a) different colors are assigned to them
  b) including just first n of them in the key using simpleKey is easy

As I am more used a little different notation to construct the levels in
the order I want.

t<-transform(t,country=factor(country,
   levels=unique(c(subset(country,year==1997),unique(country)

where

  subset(country,year==1997) are the countries I want to be first
  unique(country) after that ensures that I include all the countries and
  no NAs are introduced

This is how I plot the abbreviated key then

attach(t)
xyplot(papers~year, groups=country, type='l',
   key=simpleKey(levels(country)[1:10],columns=2,lines=T,points=F))

Thanks again,

Vaclav


> Hope that helps,
>
> Deepayan
>
> On Thursday 18 March 2004 09:42, Vaclav Petricek wrote:
> > Hello
> >
> > I have been experimenting with xyplot, reading the help and googling
> > but I am still unable to draw an abbreviated key.
> >
> > I would like to display key for a few particular countries.
> >
> > My dataset looks like this
> >
> >year paperscountry papers.total
> > 1  1988403USA  551
> > 2  1988 31 United Kingdom  551
> > 3  1988 24 Canada  551
> > 4  1988 20Netherlands  551
> > 5  1988 19 Israel  551
> > 6  1988 16Germany  551
> > 7  1988 13 France  551
> > 8  1988 10  Italy  551
> > 9  1988  8Switzerland  551
> > 10 1988  5  Japan  551
> > 11 1988  5Denmark  551
> > 12 1988  3  Spain  551
> > 13 1988  3 Russia  551
> > 14 1988  2 Sweden  551
> > 15 1988  2 Poland  551
> > 16 1988  2Finland  551
> > 17 1988  2 Brasil  551
> > 18 1988  2  Australia  551
> > 19 1988  1   Thailand  551
> > 20 1988  1 Norway  551
> > 21 1988  1 Mexico  551
> > 22 1988  1Ireland  551
> > 23 1988  1 Greece  551
> > 24 1989649USA  926
> > 25 1989 53 United Kingdom  926
> > 26 1989 43 France  926
> > 27 1989 37 Canada  926
> > 28 1989 36Germany  926
> > 29 1989 28Netherlands  926
> > 30 1989 19 Sweden  926
> > [...]
> >
> > I use xyplot to show how many papers
> >
> > > xyplot(papers~year,groups=country,type='l',auto.key=T)
> >
> > produces an extremely long key
> >
> > > xyplot(papers~year,groups=country,type='l',key=simpleKey(levels(as.
> > >factor(country))[1:5]))
> >
> > shows *alphabetically* first five countries in the key
> >
> > > xyplot(papers~year,groups=country,type='l',key=simpleKey(c('USA','G
> > >ermany')))
> >
> > displays correct countries but the colors obviously do not match.
> >
> > Could you please point me in the right direction?
> >
> > Vaclav
> >
> > __
> > [EMAIL PROTECTED] mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
>

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


[R] Draw abbreviated key (lattice, xyplot)

2004-03-18 Thread Vaclav Petricek

Hello

I have been experimenting with xyplot, reading the help and googling but
I am still unable to draw an abbreviated key.

I would like to display key for a few particular countries.

My dataset looks like this

   year paperscountry papers.total
1  1988403USA  551
2  1988 31 United Kingdom  551
3  1988 24 Canada  551
4  1988 20Netherlands  551
5  1988 19 Israel  551
6  1988 16Germany  551
7  1988 13 France  551
8  1988 10  Italy  551
9  1988  8Switzerland  551
10 1988  5  Japan  551
11 1988  5Denmark  551
12 1988  3  Spain  551
13 1988  3 Russia  551
14 1988  2 Sweden  551
15 1988  2 Poland  551
16 1988  2Finland  551
17 1988  2 Brasil  551
18 1988  2  Australia  551
19 1988  1   Thailand  551
20 1988  1 Norway  551
21 1988  1 Mexico  551
22 1988  1Ireland  551
23 1988  1 Greece  551
24 1989649USA  926
25 1989 53 United Kingdom  926
26 1989 43 France  926
27 1989 37 Canada  926
28 1989 36Germany  926
29 1989 28Netherlands  926
30 1989 19 Sweden  926
[...]

I use xyplot to show how many papers

> xyplot(papers~year,groups=country,type='l',auto.key=T)

produces an extremely long key

> xyplot(papers~year,groups=country,type='l',key=simpleKey(levels(as.factor(country))[1:5]))

shows *alphabetically* first five countries in the key

> xyplot(papers~year,groups=country,type='l',key=simpleKey(c('USA','Germany')))

displays correct countries but the colors obviously do not match.

Could you please point me in the right direction?

Vaclav

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


[R] reshape direction=wide

2004-02-19 Thread Vaclav Petricek

Hello

I am reshaping a data.frame bids --> reshaped as shown below.

I thought this should be possible with a single invocation of
reshape, but the only way I came up with is reshaping subsets for each
keyword and then joining them together. Does anyone have an idea how to
solve this in a more elegant way? Efficiency is a concern as the datasets
are very large.

Is there a way to specify multiple v.names?

bids
batch keyword rankid  bid
1   312221627   Broadband1 401173481 2.64
2   312221627   Broadband2 236096320 2.63
3   312221627   Broadband3 367411639 2.62
4   312221627   Broadband4 188906982 2.61
5   312221627   Broadband5 227691359 2.01
205 312221627 Outsourcing1 406300683 3.68
206 312221627 Outsourcing2  12862485 3.65
207 312221627 Outsourcing3 237944232 3.65
208 312221627 Outsourcing4  95867634 3.64

reshaped
   batch   keyword bid.1 bid.2 bid.3 bid.4 bid.5  id.1  id.2  id.3 
 id.4  id.5
1  312221608 Broadband  2.63  2.62  2.62  2.61  2.01 236096320 401173481 367411639 
188906982 227691359
2  312221617 Broadband  2.64  2.63  2.62  2.61  2.01 401173481 236096320 367411639 
188906982 227691359
3  312221627 Broadband  2.64  2.63  2.62  2.61  2.01 401173481 236096320 367411639 
188906982 227691359
4  312221639 Broadband  2.65  2.64  2.63  2.62  2.01 188906982 401173481 236096320 
367411639 227691359
5  312221649 Broadband  2.65  2.64  2.63  2.62  2.01 188906982 401173481 236096320 
367411639 227691359
6  312221659 Broadband  2.65  2.64  2.63  2.62  2.01 188906982 401173481 236096320 
367411639 227691359
7  312221708 Broadband  2.65  2.64  2.63  2.62  2.01 188906982 401173481 236096320 
367411639 227691359
8  312221719 Broadband  2.65  2.64  2.63  2.62  2.01 188906982 401173481 236096320 
367411639 227691359
9  312221729 Broadband  2.65  2.64  2.63  2.62  2.01 188906982 401173481 236096320 
367411639 227691359
10 312221739 Broadband  2.65  2.64  2.63  2.62  2.01 188906982 401173481 236096320 
367411639 227691359


keywords <- levels(bids[,'keyword'])

reshaped <<- NULL
for (key in keywords)
{
keywordbid <- bids[bids[,'keyword']==key,]
keywordbid[,'id'] = NULL
keywordbid <- reshape(keywordbid, v.names='bid',
  timevar='rank',direction='wide',idvar='batch')
keywordid <- bids[bids[,'keyword']==key,]
keywordid[,'bid'] = NULL
keywordid <- reshape(keywordid, v.names='id',
 timevar='rank',direction='wide',idvar='batch')
if(is.null(reshaped))
{
reshaped <<- merge(keywordbid, keywordid)
} else {
    reshaped <<- rbind(reshaped, merge(keywordbid, keywordid))
}
rm(keywordbid, keywordid)
}

Thank you very much for any comments,

--

Vaclav Petricek
http://kocour.ms.mff.cuni.cz/~petricek

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