Re: [R] how can I plot the histogram like this using R?

2010-04-14 Thread Tal Galili
Aer you asking how to have more bars on the axis ?
That can be controlled using:
barplot(stuff,  br = 50) # br can be other numbers according to needs.
The vertical line can be done with:
abline(v=20) # You may change 20

There are other elements to the plot to reproduce, but is this enough for
your needs?

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 Wed, Apr 14, 2010 at 7:45 AM, bbslover dlu...@yeah.net wrote:


 I want to get the plot like this,

 http://n4.nabble.com/file/n1839303/%25E9%25A2%2591%25E7%258E%2587%25E5%2588%2586%25E5%25B8%2583%25E5%259B%25BE%25E6%25A0%2587%25E5%2587%2586.jpg
 %E9%A2%91%E7%8E%87%E5%88%86%E5%B8%83%E5%9B%BE%E6%A0%87%E5%87%86.jpg

 not this, http://n4.nabble.com/file/n1839303/R.jpg R.jpg

 and  the data here, thank you!   http://n4.nabble.com/file/n1839303/y1.txt
 y1.txt

 can R deal with this problem?  how can I do?
 --
 View this message in context:
 http://n4.nabble.com/how-can-I-plot-the-histogram-like-this-using-R-tp1839303p1839303.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] maptools-export owin as shapefile, error message

2010-04-14 Thread Tom Elliott
Hello R users,

I am trying to export an object of class owin from the Spatstat package to
an ESRI shapefile using the package Maptools. I am using the function
writePolyShape;  pointsp is an object of class ppp, ripras is a
function in SpatStat that creates a polygon around points. I have tried with
several different owin objects and each time I get the same error, as
follows.

 x=ripras(pointsp,shape=convex)
 xpoly=as(x,SpatialPolygons)
 xpolyframe=as(xpoly,SpatialPolygonsDataFrame)
 class(xpolyframe)
[1] SpatialPolygonsDataFrame
attr(,package)
[1] sp
 writePolyShape(xpolyframe,pgon)
Error in write.polylistShape(pls, df, file = fn, factor2char = factor2char,
:
  different number of rows in polylist and data frame


thanks for any help,

Tom Elliott, Central Washington University


[[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] WinBUGS Question

2010-04-14 Thread Uwe Ligges
Or even easier: Use BRugs which has a considerably cleaner interface and 
does not need to restart the WinBUGS executable again and again.


Uwe Ligges




On 13.04.2010 22:45, Yihui Xie wrote:

If you are using R2WinBUGS, I guess you may put them in a loop like:

# models
...
data_i[j]~dnorm(...)
...
# save them in a sequence of files with names like 'model_i.bug'
# write.model() might help?

# then call bugs()
for(i in names.of.your.100.datasets){
   bugs(data=i,...,model.file='model_i.bug',...)
}

The above code might need paste() here and there, e.g. paste('data_',
i, sep='').

I don't know if WinBUGS itself supports such a loop.

Regards,
Yihui
--
Yihui Xiexieyi...@gmail.com
Phone: 515-294-6609 Web: http://yihui.name
Department of Statistics, Iowa State University
3211 Snedecor Hall, Ames, IA



On Tue, Apr 13, 2010 at 1:48 PM, Anamika Chaudhuricanam...@gmail.com  wrote:

Hi:

Is there a way we can set up WINBUGS to run 100 simulated datasets on the
same model and output results? Or do we have to call in each dataset at a
time and repeat the process 100 times manually?

Thanks
Anamika

[[alternative HTML version deleted]]

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



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


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


[R] Problem trying to plot Vennerable object

2010-04-14 Thread Chris Cole

Hi,

I'm new to the list so apologies if this has been asked before. I 
couldn't find any refs in google.


I recently installed the Vennerable library from Rforge, this required 
an upgrade of R to 2.10.0 by the 'pylr' dependency.


However, a very simple command fails:
Vcomb - Venn(SetNames= c(EOCT, EOCM), Weight=c(0, 11841, 24084, 24660))
plot(Vcomb)

with this error:
Error in do.call(c, lapply(.faceNames(new1), .faceEdgeNames, drawing = 
new1)) :

  'what' must be a character string or a function

What's frustrating is that a colleague with different versions of R 
(2.8.x) and some of the libraries gets the above function to work fine.


I have no idea how to debug this error. Any help would be much appreciated.

Chris

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


[R] Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in c(0

2010-04-14 Thread Simon Kiss

Dear colleagues,
in the help archive there was a previous person who encountered a  
problem with the recode command in the car library. I'm not sure if  
that was solved, there was no posting to that effect, but I'm having  
the same problem.


I'm trying to recode a numeric variable with values from 0-100 into a  
binary variable with values (0,1).


The following command:

recode(green_2004_2$french, c(50:100)=0; c(0:49.99)=1)

gets the following error message

Error in parse(text = range[[1]][1]) : unexpected end of input in  c(0

I tried it with a second numerical variable in the same data set, but  
get precisely the same error at precisely the same location in the  
command, i.e. the second colon.
As far as I can tell I have the most up-to-date version of car  
installed.

Any suggestions?
Yours, Simon Kiss

*
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html

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


Re: [R] creating a new corClass for lme()

2010-04-14 Thread Viechtbauer Wolfgang (STAT)
No idea if this helps, but if the optimizer (nlminb) is giving you problems, 
you could try switching to another optimizer (nlm) with:

control=list(opt=nlm)

Best,

--
Wolfgang Viechtbauerhttp://www.wvbauer.com/
Department of Methodology and StatisticsTel: +31 (43) 388-2277
School for Public Health and Primary Care   Office Location:
Maastricht University, P.O. Box 616 Room B2.01 (second floor)
6200 MD Maastricht, The Netherlands Debyeplein 1 (Randwyck)


Original Message
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Michael Steven
Rooney Sent: Wednesday, April 14, 2010 07:07 To: r-help@r-project.org
Subject: [R] creating a new corClass for lme()

 Hi,

 I have been using the function lme() of the package nlme to model
 grouped data that is auto-correlated in time and in space (the data
 was collected on different days via a moving monitor). I am aware
 that I can use the correlation classes corCAR1 and corExp (among
 other options) to model the temporal and spatial components of the
 auto-correlation. However, as far as I can tell, I can only model
 using one correlation class or the other. I would like my model to
 account for both temporal and spatial autocorrelation simultaneously.

 The ?corClasses help page provides some advice on how to create your
 own correlation class. I was able to create a new class that I called
 corSPT:  I add the spatial and temporal autocorrelation matrices to
 produce the corSPT correlation matrix. The code for this is pasted
 below:

 ## BEGIN ###

 # Create some data

 N - 100
 x - round(sin(rep(1:23/2,length.out=N)),digits=2)+1:N*2/N
 y - round(cos(rep(1:23/2,length.out=N)),digits=2)+1:N*2/N
 g - rep(1:5,each=N/5)
 a - round(runif(N,0,10))
 t - 1:N
 r - runif(N,0,5)
 e - 5*sin(4*x) +
  5*cos(4*y) +
  5*sin(t) +
  2*g +
  a +
  r
 e - round(e)

 df - data.frame(x,y,g,a,t,r,e)

 library(nlme)

 # Define constructor function and methods

 corSPT - function(a,b) {
   object - list(time=a,space=b)
   class(object)  -  c(corSPT,corStruct)
   return(object)
 }

 coef.corSPT - function(object,...) {
   c(coef(object[[time]],...)[1],coef(object[[space]],...))
 }

 coef-.corSPT - function(object,...,value) {
   coef(object[[time]]) - value[1]
   coef(object[[space]]) - value[2:3]
   class(object)  -  c(corSPT,corStruct)
   return(object)
 }

 Initialize.corSPT - function(object,...) {
   object -
 list(time=Initialize(object[[time]],...),space=Initialize(object[[space]],...))
   class(object)  -  c(corSPT,corStruct)
   return(object)
 }

 corMatrix.corSPT - function(object,covariate = NULL, ...) {
   a -
 corMatrix(object[[time]],covariate=getCovariate(object[[time]]),...)
   b -
 corMatrix(object[[space]],covariate=getCovariate(object[[space]]),...)
   lapply(seq(length(a)),function(n) pmax(-1,pmin(1,a[[n]]+b[[n]]))) }

 formula.corSPT - function(object,...) {
   a - as.character(formula(object[[time]]))
   b - as.character(formula(object[[space]]))
   a - strsplit(a[2],split=|,fixed=TRUE)[[1]]
   b - strsplit(b[2],split=|,fixed=TRUE)[[1]]
   as.formula(paste(~,a[1],+,b[1],|,a[2]))
 }

 Dim.corSPT - function(object,...) {
   Dim(object[[time]],...)
 }

   END  ###

 When I run this model on:

 mymodel - lme(fixed = e ~ a,random= ~ 1 |
 g,data=df,correlation=corSPT(corCAR1(.2,form = ~ t |
 g),corExp(c(1,.5),form= ~ x + y | g,
 nugget=TRUE)),control=list(msVerbose=TRUE))

 I get sensible results. However if I change the way the temporal data
 is
 modeled:

 mymodel - lme(fixed = e ~ a,random= ~ 1 |
 g,data=df,correlation=corSPT(corExp(.2,form = ~ t |
 g),corExp(c(1,.5),form= ~ x + y | g,
 nugget=TRUE)),control=list(msVerbose=TRUE))

 I get a C runtime error. I have been trying to track this down using
 browser() and debug(), but all I have been able to tell is that the
 problem arises during

 .Call(R_port_nlminb,obj,grad,hess,rho,low,upp,d=rep(as.double(scale),length.out=length(par)),iv,v)

 in the nlminb() function.

 Please let me know if you know what might be going on. I am using R
 version 2.7.2 on Windows XP.

 Thanks,
 Mike

   [[alternative HTML version deleted]]

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

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


[R] GAMM : how to use a smoother for some levels of a variable, and a linear effect for other levels?

2010-04-14 Thread JANSEN, Ivy
Hi, 
 
I was reading the book on Mixed Effects Models and Extensions in
Ecology with R by Zuur et al. 
In Section 6.2, an example is discussed where a gamm-model is fitted,
with a smoother for time, which differs for each value of ID (4
different bird species). In earlier versions of R, the following code
was used
 
BM2-gamm(Birds~Rain+ID+
   s(Time,by=as.numeric(ID==Stilt.Oahu))+
   s(Time,by=as.numeric(ID==Stilt.Maui))+
   s(Time,by=as.numeric(ID==Coot.Oahu))+
   s(Time,by=as.numeric(ID==Coot.Maui)),
 correlation=corAR1(form=~Time |ID ),
 weights=varIdent(form=~1|ID))
 
However, in the current version of R, this does not work anymore, and
should be changed into 
 
BM2-gamm(Birds~Rain+ID+
   s(Time,by=ID),
 correlation=corAR1(form=~Time |ID ),
 weights=varIdent(form=~1|ID))
 
It turns out that 2 of the 4 smoothers have estimated degrees of freedom
of 1, so a linear effect would be sufficient. 
Now my question is how I need to change the code in order to have a time
smoother for ID=Coot.Oahu and ID=Coot.Maui, and a linear time effect for
ID=Stilt.Oahu and ID=Stilt.Maui. With the old R-code, this seems
trivial, but I don't have any idea how to do it in the newest R-version
(interactions with a dummy variable do not work in gamm).
 
Thanks,
Ivy

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] sum specific rows in a data frame

2010-04-14 Thread arnaud Gaboury
I have a data frame called pose:


  DESCRIPTION QUANITY CLOSING.PRICE
1   WHEAT May/101467.75
2   WHEAT May/102467.75
3   WHEAT May/101467.75
4   WHEAT May/101467.75
5 COTTON NO.2 May/101 78.13
6 COTTON NO.2 May/103 78.13
7 COTTON NO.2 May/101 78.13

I would like to sum the quantity for each category (i.e WHEAT and
COTTON),but I have no idea how to write it in a simple manner. The number or
rows will change every day.
TY for any help.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Bayesian bootstrap with boot

2010-04-14 Thread hhafner
Hi,

I wonder about whether it is possible to perform a Bayesian bootstrap 
using the boot package. The documentation isn't very detailed and I don't 
have the associated book. So I would be glad, if someone could help me. If 
it isn't possible: Which package / which function can I use instead? I'm 
rather new to R, so I don't have much knowledge about writing programs and 
it would be nice, if there exists an easy to use package. Thanks!

Hans-Peter Hafner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] sum specific rows in a data frame

2010-04-14 Thread Mohamed Lajnef

Hi Arnaud,

Try  aggregate function

regards
M

arnaud Gaboury a écrit :

I have a data frame called pose:


  DESCRIPTION QUANITY CLOSING.PRICE
1   WHEAT May/101467.75
2   WHEAT May/102467.75
3   WHEAT May/101467.75
4   WHEAT May/101467.75
5 COTTON NO.2 May/101 78.13
6 COTTON NO.2 May/103 78.13
7 COTTON NO.2 May/101 78.13

I would like to sum the quantity for each category (i.e WHEAT and
COTTON),but I have no idea how to write it in a simple manner. The number or
rows will change every day.
TY for any help.

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

  



--


Mohamed Lajnef,IE 
INSERM U955 eq 15

Pôle de Psychiatrie
Hôpital CHENEVIER
40, rue Mesly
94010 CRETEIL Cedex FRANCE
mohamed.laj...@inserm.fr
tel : 01 49 81 31 31 (poste 18470)
Sec : 01 49 81 32 90
fax : 01 49 81 30 99 


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in c(0

2010-04-14 Thread Peter Ehlers

Get rid of the unnecessary c(...) construction:

 recode(green_2004_2$french, 50:100=0; 0:49.99=1)

 -Peter Ehlers

On 2010-04-14 1:56, Simon Kiss wrote:

Dear colleagues,
in the help archive there was a previous person who encountered a
problem with the recode command in the car library. I'm not sure if
that was solved, there was no posting to that effect, but I'm having the
same problem.

I'm trying to recode a numeric variable with values from 0-100 into a
binary variable with values (0,1).

The following command:

recode(green_2004_2$french, c(50:100)=0; c(0:49.99)=1)

gets the following error message

Error in parse(text = range[[1]][1]) : unexpected end of input in  c(0

I tried it with a second numerical variable in the same data set, but
get precisely the same error at precisely the same location in the
command, i.e. the second colon.
As far as I can tell I have the most up-to-date version of car installed.
Any suggestions?
Yours, Simon Kiss

*
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html

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




--
Peter Ehlers
University of Calgary

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problem trying to plot Vennerable object

2010-04-14 Thread Peter Ehlers

On 2010-04-14 1:54, Chris Cole wrote:

Hi,

I'm new to the list so apologies if this has been asked before. I
couldn't find any refs in google.

I recently installed the Vennerable library from Rforge, this required
an upgrade of R to 2.10.0 by the 'pylr' dependency.

However, a very simple command fails:
Vcomb - Venn(SetNames= c(EOCT, EOCM), Weight=c(0, 11841, 24084,
24660))
plot(Vcomb)

with this error:
Error in do.call(c, lapply(.faceNames(new1), .faceEdgeNames, drawing =
new1)) :
'what' must be a character string or a function


I don't know the Vennerable *package*, but does this tell you
anything:

 do.call(c, list('a', 'b'))
[1] a b

 c - 3
 do.call(c, list('a', 'b'))

Then try
 rm(c)

and run your Venn code again.

 -Peter Ehlers



What's frustrating is that a colleague with different versions of R
(2.8.x) and some of the libraries gets the above function to work fine.

I have no idea how to debug this error. Any help would be much appreciated.

Chris

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




--
Peter Ehlers
University of Calgary

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] MiscPsycho - incorrect levenshtein distance?

2010-04-14 Thread Ben Meijering
For some strings I get a wrong (MiscPsycho) Levenstein distance:

 stringMatch(abc, ab, normalize=NO)
[1] 1

 stringMatch(abc, bc, normalize=NO)
[1] 2

I think the lines

d - matrix(0, nrow = n + 1, ncol = m + 1)
d[, 1] - 1:(n + 1)
d[1, ] - 1:(m + 1)
d[1, 1] - 0

should be changed to

d - matrix(0, nrow = n + 1, ncol = m + 1)
d[, 1] - 0:n
d[1, ] - 0:m

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 package documentation

2010-04-14 Thread Sébastien Bihorel
Dear R users,

I am currently writing the documentation for my first package. I have
created a short user manual using sweave/pdflatex which is distinct from the
manual/summary-of-package-functions created by R CMD CHECK. I was wondering
how could I seamlessly combine both documents.

Thanks for your help

Sebastien

[[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] Error: could not find function tsts tradesys package

2010-04-14 Thread Sarah Goslee
Did you load tradesys after you installed it?
library(tradesys)

That seems to be a common beginner problem.

Sarah

On Tue, Apr 13, 2010 at 9:56 PM, dbonneau daronnebonn...@gmail.com wrote:


 Hi, I am pretty new to R and would like to follow the code in the paper
 below, tradesys package. but I am stuck at the 2nd page where x-tsts(spx)
 is written. Could anyopne help me why I am getting an Error :could not find
 function tsts . I guess I need function call tsts. where can I find
 that function ? I installed tradesys, zoo, RUnit packages but I don't know
 why it gives me error. Thanks

 http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/inst/doc/tradesys.pdf?rev=19root=tradesys
 --
 View this message in context: 
 http://n4.nabble.com/Error-could-not-find-function-tsts-tradesys-package-tp1839233p1839233.html
 Sent from the R help mailing list archive at Nabble.com.

 _

-- 
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] R package documentation

2010-04-14 Thread Tobias Verbeke

Hi Sébastien,

Sébastien Bihorel wrote:


I am currently writing the documentation for my first package. I have
created a short user manual using sweave/pdflatex which is distinct from the
manual/summary-of-package-functions created by R CMD CHECK. I was wondering
how could I seamlessly combine both documents.


It is common to have
- technical documentation in your .Rd files (in the man/ directory
of your package)
- functional documentation as a so-called vignette (Sweave file
documenting concrete use of your package) in the
inst/doc directory of your package.

http://cran.r-project.org/doc/manuals/R-exts.html#Writing-package-vignettes

Combining both documents into one file is not common.

I hope this helps,
Tobias

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


Re: [R] R package documentation

2010-04-14 Thread Sébastien Bihorel
Hi Tobias,

The .R files that I have created for all my functions are somehow used to
generate a package manual pdf when I used R CMD CHECK. This is what I'd like
to add in my vignette. It might be uncommon, but I saw this was done for
several package documentations (e.g. PBS collections) and I kind of like
this combination.

Sebastien

On Wed, Apr 14, 2010 at 6:52 AM, Tobias Verbeke 
tobias.verb...@openanalytics.eu wrote:

 Hi Sébastien,


 Sébastien Bihorel wrote:

  I am currently writing the documentation for my first package. I have
 created a short user manual using sweave/pdflatex which is distinct from
 the
 manual/summary-of-package-functions created by R CMD CHECK. I was
 wondering
 how could I seamlessly combine both documents.


 It is common to have
 - technical documentation in your .Rd files (in the man/ directory
of your package)
 - functional documentation as a so-called vignette (Sweave file
documenting concrete use of your package) in the
inst/doc directory of your package.

 http://cran.r-project.org/doc/manuals/R-exts.html#Writing-package-vignettes

 Combining both documents into one file is not common.

 I hope this helps,
 Tobias



[[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] how can I plot the histogram like this using R?

2010-04-14 Thread bbslover

thanks for your help. I can have a try.
-- 
View this message in context: 
http://n4.nabble.com/how-can-I-plot-the-histogram-like-this-using-R-tp1839303p1839534.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] Problems getting symbols() to show table data

2010-04-14 Thread Guy Green

Hello,

I am trying to create a graphic to help me visualise data.  A (very
simplified) sample of the data is 
http://n4.nabble.com/file/n1839676/circle_data.txt circle_data.txt :

  Aug-07 Nov-07  Feb-08
data1 1  1.5   -1
data2  1  1.2 1.6
data3  1.31.41.8
data4 1.3  -1.21

What I am trying to achieve is:

 * Circles representing each item of data,
 * The circle size represents the number,
 * The data is arranged in rows and columns, similar to the table layout
(i.e. dates along the top or bottom),
 * Positive numbers are blue circles, negative red circles.

I have used info from lots of previous posts on symbols() to get me some of
the way, but I am still far off getting it to actually work, with the result
that I think I may be heading in completely the wrong direction.  I can
create a grid of circles with the right number of dimensions:

Read_data=read.table(C:/files/circle_data.txt, head = T)
number_rows = nrow(Read_data)
number_cols = ncol(Read_data)
xaxis = rep(seq(1,ncol(Read_data),1),nrow(Read_data))
yaxis = rep(seq(1,nrow(Read_data),1),ncol(Read_data))
zvalues = rep(0.1,(number_rows*number_cols))#This is just a dummy vector
symbols(xaxis, yaxis, circles = zvalues, inches = FALSE, xlab=, ylab=)
axis(2, at=c(1:number_rows), rownames(Read_data), las = 1)
axis(1, at=c(1:number_cols), colnames(Read_data))

BUT... this only uses dummy values - I can't think how to get the table into
a form the symbols() function can use.  I tried as.vector() unsuccessfully. 
Also, this code simply overwrites the x and y-axis labels, which looks
terrible: again, I can't think how to get this right from the start.

On getting positive values to be blue and negative red, I had assumed I
could just split the data into two and plot separately:

Data_positive = replace(Read_data, Read_data0,0)
Data_negative = -replace(Read_data, Read_data0,0)

However, this quick trial below gives little dots for zero values, so it is
not a perfect result:

zvalues_pos = rep(c(0.1,0.2,0), 4)  #Dummy vector for positives
zvalues_neg = rep(c(0,0,0.3), 4)#Dummy vector for negatives
symbols(xaxis, yaxis, circles = zvalues_pos, inches = FALSE, xlab=,
ylab=, bg=blue)
symbols(xaxis, yaxis, circles = zvalues_neg, inches = FALSE, xlab=,
ylab=, bg=red, add=TRUE)

[Incidentally, I have tried to work through this example (
http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=152
http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=152 ) but I am
out of my depth in making sense of the code.]

Any help would be gratefully received.  Thanks,

Guy
-- 
View this message in context: 
http://n4.nabble.com/Problems-getting-symbols-to-show-table-data-tp1839676p1839676.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 can I plot the histogram like this using R?

2010-04-14 Thread bbslover

thank you, I will try this function barplot.
-- 
View this message in context: 
http://n4.nabble.com/how-can-I-plot-the-histogram-like-this-using-R-tp1839303p1839541.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] Running cumulative sums in matrices

2010-04-14 Thread Eleni Rapsomaniki

Dear R-helpers,

I have a huge data-set so need to avoid for loops as much as possible. Can 
someone think how I can compute the result in the following example (that uses 
a for-loop) using some version of apply instead (or any other similarly 
super-efficient function)? 

example:
#Suppose a matrix:
m1=cbind(1:5,1:5,1:5)

#The aim is to create a new matrix with every column containing the cumulative 
sum of all previous columns.
m2=m1
for(i in 2:ncol(m1)){
m2[,i]=apply(m1[,1:i],1,sum)
}
m2

Many thanks in advance

Eleni Rapsomaniki

Research Associate
Strangeways Research Laboratory
Department of Public Health and Primary Care
University of Cambridge
 

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


Re: [R] R package documentation

2010-04-14 Thread Tobias Verbeke

Hi Sébastien,

Sébastien Bihorel wrote:

The .R files that I have created for all my functions are somehow used 
to generate a package manual pdf when I used R CMD CHECK. This is what 
I'd like to add in my vignette. It might be uncommon, but I saw this was 
done for several package documentations (e.g. PBS collections) and I 
kind of like this combination.


I now understand what you mean. The PBS documentation you refer to
seems a mere (manual) concatenation of a (non-LaTeX based) pdf
document and the reference manual pdf which is not generated from
a Sweave file. Such manipulations can be done using e.g. the pdfjam
toolbox by David Firth.

 http://go.warwick.ac.uk/pdfjam

Best,
Tobias

On Wed, Apr 14, 2010 at 6:52 AM, Tobias Verbeke 
tobias.verb...@openanalytics.eu 
mailto:tobias.verb...@openanalytics.eu wrote:


Hi Sébastien,


Sébastien Bihorel wrote:

I am currently writing the documentation for my first package. I
have
created a short user manual using sweave/pdflatex which is
distinct from the
manual/summary-of-package-functions created by R CMD CHECK. I
was wondering
how could I seamlessly combine both documents.


It is common to have
- technical documentation in your .Rd files (in the man/ directory
   of your package)
- functional documentation as a so-called vignette (Sweave file
   documenting concrete use of your package) in the
   inst/doc directory of your package.

http://cran.r-project.org/doc/manuals/R-exts.html#Writing-package-vignettes

Combining both documents into one file is not common.

I hope this helps,
Tobias




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


Re: [R] Running cumulative sums in matrices

2010-04-14 Thread Dennis Murphy
Hi:

Is this what you want?

 m1=cbind(1:5,1:5,1:5)
 apply(m1, 1, cumsum)
 [,1] [,2] [,3] [,4] [,5]
[1,]12345
[2,]2468   10
[3,]369   12   15


HTH,
Dennis

On Wed, Apr 14, 2010 at 5:18 AM, Eleni Rapsomaniki
er...@medschl.cam.ac.ukwrote:


 Dear R-helpers,

 I have a huge data-set so need to avoid for loops as much as possible. Can
 someone think how I can compute the result in the following example (that
 uses a for-loop) using some version of apply instead (or any other similarly
 super-efficient function)?

 example:
 #Suppose a matrix:
 m1=cbind(1:5,1:5,1:5)

 #The aim is to create a new matrix with every column containing the
 cumulative sum of all previous columns.
 m2=m1
 for(i in 2:ncol(m1)){
m2[,i]=apply(m1[,1:i],1,sum)
 }
 m2

 Many thanks in advance

 Eleni Rapsomaniki

 Research Associate
 Strangeways Research Laboratory
 Department of Public Health and Primary Care
 University of Cambridge


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in c(0

2010-04-14 Thread John Fox
Dear Simon,

The problem is that the recode specification is incorrect: In recode(),
colons mean ranges, and shouldn't appear within c(), which is used to list
values. See ?recode, and the following example:

 (green_2004_2 - data.frame(french=runif(10, 0, 100)))
  french
1  42.693517
2  18.063822
3  21.046906
4  17.045596
5   9.308359
6  30.018840
7  53.598261
8  17.739567
9  65.836818
10 37.727236
 recode(green_2004_2$french, 50:100=0; 0:49.99=1)
 [1] 1 1 1 1 1 1 0 1 0 1

BTW, 50:100=0; 0:50=1 will produce the same result -- again see ?recode.

Finally, it's generally a good idea to send a small reproducible example
with a question like this. What if there were really a data-dependent bug in
recode()?

I hope this helps,
 John


John Fox
Senator William McMaster 
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
 Behalf Of Simon Kiss
 Sent: April-14-10 3:56 AM
 To: r-help@r-project.org
 Subject: [R] Problem with recode -Error in parse(text = range[[1]][1]) :
 unexpected end of input in  c(0
 
 Dear colleagues,
 in the help archive there was a previous person who encountered a
 problem with the recode command in the car library. I'm not sure if
 that was solved, there was no posting to that effect, but I'm having
 the same problem.
 
 I'm trying to recode a numeric variable with values from 0-100 into a
 binary variable with values (0,1).
 
 The following command:
 
 recode(green_2004_2$french, c(50:100)=0; c(0:49.99)=1)
 
 gets the following error message
 
 Error in parse(text = range[[1]][1]) : unexpected end of input in  c(0
 
 I tried it with a second numerical variable in the same data set, but
 get precisely the same error at precisely the same location in the
 command, i.e. the second colon.
 As far as I can tell I have the most up-to-date version of car
 installed.
 Any suggestions?
 Yours, Simon Kiss
 
 *
 Simon J. Kiss, PhD
 SSHRC and DAAD Post-Doctoral Fellow
 John F. Kennedy Institute of North America Studies
 Free University of Berlin
 Lansstraße 7-9
 14195 Berlin, Germany
 Cell: +49 (0)1525-300-2812,
 Web: http://www.jfki.fu-berlin.de/index.html
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Running cumulative sums in matrices

2010-04-14 Thread ONKELINX, Thierry
?cumsum can help you

m1 - cbind(1:5,1:5,1:5)
m2 - m1
 for(i in 2:ncol(m1)){
m2[,i]=apply(m1[,1:i],1,sum)
}
m3 - t(apply(m1, 1, cumsum))
all.equal(m2, m3)

HTH,

Thierry

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie  Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics  Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey
  

 -Oorspronkelijk bericht-
 Van: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] Namens Eleni Rapsomaniki
 Verzonden: woensdag 14 april 2010 14:18
 Aan: r-help@r-project.org
 Onderwerp: [R] Running cumulative sums in matrices
 
 
 Dear R-helpers,
 
 I have a huge data-set so need to avoid for loops as much as 
 possible. Can someone think how I can compute the result in 
 the following example (that uses a for-loop) using some 
 version of apply instead (or any other similarly 
 super-efficient function)? 
 
 example:
 #Suppose a matrix:
 m1=cbind(1:5,1:5,1:5)
 
 #The aim is to create a new matrix with every column 
 containing the cumulative sum of all previous columns.
 m2=m1
 for(i in 2:ncol(m1)){
 m2[,i]=apply(m1[,1:i],1,sum)
 }
 m2
 
 Many thanks in advance
 
 Eleni Rapsomaniki
 
 Research Associate
 Strangeways Research Laboratory
 Department of Public Health and Primary Care University of Cambridge
  
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 can I plot the histogram like this using R?

2010-04-14 Thread Tal Galili
Hi,

My bid - do all that I wrote with
hist
instead of barplot

Best,
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 Wed, Apr 14, 2010 at 12:46 PM, bbslover dlu...@yeah.net wrote:


 thank you, I will try this function barplot.
 --
 View this message in context:
 http://n4.nabble.com/how-can-I-plot-the-histogram-like-this-using-R-tp1839303p1839541.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] can not execute two functions - env() and profile()

2010-04-14 Thread pnouvellet

Hi,
I had the same problem on windows with same R version...
With the package lme4a (from R-forge), I can use the env() function.

However, I am still unable to use the profile function (in the aim of
establishing confidence interval for the std devaition of random effect). 

any help will be greatly appreciated!!

pierre
-- 
View this message in context: 
http://n4.nabble.com/can-not-execute-two-functions-env-and-profile-tp1836709p1839737.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] Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in c(0

2010-04-14 Thread David Winsemius


On Apr 14, 2010, at 2:56 AM, Simon Kiss wrote:


Dear colleagues,
in the help archive there was a previous person who encountered a  
problem with the recode command in the car library. I'm not sure  
if that was solved, there was no posting to that effect, but I'm  
having the same problem.


I'm trying to recode a numeric variable with values from 0-100 into  
a binary variable with values (0,1).


The following command:

recode(green_2004_2$french, c(50:100)=0; c(0:49.99)=1)


Look at the last example in the recode help page:
recode(x, 1:2='A'; 3='B')
## [1] A A B A A B A A B
It appears to me that the c() function around your sequences may be  
part of the problem and I further wondered whether 0:49.99 can  
succeed. Generally the : operator expects integer arguments, but the  
help page is not clear in this area and it appears that recode has a  
different interpretation.

 require(car)
 recode(x, -Inf:0=-1; 0.01:Inf=1) # succeeds
--
David



gets the following error message

Error in parse(text = range[[1]][1]) : unexpected end of input in   
c(0


I tried it with a second numerical variable in the same data set,  
but get precisely the same error at precisely the same location in  
the command, i.e. the second colon.
As far as I can tell I have the most up-to-date version of car  
installed.

Any suggestions?
Yours, Simon Kiss

*
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html

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


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


Re: [R] Running cumulative sums in matrices

2010-04-14 Thread Dimitris Rizopoulos

you can even use a simple for-loop, e.g.,

m1 - cbind(1:5,1:5,1:5)

out - m1
for(i in 1:nrow(out))
out[i, ] - cumsum(out[i, ])

which seems to be faster than apply(m1, 1, cumsum), i.e.,

m1 - m1[rep(1:5, each = 1e04), ]

library(rbenchmark)
benchmark(
apply = apply(m1, 1, cumsum),
for = {out - m1; for(i in 1:nrow(out)) out[i, ] - cumsum(out[i, 
])},

replications = 50, order = relative
)


I hope it helps.

Best,
Dimitris


On 4/14/2010 2:18 PM, Eleni Rapsomaniki wrote:


Dear R-helpers,

I have a huge data-set so need to avoid for loops as much as possible. Can 
someone think how I can compute the result in the following example (that uses 
a for-loop) using some version of apply instead (or any other similarly 
super-efficient function)?

example:
#Suppose a matrix:
m1=cbind(1:5,1:5,1:5)

#The aim is to create a new matrix with every column containing the cumulative 
sum of all previous columns.
m2=m1
for(i in 2:ncol(m1)){
 m2[,i]=apply(m1[,1:i],1,sum)
}
m2

Many thanks in advance

Eleni Rapsomaniki

Research Associate
Strangeways Research Laboratory
Department of Public Health and Primary Care
University of Cambridge


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



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problems getting symbols() to show table data

2010-04-14 Thread Gabor Grothendieck
Try this:

library(gplots)
m - matrix(c(1, 2, -3, -6, 5, 4), 3)
tm - t(m)
balloonplot(row(tm), col(tm), abs(tm),
   dotcolor = c(blue, red)[(c(tm)  0) + 1],
   show.margins = FALSE, cum.margins = FALSE,
   xlab = Cols, ylab = Rows, main = m)



On Wed, Apr 14, 2010 at 7:58 AM, Guy Green guygr...@netvigator.com wrote:

 Hello,

 I am trying to create a graphic to help me visualise data.  A (very
 simplified) sample of the data is
 http://n4.nabble.com/file/n1839676/circle_data.txt circle_data.txt :

              Aug-07         Nov-07      Feb-08
 data1             1              1.5           -1
 data2          1              1.2             1.6
 data3          1.3            1.4            1.8
 data4             1.3          -1.2            1

 What I am trying to achieve is:

  * Circles representing each item of data,
  * The circle size represents the number,
  * The data is arranged in rows and columns, similar to the table layout
 (i.e. dates along the top or bottom),
  * Positive numbers are blue circles, negative red circles.

 I have used info from lots of previous posts on symbols() to get me some of
 the way, but I am still far off getting it to actually work, with the result
 that I think I may be heading in completely the wrong direction.  I can
 create a grid of circles with the right number of dimensions:

 Read_data=read.table(C:/files/circle_data.txt, head = T)
 number_rows = nrow(Read_data)
 number_cols = ncol(Read_data)
 xaxis = rep(seq(1,ncol(Read_data),1),nrow(Read_data))
 yaxis = rep(seq(1,nrow(Read_data),1),ncol(Read_data))
 zvalues = rep(0.1,(number_rows*number_cols))    #This is just a dummy vector
 symbols(xaxis, yaxis, circles = zvalues, inches = FALSE, xlab=, ylab=)
 axis(2, at=c(1:number_rows), rownames(Read_data), las = 1)
 axis(1, at=c(1:number_cols), colnames(Read_data))

 BUT... this only uses dummy values - I can't think how to get the table into
 a form the symbols() function can use.  I tried as.vector() unsuccessfully.
 Also, this code simply overwrites the x and y-axis labels, which looks
 terrible: again, I can't think how to get this right from the start.

 On getting positive values to be blue and negative red, I had assumed I
 could just split the data into two and plot separately:

 Data_positive = replace(Read_data, Read_data0,0)
 Data_negative = -replace(Read_data, Read_data0,0)

 However, this quick trial below gives little dots for zero values, so it is
 not a perfect result:

 zvalues_pos = rep(c(0.1,0.2,0), 4)      #Dummy vector for positives
 zvalues_neg = rep(c(0,0,0.3), 4)        #Dummy vector for negatives
 symbols(xaxis, yaxis, circles = zvalues_pos, inches = FALSE, xlab=,
 ylab=, bg=blue)
 symbols(xaxis, yaxis, circles = zvalues_neg, inches = FALSE, xlab=,
 ylab=, bg=red, add=TRUE)

 [Incidentally, I have tried to work through this example (
 http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=152
 http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=152 ) but I am
 out of my depth in making sense of the code.]

 Any help would be gratefully received.  Thanks,

 Guy
 --
 View this message in context: 
 http://n4.nabble.com/Problems-getting-symbols-to-show-table-data-tp1839676p1839676.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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] MiscPsycho - incorrect levenshtein distance?

2010-04-14 Thread David Winsemius

Generally bug reports should go the the package emaintainer.

On Apr 14, 2010, at 5:08 AM, Ben Meijering wrote:


For some strings I get a wrong (MiscPsycho) Levenstein distance:


I see you spelled it correctly in your subject line.


stringMatch(abc, ab, normalize=NO)

[1] 1


stringMatch(abc, bc, normalize=NO)

[1] 2

I think the lines

d - matrix(0, nrow = n + 1, ncol = m + 1)
d[, 1] - 1:(n + 1)
d[1, ] - 1:(m + 1)
d[1, 1] - 0

should be changed to

d - matrix(0, nrow = n + 1, ncol = m + 1)
d[, 1] - 0:n
d[1, ] - 0:m

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


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


Re: [R] R package documentation

2010-04-14 Thread Sébastien Bihorel
Thanks Tobias,

If there is no automated way to combine both documents, I will stack them
manually... that will likely cause some problems with page numbering tough.

Sebastien

On Wed, Apr 14, 2010 at 8:18 AM, Tobias Verbeke 
tobias.verb...@openanalytics.eu wrote:

 Hi Sébastien,

 Sébastien Bihorel wrote:

  The .R files that I have created for all my functions are somehow used to
 generate a package manual pdf when I used R CMD CHECK. This is what I'd like
 to add in my vignette. It might be uncommon, but I saw this was done for
 several package documentations (e.g. PBS collections) and I kind of like
 this combination.


 I now understand what you mean. The PBS documentation you refer to
 seems a mere (manual) concatenation of a (non-LaTeX based) pdf
 document and the reference manual pdf which is not generated from
 a Sweave file. Such manipulations can be done using e.g. the pdfjam
 toolbox by David Firth.

  http://go.warwick.ac.uk/pdfjam

 Best,
 Tobias


  On Wed, Apr 14, 2010 at 6:52 AM, Tobias Verbeke 
 tobias.verb...@openanalytics.eu mailto:tobias.verb...@openanalytics.eu
 wrote:

Hi Sébastien,


Sébastien Bihorel wrote:

I am currently writing the documentation for my first package. I
have
created a short user manual using sweave/pdflatex which is
distinct from the
manual/summary-of-package-functions created by R CMD CHECK. I
was wondering
how could I seamlessly combine both documents.


It is common to have
- technical documentation in your .Rd files (in the man/ directory
   of your package)
- functional documentation as a so-called vignette (Sweave file
   documenting concrete use of your package) in the
   inst/doc directory of your package.


 http://cran.r-project.org/doc/manuals/R-exts.html#Writing-package-vignettes

Combining both documents into one file is not common.

I hope this helps,
Tobias





[[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] Running cumulative sums in matrices

2010-04-14 Thread Eleni Rapsomaniki
That's really interesting... I have always assumed that for-loops take
longer than apply. Perhaps it depends on the application. I'll try both
in my code and see. 

Thank you!
Eleni Rapsomaniki
 
Research Associate
Tel: +44 (0) 1223 740273
Strangeways Research Laboratory
Department of Public Health and Primary Care
University of Cambridge
 

-Original Message-
From: Dimitris Rizopoulos [mailto:d.rizopou...@erasmusmc.nl] 
Sent: 14 April 2010 13:47
To: Eleni Rapsomaniki
Cc: r-help@r-project.org
Subject: Re: [R] Running cumulative sums in matrices

you can even use a simple for-loop, e.g.,

m1 - cbind(1:5,1:5,1:5)

out - m1
for(i in 1:nrow(out))
 out[i, ] - cumsum(out[i, ])

which seems to be faster than apply(m1, 1, cumsum), i.e.,

m1 - m1[rep(1:5, each = 1e04), ]

library(rbenchmark)
benchmark(
 apply = apply(m1, 1, cumsum),
 for = {out - m1; for(i in 1:nrow(out)) out[i, ] - cumsum(out[i,

])},
 replications = 50, order = relative
)


I hope it helps.

Best,
Dimitris


On 4/14/2010 2:18 PM, Eleni Rapsomaniki wrote:

 Dear R-helpers,

 I have a huge data-set so need to avoid for loops as much as possible.
Can someone think how I can compute the result in the following example
(that uses a for-loop) using some version of apply instead (or any other
similarly super-efficient function)?

 example:
 #Suppose a matrix:
 m1=cbind(1:5,1:5,1:5)

 #The aim is to create a new matrix with every column containing the
cumulative sum of all previous columns.
 m2=m1
 for(i in 2:ncol(m1)){
  m2[,i]=apply(m1[,1:i],1,sum)
 }
 m2

 Many thanks in advance

 Eleni Rapsomaniki

 Research Associate
 Strangeways Research Laboratory
 Department of Public Health and Primary Care
 University of Cambridge


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


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] env() for lme4

2010-04-14 Thread pnouvellet

Hi,

using lme4a, and the dystuff data, I call profile and get:
 profile(fm1ML)
Error in UseMethod(profile) : 
  no applicable method for 'profile' applied to an object of class lmer

any solutions?
-- 
View this message in context: 
http://n4.nabble.com/env-for-lme4-tp1565045p1839791.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] Third and fourth order of derivative in smooth.lf function from locfit package

2010-04-14 Thread FMH
Dear All,

Could someone please advice me the way to define the derivative of the local 
polynomial regression in third and fourth order from the smooth.lf function?

Thank you
Fir


  
[[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] Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in c(0

2010-04-14 Thread John Fox
Dear David,

Thank you for addressing this question, but I answered Simon's question in
an email I sent to the R help list a while ago: You can't mix : and c() in a
recode specification; : isn't the sequence operator in a recode
specification but rather represents a continuous range of values. Thus,
something like 0:49.99=1 is perfectly line, but c(0:49.99)=1 isn't.

Regards,
 John


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
 Behalf Of David Winsemius
 Sent: April-14-10 8:45 AM
 To: Simon Kiss
 Cc: r-help@r-project.org
 Subject: Re: [R] Problem with recode -Error in parse(text = range[[1]][1])
:
 unexpected end of input in  c(0
 
 
 On Apr 14, 2010, at 2:56 AM, Simon Kiss wrote:
 
  Dear colleagues,
  in the help archive there was a previous person who encountered a
  problem with the recode command in the car library. I'm not sure
  if that was solved, there was no posting to that effect, but I'm
  having the same problem.
 
  I'm trying to recode a numeric variable with values from 0-100 into
  a binary variable with values (0,1).
 
  The following command:
 
  recode(green_2004_2$french, c(50:100)=0; c(0:49.99)=1)
 
 Look at the last example in the recode help page:
 recode(x, 1:2='A'; 3='B')
 ## [1] A A B A A B A A B
 It appears to me that the c() function around your sequences may be
 part of the problem and I further wondered whether 0:49.99 can
 succeed. Generally the : operator expects integer arguments, but the
 help page is not clear in this area and it appears that recode has a
 different interpretation.
   require(car)
   recode(x, -Inf:0=-1; 0.01:Inf=1) # succeeds


 --
 David
 
 
  gets the following error message
 
  Error in parse(text = range[[1]][1]) : unexpected end of input in 
  c(0
 
  I tried it with a second numerical variable in the same data set,
  but get precisely the same error at precisely the same location in
  the command, i.e. the second colon.
  As far as I can tell I have the most up-to-date version of car
  installed.
  Any suggestions?
  Yours, Simon Kiss
 
  *
  Simon J. Kiss, PhD
  SSHRC and DAAD Post-Doctoral Fellow
  John F. Kennedy Institute of North America Studies
  Free University of Berlin
  Lansstraße 7-9
  14195 Berlin, Germany
  Cell: +49 (0)1525-300-2812,
  Web: http://www.jfki.fu-berlin.de/index.html
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] MiscPsycho - incorrect levenshtein distance?

2010-04-14 Thread Doran, Harold
Thanks for pointing this out, it is indeed a bug. I have a few things on my 
plate today but will try and revise and place a new version on CRAN soon.


-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Wednesday, April 14, 2010 9:06 AM
To: Ben Meijering
Cc: r help; Doran, Harold
Subject: Re: [R] MiscPsycho - incorrect levenshtein distance?

Generally bug reports should go the the package emaintainer.

On Apr 14, 2010, at 5:08 AM, Ben Meijering wrote:

 For some strings I get a wrong (MiscPsycho) Levenstein distance:

I see you spelled it correctly in your subject line.

 stringMatch(abc, ab, normalize=NO)
 [1] 1

 stringMatch(abc, bc, normalize=NO)
 [1] 2

 I think the lines

 d - matrix(0, nrow = n + 1, ncol = m + 1)
 d[, 1] - 1:(n + 1)
 d[1, ] - 1:(m + 1)
 d[1, 1] - 0

 should be changed to

 d - matrix(0, nrow = n + 1, ncol = m + 1)
 d[, 1] - 0:n
 d[1, ] - 0:m

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] import file formatted RFC-822

2010-04-14 Thread Sebastian Kruk
Barry, thank you so much! It's work.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] total. factor. prodctvty. help!!

2010-04-14 Thread serdal
Dear all,

I have a basic(!) econometric question which i couldnt find the way to do it
in R. Well this could be also because of my wrong interpretation of the
econometric process that i am trying to implemet.so here i wanna ask if am
doing a logical mistake!!!

so here is the question with the explanation of the process, hope there will
be someone who can help me!

suppose i have a basic Cobb-Douglas production function, ( i am not gonna
give many information about the R commands or about the data since my
questionn is rather theoric)
and i run this model with OLS as following;

mdl1 = lm(lnQ~lnC+lnL+lnM+lnE,data=newdata)
 than in the second step, i need to get the predicted residual as a mesure
of total factor productivity == epsilon(hat)it= lnQit-lnQ(hat)it
and i get the residual by typing;
residuals(mdl1) == do i make mistake here or should i write another command
get the epsilon(hat), suppose i typed the correct command

than i save the residuals as a vector with
resid-mdl1$residuals

supposing that epsilon(hat) measures the TFP (TFPit=epsilon(it)), i need to
regress knowledge variables on it, such as eco and RD and i want to use
panel-data techniques in order to get the effect of eco and RD net of
unobserved heterogeneity.
 so the theortically the model that i want to estimate is

TFPit=alpha0+alpha1(eco)+alpha2(RD)+Ui+Vt+Wit

so i run this command;
mdl2-plm(resid~eco+RD, data=newdata)
then there is an error
Error in model.frame.default(formula = resid ~ eco + RD, data = ds,
drop.unused.levels = TRUE) :
  variable lengths differ (found for 'eco')


well here in fact, probably i am doing a econometrical mistake that might be
quite easy for somepeople, think that it is a silly question, but i need
help in this situation... if someone knows about Total Factor Productivity
and willing to help i would be greatful
cheers

[[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] svm of e1071 package

2010-04-14 Thread Steve Lianoglou
Hi Shyama,

On Tue, Apr 13, 2010 at 10:40 AM, Shyamasree Saha [shs] s...@aber.ac.uk wrote:
 Dear Steve,

 We have finally managed to run our code. Sparse matrix is helping a lot (I 
 should say without matrix.csr, we would not be able to do it). This time it 
 is taking very small amount of memory while running svm, but we could not use 
 as.matrix.csr directly on our huge data. we had to divide the data in small 
 chunk. we created matrix.csr from those small chunk, removed our original 
 object, loaded next chunk and used rbind to put all of them together. we need 
 to be very careful how much data we load at a time. Thanks again for you kind 
 help.

This is great news :-)

So, just to recap -- is the only thing that you did to get this to
work is to convert your input matrix to a sparse matrix (via SparseM)?
No parameter tweaking necessary?

Would an alternative approach to creating the sparse matrix be more
helpful? You can, for instance, create the entire sparse matrix in one
shot, like:

R m - as.matrix.csr(0, nrow=10, ncol=10)

(with appropriate numbers for your nrow,ncol params)

Then you can load subsets of your data into it and skipping the
chunked-`rbing` strategy .. is that easier?

Also, the e1071 package has read.matrix.csr and write.matrix.csr
functinos that might help facilitate loading/saving your data matrices
in the future.

-steve


 Regards
 Shyama
 
 From: Steve Lianoglou [mailinglist.honey...@gmail.com]
 Sent: Wednesday, April 07, 2010 4:00 PM
 To: Shyamasree Saha [shs]
 Cc: r help
 Subject: Re: [R] svm of e1071 package

 Hi,

 On Tue, Apr 6, 2010 at 7:16 PM, Shyamasree Saha [shs] s...@aber.ac.uk wrote:
 Dear Steve,

 Thanks again for your help and reply. your help was very useful and gave us 
 some options. We will follow your suggestions and let you know about it.

 No problem ... yeah, please write back when you figure out what's up
 (or hit more roadblocks), I'd be curious to know what the solution is.

 Thanks,
 -steve


 Regards,
 shyama
 
 From: Steve Lianoglou [mailinglist.honey...@gmail.com]
 Sent: Tuesday, April 06, 2010 9:40 PM
 To: Shyamasree Saha [shs]
 Cc: r help
 Subject: Re: [R] svm of e1071 package

 Hi Shyama,

 Don't forget to CC the r-help list in your discussions so that there
 are more eyes on this problem, and others might potentially benefit
 from discussion.

 Comments in line.

 On Tue, Apr 6, 2010 at 4:06 PM, Shyamasree Saha [shs] s...@aber.ac.uk 
 wrote:
 Dear Steve,

 Thanks a lot for your reply. As you have suggested kernlab and SparseM 
 packages, we have now installed it and reading about these packages. I am 
 trying to answer your questions. I have also added a bit of code. Please 
 let me know whether you need to know more and what is your suggestions.

 Thanks again for your help.

 Regards,
 Shyamasree

 R .Machine$sizeof.pointer ## it should be 8
 Yes, it is indeed 8.

 OK

 * What type of kernel are you using? Have you tried different ones?
 Just tried the linear kernel, haven't tried with other kernels.

 OK, let's stick with that for now.

 * Are you doing classification or regression?
 We are doing multi-class classification. There are 11 classes.

 Is it any better if you just do 1-vs-all?
 Also (from your code at the end of the email) what if you train the
 model with `probability=FALSE`?

 * Is your data/feature matrix sparse? If so, are you passing libsvm a
 SparseM matrix?
 Yes, the feature matrix is indeed very sparse. Just passing a matrix
 at the moment.
 Not sure how to define it as SparseM matrix.

 R library(SparseM)
 R ?as.matrix.csr

 * Have you tried playing with some of the params in the svm call, like
 the values for tolerance, epsilon, cost/nu/etc.
 No, have not played with these at all. What do you recommend?

 Try to increase (I think (maybe decrease??)) the tolerance from its
 default value. Moving this in one direction or the other allows the
 solver to converge to a less-precise solution -- haven't read the
 source in a while, though, so test it.

 * Try an even smaller subset of your data ( 1.4 GB)
 It works fine with a much smaller subset but have not tried with
 intermediate sizes.

 OK

 Can you give an idea of how long it takes for your call to `svm` to
 return with different data sizes?
 How does its memory stats look like?

 * What is the dimensionality of your X matrix -- how many examples,
 and how many features does each example have
 X matrix dimensionality: 35,500 rows x 52,058 cols . All features are
 binary.

 I think that's quite large.

 This might be a good reason to try liblinear as it is more appropriate
 for large feature spaces and is made by the same libsvm folks:

 http://www.csie.ntu.edu.tw/~cjlin/liblinear/
 http://www.csie.ntu.edu.tw/~cjlin/papers/liblinear.pdf

 * Include sessionInfo() -- we don't know what version of R/e1071 etc.
 R version 2.10.1 (2009-12-14)
 e1071      1.5-23
 running on
 Linux version 

Re: [R] env() for lme4

2010-04-14 Thread Rob Goedman
Pierre,

This question is better asked on R-sig-ME.

I updated below call to 'profile(fm...@env)'

Regards,
Rob


On Apr 14, 2010, at 6:28 AM, pnouvellet wrote:

 
 Hi,
 
 using lme4a, and the dystuff data, I call profile and get:
 profile(fm1ML)
 Error in UseMethod(profile) : 
  no applicable method for 'profile' applied to an object of class lmer
 
 any solutions?
 -- 
 View this message in context: 
 http://n4.nabble.com/env-for-lme4-tp1565045p1839791.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 delete columns with NA values?

2010-04-14 Thread muting

Hi everyone:

I have a dataset:

tm1
 col1 col2
[1,]1   NA
[2,]11
[3,]22
[4,]11
[5,]22
[6,]1   NA

I need to delete entire column 2 that has NA in it(not all of them are NAs),
and the result I want is

tm1
 col1 
[1,]1  
[2,]1
[3,]2
[4,]1
[5,]2
[6,]1   

what should I do? 
I search a lot, all I found is how to delete column with all NA values..

Thanks a lot

muting

-- 
View this message in context: 
http://n4.nabble.com/how-to-delete-columns-with-NA-values-tp1839902p1839902.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 delete columns with NA values?

2010-04-14 Thread Erik Iverson

Hello,

muting wrote:

Hi everyone:

I have a dataset:


This looks like a matrix.  To perform functions on each row or column of 
a matrix, use the apply function.


If you had a data.frame, you could perform a function on each column 
using sapply or lapply.


tm1
 col1 col2
[1,]1   NA
[2,]11
[3,]22
[4,]11
[5,]22
[6,]1   NA

I need to delete entire column 2 that has NA in it(not all of them are NAs),
and the result I want is

tm1
 col1 
[1,]1  
[2,]1
[3,]2
[4,]1
[5,]2
[6,]1   

what should I do? 


## for a data.frame x
x - data.frame(a = 1:10, b = c(2:10, NA), c = 2:11)

x[sapply(x, function(x) !any(is.na(x)))]

## for a matrix y
y - matrix(1:30, ncol = 3)
y[20] - NA

y[, apply(y, 2, function(x) !any(is.na(x)))]

## or maybe even simply...
y[,complete.cases(t(y))]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 delete columns with NA values?

2010-04-14 Thread Chuck Cleland
On 4/14/2010 10:56 AM, muting wrote:
 Hi everyone:
 
 I have a dataset:
 
 tm1
  col1 col2
 [1,]1   NA
 [2,]11
 [3,]22
 [4,]11
 [5,]22
 [6,]1   NA
 
 I need to delete entire column 2 that has NA in it(not all of them are NAs),
 and the result I want is
 
 tm1
  col1 
 [1,]1  
 [2,]1
 [3,]2
 [4,]1
 [5,]2
 [6,]1   
 
 what should I do? 

subset(tm1, select=colMeans(is.na(tm1)) == 0)

OR

tm1[,colMeans(is.na(tm1)) == 0]

 I search a lot, all I found is how to delete column with all NA values..
 
 Thanks a lot
 
 muting

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

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


[R] Roxygen - basic usage uncertain

2010-04-14 Thread David Esp

I am trying to make a package consisting of a single function with
auto-documentation assistance from 'roxygen' but am uncertain of the correct
procedure.  My version of 'R' is 2.10.1.  

I followed the following steps:
1) Get an existing function (un-commented) as an '.R' file.
2) Add formal comments (e.g. owner) above that function's code using the [#'
@] syntax.
3) Create a further '.R' file to contain formal comments relating to the
package as a whole.  This file contains no meaningful 'R' code but must at
least have an NA at the end to ensure it gets parsed. 
4) Use 'package.skeleton' to turn these two files into a basic package
(folder structure etc.)
5) The '.Rd' files so-produced to have empty titles.  Empty titles would
give rise to error message when installing.  However 'roxygenize' (next
step) will replace these '.Rd' files with its own generated ones having
non-empty titles.  To avoid clutter and confusion (e.g. if package name not
identical in formal comments), the existing '.Rd' files are best deleted.
6) From 'R', apply 'roxygenize' to the basic package.  Must make the target
directory the same as the source directory otherwise no '.R' files will be
present (that's what I observe - does it indicate some problem with my
procedure or is that to be expected?).  So make a safe copy of the source
directory first.
7) R CMD check mypackage
8) R CMD INSTALL mypackage

Is that a reasonable process?  Please, I'm really needing baby-steps here.

-- 
View this message in context: 
http://n4.nabble.com/Roxygen-basic-usage-uncertain-tp1839933p1839933.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] R package documentation

2010-04-14 Thread Sharpie


pomchip wrote:
 
 Dear R users,
 
 I am currently writing the documentation for my first package. I have
 created a short user manual using sweave/pdflatex which is distinct from
 the
 manual/summary-of-package-functions created by R CMD CHECK. I was
 wondering
 how could I seamlessly combine both documents.
 
 Thanks for your help
 
 Sebastien
 

The .Rd files are normally kept separate from the vignette- this is because
Rd files have to be translated into several different formats such as html,
man pages and pdf.  The vignette allows for a more free-form discussion as
it does not have the rigid structure that allows .Rd files to be translated.

That being said, you could add the contents of .Rd files to something like
an appendix in your vignette by converting the .Rd files to .tex and
including them in your Sweave source.  Something like the following would
convert each .Rd file and append it to a single .tex file (on UNIX/Linux
systems):

  cd yourPackage/man
  ls *.Rd | xargs -I % R CMD Rdconv -t latex %  manPages.tex

You could then move manPages.tex to yourPackage/inst/doc and include int in
your Sweave source via \input{}.  You will need to ensure
$R_HOME/share/texmf is on your tex search path as the LaTeX compiler will
need Rd.sty to define some of the macros in the code produced by R CMD
Rdconv.

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://n4.nabble.com/R-package-documentation-tp1839589p1839922.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] fitting a quadratic function - poly?

2010-04-14 Thread Stefan Uhmann

Hi List,

I can not get my head around the following problem. I want to fit a 
quadratic function to some data and stumbled across poly(). What exactly 
does it, i.e. why are there different results for fit1 and fit2?


x = seq(-10, 10)
y = x^2

fit1 = lm(y ~ x + I(x^2))
fit2 = lm(y ~ poly(x, 2))

plot(x,y)
lines(x, fit1$fitted.values, col = 2)
lines(x, fit2$fitted.values, col = 3)

round(fit1$coefficients, 2)
round(fit2$coefficients, 2)

Thanks in advance,
Stefan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 delete columns with NA values?

2010-04-14 Thread muting

Thank you all!
It works well now
-- 
View this message in context: 
http://n4.nabble.com/how-to-delete-columns-with-NA-values-tp1839902p1839953.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 delete columns with NA values?

2010-04-14 Thread Stefan Uhmann

Hi muting,

# your data
muting - data.frame(col1 = c(1,1,2,1,2,1), col2=c(NA,1,2,1,2,NA))
# 1. finding rows with NA
is.na(muting)
# 2. counting the NAs per column
colSums(is.na(muting))
# 3. keeping only the ones without NAs
muting[,colSums(is.na(muting)) == 0]

Regards,
Stefan

schrieb muting, Am 14.04.2010 16:56:


Hi everyone:

I have a dataset:

tm1
  col1 col2
[1,]1   NA
[2,]11
[3,]22
[4,]11
[5,]22
[6,]1   NA

I need to delete entire column 2 that has NA in it(not all of them are NAs),
and the result I want is

tm1
  col1
[1,]1
[2,]1
[3,]2
[4,]1
[5,]2
[6,]1

what should I do?
I search a lot, all I found is how to delete column with all NA values..

Thanks a lot

muting



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] fitting a quadratic function - poly?

2010-04-14 Thread Duncan Murdoch

On 14/04/2010 11:12 AM, Stefan Uhmann wrote:

Hi List,

I can not get my head around the following problem. I want to fit a 
quadratic function to some data and stumbled across poly(). What exactly 
does it, i.e. why are there different results for fit1 and fit2?


x = seq(-10, 10)
y = x^2

fit1 = lm(y ~ x + I(x^2))
fit2 = lm(y ~ poly(x, 2))

plot(x,y)
lines(x, fit1$fitted.values, col = 2)
lines(x, fit2$fitted.values, col = 3)
  


These look the same to me.

round(fit1$coefficients, 2)
round(fit2$coefficients, 2)
  


These look different, because poly uses orthogonal polynomials, a 
different parametrization.  You can see the difference if you ask for 
model.matrix(fit1) and model.matrix(fit2).  (You can plot these using 
matplot(model.matrix(fit1)), etc.)


Duncan Murdoch

Thanks in advance,
Stefan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] sum specific rows in a data frame

2010-04-14 Thread arnaud Gaboury
Thank you for your help. The best I have found is to use the ddply function.

 pose
  DESCRIPTION QUANITY CLOSING.PRICE
1   WHEAT May/101467.75
2   WHEAT May/101467.75
3   WHEAT May/101467.75
4   WHEAT May/101467.75
5 COTTON NO.2 May/101 78.13
6 COTTON NO.2 May/101 78.13
7 COTTON NO.2 May/101 78.13

 library(plyr)
 op=ddply(pose, c(DESCRIPTION,CLOSING.PRICE),summarise, POSITION=
sum(QUANITY))
 op
  DESCRIPTION CLOSING.PRICE POSITION
1 COTTON NO.2 May/10  78.133
2   WHEAT May/10 467.754

Op is a data.frame object.The trick is done!



***
Arnaud Gaboury
Mobile: +41 79 392 79 56
BBM: 255B488F

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Network Analysis

2010-04-14 Thread bchaney

Does anyone have any thoughts on this? I would really appreciate any
insights/suggestions that the group could provide.
-- 
View this message in context: 
http://n4.nabble.com/Network-Analysis-tp1838902p1839992.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] Running cumulative sums in matrices

2010-04-14 Thread Bert Gunter
Eleni et. al.:

Perhaps it's worth noting that there is generally NO reason to prefer
apply-family code to explicit for-loops for execution speed. Apply-type
statments **are** essentially disguised loops -- that is, they execute the
loop code repeatedly at the R interpreter level. They do employ some
efficiency tricks to try to do so as fast as possible; but as posts in this
thread have already noted, whether they run faster or slower than explicit
loops is generally code and problem specific. Sometimes yes; sometimes no;
often about the same.

So, for example,

myfun - function(x){...}
z - somelist
ans -lapply(z,myfun)

## and 

ans - vector(list,10)
for(i in seq_len(length(z)))ans[[i]] - myfun(z[[i]])

should take about the same time.

The main reason to prefer the former instead of the latter is that the
former conforms to R's functional programming paradigm and tends to produce
cleaner, more debuggable, more maintainable code (I realize that this is a
subjective preference with which many may disagree).

When speedup is desired, the key is to move the loop from the interpreted to
the compiled code level via vectorization, either by making use of R's
built-in compiled functions (like cumsum), which are generally .Internal or
.Primitive, or to write and call your own compiled code, e.g.via .Call. This
often can make things orders of magnitude faster.

I hope this provides some clarification about an issue that many seem
confused about. If anything I have said is misstated or requires further
clarification, I would appreciate corrections.


Bert Gunter
Genentech Nonclinical Statistics

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Eleni Rapsomaniki
Sent: Wednesday, April 14, 2010 5:18 AM
To: r-help@r-project.org
Subject: [R] Running cumulative sums in matrices


Dear R-helpers,

I have a huge data-set so need to avoid for loops as much as possible. Can
someone think how I can compute the result in the following example (that
uses a for-loop) using some version of apply instead (or any other similarly
super-efficient function)? 

example:
#Suppose a matrix:
m1=cbind(1:5,1:5,1:5)

#The aim is to create a new matrix with every column containing the
cumulative sum of all previous columns.
m2=m1
for(i in 2:ncol(m1)){
m2[,i]=apply(m1[,1:i],1,sum)
}
m2

Many thanks in advance

Eleni Rapsomaniki

Research Associate
Strangeways Research Laboratory
Department of Public Health and Primary Care
University of Cambridge
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] - how/when/why do you use it?

2010-04-14 Thread Greg Snow
The - assignment operator is very powerful, but can be dangerous as well.  
When tempted to use it, look for alternatives first, there may be a better way. 
 But having said that, I am one of the more guilty people for using it (quite a 
few of the functions in the TeachingDemos package use -).

The main use that I see is when you are using a function written by someone 
else that takes one of your functions as an argument and you want to save 
information from your function that is not being passed back through the 
calling function.  For example you may want to trace the calls to your function 
that is being called by optim, just define your function A which defines within 
it function B which is to be optimized, A also contains an empty vector to 
store results in, then A calls optim passing B to it, B uses - to update the 
vector in A every time that it is called, now A has the results of optim and 
also a trace of info on all the calls to B.

- can also be used for package local variables (less evil than globals) where 
within a package you can call one function to set some things up, then other 
functions in the package can refer to the variable created to see the setup as 
well as modifying options local to the package.

Hope this helps,

-- 
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-boun...@r-
 project.org] On Behalf Of Tal Galili
 Sent: Tuesday, April 13, 2010 8:03 AM
 To: r-help@r-project.org
 Subject: [R] - how/when/why do you use it?
 
 Hi all,
 
 Today I came across scoping in the R
 introhttp://cran.r-project.org/doc/manuals/R-intro.html#Scope (after
 reading Robert Gentleman
 fortunehttp://rfortunes.posterous.com/im-always-thrilled-when-people-
 discover-what
 on
 lexical scooping) , and am very curious about the - assignment.
 
 The manual showed one (very interesting) example for -, which I
 feel I
 understood. What I am still missing is the context of when this can be
 useful.
 
 So what I would love to read from you are examples (or links to
 examples) on
 when using - can be interesting/useful. What might be the dangers
 of
 using it (it looks easy to loose track of), and any tips you might feel
 like
 sharing.
 
 Thanks,
 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)
 ---
 ---
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: fitting a quadratic function - poly?

2010-04-14 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 14.04.2010 17:12:51:

 Hi List,
 
 I can not get my head around the following problem. I want to fit a 
 quadratic function to some data and stumbled across poly(). What exactly 

 does it, i.e. why are there different results for fit1 and fit2?
 
 x = seq(-10, 10)
 y = x^2
 
 fit1 = lm(y ~ x + I(x^2))
 fit2 = lm(y ~ poly(x, 2))
 
 plot(x,y)
 lines(x, fit1$fitted.values, col = 2)
 lines(x, fit2$fitted.values, col = 3)

 round(fitted(fit1)-fitted(fit2),5)
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 

results are same.

 
 round(fit1$coefficients, 2)
 round(fit2$coefficients, 2)

Coefficients are different as you fit different values. See

?poly

poly(-10:10,2)

I believe that others give you better explanation. So you can not use 
coefficients evaluated by lm(.~poly(...)) directly.

Regards
Petr

 
 Thanks in advance,
 Stefan
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Odp: fitting a quadratic function - poly?

2010-04-14 Thread Bert Gunter
Below.

-- Bert 


Bert Gunter
Genentech Nonclinical Statistics


Coefficients are different as you fit different values. See

?poly

poly(-10:10,2)

I believe that others give you better explanation. So you can not use 
coefficients evaluated by lm(.~poly(...)) directly.

-- Well, it depends what you mean by use...directly. But I think the
answer is, yes you can. See ?SafePrediction  for details. -- Bert

Regards
Petr

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

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

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


Re: [R] Odp: fitting a quadratic function - poly?

2010-04-14 Thread Petr PIKAL
Hi


Bert Gunter gunter.ber...@gene.com napsal dne 14.04.2010 18:01:52:

 Below.
 
 -- Bert 
 
 
 Bert Gunter
 Genentech Nonclinical Statistics
 
 
 Coefficients are different as you fit different values. See
 
 ?poly
 
 poly(-10:10,2)
 
 I believe that others give you better explanation. So you can not use 
 coefficients evaluated by lm(.~poly(...)) directly.
 
 -- Well, it depends what you mean by use...directly. But I think the

I mean that you can use

fit- lm(y~x+I(x^2))
coef(fit)[1] + coef(fit)[2]*x + coef(fit)[3]*x^2

but you can not use

fit- lm(y~poly(x,2))
coef(fit)[1] + coef(fit)[2]*x + coef(fit)[3]*x^2

to compute y.

Regards
Petr


 answer is, yes you can. See ?SafePrediction  for details. -- Bert
 
 Regards
 Petr
 
  
  Thanks in advance,
  Stefan
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


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


Re: [R] - how/when/why do you use it?

2010-04-14 Thread Szumiloski, John
I love Patrick Burns' comment on the - operator in R Inferno:

If you think you need '-', think again.  If on reflection you still
think you need '-', think again. 

Is this in package::fortunes?

John 

John  Szumiloski,  Ph.D.

Senior Biometrician
Biometrics Research
WP53B-120
Merck Research Laboratories
P.O. Box 0004
West Point, PA 19486-0004

(215) 652-7346 (PH)
(215) 993-1835 (FAX)



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Greg Snow
Sent: Wednesday, 14 April, 2010 11:43 AM
To: Tal Galili; r-help@r-project.org
Subject: Re: [R] - how/when/why do you use it?

The - assignment operator is very powerful, but can be dangerous as
well.  When tempted to use it, look for alternatives first, there may be
a better way.  But having said that, I am one of the more guilty people
for using it (quite a few of the functions in the TeachingDemos package
use -).

The main use that I see is when you are using a function written by
someone else that takes one of your functions as an argument and you
want to save information from your function that is not being passed
back through the calling function.  For example you may want to trace
the calls to your function that is being called by optim, just define
your function A which defines within it function B which is to be
optimized, A also contains an empty vector to store results in, then A
calls optim passing B to it, B uses - to update the vector in A every
time that it is called, now A has the results of optim and also a trace
of info on all the calls to B.

- can also be used for package local variables (less evil than
globals) where within a package you can call one function to set some
things up, then other functions in the package can refer to the variable
created to see the setup as well as modifying options local to the
package.

Hope this helps,

--
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-boun...@r-
 project.org] On Behalf Of Tal Galili
 Sent: Tuesday, April 13, 2010 8:03 AM
 To: r-help@r-project.org
 Subject: [R] - how/when/why do you use it?
 
 Hi all,
 
 Today I came across scoping in the R
 introhttp://cran.r-project.org/doc/manuals/R-intro.html#Scope (after
 reading Robert Gentleman
 fortunehttp://rfortunes.posterous.com/im-always-thrilled-when-people-
 discover-what
 on
 lexical scooping) , and am very curious about the - assignment.
 
 The manual showed one (very interesting) example for -, which I
 feel I
 understood. What I am still missing is the context of when this can be
 useful.
 
 So what I would love to read from you are examples (or links to
 examples) on
 when using - can be interesting/useful. What might be the dangers
 of
 using it (it looks easy to loose track of), and any tips you might
feel
 like
 sharing.
 
 Thanks,
 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)

---
 ---
 
   [[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.
Notice:  This e-mail message, together with any attachme...{{dropped:10}}

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


[R] array manipulation

2010-04-14 Thread Muhammad Rahiz

Hello listeRs,

I'm trying to make a square radius around a given reference point. So 
given the following array, how can I manipulate it so that


x0 - array(1,dim=c(5,5))
x0

1 1 1 1 1
1 1 1 1 1
1 1 *1* 1 1
1 1 1 1 1
1 1 1 1 1

becomes

into

3 3 3 3 3
3 2 2 2 3
3 2 *1* 2 3
3 2 2 2 3
3 3 3 3 3

Thanks.

Muhammad

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] memory failure in adonis function (permanova)

2010-04-14 Thread Gavin Simpson
On Tue, 2010-03-16 at 17:12 +0100, Paloma Ruiz wrote:
 Dear all,
 
 I am trying to get a PERMANOVA with quite large data set. I am reading a lot
 about this question, but I do not get the answer about it. Although I know
 that the R function is adonis () (vegan package), it does not work:
 
 adonis(Pha.env~SPha, data=Pha, permutations=10)
 
 The error message:
  Error: cannot allocate vector of size 334.2 Mb
 In addition: Warning messages:
 1: In vegdist(lhs, method = method, ...) :
   Reached total allocation of 1535Mb: see help(memory.size)
 2: In vegdist(lhs, method = method, ...) :
   Reached total allocation of 1535Mb: see help(memory.size)
 3: In vegdist(lhs, method = method, ...) :
   Reached total allocation of 1535Mb: see help(memory.size)
 4: In vegdist(lhs, method = method, ...) :
   Reached total allocation of 1535Mb: see help(memory.size)
 
 When I have received this message from R usually it is due to an incorrect
 introduction of the function elements (i.e., memory message errors).
 However, I've just checked my matrix (Pha.env is a data.frame with num or
 int variables, and, Pha is a data.frame with factor variables) and the
 length of matrices is the same. I know that I'm wrong somewhere specifying
 the matrices in adonis(), but I can't fix it.

That error is coming from the calculation of the dissimilarity matrix
and you've exhausted the 1.5GB of (allocated) RAM on your system. How
many samples (rows) are you trying that on?

G

 
 Thanks in advance,
 
 Paloma
 
   [[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. 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.


Re: [R] Gaussian Quadrature Numerical Integration In R

2010-04-14 Thread Ravi Varadhan
Just do a variable transformation. If your function is f(x), your new
function would be:
f'(x) = sigma * f(sigma * x + mu).  You can integrate f'(x) using
the Hermite quadrature.

Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Ines Azaiez
Sent: Tuesday, April 13, 2010 9:25 PM
To: r-help-boun...@stat.math.ethz.ch; r-help@r-project.org
Subject: [R] Gaussian Quadrature Numerical Integration In R

Hi All,

I am trying to use A Gaussian quadrature over the interval (-infty,infty)
with weighting function W(x)=exp(-(x-mu)^2/sigma) to estimate an integral.
Is there a way to do it in R? Is there a function already implemented which
uses such weighting function. 
I have been searching in the statmode package and I found the function
gauss.quad(100, kind=hermite) which uses the weighting function
W(x)=exp(-x^2). Is there a more general version of this weighting function
(using mu and sigma)?

Thanks for your help

Iazaiez
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: fitting a quadratic function - poly?

2010-04-14 Thread Bert Gunter
 

Petr Pikal wrote:

...

I mean that you can use

fit- lm(y~x+I(x^2))
coef(fit)[1] + coef(fit)[2]*x + coef(fit)[3]*x^2

but you can not use

fit- lm(y~poly(x,2))
coef(fit)[1] + coef(fit)[2]*x + coef(fit)[3]*x^2  

(to get the fits for any x vector)

-- But you **can** use

ypred - predict(fit,data.frame(x = x))

-- in **both** cases. Which is, I think, how it should be done.

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Statistics 



 answer is, yes you can. See ?SafePrediction  for details. -- Bert
 
 Regards
 Petr
 
  
  Thanks in advance,
  Stefan
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


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


Re: [R] Import ASCII data using a .sas program

2010-04-14 Thread Donald Catanzaro, PhD

Good Day,

I have several ASCII data files that I would like to import into R.  
They all have a SAS import file which is used to bring the data into SAS 
and I am hoping to use this to bring the data into R.  There are lots of 
variables involved and the ASCII data file is 2308 columns long so I 
would certainly prefer to figure out a smart way of converting the data 
to R.


The ASCII data is a long stream of numbers (no field separators or 
delimiters) while the SAS import file looks like:


libname mine 'c:\';
data mine.fh4;
infile 'd:\fh4.txt' lrecl=2309;
input
   perstat1 $1-2
   linenum $3-4
   I_wave1 $5-5
   bnocost1 $6-10
   bnosta1 $11-12

So SAS uses the position of the ASCII character to determine what 
variable the data should be in while the SCAN or the READ. FWF function 
of R uses the width of the column.


Does anyway have a smart and/or automated way of moving my ASCII data 
into R using this .SAS program  ?


--
-Don 

Don Catanzaro, PhD  
Landscape Ecologist

dgcatanz...@gmail.com
16144 Sigmond Lane
Lowell, AR 72745
479-751-3616

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Simulation problem.

2010-04-14 Thread Greg Snow
This looks like homework.  If it is, you should really tell us along with what 
your teacher's policy is on getting help over the internet is (and note that 
many teachers monitor this list and can see if you are getting help).

You have done the first part yourself, much better than some who have tried to 
get us to do the whole thing for them, so a possible hint:  the new problem 
really has 3 groups, never sick, currently sick, and healed.  Just modify your 
current code to allow for people to move from the currently sick to the healed 
group.

-- 
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-boun...@r-
 project.org] On Behalf Of Piotr Arendarski
 Sent: Tuesday, April 13, 2010 4:27 PM
 To: r-help@r-project.org
 Subject: [R] Simulation problem.
 
 Hi,
 I have problem with simulating.
 This is my task...
 
 Suppose that there are N persons some of whom are sick with influenza.
 The
 following assumptions are made:
 * when a sick person meets a healthy one, the chance is á that the
 latter
 will be infected
 * all encounters are between two persons
 
 Write a function which simulates this model for various values of
 N (say, 10 000) and á (say, between 0.001 and 0.1). Monitor the
 history of this process, assuming that one individual is infected at
 the beginning.
 
 The code is:
 *
 simulation - function(number, prob){
 cumulative.time - 0
 current.time - 0
 number.sick - 1
 while(number.sicknumber){
 current.time - current.time + 1
 
 meetings - rhyper(nn=1, m=number.sick, n=number-number.sick, k=2)
 
 if(meetings==1){
 one.sick - rbinom(n=1, size=1, prob)
 if(one.sick==1){
 cumulative.time - c(cumulative.time, current.time)
 number.sick - number.sick + 1
 }}}
 cumulative.time
 }
 
 number - 1000
 prob - .05
 model - simulate(number, prob)*
 
 But than  add the assumption that *each infected person has a 0.01
 chance
 of recovering at each time unit* Do you have idea how to modify the
 code
 ?
 
 Piotr Arendarski
 
   [[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] array manipulation

2010-04-14 Thread Bert Gunter
1+pmax(abs(row(z)-3),abs(col(z)-3)) 


?row  ?col  ?pmax for details.

Bert Gunter
Genentech Nonclinical Statistics

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Muhammad Rahiz
Sent: Wednesday, April 14, 2010 9:44 AM
To: r-help@r-project.org
Subject: [R] array manipulation

Hello listeRs,

I'm trying to make a square radius around a given reference point. So 
given the following array, how can I manipulate it so that

x0 - array(1,dim=c(5,5))
x0

1 1 1 1 1
1 1 1 1 1
1 1 *1* 1 1
1 1 1 1 1
1 1 1 1 1

becomes

into

3 3 3 3 3
3 2 2 2 3
3 2 *1* 2 3
3 2 2 2 3
3 3 3 3 3

Thanks.

Muhammad

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] - how/when/why do you use it?

2010-04-14 Thread jim holtman
If you use '-' remember that you are going to get into trouble and it will
be a challange to debug your script.  Only use it if you have a real good
understanding of the scoping rules in R and have exhausted all the other
avenues.

I, like Greg, am guilty of using it because I still keep some of my old
habits (like COMMON in FORTRAN) and every so often do have the need for a
global variable I can change in a lower level routine without returning a
value (and am willing to suffer the consequences of side effects).  And
make sure that you always use the - when referring to that object so that
you do not create a local copy in some subroutine and really get messed up.

So as the answer to when, I typically says never.

On Wed, Apr 14, 2010 at 11:42 AM, Greg Snow greg.s...@imail.org wrote:

 The - assignment operator is very powerful, but can be dangerous as well.
  When tempted to use it, look for alternatives first, there may be a better
 way.  But having said that, I am one of the more guilty people for using it
 (quite a few of the functions in the TeachingDemos package use -).

 The main use that I see is when you are using a function written by someone
 else that takes one of your functions as an argument and you want to save
 information from your function that is not being passed back through the
 calling function.  For example you may want to trace the calls to your
 function that is being called by optim, just define your function A which
 defines within it function B which is to be optimized, A also contains an
 empty vector to store results in, then A calls optim passing B to it, B uses
 - to update the vector in A every time that it is called, now A has the
 results of optim and also a trace of info on all the calls to B.

 - can also be used for package local variables (less evil than globals)
 where within a package you can call one function to set some things up, then
 other functions in the package can refer to the variable created to see the
 setup as well as modifying options local to the package.

 Hope this helps,

 --
 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-boun...@r-
  project.org] On Behalf Of Tal Galili
  Sent: Tuesday, April 13, 2010 8:03 AM
  To: r-help@r-project.org
  Subject: [R] - how/when/why do you use it?
 
  Hi all,
 
  Today I came across scoping in the R
  introhttp://cran.r-project.org/doc/manuals/R-intro.html#Scope (after
  reading Robert Gentleman
  fortunehttp://rfortunes.posterous.com/im-always-thrilled-when-people-
  discover-what
  on
  lexical scooping) , and am very curious about the - assignment.
 
  The manual showed one (very interesting) example for -, which I
  feel I
  understood. What I am still missing is the context of when this can be
  useful.
 
  So what I would love to read from you are examples (or links to
  examples) on
  when using - can be interesting/useful. What might be the dangers
  of
  using it (it looks easy to loose track of), and any tips you might feel
  like
  sharing.
 
  Thanks,
  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)
  ---
  ---
 
[[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-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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] what is the intercept of a two-way anova model without interaction term?

2010-04-14 Thread Xiaokuan Wei
Dear list,

I have a question regarding the meaning of intercept term in a two-way anova 
model without interaction term.

for example (let's assume there is no interaction between factor1 and factor2) :

 df
        val        factor1 factor2
1  48.61533       A      t1
2 171.13535       B      t1
3  65.96884       C      t1
4  63.71222       A      t2
5  80.22049       B      t2
6  96.95929       C      t2
7  38.70078       A      t3
8  99.44787       B      t3
9  36.58818       C      t3

the summary of regression :

 summary(m)
Call:
lm(formula = val ~ factor1 + factor2, data = df)
Residuals:
      1       2       3       4       
5       6       7       8       9 
-19.040  36.889 -17.849  11.000 -39.084  28.084   8.040   2.195 -10.235 
Coefficients:
            Estimate Std. Error t value Pr(|t|)  
(Intercept)    67.66      25.42   2.661   0.0563 .
factor1B       66.59      27.85   2.391   0.0751 .
factor1C       16.16      27.85   0.580   0.5928  
factor2t2     -14.94      27.85  -0.537   0.6200  
factor2t3     -36.99      27.85  -1.328   0.2548  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ 
’ 1 
Residual standard error: 34.11 on 4 degrees of freedom
Multiple R-squared: 0.6669,     Adjusted R-squared: 0.3338 
F-statistic: 2.002 on 4 and 4 DF,  p-value: 0.2589 


This is contrast treatment, and my question is what the intercept (here is 
67.66) represent for?

Thank you.


Xiaokuan


  
[[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] Network Analysis

2010-04-14 Thread Jakson A. Aquino
On Wed, Apr 14, 2010 at 07:44:23AM -0800, bchaney wrote:
 
 Does anyone have any thoughts on this? I would really appreciate any
 insights/suggestions that the group could provide.

I did not do sophisticated analyzes, but my opinion is that igraph
is easier to use and more versatile than statnet. It is also more
capable of dealing with big networks. The only issue with igraph
functions is that we have to remember that the indexes start at 0
and not 1 as all other R functions. The default igraph plots are
very simple, but it is easy to add attributes to an igraph object
to make nice graphics.

-- 
Jakson A. Aquino
Federal Uni. of Ceara
www.lepem.ufc.br - Brazil

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 can I plot the histogram like this using R?

2010-04-14 Thread Greg Snow
There are several ways in which the picture you show is uglier than the 
histogram produced by R.  Which of these do you want to accomplish and why?

-- 
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-boun...@r-
 project.org] On Behalf Of bbslover
 Sent: Tuesday, April 13, 2010 10:46 PM
 To: r-help@r-project.org
 Subject: [R] how can I plot the histogram like this using R?
 
 
 I want to get the plot like this,
 http://n4.nabble.com/file/n1839303/%25E9%25A2%2591%25E7%258E%2587%25E5%
 2588%2586%25E5%25B8%2583%25E5%259B%25BE%25E6%25A0%2587%25E5%2587%2586.j
 pg
 %E9%A2%91%E7%8E%87%E5%88%86%E5%B8%83%E5%9B%BE%E6%A0%87%E5%87%86.jpg
 
 not this, http://n4.nabble.com/file/n1839303/R.jpg R.jpg
 
 and  the data here, thank you!
 http://n4.nabble.com/file/n1839303/y1.txt
 y1.txt
 
 can R deal with this problem?  how can I do?
 --
 View this message in context: http://n4.nabble.com/how-can-I-plot-the-
 histogram-like-this-using-R-tp1839303p1839303.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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Getting Started with Bayesian MCMC

2010-04-14 Thread Greg Snow
The purpose of the task view is to answer questions like this.  I for one would 
not be able to give a better answer than what is there.

My suggestion would be to pull out your Bayesian textbook (or get one, or use 
online notes from a class, etc.) and look through the homework problems and 
examples for things that may be similar to what you may be doing in the future. 
 Then try doing those problems/examples using a few of the different tools 
recommended in the task view (start with simple things even if they are not the 
types of problems you will do for real, just to get a feel for the different 
packages).  This will help you decide which packages work best for you and 
which interfaces you prefer.  Then when you have real problems to solve, you 
will have the knowledge of which tools to use and how to use them.

You should also consider contributing what you learn back to the task view for 
others.

-- 
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-boun...@r-
 project.org] On Behalf Of Ben
 Sent: Tuesday, April 13, 2010 5:50 PM
 To: r-help@r-project.org
 Subject: [R] Getting Started with Bayesian MCMC
 
 Hi all,
 
 I would like to start to use R's MCMC abilities to compute answers in
 Bayesian statistics.  I don't have any specific problems in mind yet,
 but I would like to be able to compute/sample posterior probabilities
 for low-dimensional custom models, as well as handle standard
 Bayesian cases like linear regression and hierarchical models.
 
 R clearly has a lot of abilities in this area:
 
 http://cran.r-project.org/web/views/Bayesian.html
 
 --enough to be confusing!  For instance, there are apparently three
 separate interfaces to JAGS, and I'm not even sure I want/need to
 interface to JAGS at all.
 
 Can someone please get me started?  Are there a handful of must-have
 packages and software that everyone (who uses MCMC regularly) uses?
 
 Any responses are appreciated,
 
 --
 Ben
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] import file formatted RFC-822

2010-04-14 Thread Sebastian Kruk
I have a problem, In a few cases robot-exclusion-useragent have 2 or
more values, is there a manner to fix it? For example, robot askjeeves
has three names.

2010/4/13 Barry Rowlingson b.rowling...@lancaster.ac.uk:
 On Tue, Apr 13, 2010 at 6:26 PM, Sebastian Kruk residuo.so...@gmail.com 
 wrote:
 Dear R-list users:

 I would like to import a database of web robots,
 http://www.robotstxt.org/db/all.txt, it´s formatted RFC-822, ¿how can
 I do it?

  RFC822 looks very much like R's package DESCRIPTION files, and they
 are read in using read.dcf because they are conformant to 'Debian
 Control File' format. So I tried read.dcf on it:

   robots = read.dcf(all.txt)
   dim(robots)
  [1] 298  38

  so that's a matrix:

   dimnames(robots)
 [[1]]
 NULL

 [[2]]
  [1] robot-id                  robot-name
  [3] robot-cover-url           robot-details-url
  [5] robot-owner-name          robot-owner-url
  [7] robot-owner-email         robot-status
  [9] robot-purpose             robot-type
 [11] robot-platform            robot-availability
 [13] robot-exclusion           robot-exclusion-useragent
 [15] robot-noindex             robot-host
 [17] robot-from                robot-useragent
 [19] robot-language            robot-description
 [21] robot-history             robot-environment
 [23] modified-date             modified-by
 [25] robot-nofollow            robot-owner-name2
 [27] robot-owner-url2          robot-owner-email2
 [29] robot-owner-name3         robot-owner-name4
 [31] robot-environment1        robot-environment2
 [33] robot-purpose1            robot-purpose2
 [35] robot-purpose3            robot-platform1
 [37] robot-description1        robot-description2

  and I guess it pads out the columns so every row has every possible
 variable value even if it doesn't exist in the record for that robot.

  Sorted?

 Barry


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] import file formatted RFC-822

2010-04-14 Thread Barry Rowlingson
On Wed, Apr 14, 2010 at 6:20 PM, Sebastian Kruk residuo.so...@gmail.com wrote:
 I have a problem, In a few cases robot-exclusion-useragent have 2 or
 more values, is there a manner to fix it? For example, robot askjeeves
 has three names.

 use 'all=TRUE'?

test data:

foo: 1
bar: 2

foo: 1
foo: 2
bar: 4
baz: 7

 read.dcf(simple.txt,all=TRUE)
   foo bar  baz
11   2 NA
2 1, 2   47

 note that $foo is a *list* in order to handle multiple values in its elements:

  m=read.dcf(simple.txt,all=TRUE)
  m$foo
[[1]]
[1] 1

[[2]]
[1] 1 2

 whereas $bar is a simple vector:

  m$bar
[1] 2 4

 as is $baz (with NA where no baz record exists)

  m$baz
[1] NA  7

sorted?

Barry

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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/when/why do you use it?

2010-04-14 Thread Gabor Grothendieck
x - will usually wind up assigning into the parent or global
environment but since it depends on what is already there the
following are safer:

e - environment()
parent.env(e)$x - 1

globalenv()$x - 2

Typically in cases like this the function that contains the assignment
can be regarded as a method of the object containing x so an OO
approach can be taken such as facilitated by the proto package.  Here
p is defined to be a proto object with method square.x and property x.

 library(proto)
 p - proto(x = 2, square.x = function(.) .$x - .$x^2)
 p$x
[1] 2
 p$square.x()
 p$x
[1] 4



On Wed, Apr 14, 2010 at 11:42 AM, Greg Snow greg.s...@imail.org wrote:
 The - assignment operator is very powerful, but can be dangerous as well.  
 When tempted to use it, look for alternatives first, there may be a better 
 way.  But having said that, I am one of the more guilty people for using it 
 (quite a few of the functions in the TeachingDemos package use -).

 The main use that I see is when you are using a function written by someone 
 else that takes one of your functions as an argument and you want to save 
 information from your function that is not being passed back through the 
 calling function.  For example you may want to trace the calls to your 
 function that is being called by optim, just define your function A which 
 defines within it function B which is to be optimized, A also contains an 
 empty vector to store results in, then A calls optim passing B to it, B uses 
 - to update the vector in A every time that it is called, now A has the 
 results of optim and also a trace of info on all the calls to B.

 - can also be used for package local variables (less evil than globals) 
 where within a package you can call one function to set some things up, then 
 other functions in the package can refer to the variable created to see the 
 setup as well as modifying options local to the package.

 Hope this helps,

 --
 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-boun...@r-
 project.org] On Behalf Of Tal Galili
 Sent: Tuesday, April 13, 2010 8:03 AM
 To: r-help@r-project.org
 Subject: [R] - how/when/why do you use it?

 Hi all,

 Today I came across scoping in the R
 introhttp://cran.r-project.org/doc/manuals/R-intro.html#Scope (after
 reading Robert Gentleman
 fortunehttp://rfortunes.posterous.com/im-always-thrilled-when-people-
 discover-what
 on
 lexical scooping) , and am very curious about the - assignment.

 The manual showed one (very interesting) example for -, which I
 feel I
 understood. What I am still missing is the context of when this can be
 useful.

 So what I would love to read from you are examples (or links to
 examples) on
 when using - can be interesting/useful. What might be the dangers
 of
 using it (it looks easy to loose track of), and any tips you might feel
 like
 sharing.

 Thanks,
 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)
 ---
 ---

       [[alternative HTML version deleted]]

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

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


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


Re: [R] - how/when/why do you use it?

2010-04-14 Thread Steve Lianoglou
 If you think you need '-', think again.  If on reflection you still
 think you need '-', think again.

 Is this in package::fortunes?

+1 for adding that to fortunes ... I remember reading through The R
Inferno and getting a good laugh from several such one liners ...

-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] Factor variables with GAM models

2010-04-14 Thread Gavin Simpson
On Fri, 2010-03-19 at 20:37 -0700, Steven McKinney wrote:
 Hi Noah
 
 GAM models were developed to assess the functional form
 of the relationship of continuous predictor variables to the
 response, so weren't really meant to handle factor variables
 as predictor variables.  GAMs are of the form
 E(Y | X1, X2, ...) = So + S(X1) + S(X2) + ...
 where S(X) is a smooth function of X.

But there is absolutely nothing wrong with including factors in
mgcv::gam - they get expanded into the usually dummy variables depending
on the current contrasts as part of the model set-up routines just like
they do in lm(). Perhaps semiparametric might be a better description of
such a model but at least one implementation of GAMs in R can certainly
handle factors.

I haven't used gam::gam so can't comment on that and the OP doesn't say
which gam he is using.

HTH

G

 Hence you might want to rethink why you'd want a
 factor variable as a predictor variable in a GAM.
 This is why the gam machinery doesn't just do the
 factor conversion to indicator variables as is done in
 lm.
 
 HTH
 
 Steven McKinney
 
 
 From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf 
 Of Noah Silverman [n...@smartmediacorp.com]
 Sent: March 19, 2010 12:54 PM
 To: r-help@r-project.org
 Subject: [R] Factor variables with GAM models
 
 I'm just starting to learn about GAM models.
 
 When using the lm function in R, any factors I have in my data set are
 automatically converted into a series of binomial variables.
 
 For example, if I have a data.frame with a column named color and values
 red, green, blue.   The lm function automatically replaces it with
 3 variables colorred, colorgreen, colorblue which are binomial {0,1}
 
 When I use the gam function, R doesn't do this so I get an error.
 
 1) Is there a way to ask the gam function to do this conversion for me?
 2) If not, is there some other tool or utility to make this data
 transformation easy?
 3) Last option - can I use lm to transform the data and then extract it
 into a new data.frame to then pass to gam?
 
 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.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 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] ur.df ADF Unit Root Test: what is the meaning of phi1 and phi2 test statistic?

2010-04-14 Thread Maximilian Rausch
Hello,

I am using the ur.df function from the {arca} package to run the augmented
Dickey-Fuller unit root test on several time series. However; I do not
understand the econometric interpretation of the the phi1 and phi2
test-statisitc which are output if you choose a trend or drift model. I
looked at the source code for the function but I do not quite understand the
code (which I have included below). Any help would be much appreciate.

Thanks,

Max

if (type == drift) {
result - lm(z.diff ~ z.lag.1 + 1)
phi1.reg - lm(z.diff ~ -1)
phi1 - anova(phi1.reg, result)$F[2]
tau - coef(summary(result))[2, 3]
teststat - as.matrix(t(c(tau, phi1)))
colnames(teststat) - c(tau2, phi1)
}
if (type == trend) {
result - lm(z.diff ~ z.lag.1 + 1 + tt)
phi2.reg - lm(z.diff ~ -1)
phi3.reg - lm(z.diff ~ 1)
phi2 - anova(phi2.reg, result)$F[2]
phi3 - anova(phi3.reg, result)$F[2]
tau - coef(summary(result))[2, 3]
teststat - as.matrix(t(c(tau, phi2, phi3)))
colnames(teststat) - c(tau3, phi2, phi3)

[[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] Sig differences in Loglinear Models for Three-Way Tables

2010-04-14 Thread Sachi Ito
Hi all,

I've been running loglinear models for three-way tables: one of the
variables having three levels, and the other two having two levels each.

An example looks like below:

 yes.no - c(Yes,No)

 switch - c(On,Off)

 att - c(BB,AA,CC)

 L - gl(2,1,12,yes.no)

 T - gl(2,2,12,switch)

 A - gl(3,4,12,att)

 n - c(1136,4998,25,339,305,2752,31,692,251,1677,17,557)

 d.table - data.frame(A,T,L,n)

 d.table

A   T   Ln

1  BB  On Yes 1136

2  BB  On  No 4998

3  BB Off Yes   25

4  BB Off  No  339

5  AA  On Yes  305

6  AA  On  No 2752

7  AA Off Yes   31

8  AA Off  No  692

9  CC  On Yes  251

10 CC  On  No 1677

11 CC Off Yes   17

12 CC Off  No  557



First, I run the independence model and found a poor fit:

 library(MASS)
 loglm(n~A+T+L)
Call:
loglm(formula = n ~ A + T + L)

Statistics:
  X^2 df P( X^2)
Likelihood Ratio 1001.431  70
Pearson  1006.287  70



Thus, I went on and run the two-way association model and found a good fit:

 loglm(n~A:T+A:L+T:L)
Call:
loglm(formula = n ~ A:T + A:L + T:L)

Statistics:
  X^2 df   P( X^2)
Likelihood Ratio 4.827261  2 0.08948981
Pearson  4.680124  2 0.09632168


I compared the independence model (Model1), two-way association model (Model
2), and three-way interaction model (Saturated), and found that the two-way
association model was the most parsimonious one:

 ind - loglm(n~A+T+L)
 twoway - loglm(n~A:T+A:L+T:L)
 anova(ind,twoway)
LR tests for hierarchical log-linear models

Model 1:
 n ~ T + A + L
Model 2:
 n ~ A:L + A:T + T:L

 Deviance df Delta(Dev) Delta(df) P( Delta(Dev)
Model 1   1001.430955  7
Model 2  4.827261  2 996.603694 50.0
Saturated0.00  0   4.827261 20.08949


By running a Chi-square test, I found that all of the three two-way
associations are significant.
 drop1(twoway,test=Chisq)
Single term deletions

Model:
n ~ A:T + A:L + T:L
   DfAICLRT   Pr(Chi)
none 24.83
A:T 2 645.91 625.08  2.2e-16 ***
A:L 2 152.93 132.10  2.2e-16 ***
T:L 1 143.60 120.77  2.2e-16 ***
---
Signif. codes:  0 ¡***¢ 0.001 ¡**¢ 0.01 ¡*¢ 0.05 ¡.¢ 0.1 ¡ ¢ 1


Then, I got the coefficients:
 coef(twoway)
$`(Intercept)`
[1] 5.866527

$A
 BB  AA  CC
 0.27277069 -0.01475892 -0.25801177

$T
   On   Off
 1.156143 -1.156143

$L
  YesNo
-1.225228  1.225228

$A.T
T
AOnOff
  BB  0.4809533 -0.4809533
  AA -0.1783651  0.1783651
  CC -0.3025882  0.3025882

$A.L
L
AYes  No
  BB  0.19166429 -0.19166429
  AA -0.15632604  0.15632604
  CC -0.03533825  0.03533825

$T.L
 L
TYes No
  On   0.2933774 -0.2933774
  Off -0.2933774  0.2933774


I, then, hand-calculated odds ratio for A x T, A x L, and T x L.

T x L:
*èTL *=* e4(.293) *= 3.23

A x L:
*èAL(BB vs. AA) *= *e 2(.19166) + 2(.1563) = *2.01

*èAL(BB vs. CC) *= *e 2(.19166) + 2(.03533) = *1.57

A x T:

*èAT(BB vs. AA) *= *e 2(.48095) + 2(.17837) = 3.74*
*
*
*èAT(BB vs. CC) = e 2(.48095) + 2(.30259) = 4.79 *



Now, I'd like to know if BB and AA (or BB and CC) are significantly
different from each other (i.e., the odds of BB to be 2.01 times larger than
AA is significant) and the differences between BB and CC are significant
(i.e., the odds of BB to be 1.6 times bigger is significant) etc.


I'd really appreciate if someone can answer this question!

Thank you,
Sachi

[[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] Running cumulative sums in matrices

2010-04-14 Thread Greg Snow
Does this do what you want?

m1 - cbind(1:5,1:5,1:5)

m2 - m1
for(i in 2:ncol(m1)){
m2[,i] - apply(m1[,1:i],1,sum)
}
m2

ut - diag( ncol(m1) )
ut[upper.tri(ut)] - 1

m3 - m1 %*% ut
m3

all.equal(m2,m3)


hope this helps,

-- 
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-boun...@r-
 project.org] On Behalf Of Eleni Rapsomaniki
 Sent: Wednesday, April 14, 2010 6:18 AM
 To: r-help@r-project.org
 Subject: [R] Running cumulative sums in matrices
 
 
 Dear R-helpers,
 
 I have a huge data-set so need to avoid for loops as much as possible.
 Can someone think how I can compute the result in the following example
 (that uses a for-loop) using some version of apply instead (or any
 other similarly super-efficient function)?
 
 example:
 #Suppose a matrix:
 m1=cbind(1:5,1:5,1:5)
 
 #The aim is to create a new matrix with every column containing the
 cumulative sum of all previous columns.
 m2=m1
 for(i in 2:ncol(m1)){
 m2[,i]=apply(m1[,1:i],1,sum)
 }
 m2
 
 Many thanks in advance
 
 Eleni Rapsomaniki
 
 Research Associate
 Strangeways Research Laboratory
 Department of Public Health and Primary Care
 University of Cambridge
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] NMDS Ordination Graphics Problem

2010-04-14 Thread Gavin Simpson
On Mon, 2010-04-05 at 09:58 -0800, Trey wrote:
 Dr. Stevens,

Hmm, did you get the wrong address there ;-)

As Michael Denslow has mentioned, the way to handle this sort of
customised plotting at the moment in vegan is to build the plot up by
hand. Michael's response earlier showed you how to do it with the
in-built data set. Here's how I'd do it (essentially the same thing),
using Stephen Sefick's conveniently dput()ed version of your example
data:

## something to hold the data
dat - (structure(list(a = c(1L, 12L, 2L, 0L, 0L, 13L), b = c(4L, 17L,
5L, 2L, 1L, 15L), c = c(7L, 6L, 8L, 4L, 4L, 19L), d = c(9L, 2L,
1L, 7L, 6L, 10L), e = c(2L, 3L, 3L, 2L, 9L, 8L), f = c(5L, 7L,
2L, 1L, 10L, 9L)), .Names = c(a, b, c, d, e, f), class =
data.frame, row.names = c(1i,
2i, 3i, 1c, 2c, 3c)))

## to hold the factor for whether a site is infested or control
tlabs - c(infested,control)
treat - factor(rep(tlabs, each = 3), levels = tlabs)
## setting the levels explicitly insures R doesn't reorder them
alphabetically

## sanity check:
all.equal(length(treat), nrow(dat))

## do the analysis
p - metaMDS(x)

## set-up the plotting region:
plot(p, display = sites, type = n)

## now add the points, coding the infested/control by colour and pch
## this is where I differ slightly from the example Michael gave
## as here the user can specify the cols, pchs etc required
cols - c(red,navy) ## chose what you want
pchs - c(3,16) ## ditto choose what you want
points(p, display = sites, pch = pchs[treat], col = cols[treat])
## add a legend:
legend(topleft, legend = levels(treat), pch = pchs, col = cols, bty =
n)

Notice how I've done the indexing there. Remember treat is a factor with
more than two observations in it. In the points call above we rely on
the factor being coded internally as 1,2,3,...,k for the k levels in the
factor. To see what is actually being passed to col in the above call,
do:

cols[treat]

So we've only specified our two colours and then used the treatment
variable created earlier to do the right thing for us.

If you have more toruble with vegan, try posting on the R SIG Ecology
list (as that's where Jari Oksanen tends to hang out rather than R-Help)
or on the R-Forge forum for Vegan:

http://r-forge.r-project.org/forum/forum.php?forum_id=194

HTH

G

 
 Hi, my name is Trey Scott, and I'm a grad student of Brian McCarthy's.  He
 referred me to you because of your expertise in handling complex R problems. 
 We were hoping you could help us solve a nagging problem that is prohibiting
 me from producing graphicl output.
 
 Here is a simple mock-up of the matrix I'm using
 
 a b c d e f
 1i  1 4 7 9 2 5
 2i  12   176 2 3 7
 3i   25 8 1 3 2
 1c  02 4 7 2 1
 2c  01 4 6 9 10 
 3c  13   15   19   108 9
 
 Where:  1i-3i are infested sites, and 1c-3c are control sites.  A-F are
 species found at each site.  I have several of these ordinations to perform
 on different variables (BA, density, RIV, cover, etc..., all in different
 matrices).  I'm running NMDS (metaMDS) ordinations on each matrices, and
 producing ordination graphs for each cloud of points.  The problem I have is
 that I cannot devise a way to split the cloud of points into infested and
 control so that I can deduce any significant groupings.  A simple difference
 in symbols/color (Ex. gray triangles for infested, black circles for
 control) would do.  Also, I understand the use of pch/col/cex, I just need
 to apply them to the split.
 
 So:
 
 +   How would I split these out in R after I run the metaMDS in vegan?
 +   What code would be necessary to bring this about?
 
 McCarthy and I are at the end of our preoverbial rope on this; nothing has
 worked.

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


Re: [R] vegan (ordisurf): R² for smoothed surf aces

2010-04-14 Thread Gavin Simpson
On Tue, 2010-04-13 at 15:02 +0200, Kim Vanselow wrote:
 Dear r-helpers,
 I just read in an article by Virtanen et al. (2006) where
 vegetation-environment relationships  are studied by fitting smoothed
 surfaces on an NMDS ordination using GAMs (Wood 2000). The authors
 describe, that they used R² as goodness-of-fit statistic, which they
 compare to the R² of fitted vectors. Calculations were carried out
 using the package vegan (Oksanen).
 I know that I can fit vectors onto ordinations with the function
 envfit. The R² is listed in the output table. I also know that GAMs
 are implemented in vegan by the function ordisurf. But how can I get
 an R² from this function.

?ordisurf and see the Value section. ordisurf returns the mgcv::gam
object describing the model fit. If you assign the object returned by
ordisurf and run summary on it (as you would any other mgcv::gam model),
you'll get the R^2(adj). Here's an example:

data(varespec)
data(varechem)
library(MASS)
vare.dist - vegdist(varespec)
vare.mds - isoMDS(vare.dist)
## capture return value
mod - with(varechem, ordisurf(vare.mds, Baresoil, bubble = 5))
## summary
summary(mod)

You can then pull apart the returned object ('mod') if you need to get
at the R^2 for subsequent computations, storage etc rather than just
display it.

HTH

G

 
 Thanks in advance,
 Kim 
 
 -- 
 GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
 
 

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


Re: [R] GAMM : how to use a smoother for some levels of a variable, and a linear effect for other levels?

2010-04-14 Thread Gavin Simpson
On Wed, 2010-04-14 at 10:03 +0200, JANSEN, Ivy wrote:
 Hi, 
  
 I was reading the book on Mixed Effects Models and Extensions in
 Ecology with R by Zuur et al. 
 In Section 6.2, an example is discussed where a gamm-model is fitted,
 with a smoother for time, which differs for each value of ID (4
 different bird species). In earlier versions of R, the following code
 was used
  
 BM2-gamm(Birds~Rain+ID+
s(Time,by=as.numeric(ID==Stilt.Oahu))+
s(Time,by=as.numeric(ID==Stilt.Maui))+
s(Time,by=as.numeric(ID==Coot.Oahu))+
s(Time,by=as.numeric(ID==Coot.Maui)),
  correlation=corAR1(form=~Time |ID ),
  weights=varIdent(form=~1|ID))
  
 However, in the current version of R, this does not work anymore, and
 should be changed into 
  
 BM2-gamm(Birds~Rain+ID+
s(Time,by=ID),
  correlation=corAR1(form=~Time |ID ),
  weights=varIdent(form=~1|ID))
  
 It turns out that 2 of the 4 smoothers have estimated degrees of freedom
 of 1, so a linear effect would be sufficient. 
 Now my question is how I need to change the code in order to have a time
 smoother for ID=Coot.Oahu and ID=Coot.Maui, and a linear time effect for
 ID=Stilt.Oahu and ID=Stilt.Maui. With the old R-code, this seems
 trivial, but I don't have any idea how to do it in the newest R-version
 (interactions with a dummy variable do not work in gamm).

Isn't a smooth that uses 1 df == to a linear function? So doesn't the
current model already do what you want? You don't need to refit it with
two smooths and two linear parametric terms as the two models should be
effectively equivalent anyway.

Or have I misunderstood your question?

HTH

G

  
 Thanks,
 Ivy
 
 Druk dit bericht a.u.b. niet onnodig af.
 Please do not print this message unnecessarily.
 
 Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
 en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd 
 is
 door een geldig ondertekend document. The views expressed in  this message 
 and any annex are purely those of the writer and may not be regarded as 
 stating 
 an official position of INBO, as long as the message is not confirmed by a 
 duly 
 signed document.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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. 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.


Re: [R] what is the intercept of a two-way anova model without interaction term?

2010-04-14 Thread Dennis Murphy
Hi:

Perhaps this will clarify some things:

 model.matrix(m)
  (Intercept) factor1B factor1C factor2t2 factor2t3
1   100 0 0
2   110 0 0
3   101 0 0
4   100 1 0
5   110 1 0
6   101 1 0
7   100 0 1
8   110 0 1
9   101 0 1

Now tack on the predicted values from the model:

 cbind(model.matrix(m), predict(m))
  (Intercept) factor1B factor1C factor2t2 factor2t3
1   100 0 0  67.65502
2   110 0 0 134.24682
3   101 0 0  83.81768
4   100 1 0  52.71252
5   110 1 0 119.30431
6   101 1 0  68.87518
7   100 0 1  30.66079
8   110 0 1  97.25259
9   101 0 1  46.82345

In the first row, the subject is neither at levels B nor C of factor1, nor
at level t2 of factor2. At what levels of factor1 and factor2 must
this subject be? You'll see a pattern in how the predicted values
are obtained from the level combinations in each observation, the
model and its estimated coefficients. In the process, you'll learn how
treatment contrasts work. Since I smell homework, this is as far
as I'll go.

HTH,
Dennis

On Wed, Apr 14, 2010 at 10:13 AM, Xiaokuan Wei weixiaok...@yahoo.comwrote:

 Dear list,

 I have a question regarding the meaning of intercept term in a two-way
 anova model without interaction term.

 for example (let's assume there is no interaction between factor1 and
 factor2) :

  df
 valfactor1 factor2
 1  48.61533   A  t1
 2 171.13535   B  t1
 3  65.96884   C  t1
 4  63.71222   A  t2
 5  80.22049   B  t2
 6  96.95929   C  t2
 7  38.70078   A  t3
 8  99.44787   B  t3
 9  36.58818   C  t3

 the summary of regression :

  summary(m)
 Call:
 lm(formula = val ~ factor1 + factor2, data = df)
 Residuals:
   1   2   3   4   5   6   7   8   9
 -19.040  36.889 -17.849  11.000 -39.084  28.084   8.040   2.195 -10.235
 Coefficients:
 Estimate Std. Error t value Pr(|t|)
 (Intercept)67.66  25.42   2.661   0.0563 .
 factor1B   66.59  27.85   2.391   0.0751 .
 factor1C   16.16  27.85   0.580   0.5928
 factor2t2 -14.94  27.85  -0.537   0.6200
 factor2t3 -36.99  27.85  -1.328   0.2548
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 Residual standard error: 34.11 on 4 degrees of freedom
 Multiple R-squared: 0.6669, Adjusted R-squared: 0.3338
 F-statistic: 2.002 on 4 and 4 DF,  p-value: 0.2589


 This is contrast treatment, and my question is what the intercept (here is
 67.66) represent for?

 Thank you.


 Xiaokuan



[[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] Import ASCII data using a .sas program

2010-04-14 Thread John Fox
Dear Don,

What read.fwf() needs are the field widths. I think that the following will
do what you want:

 strings - scan(what=)
1: perstat1 $1-2
3: linenum $3-4
5: I_wave1 $5-5
7: bnocost1 $6-10
9: bnosta1 $11-12
11: 
Read 10 items

 (fields - matrix(as.numeric(unlist(strsplit(
+ gsub(\\$, , grep(^\\$, strings, value=TRUE)), -))), 
+ ncol=2, byrow=TRUE))
 [,1] [,2]
[1,]12
[2,]34
[3,]55
[4,]6   10
[5,]   11   12
 
 (widths - fields[,2] - fields[,1] + 1)
[1] 2 2 1 5 2

I hope this helps,
 John


John Fox
Senator William McMaster 
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
 Behalf Of Donald Catanzaro, PhD
 Sent: April-14-10 1:02 PM
 To: r-help@r-project.org
 Subject: Re: [R] Import ASCII data using a .sas program
 
 Good Day,
 
 I have several ASCII data files that I would like to import into R.
 They all have a SAS import file which is used to bring the data into SAS
 and I am hoping to use this to bring the data into R.  There are lots of
 variables involved and the ASCII data file is 2308 columns long so I
 would certainly prefer to figure out a smart way of converting the data
 to R.
 
 The ASCII data is a long stream of numbers (no field separators or
 delimiters) while the SAS import file looks like:
 
 libname mine 'c:\';
 data mine.fh4;
 infile 'd:\fh4.txt' lrecl=2309;
 input
 perstat1 $1-2
 linenum $3-4
 I_wave1 $5-5
 bnocost1 $6-10
 bnosta1 $11-12
 
 So SAS uses the position of the ASCII character to determine what
 variable the data should be in while the SCAN or the READ. FWF function
 of R uses the width of the column.
 
 Does anyway have a smart and/or automated way of moving my ASCII data
 into R using this .SAS program  ?
 
 --
 -Don
 
 Don Catanzaro, PhD
 Landscape Ecologist
 dgcatanz...@gmail.com
 16144 Sigmond Lane
 Lowell, AR 72745
 479-751-3616
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Error: could not find function tsts tradesys package

2010-04-14 Thread dbonneau

Thank you so much for your reply. On the first page of the paper, there are
logics which I typed 
 library(tradesys) 
 library(TTR)
 data(spx)
 tail(spx)

,and it runs smoothly.
But it gives me an error at 
x - tsts(spx)

Thanks, db
-- 
View this message in context: 
http://n4.nabble.com/Error-could-not-find-function-tsts-tradesys-package-tp1839233p1840069.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] svm of e1071 package

2010-04-14 Thread Shyamasree Saha [shs]
Hello Steve, 
Thanks for your reply. yes, i converted input matrix to a sparse matrix (via 
SparseMatrix). rbind is fine for our case as anyway we have to do it. So, 
instead of using rbind on dense matrix and convert the whole matrix at the end, 
we take convert each chunk and add it to the big one. No parameter tweaking was 
necessary. But as you have mentioned, I will like to try read.matrix.csr and 
write.matrix.csr . this can save lot of our time and resources. 

Thanks again for your help.

Regards
Shyama

From: Steve Lianoglou [mailinglist.honey...@gmail.com]
Sent: Wednesday, April 14, 2010 2:49 PM
To: Shyamasree Saha [shs]
Cc: r help
Subject: Re: [R] svm of e1071 package

Hi Shyama,

On Tue, Apr 13, 2010 at 10:40 AM, Shyamasree Saha [shs] s...@aber.ac.uk wrote:
 Dear Steve,

 We have finally managed to run our code. Sparse matrix is helping a lot (I 
 should say without matrix.csr, we would not be able to do it). This time it 
 is taking very small amount of memory while running svm, but we could not use 
 as.matrix.csr directly on our huge data. we had to divide the data in small 
 chunk. we created matrix.csr from those small chunk, removed our original 
 object, loaded next chunk and used rbind to put all of them together. we need 
 to be very careful how much data we load at a time. Thanks again for you kind 
 help.

This is great news :-)

So, just to recap -- is the only thing that you did to get this to
work is to convert your input matrix to a sparse matrix (via SparseM)?
No parameter tweaking necessary?

Would an alternative approach to creating the sparse matrix be more
helpful? You can, for instance, create the entire sparse matrix in one
shot, like:

R m - as.matrix.csr(0, nrow=10, ncol=10)

(with appropriate numbers for your nrow,ncol params)

Then you can load subsets of your data into it and skipping the
chunked-`rbing` strategy .. is that easier?

Also, the e1071 package has read.matrix.csr and write.matrix.csr
functinos that might help facilitate loading/saving your data matrices
in the future.

-steve


 Regards
 Shyama
 
 From: Steve Lianoglou [mailinglist.honey...@gmail.com]
 Sent: Wednesday, April 07, 2010 4:00 PM
 To: Shyamasree Saha [shs]
 Cc: r help
 Subject: Re: [R] svm of e1071 package

 Hi,

 On Tue, Apr 6, 2010 at 7:16 PM, Shyamasree Saha [shs] s...@aber.ac.uk wrote:
 Dear Steve,

 Thanks again for your help and reply. your help was very useful and gave us 
 some options. We will follow your suggestions and let you know about it.

 No problem ... yeah, please write back when you figure out what's up
 (or hit more roadblocks), I'd be curious to know what the solution is.

 Thanks,
 -steve


 Regards,
 shyama
 
 From: Steve Lianoglou [mailinglist.honey...@gmail.com]
 Sent: Tuesday, April 06, 2010 9:40 PM
 To: Shyamasree Saha [shs]
 Cc: r help
 Subject: Re: [R] svm of e1071 package

 Hi Shyama,

 Don't forget to CC the r-help list in your discussions so that there
 are more eyes on this problem, and others might potentially benefit
 from discussion.

 Comments in line.

 On Tue, Apr 6, 2010 at 4:06 PM, Shyamasree Saha [shs] s...@aber.ac.uk 
 wrote:
 Dear Steve,

 Thanks a lot for your reply. As you have suggested kernlab and SparseM 
 packages, we have now installed it and reading about these packages. I am 
 trying to answer your questions. I have also added a bit of code. Please 
 let me know whether you need to know more and what is your suggestions.

 Thanks again for your help.

 Regards,
 Shyamasree

 R .Machine$sizeof.pointer ## it should be 8
 Yes, it is indeed 8.

 OK

 * What type of kernel are you using? Have you tried different ones?
 Just tried the linear kernel, haven't tried with other kernels.

 OK, let's stick with that for now.

 * Are you doing classification or regression?
 We are doing multi-class classification. There are 11 classes.

 Is it any better if you just do 1-vs-all?
 Also (from your code at the end of the email) what if you train the
 model with `probability=FALSE`?

 * Is your data/feature matrix sparse? If so, are you passing libsvm a
 SparseM matrix?
 Yes, the feature matrix is indeed very sparse. Just passing a matrix
 at the moment.
 Not sure how to define it as SparseM matrix.

 R library(SparseM)
 R ?as.matrix.csr

 * Have you tried playing with some of the params in the svm call, like
 the values for tolerance, epsilon, cost/nu/etc.
 No, have not played with these at all. What do you recommend?

 Try to increase (I think (maybe decrease??)) the tolerance from its
 default value. Moving this in one direction or the other allows the
 solver to converge to a less-precise solution -- haven't read the
 source in a while, though, so test it.

 * Try an even smaller subset of your data ( 1.4 GB)
 It works fine with a much smaller subset but have not tried with
 intermediate sizes.

 OK

 Can you give an idea of 

[R] Selecting derivative order penalty for thin plate spline regression (GAM - mgcv)

2010-04-14 Thread Christos Argyropoulos

Hi, 

 

I am using GAMs (package mgcv) to smooth event rates in a penalized regression 
setting and I was wondering if/how one can

select the order of the derivative penalty.

 

For my particular problem the order of the penalty (parameter m inside the 
s terms of the formula argument) appears to 

have a larger effect on the AIC/deviance of the estimated model than the number 
(or even the location!) of the knots for the covariate

of interest. In particular, the estimated smooth changes shape from a linear 
(default m (=2) value for a TP smooth or a P-spline

smooth) with a edf of 2.06 to a non-linear one with a edf of 4.8-5.1 when the 
m is raised to 3. There are no changes in the 

estimate shape of the smooth when I tried higher values of m and different  
bases (thin plate, p-spline).

 

The overall significance of the smooth term changes, but is 0.05 in both 
cases, however the interpretation afforded by the

shapes of the smooths are different. 

 

Smoothing the same dataset with a different approach to GAMs (BayesX) results 
in shapes that are more like the ones I have been getting with m=3 rather than 
m=2 (I have not tried the conditional autoregressive regressions of WinBUGS 
yet). 

Any suggestion on how to proceed to test the optimal order of the penalty would 
be appreciated. The 2 approaches I am thinking of trying are:

a) use un-penalized smoothing regressions and comparing the 2 models with ANOVA

b) First, fit the m=2 model and extract the smoothing parameters of all other 
smooth terms from that model. Second, fit a model in which the smooth of the 
covariate of interest is set to m=3 , fixing the parameters of all other 
smooth terms appearing in the model statement to the values estimated in the 
first step. Then I could compare the (m=2) v.s. (m=3) models with ANOVA as the 
2 models are properly nested within each other.

 

Any other ideas?

 

Sincerely, 

 

Christos Argyropoulos

University of Pittsburgh

 

 
  
_
Hotmail: Trusted email with powerful SPAM protection.

[[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 draw multiple vertical bands

2010-04-14 Thread senne
hi R gurus

I saw some graphs with vertical band like this one:

http://pragcap.com/wp-content/uploads/2010/04/GS.png

how to draw the blue band in R, can't find any clue to do this,any ideas?

thanks in advance

[[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] envelope in spatstat

2010-04-14 Thread T.O. Richardson

Hi R users,

This query is regarding the use of the 'envelope' function in Spatstat.

My data can be represented as a point process with CONTINUOUS marks:

points - ppp(x=x,y=y, marks=m, window= wind)

However the marks are alignments (lines), and so have to be treated 
differently to normal scalar marks. Hence to create a mcf object with the 
appropriate test function for alignment marks, I input 'func' (below) 
suggested by Stoyan  Penttinen (1989):


func - function(m1,m2) { sin(abs(m1-m2))^2} 
mcf - markcorr(points, func, normalise = TRUE, method=density)  

So far, so good. However, usinf 'envelope' and 'rlabel' I would like to 
check if the pattern in the data is  lost when randomly relabeling the mark 
for each point. If the test function, 'func' were the usual G(m1,m2)=m1*m2, 
then the following would work:


E - envelope(points,  markcorr, nsim=20, 
simulate=expression(rlabel(points)))


Howeve, in the above 'markcorr' calculates  G(m1,m2)=m1*m2  by default. So 
need to specify the test function to be G(m1,m2)= sin(abs(m1-m2))^2.


According to the spatstat manual (p177), I may need to 'cook up' a specific 
function, like this:


Kdif = function(X, ..., i) {
 Kidot = Kdot(X, ..., i = i)
 K = Kest(X, ...)
 dif = eval.fv(Kidot - K)
 return(dif)
}
E = envelope(lansing, Kdif, i='blackoak', 
simulate=expression(rlabel(lansing)))



So how do I tell 'envelope' that I want to specify the mark correlation 
test function ??



Many thanks in advance!
T






---
Dept. of Maths and Stats, UWE and Ant Lab, Bristol

Room B79.
SoBS, Woodland Rd. BS8 1UG.
+44 (0)117 928 8443

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Conflict plot.circular and layout() using different column width of the layout matrix

2010-04-14 Thread Daniela Buesser
Hi

I am trying to make a figure with several subfigure using the layout(). The 
subfigures include circular plots (package:circular). When I use different 
widths of the columns (layout(matrix(1:6, 2,3), width=c(1,1.5,1))) the circular 
plots in the first row have an elliptic and unpredictible shape but are normal 
in the second row. When the widths of the columns are equal the problem does 
not occur. The same problems occurs when the heights of the subfigure rows are 
different. Is this a bug? Any suggestions how to solve the problem? Below is an 
example to outline the problem.
Many thanks,
Daniela

library(circular)
layout(matrix(1:6, 2,3), width=c(1,1.5,1))
layout.show(6)
angles - circular(pi)
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))

Without different column widths there it works fine.
library(circular)
layout(matrix(1:6, 2,3))
layout.show(6)
angles - circular(pi)
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))
plot(angles, stack=T, bins=360, col=green, xlim=c(-1,1), ylim=c(-1,1))





-- 
Sicherer, schneller und einfacher. Die aktuellen Internet-Browser -
jetzt kostenlos herunterladen! http://portal.gmx.net/de/go/chbrowser

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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: could not find function tsts tradesys package

2010-04-14 Thread Erik Iverson
You need to take this up with the package authors.  After I install 
tradesys, and type vignette(tradesys), I get a PDF that no longer 
contains the example in the PDF you reference from the web.  That 
particular version of the PDF that you reference is probably no longer 
relevant to the package.  Those functions are no longer distributed with 
tradesys, it appears.




dbonneau wrote:

Thank you so much for your reply. On the first page of the paper, there are
logics which I typed 
library(tradesys) 
library(TTR)

data(spx)
tail(spx)


,and it runs smoothly.
But it gives me an error at 
x - tsts(spx)


Thanks, db


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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: could not find function tsts tradesys package

2010-04-14 Thread Peter Ehlers

I think that this package is very much in the early stages
of development. It may be that the tsts function is still
just a gleam in the eyes of the developers. The paper that
you cite may be ahead of code development.

 -Peter Ehlers

On 2010-04-14 10:20, dbonneau wrote:


Thank you so much for your reply. On the first page of the paper, there are
logics which I typed

library(tradesys)
library(TTR)
data(spx)
tail(spx)


,and it runs smoothly.
But it gives me an error at
x- tsts(spx)

Thanks, db


--
Peter Ehlers
University of Calgary

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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: could not find function tsts tradesys package

2010-04-14 Thread Erik Iverson



Peter Ehlers wrote:

I think that this package is very much in the early stages
of development. It may be that the tsts function is still
just a gleam in the eyes of the developers. The paper that
you cite may be ahead of code development.



Yes, in my reply I assumed behind, but 'ahead' is certainly possible, too!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] curve

2010-04-14 Thread Dwayne Blind
Dear R users,

How can I use curve with a function of two variables ?

Thank you very much,
Dwayne

[[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] liner regression for multiple keys

2010-04-14 Thread Ben Bolker
newbie_2010 girishbogu at gmail.com writes:

 a1 is the first key in input. second column is x-axis and 3rd is y-axis and
 4th is its corresponding key.
 Now for every key in 1st column I would like to calculate LR that gives p
 value. I tried to manage with a single key. But my problem is that How could
 I manage multiple keys in input.
 Thanx in advance
 

 something like:

library(nlme)
fm - lmList(y~x|key,data=...) 
get.pval - function(z) {
  x - summary(z)
  pf(x$fstatistic[1L], 
x$fstatistic[2L], x$fstatistic[3L], lower.tail = FALSE)
}
sapply(fm,get.pval)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] curve

2010-04-14 Thread Ben Bolker
Dwayne Blind dwayneblind at gmail.com writes:

 How can I use curve with a function of two variables ?

see curve3d in the emdbook package.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Sig differences in Loglinear Models for Three-Way Tables

2010-04-14 Thread Charles C. Berry


See comments in line.

On Wed, 14 Apr 2010, Sachi Ito wrote:


Hi all,

I've been running loglinear models for three-way tables: one of the
variables having three levels, and the other two having two levels each.

An example looks like below:


yes.no - c(Yes,No)



switch - c(On,Off)



att - c(BB,AA,CC)



L - gl(2,1,12,yes.no)



T - gl(2,2,12,switch)



A - gl(3,4,12,att)



n - c(1136,4998,25,339,305,2752,31,692,251,1677,17,557)



d.table - data.frame(A,T,L,n)



d.table


   A   T   Ln

1  BB  On Yes 1136

2  BB  On  No 4998

3  BB Off Yes   25

4  BB Off  No  339

5  AA  On Yes  305

6  AA  On  No 2752

7  AA Off Yes   31

8  AA Off  No  692

9  CC  On Yes  251

10 CC  On  No 1677

11 CC Off Yes   17

12 CC Off  No  557



First, I run the independence model and found a poor fit:


library(MASS)
loglm(n~A+T+L)

Call:
loglm(formula = n ~ A + T + L)

Statistics:
 X^2 df P( X^2)
Likelihood Ratio 1001.431  70
Pearson  1006.287  70



Thus, I went on and run the two-way association model and found a good fit:


loglm(n~A:T+A:L+T:L)

Call:
loglm(formula = n ~ A:T + A:L + T:L)

Statistics:
 X^2 df   P( X^2)
Likelihood Ratio 4.827261  2 0.08948981
Pearson  4.680124  2 0.09632168


I compared the independence model (Model1), two-way association model (Model
2), and three-way interaction model (Saturated), and found that the two-way
association model was the most parsimonious one:


ind - loglm(n~A+T+L)
twoway - loglm(n~A:T+A:L+T:L)
anova(ind,twoway)

LR tests for hierarchical log-linear models

Model 1:
n ~ T + A + L
Model 2:
n ~ A:L + A:T + T:L

Deviance df Delta(Dev) Delta(df) P( Delta(Dev)
Model 1   1001.430955  7
Model 2  4.827261  2 996.603694 50.0
Saturated0.00  0   4.827261 20.08949


By running a Chi-square test, I found that all of the three two-way
associations are significant.

drop1(twoway,test=Chisq)

Single term deletions

Model:
n ~ A:T + A:L + T:L
  DfAICLRT   Pr(Chi)
none 24.83
A:T 2 645.91 625.08  2.2e-16 ***
A:L 2 152.93 132.10  2.2e-16 ***
T:L 1 143.60 120.77  2.2e-16 ***
---
Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1


Then, I got the coefficients:

coef(twoway)

$`(Intercept)`
[1] 5.866527

$A
BB  AA  CC
0.27277069 -0.01475892 -0.25801177

$T
  On   Off
1.156143 -1.156143

$L
 YesNo
-1.225228  1.225228

$A.T
   T
AOnOff
 BB  0.4809533 -0.4809533
 AA -0.1783651  0.1783651
 CC -0.3025882  0.3025882

$A.L
   L
AYes  No
 BB  0.19166429 -0.19166429
 AA -0.15632604  0.15632604
 CC -0.03533825  0.03533825

$T.L
L
TYes No
 On   0.2933774 -0.2933774
 Off -0.2933774  0.2933774


I, then, hand-calculated odds ratio for A x T, A x L, and T x L.

T x L:
*?TL *=* e4(.293) *= 3.23

A x L:
*?AL(BB vs. AA) *= *e 2(.19166) + 2(.1563) = *2.01

*?AL(BB vs. CC) *= *e 2(.19166) + 2(.03533) = *1.57

A x T:

*?AT(BB vs. AA) *= *e 2(.48095) + 2(.17837) = 3.74*
*
*
*?AT(BB vs. CC) = e 2(.48095) + 2(.30259) = 4.79 *



Now, I'd like to know if BB and AA (or BB and CC) are significantly
different from each other (i.e., the odds of BB to be 2.01 times larger than
AA is significant) and the differences between BB and CC are significant
(i.e., the odds of BB to be 1.6 times bigger is significant) etc.



It will be easier to answer this if you formulate the problem as a 
surrogate Poisson regression via glm().


The relationship between the surrogate Poisson and the loglinear model is 
well known. See VR or McCullagh and Nelder, for example.


Then the hypotheses about odds ratios become hypotheses about 
coefficients, which you can test via summary(), or linear combinations of 
coefficients, which you can test with the pieces that vcov() and coef() 
provide.


HTH,

Chuck




I'd really appreciate if someone can answer this question!

Thank you,
Sachi

[[alternative HTML version deleted]]




Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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


Re: [R] R package documentation

2010-04-14 Thread David Scott

Sébastien Bihorel wrote:

Thanks Tobias,

If there is no automated way to combine both documents, I will stack them
manually... that will likely cause some problems with page numbering tough.

Sebastien



There was a thread a while back (this year) about someone who wanted to 
incorporate his package manual in his thesis. A solution was offered to 
this as I recall and it seems like the same problem to me.


What you need is the LaTeX that comes out of the package check. Just add 
it to your vignette LaTeX and that should do the trick.


David

_
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

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


Re: [R] Ranking correlation with R

2010-04-14 Thread David Nemer
Hello Guys, thank you all very much for the help!

Sorry for my total lack of knowledge in R... so I did the correlation.. and
got these results:

 cor(A, C, method = spearman)
[1] 0.4922165
 cor(B, C, method = spearman)
[1] 0.1922412
 cor(A, B, method = spearman)
 [1] -0.00889328

I don't know how to interpret them... so the correlation is good when it is
really close to 1 or to 0? What about negative correlation??

Cheers,
--
David Nemer


On Sat, Apr 10, 2010 at 2:58 PM, Gabor Grothendieck ggrothendi...@gmail.com
 wrote:

 Try this:

  A - c(file1.java, file3.java, file2.java)
  B - c(file2.java, file4.java, file1.java)
  cor(A, B, method = spearman)
 [1] 0.5


 On Fri, Apr 9, 2010 at 11:22 AM, David Nemer davidne...@gmail.com wrote:
  Hey Everyone,
 
  Im fresh new in R, and Im supposed to write a code to give me a
 correlation
  between two rankings. So I have two ranking lists, which contain file
 names,
  e.g.:
 
  Ranking list 1:
  file1.java
  file3.java
  file2.java
 
  Ranking list 2:
  fiile2.java
  file4.java
  file1.java
 
  I need to see how much are these two ranking lists are alike, get a
  correlation between them. I dont even know where to start. Can anyone
 bring
  me some light or tips? Thank you in advance.
 
  Cheers,
  --
  David Nemer
 
 [[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] how to draw multiple vertical bands

2010-04-14 Thread jim holtman
?rect

On Wed, Apr 14, 2010 at 10:36 AM, senne wase...@gmail.com wrote:

 hi R gurus

 I saw some graphs with vertical band like this one:

 http://pragcap.com/wp-content/uploads/2010/04/GS.png

 how to draw the blue band in R, can't find any clue to do this,any ideas?

 thanks in advance

[[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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] filled.contour ON TOP of a base map

2010-04-14 Thread Víctor Homar Santaner
Anyone?


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


  1   2   >