Re: [R] detect filetype (as in unix 'file')

2011-04-04 Thread Prof Brian Ripley

On Sun, 3 Apr 2011, Jeroen Ooms wrote:


Is there a way in R (in Linux) to detect the type of a file without invoking
a shell? E.g to do this:


system(file density.plot)

density.plot: PDF document, version 1.4

but without using system()? I tried file() and file.info(), but both do
display the information I am looking for.


No, but what is wrong with using system()?

'file' is large and complex because it tries to be comprehensive (but 
it still does not know about some common systems, e.g. 64-bit Windows 
binaries).  There simply is no point in replicating that in R: which 
is why we chose rather to port 'file' to Windows and provide in in 
Rools.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
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] RmetricsTools.R

2011-04-04 Thread Luis Felipe Parra
Hello I read on the Rmetrics webpage that all the development packages could
be intalled using the following command

 source(RmetricsTools.R)
   install.RmetricsDev([Rmetrics package to be installed]


I would like to know where I could get this RmetricsTools.R . I suppose it
might be somewhere on R-Forge but I haven't been able to find it. Thank you

Felipe Parra

[[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] loading R object files on an RWeb server

2011-04-04 Thread Dieter Menne

jose romero-3 wrote:
 
 For one thing, i am using google docs to host the R object file and google
 docs has secure https URL's, which apparently cannot be handled by R's
 url(). So my questions are these:
 
 

Try ?getURL in the RCurl package

Dieter



--
View this message in context: 
http://r.789695.n4.nabble.com/loading-R-object-files-on-an-RWeb-server-tp3424613p3424761.html
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] Support Counting

2011-04-04 Thread psombe
Hi,
   I'm new to R and trying to some simple analysis. I have a data set with
about 88000 transactions and i want to perform a simple support count
analysis of an itemset which is say not a complete transaction but a subset
of a transaction.
say

{A,B,D} is a transaction and i want to find support of {A,B} even though it
never occurs as only A,B in the entire set


 To this i needed to create a new itemsets class and then use the support
function but somehow the answers never seem to tally.

Thanks in advance
Srinivas

--
View this message in context: 
http://r.789695.n4.nabble.com/Support-Counting-tp3424730p3424730.html
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] Structural equation modeling in R(lavaan,sem)

2011-04-04 Thread yrosseel

On 04/03/2011 09:38 PM, jouba wrote:


Daer all, I have a question concerning longitudinal data: When we
have a longitudinal data and we have to do sem analysis there is in
the package lavaan some functions,options in this package that help
to do this or we can treat these data like non longitudinal data


The function 'growth' (in the lavaan package) can be used for (standard) 
growth modeling. Good material about growth modeling (using Mplus) can 
be found here:


http://statistics.ats.ucla.edu/stat/mplus/seminars/gm/default.htm

Next, you can read how to do growth modeling with lavaan by reading 
section 7 in the lavaan intro, which you can download from the 
documentation section on the lavaan website (http://lavaan.org).


Yves.

--
Yves Rosseel -- http://www.da.ugent.be
Department of Data Analysis, Ghent University
Henri Dunantlaan 1, B-9000 Gent, Belgium

__
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] multiple variables Y and X

2011-04-04 Thread Rosario Garcia Gil
Hello

I have a model with several hundred Y variables, and also several 1000 X 
variables. The model is linear lm(Y ~ X). My questions are:

1.- how to avoid writing all Xs variables? is list() the right function?

2.- about the multiple Ys with dependence among some of them, how to 
incorporate that information in the linear model?

Thank you

Rosario
__
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] MySql Versus R

2011-04-04 Thread Henri Mone
Dear All,

Thank you to all of you for your fast reply. I will run the test and
subscribe to the R-sig-db list.

Cheers,
Henri

__
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] RmetricsTools.R

2011-04-04 Thread Martin Maechler
 LFP == Luis Felipe Parra felipe.pa...@quantil.com.co
 on Mon, 4 Apr 2011 14:32:32 +0800 writes:

LFP Hello I read on the Rmetrics webpage that all the
LFP development packages could be intalled using the
LFP following command

LFP  source(RmetricsTools.R)
LFP install.RmetricsDev([Rmetrics package to be installed]


LFP I would like to know where I could get this
LFP RmetricsTools.R . I suppose it might be somewhere on
LFP R-Forge but I haven't been able to find it. Thank you

It's  top-level.

With the standard subversion client, 
you can get it, e.g., by

  svn export 
svn://svn.r-forge.r-project.org/svnroot/rmetrics/pkg/RmetricsTools.R

--
Martin Maechler, ETH Zurich

__
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] Error in color2D.matplot : Error in plot.new() : figure margins too large

2011-04-04 Thread Jim Lemon

On 04/03/2011 10:02 PM, shahab wrote:

Hi,

I am using color2D.matplot (...) function of plotrix package. I used
a matrix of size  around 20*20
However, apparently it failed to visualize the matrix and gave the
following exception, which I don't have any idea about possible source
of this error.

  Error in plot.new() : figure margins too large

It would be appreciated if someone points me to the right origin of this error.


Hi Shahab,
If you could send me the data you used (real or fake, as long as it 
produces the error), I'll try to work out what has happened.


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.


[R] svd

2011-04-04 Thread nuncio m
Dear list,
I searched the libraries but could not find means to compute the
svd of a coupled field. Is it possible in R

Thanks
nuncio
-- 
Nuncio.M
Research Scientist
National Center for Antarctic and Ocean research
Head land Sada
Vasco da Gamma
Goa-403804

[[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] power of 2 way ANOVA with interaction

2011-04-04 Thread peter dalgaard

On Apr 4, 2011, at 01:10 , Timothy Spier wrote:

 
 I've been searching for an answer to this for a while but no joy. I have a 
 simple 2-way ANOVA with an interaction. I'd like to determine the power of 
 this test for each factor (factor A, factor B, and the A*B interaction). How 
 can I do this in R? I used to do this with proc Glmpower in SAS, but I can 
 find no analogue in R.

They're not massively hard to do by hand, if you know what you're doing (which, 
admittedly is a bit hard to be sure of in this case). The basic structure can 
be lifted from power.anova.test and the name of the game is to work out the 
noncentrality parameter of the  relevant F tests. E.g., lifting an example from 
the SAS manual:

 twoway - 
 cbind(expand.grid(ex=factor(1:2),var=factor(1:3)),x=c(14,10,16,15,21,16))
 with(twoway,tapply(x,list(ex,var),mean))
   1  2  3
1 14 16 21
2 10 15 16

Now, you have 10 replicates of this with a specified SD of 5. If we do a 
skeleton analysis of the above table, we get

 anova(lm(x~ex*var,twoway))
Analysis of Variance Table

Response: x
  Df Sum Sq Mean Sq F value Pr(F)
ex 1 16.667 16.6667   
var2 42.333 21.1667   
ex:var 2  4.333  2.1667   
Residuals  0  0.000   
Warning message:
In anova.lm(lm(x ~ ex * var, twoway)) :
  ANOVA F-tests on an essentially perfect fit are unreliable

In a 10-fold replication, the SS would be 10 times bigger, and the residual Df 
would be 54; also, we need to take the error variance of 5^2 = 25 into account. 
The noncentrality for the interaction term is thus 43.333/25 and you can work 
out the power as

 pf(qf(.95,2,54),2,54,ncp=43.333/25,lower=F)
[1] 0.1914457

Similarly, the main effect powers are

 pf(qf(.95,2,54),2,54,423.333/25,lower=F)
[1] 0.956741
 pf(qf(.95,1,54),1,54,166.7/25,lower=F)
[1] 0.7176535

(whatever that means in the presence of interaction, but that is a different 
discussion)


-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] svd

2011-04-04 Thread nuncio m
Thanks juan, I got that, but what I have two matrices A and B,  How can an
svd be performed on the two together.  Is it correct to get the covariance
matrix and then perform the svd on the covariance matrix. If that is the
case I have another doubt.  I understand the covariance of A and B is
t(A)%*%B.  but this differs significantly from cov(A,B).
Thanks
nuncio

2011/4/4 Juan Carlos Borrás jcbor...@gmail.com

 m - matrix(c(1:12), nrow=3, ncol=4)
 svd(m)



 On Mon, Apr 4, 2011 at 11:51 AM, nuncio m nunci...@gmail.com wrote:
  Dear list,
 I searched the libraries but could not find means to compute
 the
  svd of a coupled field. Is it possible in R
 
  Thanks
  nuncio
  --
  Nuncio.M
  Research Scientist
  National Center for Antarctic and Ocean research
  Head land Sada
  Vasco da Gamma
  Goa-403804
 
 [[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.
 



 --
 Cheers,
 jcb!
 ___
 http://twitter.com/jcborras




-- 
Nuncio.M
Research Scientist
National Center for Antarctic and Ocean research
Head land Sada
Vasco da Gamma
Goa-403804

[[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] multiple variables Y and X

2011-04-04 Thread Carlos Ortega
Hello,

You can do that like in the example included in the function step()

lm1 - lm(Fertility ~ ., data = swiss)


But my advise is that prior to doing that, you should check this old
thread in this list:

http://tolstoy.newcastle.edu.au/R/e4/help/08/02/2842.html


Regards,
Carlos Ortega
www.qualityexcellence.es

On Mon, Apr 4, 2011 at 8:58 AM, Rosario Garcia Gil
m.rosario.gar...@slu.sewrote:

 Hello

 I have a model with several hundred Y variables, and also several 1000 X
 variables. The model is linear lm(Y ~ X). My questions are:

 1.- how to avoid writing all Xs variables? is list() the right function?

 2.- about the multiple Ys with dependence among some of them, how to
 incorporate that information in the linear model?

 Thank you

 Rosario
 __
 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] Support Counting

2011-04-04 Thread Petr Savicky
On Mon, Apr 04, 2011 at 01:11:37AM -0500, psombe wrote:
 Hi,
I'm new to R and trying to some simple analysis. I have a data set with
 about 88000 transactions and i want to perform a simple support count
 analysis of an itemset which is say not a complete transaction but a subset
 of a transaction.
 say
 
 {A,B,D} is a transaction and i want to find support of {A,B} even though it
 never occurs as only A,B in the entire set
 
 
  To this i needed to create a new itemsets class and then use the support
 function but somehow the answers never seem to tally.

Hi.

The answer depends on the representation of the data set. Can you
describe the representation?

A possible representation of a data set for itemsets counting is a matrix
of 0/1. Using this representation, computing the support may be done
as follows.

  db - matrix(0, nrow=5, ncol=5, dimnames=list(NULL, LETTERS[1:5]))
  db[1, c(A, B, D)] - 1
  db[2, c(A, B)] - 1
  db[3, c(A, D, E)] - 1
  db[4, c(B, C, D)] - 1
  db[5, c(A, B, C)] - 1
  db

   A B C D E
  [1,] 1 1 0 1 0
  [2,] 1 1 0 0 0
  [3,] 1 0 0 1 1
  [4,] 0 1 1 1 0
  [5,] 1 1 1 0 0

  itemset - c(A, B)
 
  # for each transaction, whether it contains c(A, B)
  rowSums(db[, itemset]) == length(itemset)

  [1]  TRUE  TRUE FALSE FALSE  TRUE
 
  # the number of transactions containing c(A, B)
  sum(rowSums(db[, itemset]) == length(itemset))

  [1] 3

Hope this helps.

Petr Savicky.

__
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] another question on shapefiles and geom_point in ggplot2

2011-04-04 Thread ahmadou dicko
Hi all
Just as Pierre pointed out, i used rgeos instead of gpclib (the licence is
less restrictive even though i'm still students). A since the last release
the rgeos package seems to work well.
I'm really disapointed by the fact that some packages (e.g adehabitatMA
which is great thank's M. Calenge) still use gpclib and don't  offer the
possibility to switch to rgeos, and is really messy to have two package to
do the same task and with the same function name in the path (eg when  i use
adehabitatMA and maptools).

Manuel:
May be you should use the *colour* aesthetic instead of* *the* fill *one* *in
the call of *geom_path*. Something like that :

p = ggplot(geo, aes(x, y))
p + geom_point(aes(size = ACE, colour = ACE)) + theme_bw() + scale_size(name
= Número de especies, breaks = c(2, 4, 6, 8, 10, 12, 14, 16, 18, 20)) +
scale_colour_gradientn(name = 'Número de especies', colours =
heat.colors(10), breaks = c(2, 4, 6, 8, 10, 12, 14, 16, 18, 20))+
xlab(Longitud) + ylab(Latitud) + opts(axis.text.x = theme_text(size = 8,
vjust = 1)) + opts(axis.text.y = theme_text(size = 8, hjust = 1)) +
geom_path(aes(x=long,y=lat, group=group, *colour=id*
),data=fortify.ai_biotica)

not tested, so i'm not really sure about this one

2011/4/4 Pierre Roudier pierre.roud...@gmail.com

 Hi all,

 2011/4/4 Felipe Carrillo mazatlanmex...@yahoo.com:
  Manuel:
  As far as I know one needs gpclibPermit() in order to fortify
  see this:
  Note: polygon geometry computations in maptools
  depend on the package gpclib, which has a
  restricted licence. It is disabled by default;
  to enable gpclib, type gpclibPermit()
  I am going to guess that ahmadou dicko doesn't show gpclibPermit() on his
  code
  because he loaded it with Rprofile or some other way. I tried to run his
  code without
  gpclibPermit() and it wouldn't let me fortify, so not sure how he did it.

 On that specific point, Colin Arundel and Roger Bivant released the
 rgeos package on CRAN a few days [1]. This is a great achievement as
 it brings bindings to the GEOS C++ lib [2] - long story short, it
 makes the job the non-free [3] gpclib used to do.

 In its later release, maptools has an option to check if rgeos if
 present - if it is the case it is used instead of gpclib:

  library(maptools)
 Loading required package: foreign
 Loading required package: sp
 Loading required package: lattice

Note: polygon geometry computations in maptools
depend on the package gpclib, which has a
restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()

 Checking rgeos availability as gpclib substitute:
 TRUE
  ?gpclibPermit

 Pierre

 [1] http://cran.r-project.org/web/packages/rgeos/
 [2] http://trac.osgeo.org/geos/
 [3] https://stat.ethz.ch/pipermail/r-sig-geo/2010-January/007400.html
 --
 Scientist
 Landcare Research, New Zealand

 --
 You received this message because you are subscribed to the ggplot2 mailing
 list.
 Please provide a reproducible example: http://gist.github.com/270442

 To post: email ggpl...@googlegroups.com
 To unsubscribe: email ggplot2+unsubscr...@googlegroups.com
 More options: http://groups.google.com/group/ggplot2


[[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] Deriving formula with deriv

2011-04-04 Thread kitty
Dear list,

Hi,

I am trying to get the second derivative of a logistic formula, in R summary
the model is given as :

###
$nls
Nonlinear regression model
  model:  data ~ logistic(time, A, mu, lambda, addpar)
   data:  parent.frame()
  A  mu  lambda
0.53243 0.03741 6.94296
###

but I know the formula used is

# y~'A'/(1+exp((4*'mu'/'A')*('lambda'-'time'))+2))# from the grofit (
package I am using to fit the model) documentation.

I have attempted to use the R function 'deriv' to get the
first derivative from which I can then reuse the deriv function to get the
second derivative unfortunately this does not seem to work

###
express-expression(y~'A'/(1+exp((4*'mu'/'A')*('lambda'-'time'))+2))
 express
expression(y ~ A/(1 + exp((4 * mu/A) * (lambda - time)) +
2))

 d1-deriv(express)
Error in deriv.default(express) : element 2 is empty;
   the part of the args list of '.Internal' being evaluated was:
   (expr, namevec, function.arg, tag, hessian)
 

Why is this not working and how do I get the second derivative?

Thank you for reading my post, all help is appreciated,
Kitty

[[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] add zero in front of numbers

2011-04-04 Thread Yan Jiao
Dear R users,

I need to add 0 in front of a series of numbers, e.g. 1-001, 19-019,
Is there a fast way of doing that?

Many thanks

yan

[[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] add zero in front of numbers

2011-04-04 Thread Luis Ridao
Have a look at

?formatC

On Mon, Apr 4, 2011 at 11:35 AM, Yan Jiao y.j...@ucl.ac.uk wrote:

 Dear R users,

 I need to add 0 in front of a series of numbers, e.g. 1-001, 19-019,
 Is there a fast way of doing that?

 Many thanks

 yan

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


[[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] principal components

2011-04-04 Thread Gavin Simpson
On Fri, 2011-04-01 at 11:52 +0530, nuncio m wrote:
 HI all,
  I am trying to compute the EOF of a matrix using prcomp but unable to get
 the expansion co-efficients.
 is it possible using prcomp or are there any other methods
 thanks
 nuncio
 

*sigh*

 RSiteSearch(EOF)

It is at times like this that an R equivalent of:

http://lmgtfy.com/

would be handy ;-)

Or it slightly cruder cousin...

G
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
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] Clarks 2Dt function in R

2011-04-04 Thread bialozyt
Dear Ben,

you answerd to Nancy Shackelford about Clarks 2Dt function.
Since the thread ended just after your reply,
I would like to ask, if you have an idea how to use this function in R

I defined it the following way:

function(x , p, u) {
  (p/(pi*u))*(1+(x^2/u))^(p+1)
}

and would like to fit this one to my obeservational data (count)

   [,1] [,2]
 [1,]   15   12
 [2,]   45   13
 [3,]   75   10
 [4,]  1058
 [5,]  135   16
 [6,]  1655
 [7,]  195   15
 [8,]  2258
 [9,]  2559
[10,]  285   12
[11,]  3155
[12,]  3454
[13,]  3751
[14,]  4051
[15,]  4351
[16,]  4650
[17,]  4951
[18,]  5252
[19,]  5550
[20,]  5850
[21,]  6150
[22,]  6450
[23,]  6750

but I am not able to fit anything.
Do you have an idea?
I guess there is something wrong in my formula for Clarks 2Dt

Thank you for reading 

Ciao
Ronald Bialozyt

__
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] Please help

2011-04-04 Thread Sadaf Zaidi
Dear Sir/Madam,
I am stuck with a nagging problem in using R for SVM regression. My data has 5
dimensions and 400 observations. The independent variables are :
Peb, Ksub, Sub, and Xtt.
The dependent variable is: Rexp.
I tried using the svm.tune function to tune the hyper parameters: gamma, 
epsilon and C. 
I am getting the following error message:
Error in predict.svm(ret, xhold, decision.values+TRUE): Model is empty!
May you please help me!
SADAF ZAIDI
Associate Professor
Department of
Aligarh Muslim University
Aligarh 202002.

__
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 using svm.tune

2011-04-04 Thread sadaf zaidi
Dear Sir,

I am stuck with a nagging problem in using R for SVM regression. My data has 5 
dimensions and 400 observations. The independent variables are :
Peb, Ksub, Sub, and Xtt.
The dependent variable is: Rexp.
I tried using the svm.tune function as well as _tune(svm.), to tune the 
hyper parameters: gamma, epsilon and C. 

Since I am new to R, I am probably not using the svm.tune function properly. I 
am getting the following error message:
Error in predict.svm(ret, xhold, decision.values=TRUE): Model is empty!
May you please help me!SADAF ZAIDI

[[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] ticklabs in scatterplot3d

2011-04-04 Thread suparna mitra
Hello,
I am having a problem to control ticklabs in scatterplot3d. When I am using
it for small data then it is working fine. But with my big data all the
labels are misplaced (one upon another).
For example see the code below (I have just modified the scatterplot3d
example to show my problem ).

==

my.mat - matrix(runif(625), nrow=25)

dimnames(my.mat) - list(LETTERS[1:25], letters[1:25])

my.mat # this matrix I want to plot with the all 25 ticklabs

scatterplot3d(s3d.dat, type=h, lwd=1, pch= ,x.ticklabs=colnames(my.mat),
y.ticklabs=rownames(my.mat))

==
I want all 25 labels to be written in y.ticklabs
Can anyone please help me?
Thank you very much,
Suparna.

[[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] add zero in front of numbers

2011-04-04 Thread January Weiner
Dear Yan,

apart from formatC, you can also use sprintf, which works almost
exactly like the C sprintf function. To convert an integer x to a
string with 5 leading 0s, you do:

sprintf( %05d, x )

Best regards,

j.

On Mon, Apr 4, 2011 at 12:35 PM, Yan Jiao y.j...@ucl.ac.uk wrote:
 Dear R users,

 I need to add 0 in front of a series of numbers, e.g. 1-001, 19-019,
 Is there a fast way of doing that?

 Many thanks

 yan

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




-- 
 Dr. January Weiner 3 --
Max Planck Institute for Infection Biology
Charitéplatz 1
D-10117 Berlin, Germany
Web   : www.mpiib-berlin.mpg.de
Tel     : +49-30-28460514

__
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] lattice: how to center a subtitle?

2011-04-04 Thread Marius Hofert
Dear expeRts,

I recently asked for a real centered title (see, e.g., 
http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html). 
A nice solution (from Deepayan Sarkar) is to use xlab.top instead of main:

library(lattice)
trellis.device(pdf) 
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
eye, sub = but subtitles are not centered, scales = list(alternating = 
c(1,1), tck = c(1,0 
dev.off()

My question is whether there is something similar for *sub*titles [so something 
like xlab.bottom]? As you can see from the plot, the subtitle does not seem 
to be centered for the human's eye. I would like to center it according to 
the x-axis label. 

Cheers,

Marius
__
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] system() command in R

2011-04-04 Thread rasanpreet kaur suri
Hi all,
I have a local server insalled on my system and have to start that from
within my R function.

here is how I start it:

cmd-sh start-server.sh

system(cmd, wait=FALSE)

My function has to start the server and proceed with further steps. The
server starts but the further steps of the program are not executed.The
cursor keeps waiting after the server is started.

i tried removing the wait=FALSE, but it still keeps waiting.

I also tried putting the start-server in a separate function and my further
script in a separate function and then run them together, but it still
waits. The transition from the start of server to next step is not
happening.

Please help. I have been stuck on this for quite some time now.

-- 
Rasanpreet Kaur

[[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] another question on shapefiles and geom_point in ggplot2

2011-04-04 Thread Manuel Spínola
Thank you Ahmadou,

I got an error when I change fill to colour:

  p + geom_point(aes(size = ACE, colour = ACE)) + theme_bw() +
+  scale_size(to = c(3, 15), name = Número de especies, breaks = c(10, 
40, 70, 100, 130, 160, 190, 220, 250)) +
+  scale_colour_gradientn(name = 'Número de especies', colours = 
heat.colors(9), breaks = c(10, 40, 70, 100, 130, 160, 190, 220, 250)) + 
xlab(Longitud) + ylab(Latitud) +
+  opts(axis.text.x = theme_text(size = 8, vjust = 1)) + 
opts(axis.text.y = theme_text(size = 8, hjust = 1)) +
+  geom_path(aes(x=long,y=lat,group=group, 
colour=id),data=fortify.ai_biotica)
Error: Non-continuous variable supplied to scale_colour_gradientn.

Best,

Manuel

On 04/04/2011 03:37 a.m., ahmadou dicko wrote:
 Hi all
 Just as Pierre pointed out, i used rgeos instead of gpclib (the 
 licence is less restrictive even though i'm still students). A since 
 the last release the rgeos package seems to work well.
 I'm really disapointed by the fact that some packages (e.g 
 adehabitatMA which is great thank's M. Calenge) still use gpclib and 
 don't  offer the possibility to switch to rgeos, and is really messy 
 to have two package to do the same task and with the same function 
 name in the path (eg when  i use adehabitatMA and maptools).

 Manuel:
 May be you should use the *colour* aesthetic instead of**the*fill 
 *one**in the call of *geom_path*. Something like that :

 p = ggplot(geo, aes(x, y))
 p + geom_point(aes(size = ACE, colour = ACE)) + theme_bw() + 
 scale_size(name = Número de especies, breaks = c(2, 4, 6, 8, 10, 12, 
 14, 16, 18, 20)) + scale_colour_gradientn(name = 'Número de especies', 
 colours = heat.colors(10), breaks = c(2, 4, 6, 8, 10, 12, 14, 16, 18, 
 20))+ xlab(Longitud) + ylab(Latitud) + opts(axis.text.x = 
 theme_text(size = 8, vjust = 1)) + opts(axis.text.y = theme_text(size 
 = 8, hjust = 1)) + geom_path(aes(x=long,y=lat, group=group, 
 *colour=id*),data=fortify.ai_biotica)

 not tested, so i'm not really sure about this one

 2011/4/4 Pierre Roudier pierre.roud...@gmail.com 
 mailto:pierre.roud...@gmail.com

 Hi all,

 2011/4/4 Felipe Carrillo mazatlanmex...@yahoo.com
 mailto:mazatlanmex...@yahoo.com:
  Manuel:
  As far as I know one needs gpclibPermit() in order to fortify
  see this:
  Note: polygon geometry computations in maptools
  depend on the package gpclib, which has a
  restricted licence. It is disabled by default;
  to enable gpclib, type gpclibPermit()
  I am going to guess that ahmadou dicko doesn't show
 gpclibPermit() on his
  code
  because he loaded it with Rprofile or some other way. I tried to
 run his
  code without
  gpclibPermit() and it wouldn't let me fortify, so not sure how
 he did it.

 On that specific point, Colin Arundel and Roger Bivant released the
 rgeos package on CRAN a few days [1]. This is a great achievement as
 it brings bindings to the GEOS C++ lib [2] - long story short, it
 makes the job the non-free [3] gpclib used to do.

 In its later release, maptools has an option to check if rgeos if
 present - if it is the case it is used instead of gpclib:

  library(maptools)
 Loading required package: foreign
 Loading required package: sp
 Loading required package: lattice

Note: polygon geometry computations in maptools
depend on the package gpclib, which has a
restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()

 Checking rgeos availability as gpclib substitute:
 TRUE
  ?gpclibPermit

 Pierre

 [1] http://cran.r-project.org/web/packages/rgeos/
 [2] http://trac.osgeo.org/geos/
 [3] https://stat.ethz.ch/pipermail/r-sig-geo/2010-January/007400.html
 --
 Scientist
 Landcare Research, New Zealand

 --
 You received this message because you are subscribed to the
 ggplot2 mailing list.
 Please provide a reproducible example: http://gist.github.com/270442

 To post: email ggpl...@googlegroups.com
 mailto:ggpl...@googlegroups.com
 To unsubscribe: email ggplot2+unsubscr...@googlegroups.com
 mailto:ggplot2%2bunsubscr...@googlegroups.com
 More options: http://groups.google.com/group/ggplot2




-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.ac.cr
mspinol...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río 
https://sites.google.com/site/lobitoderio/
Institutional website: ICOMVIS http://www.icomvis.una.ac.cr/

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

[R] moving mean and moving variance functions

2011-04-04 Thread Steve Friedman
Hello


Lets say as an example I have a dataframe with the following attributes:
rownum(1:405), colnum(1:287), year(2000:2009), daily(rownum x colnum x year)
and foragePotential (0:1, by 0.01).  The data is actually stored in a netcdf
file and I'm trying to provide a conceptual version of the data.

Ok. I need to calculate a moving mean and a moving variance for each cell on
the following temporal
windows - 7 day, 14 day, and 28 day. So far I have code for the moving
average.

ma - function(x , n) {
  filter(x, rep(1/n, n), sides = 1)
  }   # note that when the function is used, n is defined for the
temporal period (7, 14, and 28), and x is the input variable.


ma7 -   ma(dat, 7)  # where dat is accessing the foraging potential of the
birds.
ma14 - ma(dat, 14)
ma28 - ma(dat, 28)

This works fine.  What I don't have is the code for a moving variance.

filter in the function above is included in the stats package and conducts a
linear filtering on a Time Series.

Is there comparable code some place in R for a moving variance?

Thanks in advance.

Thanks,
Steve

[[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] Examples of web-based Sweave use?

2011-04-04 Thread carslaw
I appreciate that this is OT, but I'd be grateful for pointers to examples of
where 
Sweave has been used for web-based applications.  In particular, examples of 
where reports/analyses are produced automatically through submission of data 
to a web-sever.  I am mostly interested in situations where pdf reports have 
been produced rather than, say, a plot/table etc shown on a web page.

I've had limited success finding examples on this.

Many thanks.

David Carslaw


Environmental Research Group
MRC-HPA Centre for Environment and Health
King's College London
Franklin Wilkins Building
Stamford Street
London SE1 9NH

david.cars...@kcl.ac.uk


--
View this message in context: 
http://r.789695.n4.nabble.com/Examples-of-web-based-Sweave-use-tp3425324p3425324.html
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] hc2Newick is different than th hclust dendrogram

2011-04-04 Thread Jose Hleap Lozano
Hi R helpers... I am having troubles because of the discrepancy  
between the dendrogram plotted from hclust and what is wrote in the  
hc2Newick file. I've got a matrix C:

hc - hclust(dist(C))
plot(hc)
with the:
write(hc2Newick(hc),file='test.newick')
both things draw completely different trees...

I have also tried with the raw distance matrix D and also the agnes  
function, but the same happens. The hclus and agnes dendrogram is  
logical, whereas the newick tree is not.


Thanks for any help!

PS attached C matrix that is a 112x112 matrix
--
Jose Sergio Hleap Lozano, M. Sc.
Ph. D. Student, Dalhousie University
Researcher, SQUALUS Foundation

__
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] I think I just broke R

2011-04-04 Thread Thomas Rusch


  and time to upgrade R
 
 I'm still fighting to find out how to upgrade stuff on Ubuntu. After
 a 
 repository update the newest available version was still 2.10.1.
 I'll figure it out, sooner or later :)
 

That's simple. Just add 

$deb http://my.favorite.cran.mirror/bin/linux/ubuntu maverick/ 

to /etc/apt/sources.list (or whatever Ubuntu version you use) and type

 $sudo aptitude update
 $sudo aptitude safe-upgrade

See http://cran.r-project.org/bin/linux/ubuntu/

Regards

__
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] moving mean and moving variance functions

2011-04-04 Thread Gabor Grothendieck
On Mon, Apr 4, 2011 at 8:30 AM, Steve Friedman skfgla...@gmail.com wrote:
 Hello


 Lets say as an example I have a dataframe with the following attributes:
 rownum(1:405), colnum(1:287), year(2000:2009), daily(rownum x colnum x year)
 and foragePotential (0:1, by 0.01).  The data is actually stored in a netcdf
 file and I'm trying to provide a conceptual version of the data.

 Ok. I need to calculate a moving mean and a moving variance for each cell on
 the following temporal
 windows - 7 day, 14 day, and 28 day. So far I have code for the moving
 average.

 ma - function(x , n) {
          filter(x, rep(1/n, n), sides = 1)
      }   # note that when the function is used, n is defined for the
 temporal period (7, 14, and 28), and x is the input variable.


 ma7 -   ma(dat, 7)  # where dat is accessing the foraging potential of the
 birds.
 ma14 - ma(dat, 14)
 ma28 - ma(dat, 28)

 This works fine.  What I don't have is the code for a moving variance.

 filter in the function above is included in the stats package and conducts a
 linear filtering on a Time Series.

 Is there comparable code some place in R for a moving variance?


See rollmean and rollapply in the zoo package and runmean and runsd in
the caTools package.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] RGtk2: How to populate an GtkListStore data model?

2011-04-04 Thread Michael Lawrence
On Sun, Apr 3, 2011 at 8:29 PM, Cleber N. Borges kle...@yahoo.com.brwrote:

 hello all
 I am trying to learn how to use the RGtk2 package...
 so, my first problem is: I don't get the right way for populate my
 gtkListStore object!
 any help is welcome... because I am trying several day to mount the code...
 Thanks in advanced
 Cleber N. Borges
 ---
 # my testing code

 library(RGtk2)
 win - gtkWindowNew()
 datamodel - gtkListStoreNew('gchararray')
 treeview - gtkTreeViewNew()
 renderer - gtkCellRendererText()
 col_0 - gtkTreeViewColumnNewWithAttributes(title=TitleXXX,
 cell=renderer, text=Bar)
 nc_next - gtkTreeViewInsertColumn(object=treeview, column=col_0,
 position=0)
 gtkTreeViewSetModel( treeview, datamodel )
 win$add( treeview ) # is there an alternative function for this?

 # iter - gtkTreeModelGetIterFirst( datamodel )[[2]]
 # this function don't give VALID iter
 # gtkListStoreIterIsValid( datamodel, iter )  result in FALSE
 iter - gtkListStoreInsert( datamodel, position=0 )[[2]]
 gtkListStoreIterIsValid( datamodel, iter )

 # the help of this function say to terminated in -1 value
 # but -1 crash the R-pckage (or the gtk)...


Sorry about this. The help is autogenerated from the GTK+ C documentation.


 gtkListStoreSet(object=datamodel, iter=iter, 0, textFoo)
 # don't make any difference in the window... :-(



It would be much easier to use rGtkDataFrame for populating this list. See
the help for that function.


 
 R version 2.13.0 alpha (2011-03-27 r55091)
 Platform: i386-pc-mingw32/i386 (32-bit)

 locale:
 [1] LC_COLLATE=Portuguese_Brazil.1252
 [2] LC_CTYPE=Portuguese_Brazil.1252
 [3] LC_MONETARY=Portuguese_Brazil.1252
 [4] LC_NUMERIC=C
 [5] LC_TIME=Portuguese_Brazil.1252

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

 other attached packages:
 [1] RGtk2_2.20.8

 loaded via a namespace (and not attached):
 [1] tools_2.13.0
 


 my gtk version == 2.16.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.


[[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] Examples of web-based Sweave use?

2011-04-04 Thread Tal Galili
I've written about a bunch of Web R interfaces here:
*
http://www.r-statistics.com/2010/04/jeroen-oomss-ggplot2-web-interface-a-new-version-released-v0-2/
*
http://www.r-statistics.com/2010/04/r-node-a-web-front-end-to-r-with-protovis/
(And some other posts here:
http://www.r-statistics.com/category/r-and-the-web/
)
http://www.r-statistics.com/category/r-and-the-web/I'm not sure which of
them use Sweave behind them, but you could look around and check.

Hope that helps,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Mon, Apr 4, 2011 at 2:31 PM, carslaw david.cars...@kcl.ac.uk wrote:

 I appreciate that this is OT, but I'd be grateful for pointers to examples
 of
 where
 Sweave has been used for web-based applications.  In particular, examples
 of
 where reports/analyses are produced automatically through submission of
 data
 to a web-sever.  I am mostly interested in situations where pdf reports
 have
 been produced rather than, say, a plot/table etc shown on a web page.

 I've had limited success finding examples on this.

 Many thanks.

 David Carslaw


 Environmental Research Group
 MRC-HPA Centre for Environment and Health
 King's College London
 Franklin Wilkins Building
 Stamford Street
 London SE1 9NH

 david.cars...@kcl.ac.uk


 --
 View this message in context:
 http://r.789695.n4.nabble.com/Examples-of-web-based-Sweave-use-tp3425324p3425324.html
 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.


[[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] How to speed up grouping time series, help please

2011-04-04 Thread Den Alpin
I retrieve for a few hundred times a group of time series (10-15 ts
with 1 values each), on every group I do some calculation, graphs
etc. I wonder if there is a faster method than what presented below to
get an appropriate timeseries object.

Making a query with RODBC for every group I get a data frame like this:

 X
   IDDATE VALUE
14  3 2000-01-01 00:00:03 0.5726334
4   1 2000-01-01 00:00:03 0.8830174
1   1 2000-01-01 00:00:00 0.2875775
15  3 2000-01-01 00:00:04 0.1029247
11  3 2000-01-01 00:00:00 0.9568333
9   2 2000-01-01 00:00:03 0.5514350
7   2 2000-01-01 00:00:01 0.5281055
6   2 2000-01-01 00:00:00 0.0455565
12  3 2000-01-01 00:00:01 0.4533342
8   2 2000-01-01 00:00:02 0.8924190
3   1 2000-01-01 00:00:02 0.4089769
13  3 2000-01-01 00:00:02 0.6775706

And I want to get a timeSeries object or xts object like this:

1 2 3
2000-01-01 00:00:00 0.2875775 0.0455565 0.9568333
2000-01-01 00:00:01NA 0.5281055 0.4533342
2000-01-01 00:00:02 0.4089769 0.8924190 0.6775706
2000-01-01 00:00:03 0.8830174 0.5514350 0.5726334
2000-01-01 00:00:04NANA 0.1029247


Input data can be sorted or unsorted (the most complicated case is in
the example, unsorted and missing data) in the sense that I can sort
in query if I can take an advantage from this.

Some considerations:
- Xts is generally faster than timeSeries
- both accept a matrix so if I can create a matrix like the one
represented above and an array of characters representing dates faster
than what possible with xts:::cbind, for examole,I will have a faster
implementation (package data.table ?).
- create timeseries objects in multithread and then merge (package plyr ?)
- faster merge algorithms?

Below some code to generate the test case above:


set.seed(123)
N - 5 # number of observations
K - 3 # number of timeseries ID

X - data.frame(
  ID = rep(1:K, each = N),
  DATE = as.character(rep(as.POSIXct(2000-01-01, tz = GMT)+ 0:(N-1), K)),
  VALUE = runif(N*K), stringsAsFactors = FALSE)

X - X[sample(1:(N*K), N*K),] # sample observations to get random
order (optional)
X - X[-(sample(1:nrow(X), floor(nrow(X)*0.2))),] # 20% missing

head(X, 15)

# use explicitly environments to avoid '-'
buildTimeSeriesFromDataFrame - function(x, env)
{
  {
if(exists(xx, envir = env)) # if exist variable xx in env cbind
  assign(xx,
cbind(get(xx, env), timeSeries(x$VALUE, x$DATE,
  format = '%Y-%m-%d %H:%M:%S',
  zone = 'GMT', units = as.character(x$ID[1]))),
envir = env)
else  # create xx in env
  assign(xx,
timeSeries(x$VALUE, x$DATE, format = '%Y-%m-%d %H:%M:%S',
  zone = 'GMT', units = as.character(x$ID[1])),
envir = env)

return(TRUE)
  }
}

# use package plyr, faster than 'by' function
tsDaply - function(...)
{
  library(plyr)
  e1 - new.env(parent = baseenv()) #create a new env
  res - daply(X, ID, buildTimeSeriesFromDataFrame,
  env = e1)
  return(get(xx, e1)) # return xx from env
}

##replicate 100 times
#Time03 - replicate(100,
#  system.time(tsDaply(X, X$ID))[[1]])
#median(Time03)

# result
tsDaply(X, X$ID)


Thanks in advance for any input, best regards,
Den

__
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] reading from text file that have different rowlength and create a data frame

2011-04-04 Thread Ram H. Sharma
Hi R-experts

I have many text files to read and combined them into one into R that are
output from other programs. My textfile have unbalanced number of rows for
example:

;this is example
; r help
Var1 Var2  Var3  Var4  Var5
0 0.05 0.0112
1 0.04 0.0618A
2 0.05 0.0814
3 0.01 0.0615   B
4 0.05 0.0714   C

and so on
Inames-as.data.frame(read.table(CLG1mpd.asc,header=T,comment=;))
Inames-as.matrix(read.table(example.txt,header=T,comment=;))
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
:
  line 1 did not have 5 elements


In bestcase scenerio, I want to fill the blank space with NA's, with matrix
or dataframe
 Var1 Var2  Var3  Var4  Var5
0 0.05 0.0112NA
1 0.04 0.0618A
2 0.05 0.0814   NA
3 0.01 0.0615   B
4 0.05 0.0714   C

The minimum would be to  remove the column Var5, so that my data.frame would
look like the follows:
 Var1 Var2  Var3  Var4
0 0.05 0.0112
1 0.04 0.0618
2 0.05 0.0814
3 0.01 0.0615
4 0.05 0.0714
-- 
Thank you in advance for the help.

Ram H

[[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] gap.barplot doesn't support data arrays?

2011-04-04 Thread Andrew D. Steen
I am trying to make a barplot with a broken axis using gap.barplot (in the
indispensable plotrix package).  This works well when the data is a vector:

 twogrp-c(rnorm(10)+4,rnorm(10)+20)
 gap.barplot(twogrp,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),ylab=Group
values,main=Barplot with gap)

But when the data is an array (for a bar plot with multiple series) I get an
error and a strange plot with no y-tics and bars stretching downwards, as if
all the values were negative:

 twogrp2-array(twogrp, dim=c(2,5))

gap.barplot(twogrp2,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),ylab=Group
values,main=Barplot with gap)

Error in rect(xtics[bigones] - halfwidth, botgap, xtics[bigones] +
halfwidth,  : 
  cannot mix zero-length and non-zero-length coordinates

However, the main title and axis labels do appear correctly.

Are data arrays unsupported for gap.barplot, or am I missing something?

Thanks,
Drew Steen

__
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] reading from text file that have different rowlength and create a data frame

2011-04-04 Thread jim holtman
?read.table

Then look at the 'fill'  'flush' parameters; this may do the trick

On Mon, Apr 4, 2011 at 9:32 AM, Ram H. Sharma sharma.ra...@gmail.com wrote:
 Hi R-experts

 I have many text files to read and combined them into one into R that are
 output from other programs. My textfile have unbalanced number of rows for
 example:

 ;this is example
 ; r help
 Var1     Var2      Var3      Var4      Var5
 0             0.05     0.01        12
 1             0.04     0.06        18        A
 2             0.05     0.08        14
 3             0.01     0.06        15       B
 4             0.05     0.07        14       C

 and so on
 Inames-as.data.frame(read.table(CLG1mpd.asc,header=T,comment=;))
 Inames-as.matrix(read.table(example.txt,header=T,comment=;))
 Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
 :
  line 1 did not have 5 elements


 In bestcase scenerio, I want to fill the blank space with NA's, with matrix
 or dataframe
  Var1     Var2      Var3      Var4      Var5
 0             0.05     0.01        12        NA
 1             0.04     0.06        18        A
 2             0.05     0.08        14       NA
 3             0.01     0.06        15       B
 4             0.05     0.07        14       C

 The minimum would be to  remove the column Var5, so that my data.frame would
 look like the follows:
  Var1     Var2      Var3      Var4
 0             0.05     0.01        12
 1             0.04     0.06        18
 2             0.05     0.08        14
 3             0.01     0.06        15
 4             0.05     0.07        14
 --
 Thank you in advance for the help.

 Ram H

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




-- 
Jim Holtman
Data Munger Guru

What is the problem that 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] Difference in mixture normals and one density

2011-04-04 Thread Jim Silverton
Hello,
I am trying to find out if R can do the following:

I have a mixture of normals say f = 0.2*Normal(2, 5) + 0.8*Normal(3,2)
How do I find the difference in the densities at any particular point of f
and at Normal(2,5)?

-- 
Thanks,
Jim.

[[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] reading from text file that have different rowlength and create a data frame

2011-04-04 Thread jim holtman
try this:

 x - read.table(textConnection(;this is example
+ ; r help
+ Var1 Var2  Var3  Var4  Var5
+ 0 0.05 0.0112
+ 1 0.04 0.0618A
+ 2 0.05 0.0814
+ 3 0.01 0.0615   B
+ 4 0.05 0.0714   C)
+ , comment = ';'
+ , fill = TRUE
+ , header = TRUE
+ , na.strings = ''
+ )
 closeAllConnections()

 x
  Var1 Var2 Var3 Var4 Var5
10 0.05 0.01   12 NA
21 0.04 0.06   18A
32 0.05 0.08   14 NA
43 0.01 0.06   15B
54 0.05 0.07   14C


On Mon, Apr 4, 2011 at 9:32 AM, Ram H. Sharma sharma.ra...@gmail.com wrote:
 Hi R-experts

 I have many text files to read and combined them into one into R that are
 output from other programs. My textfile have unbalanced number of rows for
 example:

 ;this is example
 ; r help
 Var1     Var2      Var3      Var4      Var5
 0             0.05     0.01        12
 1             0.04     0.06        18        A
 2             0.05     0.08        14
 3             0.01     0.06        15       B
 4             0.05     0.07        14       C

 and so on
 Inames-as.data.frame(read.table(CLG1mpd.asc,header=T,comment=;))
 Inames-as.matrix(read.table(example.txt,header=T,comment=;))
 Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
 :
  line 1 did not have 5 elements


 In bestcase scenerio, I want to fill the blank space with NA's, with matrix
 or dataframe
  Var1     Var2      Var3      Var4      Var5
 0             0.05     0.01        12        NA
 1             0.04     0.06        18        A
 2             0.05     0.08        14       NA
 3             0.01     0.06        15       B
 4             0.05     0.07        14       C

 The minimum would be to  remove the column Var5, so that my data.frame would
 look like the follows:
  Var1     Var2      Var3      Var4
 0             0.05     0.01        12
 1             0.04     0.06        18
 2             0.05     0.08        14
 3             0.01     0.06        15
 4             0.05     0.07        14
 --
 Thank you in advance for the help.

 Ram H

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




-- 
Jim Holtman
Data Munger Guru

What is the problem that 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] How to speed up grouping time series, help please

2011-04-04 Thread Joshua Ulrich
Hi Dan,

On Mon, Apr 4, 2011 at 7:49 AM, Den Alpin den.al...@gmail.com wrote:
 I retrieve for a few hundred times a group of time series (10-15 ts
 with 1 values each), on every group I do some calculation, graphs
 etc. I wonder if there is a faster method than what presented below to
 get an appropriate timeseries object.

 Making a query with RODBC for every group I get a data frame like this:

 X
   ID                DATE     VALUE
 14  3 2000-01-01 00:00:03 0.5726334
 4   1 2000-01-01 00:00:03 0.8830174
 1   1 2000-01-01 00:00:00 0.2875775
 15  3 2000-01-01 00:00:04 0.1029247
 11  3 2000-01-01 00:00:00 0.9568333
 9   2 2000-01-01 00:00:03 0.5514350
 7   2 2000-01-01 00:00:01 0.5281055
 6   2 2000-01-01 00:00:00 0.0455565
 12  3 2000-01-01 00:00:01 0.4533342
 8   2 2000-01-01 00:00:02 0.8924190
 3   1 2000-01-01 00:00:02 0.4089769
 13  3 2000-01-01 00:00:02 0.6775706

 And I want to get a timeSeries object or xts object like this:

                            1         2         3
 2000-01-01 00:00:00 0.2875775 0.0455565 0.9568333
 2000-01-01 00:00:01        NA 0.5281055 0.4533342
 2000-01-01 00:00:02 0.4089769 0.8924190 0.6775706
 2000-01-01 00:00:03 0.8830174 0.5514350 0.5726334
 2000-01-01 00:00:04        NA        NA 0.1029247


 Input data can be sorted or unsorted (the most complicated case is in
 the example, unsorted and missing data) in the sense that I can sort
 in query if I can take an advantage from this.

 Some considerations:
 - Xts is generally faster than timeSeries
 - both accept a matrix so if I can create a matrix like the one
 represented above and an array of characters representing dates faster
 than what possible with xts:::cbind, for examole,I will have a faster
 implementation (package data.table ?).
 - create timeseries objects in multithread and then merge (package plyr ?)
 - faster merge algorithms?

 Below some code to generate the test case above:


 set.seed(123)
 N - 5 # number of observations
 K - 3 # number of timeseries ID

 X - data.frame(
  ID = rep(1:K, each = N),
  DATE = as.character(rep(as.POSIXct(2000-01-01, tz = GMT)+ 0:(N-1), K)),
  VALUE = runif(N*K), stringsAsFactors = FALSE)

 X - X[sample(1:(N*K), N*K),] # sample observations to get random
 order (optional)
 X - X[-(sample(1:nrow(X), floor(nrow(X)*0.2))),] # 20% missing

 head(X, 15)

 # use explicitly environments to avoid '-'
 buildTimeSeriesFromDataFrame - function(x, env)
 {
  {
    if(exists(xx, envir = env)) # if exist variable xx in env cbind
      assign(xx,
        cbind(get(xx, env), timeSeries(x$VALUE, x$DATE,
          format = '%Y-%m-%d %H:%M:%S',
          zone = 'GMT', units = as.character(x$ID[1]))),
        envir = env)
    else  # create xx in env
      assign(xx,
        timeSeries(x$VALUE, x$DATE, format = '%Y-%m-%d %H:%M:%S',
          zone = 'GMT', units = as.character(x$ID[1])),
        envir = env)

    return(TRUE)
  }
 }

 # use package plyr, faster than 'by' function
 tsDaply - function(...)
 {
  library(plyr)
  e1 - new.env(parent = baseenv()) #create a new env
  res - daply(X, ID, buildTimeSeriesFromDataFrame,
      env = e1)
  return(get(xx, e1)) # return xx from env
 }

 ##replicate 100 times
 #Time03 - replicate(100,
 #  system.time(tsDaply(X, X$ID))[[1]])
 #median(Time03)

 # result
 tsDaply(X, X$ID)


 Thanks in advance for any input, best regards,
 Den



Here's how I would do it with xts:

x - xts(X[,c(ID,VALUE)], as.POSIXct(X[,DATE]))
do.call(merge, split(x$VALUE,x$ID))

My xts solution compares favorably to your solution:
 Time03 - replicate(100,
+   system.time(tsDaply(X, X$ID))[[1]])
 median(Time03)
[1] 0.02
 xtsTime - replicate(100,
+   system.time(do.call(merge, split(x$VALUE,x$ID)))[[1]])
 median(xtsTime)
[1] 0

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.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] How to speed up grouping time series, help please

2011-04-04 Thread Gabor Grothendieck
On Mon, Apr 4, 2011 at 8:49 AM, Den Alpin den.al...@gmail.com wrote:
 I retrieve for a few hundred times a group of time series (10-15 ts
 with 1 values each), on every group I do some calculation, graphs
 etc. I wonder if there is a faster method than what presented below to
 get an appropriate timeseries object.

 Making a query with RODBC for every group I get a data frame like this:

 X
   ID                DATE     VALUE
 14  3 2000-01-01 00:00:03 0.5726334
 4   1 2000-01-01 00:00:03 0.8830174
 1   1 2000-01-01 00:00:00 0.2875775
 15  3 2000-01-01 00:00:04 0.1029247
 11  3 2000-01-01 00:00:00 0.9568333
 9   2 2000-01-01 00:00:03 0.5514350
 7   2 2000-01-01 00:00:01 0.5281055
 6   2 2000-01-01 00:00:00 0.0455565
 12  3 2000-01-01 00:00:01 0.4533342
 8   2 2000-01-01 00:00:02 0.8924190
 3   1 2000-01-01 00:00:02 0.4089769
 13  3 2000-01-01 00:00:02 0.6775706

 And I want to get a timeSeries object or xts object like this:

                            1         2         3
 2000-01-01 00:00:00 0.2875775 0.0455565 0.9568333
 2000-01-01 00:00:01        NA 0.5281055 0.4533342
 2000-01-01 00:00:02 0.4089769 0.8924190 0.6775706
 2000-01-01 00:00:03 0.8830174 0.5514350 0.5726334
 2000-01-01 00:00:04        NA        NA 0.1029247


 Input data can be sorted or unsorted (the most complicated case is in
 the example, unsorted and missing data) in the sense that I can sort
 in query if I can take an advantage from this.

 Some considerations:
 - Xts is generally faster than timeSeries
 - both accept a matrix so if I can create a matrix like the one
 represented above and an array of characters representing dates faster
 than what possible with xts:::cbind, for examole,I will have a faster
 implementation (package data.table ?).
 - create timeseries objects in multithread and then merge (package plyr ?)
 - faster merge algorithms?

 Below some code to generate the test case above:


 set.seed(123)
 N - 5 # number of observations
 K - 3 # number of timeseries ID

 X - data.frame(
  ID = rep(1:K, each = N),
  DATE = as.character(rep(as.POSIXct(2000-01-01, tz = GMT)+ 0:(N-1), K)),
  VALUE = runif(N*K), stringsAsFactors = FALSE)

 X - X[sample(1:(N*K), N*K),] # sample observations to get random
 order (optional)
 X - X[-(sample(1:nrow(X), floor(nrow(X)*0.2))),] # 20% missing

 head(X, 15)

 # use explicitly environments to avoid '-'
 buildTimeSeriesFromDataFrame - function(x, env)
 {
  {
    if(exists(xx, envir = env)) # if exist variable xx in env cbind
      assign(xx,
        cbind(get(xx, env), timeSeries(x$VALUE, x$DATE,
          format = '%Y-%m-%d %H:%M:%S',
          zone = 'GMT', units = as.character(x$ID[1]))),
        envir = env)
    else  # create xx in env
      assign(xx,
        timeSeries(x$VALUE, x$DATE, format = '%Y-%m-%d %H:%M:%S',
          zone = 'GMT', units = as.character(x$ID[1])),
        envir = env)

    return(TRUE)
  }
 }

 # use package plyr, faster than 'by' function
 tsDaply - function(...)
 {
  library(plyr)
  e1 - new.env(parent = baseenv()) #create a new env
  res - daply(X, ID, buildTimeSeriesFromDataFrame,
      env = e1)
  return(get(xx, e1)) # return xx from env
 }

 ##replicate 100 times
 #Time03 - replicate(100,
 #  system.time(tsDaply(X, X$ID))[[1]])
 #median(Time03)

 # result
 tsDaply(X, X$ID)


Haven't checked how fast it is but using read.zoo its just one line of
code to produce the required matrix:

# set up input data frame, DF

Lines - ID,DATE,VALUE
3,2000-01-01 00:00:03,0.5726334
1,2000-01-01 00:00:03,0.8830174
1,2000-01-01 00:00:00,0.2875775
3,2000-01-01 00:00:04,0.1029247
3,2000-01-01 00:00:00,0.9568333
2,2000-01-01 00:00:03,0.5514350
2,2000-01-01 00:00:01,0.5281055
2,2000-01-01 00:00:00,0.0455565
3,2000-01-01 00:00:01,0.4533342
2,2000-01-01 00:00:02,0.8924190
1,2000-01-01 00:00:02,0.4089769
3,2000-01-01 00:00:02,0.6775706
DF - read.table(textConnection(Lines), header = TRUE, sep = ,)

# create zoo matrix

library(zoo)
z - read.zoo(DF, split = 1, index = 2, tz = )

The last line gives:

 z
1 2 3
2000-01-01 00:00:00 0.2875775 0.0455565 0.9568333
2000-01-01 00:00:01NA 0.5281055 0.4533342
2000-01-01 00:00:02 0.4089769 0.8924190 0.6775706
2000-01-01 00:00:03 0.8830174 0.5514350 0.5726334
2000-01-01 00:00:04NANA 0.1029247

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] Difference in mixture normals and one density

2011-04-04 Thread Liaw, Andy
Is something like this what you're looking for?

R library(nor1mix)
R nmix2 - norMix(c(2, 3), sig2=c(25, 4), w=c(.2, .8))
R dnorMix(1, nmix2) - dnorm(1, 2, 5)
[1] 0.03422146

Andy

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Silverton
 Sent: Monday, April 04, 2011 10:01 AM
 To: r-help@r-project.org
 Subject: Re: [R] Difference in mixture normals and one density
 
 Hello,
 I am trying to find out if R can do the following:
 
 I have a mixture of normals say f = 0.2*Normal(2, 5) + 0.8*Normal(3,2)
 How do I find the difference in the densities at any 
 particular point of f
 and at Normal(2,5)?
 
 -- 
 Thanks,
 Jim.
 
   [[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.
 
Notice:  This e-mail message, together with any attachme...{{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.


Re: [R] Please help

2011-04-04 Thread Steve Lianoglou
Hi,

On Mon, Apr 4, 2011 at 5:15 AM, Sadaf Zaidi s.zaidi...@amu.ac.in wrote:
 Dear Sir/Madam,
 I am stuck with a nagging problem in using R for SVM regression. My data has 5
 dimensions and 400 observations. The independent variables are :
 Peb, Ksub, Sub, and Xtt.
 The dependent variable is: Rexp.
 I tried using the svm.tune function to tune the hyper parameters: gamma, 
 epsilon and C.
 I am getting the following error message:
 Error in predict.svm(ret, xhold, decision.values+TRUE): Model is empty!
 May you please help me!

You're not giving us much to go on, can you show us the code that you
are using that gets you into this problem?

(i) For example -- by svm.tune, do you mean the tune function from
the e1071 package?

(ii) What is the exact function call you are using that gives you this error.

(iii) Can you build a normal svm model without tuning it. For
instance, does svm(x,y,..) work with your data?

(iv) Are you sure that the values you are inputting to the svm (and/or
tune function) are of the correct type?

With your follow up email that provides the code you tried and answers
to some of the Q's above. Also provide a small bit of your data that
we can use to help you debug. You can easily do so by using the `dput`
function. Say your data (predictors and label) are in a variable `x`,
paste the output of the following command in your follow up email:

R dput(x[sample(nrow(x), 10),])

This will give us 10 random rows from your data that people trying to
help you can use.

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] gap.barplot doesn't support data arrays?

2011-04-04 Thread Peter Ehlers

On 2011-04-04 06:39, Andrew D. Steen wrote:

I am trying to make a barplot with a broken axis using gap.barplot (in the
indispensable plotrix package).  This works well when the data is a vector:


twogrp-c(rnorm(10)+4,rnorm(10)+20)
gap.barplot(twogrp,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),ylab=Group

values,main=Barplot with gap)

But when the data is an array (for a bar plot with multiple series) I get an
error and a strange plot with no y-tics and bars stretching downwards, as if
all the values were negative:


twogrp2-array(twogrp, dim=c(2,5))


gap.barplot(twogrp2,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),ylab=Group
values,main=Barplot with gap)

Error in rect(xtics[bigones] - halfwidth, botgap, xtics[bigones] +
halfwidth,  :
   cannot mix zero-length and non-zero-length coordinates

However, the main title and axis labels do appear correctly.

Are data arrays unsupported for gap.barplot, or am I missing something?


Looks like they're not supported, as you could easily see from
the code. But do gapped stacked barplots even make sense? Not
to me.

Still, I think that the plotrix documentation is somewhat
spotty. The help page for gap.barplot indicates that the
input 'y' should be 'data values'; not overly informative.

Peter Ehlers



Thanks,
Drew Steen

__
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] Creating multiple vector/list names-novice

2011-04-04 Thread michalseneca
Hi I have very simple issue as I am still new to the group of R 

I have basically 

vector of names for which i want to create mutliple combinations and then
place them in different vectors. In some other language I can just place a
third dimension to separate list (or matrix) but i do not know how to do it
in R.

My issue is simple I use 
cc-combn(colnames(DD),2)

I would need to have this as 

vector1 or like vector[,,1] :   cc-combn(colnames(DD),2)
vector2or like vector[,,2]  cc-combn(colnames(DD),3)

etc..for up to k combinations

something so then I can use for loop to go through the al of these
combinations

example:

string-a, b , c ,d

vector/list(1) ab ac ad bc bd be cd ce de
vector/list  (2) abc abd abe bcd bce bde cde


Can you help me with this.. I know that it is a simple question for this
thread thank you..

Michal


--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-multiple-vector-list-names-novice-tp3425616p3425616.html
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] Clarks 2Dt function in R

2011-04-04 Thread Ben Bolker

bialozyt at biologie.uni-marburg.de writes:

 
 Dear Ben,
 
 you answerd to Nancy Shackelford about Clarks 2Dt function.
 Since the thread ended just after your reply,
 I would like to ask, if you have an idea how to use this function in R


  Dear Ronald,

  I got started on your problem, but I didn't finish it.
I got a plausible answer to start with, but when checking
the answer I ran into some trouble.  Unfortunately, fitting
these functions is a bit harder than one might expect ...
it takes quite a bit of fussing to get a good, reliable answer.

  My partly-worked solution is below.


 I defined it the following way:

You were multiplying instead of dividing by the second
term (I changed it by raising the term to a negative
power instead.

The lesson here: *always* do some sanity checks (graphical or otherwise)
of your functions.  I actually did the whole fit before I tried to plot
the curves and found that they were increasing rather than decreasing ...

## fixed
clark2Dt - function(x , p, u=1) {
   (p/(pi*u))/(1+(x^2/u))^(p+1)
 }

It might be preferable to define this in terms of s=sqrt(u)
instead (then s would be a scale parameter with the same units
as x, more easily interpretable ...


Sanity checks:
 
par(las=1,bty=l) ## personal preferences
curve(clark2Dt(x,p=6),from=0,to=5)
curve(clark2Dt(x,p=4),col=2,add=TRUE)
curve(clark2Dt(x,p=2),col=4,add=TRUE)
legend(topright,paste(p,c(6,4,2),sep==),col=c(1,2,4),lty=1)

Grab data (in the future, if possible, please use dput(), which puts
your data in the most convenient form, or write out a statement like
this to define your data ...)
 
X - as.data.frame(matrix(
c(15,12,
  45,13,
  75,10,
  105,8,
  135,16,
  165,5,
  195,15,
  225,8,
  255,9,
  285,12,
  315,5,
  345,4,
  375,1,
  405,1,
  435,1,
  465,0,
  495,1,
  525,2,
  555,0,
  585,0,
  615,0,
  645,0,
  675,0),
   ncol=2,byrow=TRUE,
 dimnames=list(NULL,c(dist,count

## assume these are traps/samples with unit size
## (if not, it will get absorbed into the fecundity constant

library(bbmle)
m1 - mle2(count~dnbinom(mu=f*clark2Dt(dist,p,u),size=k),
 data=X,start=list(f=20,u=10,p=5,k=2),
 lower=rep(0.002,4),method=L-BFGS-B)

## we get a plausible-looking fit ...
with(X,plot(count~dist,pch=16,las=1,bty=l))
newdat - data.frame(dist=1:700)  ## overkill but harmless
lines(newdat$dist,predict(m1,newdata=newdat))

## but the coefficients look funny, especially f

coef(m1) 

## tried resetting parscale but it's bogus (gets stuck at a worse likelihood)
m2 - mle2(count~dnbinom(mu=f*clark2Dt(dist,p,u),size=k),
   data=X,start=list(f=20,u=10,p=5,k=2),
   control=list(parscale=abs(coef(m1))),
 lower=rep(0.002,4),method=L-BFGS-B)

m3 - mle2(count~dnbinom(mu=exp(logf)*clark2Dt(dist,exp(logp),exp(logu)),
 size=exp(logk)),
   data=X,start=list(logf=log(20),logu=log(10),logp=log(5),
logk=log(2)),
   method=Nelder-Mead)

exp(coef(m3))
coef(m1)
summary(m1)

## hmm.  Redefine in terms of s instead of u and (more importantly)
## with f = seed density at r=0 rather the

cov2cor(vcov(m1)) ## shows that f and u are horribly correlated 

newclark2Dt - function(x , p, s=1, eps=1e-70) {
  d - (1+(x/s)^2)
  r - 1/d^(p+1)
  if (any(!is.finite(r))) browser()
  r
}

dnbinom_pen - function(x,mu,size,pen=1000,log=TRUE) {
  mu - rep(mu,length.out=length(x))
  logval - ifelse(mu==0  x==0,pen*x^2,dnbinom(x,mu=mu,size=size,log=TRUE))
  if (log) logval else exp(logval)
}

## needed for predict()
snbinom_pen - snbinom

m4 - mle2(count~dnbinom(mu=f*newclark2Dt(dist,p,s),size=k),
 data=X,start=list(f=20,s=10,p=5,k=2),
 lower=rep(0.002,4),method=L-BFGS-B)

m5 - mle2(count~dnbinom_pen(mu=f*newclark2Dt(dist,1/(pinv),s),size=exp(logk)),
   data=X,start=list(f=15,s=10,pinv=100,logk=1),trace=TRUE,
##   control=list(parscale=c(200,0.002,1.66,3600)),
   lower=rep(0.002,4),method=L-BFGS-B)

with(X,plot(count~dist,pch=16,las=1,bty=l))
newdat - data.frame(dist=1:700)  ## overkill but harmless
lines(newdat$dist,predict(m1,newdata=newdat))
lines(newdat$dist,predict(m5,newdata=newdat),col=2)
 
 but I am not able to fit anything.
 Do you have an idea?
 I guess there is something wrong in my formula for Clarks 2Dt
 
 Thank you for reading 
 
 Ciao
 Ronald Bialozyt
 


__
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 multiple vector/list names-novice

2011-04-04 Thread Henrique Dallazuanna
Try this:

 lapply(2:3, FUN = combn, x = string, paste, collapse = '')

On Mon, Apr 4, 2011 at 11:24 AM, michalseneca michalsen...@gmail.com wrote:
 Hi I have very simple issue as I am still new to the group of R

 I have basically

 vector of names for which i want to create mutliple combinations and then
 place them in different vectors. In some other language I can just place a
 third dimension to separate list (or matrix) but i do not know how to do it
 in R.

 My issue is simple I use
 cc-combn(colnames(DD),2)

 I would need to have this as

 vector1 or like vector[,,1] :           cc-combn(colnames(DD),2)
 vector2or like vector[,,2]              cc-combn(colnames(DD),3)

 etc..for up to k combinations

 something so then I can use for loop to go through the al of these
 combinations

 example:

 string-a, b , c ,d

 vector/list(1) ab ac ad bc bd be cd ce de
 vector/list  (2) abc abd abe bcd bce bde cde


 Can you help me with this.. I know that it is a simple question for this
 thread thank you..

 Michal


 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Creating-multiple-vector-list-names-novice-tp3425616p3425616.html
 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

__
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] lattice: how to center a subtitle?

2011-04-04 Thread David Winsemius


On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:


Dear expeRts,

I recently asked for a real centered title (see, e.g., http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html) 
.
A nice solution (from Deepayan Sarkar) is to use xlab.top instead  
of main:


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the  
human's eye, sub = but subtitles are not centered, scales =  
list(alternating = c(1,1), tck = c(1,0

dev.off()


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the  
human's eye, xlab = but subtitles are _now_ centered, scales =  
list(alternating = c(1,1), tck = c(1,0

dev.off()


(I realize that those are not really subtitles by a 'lab', but that  
appears acceptable in your current test case.)




My question is whether there is something similar for *sub*titles  
[so something like xlab.bottom]? As you can see from the plot, the  
subtitle does not seem to be centered for the human's eye. I would  
like to center it according to the x-axis label.





David Winsemius, MD
West Hartford, CT

__
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] simulating a VARXls model using dse

2011-04-04 Thread Alison Callahan
Hello,

Using the dse package I have estimated a VAR model using estVARXls().
I can perform forecasts using forecast() with no problems, but when I
try to use simulate() with the same model, I get the following error:

Error in diag(Cov, p) :
  'nrow' or 'ncol' cannot be specified when 'x' is a matrix

Can anyone shed some light on the meaning of this error? How can I
simulate output using a model created with estVARXls()?

Thanks,

Alison

__
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] simulating a VARXls model using dse

2011-04-04 Thread Alison Callahan
Hi Paul,

I am using R v. 2.12.2, and the dse package with build 2.12.2.

I have attached some sample data to this email, and the R code I use
to create the model and then forecast with it.

Thanks,

Alison

On Mon, Apr 4, 2011 at 11:02 AM, Paul Gilbert
pgilb...@bank-banque-canada.ca wrote:
 Could you please send me a reproducible example, and R and dse version info.

 Thanks,
 Paul

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Alison Callahan
 Sent: April 4, 2011 10:56 AM
 To: r-help@r-project.org
 Subject: [R] simulating a VARXls model using dse

 Hello,

 Using the dse package I have estimated a VAR model using estVARXls().
 I can perform forecasts using forecast() with no problems, but when I
 try to use simulate() with the same model, I get the following error:

 Error in diag(Cov, p) :
   'nrow' or 'ncol' cannot be specified when 'x' is a matrix

 Can anyone shed some light on the meaning of this error? How can I
 simulate output using a model created with estVARXls()?

 Thanks,

 Alison

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

 La version française suit le texte anglais.

 

 This email may contain privileged and/or confidential information, and the 
 Bank of
 Canada does not waive any related rights. Any distribution, use, or copying 
 of this
 email or the information it contains by other than the intended recipient is
 unauthorized. If you received this email in error please delete it 
 immediately from
 your system and notify the sender promptly by email that you have done so.

 

 Le présent courriel peut contenir de l'information privilégiée ou 
 confidentielle.
 La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute 
 diffusion,
 utilisation ou copie de ce courriel ou des renseignements qu'il contient par 
 une
 personne autre que le ou les destinataires désignés est interdite. Si vous 
 recevez
 ce courriel par erreur, veuillez le supprimer immédiatement et envoyer sans 
 délai à
 l'expéditeur un message électronique pour l'aviser que vous avez éliminé de 
 votre
 ordinateur toute copie du courriel reçu.

__
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 speed up grouping time series, help please

2011-04-04 Thread Den Alpin
I did some tests on Your and Gabor solutions, below my findings:

- Your solution is fast as my solution in xts (below) but MUCH MORE
READABLE, in particular I think your test should take into account xts
creation from the data.frame (see below);
- Gabor's solution with read.zoo is fast as xts but give an xts object
that has some problems with time zones.

Any better idea to speed up grouping time series?

Thanks!

Below few line of codes to test (I suggest to grow X size to get
better comparison results):
xtsSplit - function(x)
{
  x - xts(x[,c(ID,VALUE)], as.POSIXct(x[,DATE]))
  x - do.call(merge, split(x$VALUE,x$ID))
  return(x)
}

xtsSplitTime - replicate(100,
  system.time(xtsSplit(X))[[1]])
median(xtsTime)

zooReadTime - replicate(100,
 system.time(z - read.zoo(X, split = 1, index = 2, tz = ))[[1]])
median(zooReadTime)

And my (unreadable) solution:
library(xts)
buildXtsFromDataFrame - function(x, env)
{
  {
if(exists(xx, envir = env))
{
  VALUE - as.matrix(x$VALUE)
  colnames(VALUE) - as.character(x$ID[1])
  assign(xx,
cbind(get(xx, env), xts(VALUE,
  as.POSIXct(x$DATE, tz = GMT,
format = '%Y-%m-%d %H:%M:%S'),
  tzone = 'GMT')),
envir = env)
} else
{
  VALUE - as.matrix(x$VALUE)
  colnames(VALUE) - as.character(x$ID[1])
  assign(xx,
xts(VALUE, as.POSIXct(x$DATE, tz = GMT,
format = '%Y-%m-%d %H:%M:%S'),
  tzone = 'GMT'),
envir = env)
}
return(TRUE)
  }
}

xtsDaply - function(...)
{
  e1 - new.env(parent = baseenv())
  res - daply(X, ID, buildXtsFromDataFrame,
  env = e1)
  return(get(xx, e1))
}

Time04 - replicate(100,
  system.time(xtsDaply(X, X$ID))[[1]])




2011/4/4 Joshua Ulrich josh.m.ulr...@gmail.com:
 Hi Dan,

 On Mon, Apr 4, 2011 at 7:49 AM, Den Alpin den.al...@gmail.com wrote:
 I retrieve for a few hundred times a group of time series (10-15 ts
 with 1 values each), on every group I do some calculation, graphs
 etc. I wonder if there is a faster method than what presented below to
 get an appropriate timeseries object.

 Making a query with RODBC for every group I get a data frame like this:

 X
   ID                DATE     VALUE
 14  3 2000-01-01 00:00:03 0.5726334
 4   1 2000-01-01 00:00:03 0.8830174
 1   1 2000-01-01 00:00:00 0.2875775
 15  3 2000-01-01 00:00:04 0.1029247
 11  3 2000-01-01 00:00:00 0.9568333
 9   2 2000-01-01 00:00:03 0.5514350
 7   2 2000-01-01 00:00:01 0.5281055
 6   2 2000-01-01 00:00:00 0.0455565
 12  3 2000-01-01 00:00:01 0.4533342
 8   2 2000-01-01 00:00:02 0.8924190
 3   1 2000-01-01 00:00:02 0.4089769
 13  3 2000-01-01 00:00:02 0.6775706

 And I want to get a timeSeries object or xts object like this:

                            1         2         3
 2000-01-01 00:00:00 0.2875775 0.0455565 0.9568333
 2000-01-01 00:00:01        NA 0.5281055 0.4533342
 2000-01-01 00:00:02 0.4089769 0.8924190 0.6775706
 2000-01-01 00:00:03 0.8830174 0.5514350 0.5726334
 2000-01-01 00:00:04        NA        NA 0.1029247


 Input data can be sorted or unsorted (the most complicated case is in
 the example, unsorted and missing data) in the sense that I can sort
 in query if I can take an advantage from this.

 Some considerations:
 - Xts is generally faster than timeSeries
 - both accept a matrix so if I can create a matrix like the one
 represented above and an array of characters representing dates faster
 than what possible with xts:::cbind, for examole,I will have a faster
 implementation (package data.table ?).
 - create timeseries objects in multithread and then merge (package plyr ?)
 - faster merge algorithms?

 Below some code to generate the test case above:


 set.seed(123)
 N - 5 # number of observations
 K - 3 # number of timeseries ID

 X - data.frame(
  ID = rep(1:K, each = N),
  DATE = as.character(rep(as.POSIXct(2000-01-01, tz = GMT)+ 0:(N-1), K)),
  VALUE = runif(N*K), stringsAsFactors = FALSE)

 X - X[sample(1:(N*K), N*K),] # sample observations to get random
 order (optional)
 X - X[-(sample(1:nrow(X), floor(nrow(X)*0.2))),] # 20% missing

 head(X, 15)

 # use explicitly environments to avoid '-'
 buildTimeSeriesFromDataFrame - function(x, env)
 {
  {
    if(exists(xx, envir = env)) # if exist variable xx in env cbind
      assign(xx,
        cbind(get(xx, env), timeSeries(x$VALUE, x$DATE,
          format = '%Y-%m-%d %H:%M:%S',
          zone = 'GMT', units = as.character(x$ID[1]))),
        envir = env)
    else  # create xx in env
      assign(xx,
        timeSeries(x$VALUE, x$DATE, format = '%Y-%m-%d %H:%M:%S',
          zone = 'GMT', units = as.character(x$ID[1])),
        envir = env)

    return(TRUE)
  }
 }

 # use package plyr, faster than 'by' function
 tsDaply - function(...)
 {
  library(plyr)
  e1 - new.env(parent = baseenv()) #create a new env
  res - daply(X, ID, buildTimeSeriesFromDataFrame,
      env = e1)
  return(get(xx, e1)) # return xx from env
 }

 ##replicate 100 times
 #Time03 - replicate(100,
 #  

Re: [R] Deriving formula with deriv

2011-04-04 Thread David Winsemius


On Apr 4, 2011, at 6:35 AM, kitty wrote:


Dear list,

Hi,

I am trying to get the second derivative of a logistic formula, in R  
summary

the model is given as :

###

$nls
Nonlinear regression model
model:  data ~ logistic(time, A, mu, lambda, addpar)
data:  parent.frame()
A  mu  lambda
0.53243 0.03741 6.94296

###

but I know the formula used is

# y~'A'/(1+exp((4*'mu'/'A')*('lambda'-'time'))+2))# from the  
grofit (

package I am using to fit the model) documentation.

I have attempted to use the R function 'deriv' to get the
first derivative from which I can then reuse the deriv function to  
get the

second derivative unfortunately this does not seem to work

###

express-expression(y~'A'/(1+exp((4*'mu'/'A')*('lambda'-'time'))+2))
express

expression(y ~ A/(1 + exp((4 * mu/A) * (lambda - time)) +
   2))


d1-deriv(express)

Error in deriv.default(express) : element 2 is empty;
  the part of the args list of '.Internal' being evaluated was:
  (expr, namevec, function.arg, tag, hessian)



For one thing you are not specifying what variable you want to  
differentiate with-respect-to: Assuming this to be `A` then:


 express -
 expression( A/(1+exp((4*mu/A)*(lambda-time))+ 2))
 # The quotes looked wrong inside an expression, so I removed them

 d1-deriv(express, A)  #  but the diff w.r.t variable needs to be  
quoted.

  d1
expression({
.expr1 - 4 * mu
.expr3 - lambda - time
.expr5 - exp(.expr1/A * .expr3)
.expr7 - 1 + .expr5 + 2
.value - A/.expr7
.grad - array(0, c(length(.value), 1L), list(NULL, c(A)))
.grad[, A] - 1/.expr7 + A * (.expr5 * (.expr1/A^2  
* .expr3))/.expr7^2

attr(.value, gradient) - .grad
.value
})


All this should have been clear if you had looked at the examples in  
help(deriv).




Why is this not working and how do I get the second derivative?


That , too, is clearly exemplified in the help page.



Thank you for reading my post, all help is appreciated,
Kitty



--
David Winsemius, MD
West Hartford, CT

__
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] D'Agostino test

2011-04-04 Thread Dieter Menne

Juraj17 wrote:
 
 Do I have to write my own, or it exists yet? How name has it, or how can I
 use it.
 

Try the R-function search. It return the function you are looking for as the
first match.

Dieter




--
View this message in context: 
http://r.789695.n4.nabble.com/D-Agostino-test-tp3424952p3425833.html
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] How to speed up grouping time series, help please

2011-04-04 Thread Gabor Grothendieck
On Mon, Apr 4, 2011 at 11:20 AM, Den Alpin den.al...@gmail.com wrote:
 I did some tests on Your and Gabor solutions, below my findings:

 - Your solution is fast as my solution in xts (below) but MUCH MORE
 READABLE, in particular I think your test should take into account xts
 creation from the data.frame (see below);
 - Gabor's solution with read.zoo is fast as xts but give an xts object
 that has some problems with time zones.

read.zoo gives a zoo object, not an xts object.  If you want an xts
object  try as.xts(z). If you were expecting an xts object that may be
the source of your other problems.



-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] replace last 3 characters of string

2011-04-04 Thread Dieter Menne

Bert Jacobs-2 wrote:
 
 I would like to replace the last tree characters of the values of a
 certain
 column in a dataframe.
 
 

Besides the mentioned standard method: I found the subset of string
operations in Hadley Wickhams stringr package helpful. They have a much more
consistent interface compared to the standard interface.

str_sub: accepts negative positions, which are calculated from the left of
the last character.

Dieter



--
View this message in context: 
http://r.789695.n4.nabble.com/replace-last-3-characters-of-string-tp3424354p3425855.html
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] gap.barplot doesn't support data arrays?

2011-04-04 Thread Andrew D. Steen
True - gapped stacked bar plots make no sense at all.  I'm working my way up
to a gapped bar plot with series next to each other (and error bars!), what
you'd get if you put a gap in the y-axis of 

 twogrp2-array(twogrp, dim=c(2,5))
 barplot(twogrp2, beside=TRUE)

I'm guessing I can do this if I spend enough time with the axis.break()
function.  But is there an easier way?

--Drew

 -Original Message-
 From: Peter Ehlers [mailto:ehl...@ucalgary.ca]
 Sent: Monday, April 04, 2011 4:33 PM
 To: Andrew D. Steen
 Cc: r-help@r-project.org
 Subject: Re: [R] gap.barplot doesn't support data arrays?
 
 On 2011-04-04 06:39, Andrew D. Steen wrote:
  I am trying to make a barplot with a broken axis using gap.barplot
 (in the
  indispensable plotrix package).  This works well when the data is a
 vector:
 
  twogrp-c(rnorm(10)+4,rnorm(10)+20)
 
 gap.barplot(twogrp,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),ylab=Gr
 oup
  values,main=Barplot with gap)
 
  But when the data is an array (for a bar plot with multiple series) I
 get an
  error and a strange plot with no y-tics and bars stretching
 downwards, as if
  all the values were negative:
 
  twogrp2-array(twogrp, dim=c(2,5))
 
 
 gap.barplot(twogrp2,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),ylab=G
 roup
  values,main=Barplot with gap)
 
  Error in rect(xtics[bigones] - halfwidth, botgap, xtics[bigones] +
  halfwidth,  :
 cannot mix zero-length and non-zero-length coordinates
 
  However, the main title and axis labels do appear correctly.
 
  Are data arrays unsupported for gap.barplot, or am I missing
 something?
 
 Looks like they're not supported, as you could easily see from
 the code. But do gapped stacked barplots even make sense? Not
 to me.
 
 Still, I think that the plotrix documentation is somewhat
 spotty. The help page for gap.barplot indicates that the
 input 'y' should be 'data values'; not overly informative.
 
 Peter Ehlers
 
 
  Thanks,
  Drew Steen
 
  __
  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] help

2011-04-04 Thread Vijayan Padmanabhan
Hi R Group
Thanks for some suggestions.
I have finally figured it out..
The following script called from within R Session does what i want..(to
attach files called test1.pdf and Document-1.pdf into the file test2.pdf and
then save the new file with attachments as test3.pdf at the given path)

options(useFancyQuotes=FALSE)
system(noquote(paste(pdftools
-S,dQuote(paste(attachfiles=C:\\test1.pdf|C:\\Document-1.pdf)),
paste(-i C:\\test2.pdf -o C:\\test3.pdf
Regards
Vijayan Padmanabhan
On Sun, Apr 3, 2011 at 5:21 PM, Mike Marchywka marchy...@hotmail.comwrote:




  Date: Sun, 3 Apr 2011 01:35:16 +0530
  From: nandan.a...@gmail.com
  To: padmanabhan.vija...@gmail.com
  CC: r-help@r-project.org
  Subject: Re: [R] help
 
  One way that u might have thought of is to create plot in PDF in R and
 the
  use pdftools.
  Additionally one can also think of running R script using R CMD and then
  using pdftools in a .sh script file if u r in linux.
  I am not aware of pdftools capability in R.
 
  On 2 April 2011 23:01, Vijayan Padmanabhan wrote:
 
   Dear R Help group
   I need to run a command line script from within R session. I am not
 clear
   how i can acheive this. I tried shell and system function, but i am
 missing
   something critical.can someone provide help?
   My intention is to create a pdf file of a plot in R and then attach
   existing files from my system as attachment into the newly created pdf
   file.
   Any help would be greatly appreciated.. Here is the command line script
 i
   want to execute from within R.
  
  
   pdftools -S attachfiles=C:\test1.pdf -i C:\test2.pdf -o C:\test4.pdf
  
   Regards
   Vijayan Padmanabhan


 I just tried

  system(pdftk --help)

 and it appeared to work as I have pdftk from cygwin.I routinely do this the
 other way however and invoke
 R from a bash script and then use external tools like this from the bash
 script
 after R is done. If I'm generating various pieces, it seems to make sense
 to get them all first and release any resources R has accumulated
 as pdf manipulation itself can often require lots of memory etc.






[[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] merging data list in to single data frame

2011-04-04 Thread Umesh Rosyara
Dear R community members 

 

I did find a good way to merge my 200 text data files in to a single data
file with one column added will show indicator for that file.  

 

filelist = list.files(pattern = K*cd.txt) # the file names are K1cd.txt
.to K200cd.txt 

data_list -lapply(filelist, read.table, header=T, comment=;, fill=T)

 

This will create list, but this is not what I want.  

 

I want a single dataframe (all separate dataframes have same variable
headings) with additional row for example 

 

; just for example, two small datasets are created by my component datasets
are huge, need automation

;read from file K1cd.txt 

var1  var2  var3var4 

1   6 0.3 8

3  4 0.4 9

2  3 0.4 6

1   0.40.9  3

 

;read from file K2cd.txt 

var1  var2  var3var4 

1   16 0.67

3  14 0.4 6

2 1 3 0.4 5

1  0.60.9  2

 

the output dataframe should look like 

 

Fileno  var1  var2  var3var4 

1  1   6 0.38

1  3  4 0.4 9

1  2  3 0.4 6

1  1   0.4  0.93

2  1   16   0.67

2  3  14 0.46

2  2 1 3 0.45

2  1  0.6 0.9   2

 

Please note that new file no column is added 

 

Thank you for the help.

 

Umesh R 

 


[[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] Adjusting p values of a matrix

2011-04-04 Thread January Weiner
Dear all,

I have an n x n matrix of p-values. The matrix is symmetrical, as it
describes the each against each p values of correlation
coefficients.

How can I best correct the p values of the matrix? Notably, the total
number of the tests performed is n(n-1)/2, since I do not test the
correlation of each variable with itself. That means, I only want to
correct one half of the matrix, not including the diagonal. Therefore,
simply writing

pmat - p.adjust( pmat, method= fdr )
# where pmat is an n x n matrix

...doesn't cut it.

Of course, I can turn the matrix in to a three column data frame with
n(n-1)/2 rows, but that is slow and not elegant.

regards,
j.

-- 
 Dr. January Weiner 3 --
Max Planck Institute for Infection Biology
Charitéplatz 1
D-10117 Berlin, Germany
Web   : www.mpiib-berlin.mpg.de
Tel     : +49-30-28460514

__
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 multiple vector/list names-novice

2011-04-04 Thread michalseneca
Hi 

Thanks ,however I would need something different still...

I would need  to return a vector so if as  to choose 


cc[[3]] [2] would return vector/list  as in terms of  c(b,d,e)


Thanks 

--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-multiple-vector-list-names-novice-tp3425616p3425759.html
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] Multithreading of Geneland

2011-04-04 Thread Aurélien Chateigner
Hi all,

I would like to multithread that script, to detect structure from multilocus 
genetic data :

library(Geneland)

geno = read.table(cot966gen_test.txt) #the file is show after
MCMC(geno.dip.codom = geno, varnpop=T, npopmax=20, spatial = F, nit=10, 
thinnin=100, path.mcmc=./)
PostProcessChain(path.mcmc=./, nxdom=100, nydom=100, burnin=200)

I have an 8 cores computer, and since I have to compute that bit on a thousand 
of line like that :

209 209 217 217 180 180 154 154 181 181 
192 192 -9  -9  211 211 -9  -9  160 160 
-9  -9
-9  -9  -9  -9  254 254 140 140 181 181 
-9  -9  -9  -9  211 211 158 158 160 160 
158 146
209 209 223 223 348 348 186 186 -9  -9  
-9  -9  -9  -9  -9  -9  -9  -9  154 154 
146 146
212 212 291 291 218 218 170 170 187 187 
194 194 190 190 214 208 152 152 158 158 
155 155
209 209 -9  -9  180 180 150 150 185 185 
-9  -9  -9  -9  211 211 152 152 -9  -9  
155 155
212 212 209 209 234 234 166 166 187 187 
-9  -9  -9  -9  -9  -9  -9  -9  -9  -9  
-9  -9
212 212 205 205 236 236 164 164 187 187 
194 194 183 183 214 214 163 163 160 160 
155 155
212 212 203 203 238 236 164 164 187 187 
-9  -9  179 179 -9  -9  -9  -9  -9  -9  
-9  -9
212 212 203 203 236 236 164 164 187 187 
194 194 -9  -9  214 214 165 165 160 160 
155 155
212 212 209 209 236 234 164 164 187 187 
194 194 179 179 -9  -9  -9  -9  -9  -9  
-9  -9
212 212 205 205 236 236 166 166 -9  -9  
-9  -9  -9  -9  -9  -9  -9  -9  -9  -9  
-9  -9
212 212 -9  -9  180 180 147 147 181 181 
-9  -9  -9  -9  -9  -9  -9  -9  -9  -9  
-9  -9
212 212 -9  -9  180 180 147 147 181 181 
198 198 -9  -9  -9  -9  -9  -9  -9  -9  
-9  -9
212 212 209 209 234 234 166 166 187 187 
-9  -9  -9  -9  -9  -9  -9  -9  -9  -9  
-9  -9
212 212 209 209 234 234 166 166 187 187 
-9  -9  -9  -9  -9  -9  -9  -9  -9  -9  
-9  -9
212 212 209 209 236 236 166 166 187 187 
194 194 -9  -9  -9  -9  -9  -9  -9  -9  
-9  -9
212 212 207 207 236 236 164 164 -9  -9  
194 194 -9  -9  -9  -9  -9  -9  -9  -9  
-9  -9
212 212 205 205 238 238 164 164 187 187 
-9  -9  -9  -9  -9  -9  -9  -9  160 160 
155 155
212 212 209 207 234 234 164 164 187 187 
194 194 183 183 -9  -9  -9  -9  -9  -9  
-9  -9
-9  -9  -9  -9  -9  -9  166 166 -9  -9  
194 194 183 183 -9  -9  -9  -9  -9  -9  
-9  -9
212 212 209 205 234 234 164 164 187 187 
194 194 179 179 214 214 165 165 160 160 
155 155
212 212 205 205 234 234 164 164 187 187 
194 194 183 183 214 214 163 163 160 160 
155 155
212 212 209 209 236 236 166 166 187 187 
194 194 -9  -9  -9  -9  -9  -9  -9  -9  
-9  -9
212 209 -9  -9  180 180 150 147 187 187 
-9  -9  -9  -9  211 211 158 154 -9  -9  
155 155
209 209 207 207 328 328 184 184 181 181 
-9  -9  -9  -9  211 211 165 165 -9  -9  
155 155
212 212 253 253 212 212 168 150 187 181 
-9  -9  -9  -9  208 208 160 160 -9  -9  
155 146
212 212 -9  -9  

Re: [R] Adjusting p values of a matrix

2011-04-04 Thread Bert Gunter
1. This is not an R question, AFAICS.

2. Sounds like a research topic.  I don't think there's a meaningful
simple answer. I suspect it strongly depends on the model and context.

-- Bert

On Mon, Apr 4, 2011 at 8:02 AM, January Weiner
january.wei...@mpiib-berlin.mpg.de wrote:
 Dear all,

 I have an n x n matrix of p-values. The matrix is symmetrical, as it
 describes the each against each p values of correlation
 coefficients.

 How can I best correct the p values of the matrix? Notably, the total
 number of the tests performed is n(n-1)/2, since I do not test the
 correlation of each variable with itself. That means, I only want to
 correct one half of the matrix, not including the diagonal. Therefore,
 simply writing

 pmat - p.adjust( pmat, method= fdr )
 # where pmat is an n x n matrix

 ...doesn't cut it.

 Of course, I can turn the matrix in to a three column data frame with
 n(n-1)/2 rows, but that is slow and not elegant.

 regards,
 j.

 --
  Dr. January Weiner 3 --
 Max Planck Institute for Infection Biology
 Charitéplatz 1
 D-10117 Berlin, Germany
 Web   : www.mpiib-berlin.mpg.de
 Tel     : +49-30-28460514

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




-- 
Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions.

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

__
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] power of 2 way ANOVA with interaction

2011-04-04 Thread Greg Snow
You can use simulation:

1. decide what you think your data will look like
2. decide how you plan to analyze your data
3. write a function that simulates a dataset (common arguments include sample 
size(s) and effect sizes) then analyzes the data in your planned manner and 
returns the p-value(s) or other statistic(s) of interest
4. run the function from 3 a bunch (1000 or more) times, the replicate function 
is useful for this (progress bars can also be useful)
5. the proportion of times that the results are significant is your estimate of 
power

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Timothy Spier
 Sent: Sunday, April 03, 2011 5:11 PM
 To: R Help
 Subject: [R] power of 2 way ANOVA with interaction
 
 
 I've been searching for an answer to this for a while but no joy. I
 have a simple 2-way ANOVA with an interaction. I'd like to determine
 the power of this test for each factor (factor A, factor B, and the A*B
 interaction). How can I do this in R? I used to do this with proc
 Glmpower in SAS, but I can find no analogue in R.
 
   [[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] Adjusting p values of a matrix

2011-04-04 Thread peter dalgaard

On Apr 4, 2011, at 17:02 , January Weiner wrote:

 Dear all,
 
 I have an n x n matrix of p-values. The matrix is symmetrical, as it
 describes the each against each p values of correlation
 coefficients.
 
 How can I best correct the p values of the matrix? Notably, the total
 number of the tests performed is n(n-1)/2, since I do not test the
 correlation of each variable with itself. That means, I only want to
 correct one half of the matrix, not including the diagonal. Therefore,
 simply writing
 
 pmat - p.adjust( pmat, method= fdr )
 # where pmat is an n x n matrix
 
 ...doesn't cut it.
 
 Of course, I can turn the matrix in to a three column data frame with
 n(n-1)/2 rows, but that is slow and not elegant.


I don't think there's a really elegant way (have a look inside pairwise.table 
if you care).

If you start one step further back, you could just use pairwise.table with a 
suitably defined comparison function. Otherwise, how about

ltri - lower.tri(pmat)
utri - upper.tri(pmat)
pmat[ltri] - p.adjust(pmat[ltri], method = fdr)
pmat[utri] - t(pmat)[utri]

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] Adjusting p values of a matrix

2011-04-04 Thread Spencer Graves
  There are also the multcomp and multcompView packages that might 
provide something of interest in this regard.  multcomp has a 
companion book,  Multiple Comparisons Using R (Bretz, Hothorn, 
Westfall, 2010, CRC Press), which I believe provides an excellent 
overview of the state of the art in multiple comparisons.  The simple 
rule is Bonferroni, which involves multiplying the p-values by n or 
n(n-1)/2.



  Note, also, that one of the most important innovations in 
statistical methods of the past quarter century is the development of 
false discovery rate, which estimates the false alarm rate among the 
cases that the user actually sees, which is a mixture of true and false 
hypotheses.  The p value, by contrast, is the probability of a decision 
error only among hypotheses that are true.



  For more info, see the Wikipedia entries on Bonferroni or false 
discovery rate -- or the book by Bretz, Hothorn and Westfall or the 
vignettes accompanying the multcomp package.



  Hope this helps.
  Spencer


On 4/4/2011 8:54 AM, Bert Gunter wrote:

1. This is not an R question, AFAICS.

2. Sounds like a research topic.  I don't think there's a meaningful
simple answer. I suspect it strongly depends on the model and context.

-- Bert

On Mon, Apr 4, 2011 at 8:02 AM, January Weiner
january.wei...@mpiib-berlin.mpg.de  wrote:

Dear all,

I have an n x n matrix of p-values. The matrix is symmetrical, as it
describes the each against each p values of correlation
coefficients.

How can I best correct the p values of the matrix? Notably, the total
number of the tests performed is n(n-1)/2, since I do not test the
correlation of each variable with itself. That means, I only want to
correct one half of the matrix, not including the diagonal. Therefore,
simply writing

pmat- p.adjust( pmat, method= fdr )
# where pmat is an n x n matrix

...doesn't cut it.

Of course, I can turn the matrix in to a three column data frame with
n(n-1)/2 rows, but that is slow and not elegant.

regards,
j.

--
 Dr. January Weiner 3 --
Max Planck Institute for Infection Biology
Charitéplatz 1
D-10117 Berlin, Germany
Web   : www.mpiib-berlin.mpg.de
Tel : +49-30-28460514

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







--
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567

__
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] add zero in front of numbers

2011-04-04 Thread Uwe Ligges



On 04.04.2011 12:35, Yan Jiao wrote:

Dear R users,

I need to add 0 in front of a series of numbers, e.g. 1-001, 19-019,
Is there a fast way of doing that?


formatC(c(1, 19), flag=0, width=3)

Uwe Ligges


Many thanks

yan

[[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] Adjusting p values of a matrix

2011-04-04 Thread Benno Pütz
How about

as.matrix(p.adjust(as.dist(pmat)))


Benno

On 4.Apr.2011, at 17:02, January Weiner wrote:

 Dear all,
 
 I have an n x n matrix of p-values. The matrix is symmetrical, as it
 describes the each against each p values of correlation
 coefficients.
 
 How can I best correct the p values of the matrix? Notably, the total
 number of the tests performed is n(n-1)/2, since I do not test the
 correlation of each variable with itself. That means, I only want to
 correct one half of the matrix, not including the diagonal. Therefore,
 simply writing
 
 pmat - p.adjust( pmat, method= fdr )
 # where pmat is an n x n matrix
 
 ...doesn't cut it.
 
 Of course, I can turn the matrix in to a three column data frame with
 n(n-1)/2 rows, but that is slow and not elegant.
 
 regards,
 j.
 
 -- 
  Dr. January Weiner 3 --
 Max Planck Institute for Infection Biology
 Charitéplatz 1
 D-10117 Berlin, Germany
 Web   : www.mpiib-berlin.mpg.de
 Tel : +49-30-28460514
 
 __
 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] merging data list in to single data frame

2011-04-04 Thread Uwe Ligges



On 04.04.2011 16:41, Umesh Rosyara wrote:

Dear R community members



I did find a good way to merge my 200 text data files in to a single data
file with one column added will show indicator for that file.



filelist = list.files(pattern = K*cd.txt)



I doubt you meant K*cd.txt but ^K[[:digit:]]*cd\\.txt$.



# the file names are K1cd.txt

.to K200cd.txt

data_list-lapply(filelist, read.table, header=T, comment=;, fill=T)



Replace by:

data_list - lapply(filelist, function(x)
   cbind(Filename = x, read.table(x, header=T, comment=;, fill=TRUE))


And then:

result - do.call(rbind, data_list)

Uwe Ligges






This will create list, but this is not what I want.



I want a single dataframe (all separate dataframes have same variable
headings) with additional row for example



; just for example, two small datasets are created by my component datasets
are huge, need automation

;read from file K1cd.txt

var1  var2  var3var4

1   6 0.3 8

3  4 0.4 9

2  3 0.4 6

1   0.40.9  3



;read from file K2cd.txt

var1  var2  var3var4

1   16 0.67

3  14 0.4 6

2 1 3 0.4 5

1  0.60.9  2



the output dataframe should look like



Fileno  var1  var2  var3var4

1  1   6 0.38

1  3  4 0.4 9

1  2  3 0.4 6

1  1   0.4  0.93

2  1   16   0.67

2  3  14 0.46

2  2 1 3 0.45

2  1  0.6 0.9   2



Please note that new file no column is added



Thank you for the help.



Umesh R




[[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] 'RQuantLib for 2.12 version

2011-04-04 Thread Joshua Ulrich
Hi Mauricio,

A Windows binary is now available on CRAN:
http://dirk.eddelbuettel.com/blog/2011/04/04/#rquantlib_0.3.7

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



On Tue, Mar 29, 2011 at 10:38 AM, Mauricio Romero
mauricio.rom...@quantil.com.co wrote:
 Dear R users,

 I have been trying to use RQuantLib in the 2.12.2 R version. I downloaded
 the .zip file from
 http://sourceforge.net/projects/quantlib/files/QuantLib/
 http://sourceforge.net/projects/quantlib/files/QuantLib/ which didn't work,
 so I

 I downloaded the package source from
 http://sourceforge.net/projects/quantlib/files/QuantLib/1.0.1/
 http://sourceforge.net/projects/quantlib/files/QuantLib/1.0.1/



 Then I run:

 install.packages(RQuantLib_0.3.6.tar.gz, type=source, repos=NULL)

 and get the following error:



 Installing package(s) into 'C:\Users\Mauricio\Documents/R/win-library/2.12'

 (as 'lib' is unspecified)

 * installing *source* package 'RQuantLib' ...



   **

   WARNING: this package has a configure script

         It probably needs manual configuration

   **





 ** libs



 *** arch - i386

 cygwin warning:

  MS-DOS style path detected: C:/PROGRA~1/R/R-212~1.2/etc/i386/Makeconf

  Preferred POSIX equivalent is:
 /cygdrive/c/PROGRA~1/R/R-212~1.2/etc/i386/Makeconf

  CYGWIN environment variable option nodosfilewarning turns off this
 warning.

  Consult the user's guide for more details about POSIX paths:

    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames

 g++ -IC:/PROGRA~1/R/R-212~1.2/include
 -IC:/Users/Mauricio/Documents/R/win-library/2.12/Rcpp/include   -I -I.
 -O2 -Wall  -c asian.cpp -o asian.o

 asian.cpp:26:23: fatal error: rquantlib.h: No such file or directory

 compilation terminated.

 make: *** [asian.o] Error 1

 ERROR: compilation failed for package 'RQuantLib'

 * removing 'C:/Users/Mauricio/Documents/R/win-library/2.12/RQuantLib'

 Warning messages:

 1: running command 'C:\PROGRA~1\R\R-212~1.2/bin/i386/R CMD INSTALL -l
 C:\Users\Mauricio\Documents/R/win-library/2.12   RQuantLib_0.3.6.tar.gz'
 had status 1

 2: In install.packages(RQuantLib_0.3.6.tar.gz, type = source, repos =
 NULL) :

  installation of package 'RQuantLib_0.3.6.tar.gz' had non-zero exit status





 Any ideas?



 Thanks,



 Mauricio Romero


        [[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] lattice: how to center a subtitle?

2011-04-04 Thread Marius Hofert
Dear David,

I intended to use another x-label. But your suggestion brings me to the idea of 
just using a two-line xlab, so s.th. like
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
eye, xlab = but subtitles are _now_ centered\nbla, scales = list(alternating 
= c(1,1), tck = c(1,0

Thanks!

Cheers,

Marius

On 2011-04-04, at 16:47 , David Winsemius wrote:

 
 On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:
 
 Dear expeRts,
 
 I recently asked for a real centered title (see, e.g., 
 http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
 A nice solution (from Deepayan Sarkar) is to use xlab.top instead of 
 main:
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
 eye, sub = but subtitles are not centered, scales = list(alternating = 
 c(1,1), tck = c(1,0
 dev.off()
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
 eye, xlab = but subtitles are _now_ centered, scales = list(alternating = 
 c(1,1), tck = c(1,0
 dev.off()
 
 
 (I realize that those are not really subtitles by a 'lab', but that appears 
 acceptable in your current test case.)
 
 
 My question is whether there is something similar for *sub*titles [so 
 something like xlab.bottom]? As you can see from the plot, the subtitle 
 does not seem to be centered for the human's eye. I would like to center 
 it according to the x-axis label.
 
 
 
 David Winsemius, MD
 West Hartford, CT
 

__
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] converting affybatch object to matrix

2011-04-04 Thread Juliet Hannah
Use exprs on the output from RMA (or another method you like)

library(affy)
myData -ReadAffy()
myRMA - rma(myData)
e = exprs(myRMA)

Also, check out the  Bioconductor mailing list where
Bioconductor-related topics are discussed.


On Fri, Apr 1, 2011 at 9:54 AM, Landes, Ezekiel
ezekiel_lan...@hms.harvard.edu wrote:
 I have an Affybatch object called batch :


 batch
 AffyBatch object
 size of arrays=1050x1050 features (196 kb)
 cdf=HuGene-1_0-st-v1 (32321 affyids)
 number of samples=384
 number of genes=32321
 annotation=hugene10stv1
 notes=



 Is there a way of converting a portion of this data into a matrix? More 
 specifically, a matrix where the 384 samples are columns and the 32321 genes 
 are rows? The exprs function returns a matrix that has 384 columns but for 
 some reason there are 1050^2 rows.

 Thanks!
 __
 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] r-squared for object timeseries

2011-04-04 Thread user84
Hi,

i am new in this forum.
I hope someone can help me or correct me, if this is the false subforum to
write this.

I have to choose the best arima model from different possibilities of a
timeseries. I know the AIC; BIC and similar. But now i would like to check
the value called r-squared or adjusted r-squared in a linear model (in
german called: Bestimmtheitsmaß). How can i get it in R? The function
summary is not availiable for the type timeseries.

If there is a routine or function that gets it, perfect, if not i am able to
calculate this value for linear models. Is the equivalent thing for
timeseries given, if i simply change the variable y from a linear model by
the time?

Thanks for any help!

--
View this message in context: 
http://r.789695.n4.nabble.com/r-squared-for-object-timeseries-tp3425984p3425984.html
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] Adjusting p values of a matrix

2011-04-04 Thread Spencer Graves
  There are, however, the multcomp and multcompView packages that 
might provide something of interest in this regard.  multcomp has a 
companion book,  Multiple Comparisons Using R (Bretz, Hothorn, 
Westfall, 2010, CRC Press), which I believe provides an excellent 
overview of the state of the art in multiple comparisons.  The simple 
rule is Bonferroni, which involves multiplying the p-values by n or 
n(n-1)/2.



  Note, also, that one of the most important innovations in 
statistical methods of the past quarter century is the development of 
false discovery rate, which estimates the false alarm rate among the 
cases that the user actually sees, which is a mixture of true and false 
hypotheses.  The p value, by contrast, is the probability of a decision 
error only among hypotheses that are true.



  For more info, see the Wikipedia entries on Bonferroni or false 
discovery rate -- or the book by Bretz, Hothorn and Westfall or the 
vignettes accompanying the multcomp package.



  Hope this helps.
  Spencer


On 4/4/2011 8:54 AM, Bert Gunter wrote:

1. This is not an R question, AFAICS.

2. Sounds like a research topic.  I don't think there's a meaningful
simple answer. I suspect it strongly depends on the model and context.

-- Bert

On Mon, Apr 4, 2011 at 8:02 AM, January Weiner
january.wei...@mpiib-berlin.mpg.de  wrote:

Dear all,

I have an n x n matrix of p-values. The matrix is symmetrical, as it
describes the each against each p values of correlation
coefficients.

How can I best correct the p values of the matrix? Notably, the total
number of the tests performed is n(n-1)/2, since I do not test the
correlation of each variable with itself. That means, I only want to
correct one half of the matrix, not including the diagonal. Therefore,
simply writing

pmat- p.adjust( pmat, method= fdr )
# where pmat is an n x n matrix

...doesn't cut it.

Of course, I can turn the matrix in to a three column data frame with
n(n-1)/2 rows, but that is slow and not elegant.

regards,
j.

--
 Dr. January Weiner 3 --
Max Planck Institute for Infection Biology
Charitéplatz 1
D-10117 Berlin, Germany
Web   : www.mpiib-berlin.mpg.de
Tel : +49-30-28460514

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







--
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567

__
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] Questions remaining: define any character as na.string RE: merging data list in to single data frame

2011-04-04 Thread Umesh Rosyara
Dear Uwe and R community members 

Thank you Uwe for the help. 

I have still a question remaining, I am trying to find answer from long
time.  

While exporting my data, I have some characters mixed into it. I want to
define any characters as na.string? Is it possible to do so?

Thanks;

Umesh 



-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: Monday, April 04, 2011 12:22 PM
To: Umesh Rosyara
Cc: r-help@r-project.org; rosyar...@gmail.com
Subject: Re: [R] merging data list in to single data frame



On 04.04.2011 16:41, Umesh Rosyara wrote:
 Dear R community members



 I did find a good way to merge my 200 text data files in to a single data
 file with one column added will show indicator for that file.



 filelist = list.files(pattern = K*cd.txt)


I doubt you meant K*cd.txt but ^K[[:digit:]]*cd\\.txt$.



# the file names are K1cd.txt
 .to K200cd.txt

 data_list-lapply(filelist, read.table, header=T, comment=;, fill=T)


Replace by:

data_list - lapply(filelist, function(x)
cbind(Filename = x, read.table(x, header=T, comment=;, fill=TRUE))


And then:

result - do.call(rbind, data_list)

Uwe Ligges





 This will create list, but this is not what I want.



 I want a single dataframe (all separate dataframes have same variable
 headings) with additional row for example



 ; just for example, two small datasets are created by my component
datasets
 are huge, need automation

 ;read from file K1cd.txt

 var1  var2  var3var4

 1   6 0.3 8

 3  4 0.4 9

 2  3 0.4 6

 1   0.40.9  3



 ;read from file K2cd.txt

 var1  var2  var3var4

 1   16 0.67

 3  14 0.4 6

 2 1 3 0.4 5

 1  0.60.9  2



 the output dataframe should look like



 Fileno  var1  var2  var3var4

 1  1   6 0.38

 1  3  4 0.4 9

 1  2  3 0.4 6

 1  1   0.4  0.93

 2  1   16   0.67

 2  3  14 0.46

 2  2 1 3 0.45

 2  1  0.6 0.9   2



 Please note that new file no column is added



 Thank you for the help.



 Umesh R




   [[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] lattice: how to center a subtitle?

2011-04-04 Thread David Winsemius


On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:


Dear David,

I intended to use another x-label. But your suggestion brings me to  
the idea of just using a two-line xlab, so s.th. like
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the  
human's eye, xlab = but subtitles are _now_ centered\nbla, scales  
= list(alternating = c(1,1), tck = c(1,0


And if you wanted different fontface (underline, italic or bold) then  
you could use plotmath expressions:


xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's  
eye, xlab =  
expression( atop(but~subtitles2~are~underline(now)~centered,  
bold(bla) )), scales = list(alternating = c(1,1), tck = c(1,0)))


--
David.



Thanks!

Cheers,

Marius

On 2011-04-04, at 16:47 , David Winsemius wrote:



On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:


Dear expeRts,

I recently asked for a real centered title (see, e.g., http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html) 
.
A nice solution (from Deepayan Sarkar) is to use xlab.top  
instead of main:


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for  
the human's eye, sub = but subtitles are not centered, scales =  
list(alternating = c(1,1), tck = c(1,0

dev.off()


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for  
the human's eye, xlab = but subtitles are _now_ centered, scales  
= list(alternating = c(1,1), tck = c(1,0

dev.off()


(I realize that those are not really subtitles by a 'lab', but that  
appears acceptable in your current test case.)




My question is whether there is something similar for *sub*titles  
[so something like xlab.bottom]? As you can see from the plot,  
the subtitle does not seem to be centered for the human's eye. I  
would like to center it according to the x-axis label.





David Winsemius, MD
West Hartford, CT





David Winsemius, MD
West Hartford, CT

__
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] merging 2 frames while keeping all the entries from the reference frame

2011-04-04 Thread Dimitri Liakhovitski
Hello!
I have my data frame mydata (below) and data frame reference -
that contains all the dates I would like to be present in the final
data frame.
I am trying to merge them so that the the result data frame contains
all 8 dates in both subgroups (i.e., Group1 should have 8 rows and
Group2 too). But when I merge it it's not coming out this way. Any
hint would be greatly appreciated!
Dimitri

mydata-data.frame(mydate=rep(seq(as.Date(2008-12-29), length = 8,
by = week),2),
group=c(rep(Group1,8),rep(Group2,8)),values=rnorm(16,1,1))
(reference);(mydata)
set.seed(1234)
out-sample(1:16,5,replace=F)
mydata-mydata[-out,]; dim(mydata)
(mydata)

# reference contains the dates I want to be present in the final data frame:
reference-data.frame(mydate=seq(as.Date(2008-12-29), length = 8, by
= week))

# Merging:
new.data-merge(mydata,reference,by=mydate,all.x=T,all.y=T)
new.data-new.data[order(new.data$group,new.data$mydate),]
(new.data)
# my new.data contains only 7 rows in Group 1 and 4 rows in Group 2


-- 
Dimitri Liakhovitski
Ninah Consulting

__
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] Questions remaining: define any character as na.string RE: merging data list in to single data frame

2011-04-04 Thread David Winsemius


On Apr 4, 2011, at 12:37 PM, Umesh Rosyara wrote:


Dear Uwe and R community members

Thank you Uwe for the help.

I have still a question remaining, I am trying to find answer from  
long

time.

While exporting my data, I have some characters mixed into it. I  
want to

define any characters as na.string? Is it possible to do so?


Option 1: do it in an editor that is regex aware.
Option 2: input the file with readLines, use gsub to remove the  
unwanted characters, read.table(textConnection(obj))  on the resulting  
object. [There are many worked examples in the archives. Search on  
read.table(textConnection(  .]


--
David.




Thanks;

Umesh



-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Sent: Monday, April 04, 2011 12:22 PM
To: Umesh Rosyara
Cc: r-help@r-project.org; rosyar...@gmail.com
Subject: Re: [R] merging data list in to single data frame



On 04.04.2011 16:41, Umesh Rosyara wrote:

Dear R community members



I did find a good way to merge my 200 text data files in to a  
single data

file with one column added will show indicator for that file.



filelist = list.files(pattern = K*cd.txt)



I doubt you meant K*cd.txt but ^K[[:digit:]]*cd\\.txt$.



# the file names are K1cd.txt

.to K200cd.txt

data_list-lapply(filelist, read.table, header=T, comment=;,  
fill=T)



Replace by:

data_list - lapply(filelist, function(x)
   cbind(Filename = x, read.table(x, header=T, comment=;,  
fill=TRUE))



And then:

result - do.call(rbind, data_list)

Uwe Ligges






This will create list, but this is not what I want.



I want a single dataframe (all separate dataframes have same variable
headings) with additional row for example



; just for example, two small datasets are created by my component

datasets

are huge, need automation

;read from file K1cd.txt

var1  var2  var3var4

1   6 0.3 8

3  4 0.4 9

2  3 0.4 6

1   0.40.9  3



;read from file K2cd.txt

var1  var2  var3var4

1   16 0.67

3  14 0.4 6

2 1 3 0.4 5

1  0.60.9  2



the output dataframe should look like



Fileno  var1  var2  var3var4

1  1   6 0.38

1  3  4 0.4 9

1  2  3 0.4 6

1  1   0.4  0.93

2  1   16   0.67

2  3  14 0.46

2  2 1 3 0.45

2  1  0.6 0.9   2



Please note that new file no column is added



Thank you for the help.



Umesh R




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


David Winsemius, MD
West Hartford, CT

__
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] merging 2 frames while keeping all the entries from the reference frame

2011-04-04 Thread Dimitri Liakhovitski
To clarify just in case, here is the result I am trying to get:

mydate  group   values
12/29/2008  Group1  0.453466522
1/5/2009Group1  NA
1/12/2009   Group1  0.416548943
1/19/2009   Group1  2.066275155
1/26/2009   Group1  2.037729638
2/2/2009Group1  -0.598040483
2/9/2009Group1  1.658999227
2/16/2009   Group1  -0.869325211
12/29/2008  Group2  NA
1/5/2009Group2  NA
1/12/2009   Group2  NA
1/19/2009   Group2  0.375284194
1/26/2009   Group2  0.706785401
2/2/2009Group2  NA
2/9/2009Group2  2.104937151
2/16/2009   Group2  2.880393978



On Mon, Apr 4, 2011 at 1:09 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 Hello!
 I have my data frame mydata (below) and data frame reference -
 that contains all the dates I would like to be present in the final
 data frame.
 I am trying to merge them so that the the result data frame contains
 all 8 dates in both subgroups (i.e., Group1 should have 8 rows and
 Group2 too). But when I merge it it's not coming out this way. Any
 hint would be greatly appreciated!
 Dimitri

 mydata-data.frame(mydate=rep(seq(as.Date(2008-12-29), length = 8,
 by = week),2),
 group=c(rep(Group1,8),rep(Group2,8)),values=rnorm(16,1,1))
 (reference);(mydata)
 set.seed(1234)
 out-sample(1:16,5,replace=F)
 mydata-mydata[-out,]; dim(mydata)
 (mydata)

 # reference contains the dates I want to be present in the final data frame:
 reference-data.frame(mydate=seq(as.Date(2008-12-29), length = 8, by
 = week))

 # Merging:
 new.data-merge(mydata,reference,by=mydate,all.x=T,all.y=T)
 new.data-new.data[order(new.data$group,new.data$mydate),]
 (new.data)
 # my new.data contains only 7 rows in Group 1 and 4 rows in Group 2


 --
 Dimitri Liakhovitski
 Ninah Consulting




-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.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] lattice: how to center a subtitle?

2011-04-04 Thread Marius Hofert
Dear David,

do you know how to get plotmath-like symbols in both rows?
I tried s.th. like:

lab - expression(paste(alpha==1, , , beta==2, sep=))
xlab - substitute(expression( atop(lab==lab., bold(foo)) ), list(lab.=lab))
xyplot(0 ~ 0, xlab = xlab)

Cheers,

Marius

On 2011-04-04, at 18:59 , David Winsemius wrote:

 
 On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:
 
 Dear David,
 
 I intended to use another x-label. But your suggestion brings me to the idea 
 of just using a two-line xlab, so s.th. like
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
 eye, xlab = but subtitles are _now_ centered\nbla, scales = 
 list(alternating = c(1,1), tck = c(1,0
 
 And if you wanted different fontface (underline, italic or bold) then you 
 could use plotmath expressions:
 
 xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's eye, 
 xlab = expression( atop(but~subtitles2~are~underline(now)~centered, bold(bla) 
 )), scales = list(alternating = c(1,1), tck = c(1,0)))
 
 -- 
 David.
 
 
 Thanks!
 
 Cheers,
 
 Marius
 
 On 2011-04-04, at 16:47 , David Winsemius wrote:
 
 
 On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:
 
 Dear expeRts,
 
 I recently asked for a real centered title (see, e.g., 
 http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
 A nice solution (from Deepayan Sarkar) is to use xlab.top instead of 
 main:
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the 
 human's eye, sub = but subtitles are not centered, scales = 
 list(alternating = c(1,1), tck = c(1,0
 dev.off()
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the 
 human's eye, xlab = but subtitles are _now_ centered, scales = 
 list(alternating = c(1,1), tck = c(1,0
 dev.off()
 
 
 (I realize that those are not really subtitles by a 'lab', but that appears 
 acceptable in your current test case.)
 
 
 My question is whether there is something similar for *sub*titles [so 
 something like xlab.bottom]? As you can see from the plot, the subtitle 
 does not seem to be centered for the human's eye. I would like to center 
 it according to the x-axis label.
 
 
 
 David Winsemius, MD
 West Hartford, CT
 
 
 
 David Winsemius, MD
 West Hartford, CT
 

__
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] lattice: how to center a subtitle?

2011-04-04 Thread David Winsemius


On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:


Dear David,

do you know how to get plotmath-like symbols in both rows?
I tried s.th. like:

lab - expression(paste(alpha==1, , , beta==2, sep=))
xlab - substitute(expression( atop(lab==lab., bold(foo)) ),  
list(lab.=lab))

xyplot(0 ~ 0, xlab = xlab)


I _did_ have plotmath functions in both rows: But here is your solution:

xyplot(0 ~ 0,  xlab =
expression( atop(paste(alpha==1,, beta==2), bold(bla) )) )
  )

Note that `paste` in plotmath is different than `paste` in regular R.  
It has no `sep` argument. I did try both substitute and bquote on you  
externally expression,  but lattice seems to be doing some non- 
standard evaluation and I never got it to work. Using what I thought  
_should_ work, does work with `plot`:


 x=1;y=2
 plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),  
bold(foo) ) )

+ )

But the same expression throws an error with xyplot:
 x=1;y=2
 xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y),  
bold(foo) ) )

+ )
Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect =  
fill,  :

  could not find function atop

--
David.




Cheers,

Marius

On 2011-04-04, at 18:59 , David Winsemius wrote:



On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:


Dear David,

I intended to use another x-label. But your suggestion brings me  
to the idea of just using a two-line xlab, so s.th. like
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for  
the human's eye, xlab = but subtitles are _now_ centered\nbla,  
scales = list(alternating = c(1,1), tck = c(1,0


And if you wanted different fontface (underline, italic or bold)  
then you could use plotmath expressions:


xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the  
human's eye, xlab =  
expression( atop(but~subtitles2~are~underline(now)~centered,  
bold(bla) )), scales = list(alternating = c(1,1), tck = c(1,0)))


--
David.



Thanks!

Cheers,

Marius

On 2011-04-04, at 16:47 , David Winsemius wrote:



On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:


Dear expeRts,

I recently asked for a real centered title (see, e.g., http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html) 
.
A nice solution (from Deepayan Sarkar) is to use xlab.top  
instead of main:


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for  
the human's eye, sub = but subtitles are not centered, scales  
= list(alternating = c(1,1), tck = c(1,0

dev.off()


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for  
the human's eye, xlab = but subtitles are _now_ centered,  
scales = list(alternating = c(1,1), tck = c(1,0

dev.off()


(I realize that those are not really subtitles by a 'lab', but  
that appears acceptable in your current test case.)




My question is whether there is something similar for  
*sub*titles [so something like xlab.bottom]? As you can see  
from the plot, the subtitle does not seem to be centered for  
the human's eye. I would like to center it according to the x- 
axis label.





David Winsemius, MD
West Hartford, CT





David Winsemius, MD
West Hartford, CT





David Winsemius, MD
West Hartford, CT

__
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] lattice: how to center a subtitle?

2011-04-04 Thread Peter Ehlers

On 2011-04-04 10:27, Marius Hofert wrote:

Dear David,

do you know how to get plotmath-like symbols in both rows?
I tried s.th. like:

lab- expression(paste(alpha==1, , , beta==2, sep=))
xlab- substitute(expression( atop(lab==lab., bold(foo)) ), list(lab.=lab))
xyplot(0 ~ 0, xlab = xlab)


Marius,

I always find paste a bit tricky with plotmath.
Maybe this will do what you want:

 mylab - expression( atop(lab==list(alpha==1, beta==2), bold(foo)) )
 xyplot(0 ~ 0, xlab = mylab)

Peter Ehlers



Cheers,

Marius

On 2011-04-04, at 18:59 , David Winsemius wrote:



On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:


Dear David,

I intended to use another x-label. But your suggestion brings me to the idea of 
just using a two-line xlab, so s.th. like
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's eye, xlab = 
but subtitles are _now_ centered\nbla, scales = list(alternating = c(1,1), tck = 
c(1,0


And if you wanted different fontface (underline, italic or bold) then you could 
use plotmath expressions:

xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's eye, 
xlab = expression( atop(but~subtitles2~are~underline(now)~centered, bold(bla) )), scales 
= list(alternating = c(1,1), tck = c(1,0)))

--
David.



Thanks!

Cheers,

Marius

On 2011-04-04, at 16:47 , David Winsemius wrote:



On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:


Dear expeRts,

I recently asked for a real centered title (see, e.g., 
http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
A nice solution (from Deepayan Sarkar) is to use xlab.top instead of main:

library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's eye, sub = 
but subtitles are not centered, scales = list(alternating = c(1,1), tck = c(1,0
dev.off()


library(lattice)
trellis.device(pdf)
print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's eye, xlab = 
but subtitles are _now_ centered, scales = list(alternating = c(1,1), tck = c(1,0
dev.off()


(I realize that those are not really subtitles by a 'lab', but that appears 
acceptable in your current test case.)



My question is whether there is something similar for *sub*titles [so something like 
xlab.bottom]? As you can see from the plot, the subtitle does not seem to be 
centered for the human's eye. I would like to center it according to the x-axis label.




David Winsemius, MD
West Hartford, CT





David Winsemius, MD
West Hartford, CT



__
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] lattice: how to center a subtitle?

2011-04-04 Thread Henrique Dallazuanna
Maybe:

xyplot(0 ~ 0, xlab =
bquote(expression(atop(alpha==.(x)*,~beta==.(y), bold(foo) )) ))

On Mon, Apr 4, 2011 at 2:58 PM, David Winsemius dwinsem...@comcast.net wrote:

 On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:

 Dear David,

 do you know how to get plotmath-like symbols in both rows?
 I tried s.th. like:

 lab - expression(paste(alpha==1, , , beta==2, sep=))
 xlab - substitute(expression( atop(lab==lab., bold(foo)) ),
 list(lab.=lab))
 xyplot(0 ~ 0, xlab = xlab)

 I _did_ have plotmath functions in both rows: But here is your solution:

 xyplot(0 ~ 0,  xlab =
    expression( atop(paste(alpha==1,    , beta==2), bold(bla) )) )
      )

 Note that `paste` in plotmath is different than `paste` in regular R. It has
 no `sep` argument. I did try both substitute and bquote on you externally
 expression,  but lattice seems to be doing some non-standard evaluation and
 I never got it to work. Using what I thought _should_ work, does work with
 `plot`:

 x=1;y=2
 plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) ) )
 + )

 But the same expression throws an error with xyplot:
 x=1;y=2
 xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) )
 )
 + )
 Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect = fill,
  :
  could not find function atop

 --
 David.



 Cheers,

 Marius

 On 2011-04-04, at 18:59 , David Winsemius wrote:


 On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:

 Dear David,

 I intended to use another x-label. But your suggestion brings me to the
 idea of just using a two-line xlab, so s.th. like
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the
 human's eye, xlab = but subtitles are _now_ centered\nbla, scales =
 list(alternating = c(1,1), tck = c(1,0

 And if you wanted different fontface (underline, italic or bold) then you
 could use plotmath expressions:

 xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's
 eye, xlab = expression( atop(but~subtitles2~are~underline(now)~centered,
 bold(bla) )), scales = list(alternating = c(1,1), tck = c(1,0)))

 --
 David.


 Thanks!

 Cheers,

 Marius

 On 2011-04-04, at 16:47 , David Winsemius wrote:


 On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:

 Dear expeRts,

 I recently asked for a real centered title (see, e.g.,
 http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
 A nice solution (from Deepayan Sarkar) is to use xlab.top instead of
 main:

 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the
 human's eye, sub = but subtitles are not centered, scales =
 list(alternating = c(1,1), tck = c(1,0
 dev.off()

 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the
 human's eye, xlab = but subtitles are _now_ centered, scales =
 list(alternating = c(1,1), tck = c(1,0
 dev.off()


 (I realize that those are not really subtitles by a 'lab', but that
 appears acceptable in your current test case.)


 My question is whether there is something similar for *sub*titles [so
 something like xlab.bottom]? As you can see from the plot, the subtitle
 does not seem to be centered for the human's eye. I would like to 
 center
 it according to the x-axis label.



 David Winsemius, MD
 West Hartford, CT



 David Winsemius, MD
 West Hartford, CT



 David Winsemius, MD
 West Hartford, CT

 __
 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

__
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] Granger Causality in a VAR Model

2011-04-04 Thread ivan
Dear Community,

I am new to R and have a question concerning the causality () test in
the vars package. I need to test whether, say, the variable y Granger
causes the variable x, given z as a control variable.

I estimated the VAR model as follows: model-VAR(cbind(x,y,z),p=2)

Then I did the following: causality(model, cause=y). I thing this
tests the Granger causality of y on the vector (x,z), though. How can
I implement the test for y causing x controlled for z? Thus, the
F-test comparing the two models M1:x~lagged(x)+lagged(z) and
M2:x~lagged(x)+lagged(y)+lagged(z)?

Thank you in advance.

Best Regards

__
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] lattice: how to center a subtitle?

2011-04-04 Thread Marius Hofert
Dear all,

many thanks, that helped a lot!

Cheers,

Marius

On 2011-04-04, at 19:58 , David Winsemius wrote:

 
 On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote:
 
 Dear David,
 
 do you know how to get plotmath-like symbols in both rows?
 I tried s.th. like:
 
 lab - expression(paste(alpha==1, , , beta==2, sep=))
 xlab - substitute(expression( atop(lab==lab., bold(foo)) ), list(lab.=lab))
 xyplot(0 ~ 0, xlab = xlab)
 
 I _did_ have plotmath functions in both rows: But here is your solution:
 
 xyplot(0 ~ 0,  xlab =
expression( atop(paste(alpha==1,, beta==2), bold(bla) )) )
  )
 
 Note that `paste` in plotmath is different than `paste` in regular R. It has 
 no `sep` argument. I did try both substitute and bquote on you externally 
 expression,  but lattice seems to be doing some non-standard evaluation and I 
 never got it to work. Using what I thought _should_ work, does work with 
 `plot`:
 
  x=1;y=2
  plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) ) )
 + )
 
 But the same expression throws an error with xyplot:
  x=1;y=2
  xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) ) )
 + )
 Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect = fill,  
 :
  could not find function atop
 
 -- 
 David.
 
 
 
 Cheers,
 
 Marius
 
 On 2011-04-04, at 18:59 , David Winsemius wrote:
 
 
 On Apr 4, 2011, at 12:45 PM, Marius Hofert wrote:
 
 Dear David,
 
 I intended to use another x-label. But your suggestion brings me to the 
 idea of just using a two-line xlab, so s.th. like
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the 
 human's eye, xlab = but subtitles are _now_ centered\nbla, scales = 
 list(alternating = c(1,1), tck = c(1,0
 
 And if you wanted different fontface (underline, italic or bold) then you 
 could use plotmath expressions:
 
 xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the human's 
 eye, xlab = expression( atop(but~subtitles2~are~underline(now)~centered, 
 bold(bla) )), scales = list(alternating = c(1,1), tck = c(1,0)))
 
 -- 
 David.
 
 
 Thanks!
 
 Cheers,
 
 Marius
 
 On 2011-04-04, at 16:47 , David Winsemius wrote:
 
 
 On Apr 4, 2011, at 7:39 AM, Marius Hofert wrote:
 
 Dear expeRts,
 
 I recently asked for a real centered title (see, e.g., 
 http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0135.html).
 A nice solution (from Deepayan Sarkar) is to use xlab.top instead of 
 main:
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the 
 human's eye, sub = but subtitles are not centered, scales = 
 list(alternating = c(1,1), tck = c(1,0
 dev.off()
 
 library(lattice)
 trellis.device(pdf)
 print(xyplot(0 ~ 0, xlab.top = This title is now 'centered' for the 
 human's eye, xlab = but subtitles are _now_ centered, scales = 
 list(alternating = c(1,1), tck = c(1,0
 dev.off()
 
 
 (I realize that those are not really subtitles by a 'lab', but that 
 appears acceptable in your current test case.)
 
 
 My question is whether there is something similar for *sub*titles [so 
 something like xlab.bottom]? As you can see from the plot, the 
 subtitle does not seem to be centered for the human's eye. I would 
 like to center it according to the x-axis label.
 
 
 
 David Winsemius, MD
 West Hartford, CT
 
 
 
 David Winsemius, MD
 West Hartford, CT
 
 
 
 David Winsemius, MD
 West Hartford, CT
 

__
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] automating regression or correlations for many variables

2011-04-04 Thread geral
Dear All,

I have a large data frame with 10 rows and 82 columns. I want to apply the
same function to all of the columns with a single command. e.g. zl - lm
(snp$a_109909 ~ snp$lat) will fit a linear model to the values in lat and 
a_109909. What I want to do is fit linear models for the values in each
column against lat. I tried doing zl - (snp[,2:82] ~ snp$lat[,1]) but got
the following error message Error in model.frame.default(formula = snp[,
2:82] ~ snp[, 1], drop.unused.levels = TRUE) : 
  invalid type (list) for variable 'snp[, 2:82]'. Does this mean I cannot
use a data frame to do this? Should I have my data in a matrix instead?

Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/automating-regression-or-correlations-for-many-variables-tp3426091p3426091.html
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] Structural equation modeling in R(lavaan,sem)

2011-04-04 Thread jouba


Thanks you for your response 
For lavaan package can i have more information about this example you have 
applied in the section 7
the meanings  of The variables (c1,c2,c3,c4, i ,s ,x1,x2)
I think i have need more information to learn  more about how  able to apply 
growth model  in my data (longitudianl data)
Thanks a lot 

Antra EL MOUSSELLY 


 


Date: Mon, 4 Apr 2011 02:16:42 -0500
From: ml-node+3424797-1256108745-225...@n4.nabble.com
To: antr...@hotmail.com
Subject: Re: Structural equation modeling in R(lavaan,sem)

On 04/03/2011 09:38 PM, jouba wrote: 
 
 Daer all, I have a question concerning longitudinal data: When we 
 have a longitudinal data and we have to do sem analysis there is in 
 the package lavaan some functions,options in this package that help 
 to do this or we can treat these data like non longitudinal data 

The function 'growth' (in the lavaan package) can be used for (standard) 
growth modeling. Good material about growth modeling (using Mplus) can 
be found here: 

http://statistics.ats.ucla.edu/stat/mplus/seminars/gm/default.htm

Next, you can read how to do growth modeling with lavaan by reading 
section 7 in the lavaan intro, which you can download from the 
documentation section on the lavaan website (http://lavaan.org). 

Yves. 

-- 
Yves Rosseel -- http://www.da.ugent.be
Department of Data Analysis, Ghent University 
Henri Dunantlaan 1, B-9000 Gent, Belgium 

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






If you reply to this email, your message will be added to the discussion 
below:http://r.789695.n4.nabble.com/Structural-equation-modeling-in-R-lavaan-sem-tp3409642p3424797.html
 
To unsubscribe from Structural equation modeling in R(lavaan,sem), click here.  
  

--
View this message in context: 
http://r.789695.n4.nabble.com/Structural-equation-modeling-in-R-lavaan-sem-tp3409642p3426097.html
Sent from the R help mailing list archive at Nabble.com.
[[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] merging 2 frames while keeping all the entries from the reference frame

2011-04-04 Thread Gabor Grothendieck
On Mon, Apr 4, 2011 at 1:09 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 Hello!
 I have my data frame mydata (below) and data frame reference -
 that contains all the dates I would like to be present in the final
 data frame.
 I am trying to merge them so that the the result data frame contains
 all 8 dates in both subgroups (i.e., Group1 should have 8 rows and
 Group2 too). But when I merge it it's not coming out this way. Any
 hint would be greatly appreciated!
 Dimitri

 mydata-data.frame(mydate=rep(seq(as.Date(2008-12-29), length = 8,
 by = week),2),
 group=c(rep(Group1,8),rep(Group2,8)),values=rnorm(16,1,1))
 (reference);(mydata)
 set.seed(1234)
 out-sample(1:16,5,replace=F)
 mydata-mydata[-out,]; dim(mydata)
 (mydata)

 # reference contains the dates I want to be present in the final data frame:
 reference-data.frame(mydate=seq(as.Date(2008-12-29), length = 8, by
 = week))

 # Merging:
 new.data-merge(mydata,reference,by=mydate,all.x=T,all.y=T)
 new.data-new.data[order(new.data$group,new.data$mydate),]
 (new.data)
 # my new.data contains only 7 rows in Group 1 and 4 rows in Group 2


It might make more sense to put each group into its own column since
then the object is a multivariate time series:

 library(zoo)
 z - merge(read.zoo(mydata, split = 2), zoo(, reference[[1]]), all = c(FALSE, 
 TRUE))
 z
  Group1Group2
2008-12-29 2.0266215NA
2009-01-05NANA
2009-01-12 1.0255344NA
2009-01-19 1.3880938 0.8135788
2009-01-26 1.4380978 1.6068682
2009-02-02 1.1764965NA
2009-02-09 1.1578531 1.4484447
2009-02-16 0.6673568 1.4760864

although if you really need to you could string them out like this:

library(reshape2)
melt(data.frame(time(z), coredata(z)), id = 1)

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] merging 2 frames while keeping all the entries from the reference frame

2011-04-04 Thread Henrique Dallazuanna
Try this:

 merge(mydata, cbind(reference, group = rep(unique(mydata$group), each
= nrow(reference))), all = TRUE)

On Mon, Apr 4, 2011 at 2:24 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 To clarify just in case, here is the result I am trying to get:

 mydate  group   values
 12/29/2008      Group1  0.453466522
 1/5/2009        Group1  NA
 1/12/2009       Group1  0.416548943
 1/19/2009       Group1  2.066275155
 1/26/2009       Group1  2.037729638
 2/2/2009        Group1  -0.598040483
 2/9/2009        Group1  1.658999227
 2/16/2009       Group1  -0.869325211
 12/29/2008      Group2  NA
 1/5/2009        Group2  NA
 1/12/2009       Group2  NA
 1/19/2009       Group2  0.375284194
 1/26/2009       Group2  0.706785401
 2/2/2009        Group2  NA
 2/9/2009        Group2  2.104937151
 2/16/2009       Group2  2.880393978



 On Mon, Apr 4, 2011 at 1:09 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 Hello!
 I have my data frame mydata (below) and data frame reference -
 that contains all the dates I would like to be present in the final
 data frame.
 I am trying to merge them so that the the result data frame contains
 all 8 dates in both subgroups (i.e., Group1 should have 8 rows and
 Group2 too). But when I merge it it's not coming out this way. Any
 hint would be greatly appreciated!
 Dimitri

 mydata-data.frame(mydate=rep(seq(as.Date(2008-12-29), length = 8,
 by = week),2),
 group=c(rep(Group1,8),rep(Group2,8)),values=rnorm(16,1,1))
 (reference);(mydata)
 set.seed(1234)
 out-sample(1:16,5,replace=F)
 mydata-mydata[-out,]; dim(mydata)
 (mydata)

 # reference contains the dates I want to be present in the final data 
 frame:
 reference-data.frame(mydate=seq(as.Date(2008-12-29), length = 8, by
 = week))

 # Merging:
 new.data-merge(mydata,reference,by=mydate,all.x=T,all.y=T)
 new.data-new.data[order(new.data$group,new.data$mydate),]
 (new.data)
 # my new.data contains only 7 rows in Group 1 and 4 rows in Group 2


 --
 Dimitri Liakhovitski
 Ninah Consulting




 --
 Dimitri Liakhovitski
 Ninah Consulting
 www.ninah.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

__
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] merging data list in to single data frame

2011-04-04 Thread Dennis Murphy
Hi:

Here's an alternative using ldply() from the plyr package. The idea is to
read the data frames into a list, name them accordingly and then call
ldply().

# Read in the test data frames (you want to use list.files() instead to
input the data per Uwe's guidelines)
df1 - read.table(textConnection(
+ var1  var2  var3var4
+ 1   6 0.3 8
+ 3  4 0.4 9
+ 2  3 0.4 6
+ 1   0.40.9  3), header = TRUE)
 df2 - read.table(textConnection(
+ var1 var2 var3 var4
+ 1 16 0.6 7
+ 3 14 0.4 6
+ 2 13 0.4 5
+ 1 0.6 0.9 2), header = TRUE)
closeAllConnections()
# generate the list
dl - list(df1, df2)

# Name the list components by number and then call ldply():
names(dl) - 1:2  # more generally, names(dl) - 1:length(dl)
library(plyr)
ldply(dl, rbind)
  .id var1 var2 var3 var4
1   11  6.0  0.38
2   13  4.0  0.49
3   12  3.0  0.46
4   11  0.4  0.93
5   21 16.0  0.67
6   23 14.0  0.46
7   22 13.0  0.45
8   21  0.6  0.92

You can always change .id to fileno afterwards.

HTH,
Dennis

On Mon, Apr 4, 2011 at 7:41 AM, Umesh Rosyara rosy...@msu.edu wrote:

 Dear R community members



 I did find a good way to merge my 200 text data files in to a single data
 file with one column added will show indicator for that file.



 filelist = list.files(pattern = K*cd.txt) # the file names are K1cd.txt
 .to K200cd.txt

 data_list -lapply(filelist, read.table, header=T, comment=;, fill=T)



 This will create list, but this is not what I want.



 I want a single dataframe (all separate dataframes have same variable
 headings) with additional row for example



 ; just for example, two small datasets are created by my component datasets
 are huge, need automation

 ;read from file K1cd.txt

 var1  var2  var3var4

 1   6 0.3 8

 3  4 0.4 9

 2  3 0.4 6

 1   0.40.9  3



 ;read from file K2cd.txt

 var1  var2  var3var4

 1   16 0.67

 3  14 0.4 6

 2 1 3 0.4 5

 1  0.60.9  2



 the output dataframe should look like



 Fileno  var1  var2  var3var4

 1  1   6 0.38

 1  3  4 0.4 9

 1  2  3 0.4 6

 1  1   0.4  0.93

 2  1   16   0.67

 2  3  14 0.46

 2  2 1 3 0.45

 2  1  0.6 0.9   2



 Please note that new file no column is added



 Thank you for the help.



 Umesh R




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


[[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] automating regression or correlations for many variables

2011-04-04 Thread Dennis Murphy
Hi:

Here's a small example:
 df - data.frame(y1 = rnorm(10), y2 = rnorm(10), y3 = rnorm(10), lat =
rnorm(10))
 m - lm(cbind(y1, y2, y3) ~ lat, data = df)
 summary(m)
snip...provides summaries for each response

The LHS of the model formula needs to be a matrix. In your case, something
like

m - lm(as.matrix(snp[, -1])  ~ lat, data = snp)

ought to work.

HTH,
Dennis


On Mon, Apr 4, 2011 at 10:13 AM, geral geral...@mail.ubc.ca wrote:

 Dear All,

 I have a large data frame with 10 rows and 82 columns. I want to apply the
 same function to all of the columns with a single command. e.g. zl - lm
 (snp$a_109909 ~ snp$lat) will fit a linear model to the values in lat and
 a_109909. What I want to do is fit linear models for the values in each
 column against lat. I tried doing zl - (snp[,2:82] ~ snp$lat[,1]) but got
 the following error message Error in model.frame.default(formula = snp[,
 2:82] ~ snp[, 1], drop.unused.levels = TRUE) :
  invalid type (list) for variable 'snp[, 2:82]'. Does this mean I cannot
 use a data frame to do this? Should I have my data in a matrix instead?

 Thanks

 --
 View this message in context:
 http://r.789695.n4.nabble.com/automating-regression-or-correlations-for-many-variables-tp3426091p3426091.html
 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.


[[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] zoo:rollapply by multiple grouping factors

2011-04-04 Thread Gabor Grothendieck
On Mon, Apr 4, 2011 at 3:40 PM, Mark Novak mnov...@ucsc.edu wrote:
 Thank you very much Gabor!  It looks like that's gonna work wonderfully.  I
 didn't even know 'ave' existed.

 For others out there:  I only needed to add a comma:   dat[,c(Site,
 Plot, Sp)]

Actually, if dd is a data frame dd[, ix] and dd[ix] give the same result. e.g.

 dd - data.frame(a = 1:3, b = 11:13, c = 21:23)
 identical(dd[, c(b, c)], dd[c(b, c)])
[1] TRUE

 Small follow up Q:  Is there any reason to use 'aggregate' vs. 'ave' in
 general?

aggregate reduces the data to fewer rows. ave adds a potentially
additional column to the original data.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] Linear Model with curve fitting parameter?

2011-04-04 Thread Steven McKinney

 -Original Message-
 From: stephen sefick [mailto:ssef...@gmail.com]
 Sent: April-03-11 5:35 PM
 To: Steven McKinney
 Cc: R help
 Subject: Re: [R] Linear Model with curve fitting parameter?
 
 Steven:
 
 You are exactly right sorry I was confused.
 
 
 ###
 so log(y-intercept)+log(K) is a constant called b0 (is this right?)

Doesn't look right to me based on the information you've provided.
I don't see anything labeled y in your previous emails, so I'm
not clear on what y is and how it relates to the original model 
you described

 I have a model Q=K*A*(R^r)*(S^s)

 A, R, and S are data I have and K is a curve fitting parameter. 

If the model is 
  
   Q=K*A*(R^r)*(S^s)

then

   log(Q) = log(K) + log(A) + r*log(R) + s*log(S)

Rearranging yields

   log(Q) - log(A) = log(K) + r*log(R) + s*log(S)

Let  Z = log(Q) - log(A) = log(Q/A)

so

   Z = log(K) + r*log(R) + s*log(S)

and a linear model fit of
   
   Z ~ log(R) + log(S)

will yield parameter estimates for the linear equation

   E(Z) = B0 + B1*log(R) + B2*log(S)

(E(Z) = expected value of Z)

so B0 estimate is an estimate of log(K)
   B1 estimate is an estimate of r
   B2 estimate is an estimate of s

and these are the only parameters you described in the original model.


 
 lm(log(Q)~log(A)+log(R)+log(S)-1)
 
 is fitting the model
 
 log(Q)=a*log(A)+r*log(R)+s*log(S) (no beta 0)
 
 and
 
 lm(log(Q)~log(A)+log(R)+log(S))
 
 
 is fitting the model
 
 log(Q)=b0+a*log(A)+r*log(R)+s*log(S)

K has disappeared from these equations so these model fits do
not correspond to the model originally described.  Now a b0
appears, and is used in models below.  I think changing notation
is also adding confusion.  What are y and intercept you
discuss above, in relation to your original notation?

 
 ##
 
 These are the models I am trying to fit and if I have reasoned
 correctly above then I should be able to fit the below models
 similarly.

You will be able to fit models appropriately once you have a
clearly defined system of notation that allows you to map between
the proposed data model, the parameters in that model, and the
corresponding regression equations.  

Once you have consistent notation, you will be able to see
if you can express your model as a linear regression, or
if not, what kind of non-linear regression you will need to
do to get estimates for the parameters in your model.

Best

Steve McKinney

 
 manning
 log(Q)=log(b0)+log(K)+log(A)+r*log(R)+s*log(S)
 
 dingman
 log(Q)=log(b0)+log(K)+a*log(A)+r*log(R)+s*(log(S))^2
 
 bjerklie
 log(Q)=log(b0)+log(K)+a*log(A)+r*log(R)+s*log(S)
 
 ###
 
 Thank you for all of your help!
 
 Stephen
 
 On Fri, Apr 1, 2011 at 2:44 PM, Steven McKinney smckin...@bccrc.ca wrote:
 
  -Original Message-
  From: stephen sefick [mailto:ssef...@gmail.com]
  Sent: April-01-11 5:44 AM
  To: Steven McKinney
  Cc: R help
  Subject: Re: [R] Linear Model with curve fitting parameter?
 
  Setting Z=Q-A would be the incorrect dimensions.  I could Z=Q/A.
 
  I suspect this is confusion about what Q is.  I was presuming that
  the Q in this following formula was log(Q) with Q from the original data.
 
   I have taken the log of the data that I have and this is the model
   formula without the K part
  
   lm(Q~offset(A)+R+S, data=x)
 
  If the model is
 
    Q=K*A*(R^r)*(S^s)
 
  then
 
    log(Q) = log(K) + log(A) + r*log(R) + s*log(S)
 
  Rearranging yields
 
    log(Q) - log(A) = log(K) + r*log(R) + s*log(S)
 
  so what I labeled 'Z' below is
 
    Z = log(Q) - log(A) = log(Q/A)
 
  so
 
    Z = log(K) + r*log(R) + s*log(S)
 
  and a linear model fit of
 
    Z ~ log(R) + log(S)
 
  will yield parameter estimates for the linear equation
 
    E(Z) = B0 + B1*log(R) + B2*log(S)
 
  (E(Z) = expected value of Z)
 
  so B0 estimate is an estimate of log(K)
    B1 estimate is an estimate of r
    B2 estimate is an estimate of s
 
  More details and careful notation will eventually lead
  to a reasonable description and analysis strategy.
 
 
  Best
 
  Steve McKinney
 
 
 
  Is fitting a nls model the same as fitting an ols?  These data are
  hydraulic data from ~47 sites.  To access predictive ability I am
  removing one site fitting a new model and then accessing the fit with
  a myriad of model assessment criteria.  I should get the same answer
  with ols vs nls?  Thank you for all of your help.
 
  Stephen
 
  On Thu, Mar 31, 2011 at 8:34 PM, Steven McKinney smckin...@bccrc.ca 
  wrote:
  
   -Original Message-
   From: r-help-boun...@r-project.org 
   [mailto:r-help-boun...@r-project.org] On Behalf Of stephen
  sefick
   Sent: March-31-11 3:38 PM
   To: R help
   Subject: [R] Linear Model with curve fitting parameter?
  
   I have a model Q=K*A*(R^r)*(S^s)
  
   A, R, and S are data I have and K is a curve fitting parameter.  I
   have 

Re: [R] zoo:rollapply by multiple grouping factors

2011-04-04 Thread Mark Novak
Thank you very much Gabor!  It looks like that's gonna work 
wonderfully.  I didn't even know 'ave' existed.


For others out there:  I only needed to add a comma:   dat[,c(Site, 
Plot, Sp)]


Small follow up Q:  Is there any reason to use 'aggregate' vs. 'ave' in 
general?


-mark


On 4/3/11 3:27 PM, Gabor Grothendieck wrote:

Try ave:

dat$cv- ave(dat$Count, dat[c(Site, Plot, Sp)], FUN =
function(x) rollapply(zoo(x), 2, cv, na.pad = TRUE, align = right))



On Sun, Apr 3, 2011 at 11:58 AM, Mark Novakmnov...@ucsc.edu  wrote:

# Hi there,
# I am trying to apply a function over a moving-window for a large number of
multivariate time-series that are grouped in a nested set of factors.  I
have spent a few days searching for solutions with no luck, so any
suggestions are much appreciated.

# The data I have are for the abundance dynamics of multiple species
observed in multiple fixed plots at multiple sites.  (I total I have 7
sites, ~3-5 plots/site, ~150 species/plot, for 60 time-steps each.) So my
data look something like this:

dat-data.frame(Site=rep(1), Plot=rep(c(rep(1,8),rep(2,8),rep(3,8)),1),
Time=rep(c(1,1,2,2,3,3,4,4)), Sp=rep(1:2), Count=sample(24))
dat

# Let the function I want to apply over a right-aligned window of w=2 time
steps be:
cv-function(x){sd(x)/mean(x)}
w-2

# The final output I want would look something like this:
Out-data.frame(dat,CV=round(c(NA,NA,runif(6,0,1),c(NA,NA,runif(6,0,1))),2))

# I could reshape and apply zoo:rollapply() to a given plot at a given site,
and reshape again as follows:
library(zoo)
a-subset(dat,Site==1Plot==1)
b-reshape(a[-c(1,2)],v.names='Count',idvar='Time',timevar='Sp',direction='wide')
d-zoo(b[,-1],b[,1])
d
out-rollapply(d, w, cv, na.pad=T, align='right')
out

# I would thereby have to loop through all my sites and plots which,
although it deals with all species at once, still seems exceedingly
inefficient.

# So the question is, how do I use something like aggregate.zoo or tapply or
even lapply to apply rollapply on each species' time series.

# The closest I've come is the following two approaches:

# First let:
datx-list(Site=dat$Site,Plot=dat$Plot,Sp=dat$Sp)
daty-dat$Count

# Method 1.
out1-tapply(seq(along=daty),datx,function(i,x=daty){ rollapply(zoo(x[i]),
w, cv, na.pad=T, align='right') })
out1
out1[,,1]

# Which works in that it gives me the right answers, but in a format from
which I can't figure out how to get back into the format I want.

# Method 2.
fun-function(x){y-zoo(x);coredata(rollapply(y, w,
cv,na.pad=T,align='right'))}
out2-aggregate(daty,by=datx,fun)
out2

# Which superficially works better, but again only in a format I can't
figure out how to use because the output seems to be a mix of data.frame and
lists.
out2[1,4]
out2[1,5]
is.data.frame(out2)
is.list(out2)

# The situation is made more problematic by the fact that the time point of
first survey can differ between plots  (e.g., site1-plot3 may only start at
time-point 3).  As in...
dat2-dat
dat2-dat2[-which(dat2$Plot==3  dat2$Time3),]
dat2

# I must therefore ensure that I'm keeping track of the true time associated
with each value, not just the order of their occurences.  This information
is (seemingly) lost by both methods.
datx-list(Site=dat2$Site,Plot=dat2$Plot,Sp=dat2$Sp)
daty-dat2$Count

# Method 1.
out3-tapply(seq(along=daty),datx,function(i,x=daty){ rollapply(zoo(x[i]),
w, cv, na.pad=T, align='right') })
out3
out3[1,3,1]
time(out3[1,3,1])

# Method 2
out4-aggregate(daty,by=datx,fun)
out4
time(out4[3,4])


# Am I going about this all wrong?  Is there a different package to try?
  Any thoughts and suggestions are much appreciated!

# R 2.12.2 GUI 1.36 Leopard build 32-bit (5691); zoo 1.6-4

# Thanks!
# -mark





__
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] General binary search?

2011-04-04 Thread Stavros Macrakis
Is there a generic binary search routine in a standard library which

   a) works for character vectors
   b) runs in O(log(N)) time?

I'm aware of findInterval(x,vec), but it is restricted to numeric vectors.

I'm also aware of various hashing solutions (e.g. new.env(hash=TRUE) and
fastmatch), but I need the greatest-lower-bound match in my application.

findInterval is also slow for large N=length(vec) because of the O(N)
checking it does, as Duncan Murdoch has pointed
outhttps://stat.ethz.ch/pipermail/r-help/2008-September/174584.html:
though
its documentation says it runs in O(n * log(N)), it actually runs in O(n *
log(N) + N), which is quite noticeable for largish N.  But that is easy
enough to work around by writing a variant of findInterval which calls
find_interv_vec without checking.

-s

PS Yes, binary search is a one-liner in R, but I always prefer to use
standard, fast native libraries when possible

binarysearch - function(val,tab,L,H) {while (H=L) { M=L+(H-L) %/% 2; if
(tab[M]val) H-M-1 else if (tab[M]val) L-M+1 else return(M)};
return(L-1)}

[[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] merging data list in to single data frame

2011-04-04 Thread Umesh Rosyara
Thank you Dennis for the solution. It is a step ahead..However I need to
read all 200 files as  dataframes one-by-one. Can we automate this process.
I used the following step to read all file at once however the data_list
ended as list. 

 

filelist = list.files(pattern = K*cd.txt) # the file names are K1cd.txt
.to K200cd.txt

data_list -lapply(filelist, read.table, header=T, comment=;, fill=T)
names(filelist) - 1:length(filelist)

library(plyr)

ldply(data_list, rbind)

 

I tried to use your approach to list, is not successful to have the var  .id
(otherwise it is binding the component dataframes !), probably this is
applicable to component data frames not list with many data frames. 

Do you any suggestion on using fuctions that can read the files (as I did
above) and save as new dataframe (for example DF1.DF2) not a list of 200
data frames? If we can do that then we will able to use this approach.

 

Thank you so much,

Umesh R 



 

From: Dennis Murphy [mailto:djmu...@gmail.com] 
Sent: Monday, April 04, 2011 3:25 PM
To: Umesh Rosyara
Cc: r-help@r-project.org; rosyar...@gmail.com
Subject: Re: [R] merging data list in to single data frame

 

Hi:

Here's an alternative using ldply() from the plyr package. The idea is to
read the data frames into a list, name them accordingly and then call
ldply().

# Read in the test data frames (you want to use list.files() instead to
input the data per Uwe's guidelines)
df1 - read.table(textConnection(
+ var1  var2  var3var4
+ 1   6 0.3 8
+ 3  4 0.4 9
+ 2  3 0.4 6
+ 1   0.40.9  3), header = TRUE)
 df2 - read.table(textConnection(
+ var1 var2 var3 var4
+ 1 16 0.6 7
+ 3 14 0.4 6
+ 2 13 0.4 5
+ 1 0.6 0.9 2), header = TRUE)
closeAllConnections()
# generate the list
dl - list(df1, df2)

# Name the list components by number and then call ldply():
names(dl) - 1:2  # more generally, names(dl) - 1:length(dl)
library(plyr)
ldply(dl, rbind)
  .id var1 var2 var3 var4
1   11  6.0  0.38
2   13  4.0  0.49
3   12  3.0  0.46
4   11  0.4  0.93
5   21 16.0  0.67
6   23 14.0  0.46
7   22 13.0  0.45
8   21  0.6  0.92

You can always change .id to fileno afterwards.

HTH,
Dennis

On Mon, Apr 4, 2011 at 7:41 AM, Umesh Rosyara rosy...@msu.edu wrote:

Dear R community members



I did find a good way to merge my 200 text data files in to a single data
file with one column added will show indicator for that file.



filelist = list.files(pattern = K*cd.txt) # the file names are K1cd.txt
.to K200cd.txt

data_list -lapply(filelist, read.table, header=T, comment=;, fill=T)



This will create list, but this is not what I want.



I want a single dataframe (all separate dataframes have same variable
headings) with additional row for example



; just for example, two small datasets are created by my component datasets
are huge, need automation

;read from file K1cd.txt

var1  var2  var3var4

1   6 0.3 8

3  4 0.4 9

2  3 0.4 6

1   0.40.9  3



;read from file K2cd.txt

var1  var2  var3var4

1   16 0.67

3  14 0.4 6

2 1 3 0.4 5

1  0.60.9  2



the output dataframe should look like



Fileno  var1  var2  var3var4

1  1   6 0.38

1  3  4 0.4 9

1  2  3 0.4 6

1  1   0.4  0.93

2  1   16   0.67

2  3  14 0.46

2  2 1 3 0.45

2  1  0.6 0.9   2



Please note that new file no column is added



Thank you for the help.



Umesh R




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

 


[[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] automating regression or correlations for many variables

2011-04-04 Thread geral
Thanks!

I must confess I am just a beginner, but I followed your suggestion and did
'm - lm(as.matrix(snp[, -1])  ~ lat, data = snp) ' and it worked perfectly.
I would like to understand what is being done here. as.matrix I understand
makes my data frame be a matrix, but I don't understand the part snp[,-1]. I
think I am saying use all rows of... but I don't understand the -1, does
that mean, all columns but column 1?

I really appreciate the help! It was really really valuable. 

A related question is, what is m? If I do is.object(m) I get true. so I
guess it is an object. I now need to use each of the fitted models for more
things, such as calculate anova, etc... How do I do that? When I do this
column by column I just do anova(m), but it does not seem to work now...

Thanks!
AG

--
View this message in context: 
http://r.789695.n4.nabble.com/automating-regression-or-correlations-for-many-variables-tp3426091p3426519.html
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] General binary search?

2011-04-04 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Stavros Macrakis
 Sent: Monday, April 04, 2011 1:15 PM
 To: r-help
 Subject: [R] General binary search?
 
 Is there a generic binary search routine in a standard library which
 
a) works for character vectors
b) runs in O(log(N)) time?
 
 I'm aware of findInterval(x,vec), but it is restricted to 
 numeric vectors.

xtfrm(x) will convert a character (or other) vector to
a numeric vector with the same ordering.  findInterval
can work on that.  E.g., 
f0 - function(x, vec) {
   tmp - xtfrm(c(x, vec))
   findInterval(tmp[seq_along(x)], tmp[-seq_along(x)])
 }
f0(c(Baby, Aunt, Dog), LETTERS)
   [1] 2 1 4
I've never looked at its speed.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 
 I'm also aware of various hashing solutions (e.g. 
 new.env(hash=TRUE) and
 fastmatch), but I need the greatest-lower-bound match in my 
 application.
 
 findInterval is also slow for large N=length(vec) because of the O(N)
 checking it does, as Duncan Murdoch has pointed
 outhttps://stat.ethz.ch/pipermail/r-help/2008-September/174584.html:
 though
 its documentation says it runs in O(n * log(N)), it actually 
 runs in O(n *
 log(N) + N), which is quite noticeable for largish N.  But 
 that is easy
 enough to work around by writing a variant of findInterval which calls
 find_interv_vec without checking.
 
 -s
 
 PS Yes, binary search is a one-liner in R, but I always prefer to use
 standard, fast native libraries when possible
 
 binarysearch - function(val,tab,L,H) {while (H=L) { 
 M=L+(H-L) %/% 2; if
 (tab[M]val) H-M-1 else if (tab[M]val) L-M+1 else return(M)};
 return(L-1)}
 
   [[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] moving mean and moving variance functions

2011-04-04 Thread skfgla...@gmail.com
Thanks, I had recently seen reference to caTools but had forgotten about it.

Much appreciated.


friedman.st...@gmail.com
517-648-6290

-Original message-
From: Gabor Grothendieck ggrothendi...@gmail.com
To: Steve Friedman skfgla...@gmail.com
Cc: r-help@r-project.org
Sent: Mon, Apr 4, 2011 13:17:36 GMT+00:00
Subject: Re: [R] moving mean and moving variance functions

On Mon, Apr 4, 2011 at 8:30 AM, Steve Friedman skfgla...@gmail.com wrote:
 Hello


 Lets say as an example I have a dataframe with the following attributes:
 rownum(1:405), colnum(1:287), year(2000:2009), daily(rownum x colnum x year)
 and foragePotential (0:1, by 0.01).  The data is actually stored in a netcdf
 file and I'm trying to provide a conceptual version of the data.

 Ok. I need to calculate a moving mean and a moving variance for each cell on
 the following temporal
 windows - 7 day, 14 day, and 28 day. So far I have code for the moving
 average.

 ma - function(x , n) {
          filter(x, rep(1/n, n), sides = 1)
      }   # note that when the function is used, n is defined for the
 temporal period (7, 14, and 28), and x is the input variable.


 ma7 -   ma(dat, 7)  # where dat is accessing the foraging potential of the
 birds.
 ma14 - ma(dat, 14)
 ma28 - ma(dat, 28)

 This works fine.  What I don't have is the code for a moving variance.

 filter in the function above is included in the stats package and conducts a
 linear filtering on a Time Series.

 Is there comparable code some place in R for a moving variance?


See rollmean and rollapply in the zoo package and runmean and runsd in
the caTools package.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

[[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] how to handle no lines in input with pipe()

2011-04-04 Thread Andrew Yee
This has to do with using pipe() and grep and read.csv()

I have a .csv file that I grep using pipe() and read.csv() as follows:

read.csv(pipe('grep foo bar.csv'))

However, is there a way to have this command run when for example,
there is no foo text in the bar.csv file?  I get an error message
(appropriately):

Error in read.table(file = file, header = header, sep = sep, quote = quote,  :
  no lines available in input

Is there a way to inspect the output of pipe before passing it on to
read.csv()?

Thanks,
Andrew

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