Re: [R] maps does not work

2007-10-12 Thread Prof Brian Ripley
I think the problem is that tempdir() has been set somewhere invalid.
However, does help() work at all, since that uses the same mechanism?

Here are some diagnostic hints:

Start an R session, printout tempdir() and see if it looks right.  Search 
for the directory on your file system and see if you can create a file in 
it. If it is on a remote file system there could well be permission 
issues.

See ?tempdir and set (or unset) environment variables to change tempdir() 
to somewhere else you know is valid.

On Fri, 12 Oct 2007, Lukas Gudmundsson wrote:

 2007/10/11, Ray Brownrigg [EMAIL PROTECTED]:
 On Thu, 11 Oct 2007, Lukas Gudmundsson wrote:
 Hello,
 I am trying to draw geographical maps with the maps package. However

 if I try to access the data following error occurs:
 require(maps)
 map()

 Fehler in zip.file.extract(file, Rdata.zip) :
   'destination' existiert nicht
 # Error in zip.file.extract(file, Rdata.zip) : 'destination' does not
 exist

 traceback()

 4: zip.file.extract(file, Rdata.zip)
 3: data(list = dbname)
 2: maptype(database)
 1: map()

 To check if I have principle problems with my system I tried:
 require(mapdata)
 map('worldHires', col=1:10)

 # Works


 I am running R 2.6.0 and a current version of maps. But I had a
 similar problem with R 2.5.1
 Is this a known issue?

 thanks
 Lukas

 You don't say which OS you are using and I can't reproduce this on Windows so
 it is hard to give explicit recommendations, but what if you try running:
 R --vanilla
 then:
 library(maps); map()

 Alternately, try:
 map(world)

 I suspect you have something in your workspace or your environment that is
 clashing.

 Ray


 First at all thanks a lot for the reply and sorry for the incomplete
 informations:
 OS: Windows XP, SP2, version 2002
 The computer is connected to a network with several data servers
 (uni). R is installed locally at the default location. I have an user
 and an admin account for this computer. As the problem I have seams
 not to be common a short history of what I have done so far (without
 success):

 1. Installed the package using the admin login at the default location

 2. Installed the package from the usr account into R_LIBS_USER (C:\RLIBS)

 3. I have tried to dig into the error using options(error=recover). I
 did not get to far but
 file == C:/RLIBS/maps/data/worldMapEnv.r.
 I had a look at the zip file in C:/RLIBS/maps/data. It contains
 worldMapEnv.r (but as I do not really understand the package
 architecture I can not interpret its single line contents (worldMapEnv
 - R_MAP_DATA_DIR))

 4. If I am trying to run any thing like example(lm) I am getting the
 same error in zip.file.extract (but so far i did not care)

 5. I tried to call R from the DOS box using R --vanilla but that did
 not work either

 6. I reinstalled maps form several CRAN mirrors

 7. I tried to run maps on my private computer at home and that did
 work... which increases the confusion.

 again thanks for any help!

 Lukas

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


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


[R] random forest mtry and mse

2007-10-12 Thread David Rogowski
I have been using random forest on a data set with 226 sites and 36 
explanatory variables (continuous and categorical). When I use 
tune.randomforest to determine the best value to use in mtry there 
is a fairly consistent and steady decrease in MSE, with the optimum of 
mtry usually equal to 1. Why would that occur, and what does it 
signify? What I would assume is that most of my explanatory variables 
have little to no explanatory power. Does that sound about right?

Thanks for any insight that anyone may have.

dave

__
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] accessing ylim set by xyplot

2007-10-12 Thread Duncan Mackay

At 22:48 12/10/07, you wrote:
Hello,

I would like to know if there is a clever way to avoid the problem
illustrated below within the xyplot function.

x - seq(1:10)
y - seq(1:10)
pr1 - xyplot(x ~ y)

u - seq(1:12)
v - seq(1:12)
pr2 - xyplot(u ~ v, col = red, more = FALSE)

prts - list(pr1, pr2)

for(i in prts) print(i, more = TRUE)


I realize that one possibility is to explicitly set the same values for
xlim and ylim for the plot, but that doesn't work very well for me
because I am accessing data via a function in a simulation loop in which
the ylims vary substantially depending on the variable being plotted.

What I would like to be able to do is to access the limits that xyplot
automatically sets when it initially creates a plot and then use those
values to estimate a ylim for succeeding rounds of the simulation.  For
instance, if in the first round of a simulation the ylim set by xyplot
for a variable is c(0,20), I could then use that value as the ylim in
the following rounds for the same variable (other variables will be
assigned their limits accordingly).  At the end of the program I will
have plots for 20 or so variables with each plot having several 'lines'
for each round of the simulation.

In short, is there a way to access the automatically determined ylim?

Kind regards,
Jeff

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

Try using the prepanel function (untested for your example)

xyplot(x,y,
   prepanel = function(y ...){list(ylim = range(y))}
   )
you may have to use pretty to improve the values from the range

Regards

Duncan Mackay
Dept of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351
Email [EMAIL PROTECTED]
home: [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] Anybody has ever met the problem to add a legend to a figure generated by image()

2007-10-12 Thread Katharine Mullen
have you tried the function image.plot in the package fields?

On Fri, 12 Oct 2007, zhijie zhang wrote:

 Dear friends,
   Anybody has ever met the problem to add a legend to a figure generated by
 image()? I have three variables,x,y and z.
 x and y are the coordinates, and z is the third values. we can use image(x,
 y, z,...) to generate a figure according to the z-values, but the problem is
 the figure legend. How can the legend be added to a figure generated
 by image()? Note that filled.contour() can add the figure legend
 automatically, but there are some problems sometime. I want to know the
 specific method for adding the legend to the figure generated by image().
  Thanks very much.

 --
 With Kind Regards,

 oooO:
 (..):
 :\.(:::Oooo::
 ::\_)::(..)::
 :::)./:::
 ::(_/
 :
 [***]
 Zhi Jie,Zhang ,PHD
 Tel:86-21-54237149
 Dept. of Epidemiology,School of Public Health,Fudan University
 Address:No. 138 Yi Xue Yuan Road,Shanghai,China
 Postcode:200032
 Email:[EMAIL PROTECTED]
 Website: www.statABC.com
 [***]
 oooO:
 (..):
 :\.(:::Oooo::
 ::\_)::(..)::
 :::)./:::
 ::(_/
 :

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


Re: [R] collapsing a data frame

2007-10-12 Thread jim holtman
Here is one way.  Not sure what you wanted done with some of the other
variables, so I just chose the first one; you could do max/min:

 z - by(h, h$BROOD, function(x){
+ # take first value of elements you don't want to change
+ data.frame(BROOD=x$BROOD[1], TICKS.mean=mean(x$TICKS),
TICKS.sd=sd(x$TICKS),
+ HEIGHT=x$HEIGHT[1], YEAR=x$YEAR[1], LOCATION=x$LOCATION[1])
+ })
 do.call('rbind', z)
BROOD TICKS.mean TICKS.sd HEIGHT YEAR LOCATION
501   501  0 0.00465   95   32
502   502  0   NA472   95   36
503   503  1 1.732051475   95   37


On 10/12/07, Ben Bolker [EMAIL PROTECTED] wrote:

   Trying to find a quick/slick/easily interpretable way to
 collapse a data set.

  Suppose I have a data set that looks like this:

 h - structure(list(INDEX = structure(1:6, .Label = c(1, 2, 3,
 4, 5, 6), class = factor), TICKS = c(0, 0, 0, 0, 0, 3
 ), BROOD = structure(c(1L, 1L, 2L, 3L, 3L, 3L), .Label = c(501,
 502, 503), class = factor), HEIGHT = c(465, 465, 472, 475,
 475, 475), YEAR = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c(95,
 96, 97), class = factor), LOCATION = structure(c(1L, 1L,
 2L, 3L, 3L, 3L), .Label = c(32, 36, 37), class = factor)), .Names =
 c(INDEX,
 TICKS, BROOD, HEIGHT, YEAR, LOCATION), row.names = c(NA,
 6L), class = data.frame)

 i.e.,
  h
  INDEX TICKS BROOD HEIGHT YEAR LOCATION
 1 1 0   501465   95   32
 2 2 0   501465   95   32
 3 3 0   502472   95   36
 4 4 0   503475   95   37
 5 5 0   503475   95   37
 6 6 3   503475   95   37

 I want a data set that looks like this:
  BROOD TICKS.mean HEIGHT YEAR LOCATION
501  0   465  95  32
502  0   472  95  36
503  1   475  95  37

 (for example).  I.e.,  I want to collapse it to a dataset by brood,
 taking the mean of TICKS and reducing each of
 the other variables (would be nice to allow multiple summary
 statistics, e.g. TICKS.mean and TICKS.sd ...)
 In some ways, this is the opposite of a database join/merge
 operation -- I want to collapse the data frame back down.
 If I had the unmerged (i.e., the brood table) handy I could
 use it.

  I know I can construct this table a bit at a time,
  using tapply() or by()  or aggregate() to get the means.

  Here's a solution that takes the first element of each factor
 and the mean of each numeric variable.  I can imagine there
 are more general/flexible solutions.  (One might want to
 specify more than one summary function, or specify that
 factors that vary within group should be dropped.)

 vtype = sapply(h,class)  ## variable types [numeric or factor]
 vtypes = unique(vtype)   ## possible types
 v2 = lapply(vtypes,function(z) which(vtype==z))  ## which are which?
 cfuns = list(factor=function(z)z[1],numeric=mean)## functions to apply
 m = mapply(function(w,f) { aggregate(h[w],list(h$BROOD),f) },
  v2,cfuns,SIMPLIFY=FALSE)
 data.frame(m[[1]],m[[2]][-1])

  My question is whether this is re-inventing the wheel.  Is there
 some function or package that performs this task?

  cheers
Ben Bolker

 --
 View this message in context: 
 http://www.nabble.com/collapsing-a-data-frame-tf4614195.html#a13177053
 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.



-- 
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] Basic plot question: Figure 1.1 Pinheiro Bates

2007-10-12 Thread Douglas Bates
On 10/12/07, David Afshartous [EMAIL PROTECTED] wrote:
 All,
 Sorry for overly simplistic question, but I can't seem to remember how to
 create the basic plot shown in Figure 1.1 of Pinheiro  Bates (2004; p.4).
 The y-axis delineates a factor (Rail) while the x-axis displays the
 distribution of a continuous variable (time) according to each level of the
 factor.  Didn't see it in archives but perhaps I'm not searching on correct
 key words, any help appreciated,
 David

  library(nlme)
  Rail
 Grouped Data: travel ~ 1 | Rail
Rail travel
 1 1 55
 2 1 53
 3 1 54
 4 2 26
 5 2 37
 6 2 32
 7 3 78
 8 3 91
 9 3 85
 104 92
 114100
 124 96
 135 49
 145 51
 155 50
 166 80
 176 85
 186 83

That plot can be reproduced by

 library(lattice)
 data(Rail, package = nlme)
 dotplot(Rail ~ travel, Rail)

However, this relies on the Rail$Rail factor being ordered by
increasing mean travel time, which is fine for the plot but may get in
the way of other uses of the data.  In a way we only want to assign an
order to the levels of the Rail factor for the purposes of the plot.

As Deepayan Sarkar mentions in his useR!2007 presentation
(http://user2007.org/program/presentations/sarkar.pd) he has done a
considerable amount of upgrading of the lattice package, relative to
the original design of Trellis graphics, in part to make the nlme
plots easier to create.  The version of the Rail data in the MEMSS
package removes the ordering on the levels of the Rail factor so it
defaults to the original order.  Compare

 data(Rail, package = MEMSS)
 dotplot(Rail ~ travel, Rail)
 dotplot(reorder(Rail, travel) ~ travel, Rail)

The latter plot is the way I would recommend constructing that plot now.

__
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] Automating binning for chisq.test()

2007-10-12 Thread Marc Schwartz
On Fri, 2007-10-12 at 11:16 -0600, D. R. Evans wrote:
 The standard chisq.test() and fisher.test() functions, when applied to
 two distributions (to determine whether the same underlying
 distribution applies to both) requires one to pre-bin the
 distributions.
 
 Is there a library function (either built-in or in a package) that
 acts more like the ks.test() function, in that one can simply pass the
 two distributions and have it do the necessary binning as well as the
 actual statistical test?
 
 (Yes, you can accuse me of laziness: I just don't fancy trying to
 figure out a routine that would make sure that there more than 5
 samples in each of the expected bins before applying the chi-squared
 test. It seems too much like re-inventing an elementary wheel that
 must have been invented by someone else.)

You might want to review the following article:

Chi-squared and Fisher-Irwin tests of two-by-two tables with small 
sample recommendations 
Ian Campbell
Stat in Med 26:3661-3675; 2007 
http://www3.interscience.wiley.com/cgi-bin/abstract/114125487/ABSTRACT 


Frank Harrell has offered some comments here (bottom of page): 

  http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/DataAnalysisDisc

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.


Re: [R] Automating binning for chisq.test()

2007-10-12 Thread Duncan Murdoch
On 10/12/2007 1:16 PM, D. R. Evans wrote:
 The standard chisq.test() and fisher.test() functions, when applied to
 two distributions (to determine whether the same underlying
 distribution applies to both) requires one to pre-bin the
 distributions.
 
 Is there a library function (either built-in or in a package) that
 acts more like the ks.test() function, in that one can simply pass the
 two distributions and have it do the necessary binning as well as the
 actual statistical test?
 
 (Yes, you can accuse me of laziness: I just don't fancy trying to
 figure out a routine that would make sure that there more than 5
 samples in each of the expected bins before applying the chi-squared
 test. It seems too much like re-inventing an elementary wheel that
 must have been invented by someone else.)

If you have a quantile function q() for the distribution, a sample size 
of N, and want expected counts of 5 in each bin, just calculate the 
cutpoints as

nbins - floor(N/5)
cutpoints - c(-Inf, q( (1:(nbins-1)/nbins)), Inf)

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.


[R] collapsing a data frame

2007-10-12 Thread Ben Bolker

   Trying to find a quick/slick/easily interpretable way to
collapse a data set.

  Suppose I have a data set that looks like this:

h - structure(list(INDEX = structure(1:6, .Label = c(1, 2, 3, 
4, 5, 6), class = factor), TICKS = c(0, 0, 0, 0, 0, 3
), BROOD = structure(c(1L, 1L, 2L, 3L, 3L, 3L), .Label = c(501, 
502, 503), class = factor), HEIGHT = c(465, 465, 472, 475, 
475, 475), YEAR = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c(95, 
96, 97), class = factor), LOCATION = structure(c(1L, 1L, 
2L, 3L, 3L, 3L), .Label = c(32, 36, 37), class = factor)), .Names =
c(INDEX, 
TICKS, BROOD, HEIGHT, YEAR, LOCATION), row.names = c(NA, 
6L), class = data.frame)

i.e., 
 h
  INDEX TICKS BROOD HEIGHT YEAR LOCATION
1 1 0   501465   95   32
2 2 0   501465   95   32
3 3 0   502472   95   36
4 4 0   503475   95   37
5 5 0   503475   95   37
6 6 3   503475   95   37

I want a data set that looks like this:
  BROOD TICKS.mean HEIGHT YEAR LOCATION
501  0   465  95  32
502  0   472  95  36
503  1   475  95  37

(for example).  I.e.,  I want to collapse it to a dataset by brood,
taking the mean of TICKS and reducing each of 
the other variables (would be nice to allow multiple summary
statistics, e.g. TICKS.mean and TICKS.sd ...)
In some ways, this is the opposite of a database join/merge
operation -- I want to collapse the data frame back down.
If I had the unmerged (i.e., the brood table) handy I could
use it.

  I know I can construct this table a bit at a time,
 using tapply() or by()  or aggregate() to get the means.

  Here's a solution that takes the first element of each factor 
and the mean of each numeric variable.  I can imagine there
are more general/flexible solutions.  (One might want to 
specify more than one summary function, or specify that
factors that vary within group should be dropped.)

vtype = sapply(h,class)  ## variable types [numeric or factor]
vtypes = unique(vtype)   ## possible types
v2 = lapply(vtypes,function(z) which(vtype==z))  ## which are which?
cfuns = list(factor=function(z)z[1],numeric=mean)## functions to apply
m = mapply(function(w,f) { aggregate(h[w],list(h$BROOD),f) },
  v2,cfuns,SIMPLIFY=FALSE)
data.frame(m[[1]],m[[2]][-1])

  My question is whether this is re-inventing the wheel.  Is there
some function or package that performs this task?

  cheers
Ben Bolker

-- 
View this message in context: 
http://www.nabble.com/collapsing-a-data-frame-tf4614195.html#a13177053
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] Batch-Plot Histograms

2007-10-12 Thread Thomas Schwander
Hi everyone,

 

anybody’s got an idea why the following script doesn’t produce 
batch-histograms?

I’m using Windows XP and R 2.5.1.

 

Here’s the script:

 

matrix-read.csv(C:\\Stadtwerke_mit_Umlage.csv, header=TRUE,sep=;,dec=.)

Stadtwerke-colnames(matrix)

Bereich_blau-66.67

Schleifen-dim(matrix)[2]

Plan-c(35.46,1.75,63.49,13.52,39.38,21.83)

Median-apply(matrix,2,median)

 

breaks-round((0.01)*dim(matrix[1]))

 

for(i in 1:Schleifen){

  hist(matrix[,i],main=paste(Risiko-Chancenprofil der Stadtwerke ,

  Stadtwerke[i]),col=blue,xlab=EBIT in Mio. €, 
ylab=Häufigkeit,breaks[1])

  abline(v=Median[i],lwd=2,col=grey,lty=3)

  axis(side=1,at=Median[i],labels=Median,col=grey)

  hist_data-hist(matrix[,i],plot=F,breaks[1])

  Quantil_unten-quantile(matrix[,i],((100-Bereich_blau)/2)/100)

  Quantil_oben-quantile(matrix[,i], (100-(100-Bereich_blau)/2)/100)

 

  #Plotten der roten unterer Teil

for(j in 1:length(hist_data$breaks)){

  if (hist_data$breaks[j]Quantil_unten)

  hv-j

}

  for(k in 1:hv){

  
rect(hist_data$breaks[k],0,hist_data$breaks[k+1],hist_data$counts[k],col=red)

}

 

for(l in 1:length(hist_data$breaks)){

  if (hist_data$breaks[l]Quantil_oben)

  hv2-l+1

}

for(m in hv2:length(hist_data$breaks)){

  
rect(hist_data$breaks[m],0,hist_data$breaks[m+1],hist_data$counts[m],col=red)

}

  dev.copy(device = postscript,file=paste(C:\\,Stadtwerke[i],.ps))

  dev.off()

}

 

It seems, that the error is in line „dev.copy“… but I don’t understand 
why. It doesn’t matter if I’m using device = jpeg or postscript. Maybe I 
must add a waiting time of 2 seconds or something like that?

 

Thanks a lot,

Thomas


[[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] calculate impulse responses

2007-10-12 Thread sj
Perhaps the VAR and irf functions in the vars library will allow you to do
what you want.


good luck,


spencer



On 10/12/07, Martin Ivanov [EMAIL PROTECTED] wrote:

 Dear R users,

 I need perform structural analysis on a no intercept VAR model.
 Unfortunately the functions irf.VAR and dfev that come with the MSBVAR
 package only work with objects output by the reduced.form.var function,
 which seems to only evaluate VAR models with intercept. Is there a way to
 suppress the estimation of intercept term in reduced.form.var? Do I need
 to modify the code, and if I do, how? Is there a way to apply irf and dfev
 to objects of type systemfit?

 Regards,
 Martin Ivanov

 -
 ëÒÁÊÎÁ ÃÅÌ - äÁ ÏÃÅÌÅÅÛ! www.survivor.btv.bg

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


[R] embedding plots

2007-10-12 Thread Josue G. Martinez
Hello!

I am trying to embed a plot of a curve(say x^2) on a matrix that
I am viewing using the image(matrix) command.

I was wondering if someone could give me some idea
of how to do this.

Thanks,

J.

[[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] Basic plot question: Figure 1.1 Pinheiro Bates

2007-10-12 Thread Stefan Grosse
On Friday 12 October 2007 17:31:22 David Afshartous wrote:
DA  All,
DA  Sorry for overly simplistic question, but I can't seem to remember how
 to 
DA  create the basic plot shown in Figure 1.1 of Pinheiro  Bates (2004;
 p.4). 
DA  The y-axis delineates a factor (Rail) while the x-axis displays
 the 
DA  distribution of a continuous variable (time) according to each
 level of the 
DA  factor.  Didn't see it in archives but perhaps I'm not
 searching on correct 
DA  key words, any help appreciated,
DA  David

library(lattice)
xyplot(Rail~travel,data=Rail)


signature.asc
Description: This is a digitally signed message part.
__
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] Disregard my previous question

2007-10-12 Thread Leeds, Mark (IED)
I did ?par and it looks  switching to mfrow will fix my problem so
thanks but disregard my previous message and
I apologize for not checking ?par first. I never thought it would be
that simple.


This is not an offer (or solicitation of an offer) to bu...{{dropped:22}}

__
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] hist () x-axis

2007-10-12 Thread Birgit Lemcke
Hello all together,

I (R Beginner) think the answer for my question is easy but anyway I  
have not found the solution.

I am using hist for a frequency histogramm. But the divisions of the  
xaxis is to large

How can I change the division (I am not sure if this is the right  
name for what I mean) of the xaxis, so that it shows not only 0.3 and  
0.4 but also 0.35?

Thanks in advance for your help.

Regards

Birgit

Birgit Lemcke
Institut für Systematische Botanik
Zollikerstrasse 107
CH-8008 Zürich
Switzerland
Ph: +41 (0)44 634 8351
[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] Problem with two libraries

2007-10-12 Thread Michael Kubovy
Hi,

I'm running
  sessionInfo()
R version 2.6.0 (2007-10-03)
i386-apple-darwin8.10.1

locale:
en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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


I have two libraries:
(1) /Users/mk/R/i386-apple-darwin8.10.1-library/2.6/

and

(2) /Library/Frameworks/R.framework/Versions/2.6/Resources/library/

When I try to load a recently-installed package (plotAndPlayGTK)  
which got installed in (1) it tries to load RGtk2 which is in (2) and  
it fails.

I would like advice on how to consolidate these two in (2) and make  
(2) the default library (if that's adivsable) and how to make the  
upgrade to future versions of R as trouble-free as possible.
_
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS: P.O.Box 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
 McCormick RoadCharlottesville, VA 22903
Office:B011+1-434-982-4729
Lab:B019+1-434-982-4751
Fax:+1-434-982-4766
WWW:http://www.people.virginia.edu/~mk9y/

__
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] how to know whether Vector B is a subset of Vector A

2007-10-12 Thread Marc Schwartz
On Fri, 2007-10-12 at 18:47 +0800, Samuel wrote:
 Hi,
 
 I'm quite fresh to R, and a layman of English as well. I hope I can make you
 understood.
 
 Now I have two vectors A and B. Is there any quick way to know whether B is
 a subset of A? and If B is a subset of A, can I know easily which elements
 in A (the index of A) equals to B's elements accordingly?
 
 For example,
 
  a-1:20
  b=c(2,5,9,7,4,8,3)
 
 
 Question 1: we know b is a subset of a, but how does R know that?
 
 Question 2: since we know b is a subset of a, then which a's elements equals
 to b? I do it like this:
 
 test=0
  for (i in 1:length(b)) test[i]=which(a==b[i])
  test
 
 
 Is there any easier way to know these indexes?
 
 Thanks a lot for you helps in advance


You can use %in% to determine whether or not the elements of 'b' are in
'a':

a - 1:20
b - c(2, 5, 9, 7, 4, 8, 3)
 
 b %in% a
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE

To get the indices of b's elements in 'a', you can do:

 which(a %in% b)
[1] 2 3 4 5 7 8 9


If you want to know whether or not ALL of the elements of 'b' are in
'a', you add the use of all() to the first example:

 all(b %in% a)
[1] TRUE

See ?%in% and ?all

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.


Re: [R] how to know whether Vector B is a subset of Vector A

2007-10-12 Thread Peter Dalgaard
Samuel wrote:
 Hi,

 I'm quite fresh to R, and a layman of English as well. I hope I can make you
 understood.

 Now I have two vectors A and B. Is there any quick way to know whether B is
 a subset of A? and If B is a subset of A, can I know easily which elements
 in A (the index of A) equals to B's elements accordingly?

 For example,

   
 a-1:20
 b=c(2,5,9,7,4,8,3)

 

 Question 1: we know b is a subset of a, but how does R know that?

 Question 2: since we know b is a subset of a, then which a's elements equals
 to b? I do it like this:

 test=0
   
 for (i in 1:length(b)) test[i]=which(a==b[i])
 test

 

 Is there any easier way to know these indexes?

 Thanks a lot for you helps in advance

   
 a-1:20
 b-c(2,5,9,7,4,8,3)
 !length(setdiff(b,a))
[1] TRUE
 a %in% b
 [1] FALSE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
[13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 which(a %in% b)
[1] 2 3 4 5 7 8 9


-- 
   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] Anybody has ever met the problem to add a legend to a figure generated by image()?

2007-10-12 Thread zhijie zhang
Dear friends,
  Anybody has ever met the problem to add a legend to a figure generated by
image()? I have three variables,x,y and z.
x and y are the coordinates, and z is the third values. we can use image(x,
y, z,...) to generate a figure according to the z-values, but the problem is
the figure legend. How can the legend be added to a figure generated
by image()? Note that filled.contour() can add the figure legend
automatically, but there are some problems sometime. I want to know the
specific method for adding the legend to the figure generated by image().
 Thanks very much.

--
With Kind Regards,

oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/
:
[***]
Zhi Jie,Zhang ,PHD
Tel:86-21-54237149
Dept. of Epidemiology,School of Public Health,Fudan University
Address:No. 138 Yi Xue Yuan Road,Shanghai,China
Postcode:200032
Email:[EMAIL PROTECTED]
Website: www.statABC.com
[***]
oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/
:

[[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] Q-type factor analysis

2007-10-12 Thread Julia Kröpfl
Hallo!

Is there a package in R that does Q-type factor analysis?
I know how to do principal component analysis, but haven't found any 
application of Q-type factor analysis.

Thx, 
Julia
-- 
Pt! Schon vom neuen GMX MultiMessenger gehört?
Der kanns 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] irfs from a no intercept VAR

2007-10-12 Thread Martin Ivanov
Dear R users,

I need perform structural analysis on a no intercept VAR model. Unfortunately 
the functions irf.VAR and dfev that come with the MSBVAR package only work with 
objects output by the reduced.form.var function, which seems to only evaluate 
VAR models with intercept. Is there a way to suppress the estimation of 
intercept term in reduced.form.var? Do I need to modify the code, and if I do, 
how? Is there a way to apply irf and dfev to objects of type systemfit?

Regards,
Martin Ivanov

-
Крайна цел - Да оцелееш! www.survivor.btv.bg

__
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] Basic plot question: Figure 1.1 Pinheiro Bates

2007-10-12 Thread David Afshartous
All,
Sorry for overly simplistic question, but I can't seem to remember how to
create the basic plot shown in Figure 1.1 of Pinheiro  Bates (2004; p.4).
The y-axis delineates a factor (Rail) while the x-axis displays the
distribution of a continuous variable (time) according to each level of the
factor.  Didn't see it in archives but perhaps I'm not searching on correct
key words, any help appreciated,
David


 library(nlme)
 Rail
Grouped Data: travel ~ 1 | Rail
   Rail travel
1 1 55
2 1 53
3 1 54
4 2 26
5 2 37
6 2 32
7 3 78
8 3 91
9 3 85
104 92
114100
124 96
135 49
145 51
155 50
166 80
176 85
186 83

__
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] how to know whether Vector B is a subset of Vector A

2007-10-12 Thread Samuel
Hi,

I'm quite fresh to R, and a layman of English as well. I hope I can make you
understood.

Now I have two vectors A and B. Is there any quick way to know whether B is
a subset of A? and If B is a subset of A, can I know easily which elements
in A (the index of A) equals to B's elements accordingly?

For example,

 a-1:20
 b=c(2,5,9,7,4,8,3)


Question 1: we know b is a subset of a, but how does R know that?

Question 2: since we know b is a subset of a, then which a's elements equals
to b? I do it like this:

test=0
 for (i in 1:length(b)) test[i]=which(a==b[i])
 test


Is there any easier way to know these indexes?

Thanks a lot for you helps in advance

-- 
Samuel Wu

[[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] random forest mtry and mse

2007-10-12 Thread Kuhn, Max
Dave,

 I have been using random forest on a data set with 226 sites and 36 
 explanatory variables (continuous and categorical). When I use 
 tune.randomforest to determine the best value to use in mtry there

 is a fairly consistent and steady decrease in MSE, with the optimum of

 mtry usually equal to 1. Why would that occur, and what does it 
 signify? What I would assume is that most of my explanatory variables 
 have little to no explanatory power. Does that sound about right?

I'm not sure that it means anything (I've seen this happen too). 

Essentially, this would indicate that, for this particular dataset, the
random forest model needs the trees to be as uncorrelated as possible.
If it were to like mtry = # predictors, this would indicate that
bagging was the optimal model. There is the no free lunch theorem and
this would apply to possible random forest sub-models; without
information related to the specifics of the problem at hand, there is no
reason to believe that any one model is uniformly best across problems.
Did you have any subject-specific reason to think larger values of mtry
were optimal?

What was the difference in performance across all of the candidate
values of mtry? I don't usually see a huge effect of altering mtry
(change in accuracy or Rsquared = 5% in classification and regression
models, respectively) relative the variation in resampling.

Max

__
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] Differencing data by groups

2007-10-12 Thread Thomas Miller
Colleagues,

I am analyzing data collected during oceanographic cruises. We have
conducted many cruises over the last decade.  On each cruise we visit ~50
stations. At each station (termed EventNum)we lower an instrument that
measures depth, temperature, salinity and oxygen every few seconds as it is
lowered through the water.  Data from all EventNums on all cruises are
stacked, generating a data file that might look like 

  CruiseID Year Season EventNum Region Depth SalinityTemp  Oxygen
1CF0101 2001 Spring  849  Lower 0.056  21.1753 15.5626 8.12344
2CF0101 2001 Spring  849  Lower 0.103  21.3264 15.5511 8.11873
3CF0101 2001 Spring  849  Lower 0.131  21.4780 15.5492 8.10568
4CF0101 2001 Spring  849  Lower 0.169  21.5296 15.5492 8.10633


15000   CF0103 2001   Fall  929Mid 14.449   17.692 22.901  7.743
15001   CF0103 2001   Fall  929Mid 14.478   17.691 22.900  7.743
15002   CF0103 2001   Fall  929Mid 14.527   17.692 22.899  7.743
15003   CF0103 2001   Fall  929Mid 14.595   17.692 22.900  7.743
15004   CF0103 2001   Fall  929Mid 14.654   17.694 22.902  7.742
15005   CF0103 2001   Fall  929Mid 14.722   17.695 22.903  7.742
15006   CF0103 2001   Fall  929Mid 14.790   17.695 22.903  7.742
15007   CF0103 2001   Fall  929Mid 14.839   17.694 22.903  7.742
15008   CF0103 2001   Fall  929Mid 14.887   17.695 22.902  7.742
15009   CF0103 2001   Fall  929Mid 14.946   17.694 22.902  7.742
15010   CF0103 2001   Fall  929Mid 14.985   17.693 22.902  7.743
..

In total there are ~350k rows of data

I can calculate simple EventNum averages using

meanobs-aggregate(ctd[,7:9],by=list(EventNum=EventNum),mean)

But, I want to calculate a depth-weighted mean for salinity, temp and oxygen
for each EventNum.  The depth-weighted mean is calculated as 

Xbar = Sum{depth_interval*temp}/Sum(depth_intervals)

Where the depth interval is the differenced depths  (i.e., 0.103-0.056 for
the second row of data).

I cannot seem to get diff to work the way I want it to - advice appreciated

Tom

Thomas J. Miller, Ph.D.
Professor
Chesapeake Biological Laboratory
University of Maryland Center for Environmental Science
Solomons, MD 20688
Tel: (410) 326-7276
Fax: (410) 326-7318
WWW: hjort.cbl.umces.edu

__
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] Plotting question

2007-10-12 Thread Leeds, Mark (IED)
I am constructing plots ( regular not lattice ) and my initial command
is

par(mar=c(3,4,2,2), mfcol=c(5,2))

and then I create 10 plots on the page. It looks great but the plots on
the page go in the order

16
27
38
49
510

Where the numbers denote decile breakdowns.

Is there an easy way to make them go from left to right so

12
34
56
78
910

I could try to stay with the first way and reorder the deciles but that
would be tricky and beyond
my current knowledge base. Thanks.


This is not an offer (or solicitation of an offer) to bu...{{dropped:22}}

__
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] Plotting question

2007-10-12 Thread hadley wickham
Have you looked at layout() ?

Hadley

On 10/12/07, Leeds, Mark (IED) [EMAIL PROTECTED] wrote:
 I am constructing plots ( regular not lattice ) and my initial command
 is

 par(mar=c(3,4,2,2), mfcol=c(5,2))

 and then I create 10 plots on the page. It looks great but the plots on
 the page go in the order

 16
 27
 38
 49
 510

 Where the numbers denote decile breakdowns.

 Is there an easy way to make them go from left to right so

 12
 34
 56
 78
 910

 I could try to stay with the first way and reorder the deciles but that
 would be tricky and beyond
 my current knowledge base. Thanks.
 

 This is not an offer (or solicitation of an offer) to bu...{{dropped:22}}

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



-- 
http://had.co.nz/

__
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] variance explained by each term in a GAM

2007-10-12 Thread Julian Burgos
Dear Prof. Wood,

Just another quick question.  I am doing model selection following Wood 
and Augustin (2002).  One of the criteria for retaining a term is to see 
if removing it causes an increase in the GCV score.  When doing this, do 
I also need to fix the smooth parameters?

Thanks,

Julian Burgos

Fisheries Acoustics Research Lab
School of Aquatic and Fishery Science
University of Washington

1122 NE Boat Street
Seattle, WA  98105 


Simon Wood wrote:

 I think that your approach is reasonable, except that you should use the same 
 smoothing parameters throughout. i.e the reduced models should use the same 
 smoothing parameters as the full model. Otherwise you get in trouble if x1 
 and x2 are correlated, since the smoothing parameters will then tend to 
 change alot when terms are dropped as one smooth tries to `do the work' of 
 the other. Here's an example, (which is modifiable to illustrate the problem 
 with not fixing the sp's)

  ## simulate some data
 set.seed(0)
 n-400
 x1 - runif(n, 0, 1)
 ## to see problem with not fixing smoothing parameters
 ## remove the `##' from the next line, and the `sp'
 ## arguments from the `gam' calls generating b1 and b2. 
 x2 - runif(n, 0, 1) ## *.1 + x1 
 f1 - function(x) exp(2 * x)
 f2 - function(x) 0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10
 f - f1(x1) + f2(x2)
 e - rnorm(n, 0, 2)
 y - f + e
 ## fit full and reduced models...
 b - gam(y~s(x1)+s(x2))
 b1 - gam(y~s(x1),sp=b$sp[1])
 b2 - gam(y~s(x2),sp=b$sp[2])
 b0 - gam(y~1)
 ## calculate proportions deviance explained...
 (deviance(b1)-deviance(b))/deviance(b0) ## prop explained by s(x2)
 (deviance(b2)-deviance(b))/deviance(b0) ## prop explained by s(x1)





 On Monday 08 October 2007 20:19, Julian M Burgos wrote:
   
 Hello fellow R's,

 I do apologize if this is a basic question.  I'm doing some GAMs using the
 mgcv package, and I am wondering what is the most appropriate way to
 determine how much of the variability in the dependent variable is
 explained by each term in the model.  The information provided by
 summary.gam() relates to the significance of each term (F, p-value) and to
 the wiggliness of the fitted smooth (edf), but (as  far as I understand)
 there is no information on the proportion of variance explained.

 One alternative may be to fit alternative models without each term, and
 calculate the reduction in deviance.  For example:

 m1=gam(y~s(x1) + s(x2)) # Full model
 m2=gam(y~s(x2))
 m3=gam(y~s(x1))

 ddev1=deviance(m1)-deviance(m2)
 ddev2=deviance(m1)-deviance(m3)

 Here, ddev1 would measure the relative proportion of the variability in y
 explained by x1, and ddev2 would do the same for x2.  Does this sound like
 an appropriate approach?

 Julian

 Julian Burgos
 FAR lab
 University of Washington

 __
 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] wireframe shade=T colorkey

2007-10-12 Thread Duncan Murdoch
On 10/11/2007 6:32 PM, Deepayan Sarkar wrote:
 On 10/11/07, Karim Rahim [EMAIL PROTECTED] wrote:
 Thank you for your reply.

 In this graphics context, I'm not sure what the incident or reflected
 light rays are.

 May I ask for an example of using a colour key with the volcano data
 using the colours that appear when you select the shade option?

 It is simple to have the colour key appear using drape. Perhaps it is
 not so simple to have a colour key using shade colours or different
 colours. Once again, may I ask for an example of setting these colour
 key and/or colour options?
 
 I'm not really sure what you want. The goal of the colorkey is to
 associate a given z-value (or height) with a specific color.
 drape=TRUE does this, e.g.,
 
 wireframe(volcano, drape = TRUE, colorkey = TRUE)
 
 Now, with shade=TRUE, e.g.,
 
 wireframe(volcano, shade = TRUE)
 
 the SAME Z-VALUE CAN HAVE DIFFERENT COLORS depending on the
 orientation of the facet with respect to the viewing direction and the
 light source. So, a colorkey DOES NOT MAKE SENSE.

But the colorkey could display what the color would be at some 
particular orientation, with height allowed to vary, or perhaps with 
fixed values for irradiance and reflective angle.  With the standard 
palette this should be readable because the height determines the hue, 
and (non-colorblind) people are good at recognizing hue even when 
saturation and brightness vary.

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] wireframe shade=T colorkey

2007-10-12 Thread Deepayan Sarkar
On 10/12/07, Duncan Murdoch [EMAIL PROTECTED] wrote:
 On 10/11/2007 6:32 PM, Deepayan Sarkar wrote:
  On 10/11/07, Karim Rahim [EMAIL PROTECTED] wrote:
  Thank you for your reply.
 
  In this graphics context, I'm not sure what the incident or reflected
  light rays are.
 
  May I ask for an example of using a colour key with the volcano data
  using the colours that appear when you select the shade option?
 
  It is simple to have the colour key appear using drape. Perhaps it is
  not so simple to have a colour key using shade colours or different
  colours. Once again, may I ask for an example of setting these colour
  key and/or colour options?
 
  I'm not really sure what you want. The goal of the colorkey is to
  associate a given z-value (or height) with a specific color.
  drape=TRUE does this, e.g.,
 
  wireframe(volcano, drape = TRUE, colorkey = TRUE)
 
  Now, with shade=TRUE, e.g.,
 
  wireframe(volcano, shade = TRUE)
 
  the SAME Z-VALUE CAN HAVE DIFFERENT COLORS depending on the
  orientation of the facet with respect to the viewing direction and the
  light source. So, a colorkey DOES NOT MAKE SENSE.

 But the colorkey could display what the color would be at some
 particular orientation, with height allowed to vary, or perhaps with
 fixed values for irradiance and reflective angle.  With the standard
 palette this should be readable because the height determines the hue,
 and (non-colorblind) people are good at recognizing hue even when
 saturation and brightness vary.

Yes, and since it's easy to specify your own colors and breakpoints,
you could do

shade.col.fun - trellis.par.get(shade.colors)$palette
shade.colors - shade.col.fun(0.5, 0.5, seq(0, 1, length = 100))
wireframe(volcano, shade = TRUE,
  colorkey = list(col = shade.colors,
  at = do.breaks(range(volcano), 100)))

While this works for the standard color palette, it doesn't do
anything useful for the standard black and white palette, which
ignores height. Given the lack of generality, I would be reluctant to
have something this happen automatically.

-Deepayan

__
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] collapsing a data frame

2007-10-12 Thread Chris Stubben
 On 10/12/07, Ben Bolker bolker at ufl.edu wrote:
 
Trying to find a quick/slick/easily interpretable way to
  collapse a data set.
 

Another alternative for SQL fans is the sqldf package.  I used the MySQL driver
here since SQLite does not support standard deviation. 


sqldf(select BROOD, avg(TICKS) as 'TICKS.mean', stddev_samp(TICKS) as
'TICKS.sd', HEIGHT, YEAR, LOCATION
 from h
group by BROOD, HEIGHT, YEAR, LOCATION,  drv=MySQL)

  BROOD TICKS.mean TICKS.sd HEIGHT YEAR LOCATION
1   501  0 0.00465   95   32
2   502  0   NA472   95   36
3   503  1 1.73475   95   37



Chris

__
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] Q-type factor analysis

2007-10-12 Thread Kenn Konstabel
On 10/12/07, Julia Kröpfl [EMAIL PROTECTED] wrote:

 Is there a package in R that does Q-type factor analysis?
 I know how to do principal component analysis, but haven't found any
 application of Q-type factor analysis.


Q-mode factor analysis is not a separate type of factor analysis but (in
old-fashioned psychological slang) analyzing of rows rather than the columns
of data matrix. So you can transpose your data (with t() if it's a matrix)
and do an ordinary factor analysis or PCA.

Kenn

[[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] Addition operation based on specific columns and rows of twodata frames

2007-10-12 Thread Leeds, Mark (IED)
My guess is that there's  an easier way but this gives what you want.

newY.df-aggregate(Y.df$Counts, list(Y.df[,1],Y.df[,2]), FUN=sum)
names(newY.df)-names(X.df)

temp.df-merge(newY.df, X.df,
by=intersect(names(X.df),names(newY.df)),all=TRUE) 

almost.df-aggregate(temp.df$Counts, list(temp.df[,1],temp.df[,2]),
FUN=sum)

temp-order(almost.df$Group.1)
final.df-almost.df[temp,]
names(final.df)-names(X.df)



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Luke Neraas
Sent: Friday, October 12, 2007 5:15 PM
To: r-help
Subject: [R] Addition operation based on specific columns and rows of
twodata frames

#Hello,

# I have a question about the addition of values in specific columns and
rows of a Data frame.
# Below I have created two data frames, X.df and Y.df.

## creation of X.df data frame

X- matrix(0,16,3)
X.df-data.frame(X)
X.df[,1] - c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)
X.df[,2] - c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
names(X.df)[1]-L(A)a(i)
names(X.df)[2]-L(B)a(j)
names(X.df)[3]-Counts

X.df


## creation of Y.df data frame

Y- matrix(0,7,3)
Y.df-data.frame(Y)
Y.df[,1]-c(1,3,4,2,2,1,2)
Y.df[,2]-c(2,4,2,4,1,2,3)
Y.df[,3]-c(1,2,1,0.5,1,1,1)
names(Y.df)[1]-L(A)a(i)
names(Y.df)[2]-L(B)a(j)
names(Y.df)[3]-Counts

Y.df

# I would like to add the value in the Counts column of Y.df to the
Counts Column of X.df, based on matching # the row value from the
first two columns of each data.frame.  I have tried the merge function
but that # doesn't give me the addition operation.

# here is what i would like the resulting operation to end up with in
the X.df data frame

X.df$Counts - c(0,2,0,0,1,0,1,0.5,0,0,0,2,0,1,0,0)


X.df


# Any help or ideas would be greatly appreciated

# Thanks in advance

# Luke Neraas

# [EMAIL PROTECTED]

# University of Alaska Fairbanks
# School of Fisheries and Ocean Sciences # 11120 Glacier Highway # UAF
Fisheries Division # Juneau, AK 99801

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


This is not an offer (or solicitation of an offer) to bu...{{dropped:22}}

__
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] use 'lapply' to creat 2 new columns based on old ones in a data frame

2007-10-12 Thread Sundar Dorai-Raj


runner said the following on 10/12/2007 4:46 PM:
 There is a dataset 'm', which has 3 columns: 'index', 'old1' and 'old2';
 
 I want to create 2 new columns: 'new1' and 'new2' on this condition: 
 if 'index'==i, then 'new1'='old1'+add[i].
 'add' is a vector of numbers to be added to old columns, e.g. add=c(10,20,30
 ...)
  
 Like this:
 
 index old1old2new1new2
 1 5   6   15  16
 2 5   6 2526
 3 5   6   35  36
 3 50 60  80  90
 
 Since the actual dataset is huge, I use 'lapply'. I am able to add 1 column:
 
 do.call(rbind, lapply( 1:nrow(m), 
 function(i) {m$new1[i]=m[i,2]+add[m[i,1]];
 return (m[i,])} 
))
 
 but don't know how to do for 2 columns at the same time, sth. like this
 simply doesn't work:
 do.call(rbind,lapply(1:nrow(m), 
   function(i){ m$new1[i]=m[i,2]+add[m[i,1]]; 
   m$new2[i]=m[i,3]+add[m[i,1]]; 
   return (m[i,])}
  ))
 Could you please tell me how? or any other better approach?
 
 


No need for lapply.

x$new1 - x$old1 + add[x$index]
x$new2 - x$old2 + add[x$index]

To see how this works, try:

add - c(10, 20, 30)
index - c(1, 2, 1, 3, 1, 2, 3)
add[index]

but be careful if 'add' is length 3 and 'index' has a 4 in it you will get

index - c(index, 4)
add[index] ## produces an 'NA'

I hope I understood your question correctly. It's happy hour on the U.S. 
east coast.

HTH,

--sundar

__
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] Differencing data by groups

2007-10-12 Thread jim holtman
What problem are you actually having with 'diff'? Now if you are using
'diff', you will get a vector that is shorter by one than the
original.  Now do you want to do do something like:

Xbar = Sum{c(Depth[1], diff(Depth))*temp}/Sum(c(Depth[1], diff(Depth))


On 10/12/07, Thomas Miller [EMAIL PROTECTED] wrote:
 Colleagues,

 I am analyzing data collected during oceanographic cruises. We have
 conducted many cruises over the last decade.  On each cruise we visit ~50
 stations. At each station (termed EventNum)we lower an instrument that
 measures depth, temperature, salinity and oxygen every few seconds as it is
 lowered through the water.  Data from all EventNums on all cruises are
 stacked, generating a data file that might look like

  CruiseID Year Season EventNum Region Depth SalinityTemp  Oxygen
 1CF0101 2001 Spring  849  Lower 0.056  21.1753 15.5626 8.12344
 2CF0101 2001 Spring  849  Lower 0.103  21.3264 15.5511 8.11873
 3CF0101 2001 Spring  849  Lower 0.131  21.4780 15.5492 8.10568
 4CF0101 2001 Spring  849  Lower 0.169  21.5296 15.5492 8.10633
 

 15000   CF0103 2001   Fall  929Mid 14.449   17.692 22.901  7.743
 15001   CF0103 2001   Fall  929Mid 14.478   17.691 22.900  7.743
 15002   CF0103 2001   Fall  929Mid 14.527   17.692 22.899  7.743
 15003   CF0103 2001   Fall  929Mid 14.595   17.692 22.900  7.743
 15004   CF0103 2001   Fall  929Mid 14.654   17.694 22.902  7.742
 15005   CF0103 2001   Fall  929Mid 14.722   17.695 22.903  7.742
 15006   CF0103 2001   Fall  929Mid 14.790   17.695 22.903  7.742
 15007   CF0103 2001   Fall  929Mid 14.839   17.694 22.903  7.742
 15008   CF0103 2001   Fall  929Mid 14.887   17.695 22.902  7.742
 15009   CF0103 2001   Fall  929Mid 14.946   17.694 22.902  7.742
 15010   CF0103 2001   Fall  929Mid 14.985   17.693 22.902  7.743
 ..

 In total there are ~350k rows of data

 I can calculate simple EventNum averages using

 meanobs-aggregate(ctd[,7:9],by=list(EventNum=EventNum),mean)

 But, I want to calculate a depth-weighted mean for salinity, temp and oxygen
 for each EventNum.  The depth-weighted mean is calculated as

 Xbar = Sum{depth_interval*temp}/Sum(depth_intervals)

 Where the depth interval is the differenced depths  (i.e., 0.103-0.056 for
 the second row of data).

 I cannot seem to get diff to work the way I want it to - advice appreciated

 Tom

 Thomas J. Miller, Ph.D.
 Professor
 Chesapeake Biological Laboratory
 University of Maryland Center for Environmental Science
 Solomons, MD 20688
 Tel: (410) 326-7276
 Fax: (410) 326-7318
 WWW: hjort.cbl.umces.edu

 __
 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] TLCA Admin Email Connectivity Re: Returned mail: Data format error

2007-10-12 Thread TLCA Admin
Due to an intermittent Broadband connection, I cannot check email as
often as I'd like. Please be assured that all your emails are being
received  I will respond to those that require attention as my ISP
Connection allows. CIncinnati Bell cannot advise as to when this will
be fixed, so I ask that you please be patient in awaiting for a
response. I am doing everything I am able to in order to respond in a
timely fashion. Thank You!

If you need to renew your current membership, or would like to join,
you may do so on-line at www.tlca.org. Please click on JOIN in the
upper right hand corner.

All technical questions can be directed to www.ih8mud.com

The TLCA on-line store is currently off-line. If you are reaching a
site that is requesting a password, you are at an incorrect site.

If you have recently joined the TLCA, please allow 4 - 6 weeks for
processing. If you joined on-line, your pay pal receipt is your
confirmation,

Thank you!

-- 
Thanks!

Jennifer Lorincz
TLCA Administrator
800.655.3810

__
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] collapsing a data frame

2007-10-12 Thread hadley wickham
On 10/12/07, Ben Bolker [EMAIL PROTECTED] wrote:

Trying to find a quick/slick/easily interpretable way to
 collapse a data set.

   Suppose I have a data set that looks like this:

 h - structure(list(INDEX = structure(1:6, .Label = c(1, 2, 3,
 4, 5, 6), class = factor), TICKS = c(0, 0, 0, 0, 0, 3
 ), BROOD = structure(c(1L, 1L, 2L, 3L, 3L, 3L), .Label = c(501,
 502, 503), class = factor), HEIGHT = c(465, 465, 472, 475,
 475, 475), YEAR = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c(95,
 96, 97), class = factor), LOCATION = structure(c(1L, 1L,
 2L, 3L, 3L, 3L), .Label = c(32, 36, 37), class = factor)), .Names =
 c(INDEX,
 TICKS, BROOD, HEIGHT, YEAR, LOCATION), row.names = c(NA,
 6L), class = data.frame)

 i.e.,
  h
   INDEX TICKS BROOD HEIGHT YEAR LOCATION
 1 1 0   501465   95   32
 2 2 0   501465   95   32
 3 3 0   502472   95   36
 4 4 0   503475   95   37
 5 5 0   503475   95   37
 6 6 3   503475   95   37

 I want a data set that looks like this:
   BROOD TICKS.mean HEIGHT YEAR LOCATION
 501  0   465  95  32
 502  0   472  95  36
 503  1   475  95  37

 (for example).  I.e.,  I want to collapse it to a dataset by brood,
 taking the mean of TICKS and reducing each of
 the other variables (would be nice to allow multiple summary
 statistics, e.g. TICKS.mean and TICKS.sd ...)
 In some ways, this is the opposite of a database join/merge
 operation -- I want to collapse the data frame back down.
 If I had the unmerged (i.e., the brood table) handy I could
 use it.

   I know I can construct this table a bit at a time,
  using tapply() or by()  or aggregate() to get the means.

   Here's a solution that takes the first element of each factor
 and the mean of each numeric variable.  I can imagine there
 are more general/flexible solutions.  (One might want to
 specify more than one summary function, or specify that
 factors that vary within group should be dropped.)

 vtype = sapply(h,class)  ## variable types [numeric or factor]
 vtypes = unique(vtype)   ## possible types
 v2 = lapply(vtypes,function(z) which(vtype==z))  ## which are which?
 cfuns = list(factor=function(z)z[1],numeric=mean)## functions to apply
 m = mapply(function(w,f) { aggregate(h[w],list(h$BROOD),f) },
   v2,cfuns,SIMPLIFY=FALSE)
 data.frame(m[[1]],m[[2]][-1])

   My question is whether this is re-inventing the wheel.  Is there
 some function or package that performs this task?

Maybe the reshape package?  http://had.co.nz/reshape

hm - melt(h, m = TICKS)
cast(hm, BROOD + HEIGHT + YEAR + LOCATION ~ ., mean)
cast(hm, BROOD + HEIGHT + LOCATION ~ YEAR, mean)
cast(hm, BROOD ~ HEIGHT ~ YEAR, mean)

You should be able to create just about any data structure you need,
and if you can't let me know.

Hadley


-- 
http://had.co.nz/

__
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] collapsing a data frame

2007-10-12 Thread hadley wickham
Here's a solution that takes the first element of each factor
  and the mean of each numeric variable.  I can imagine there
  are more general/flexible solutions.  (One might want to
  specify more than one summary function, or specify that
  factors that vary within group should be dropped.)
 
  vtype = sapply(h,class)  ## variable types [numeric or factor]
  vtypes = unique(vtype)   ## possible types
  v2 = lapply(vtypes,function(z) which(vtype==z))  ## which are which?
  cfuns = list(factor=function(z)z[1],numeric=mean)## functions to apply
  m = mapply(function(w,f) { aggregate(h[w],list(h$BROOD),f) },
v2,cfuns,SIMPLIFY=FALSE)
  data.frame(m[[1]],m[[2]][-1])
 
My question is whether this is re-inventing the wheel.  Is there
  some function or package that performs this task?

 Maybe the reshape package?  http://had.co.nz/reshape

 hm - melt(h, m = TICKS)
 cast(hm, BROOD + HEIGHT + YEAR + LOCATION ~ ., mean)
 cast(hm, BROOD + HEIGHT + LOCATION ~ YEAR, mean)
 cast(hm, BROOD ~ HEIGHT ~ YEAR, mean)

 You should be able to create just about any data structure you need,
 and if you can't let me know.

Oh, and you can easily use multiple summary functions too:

cast(hm, BROOD  + HEIGHT + YEAR + LOCATION ~ ., c(mean, sd, length))

Hadley

-- 
http://had.co.nz/

__
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] Image analysis and image questions

2007-10-12 Thread Henrik Bengtsson
See the EBImage package on Bioconductor.org.  It builds on top of
ImageMagick.  /Henrik

On 10/12/07, Bio7 [EMAIL PROTECTED] wrote:

 Dear R users,

 in my application i can transfer images to R with the help of Rserve. The
 images come from
 a java application. When i plot a greyscale image (values 0-255) with images
 (imageMatrix...as grey)
 the image is created with inverse colours. My first question is how can i
 plot the image with
 the default grey values. In the application the greys are (ImageJ):
 white=0,black=255.

 I would be also interested in operations on images inside R to test some
 image functionality.
 So which packages exist to do some image operations and how can i create and
 plot images with them (with available data structures like a list or a
 matrix)?

 Another point is the creation of coloured images inside R. How could i
 create and plot coloured images inside R and which data structure do i need?

 In addition to this question for coloured images - are there any bit
 arithmetics available to seperate the colour space or do i have to transfer
 the rgb values seperately?

 Any help is appreciated

 With kind regards

 Marcel
 --
 View this message in context: 
 http://www.nabble.com/Image-analysis-and-image-questions-tf4611810.html#a13170210
 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.