[R] post hoc comparisons of the interaction of factors

2013-02-13 Thread Vasillis Papathanasiou

Hi everyone, I'm running the following analysis for two meadows and two 
periods. I need to get the post hoc comparisons for the combination of the two 
factors (meadowA*PeriodA, meadowA*PeriodB, meadowB*PeriodB, meadowB*PeriodA). I 
use the function glht glht(model, linfct=mcp(Meadow="Tukey") in order to get 
results just for the meadow factor. However I need to get the results for both 
Meadow*Period. Does anyone know how to do this? Thank you in advance, Vasillis 
lme(Yield~1+Meadow*Period, random=~1|Site/Area/Quadrate, control = 
lmeControl(   maxIter = 1, # Of course   msMaxIter = 5000, # it 
helps   niterEM = 500, # to be   msMaxEval = 500, # patient!   
msVerbose = TRUE, # Loquacity ...   opt = "optim" # Optional, and   # 
often useful   ),data=Data, weights=varPower(), 
correlation=corRatio(form=~1|Site/Area/Quadrate,nugget=T), 
method="ML")->model

Vasillis Papathanasiou,
Marine SciencesPalaion Fokon 35-37Thessaloniki, 54454Greecetel:+306945874855
  
[[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] recovering from errors with lapply()

2013-02-13 Thread Milan Bouchet-Valat
Le mardi 12 février 2013 à 15:41 -0600, Andrew Barr a écrit :
> Hi all,
> 
> I am searching for a way to recover results from lapply() when one or more
> values returns an error.  I have a written a function that uses tryCatch()
> to recover from errors. Here is a very simple example of such a function.
> 
> divideBy2<-function(X){
>   result<-tryCatch(X/2, error = function(e) "An Error Occurred")
>   return(result)
> }
> 
> This function appears to work as I expect both in cases where an error
> occurs and where no error occurs.
> 
> divideBy2(10)
> # [1] 5
> 
> divideBy2("This is not a number")
> # [1] "An Error Occurred"
> 
> I would like to use this function in an lapply(), but when I do so ALL of
> the results returned are the results of an error.
> 
> lapply(c(10,"This is not a number"),FUN=divideBy2)
> 
> #[[1]]
> #[1] "An Error Occurred"
> 
> #[[2]]
> #[1] "An Error Occurred"
> 
> Is this how lapply() is meant to work? What I want is a list that looks
> like this
The problem happens before lapply() itself:
> c(10,"This is not a number")
[1] "10"  "This is not a number"

A vector can only contain values of the same type, so 10 is converted to
a character value, and divideBy2("10") does not work. Try with:
lapply(list(10, "This is not a number"), divideBy2)

All that means that in real use cases, your tryCatch() solution should
work (I have not tested it). The bug is in your toy example.


Regards

> #[[1]]
> #[1] 5
> #[[2]]
> #[1] "An Error Occurred"
> 
> Thanks very much for your time.
> 
>   [[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] R CMD in batch mode/trycatch() keeps hold on resources

2013-02-13 Thread guillaume Le Ray
HI all,

I am using R (version 2.13.1) in batch mode on a server and I use
trycatch() to handle the exceptions.

When the code run without any exceptions, everything goes fine, however  as
soon as trycatch handle an error, my code works fine but R keeps hold on
the folder after quiting.

Therefore when I try to delete the folder it cannot...

do you have any idea of which function can be the origin of the problem? or
how to kill the process?

Regards,

Guillaume Le Ray

[[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] Is there a place to put executable R scripts in new packages?

2013-02-13 Thread Duncan Murdoch

On 13-02-12 11:09 PM, Asis Hallab wrote:

Dear R users,

writing an R package I wonder, if there is a place to put executable R
scripts into. So that when the package is installed one can use the
script from the command line.

Say we have e new package called FunkyR and wanted to deliver with it
an executable called FunkyCold.R, so that from the command line, one
could do the following:

Rscript FunkyCold.R argument_1 argument_2

Any hints or suggestions?


It's probably possible to achieve what you're asking for, but it would 
be messy and ugly.  A better approach is to write a function 
corresponding to each script, then call it as


Rscript -e "mypkg::FunkyCold(arg1, arg2)"

Duncan Murdoch

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


[R] Correlation with p value

2013-02-13 Thread Nico Met
Dear all,

I have a data (bellow) and I want to make a correlation test with p-value

structure(list(Name = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("CTJ",
"PKR", "TTK"), class = "factor"), score = c(86.4371428571428,
89.7028571428572, 87.728, 89.99, 89.42, 85.6914285714286, 82.256,
83.9942857142857, 86.4371428571429, 84.596, 84.74, 87.8771428571428,
83.12, 81.824, 88.5457142857143, 85.7171428571429, 84.902,
89.8828571428571,
91.5542857142857, 89.42, 86.81)), .Names = c("Name", "score"), class =
"data.frame", row.names = c(NA,
21L))

And finally , I would like to display as matrix where I can fill up with
p-values


 *TTK*
 *CTJ*
 *PKR*
 *TTK*
 **
 **
 **
 *CTJ*
 **
 **
 **
 *PKR*





Many thanks for your help in advance

Nico

[[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] Correlation with p value

2013-02-13 Thread Jorge I Velez
Nico,

Check https://stat.ethz.ch/pipermail/r-help/2008-May/161725.html for some
alternatives.  You might have to change the structure of your data, though.

HTH,
Jorge.-


On Wed, Feb 13, 2013 at 10:13 PM, Nico Met <> wrote:

> Dear all,
>
> I have a data (bellow) and I want to make a correlation test with p-value
>
> structure(list(Name = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("CTJ",
> "PKR", "TTK"), class = "factor"), score = c(86.4371428571428,
> 89.7028571428572, 87.728, 89.99, 89.42, 85.6914285714286, 82.256,
> 83.9942857142857, 86.4371428571429, 84.596, 84.74, 87.8771428571428,
> 83.12, 81.824, 88.5457142857143, 85.7171428571429, 84.902,
> 89.8828571428571,
> 91.5542857142857, 89.42, 86.81)), .Names = c("Name", "score"), class =
> "data.frame", row.names = c(NA,
> 21L))
>
> And finally , I would like to display as matrix where I can fill up with
> p-values
>
>
>  *TTK*
>  *CTJ*
>  *PKR*
>  *TTK*
>  **
>  **
>  **
>  *CTJ*
>  **
>  **
>  **
>  *PKR*
>
>
>
>
>
> Many thanks for your help in advance
>
> Nico
>
> [[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] plot rtf in landscape orintation

2013-02-13 Thread Adams, Jean
You can control the width and height of a plot in addPlot(), but you must
use addPageBreak() to control the width and the height of the page.  Here
is a modification of the example provided in the help for rtf,
?RTF

library(rtf)
myplot <- function() {
par(mar=c(4, 4, 1, 1), cex=2)
plot(rnorm(25), rnorm(25), pch=16, col=1:25)
 }
rtf <- RTF("test_RTF-class.doc")
addHeader(rtf, title="Example", subtitle="First page portrait, second page
landscape")
addPlot(rtf, plot.fun=myplot, width=4, height=4)
addPageBreak(rtf, width=11, height=8.5)
addPlot(rtf, plot.fun=myplot, width=9, height=6.5)
done(rtf)

Jean


On Wed, Feb 13, 2013 at 12:52 AM,  wrote:

>
> Hello All,
>
> I 'm trying to plot R graph in landscape orientation in a .rtf file.
> i 'm using library(rtf) for this.
> do we have any option in addPlot() function to rotate the orientation of
> the rtf file?
>
>
>
> Thank you,
>
>
> Deepthi BM
> PGDB-10-10-04
> Institute of Bioinformatics and Applied Biotechnology
> Biotech Park, Electronic City, Phase I, Bengaluru-560100
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] CARET: Any way to access other tuning parameters?

2013-02-13 Thread James Jong
The documentation for caret::train shows a list of parameters that one can
 tune for each method classification/regression method. For example, for
the method randomForest one can tune mtry in the call to train. But the
 function call to train random forests in the original package has many
other parameters, e.g. sampsize, maxnodes, etc.

Is there **any** way to access these parameters using train in caret? (Is
the function caret::createGrid limited to the list of parameters specified
in the caret documentation, it's not super clear if the list of parameter
is for all the caret APIs).

Thanks,

James,

[[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] Correlation with p value

2013-02-13 Thread David L Carlson
You can use package Hmisc. Assuming your data.frame is called "dta":

> library(Hmisc)
> dta2 <- do.call(cbind, split(dta[,2], dta$Name))
> dta2
  CTJ  PKR  TTK
[1,] 83.99429 88.54571 86.43714
[2,] 86.43714 85.71714 89.70286
[3,] 84.59600 84.90200 87.72800
[4,] 84.74000 89.88286 89.99000
[5,] 87.87714 91.55429 89.42000
[6,] 83.12000 89.42000 85.69143
[7,] 81.82400 86.81000 82.25600
> rcorr(dta2)
 CTJ  PKR  TTK
CTJ 1.00 0.29 0.85
PKR 0.29 1.00 0.22
TTK 0.85 0.22 1.00

n= 7 


P
CTJPKRTTK   
CTJ0.5214 0.0152
PKR 0.52140.6277
TTK 0.0152 0.6277   

--
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352


>  -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Jorge I Velez
> Sent: Wednesday, February 13, 2013 5:22 AM
> To: Nico Met
> Cc: R help
> Subject: Re: [R] Correlation with p value
> 
> Nico,
> 
> Check https://stat.ethz.ch/pipermail/r-help/2008-May/161725.html for
> some
> alternatives.  You might have to change the structure of your data,
> though.
> 
> HTH,
> Jorge.-
> 
> 
> On Wed, Feb 13, 2013 at 10:13 PM, Nico Met <> wrote:
> 
> > Dear all,
> >
> > I have a data (bellow) and I want to make a correlation test with p-
> value
> >
> > structure(list(Name = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L,
> > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label =
> c("CTJ",
> > "PKR", "TTK"), class = "factor"), score = c(86.4371428571428,
> > 89.7028571428572, 87.728, 89.99, 89.42, 85.6914285714286, 82.256,
> > 83.9942857142857, 86.4371428571429, 84.596, 84.74, 87.8771428571428,
> > 83.12, 81.824, 88.5457142857143, 85.7171428571429, 84.902,
> > 89.8828571428571,
> > 91.5542857142857, 89.42, 86.81)), .Names = c("Name", "score"), class
> =
> > "data.frame", row.names = c(NA,
> > 21L))
> >
> > And finally , I would like to display as matrix where I can fill up
> with
> > p-values
> >
> >
> >  *TTK*
> >  *CTJ*
> >  *PKR*
> >  *TTK*
> >  **
> >  **
> >  **
> >  *CTJ*
> >  **
> >  **
> >  **
> >  *PKR*
> >
> >
> >
> >
> >
> > Many thanks for your help in advance
> >
> > Nico
> >
> > [[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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] spearman correlation and p-value as a matrix

2013-02-13 Thread Ozgul Inceoglu
I have two data matrices that I want to make the correlation between each 
column from data1 and each column from data 2 and also calculate the p-value 
Matrices dont have the same size and I tried such a script.
> bg <- read.table (file.choose(), header=T, row.names) 
> bg 
> Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 
> Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 
> Otu00218 
> Gi20Jun11 0.001217 0 0.001217 0 0.00 0 0 0 0.001217 0 0 0 0 0 0.001217 0 
> 0.001217 
> Gi40Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
> 0.00 
> Gi425Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
> 0.00 
> Gi45Jun11 0.00 0 0.00 0 0.001513 0 0 0 0.00 0 0 0 0 0 0.00 0 
> 0.00 
> Gi475Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
> 0.00 
> Gi50Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
> 0.00 
ag <- read.table (file.choose(), header=T, row.names) 

for (i in 1:(ncol(bg))) 
for (j in 1:(ncol(ag))) 
print(c(i,j))
final_matrix <- matrix(rep("0",ncol(bg)*ncol(ag)),ncol=ncol(bg),nrow=ncol(ag))

cor <- cor.test(as.vector(as.matrix(bg[,i])),as.vector(as.matrix(ag[,j])), 
method="spearman")

#but the output is not matrice with all the values but a single correlation 
value

data:  bg[, i] and ag[, j] 
t = 2.2992, df = 26, p-value = 0.02978
alternative hypothesis: true correlation is not equal to 0 
95 percent confidence interval:
 0.04485289 0.67986803 
sample estimates:
  cor 
0.4110515 

# How I can creat an outfile with all the correlations and p-values?

Thank you very much!
Özgül

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] match in dependence of 2 columns

2013-02-13 Thread Mat
Hello,

i want to match a column of one data.frame to another, my problem is, that i
only want to match the data, if 2 columns are equal.

i have a example:

data.frame1
  cu.nr. name  value
A 1 Evo 100
B 1 Mer 80
C 2 Ford50

And now i want to match the value to data.frame 2 in dependence of cu.nr.
and name.

data.frame2
  cu.nr. name 
A 33 Evo  
B 1 Mer 
C 1 Pold  

as you can see, there is only one row with equal cu.nr. and name. How can i
match the data as desired?
The solution has to look like this one:

  cu.nr. name  Value
A 33 Evo  
B 1 Mer   80  
C 1 Pold   

thanks.

Mat



--
View this message in context: 
http://r.789695.n4.nabble.com/match-in-dependence-of-2-columns-tp4658405.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] recovering from errors with lapply()

2013-02-13 Thread Andrew Barr
Thanks very much Milan.  Your answer makes perfect sense.

Best,

Andrew


On Wed, Feb 13, 2013 at 3:51 AM, Milan Bouchet-Valat wrote:

> Le mardi 12 février 2013 à 15:41 -0600, Andrew Barr a écrit :
> > Hi all,
> >
> > I am searching for a way to recover results from lapply() when one or
> more
> > values returns an error.  I have a written a function that uses
> tryCatch()
> > to recover from errors. Here is a very simple example of such a function.
> >
> > divideBy2<-function(X){
> >   result<-tryCatch(X/2, error = function(e) "An Error Occurred")
> >   return(result)
> > }
> >
> > This function appears to work as I expect both in cases where an error
> > occurs and where no error occurs.
> >
> > divideBy2(10)
> > # [1] 5
> >
> > divideBy2("This is not a number")
> > # [1] "An Error Occurred"
> >
> > I would like to use this function in an lapply(), but when I do so ALL of
> > the results returned are the results of an error.
> >
> > lapply(c(10,"This is not a number"),FUN=divideBy2)
> >
> > #[[1]]
> > #[1] "An Error Occurred"
> >
> > #[[2]]
> > #[1] "An Error Occurred"
> >
> > Is this how lapply() is meant to work? What I want is a list that looks
> > like this
> The problem happens before lapply() itself:
> > c(10,"This is not a number")
> [1] "10"  "This is not a number"
>
> A vector can only contain values of the same type, so 10 is converted to
> a character value, and divideBy2("10") does not work. Try with:
> lapply(list(10, "This is not a number"), divideBy2)
>
> All that means that in real use cases, your tryCatch() solution should
> work (I have not tested it). The bug is in your toy example.
>
>
> Regards
>
> > #[[1]]
> > #[1] 5
> > #[[2]]
> > #[1] "An Error Occurred"
> >
> > Thanks very much for your time.
> >
> >   [[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.


[R] MIMIC latent variable with PLS Path Modelling with R ?

2013-02-13 Thread Hervé Guyon

I want estimate MIMIC latent variable with R in a Monte Carlo simulation.
The packages plspm and semPLS don't permit to introduce MIMIC variable 
but only reflexives or formatives variables.
The only one program which permits to use MIMIC latent variable with 
PLSPM seems to be XLSTAT, which can not be used to simulate a lot of 
data bases.
It is a real challenge to develop a package with PLSPM and MIMIC latent 
variable…. And I prefer to use a package which exists.

Has someone a solution in R ?

Hervé

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] densityplot(~x+y) for vectors of different lengths does what?

2013-02-13 Thread Michael Stob
densityplot(~x+y) does what I expect it to do if x and y have equal length.  I 
know how to get what I want if x and y have different lengths.   But what is 
this actually doing if x and y have different lengths?The relevant example 
is
 
x=rnorm(10)
y=rnorm(50,1)
densityplot(~x+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] Correlation with p value

2013-02-13 Thread arun
Hi,
#data: dat1
mat1<-matrix(dat1[,2],ncol=3,nrow=7)
colnames(mat1)<-unique(dat1[,1])
library(Hmisc)
rcorr(mat1)$P
 #     TTK   CTJ   PKR
#TTK    NA 0.0151874 0.6277163
#CTJ 0.0151874    NA 0.5214368
#PKR 0.6277163 0.5214368    NA
A.K.




- Original Message -
From: Nico Met 
To: R help 
Cc: 
Sent: Wednesday, February 13, 2013 6:13 AM
Subject: [R] Correlation with p value

Dear all,

I have a data (bellow) and I want to make a correlation test with p-value

structure(list(Name = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("CTJ",
"PKR", "TTK"), class = "factor"), score = c(86.4371428571428,
89.7028571428572, 87.728, 89.99, 89.42, 85.6914285714286, 82.256,
83.9942857142857, 86.4371428571429, 84.596, 84.74, 87.8771428571428,
83.12, 81.824, 88.5457142857143, 85.7171428571429, 84.902,
89.8828571428571,
91.5542857142857, 89.42, 86.81)), .Names = c("Name", "score"), class =
"data.frame", row.names = c(NA,
21L))

And finally , I would like to display as matrix where I can fill up with
p-values


*TTK*
*CTJ*
*PKR*
*TTK*
**
**
**
*CTJ*
**
**
**
*PKR*





Many thanks for your help in advance

Nico

    [[alternative HTML version deleted]]

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


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


Re: [R] date and matrices

2013-02-13 Thread arun
Hi Elisa,

Try this:
date1<-format(seq.Date(as.Date("1991.1.1",format="%Y.%m.%d"),as.Date("1996.12.31",format="%Y.%m.%d"),by="day"),"%Y.%m.%d")
 length(date1)
#[1] 2192
mat1<-matrix(c(.314,.314,.273,.273,.236,.236,.236,.236,.273,.314,.403,.314),ncol=1)
res1<- 
as.data.frame(do.call(rbind,lapply(split(date1,((seq_along(date1)-1)%/%12)+1),function(x){if(length(x)!=12)
 cbind(x,head(mat1,length(x))) else cbind(x,mat1)})),stringsAsFactors=FALSE)
res1[,2]<- sapply(res1[,2],as.numeric)
 str(res1)
#'data.frame':    2192 obs. of  2 variables:
# $ x : chr  "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" ...
# $ V2: num  0.314 0.314 0.273 0.273 0.236 0.236 0.236 0.236 0.273 0.314 ...
 head(res1)
#   x    V2
#1 1991.01.01 0.314
#2 1991.01.02 0.314
#3 1991.01.03 0.273
#4 1991.01.04 0.273
#5 1991.01.05 0.236
#6 1991.01.06 0.236
 tail(res1)
#  x    V2
#2187 1996.12.26 0.273
#2188 1996.12.27 0.273
#2189 1996.12.28 0.236
#2190 1996.12.29 0.236
#2191 1996.12.30 0.236
#2192 1996.12.31 0.236
 res1$x<- as.Date(res1$x,format="%Y.%m.%d")
 str(res1)
#'data.frame':    2192 obs. of  2 variables:
# $ x : Date, format: "1991-01-01" "1991-01-02" ...
# $ V2: num  0.314 0.314 0.273 0.273 0.236 0.236 0.236 0.236 0.273 0.314 ...




A.K.




From: eliza botto 
To: "smartpink...@yahoo.com"  
Sent: Wednesday, February 13, 2013 9:01 AM
Subject: date and matrices



Dear Arun,
[text files is also attached to be used in case format is changed]
i have 124 matrices with 12rows and 1 column. In all those 124 columns there 
are values of a certain quantity called disty. what i want to do is the 
following
1- insert a date column in each matrix in such a way that date should start 
from 1991. 1. 1 (. m. d) and should end at
1996.12.31.
2- against each date i want to put the values of quantity disty and as i have 
only 12 values of disty i want to start from the
first value after very 12 days.
more precisely, if i have a matrix like this
mat1
  [,1]
 .314
 .314
 .273
 .273
 .236
 .236
 .236
 .236
 .273
 .314
 .403
 .314

i want it to be like the following one
 1911. 1. 1  .314
 1911. 1. 2  .314
 1911. 1. 3  .273
 1911. 1. 4  .273
 1911. 1. 5  .236
 1911. 1. 6  .236
 1911. 1. 7  .236
 1911. 1. 8  .236
 1911. 1. 9  .273
 1911. 1.10 2.314
 1911. 1.11    12.403
 1911. 1.12  .314
 1911. 1.11  .314
 1911. 1.12  .314
 1911. 1.13  .273
 1911. 1.14  .273
 1911. 1.15  .236
 1911. 1.16  .236
 1911. 1.17  .236
 1911. 1.18  .236
 1911. 1.19  .273
 1911. 1.20 2.314
 1911. 1.21    12.403
 1911. 1.22  .314
 1911. 1.23  .314
 1911. 1.24  .314
 1911. 1.25  .273
 1911. 1.26  .273
 1911. 1.27  .236
 1911. 1.28  .236
 1911. 1.29  .236
 1911. 1.30  .236
 1911. 1.31  .273
 1911. 2. 1 2.314
 1911. 2. 2    12.403
 1911. 2. 3  .314
 1911. 2. 4  .314
 1911. 2. 5  .314
 1911. 2. 6  .273
 1911. 2. 7  .273
 1911. 2. 8  .236
 1911. 2. 9  .236
 1911. 2.10  .236
 1911. 2.11  .236
 1911. 2.12  .273
 1911. 2.13 2.314
 1911. 2.11    12.403
--
--
1911.12.17 12.403



and so on till 1996
i also want these 124 matrices to be saved in my computer with the pattern 
exactly shown above. you can see if a value is in decimal number it is exactly 
6 spaces away from the day number in date column. these spaces are subsequently 
reduced when the values go from decimal to higher. 
Actually it wont be wrong to say the pattren of output text files saved in my 
computer should stricktly carry all the patterns as given above as i will later 
on use them in fortran.   

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

2013-02-13 Thread arun
Hi,

Just forgot about one thing:
With more matrices with one column:
One way would be to combine them as a single matrix:
date1<-format(seq.Date(as.Date("1991.1.1",format="%Y.%m.%d"),as.Date("1996.12.31",format="%Y.%m.%d"),by="day"),"%Y.%m.%d")

mat1<-matrix(c(.314,.314,.273,.273,.236,.236,.236,.236,.273,.314,.403,.314),ncol=1)
mat2<-matrix(c(.314,.325,.246,.273,.226,.236,.249,.236,.289,.314,.403,.314),ncol=1)
mat3<- cbind(mat1,mat2) #if this is not feasible, tell me how these matrices 
are named

 res2<- lapply(seq_len(ncol(mat3)),function(i) 
cbind(date1,c(rep(mat3[,i],182),head(mat3[,i],8
head(res2[[1]])
# date1   
#[1,] "1991.01.01" "0.314"
#[2,] "1991.01.02" "0.314"
#[3,] "1991.01.03" "0.273"
#[4,] "1991.01.04" "0.273"
#[5,] "1991.01.05" "0.236"
#[6,] "1991.01.06" "0.236"
 tail(res2[[1]])
#    date1   
#[2187,] "1996.12.26" "0.273"
#[2188,] "1996.12.27" "0.273"
#[2189,] "1996.12.28" "0.236"
#[2190,] "1996.12.29" "0.236"
#[2191,] "1996.12.30" "0.236"
#[2192,] "1996.12.31" "0.236"


A.K.


From: eliza botto 
To: "smartpink...@yahoo.com"  
Sent: Wednesday, February 13, 2013 9:01 AM
Subject: date and matrices



Dear Arun,
[text files is also attached to be used in case format is changed]
i have 124 matrices with 12rows and 1 column. In all those 124 columns there 
are values of a certain quantity called disty. what i want to do is the 
following
1- insert a date column in each matrix in such a way that date should start 
from 1991. 1. 1 (. m. d) and should end at
1996.12.31.
2- against each date i want to put the values of quantity disty and as i have 
only 12 values of disty i want to start from the
first value after very 12 days.
more precisely, if i have a matrix like this
mat1
  [,1]
 .314
 .314
 .273
 .273
 .236
 .236
 .236
 .236
 .273
 .314
 .403
 .314

i want it to be like the following one
 1911. 1. 1  .314
 1911. 1. 2  .314
 1911. 1. 3  .273
 1911. 1. 4  .273
 1911. 1. 5  .236
 1911. 1. 6  .236
 1911. 1. 7  .236
 1911. 1. 8  .236
 1911. 1. 9  .273
 1911. 1.10 2.314
 1911. 1.11    12.403
 1911. 1.12  .314
 1911. 1.11  .314
 1911. 1.12  .314
 1911. 1.13  .273
 1911. 1.14  .273
 1911. 1.15  .236
 1911. 1.16  .236
 1911. 1.17  .236
 1911. 1.18  .236
 1911. 1.19  .273
 1911. 1.20 2.314
 1911. 1.21    12.403
 1911. 1.22  .314
 1911. 1.23  .314
 1911. 1.24  .314
 1911. 1.25  .273
 1911. 1.26  .273
 1911. 1.27  .236
 1911. 1.28  .236
 1911. 1.29  .236
 1911. 1.30  .236
 1911. 1.31  .273
 1911. 2. 1 2.314
 1911. 2. 2    12.403
 1911. 2. 3  .314
 1911. 2. 4  .314
 1911. 2. 5  .314
 1911. 2. 6  .273
 1911. 2. 7  .273
 1911. 2. 8  .236
 1911. 2. 9  .236
 1911. 2.10  .236
 1911. 2.11  .236
 1911. 2.12  .273
 1911. 2.13 2.314
 1911. 2.11    12.403
--
--
1911.12.17 12.403



and so on till 1996
i also want these 124 matrices to be saved in my computer with the pattern 
exactly shown above. you can see if a value is in decimal number it is exactly 
6 spaces away from the day number in date column. these spaces are subsequently 
reduced when the values go from decimal to higher. 
Actually it wont be wrong to say the pattren of output text files saved in my 
computer should stricktly carry all the patterns as given above as i will later 
on use them in fortran.   

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

2013-02-13 Thread Pedro Carvalho

Hello,

I have submitted a R question to stackoverflow and have not received an answer.

Could anyone help me out?

http://stackoverflow.com/questions/14825443/backtesting-accuracy-of-regression-model-through-rolling-window-regression-with

Best regards,
Pedro 
  
[[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] NA/NaN/Inf in foreign function call (arg 6) error from coxph function

2013-02-13 Thread Cindy Yao
Dear R-helpers:

I am trying to fit a multivariate Cox proportional hazards model,
modelling survival outcome as a function of treatment and receptor
status. The data look like below:

# structure of the data
str(sample.data)
List of 4
 $ survobj  : Surv [1:129, 1:2] 0.8925+ 1.8836+ 2.1191+ 5.3744+
1.6099+ 5.2567  0.2081+ 0.2108+ 0.2683+ 0.4873+ ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:2] "time" "status"
  ..- attr(*, "type")= chr "right"
 $ therapy  : Factor w/ 2 levels "treatment1","treatment2": 1 1 1 1 1
1 1 2 2 1 ...
 $ ReceptorA: Factor w/ 2 levels "0","1": 1 2 2 2 1 2 2 2 2 1 ...
 $ ReceptorB: Factor w/ 2 levels "0","1": 1 2 1 1 2 1 1 1 1 1 ...

But when I tried to fit a multivariate Cox proportional model, I got
the following error. I'm not quite what that means. Any help would be
much appreciated!

# perform multivariate Cox proportional hazards model
coxph(sample.data$survobj ~ sample.data$therapy +
sample.data$ReceptorA + sample.data$ReceptorB)

Error in fitter(X, Y, strats, offset, init, control, weights = weights,  :
  NA/NaN/Inf in foreign function call (arg 6)
In addition: Warning message:
In fitter(X, Y, strats, offset, init, control, weights = weights,  :
  Ran out of iterations and did not converge

Best regards,
Cindy

 -- output of sessionInfo():

sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
[1] C

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

other attached packages:
 [1] MASS_7.3-23
 [2] hexbin_1.26.1
 [3] cluster_1.14.3
 [4] latticeExtra_0.6-24
 [5] RColorBrewer_1.0-5
 [6] lattice_0.20-13
 [7] survival_2.37-2

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

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


Re: [R] Correlation with p value

2013-02-13 Thread David L Carlson
Minor edit

> dta2 <- unstack(dta, score~Name)

is simpler.

---
David C


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of David L Carlson
> Sent: Wednesday, February 13, 2013 9:40 AM
> To: 'Jorge I Velez'; 'Nico Met'
> Cc: 'R help'
> Subject: Re: [R] Correlation with p value
> 
> You can use package Hmisc. Assuming your data.frame is called "dta":
> 
> > library(Hmisc)
> > dta2 <- do.call(cbind, split(dta[,2], dta$Name))
> > dta2
>   CTJ  PKR  TTK
> [1,] 83.99429 88.54571 86.43714
> [2,] 86.43714 85.71714 89.70286
> [3,] 84.59600 84.90200 87.72800
> [4,] 84.74000 89.88286 89.99000
> [5,] 87.87714 91.55429 89.42000
> [6,] 83.12000 89.42000 85.69143
> [7,] 81.82400 86.81000 82.25600
> > rcorr(dta2)
>  CTJ  PKR  TTK
> CTJ 1.00 0.29 0.85
> PKR 0.29 1.00 0.22
> TTK 0.85 0.22 1.00
> 
> n= 7
> 
> 
> P
> CTJPKRTTK
> CTJ0.5214 0.0152
> PKR 0.52140.6277
> TTK 0.0152 0.6277
> 
> --
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
> 
> 
> >  -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> > project.org] On Behalf Of Jorge I Velez
> > Sent: Wednesday, February 13, 2013 5:22 AM
> > To: Nico Met
> > Cc: R help
> > Subject: Re: [R] Correlation with p value
> >
> > Nico,
> >
> > Check https://stat.ethz.ch/pipermail/r-help/2008-May/161725.html for
> > some
> > alternatives.  You might have to change the structure of your data,
> > though.
> >
> > HTH,
> > Jorge.-
> >
> >
> > On Wed, Feb 13, 2013 at 10:13 PM, Nico Met <> wrote:
> >
> > > Dear all,
> > >
> > > I have a data (bellow) and I want to make a correlation test with
> p-
> > value
> > >
> > > structure(list(Name = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L,
> > > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label =
> > c("CTJ",
> > > "PKR", "TTK"), class = "factor"), score = c(86.4371428571428,
> > > 89.7028571428572, 87.728, 89.99, 89.42, 85.6914285714286, 82.256,
> > > 83.9942857142857, 86.4371428571429, 84.596, 84.74,
> 87.8771428571428,
> > > 83.12, 81.824, 88.5457142857143, 85.7171428571429, 84.902,
> > > 89.8828571428571,
> > > 91.5542857142857, 89.42, 86.81)), .Names = c("Name", "score"),
> class
> > =
> > > "data.frame", row.names = c(NA,
> > > 21L))
> > >
> > > And finally , I would like to display as matrix where I can fill up
> > with
> > > p-values
> > >
> > >
> > >  *TTK*
> > >  *CTJ*
> > >  *PKR*
> > >  *TTK*
> > >  **
> > >  **
> > >  **
> > >  *CTJ*
> > >  **
> > >  **
> > >  **
> > >  *PKR*
> > >
> > >
> > >
> > >
> > >
> > > Many thanks for your help in advance
> > >
> > > Nico
> > >
> > > [[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.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] match in dependence of 2 columns

2013-02-13 Thread John Kane
?merge

If I have not reversed the data sets this should work
With data sets called dat1 and dat2 

merge(dat1,dat2, all.y = TRUE)

John Kane
Kingston ON Canada


> -Original Message-
> From: matthias.we...@fnt.de
> Sent: Wed, 13 Feb 2013 06:39:57 -0800 (PST)
> To: r-help@r-project.org
> Subject: [R] match in dependence of 2 columns
> 
> Hello,
> 
> i want to match a column of one data.frame to another, my problem is,
> that i
> only want to match the data, if 2 columns are equal.
> 
> i have a example:
> 
> data.frame1
>   cu.nr. name  value
> A 1 Evo 100
> B 1 Mer 80
> C 2 Ford50
> 
> And now i want to match the value to data.frame 2 in dependence of cu.nr.
> and name.
> 
> data.frame2
>   cu.nr. name
> A 33 Evo
> B 1 Mer
> C 1 Pold
> 
> as you can see, there is only one row with equal cu.nr. and name. How can
> i
> match the data as desired?
> The solution has to look like this one:
> 
>   cu.nr. name  Value
> A 33 Evo
> B 1 Mer   80
> C 1 Pold
> 
> thanks.
> 
> Mat
> 
> 
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/match-in-dependence-of-2-columns-tp4658405.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.


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] analogs of prompt(), promptData() for roxygen?

2013-02-13 Thread Michael Friendly
roxygen2::roxygenize() process an entire package and rd2roxygen can 
convert existing Rd

documentation to roxygen format.

But are there equivalents/analogs of prompt() or SoDA::promptAll() for 
one or more .R/.RData files that would

create skeleton roxygen documentation of functions or data?

--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, Quantitative Methods
York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] match in dependence of 2 columns

2013-02-13 Thread Rui Barradas

Hello,

Try the following.


data.frame1 <- read.table(text = "
  cu.nr. name  value
A 1 Evo 100
B 1 Mer 80
C 2 Ford50
", header = TRUE)


data.frame2 <- read.table(text = "
  cu.nr. name
A 33 Evo
B 1 Mer
C 1 Pold
", header = TRUE)

merge(data.frame2, data.frame1, all.x = TRUE)



Hope this helps,

Rui Barradas

Em 13-02-2013 14:39, Mat escreveu:

Hello,

i want to match a column of one data.frame to another, my problem is, that i
only want to match the data, if 2 columns are equal.

i have a example:

data.frame1
   cu.nr. name  value
A 1 Evo 100
B 1 Mer 80
C 2 Ford50

And now i want to match the value to data.frame 2 in dependence of cu.nr.
and name.

data.frame2
   cu.nr. name
A 33 Evo
B 1 Mer
C 1 Pold

as you can see, there is only one row with equal cu.nr. and name. How can i
match the data as desired?
The solution has to look like this one:

   cu.nr. name  Value
A 33 Evo
B 1 Mer   80
C 1 Pold

thanks.

Mat



--
View this message in context: 
http://r.789695.n4.nabble.com/match-in-dependence-of-2-columns-tp4658405.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.


[R] e1071::skewness and psych::skew return NaN

2013-02-13 Thread Stephen Politzer-Ahles
Hello everyone,

Does anyone know what would cause the skewness() function (from
e1071), as well as skew() from psych, to return a value of NaN?

I have a vector of positively-skewed data
(https://docs.google.com/file/d/0B6-m45Jvl3ZmYzlHRVRHRURzbVk/edit?usp=sharing)
which these functions return a value for like normal:

> skewness( data ) # returns 1.400405

but when I instead give those functions the log-transformed data they return NaN

> skewness( log( data ) ) #returns NaN

The same occurs when I feed the function data transformed by reflected
reciprocal

> skewness( max(data) - 1/data ) ) #returns NaN

The vector has no missing values (and if it did, I would get NA rather
than NaN, and the function wouldn't return a number when I give it the
raw data).

Best,
Steve

--
Stephen Politzer-Ahles
University of Kansas
Linguistics Department
http://people.ku.edu/~sjpa/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Max value of each 2 rows in dataframe

2013-02-13 Thread zuzana zajkova
Hi,

thank you for your response. I tried the
A[-1,]<-do.call(rbind,lapply(split(A[-1,],((1:nrow(A[-1,])-1)%/%2)+1),function(x){x[4]<-max(x[4]);x}))
but somehow my computer got stuck...

I tried the other option using rollapply and that works pretty well, doing
exactly what I wanted to get.
This is my final solution:

 maxlig<-rollapply(A$lig[-1],2,max,align="right",fill=NA)
 maxlig<-c(A$lig[[1]], maxlig)  # to get back the value from 1st row
 A<-cbind(A, maxlig)
 A$lig<-A$maxlig
 A$x <- ifelse(as.numeric(row.names(A)) %% 2==1, 'keep', '') # add column x
where value is 'keep' or blank
 A <- A[A$x == "keep",] # remove where x is blank, keep the values in 10
minutes interval
 A$maxlig<-A$x<-NULL

Thank you for your help,

Zuzana


On 13 February 2013 06:55, arun  wrote:

> Hi,
>
> For the dataset A,
> Assuming that this is what you meant: the maximum value of "lig" in each 2
> rows excluding the first row:
>
> #dataset: A
>
> A[-1,]<-do.call(rbind,lapply(split(A[-1,],((1:nrow(A[-1,])-1)%/%2)+1),function(x){x[4]<-max(x[4]);x}))
>  A
> #   oktime secs lig  geo ind
> #1  ok 2010-01-15 04:45:00 40193.45  28 17016001 5500519
> #2  ok 2010-01-15 04:49:59 40193.45  64 17016001 5500519
> #3  ok 2010-01-15 04:54:59 40193.45  64 17016001 5500519
> #4  ok 2010-01-15 04:59:59 40193.46  32 17016001 5500519
> #5  ok 2010-01-15 05:04:59 40193.46  32 17016001 5500519
> #6  ok 2010-01-15 05:09:59 40193.47  13 17016001 5500519
> #7  ok 2010-01-15 05:14:59 40193.47  13 17016001 5500519
> #8  ok 2010-01-15 05:19:59 40193.47   8 17016001 5500519
> #9  ok 2010-01-15 05:24:59 40193.48   8 17016001 5500519
> #10 ok 2010-01-15 05:29:59 40193.48   0 17016001 5500519
> #11 ok 2010-01-15 05:34:59 40193.48   0 17016001 5500519
> #12 ok 2010-01-15 05:39:59 40193.49  64 17016001 5500519
> #13 ok 2010-01-15 05:44:59 40193.49  64 17016001 5500519
> #14 ok 2010-01-15 05:49:59 40193.49  64 17016001 5500519
> #15 ok 2010-01-15 05:54:59 40193.50  64 17016001 5500519
> #16 ok 2010-01-15 05:59:59 40193.50  64 17016001 5500519
> #17 ok 2010-01-15 06:04:59 40193.50  64 17016001 5500519
> #18 ok 2010-01-15 06:09:59 40193.51  51 17016001 5500519
> #19 ok 2010-01-15 06:14:59 40193.51  51 17016001 5500519
> #20 ok 2010-01-15 06:19:59 40193.51  64 17016001 5500519
>
> #If you need a rolling max,
> library(zoo)
> rollapply(A$lig,2,max,align="right",fill=NA)
>  #[1] NA 64 64 44 32 22 13  4  8  8  0 45 64 64 64 64 64 64 51 64
>
>
> A.K.
>
>
>
>
>
> - Original Message -
> From: zuzana zajkova 
> To: Rui Barradas 
> Cc: r-help@r-project.org
> Sent: Tuesday, February 12, 2013 6:53 PM
> Subject: Re: [R] Max value of each 2 rows in dataframe
>
> Hi,
>
> sorry for not useable data...
>
> When I tried to use the dput function to the dataframe let's call it A, had
> some problems with the time and clock variables... however I attach an
> other dataframe B, which is created by merging A with other dataframe. The
> B dataframe has a little different structure as I mentioned before about B,
> each time is kind of doubled by variable "fix".
>
> I realized also that probably the most simple way would be to apply the
> changes directly to the original source dataframe (has 119 313 rows), which
> is later used for creating other dataframes.
> Here I attach few lines (hope this format will work well), data are grabbed
> every 5 minutes. For this data I would like to save the first row as it is
> and from there save the max value of next 5 and 10 minutes.
> example: the 3rd line should get the "lig" value equal to max of "lig"
> value of line 2 and 3 and so on
>
>
> structure(list(ok = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "ok", class =
> "factor"),
> time = structure(c(1263548700, 1263548999, 1263549299, 1263549599,
> 1263549899, 1263550199, 1263550499, 1263550799, 1263551099,
> 1263551399, 1263551699, 1263551999, 1263552299, 1263552599,
> 1263552899, 1263553199, 1263553499, 1263553799, 1263554099,
> 1263554399), class = c("POSIXct", "POSIXt"), tzone = ""),
> secs = c(40193.447917, 40193.451389, 40193.454861, 40193.458333,
> 40193.461806, 40193.465278, 40193.46875, 40193.47, 40193.475694,
> 40193.479167, 40193.482639, 40193.486111, 40193.489583, 40193.493056,
> 40193.496528, 40193.5, 40193.503472, 40193.506944, 40193.510417,
> 40193.513889), lig = c(28L, 64L, 44L, 32L, 22L, 13L, 4L,
>0L, 8L, 0L, 0L, 45L, 64L, 64L, 64L, 47L, 64L, 50L, 51L,
> 64L), geo = c(17016001, 17016001, 17016001, 17016001, 17016001,
> 17016001, 17016001, 17016001, 17016001, 17016001, 17016001,
> 17016001, 17016001, 17016001, 17016001, 17016001, 17016001,
> 17016001, 17016001, 17016001), ind = c(5500519, 5500519,
> 5500519, 5500519, 5500519, 5500519, 5500519, 5500519, 5500519,
> 5500519, 5500519, 5500519, 5500519, 5500519, 5500519, 5500519,
> 5500519, 5500519, 5500519, 5500519)), .Names = c("ok", "time",
> "secs", "lig", "geo",

Re: [R] e1071::skewness and psych::skew return NaN

2013-02-13 Thread Stephen Politzer-Ahles
Hi everyone,

Please disregard my last message, I found a 0 in the vector, which is
what was causing problems with the log and reciprocal data.

Best,
Steve

On Wed, Feb 13, 2013 at 10:55 AM, Stephen Politzer-Ahles
 wrote:
> Hello everyone,
>
> Does anyone know what would cause the skewness() function (from
> e1071), as well as skew() from psych, to return a value of NaN?
>
> I have a vector of positively-skewed data
> (https://docs.google.com/file/d/0B6-m45Jvl3ZmYzlHRVRHRURzbVk/edit?usp=sharing)
> which these functions return a value for like normal:
>
>> skewness( data ) # returns 1.400405
>
> but when I instead give those functions the log-transformed data they return 
> NaN
>
>> skewness( log( data ) ) #returns NaN
>
> The same occurs when I feed the function data transformed by reflected
> reciprocal
>
>> skewness( max(data) - 1/data ) ) #returns NaN
>
> The vector has no missing values (and if it did, I would get NA rather
> than NaN, and the function wouldn't return a number when I give it the
> raw data).
>
> Best,
> Steve
>
> --
> Stephen Politzer-Ahles
> University of Kansas
> Linguistics Department
> http://people.ku.edu/~sjpa/



-- 
Stephen Politzer-Ahles
University of Kansas
Linguistics Department
http://people.ku.edu/~sjpa/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] CARET: Any way to access other tuning parameters?

2013-02-13 Thread David Winsemius

On Feb 13, 2013, at 6:58 AM, James Jong wrote:

> The documentation for caret::train shows a list of parameters that one can
> tune for each method classification/regression method. For example, for
> the method randomForest one can tune mtry in the call to train. But the
> function call to train random forests in the original package has many
> other parameters, e.g. sampsize, maxnodes, etc.
> 
> Is there **any** way to access these parameters using train in caret? (Is
> the function caret::createGrid limited to the list of parameters specified
> in the caret documentation, it's not super clear if the list of parameter
> is for all the caret APIs).

Have you looked at the argument list in ?train:

... 
arguments passed to the classification or regression routine (such as 
randomForest). Errors will occur if values for tuning parameters are passed 
here.

Also look at:

? trainControl
? preProccess
-- 
David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] e1071::skewness and psych::skew return NaN

2013-02-13 Thread Rui Barradas

Hello,

That value means that some values of your data are negative or zero. A 
simple inspection shows that


any(dat < 0)  # FALSE
any(dat == 0) # TRUE

Solution: don't log your data


Hope this helps,

Rui Barradas

Em 13-02-2013 16:55, Stephen Politzer-Ahles escreveu:

Hello everyone,

Does anyone know what would cause the skewness() function (from
e1071), as well as skew() from psych, to return a value of NaN?

I have a vector of positively-skewed data
(https://docs.google.com/file/d/0B6-m45Jvl3ZmYzlHRVRHRURzbVk/edit?usp=sharing)
which these functions return a value for like normal:


skewness( data ) # returns 1.400405


but when I instead give those functions the log-transformed data they return NaN


skewness( log( data ) ) #returns NaN


The same occurs when I feed the function data transformed by reflected
reciprocal


skewness( max(data) - 1/data ) ) #returns NaN


The vector has no missing values (and if it did, I would get NA rather
than NaN, and the function wouldn't return a number when I give it the
raw data).

Best,
Steve

--
Stephen Politzer-Ahles
University of Kansas
Linguistics Department
http://people.ku.edu/~sjpa/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] e1071::skewness and psych::skew return NaN

2013-02-13 Thread Rui Barradas

Hello,

Just remembered, you can see how many values are zero, and since it's 
only one value, remove it and log the rest.


sum(dat == 0) # 1
d2 <- dat[dat != 0]

library(psych)
skew(log(d2))
[1] 0.6089985


Hope this helps,

Rui Barradas


Em 13-02-2013 17:59, Rui Barradas escreveu:

Hello,

That value means that some values of your data are negative or zero. A
simple inspection shows that

any(dat < 0)  # FALSE
any(dat == 0) # TRUE

Solution: don't log your data


Hope this helps,

Rui Barradas

Em 13-02-2013 16:55, Stephen Politzer-Ahles escreveu:

Hello everyone,

Does anyone know what would cause the skewness() function (from
e1071), as well as skew() from psych, to return a value of NaN?

I have a vector of positively-skewed data
(https://docs.google.com/file/d/0B6-m45Jvl3ZmYzlHRVRHRURzbVk/edit?usp=sharing)

which these functions return a value for like normal:


skewness( data ) # returns 1.400405


but when I instead give those functions the log-transformed data they
return NaN


skewness( log( data ) ) #returns NaN


The same occurs when I feed the function data transformed by reflected
reciprocal


skewness( max(data) - 1/data ) ) #returns NaN


The vector has no missing values (and if it did, I would get NA rather
than NaN, and the function wouldn't return a number when I give it the
raw data).

Best,
Steve

--
Stephen Politzer-Ahles
University of Kansas
Linguistics Department
http://people.ku.edu/~sjpa/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] NA/NaN/Inf in foreign function call (arg 6) error from coxph function

2013-02-13 Thread David Winsemius

On Feb 13, 2013, at 7:46 AM, Cindy Yao wrote:

> Dear R-helpers:
> 
> I am trying to fit a multivariate Cox proportional hazards model,
> modelling survival outcome as a function of treatment and receptor
> status. The data look like below:
> 
> # structure of the data
> str(sample.data)
> List of 4
> $ survobj  : Surv [1:129, 1:2] 0.8925+ 1.8836+ 2.1191+ 5.3744+
> 1.6099+ 5.2567  0.2081+ 0.2108+ 0.2683+ 0.4873+ ...
>  ..- attr(*, "dimnames")=List of 2
>  .. ..$ : NULL
>  .. ..$ : chr [1:2] "time" "status"
>  ..- attr(*, "type")= chr "right"
> $ therapy  : Factor w/ 2 levels "treatment1","treatment2": 1 1 1 1 1
> 1 1 2 2 1 ...
> $ ReceptorA: Factor w/ 2 levels "0","1": 1 2 2 2 1 2 2 2 2 1 ...
> $ ReceptorB: Factor w/ 2 levels "0","1": 1 2 1 1 2 1 1 1 1 1 ...
> 
> But when I tried to fit a multivariate Cox proportional model, I got
> the following error. I'm not quite what that means. Any help would be
> much appreciated!
> 
> # perform multivariate Cox proportional hazards model
> coxph(sample.data$survobj ~ sample.data$therapy +
> sample.data$ReceptorA + sample.data$ReceptorB)
> 
> Error in fitter(X, Y, strats, offset, init, control, weights = weights,  :
>  NA/NaN/Inf in foreign function call (arg 6)
> In addition: Warning message:
> In fitter(X, Y, strats, offset, init, control, weights = weights,  :
>  Ran out of iterations and did not converge

I cannot tell whether your method of calling coxph() could be part of the 
problem, or whether you just have a dataset that creates numerical 
difficulties. I would have constructed a dataset that did not have a 
Surv-object incorporated into that dataframe, sbut rather it would have been a 
list of five columns with 'time' and 'status' kept separate, and the call would 
have looked like:

coxph( Surv(time, status) ~ therapy + ReceptorA + ReceptorB , data= sample.data)

I know that people have had (occasional) problems in the past related merely to 
creating Surv-objects outside of the formula interface and your approach 
appears even more dangerous than that approach.

Once you have a more more data arrangement, you could investigate the 
possibility of a pathological arrangement of data with this since it appears 
all of you predictors are binomial.

with(sample.data, table( status, therapy,  ReceptorA ,  ReceptorB) )

-- 
David.

> 
> Best regards,
> Cindy
> 
> -- output of sessionInfo():
> 
> sessionInfo()
> R version 2.15.2 (2012-10-26)
> Platform: x86_64-unknown-linux-gnu (64-bit)
> 
> locale:
> [1] C
> 
> attached base packages:
> [1] grid  splines   stats graphics  grDevices datasets  utils
> [8] methods   base
> 
> other attached packages:
> [1] MASS_7.3-23
> [2] hexbin_1.26.1
> [3] cluster_1.14.3
> [4] latticeExtra_0.6-24
> [5] RColorBrewer_1.0-5
> [6] lattice_0.20-13
> [7] survival_2.37-2
> 
> loaded via a namespace (and not attached):
> [1] tools_2.15.2
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Kernel Density estimation at specific points

2013-02-13 Thread Robert Duval
Dear All,

I was wondering whether someone has created a kernel density evaluator that
estimates the density at given specified points.

The regular density() function evaluates the kernel at equidistant points,
but I am interested in doing such evaluation along a list of values
existing in a pre-specified vector. (Similar to the option at() in the
kdensity command in Stata).

This question has appeared before in the R-list, most recently in 2011 in :

http://tolstoy.newcastle.edu.au/R/e14/help/11/06/5232.html

There another list member suggested programming a home-made evaluator.
While the posted solution works, it is not as general, nor as fast as
density(). So I was wondering whether someone had recently came up with a
more efficient way of doing this.

N.B. Many users have suggested using some sort of interpolation over the
values provided by density(). However, for the problem I have at hand this
is not what I need.

Any help will be appreciated.
Robert

[[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 install .tar.gz source package in Windows XP 32-bit operational system

2013-02-13 Thread Marino David
Dear all mailing listers,

I failed in install source packages in Windows system. I have installed
Rtools in order to install the source package based on the discussion
available on the following link:
http://r.789695.n4.nabble.com/Installing-a-Package-tar-gz-in-windows-td3411393.html.
By the way, only installing the Rtools is ok, isn't it? Do I need to run
the Rtools?

> install.packages("adapt_1.0-4.tar.gz", type="source", repos=NULL)
* installing *source* package 'adapt' ...
** Creating default NAMESPACE file
** libs
ERROR: compilation failed for package 'adapt'
* removing 'C:/Program Files/R/R-2.15.2/library/adapt'
warning£º
1: running command'C:/PROGRA~1/R/R-215~1.2/bin/i386/R CMD INSTALL -l
"C:/Program Files/R/R-2.15.2/library"   "adapt_1.0-4.tar.gz"'had
status 1

2: In install.packages("adapt_1.0-4.tar.gz", type = "source", repos = NULL)
:
 installation of package ¡®adapt_1.0-4.tar.gz¡¯ had non-zero exit status


Any suggestion will be greatly appreciated.

Kind regards,

David

[[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] date and matrices

2013-02-13 Thread arun
HI Elisa,

You also mentioned about more than 100 matrices with 1 column each.
Suppose, if the matrices are named from mat1:mat4 (In your case mat1:mat124)
mat1<-matrix(c(.314,.314,.273,.273,.236,.236,.236,.236,.273,.314,.403,.314),ncol=1)
 
mat2<-matrix(c(.314,.325,.246,.273,.226,.236,.249,.236,.289,.314,.403,.314),ncol=1)
 
mat3<-matrix(c(.314,.320,.275,.273,.236,.232,.236,.231,.273,.315,.413,.314),ncol=1)
 
mat4<-matrix(c(.318,.327,.295,.273,.286,.236,.264,.236,.295,.315,.423,.314),ncol=1)

 res3<- lapply(paste0("mat",1:4),function(i) 
data.frame(date1,val=c(rep(get(i),182),head(get(i),8)),stringsAsFactors=FALSE))
  #change from 1:124

str(res3)
#List of 4
# $ :'data.frame':    2192 obs. of  2 variables:
 # ..$ date1: chr [1:2192] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" 
...
 # ..$ val  : num [1:2192] 0.314 0.314 0.273 0.273 0.236 0.236 0.236 0.236 
0.273 0.314 ...
 #$ :'data.frame':    2192 obs. of  2 variables:
 # ..$ date1: chr [1:2192] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" 
...
 # ..$ val  : num [1:2192] 0.314 0.325 0.246 0.273 0.226 0.236 0.249 0.236 
0.289 0.314 ...
 #$ :'data.frame':    2192 obs. of  2 variables:
  #..$ date1: chr [1:2192] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" 
...
  #..$ val  : num [1:2192] 0.314 0.32 0.275 0.273 0.236 0.232 0.236 0.231 0.273 
0.315 ...
 #$ :'data.frame':    2192 obs. of  2 variables:
  #..$ date1: chr [1:2192] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" 
...
 # ..$ val  : num [1:2192] 0.318 0.327 0.295 0.273 0.286 0.236 0.264 0.236 
0.295 0.315 ...
 head(res3[[1]])
#   date1   val
#1 1991.01.01 0.314
#2 1991.01.02 0.314
#3 1991.01.03 0.273
#4 1991.01.04 0.273
#5 1991.01.05 0.236
#6 1991.01.06 0.236


I am not sure whether you could do it in one step as memory might be an issue 
here.  You could split this to 2-3 times:
1:25, 24:50, and so on..
A.K.






From: eliza botto 
To: "smartpink...@yahoo.com"  
Sent: Wednesday, February 13, 2013 11:44 AM
Subject: RE: date and matrices



Dear Arun,
When i save the matrices in text file there are inverted commas on each date 
and value like the following
"1991.01.01" "0.314"
"1991.01.02" "0.314"
"1991.01.03" "0.273"
"1991.01.04" "0.273"
"1991.01.05" "0.236"
"1991.01.06" "0.236"
how to eliminate these inverted commas?
1991.01.01 0.314
1991.01.02 0.314
1991.01.03 0.273
1991.01.04 0.273
1991.01.05 0.236
1991.01.06 0.236
thanks
elisa


> Date: Wed, 13 Feb 2013 06:53:43 -0800
> From: smartpink...@yahoo.com
> Subject: Re: date and matrices
> To: eliza_bo...@hotmail.com
> CC: r-help@r-project.org
> 
> Hi,
> 
> Just forgot about one thing:
> With more matrices with one column:
> One way would be to combine them as a single matrix:
> date1<-format(seq.Date(as.Date("1991.1.1",format="%Y.%m.%d"),as.Date("1996.12.31",format="%Y.%m.%d"),by="day"),"%Y.%m.%d")
> 
> mat1<-matrix(c(.314,.314,.273,.273,.236,.236,.236,.236,.273,.314,.403,.314),ncol=1)
> mat2<-matrix(c(.314,.325,.246,.273,.226,.236,.249,.236,.289,.314,.403,.314),ncol=1)
> mat3<- cbind(mat1,mat2) #if this is not feasible, tell me how these matrices 
> are named
> 
>  res2<- lapply(seq_len(ncol(mat3)),function(i) 
> cbind(date1,c(rep(mat3[,i],182),head(mat3[,i],8
> head(res2[[1]])
> # date1   
> #[1,] "1991.01.01" "0.314"
> #[2,] "1991.01.02" "0.314"
> #[3,] "1991.01.03" "0.273"
> #[4,] "1991.01.04" "0.273"
> #[5,] "1991.01.05" "0.236"
> #[6,] "1991.01.06" "0.236"
>  tail(res2[[1]])
> #    date1   
> #[2187,] "1996.12.26" "0.273"
> #[2188,] "1996.12.27" "0.273"
> #[2189,] "1996.12.28" "0.236"
> #[2190,] "1996.12.29" "0.236"
> #[2191,] "1996.12.30" "0.236"
> #[2192,] "1996.12.31" "0.236"
> 
> 
> A.K.
> 
> 
> From: eliza botto 
> To: "smartpink...@yahoo.com"  
> Sent: Wednesday, February 13, 2013 9:01 AM
> Subject: date and matrices
> 
> 
> 
> Dear Arun,
> [text files is also attached to be used in case format is changed]
> i have 124 matrices with 12rows and 1 column. In all those 124 columns there 
> are values of a certain quantity called disty. what i want to do is the 
> following
> 1- insert a date column in each matrix in such a way that date should start 
> from 1991. 1. 1 (. m. d) and should end at
> 1996.12.31.
> 2- against each date i want to put the values of quantity disty and as i have 
> only 12 values of disty i want to start from the
> first value after very 12 days.
> more precisely, if i have a matrix like this
> mat1
>   [,1]
>  .314
>  .314
>  .273
>  .273
>  .236
>  .236
>  .236
>  .236
>  .273
>  .314
>  .403
>  .314
> 
> i want it to be like the following one
>  1911. 1. 1  .314
>  1911. 1. 2  .314
>  1911. 1. 3  .273
>  1911. 1. 4  .273
>  1911. 1. 5  .236
>  1911. 1. 6  .236
>  1911. 1. 7  .236
>  1911. 1. 8  .236
>  1911. 1. 9  .273
>  1911. 1.10 2.314
>  1911. 1.11    12.403
>  1911. 1.12  

Re: [R] date and matrices

2013-02-13 Thread arun
Dear Elisa,
When you save it as matrix, if there is atleast one column with character 
class, others will be converted to that class.  It would be better to store it 
as data.frame


 res2<-lapply(seq_len(ncol(mat3)),function(i) 
data.frame(date1,val=c(rep(mat3[,i],182),head(mat3[,i],8)),stringsAsFactors=FALSE))
 str(res2)
#List of 2
# $ :'data.frame':    2192 obs. of  2 variables:
 # ..$ date1: chr [1:2192] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" 
...
 # ..$ val  : num [1:2192] 0.314 0.314 0.273 0.273 0.236 0.236 0.236 0.236 
0.273 0.314 ...
# $ :'data.frame':    2192 obs. of  2 variables:
 # ..$ date1: chr [1:2192] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" 
...
  #..$ val  : num [1:2192] 0.314 0.325 0.246 0.273 0.226 0.236 0.249 0.236 
0.289 0.314 ...
head(res2[[1]])
#   date1   val
#1 1991.01.01 0.314
#2 1991.01.02 0.314
#3 1991.01.03 0.273
#4 1991.01.04 0.273
#5 1991.01.05 0.236
#6 1991.01.06 0.236

If I convert this back to matrix.
str(lapply(res2,as.matrix))
List of 2
 $ : chr [1:2192, 1:2] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:2] "date1" "val"
 $ : chr [1:2192, 1:2] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:2] "date1" "val"  # both are now of class "chr"



A.K.




From: eliza botto 
To: "smartpink...@yahoo.com"  
Sent: Wednesday, February 13, 2013 11:44 AM
Subject: RE: date and matrices



Dear Arun,
When i save the matrices in text file there are inverted commas on each date 
and value like the following
"1991.01.01" "0.314"
"1991.01.02" "0.314"
"1991.01.03" "0.273"
"1991.01.04" "0.273"
"1991.01.05" "0.236"
"1991.01.06" "0.236"
how to eliminate these inverted commas?
1991.01.01 0.314
1991.01.02 0.314
1991.01.03 0.273
1991.01.04 0.273
1991.01.05 0.236
1991.01.06 0.236
thanks
elisa


> Date: Wed, 13 Feb 2013 06:53:43 -0800
> From: smartpink...@yahoo.com
> Subject: Re: date and matrices
> To: eliza_bo...@hotmail.com
> CC: r-help@r-project.org
> 
> Hi,
> 
> Just forgot about one thing:
> With more matrices with one column:
> One way would be to combine them as a single matrix:
> date1<-format(seq.Date(as.Date("1991.1.1",format="%Y.%m.%d"),as.Date("1996.12.31",format="%Y.%m.%d"),by="day"),"%Y.%m.%d")
> 
> mat1<-matrix(c(.314,.314,.273,.273,.236,.236,.236,.236,.273,.314,.403,.314),ncol=1)
> mat2<-matrix(c(.314,.325,.246,.273,.226,.236,.249,.236,.289,.314,.403,.314),ncol=1)
> mat3<- cbind(mat1,mat2) #if this is not feasible, tell me how these matrices 
> are named
> 
>  res2<- lapply(seq_len(ncol(mat3)),function(i) 
> cbind(date1,c(rep(mat3[,i],182),head(mat3[,i],8
> head(res2[[1]])
> # date1   
> #[1,] "1991.01.01" "0.314"
> #[2,] "1991.01.02" "0.314"
> #[3,] "1991.01.03" "0.273"
> #[4,] "1991.01.04" "0.273"
> #[5,] "1991.01.05" "0.236"
> #[6,] "1991.01.06" "0.236"
>  tail(res2[[1]])
> #    date1   
> #[2187,] "1996.12.26" "0.273"
> #[2188,] "1996.12.27" "0.273"
> #[2189,] "1996.12.28" "0.236"
> #[2190,] "1996.12.29" "0.236"
> #[2191,] "1996.12.30" "0.236"
> #[2192,] "1996.12.31" "0.236"
> 
> 
> A.K.
> 
> 
> From: eliza botto 
> To: "smartpink...@yahoo.com"  
> Sent: Wednesday, February 13, 2013 9:01 AM
> Subject: date and matrices
> 
> 
> 
> Dear Arun,
> [text files is also attached to be used in case format is changed]
> i have 124 matrices with 12rows and 1 column. In all those 124 columns there 
> are values of a certain quantity called disty. what i want to do is the 
> following
> 1- insert a date column in each matrix in such a way that date should start 
> from 1991. 1. 1 (. m. d) and should end at
> 1996.12.31.
> 2- against each date i want to put the values of quantity disty and as i have 
> only 12 values of disty i want to start from the
> first value after very 12 days.
> more precisely, if i have a matrix like this
> mat1
>   [,1]
>  .314
>  .314
>  .273
>  .273
>  .236
>  .236
>  .236
>  .236
>  .273
>  .314
>  .403
>  .314
> 
> i want it to be like the following one
>  1911. 1. 1  .314
>  1911. 1. 2  .314
>  1911. 1. 3  .273
>  1911. 1. 4  .273
>  1911. 1. 5  .236
>  1911. 1. 6  .236
>  1911. 1. 7  .236
>  1911. 1. 8  .236
>  1911. 1. 9  .273
>  1911. 1.10 2.314
>  1911. 1.11    12.403
>  1911. 1.12  .314
>  1911. 1.11  .314
>  1911. 1.12  .314
>  1911. 1.13  .273
>  1911. 1.14  .273
>  1911. 1.15  .236
>  1911. 1.16  .236
>  1911. 1.17  .236
>  1911. 1.18  .236
>  1911. 1.19  .273
>  1911. 1.20 2.314
>  1911. 1.21    12.403
>  1911. 1.22  .314
>  1911. 1.23  .314
>  1911. 1.24  .314
>  1911. 1.25  .273
>  1911. 1.26  .273
>  1911. 1.27  .236
>  1911. 1.28  .236
>  1911. 1.29  .236
>  1911. 1.30  .236
>  1911. 1.31  .273
>  1911. 2. 1 2.314

Re: [R] CARET: Any way to access other tuning parameters?

2013-02-13 Thread Max Kuhn
James,

You really need to read the documentation. Almost every question that you
have has been addressed in the existing material. For this one, there is a
section on custom models here:

   http://caret.r-forge.r-project.org/training.html

Max


On Wed, Feb 13, 2013 at 9:58 AM, James Jong  wrote:

> The documentation for caret::train shows a list of parameters that one can
>  tune for each method classification/regression method. For example, for
> the method randomForest one can tune mtry in the call to train. But the
>  function call to train random forests in the original package has many
> other parameters, e.g. sampsize, maxnodes, etc.
>
> Is there **any** way to access these parameters using train in caret? (Is
> the function caret::createGrid limited to the list of parameters specified
> in the caret documentation, it's not super clear if the list of parameter
> is for all the caret APIs).
>
> Thanks,
>
> James,
>
> [[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.
>



-- 

Max

[[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] WriteXLS: 'object not found' error within function

2013-02-13 Thread Scott Robinson
Dear All,

I am using WriteXLS to write tables with multiple sheets with the command:

WriteXLS("tables", ExcelFileName = fileName, SheetNames = tableList, perl = 
"perl",
   verbose = FALSE, Encoding = c("UTF-8", "latin1"),
   row.names = TRUE, col.names = TRUE,
   AdjWidth = TRUE, AutoFilter = FALSE, BoldHeaderRow = FALSE,
   FreezeRow = 0, FreezeCol = 0,
   envir = parent.frame())


...where "tables" is the name of a list of data.frames which are the tables to 
go into my sheets. I am having no problem running my code unless it is within a 
function in which case I get the error:

"Error in get(as.character(x), envir = envir) : object 'tables' not found"

I have checked that there is not an issue with scope using these two lines 
within my function immediately before calling the WriteXLS function:

print(class(tables))
flush.console()
[1] "list"


At least I would have thought this would have ruled out any scope-related 
issues. Has anyone else had this problem or have any ideas why it might be 
happening?

Thanks,

Scott


PS here is the function in full:

makeTables <- function(design, designInfo, oldMatrix, matrix, annot, tableList)
{
rownames(design) <- designInfo[,1]

fit <- lmFit(matrix, design)
fit <- eBayes(fit)

tables<-list()

for (i in 1:length(tableList))
{
table <- makeTable(oldMatrix, matrix, annot, fit, tableList[i])
print(paste(tableList[i], "=", sep=""))
print(table)
tables[[i]] <- table
}

#Saving bit (set to FALSE if not using)
saveIt <- TRUE

if(saveIt)
{
fileName <- 
paste0("~",paste(colnames(design)[2:length(colnames(design))], collapse = 
"+"),".xls")

print(paste("sheetnames=",length(tableList),

print(class(tables))
flush.console()

WriteXLS("tables", ExcelFileName = fileName, SheetNames = tableList, 
perl = "perl",
   verbose = FALSE, Encoding = c("UTF-8", "latin1"),
   row.names = TRUE, col.names = TRUE,
   AdjWidth = TRUE, AutoFilter = FALSE, BoldHeaderRow = FALSE,
   FreezeRow = 0, FreezeCol = 0,
   envir = parent.frame())
}
}

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

2013-02-13 Thread Charles Determan Jr
Greetings,

I am exploring some random forest analysis methods and have come upon one
aspect I don't fully understand from any manual.  The code of interest is
as follows from the randomForest package:

myiris=cbind(iris[1:4], matrix(runif(508*nrow(iris)),nrow(iris),508))

This would be following by the rfcv() function for cross-validation but I
am confused about the former syntax.

My question is why 508?  Is this some arbitrary number that one just
chooses are is there some logic to the choice?  I have looked through the
package documentation and the runif() help which tells me that runif(n,
min=0, max=1):
n=length of observations
min&max = lower and upper limits

I still don't follow exactly what is taking place here.

Regards,
Charles

[[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] CARET: Any way to access other tuning parameters?

2013-02-13 Thread James Jong
Thank you David and Max,

@David -  Thanks, I am already aware that I cannot *directly* pass
arguments to train to specify parameters controlling the method, and that
one has to pass those parameters via the tuneGrid argument to caret::train.
My question is about the method parameters that are *not* listed in the
CARET documentation but that the *original methods* support, such as
sampsize, nodesize (i.e. not just mtry) for randomForest.

Also, I don't think trainControl and preProcess are related to my question.
The function trainControl specifies the parameters that train uses for
model selection and preProcess is about preparing the data (regardless of
whatever method I use later for class or reg.)

@Max - Thanks a lot for your help. I have already been using that website
as a reference, and it's incredibly helpful. I have also been experimenting
with tuneGrid already. My question was specifically if tuneGrid (or caret
in general) supports passing method parameters to the method functions from
each package other than those listed in the CARET documentation (e.g. I
would like to specify sampsize and nodesize for randomForest, and not just
mtry).

Thanks,

James






On Wed, Feb 13, 2013 at 1:07 PM, Max Kuhn  wrote:

> James,
>
> You really need to read the documentation. Almost every question that you
> have has been addressed in the existing material. For this one, there is a
> section on custom models here:
>
>http://caret.r-forge.r-project.org/training.html
>
> Max
>
>
> On Wed, Feb 13, 2013 at 9:58 AM, James Jong wrote:
>
>> The documentation for caret::train shows a list of parameters that one can
>>  tune for each method classification/regression method. For example, for
>> the method randomForest one can tune mtry in the call to train. But the
>>  function call to train random forests in the original package has many
>> other parameters, e.g. sampsize, maxnodes, etc.
>>
>> Is there **any** way to access these parameters using train in caret? (Is
>> the function caret::createGrid limited to the list of parameters specified
>> in the caret documentation, it's not super clear if the list of parameter
>> is for all the caret APIs).
>>
>> Thanks,
>>
>> James,
>>
>> [[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.
>>
>
>
>
> --
>
> Max
>

[[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] CARET: Any way to access other tuning parameters?

2013-02-13 Thread Max Kuhn
@Max - Thanks a lot for your help. I have already been using that website
> as a reference, and it's incredibly helpful. I have also been experimenting
> with tuneGrid already. My question was specifically if tuneGrid (or caret
> in general) supports passing method parameters to the method functions from
> each package other than those listed in the CARET documentation (e.g. I
> would like to specify sampsize and nodesize for randomForest, and not just
> mtry).
>
>
Yes. A custom method is how you do that.


> Thanks,
>
> James
>
>
>
>
>
>
> On Wed, Feb 13, 2013 at 1:07 PM, Max Kuhn  wrote:
>
>> James,
>>
>> You really need to read the documentation. Almost every question that you
>> have has been addressed in the existing material. For this one, there is a
>> section on custom models here:
>>
>>http://caret.r-forge.r-project.org/training.html
>>
>> Max
>>
>>
>> On Wed, Feb 13, 2013 at 9:58 AM, James Jong wrote:
>>
>>> The documentation for caret::train shows a list of parameters that one
>>> can
>>>  tune for each method classification/regression method. For example, for
>>> the method randomForest one can tune mtry in the call to train. But the
>>>  function call to train random forests in the original package has many
>>> other parameters, e.g. sampsize, maxnodes, etc.
>>>
>>> Is there **any** way to access these parameters using train in caret? (Is
>>> the function caret::createGrid limited to the list of parameters
>>> specified
>>> in the caret documentation, it's not super clear if the list of parameter
>>> is for all the caret APIs).
>>>
>>> Thanks,
>>>
>>> James,
>>>
>>> [[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.
>>>
>>
>>
>>
>> --
>>
>> Max
>>
>
>


-- 

Max

[[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] WriteXLS: 'object not found' error within function

2013-02-13 Thread Marc Schwartz

On Feb 13, 2013, at 12:07 PM, Scott Robinson  
wrote:

> Dear All,
> 
> I am using WriteXLS to write tables with multiple sheets with the command:
> 
> WriteXLS("tables", ExcelFileName = fileName, SheetNames = tableList, perl = 
> "perl",
>   verbose = FALSE, Encoding = c("UTF-8", "latin1"),
>   row.names = TRUE, col.names = TRUE,
>   AdjWidth = TRUE, AutoFilter = FALSE, BoldHeaderRow = FALSE,
>   FreezeRow = 0, FreezeCol = 0,
>   envir = parent.frame())
> 
> 
> ...where "tables" is the name of a list of data.frames which are the tables 
> to go into my sheets. I am having no problem running my code unless it is 
> within a function in which case I get the error:
> 
> "Error in get(as.character(x), envir = envir) : object 'tables' not found"
> 
> I have checked that there is not an issue with scope using these two lines 
> within my function immediately before calling the WriteXLS function:
> 
> print(class(tables))
> flush.console()
> [1] "list"
> 
> 
> At least I would have thought this would have ruled out any scope-related 
> issues. Has anyone else had this problem or have any ideas why it might be 
> happening?
> 
> Thanks,
> 
> Scott
> 
> 
> PS here is the function in full:
> 
> makeTables <- function(design, designInfo, oldMatrix, matrix, annot, 
> tableList)
> {
> rownames(design) <- designInfo[,1]
> 
> fit <- lmFit(matrix, design)
> fit <- eBayes(fit)
> 
> tables<-list()
> 
>   for (i in 1:length(tableList))
>   {
>   table <- makeTable(oldMatrix, matrix, annot, fit, tableList[i])
>   print(paste(tableList[i], "=", sep=""))
>   print(table)
>   tables[[i]] <- table
>   }
> 
> #Saving bit (set to FALSE if not using)
> saveIt <- TRUE
> 
>   if(saveIt)
>   {
>   fileName <- 
> paste0("~",paste(colnames(design)[2:length(colnames(design))], collapse = 
> "+"),".xls")
> 
>   print(paste("sheetnames=",length(tableList),
> 
>   print(class(tables))
>   flush.console()
> 
>   WriteXLS("tables", ExcelFileName = fileName, SheetNames = tableList, 
> perl = "perl",
>   verbose = FALSE, Encoding = c("UTF-8", "latin1"),
>   row.names = TRUE, col.names = TRUE,
>   AdjWidth = TRUE, AutoFilter = FALSE, BoldHeaderRow = FALSE,
>   FreezeRow = 0, FreezeCol = 0,
>   envir = parent.frame())
>   }
> }


Hi Scott,

In the call to WriteXLS() within your function, leave out the final argument 
line 'envir = parent.frame()'. That is causing WriteXLS() to look for "tables" 
in the environment in which your function makeTables() is being called and of 
course, "tables" does not exist there, but only within the scope of 
makeTables(). Leaving the argument out allows WriteXLS() to look for "tables" 
within the environment in which it is called.

This is a nuance when using environments within functions. The same thing 
commonly happens when folks use the 'subset' argument with modeling functions 
that are themselves called within a function body.

As an example with WriteXLS():

test <- function() {
   localData <- split(iris, iris$Species)
   WriteXLS("localData", "LocalData.xls", envir = parent.frame())
}


> test()
Error in get(as.character(x), envir = envir) : 
  object 'localData' not found


localData <- split(iris, iris$Species)

test() # Works fine


rm(localData)


> test()
Error in get(as.character(x), envir = envir) : 
  object 'localData' not found


test <- function() {
  localData <- split(iris, iris$Species)
  WriteXLS("localData", "LocalData.xls")
}


test() # Works fine


Hope that clarifies.

Regards,

Marc Schwartz

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


Re: [R] densityplot(~x+y) for vectors of different lengths does what?

2013-02-13 Thread ilai
Hmmm... is this a (unknown or even a) bug ? Not sure this is what OP was
getting at and I haven't gone through the lattice docs to see if this is
mentioned, but, with unequal sizes the extended formula is not producing
what one (or at least I) might expect:

 require(latticeExtra)
set.seed(4321) ; x <- rnorm(20) ; y <- rnorm(10 , 50)
c(dsp <- densityplot( ~ x + y) ,
   densityplot( ~ data , groups = which , make.groups(x, y) ) )

# because
 all.equal(dsp$panel.args[[1]]$x, c(x, y) )
# but regroups ignoring original lengths
summary(dsp$panel.args.common$groups)

An obvious BTW: problem persists using n={19,11} or n = {20,11}

sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
attached base packages:
[1] grDevices utils datasets  stats graphics  methods   base

other attached packages:
[1] nlme_3.1-104latticeExtra_0.6-24 RColorBrewer_1.0-5
[4] lattice_0.20-10


On Wed, Feb 13, 2013 at 6:38 AM, Michael Stob  wrote:

> densityplot(~x+y) does what I expect it to do if x and y have equal
> length.  I know how to get what I want if x and y have different lengths.
> But what is this actually doing if x and y have different lengths?The
> relevant example is
>
> x=rnorm(10)
> y=rnorm(50,1)
> densityplot(~x+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.
>
>

[[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] seasonal sum and mean and combine multiple, different data frames in .csv

2013-02-13 Thread arun
Hi Irucka,

No problem.

I guess this could be done using:
Sample data:
Dailydo<- structure(list(Date = structure(c(11231, 11232, 11233, 11234, 
11235, 11236, 11207, 11208, 11209, 11179, 11180, 11181, 11151, 
11152, 11123, 11093, 11064, 11065, 11035, 11036, 11008, 11009, 
10979, 10980, 11347, 11348, 11380, 11381, 11410, 11406, 11438, 
11439, 11470, 11502, 11528, 11560, 11561, 11593, 11594, 11621, 
11622, 11654, 11685, 11992, 11962, 11963, 11964, 11965, 11966, 
11937, 11938, 11939, 11909, 11910, 11911, 11881, 11882, 11853, 
11823, 11794, 11795, 11765, 11766, 11739, 11740, 11710, 11711, 
12077, 12078, 12110, 12111, 12140, 12136, 12168, 12169, 12200, 
12232, 12258, 12290, 12291, 12323, 12324, 12351, 12352, 12384, 
12415), class = "Date"), FluxDay = c(1512.2498, 1447.5309, 1410.6735, 
1366.4421, 1326.6835, 1300.182, 1248.2897, 1193.732, 1106.1205, 
1074.7132, 1037.1902, 1037.1479, 1104.1739, 1073.765, 1047.021, 
1136.9787, 988.592, 988.6488, 939.9868, 810.8965, 812.3177, 811.6353, 
801.9529, 842.2798, 812.4434, 792.9126, 823.3818, 738.851, 843.5701, 
782.4434, 792.9126, 783.3818, 793.851, 729.5701, 792.4434, 712.9126, 
793.3818, 783.851, 723.5701, 792.9126, 793.3818, 783.851, 743.5701, 
812.2498, 1437.5309, 1415.6735, 1368.4421, 1186.6835, 1188.182, 
1286.2897, 1147.732, 1186.1205, 987.7132, 1147.1902, 1137.1479, 
1204.1739, 973.765, 847.021, 1036.9787, 1088.592, 1188.6488, 
986.9868, 846.8965, 827.3177, 813.6353, 811.9529, 849.2798, 832.4434, 
782.9126, 835.3818, 745.851, 847.5701, 792.4434, 744.9126, 795.3818, 
976.851, 829.5701, 992.4434, 1112.9126, 893.3818, 783.851, 763.5701, 
798.9126, 795.3818, 763.851, 783.5701)), .Names = c("Date", "FluxDay"
), row.names = c(NA, -86L), class = "data.frame")

str(Dailydo)
#'data.frame':    86 obs. of  2 variables:
# $ Date   : Date, format: "2000-10-01" "2000-10-02" ...
# $ FluxDay: num  1512 1448 1411 1366 1327 ...


DailydoSum<-funSumSeason(Dailydo)# your function
DailydoSum
#    season  FluxDay
#1    2000 Fall 8363.762
#2  2000 Spring 4161.240
#3  2000 Summer 8875.132
#4  2000 Winter 5019.069
#5    2001 Fall 3113.716
#6  2001 Spring 3099.716
#7  2001 Summer 3806.159
#8  2001 Winter 4793.602
#9    2002 Fall 7408.762
#10 2002 Spring 4161.240
#11 2002 Summer 9070.132
#12 2002 Winter 5136.069
#13   2003 Fall 3141.716
#14 2003 Spring 3346.716
#15 2003 Summer 4546.159
#16 2003 Winter 4836.602


Suppose if I add 1 to each of Fall Season year:
DailydoSum$season[grep("Fall",DailydoSum$season)]<- 
paste(as.numeric(gsub("\\D+","",DailydoSum$season[grep("Fall",DailydoSum$season)]))+1,"Fall")
DailydoSum
#    season  FluxDay
#1    2001 Fall 8363.762
#2  2000 Spring 4161.240
#3  2000 Summer 8875.132
#4  2000 Winter 5019.069
#5    2002 Fall 3113.716
#6  2001 Spring 3099.716
#7  2001 Summer 3806.159
#8  2001 Winter 4793.602
#9    2003 Fall 7408.762
#10 2002 Spring 4161.240
#11 2002 Summer 9070.132
#12 2002 Winter 5136.069
#13   2004 Fall 3141.716
#14 2003 Spring 3346.716
#15 2003 Summer 4546.159
#16 2003 Winter 4836.602


#split based on year
sapply(split(DailydoSum, as.numeric(gsub("\\D+","",DailydoSum$season))), 
function(x)  Sum=sum(x[,2]))
 #    2000  2001  2002  2003  2004 
#18055.442 20063.238 21481.157 20138.238  3141.716 

In this dataset, some year doesn't have all the Seasons, so the value is less.

I hope it hleps.
A.K.




- Original Message -
From: "iruc...@mail2world.com" 
To: smartpink...@yahoo.com
Cc: 
Sent: Wednesday, February 13, 2013 1:27 PM
Subject: Re: seasonal sum and mean and combine multiple, different data frames 
in .csv

Hi Arun, thank-you for your assistance.

The code that you suggested is useful to calculate the sum of the calendar 
year, but I need to be able to also sum the water year as well (October to 
September).

For example, the sum of 2000 Fall, 2001 Winter, 2001 Spring, and 2001 Summer 
would represent the sum for the 2001 water year.

Can you offer any advice on summing up the seasons from October of the 
preceding year to September of the next year?

funMeanSeason <- function(DF, FUN = mean){
month <- as.integer(format(DF$Date, format="%m"))
year <- format(DF$Date, format="%Y")
DF$season<- NA
DF$season[month %in% 10:12] <- paste(year[month %in% 10:12], "Fall")
DF$season[month %in% 1:3] <- paste(year[month %in% 1:3], "Winter")
DF$season[month %in% 4:6] <- paste(year[month %in% 4:6], "Spring")
DF$season[month %in% 7:9] <- paste(year[month %in% 7:9], "Summer")
aggregate(FluxDay ~ season, data=DF, FUN = FUN) # changed here
}

ju <- funMeanSeason(Dailydo) # this provides the seasonal mean


funSumSeason <- function(DF, FUN = sum){
month <- as.integer(format(DF$Date, format="%m"))
year <- format(DF$Date, format="%Y")
DF$season<- NA
DF$season[month %in% 10:12] <- paste(year[month %in% 10:12], "Fall")
DF$season[month %in% 1:3] <- paste(year[month %in% 1:3], "Winter")
DF$season[month %in% 4:6] <- paste(year[month %in% 4:6], "Spring")
DF$season[month %in% 7:9] <- paste(year[month %in% 7:9], "Summer")
aggregate(FluxDay ~

Re: [R] How to install .tar.gz source package in Windows XP 32-bit operational system

2013-02-13 Thread David Winsemius

On Feb 13, 2013, at 9:25 AM, Marino David wrote:

> Dear all mailing listers,
> 
> I failed in install source packages in Windows system. I have installed
> Rtools in order to install the source package based on the discussion
> available on the following link:
> http://r.789695.n4.nabble.com/Installing-a-Package-tar-gz-in-windows-td3411393.html.
> By the way, only installing the Rtools is ok, isn't it? Do I need to run
> the Rtools?
> 
>> install.packages("adapt_1.0-4.tar.gz", type="source", repos=NULL)

http://cran.r-project.org/web/packages/adapt/


> * installing *source* package 'adapt' ...
> ** Creating default NAMESPACE file
> ** libs
> ERROR: compilation failed for package 'adapt'
> * removing 'C:/Program Files/R/R-2.15.2/library/adapt'
> warning£º
> 1: running command'C:/PROGRA~1/R/R-215~1.2/bin/i386/R CMD INSTALL -l
> "C:/Program Files/R/R-2.15.2/library"   "adapt_1.0-4.tar.gz"'had
> status 1
> 
> 2: In install.packages("adapt_1.0-4.tar.gz", type = "source", repos = NULL)
> :
> installation of package ¡®adapt_1.0-4.tar.gz¡¯ had non-zero exit status
> 
> 
> Any suggestion will be greatly appreciated.
> 
> Kind regards,
> 
> David
> 
>   [[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.

David Winsemius
Alameda, CA, USA

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

2013-02-13 Thread Duncan Murdoch

On 13/02/2013 1:26 PM, Charles Determan Jr wrote:

Greetings,

I am exploring some random forest analysis methods and have come upon one
aspect I don't fully understand from any manual.  The code of interest is
as follows from the randomForest package:

myiris=cbind(iris[1:4], matrix(runif(508*nrow(iris)),nrow(iris),508))

This would be following by the rfcv() function for cross-validation but I
am confused about the former syntax.

My question is why 508?  Is this some arbitrary number that one just
chooses are is there some logic to the choice?  I have looked through the
package documentation and the runif() help which tells me that runif(n,
min=0, max=1):
n=length of observations
min&max = lower and upper limits

I still don't follow exactly what is taking place here.


The code constructs a 508 column matrix and fills it with random uniform 
values.  508*nrow(iris) is just a count of how many entries there are in 
the matrix, it has nothing to do with runif() per se.


So you'll need to look elsewhere to find why they thought they needed 
508 columns.


Duncan Murdoch

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


Re: [R] How to install .tar.gz source package in Windows XP 32-bit operational system

2013-02-13 Thread David Winsemius

On Feb 13, 2013, at 12:09 PM, David Winsemius wrote:

> 
> On Feb 13, 2013, at 9:25 AM, Marino David wrote:
> 
>> Dear all mailing listers,
>> 
>> I failed in install source packages in Windows system. I have installed
>> Rtools in order to install the source package based on the discussion
>> available on the following link:
>> http://r.789695.n4.nabble.com/Installing-a-Package-tar-gz-in-windows-td3411393.html.
>> By the way, only installing the Rtools is ok, isn't it? Do I need to run
>> the Rtools?
>> 
>>> install.packages("adapt_1.0-4.tar.gz", type="source", repos=NULL)
> 
> http://cran.r-project.org/web/packages/adapt/

Try searching MarkMail for:  install adapt from sources

-- 
David.
> 
> 
>> * installing *source* package 'adapt' ...
>> ** Creating default NAMESPACE file
>> ** libs
>> ERROR: compilation failed for package 'adapt'
>> * removing 'C:/Program Files/R/R-2.15.2/library/adapt'
>> warning£º
>> 1: running command'C:/PROGRA~1/R/R-215~1.2/bin/i386/R CMD INSTALL -l
>> "C:/Program Files/R/R-2.15.2/library"   "adapt_1.0-4.tar.gz"'had
>> status 1
>> 
>> 2: In install.packages("adapt_1.0-4.tar.gz", type = "source", repos = NULL)
>> :
>> installation of package ¡®adapt_1.0-4.tar.gz¡¯ had non-zero exit status
>> 
>> 
>> Any suggestion will be greatly appreciated.
>> 
>> Kind regards,
>> 
>> David
>> 
>>  [[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.
> 
> David Winsemius
> Alameda, CA, USA
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 install .tar.gz source package in Windows XP 32-bit operational system

2013-02-13 Thread Ista Zahn
On Wed, Feb 13, 2013 at 3:09 PM, David Winsemius  wrote:
>
> On Feb 13, 2013, at 9:25 AM, Marino David wrote:
>
>> Dear all mailing listers,
>>
>> I failed in install source packages in Windows system. I have installed
>> Rtools in order to install the source package based on the discussion
>> available on the following link:
>> http://r.789695.n4.nabble.com/Installing-a-Package-tar-gz-in-windows-td3411393.html.
>> By the way, only installing the Rtools is ok, isn't it? Do I need to run
>> the Rtools?
>>
>>> install.packages("adapt_1.0-4.tar.gz", type="source", repos=NULL)
>
> http://cran.r-project.org/web/packages/adapt/

Presumably the OP knew this, since there were able to obtain the
package source already. However, reading the README file in the
package source is instructive. Pasted here for convenience to the OP:

"
This code contains an S function and supporting C and Fortran code for
adaptive quadrature.  The underlyling fortran code is purported to
work in from 2 to 20 dimensions.  The code is set up to dynamically
load from a central library area.  If you can not do dynamic loading,
you may need to build a staticly loaded version.  The adapt S function
calls load.if.needed to do the dynamic loading.  You will have to
change the functions used here (probably to call library.dynam).

To install the source, type
make
in this directory.
Move the resulting sadapt.o into (say ~s/library/cmu ).  Read the file
adapt.SS into S.  Two functions (adapt, and load.if.needed) will be
created.  Move these into ~/library/cmu/.Data.  Finally move
./.Data/.Help/adapt into ~s/library/cmu/.Data/.Help/adapt.

S code written by Michael Meyer (mi...@andrew.cmu.edu).
October, 1989."

So this looks really old. If I were the OP I would start looking for
another package.

Best,
Ista

>
>
>> * installing *source* package 'adapt' ...
>> ** Creating default NAMESPACE file
>> ** libs
>> ERROR: compilation failed for package 'adapt'
>> * removing 'C:/Program Files/R/R-2.15.2/library/adapt'
>> warning£º
>> 1: running command'C:/PROGRA~1/R/R-215~1.2/bin/i386/R CMD INSTALL -l
>> "C:/Program Files/R/R-2.15.2/library"   "adapt_1.0-4.tar.gz"'had
>> status 1
>>
>> 2: In install.packages("adapt_1.0-4.tar.gz", type = "source", repos = NULL)
>> :
>> installation of package ¡®adapt_1.0-4.tar.gz¡¯ had non-zero exit status
>>
>>
>> Any suggestion will be greatly appreciated.
>>
>> Kind regards,
>>
>> David
>>
>>   [[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.
>
> David Winsemius
> Alameda, CA, USA
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] R2OpenBUGS quesion

2013-02-13 Thread Paul J Ossenbruggen
I recently installed OpenBUGS322 and obtained the same error using the
schools example. I suspect that I will run into difficulties with other
examples. I want to download the older version but the BUGS website does not
seem to have  OpenBUGS321 available any longer.

Are there patches for  OpenBUGS322 or any other location to obtain 
OpenBUGS321?

Any suggestion will be greatly appreciated.

Paul



--
View this message in context: 
http://r.789695.n4.nabble.com/R2OpenBUGS-quesion-tp4636392p4658464.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] R2OpenBUGS quesion

2013-02-13 Thread Dan Polhamus
There is an archive link at the bottom of the downloads page from which you
can grab 321.
Dan


On Wed, Feb 13, 2013 at 3:53 PM, Paul J Ossenbruggen [via R] <
ml-node+s789695n4658464...@n4.nabble.com> wrote:

> I recently installed OpenBUGS322 and obtained the same error using the
> schools example. I suspect that I will run into difficulties with other
> examples. I want to download the older version but the BUGS website does
> not seem to have  OpenBUGS321 available any longer.
>
> Are there patches for  OpenBUGS322 or any other location to obtain
>  OpenBUGS321?
>
> Any suggestion will be greatly appreciated.
>
> Paul
>
> --
>  If you reply to this email, your message will be added to the discussion
> below:
> http://r.789695.n4.nabble.com/R2OpenBUGS-quesion-tp4636392p4658464.html
>  To start a new topic under R help, email
> ml-node+s789695n789696...@n4.nabble.com
> To unsubscribe from R2OpenBUGS quesion, click 
> here
> .
> NAML
>



-- 
Daniel G Polhamus, PhD
Metrum Research Group, LLC
2 Tunxis Rd, Suite 112
Tariffville, CT 06081
(888) 308-7049 ext 403




--
View this message in context: 
http://r.789695.n4.nabble.com/R2OpenBUGS-quesion-tp4636392p4658465.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

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


Re: [R] Kernel Density estimation at specific points

2013-02-13 Thread Bert Gunter
Please learn to search!

A google search on "R density estimation" brought up the akj()
function in the quantreg package, which would seem to do what you
requested. However, I didn't look very hard and there are probably
still others in other packages.

-- Bert

On Wed, Feb 13, 2013 at 8:35 AM, Robert Duval  wrote:
> Dear All,
>
> I was wondering whether someone has created a kernel density evaluator that
> estimates the density at given specified points.
>
> The regular density() function evaluates the kernel at equidistant points,
> but I am interested in doing such evaluation along a list of values
> existing in a pre-specified vector. (Similar to the option at() in the
> kdensity command in Stata).
>
> This question has appeared before in the R-list, most recently in 2011 in :
>
> http://tolstoy.newcastle.edu.au/R/e14/help/11/06/5232.html
>
> There another list member suggested programming a home-made evaluator.
> While the posted solution works, it is not as general, nor as fast as
> density(). So I was wondering whether someone had recently came up with a
> more efficient way of doing this.
>
> N.B. Many users have suggested using some sort of interpolation over the
> values provided by density(). However, for the problem I have at hand this
> is not what I need.
>
> Any help will be appreciated.
> Robert
>
> [[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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] An extended Hodgkin-Huxley model that doesn't want to work.

2013-02-13 Thread Jannetta Steyn
Hi All

I have been struggling with this model for some time now and I just can't
get it to work correctly. The messages I get when running the code is:

DLSODA-  Warning..Internal T (=R1) and H (=R2) are
  such that in the machine, T + H = T on the next step
 (H = step size). Solver will continue anyway.
In above message, R =
[1] 0 0
DINTDY-  T (=R1) illegal
In above message, R =
[1] 0.1
  T not in interval TCUR - HU (= R1) to TCUR (=R2)
In above message, R =
[1] 0 0
DINTDY-  T (=R1) illegal
In above message, R =
[1] 0.2
  T not in interval TCUR - HU (= R1) to TCUR (=R2)
In above message, R =
[1] 0 0
DLSODA-  Trouble in DINTDY.  ITASK = I1, TOUT = R1
In above message, I =
[1] 1
In above message, R =
[1] 0.2
Error in lsoda(y, times, func, parms, ...) :
  illegal input detected before taking any integration steps - see written
message



I'll first paste the formulae and then I'll paste my code. If anyone can
spot something wrong with my implementation it would really make my day.

(1)
dV/dt = (I_ext - I_int-I_coup)/C
I_ext = injected current
I_int = Sum of all ion currents
I_coup = coupling current (but we're not using it here )

(2)
I_i = g_i * m_i^pi * h_i^pi(V-E)
i identifies the ion, thus I_K would be Potassium current.

(3)
dm/dt = (m_inf*V - m)/tau_m

(4)
dh/dt = (h_inf*V-h)/tau_h

(5)
The Nernst equation is used to calculate reversal potential for Ca:
Eca = 12.2396 * log(13000/Ca2+)

(6)
d[Ca_2+]/dt = (F*I_Ca - [Ca2+] + C0)/Tau_Ca


tau_m, tau_h, m_inf and h_inf are all calculated according to formulae
provided in a paper. In my code these are calculated for the different
channels into the following variables:

CaTminf, CaThinf, CaTtaum, CaTtauh, CaSminf, CaStaum, Napminf, Naphinf,
taumna, tauhna, hminf, htaum, Kminf and Ktaum

The E (reversal potential) values for all the channels are given, except
for CaT and CaS which uses Eca as calculated in (5).

Current for Ca is calculated by summing the CaT and CaS currents, hence
CaI = gCaT*CaTm^3*CaTh*(v-Eca(v)) + gCaS*CaSm^3(v-ECa(v)


Here is the code:

library(simecol)
## Hodkin-Huxley model
HH_soma <-  function(time, init, parms) {
  with(as.list(c(init, parms)),{

# Na only used in Axon
#Naminf <-1/(1+exp(-(v+24.7)/5.29));
#Nataum <- function(v) 1.32 - (1.26/(1+exp(-(v+120)/25)));
#Nahinf <-1/(1+exp((v+489)/5.18));
#Natauh <-(0.67/(1+exp(-(v+62.9)/10))) * (1.5+(1/(1+exp((v+34.9)/36;

#PD
# mca10
CaTminf <- function(v) 1/(1+exp(-(v+25)/7.2));
# hca10
CaThinf <- function(v) 1/(1+exp(v+36)/7);
# taumca1
CaTtaum <- function(v) 55- (49.5/(1+exp(-v+58)/17));
# tauhca1
CaTtauh <- function(v) 350 - (300/(1+exp(-v+50)/16.9));

#mca20
CaSminf <- function(v) 1/(1+exp(-(v+22)/8.5));
#taumca2
CaStaum <- function(v) 16-(13.1/(1+exp(-(v+25.1)/26.4)));


# mna0
Napminf <- function(v) 1/(1+exp(-(v+26.8)/8.2));
# hna0
Naphinf <- function(v) 1/(1+exp(-(v+48.5)/5.18));

taumna <- function(v) 19.8-(10.7/(1+exp(-(v+26.5)/8.6)));
tauhna <- function(v) 666-(379/(1+exp(-(v+33.6)/11.7)));

# mh0
hminf <- function(v)  1/(1+exp(v+70)/6);
# taumh
htaum <- function(v)  272+(1499/(1+exp(-(v+42.2)/8.73)));

Kminf <- function(v)  1/(1+exp(-(v+14.2)/11.8));
Ktaum <- function(v)  7.2-(6.4/(1+exp(-(v+28.3)/19.2)));

# Reversal potential of intracellular calcium concentration
# Nernst Equation using  extracellular concentration of Ca = 13mM
# eca
ECa <- function(Ca2) 12.2396*log(13000/(Ca2));
#ECa <- function(CaI) 12.2396*log(13000/(CaI));


#Sum of all the Ca
# function(v) CaTminf(v) + CaSminf(v);
CaI <- gCaT*CaTm^3*CaTh*(v-ECa(CaI)) + gCaS*CaSm^3*(v-ECa(CaI))

#AB
#dCa2 <- (((-F*Caminf(v))-Caminf(v) + C0)/TauCa)
dCa2 <- (((-F*CaI) - Ca2 + C0)/TauCa)

# mk20
KCaminf <- function(v, Ca2) (Ca2/(Ca2+30))*(1/(1+exp(-(v+51)/8)));
# taumk
KCataum <- function(v) 90.3 - ((75.09/(1+exp(-(v+46)/22.7;

#AB
Aminf <- function(v) 1/(1+exp(-(v+27)/8.7));
Ahinf <- function(v) 1/(1+exp((v+56.9)/4.9));
Ataum <- function(v) 11.6-(10.4/(1+exp(-(v+32.9)/15.2)));
Atauh <- function(v) 38.6-(29.2*(1+exp(-(v+38.9)/26.5)));

#proc
#mp0
procminf <- function(v) 1/(1+exp((v+56.9)/4));
#taump
proctaum <- function(v) 0.5;


 dv <- (-1*(I
   + CaI
   + gNap*Napm^3*Naph*(v-ENap)
   + gh*hm*(v-Eh)
   + gK*Km^4*(v-EK)
   + gKCa * KCam^4*(v-EKCa)
   + gA*Am^4*Ah*(v-EA)
   + gL*(v-EL))
   / C);


dCaTm <- (CaTminf(v) - CaTm)/CaTtaum(v);
dCaTh <- (CaThinf(v) - CaTh)/CaTtauh(v);

dCaSm <- (CaSminf(v) - CaSm)/CaStaum(v);

dNapm <- (Napminf(v) - Napm)/taumna(v);
dNaph <- (Napminf(v) - Naph)/tauhna(v);

dhm <- (hminf(v) - hm)/htaum(v);

dKm <- (Kminf(v) - Km)/Ktaum(v);

dKCam <- (KCaminf(v, Ca2) - KCam)/KCataum(v);

dAm <- (Aminf(v) - Am)/Ataum(v);
dAh <-

[R] [lattice] display a projected map on a layerplot

2013-02-13 Thread Tom Roche

summary: I can display a lon-lat map on a lattice::layerplot, and I
can display a Lambert conformal conic (LCC) map on a spam::image, but
I can't display an LCC map on a lattice::layerplot. Example follows.
What am I doing wrong?

details:

I've been using `lattice` (via `rasterVis`) successfully to display
global atmospheric data, which works well enough (though I am
definitely intrigued by ggplot/ggmap). Particularly, I am able to
overlay my plots with maps, which is essential for the sort of work
I'm doing. However I'm currently unable to use lattice::layerplot for
some regional data projected LCC: the data plots, but I cannot get a
map to overlay. I can do this by cruder means, but would prefer to
know how to do this in lattice/rasterVis or similar (or ggplot/ggmap).
Two nearly-self-contained examples follow.

The data, ozone_lcc.nc, comes with CRAN package=M3 ... except that M3
supplies it as

system.file("extdata/ozone_lcc.ncf", package="M3")

and that extension currently causes problems for CRAN package=raster.
You can either rename that file (and put it some current working
directory), or you can download (270 kB)

https://bitbucket.org/tlroche/mozart-global-to-aqmeii-na/downloads/ozone_lcc.nc

You can then run the following code:

# start example #

library("M3")# http://cran.r-project.org/web/packages/M3/
library("rasterVis") # http://cran.r-project.org/web/packages/rasterVis/

## Use an example file with projection=Lambert conformal conic.
# lcc.file <- system.file("extdata/ozone_lcc.ncf", package="M3")
lcc.file <- "./ozone_lcc.nc" # unfortunate problem with raster::raster
lcc.proj4 <- get.proj.info.M3(lcc.file)
lcc.proj4   # debugging
# [1] "+proj=lcc +lat_1=33 +lat_2=45 +lat_0=40 +lon_0=-97 +a=637 +b=637"
# Note +lat_0=40 +lat_1=33 +lat_2=45 for maps::map@projection (below)
lcc.crs <- sp::CRS(lcc.proj4)
lcc.pdf <- "./ozone_lcc.pdf" # for output

## Read in variable with daily ozone.
# o3.raster <- raster::raster(x=lcc.file, varname="O3", crs=lcc.crs)
# ozone_lcc.nc has 4 timesteps, choose 1 at random
o3.raster <- raster::raster(x=lcc.file, varname="O3", crs=lcc.crs, level=1)
o3.raster@crs <- lcc.crs # why does the above assignment not take?
o3.raster # debugging
# class   : RasterLayer 
# band: 1 
# dimensions  : 112, 148, 16576  (nrow, ncol, ncell)
# resolution  : 1, 1  (x, y)
# extent  : 0.5, 148.5, 0.5, 112.5  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=lcc +lat_1=33 +lat_2=45 +lat_0=40 +lon_0=-97 +a=637 
+b=637 
# data source : .../ozone_lcc.nc 
# names   : O3 
# z-value : 1 
# zvar: O3 
# level   : 1 

## Get US state boundaries in projection units.
state.map <- maps::map(
  database="state", projection="lambert", par=c(33,45), plot=FALSE)
#  parameters to lambert: 
#  see mapproj::mapproject
state.map.shp <-
  maptools::map2SpatialLines(state.map, proj4string=lcc.crs)

pdf(file=lcc.pdf)
rasterVis::levelplot(o3.raster, margin=FALSE
) + latticeExtra::layer(
  sp::sp.lines(state.map.shp, lwd=0.8, col='darkgray'))

dev.off()
# change this as needed to view PDFs on your system
system(sprintf("xpdf %s", lcc.pdf))
# data looks good, but there's no map.

## Try again, with lambert(40,33)
state.map <- maps::map(
  database="state", projection="lambert", par=c(40,33), plot=FALSE)
#  parameters to lambert: 
#  see mapproj::mapproject
state.map.shp <-
  maptools::map2SpatialLines(state.map, proj4string=lcc.crs)

pdf(file=lcc.pdf)
rasterVis::levelplot(o3.raster, margin=FALSE
) + latticeExtra::layer(
  sp::sp.lines(state.map.shp, lwd=0.8, col='darkgray'))
# still no map :-(

dev.off()
system(sprintf("xpdf %s", lcc.pdf))

#   end example #

The data looks right, in that it greatly resembles the original
example (from which the above is adapted), which follows my .sig.
However the original-example code *does* draw a map, while the code
above does not. How to fix?

TIA, Tom Roche  
---original example follows to end of post---

# Following adapted from what is installed in my
# .../R/x86_64-pc-linux-gnu-library/2.14/m3AqfigExampleScript.r
# (probably by my sysadmin), which also greatly resembles
# https://wiki.epa.gov/amad/index.php/R_packages_developed_in_AMAD
# which is behind a firewall :-(

## EXAMPLE WITH LAMBERT CONIC CONFORMAL FILE.

library("M3")
library("aqfig") # http://cran.r-project.org/web/packages/aqfig/

## Use an example file with LCC projection: either local download ...
lcc.file <- "./ozone_lcc.nc"
## ... or as installed by package=M3:
# lcc.file <- system.file("extdata/ozone_lcc.ncf", package="M3")
## Choose the one that works for you.

##  READ AND PLOT OZONE FROM FILE WITH LCC PROJECTION.

## Read in variable with daily ozone. Note that we can give dates
## rather than date-times, and that will include all time steps
## anytime during those days.  Or, we can give lower and upper bounds
## and al

Re: [R] improving/speeding up a very large, slow simulation

2013-02-13 Thread Benjamin Caldwell
Joshua,

Thanks for the example, and the explanation. Nice article that you wrote -
the figures alone deserve a deeper dive, I think.

As side note, I found out about profiling on another post and did it - it
appears that my ignorance about how slow dataframes can be was the main
problem. After turning the dfs into lists and matrixes, the improvement was
huge! Wish I had known about this issue ahead of time - it must be
somewhere in the R help books in big red letters, but if it isn't it should
be. Seems most of the discussions about speeding up code talks about
vectorization and avoiding fragmentation.

The below was for five iterations of the simulation, and I imagine was the
reason it was hanging up and stalling out for large simulations:


Original:

$by.total
 total.time total.pct self.time self.pct
simulation.unpaired.c   2857.54 99.97111.90 3.91
[<- 2555.74 89.41  2.78 0.10
[<-.data.frame  2552.96 89.32   2543.8489.00
sequential.unpaired.c149.48  5.23  2.66 0.09
unpaired.test.c   92.30  3.23 18.80 0.66
data.frame70.72  2.47  9.68 0.34
as.data.frame 42.36  1.48  3.74 0.132


only using dataframe as the output:

$by.total
  total.time total.pct self.time self.pct
simulation.unpaired.c 109.14100.00  0.90 0.82
sequential.unpaired.c  92.16 84.44  3.28 3.01
unpaired.test.c84.48 77.41 21.0819.31
sd 43.68 40.02  5.42 4.97


Thanks again folks.


On Tue, Feb 12, 2013 at 9:45 PM, Joshua Wiley wrote:

> Hi Ben,
>
> That is correct about vectorizingto some speed tests to see the
> effects.  They can be quite dramatic (like I have easily seen 300fold
> speedups from doing that).  The apply functions are essentially
> loops---they tend to be about the same speed as loops, though slightly
> less code.
>
> Compiler is nice---not it will not help already vectorized code
> (because vectorized code really just means code that is linked to C
> code that uses a compiled loop, but C is much faster than R.
>
> Sure, check out the bootstrapping (midway down) section on this page I
> wrote: http://www.ats.ucla.edu/stat/r/dae/melogit.htm
>
> Cheers,
>
> Josh
>
> On Tue, Feb 12, 2013 at 12:57 PM, Benjamin Caldwell
>  wrote:
> > Joshua,
> >
> > So, to your first suggestion - try to figure out whether some operation
> > performed on every element of the vector at once could do the same thing
> -
> > the answer is yes! Where can I see examples of that implemented?
> >
> > e.g. would it just be
> >
> > a <- 1:1
> > b <- 1:1
> > c <- 1:1
> > d <- data.frame(b,c)
> >
> > vectorize<-function(a, d) {
> >
> > f <- d[,1]+d[,2]+a
> > f
> > }
> >
> > out<-vectorize(a=a,d=d)
> > out
> >
> > vs
> >
> > loop<- function(a,d){
> >
> > for(i in 1:length(d[,1])){
> > a[i]<-d[i,1]+d[i,2]+a[i]
> > }
> > a
> > }
> >
> > out.l<-loop(a,d)
> >
> > out.l
> >
> > If so, it's vectorization that's the big advantage, not something
> mysterious
> > that's happening under the hood with the apply functions?
> >
> > To your second : Compiler - thanks for the tip, that's great to know!
> >
> > To your last, could you please give an example or point me to one that
> was
> > useful for you? I don't understand that well enough to use it.
> >
> > Thanks!
> >
> > Ben Caldwell
> >
> > Graduate Fellow
> > University of California, Berkeley
> > 130 Mulford Hall #3114
> > Berkeley, CA 94720
> > Office 223 Mulford Hall
> > (510)859-3358
> >
> >
> > On Mon, Feb 11, 2013 at 10:10 PM, Joshua Wiley 
> > wrote:
> >>
> >> Hi Ben,
> >>
> >> I appreciate that the example is reproducible, and I understand why
> >> you shared the entire project.  At the same time, that is an awful lot
> >> of code for volunteers to go through and try to optimize.
> >>
> >> I would try to think of the structure of your task, see what the
> >> individual pieces are---figure out what can be reused and optimized.
> >> Look at loops and try to think whether some operation performed on
> >> every element of the vector at once could do the same thing.
> >> Sometimes the next iteration of a loop depends on the previous, so it
> >> is difficult to vectorize, but often that is not the case.
> >>
> >> Make use of the compiler package, especially cmpfun().  It can give
> >> fairly substantial speedups, particularly with for loops in R.
> >>
> >> Finally if you want 1000 reps, do you actually need to repeat all the
> >> steps 1000 times, or could you just simulate 1000x the data?  If the
> >> latter, do the steps once but make more data.  If the former, you
> >> ought to be able to parallelize it fairly easily, see the parallel
> >> package.
> >>
> >> Good luck,
> >>
> >> Josh
> >>
> >>
> >> On Mon, Feb 11, 2013 at 9:22 PM, Benjamin Caldwell
> >>  wrote:
> >> > Dear R help;
> >> >
> >> >

[R] Online Beginner's Guide to R course with video/audio files

2013-02-13 Thread Highland Statistics Ltd


Following our successful book: 'A Beginner's Guide to R', we are please to
announce an online R course based on this book.

Video/audio files
Discussion board
Video footage of instructors

Nearly every section of ‘A Beginner’s Guide to R’ is covered. Each 
chapter is presented as a powerpoint video file with audio comments and 
you can see our computer screen with R code and results. Video footage 
of the course instructors is included. Exercises from the book are 
worked out and video solution files (and R files) are provided. You have 
access to a discussion board where you can ask questions on the course 
material and exercises. Motivational 'exercises to get certificate' are 
provided.


Course flyer:
http://www.highstat.com/Courses/FlyerOnlineRCourse.pdf

Course website:
http://www.highstat.com/statscourse.htm


Kind regards,

Alain Zuur

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Need Help Plotting "Line" for multiple linear regression

2013-02-13 Thread Craig O'Connell
Hello,

My name is Craig and I need help plotting a "line" for a multiple linear
regression in R.

Here is my sample data (filename:  convis.txt)

Output of convis.txt is (vis and density being predictors of either
avoidance or entrance):

   vis den  avoid entrance
1   10   1 0.   0.
2   10   3 0.8750   0.
38   3 0.8180   0.0300
48   3 0.6670   0.0667
58   1 0.2110   0.
66   1 0.2500   0.
7   10   1 0.3000   0.
8   10   1 0.1050   0.
98   1 0.7000   0.1000
10   3   5 0.1176   0.0588
11   3   5 0.3077   0.1150
12   3   9 0.9090   0.0900
13   3   7 0.7778   0.1110
14   3   5 0.5560   0.1110
15   3   1 0.5710   0.
16   3   4 0.5710   0.

In order to do the multiple regression, I used the following coding:


double=read.table("convis.txt",header=TRUE)
attach(double)
double
stem(vis)
stem(den)
stem(avoid)
stem(entrance)
plot(entrance,vis*den)  *as means to see how the interaction between
visibility and density may impact entrance behaviors
model6=lm(entrance~vis*den)
model6
summary(model6)
*abline(model6)  *Here is the issue as I used this for my simple linear
regression technique, but do not know what to use for a multiple regression*

If anybody can provide some feedback on this, it would be greatly
appreciated.

Kind Regards,

Craig

-- 
<><  <><  <><
Craig O'Connell
University of Massachusetts Dartmouth
Marine Biologist
www.youtube.com/craigpoconnell
craigosea.blogspot.com

[[alternative HTML version deleted]]

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


Re: [R] sweave question

2013-02-13 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Mark Leeds
> Sent: Wednesday, February 13, 2013 2:59 PM
> To: r-help@r-project.org
> Subject: [R] sweave question
> 
> Hi Everyone: I was having trouble getting the plot size correct when
> putting a plot in an sweave document. So, I searched on the internet
> and I
> found a clever solution where the person uses
> the cat function to write latex code so he can include the cat code in
> the
> chunk and place the plot using width and height. The solution is here:
> https://stat.ethz.ch/pipermail/r-help/2009-April/195094.html.
> 
> But the solution uses a backslash before the ending quotes in the cat
> statements  that might be windows relevant possibly ? I'm not sure
> about
> that part but I'm on linux and when I tried my way to mimic that
> solution
> in the latex/sweave code below ( I think it's the same solution but
> without
> the backslash on the closing quotes. I tried that also but got a
> different
> error ) , Sweave doesn't like the start of the includegraphics command.
> The
> error I get from Sweave is
> 
> #===
> Error:  chunk 9 (label = fig3)
> Error : '\i' is an unrecognized escape in character string starting
> "\i"
> Execution halted
> :~/research/equity/projects/tree_returns/report>
> #=
> 
> The code is below but if anyone is interested and thinks they need the
> whole file to look at the problem, I can send it. I just didn't want to
> send the whole file here. Definitely the error has to do with the chunk
> below for sure ( even though it says chunk 9 because there is no chunk
> 9
> ).  Thanks a lot to anyone who can be bothered investigating because
> I've
> spent pretty much the whole day on this and think it's
> time to surrender !! or atleast give up for now and come back
> to it
> with a fresher brain. Have a good night.
> 
> # THE LATEX/SWEAVE CODE
> #
> 
> cal.tree is created in a previous chunk and that's fine.
> 
> <>=
> wid <- 5
> hei <- 5
> pdf("reg_tree-fig3.pdf", width = wid, height = hei)
> plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
> text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
> dev.off()
> cat("\begin{figure}[ht!]")
> cat("\begin{center}")
> cat("\includegraphics[width = ", wid, ", height = ", hei,
> "]{reg_tree-fig3}")
> cat("\end{center}")
> cat("\caption{The resulting unpruned regression tree of the california
> real
> estate data}")
> cat("\label{FIG:figthree}")
> cat("\end{figure}")
> @
> 

Mark,

I am not an sweave expert, but I think the problem is actually that you need to 
double all of your backslash characters that you actually want to write out as 
a backslash.  The error message says that it doesn't recognize the escape 
character '\i'.  

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


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


[R] Plotting multiple xyplots in same page

2013-02-13 Thread Lisa Daniel
Dear Rhelp,

I would like to have 6 xyplots in the same page.  Similar to (par(mfrow=c(3,3))
Found this example on the R archives.
library(lattice)
trellis.par.set(theme = col.whitebg())
xy <- xyplot(decrease ~ treatment, OrchardSprays,
  groups = rowpos, type = "a",
  auto.key = list(x = 0.2, y = 0.9,
    cex = 0.75, points = FALSE, lines = TRUE))

print(xy, pos = c(0.0, 0.0, 0.5, 0.5), more = TRUE)
print(xy, pos = c(0.0, 0.5, 0.5, 1.0), more = TRUE)
print(xy, pos = c(0.5, 0.0, 1.0, 0.5), more = TRUE)
print(xy, pos = c(0.5, 0.5, 1.0, 1.0), more = FALSE)




When I changed the print() to:

 print(xy, pos=c(0.0,0.0,0.33,0.33),more = TRUE),
the figure was not looking good.

Also, is it possible to assign A, B, C,D, etc for each figure. 



a<- rnorm(1000,0,1) 
b<- rnorm(1000,0,2) 
c<- rnorm(1000,0,3) 
d<- rnorm(1000,0,4) 
par(mfrow=c(2,2)) 
hist(a,main="") 
title(main="A",adj=0) 
hist(b,main="") 
title(main="B",adj=0) 
hist(c,main="") 
title(main="C",adj=0) 
hist(d,main="") 
title(main="D",adj=0)


I tried this to xyplot, but it was not working.

Please help me.  

Many thanks in advance,
Lisa.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] spearman correlation and p-value as a matrix

2013-02-13 Thread Jim Lemon

On 02/13/2013 08:48 PM, Ozgul Inceoglu wrote:

I have two data matrices that I want to make the correlation between each 
column from data1 and each column from data 2 and also calculate the p-value 
Matrices dont have the same size and I tried such a script.

bg<- read.table (file.choose(), header=T, row.names)
bg
Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 
Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 Otu00218
Gi20Jun11 0.001217 0 0.001217 0 0.00 0 0 0 0.001217 0 0 0 0 0 0.001217 0 
0.001217
Gi40Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
0.00
Gi425Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
0.00
Gi45Jun11 0.00 0 0.00 0 0.001513 0 0 0 0.00 0 0 0 0 0 0.00 0 
0.00
Gi475Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
0.00
Gi50Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
0.00

ag<- read.table (file.choose(), header=T, row.names)

for (i in 1:(ncol(bg)))
for (j in 1:(ncol(ag)))
print(c(i,j))
final_matrix<- matrix(rep("0",ncol(bg)*ncol(ag)),ncol=ncol(bg),nrow=ncol(ag))

cor<- cor.test(as.vector(as.matrix(bg[,i])),as.vector(as.matrix(ag[,j])), 
method="spearman")

#but the output is not matrice with all the values but a single correlation 
value

data:  bg[, i] and ag[, j]
t = 2.2992, df = 26, p-value = 0.02978
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
  0.04485289 0.67986803
sample estimates:
   cor
0.4110515

# How I can creat an outfile with all the correlations and p-values?


Hi Ozgul,
As we don't know what the "ag" data frame looks like, I'll have to fake 
it. As your "bg" data frame is 6 rows with 17 columns, I'll make "ag" 6 
rows with 3 columns. I'll also fake "bg" as I'm too lazy to write it all 
out. If "ag" differs in both rows and columns, you will have to pass 
use="pairwise.complete.obs" to the "cor.test" function.


bg<-data.frame(Otu00022=rnorm(6),Otu00039=rnorm(6),
 Otu00042=rnorm(6),Otu00101=rnorm(6))

ag<-data.frame(col1=rnorm(6),col2=rnorm(6),col3=rnorm(6))

allcor<-function(data1,data2) {
 corlist<-list()
 for(i in 1:length(data1)) {
  for(j in 1:length(data2))
   corlist[[length(data2)*(i-1)+j]]<-cor.test(data1[,i],data2[,j])
 }
 return(corlist)
}

Jim

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


Re: [R] Plotting multiple xyplots in same page

2013-02-13 Thread Lisa Daniel
Dear Rhelp,

I was able to plot 6 figures in one page.  I do need help in reducing the space 
between the title and the plot and assigning A,B,C,D,E,F to each figure
library(lattice)
trellis.par.set(theme = col.whitebg())
xy <- xyplot(decrease ~ treatment, OrchardSprays,
        main="Some plot",
  groups = rowpos, type = "a",
  auto.key = list(x = 0.2, y = 0.9,
    cex = 0.52, points = FALSE, lines = TRUE))


print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)

Thanks in advance,
Lisa



- Original Message -
From: Lisa Daniel 
To: "r-help@r-project.org" 
Cc: 
Sent: Wednesday, February 13, 2013 5:28 PM
Subject: Plotting multiple xyplots in same page

Dear Rhelp,

I would like to have 6 xyplots in the same page.  Similar to (par(mfrow=c(3,3))
Found this example on the R archives.
library(lattice)
trellis.par.set(theme = col.whitebg())
xy <- xyplot(decrease ~ treatment, OrchardSprays,
  groups = rowpos, type = "a",
  auto.key = list(x = 0.2, y = 0.9,
    cex = 0.75, points = FALSE, lines = TRUE))

print(xy, pos = c(0.0, 0.0, 0.5, 0.5), more = TRUE)
print(xy, pos = c(0.0, 0.5, 0.5, 1.0), more = TRUE)
print(xy, pos = c(0.5, 0.0, 1.0, 0.5), more = TRUE)
print(xy, pos = c(0.5, 0.5, 1.0, 1.0), more = FALSE)




When I changed the print() to:

 print(xy, pos=c(0.0,0.0,0.33,0.33),more = TRUE),
the figure was not looking good.

Also, is it possible to assign A, B, C,D, etc for each figure. 



a<- rnorm(1000,0,1) 
b<- rnorm(1000,0,2) 
c<- rnorm(1000,0,3) 
d<- rnorm(1000,0,4) 
par(mfrow=c(2,2)) 
hist(a,main="") 
title(main="A",adj=0) 
hist(b,main="") 
title(main="B",adj=0) 
hist(c,main="") 
title(main="C",adj=0) 
hist(d,main="") 
title(main="D",adj=0)


I tried this to xyplot, but it was not working.

Please help me.  

Many thanks in advance,
Lisa.


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

2013-02-13 Thread Mark Leeds
thanks dan. I'll try the double slash on both sides when I get back later
tonight. In the solution on
the net, he only had the backslash on the end quotes ( well there was a
backslash at the beginning but that's a real backslash  needed for latex
commands ). I'll let you know how it works out. thanks again.






On Wed, Feb 13, 2013 at 6:50 PM, Nordlund, Dan (DSHS/RDA) <
nord...@dshs.wa.gov> wrote:

> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> > project.org] On Behalf Of Mark Leeds
> > Sent: Wednesday, February 13, 2013 2:59 PM
> > To: r-help@r-project.org
> > Subject: [R] sweave question
> >
> > Hi Everyone: I was having trouble getting the plot size correct when
> > putting a plot in an sweave document. So, I searched on the internet
> > and I
> > found a clever solution where the person uses
> > the cat function to write latex code so he can include the cat code in
> > the
> > chunk and place the plot using width and height. The solution is here:
> > https://stat.ethz.ch/pipermail/r-help/2009-April/195094.html.
> >
> > But the solution uses a backslash before the ending quotes in the cat
> > statements  that might be windows relevant possibly ? I'm not sure
> > about
> > that part but I'm on linux and when I tried my way to mimic that
> > solution
> > in the latex/sweave code below ( I think it's the same solution but
> > without
> > the backslash on the closing quotes. I tried that also but got a
> > different
> > error ) , Sweave doesn't like the start of the includegraphics command.
> > The
> > error I get from Sweave is
> >
> > #===
> > Error:  chunk 9 (label = fig3)
> > Error : '\i' is an unrecognized escape in character string starting
> > "\i"
> > Execution halted
> > :~/research/equity/projects/tree_returns/report>
> > #=
> >
> > The code is below but if anyone is interested and thinks they need the
> > whole file to look at the problem, I can send it. I just didn't want to
> > send the whole file here. Definitely the error has to do with the chunk
> > below for sure ( even though it says chunk 9 because there is no chunk
> > 9
> > ).  Thanks a lot to anyone who can be bothered investigating because
> > I've
> > spent pretty much the whole day on this and think it's
> > time to surrender !! or atleast give up for now and come back
> > to it
> > with a fresher brain. Have a good night.
> >
> > # THE LATEX/SWEAVE CODE
> > #
> >
> > cal.tree is created in a previous chunk and that's fine.
> >
> > <>=
> > wid <- 5
> > hei <- 5
> > pdf("reg_tree-fig3.pdf", width = wid, height = hei)
> > plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
> > text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
> > dev.off()
> > cat("\begin{figure}[ht!]")
> > cat("\begin{center}")
> > cat("\includegraphics[width = ", wid, ", height = ", hei,
> > "]{reg_tree-fig3}")
> > cat("\end{center}")
> > cat("\caption{The resulting unpruned regression tree of the california
> > real
> > estate data}")
> > cat("\label{FIG:figthree}")
> > cat("\end{figure}")
> > @
> >
>
> Mark,
>
> I am not an sweave expert, but I think the problem is actually that you
> need to double all of your backslash characters that you actually want to
> write out as a backslash.  The error message says that it doesn't recognize
> the escape character '\i'.
>
> Hope this is helpful,
>
> Dan
>
> Daniel J. Nordlund
> Washington State Department of Social and Health Services
> Planning, Performance, and Accountability
> Research and Data Analysis Division
> Olympia, WA 98504-5204
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Error Message During ANOVA

2013-02-13 Thread Pascal Oettli

Hello,

The first error message says:

> Error in model.frame.default(formula = r ~ tm, drop.unused.levels = 
TRUE) : variable lengths differ (found for 'tm')


Please compare the size of 'r' and 'tm'.

Regards,
Pascal

Le 14/02/2013 07:14, Craig O'Connell a écrit :

Dear R-Help,

I'm using an ANOVA to determine if there is any variation that exists
between my four different shark-types and their entrance behavior towards
an apparatus.

To do this, my coding was:

df1=read.table("lemonentrance.txt", header=TRUE); df1

c(t(as.matrix(df1)))

r = c(t(as.matrix(df1))) # response data

r

f=c("Con","Bro","OEy","Bli")

k=4

n=6

tm=gl(k,1,n*k,factor(f))

tm

av=aov(r~tm)

Error in model.frame.default(formula = r ~ tm, drop.unused.levels = TRUE) :
   variable lengths differ (found for 'tm')

summary(av)

Error in summary(av) : object 'av' not found

As you can see, I receive two error message, with teh second being a cause
of the first.  Does anybody have any idea how I can fix this, or at least
would you happen to know what the error is referring to?

Thanks and a response would be greatly appreciated.

Kind Regards,

Craig





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] improving/speeding up a very large, slow simulation

2013-02-13 Thread David Winsemius

On Feb 13, 2013, at 3:33 PM, Benjamin Caldwell wrote:

> Joshua,
> 
> Thanks for the example, and the explanation. Nice article that you wrote -
> the figures alone deserve a deeper dive, I think.
> 
> As side note, I found out about profiling on another post and did it - it
> appears that my ignorance about how slow dataframes can be was the main
> problem. After turning the dfs into lists and matrixes, the improvement was
> huge! Wish I had known about this issue ahead of time - it must be
> somewhere in the R help books in big red letters, but if it isn't it should
> be. Seems most of the discussions about speeding up code talks about
> vectorization and avoiding fragmentation.

I don't know if that information is in the unnamed books you read, but it is no 
surprise to regular readers of Rhelp that `[<-.data.frame` is a bottleneck. It 
requires a lot of extra overhead to support the possibility of having different 
datatypes in each column and to maintain row numbering correctly.

-- 
David.


> 
> The below was for five iterations of the simulation, and I imagine was the
> reason it was hanging up and stalling out for large simulations:
> 
> 
> Original:
> 
> $by.total
> total.time total.pct self.time self.pct
> simulation.unpaired.c   2857.54 99.97111.90 3.91
> [<- 2555.74 89.41  2.78 0.10
> [<-.data.frame  2552.96 89.32   2543.8489.00
> sequential.unpaired.c149.48  5.23  2.66 0.09
> unpaired.test.c   92.30  3.23 18.80 0.66
> data.frame70.72  2.47  9.68 0.34
> as.data.frame 42.36  1.48  3.74 0.132
> 
> 
> only using dataframe as the output:
> 
> $by.total
>  total.time total.pct self.time self.pct
> simulation.unpaired.c 109.14100.00  0.90 0.82
> sequential.unpaired.c  92.16 84.44  3.28 3.01
> unpaired.test.c84.48 77.41 21.0819.31
> sd 43.68 40.02  5.42 4.97
> 
> 
> Thanks again folks.
> 
> 
> On Tue, Feb 12, 2013 at 9:45 PM, Joshua Wiley wrote:
> 
>> Hi Ben,
>> 
>> That is correct about vectorizingto some speed tests to see the
>> effects.  They can be quite dramatic (like I have easily seen 300fold
>> speedups from doing that).  The apply functions are essentially
>> loops---they tend to be about the same speed as loops, though slightly
>> less code.
>> 
>> Compiler is nice---not it will not help already vectorized code
>> (because vectorized code really just means code that is linked to C
>> code that uses a compiled loop, but C is much faster than R.
>> 
>> Sure, check out the bootstrapping (midway down) section on this page I
>> wrote: http://www.ats.ucla.edu/stat/r/dae/melogit.htm
>> 
>> Cheers,
>> 
>> Josh
>> 
>> On Tue, Feb 12, 2013 at 12:57 PM, Benjamin Caldwell
>>  wrote:
>>> Joshua,
>>> 
>>> So, to your first suggestion - try to figure out whether some operation
>>> performed on every element of the vector at once could do the same thing
>> -
>>> the answer is yes! Where can I see examples of that implemented?
>>> 
>>> e.g. would it just be
>>> 
>>> a <- 1:1
>>> b <- 1:1
>>> c <- 1:1
>>> d <- data.frame(b,c)
>>> 
>>> vectorize<-function(a, d) {
>>> 
>>> f <- d[,1]+d[,2]+a
>>> f
>>> }
>>> 
>>> out<-vectorize(a=a,d=d)
>>> out
>>> 
>>> vs
>>> 
>>> loop<- function(a,d){
>>> 
>>> for(i in 1:length(d[,1])){
>>> a[i]<-d[i,1]+d[i,2]+a[i]
>>> }
>>> a
>>> }
>>> 
>>> out.l<-loop(a,d)
>>> 
>>> out.l
>>> 
>>> If so, it's vectorization that's the big advantage, not something
>> mysterious
>>> that's happening under the hood with the apply functions?
>>> 
>>> To your second : Compiler - thanks for the tip, that's great to know!
>>> 
>>> To your last, could you please give an example or point me to one that
>> was
>>> useful for you? I don't understand that well enough to use it.
>>> 
>>> Thanks!
>>> 
>>> Ben Caldwell
>>> 
>>> Graduate Fellow
>>> University of California, Berkeley
>>> 130 Mulford Hall #3114
>>> Berkeley, CA 94720
>>> Office 223 Mulford Hall
>>> (510)859-3358
>>> 
>>> 
>>> On Mon, Feb 11, 2013 at 10:10 PM, Joshua Wiley 
>>> wrote:
 
 Hi Ben,
 
 I appreciate that the example is reproducible, and I understand why
 you shared the entire project.  At the same time, that is an awful lot
 of code for volunteers to go through and try to optimize.
 
 I would try to think of the structure of your task, see what the
 individual pieces are---figure out what can be reused and optimized.
 Look at loops and try to think whether some operation performed on
 every element of the vector at once could do the same thing.
 Sometimes the next iteration of a loop depends on the previous, so it
 is difficult to vectorize, but often that is not the case.
 
 Make use of the compiler package, especially cmpfun().  It can give
 fa

Re: [R] character strings with embedded commands: perl "/gee" ?

2013-02-13 Thread Greg Snow
Look at the gsubfn package, it has functionality to do this.

Here is an example from the vignette:

> fn$cat("pi = $pi, exp = `exp(1)`\n")
pi = 3.14159265358979, exp = 2.71828182845905

The formula syntax to function conversion in the package may help with the
last part.




On Fri, Feb 8, 2013 at 5:01 PM, ivo welch wrote:

> dear R experts---I am trying to replicate a perl feature. I want to be
> able to embed R commands inside a character string, and have the
> string be printed with the command executed.  my perl equivalent is
>
>   my $a=10;
>   my $teststring = "the expression, $a+1, is ::$a+1::, but add one
> more for ::$a+2::\n";
>   $teststring =~ s/::(.*?)::/$1/gee;
>   print $teststring;
>
> of course, R does not use '$' for variable names.  my ultimate goal is
> to write something like
>
>   cat("d is a ::class(d):: with names ::names(d)::")
>
> of course, I know I can write this as cat("d is a", class(d), "with
> names", names(d)), but I also want to be define %or% so that I can
> write
>
>   (is.data.frame(d)) %or% "d is a ::class(d):: with names ::names(d)::" ;
>
> operators don't take variable arguments afaik.  :-(.
>
> advice appreciated.
>
> regards,
>
> /iaw
> 
> Ivo Welch (ivo.we...@gmail.com)
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] Plotting multiple xyplots in same page

2013-02-13 Thread Duncan Mackay

Hi Lisa

You can use the page function of xyplot to do this

xy <-
xyplot(decrease ~ treatment, OrchardSprays,
   groups = rowpos, type = "a",
   page = function(n){
grid.text(LETTERS[j],
y = 0.95,
x = 0.01,
default.units = "npc",
just = c("left"),
gp = gpar(fontsize = 12) )
  },
   auto.key = list(x = 0.2, y = 0.9,
   cex = 0.75, points = FALSE, lines = TRUE))

j = 1
print(xy, pos = c(0.0, 0.0, 0.5, 0.5), more = TRUE)
j = j+1
print(xy, pos = c(0.0, 0.5, 0.5, 1.0), more = TRUE)
j = j+1
print(xy, pos = c(0.5, 0.0, 1.0, 0.5), more = TRUE)
j = j+1
print(xy, pos = c(0.5, 0.5, 1.0, 1.0), more = FALSE)

amend x, y  and grid::gp positions/values to suit

There are other ways using trellis.focus and the package grid

HTH

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


At 08:28 14/02/2013, you wrote:

Dear Rhelp,

I would like to have 6 xyplots in the same page.  Similar to 
(par(mfrow=c(3,3))

Found this example on the R archives.
library(lattice)
trellis.par.set(theme = col.whitebg())
xy <- xyplot(decrease ~ treatment, OrchardSprays,
  groups = rowpos, type = "a",
  auto.key = list(x = 0.2, y = 0.9,
cex = 0.75, points = FALSE, lines = TRUE))

print(xy, pos = c(0.0, 0.0, 0.5, 0.5), more = TRUE)
print(xy, pos = c(0.0, 0.5, 0.5, 1.0), more = TRUE)
print(xy, pos = c(0.5, 0.0, 1.0, 0.5), more = TRUE)
print(xy, pos = c(0.5, 0.5, 1.0, 1.0), more = FALSE)




When I changed the print() to:

 print(xy, pos=c(0.0,0.0,0.33,0.33),more = TRUE),
the figure was not looking good.

Also, is it possible to assign A, B, C,D, etc for each figure.



a<- rnorm(1000,0,1)
b<- rnorm(1000,0,2)
c<- rnorm(1000,0,3)
d<- rnorm(1000,0,4)
par(mfrow=c(2,2))
hist(a,main="")
title(main="A",adj=0)
hist(b,main="")
title(main="B",adj=0)
hist(c,main="")
title(main="C",adj=0)
hist(d,main="")
title(main="D",adj=0)


I tried this to xyplot, but it was not working.

Please help me.

Many thanks in advance,
Lisa.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] improving/speeding up a very large, slow simulation

2013-02-13 Thread Benjamin Caldwell
That makes sense David; thanks again everyone for your help.

*Ben Caldwell*

Graduate Fellow
University of California, Berkeley
130 Mulford Hall #3114
Berkeley, CA 94720
Office 223 Mulford Hall
(510)859-3358


On Wed, Feb 13, 2013 at 4:25 PM, David Winsemius wrote:

>
> On Feb 13, 2013, at 3:33 PM, Benjamin Caldwell wrote:
>
> > Joshua,
> >
> > Thanks for the example, and the explanation. Nice article that you wrote
> -
> > the figures alone deserve a deeper dive, I think.
> >
> > As side note, I found out about profiling on another post and did it - it
> > appears that my ignorance about how slow dataframes can be was the main
> > problem. After turning the dfs into lists and matrixes, the improvement
> was
> > huge! Wish I had known about this issue ahead of time - it must be
> > somewhere in the R help books in big red letters, but if it isn't it
> should
> > be. Seems most of the discussions about speeding up code talks about
> > vectorization and avoiding fragmentation.
>
> I don't know if that information is in the unnamed books you read, but it
> is no surprise to regular readers of Rhelp that `[<-.data.frame` is a
> bottleneck. It requires a lot of extra overhead to support the possibility
> of having different datatypes in each column and to maintain row numbering
> correctly.
>
> --
> David.
>
>
> >
> > The below was for five iterations of the simulation, and I imagine was
> the
> > reason it was hanging up and stalling out for large simulations:
> >
> >
> > Original:
> >
> > $by.total
> > total.time total.pct self.time self.pct
> > simulation.unpaired.c   2857.54 99.97111.90 3.91
> > [<- 2555.74 89.41  2.78 0.10
> > [<-.data.frame  2552.96 89.32   2543.8489.00
> > sequential.unpaired.c149.48  5.23  2.66 0.09
> > unpaired.test.c   92.30  3.23 18.80 0.66
> > data.frame70.72  2.47  9.68 0.34
> > as.data.frame 42.36  1.48  3.74 0.132
> >
> >
> > only using dataframe as the output:
> >
> > $by.total
> >  total.time total.pct self.time self.pct
> > simulation.unpaired.c 109.14100.00  0.90 0.82
> > sequential.unpaired.c  92.16 84.44  3.28 3.01
> > unpaired.test.c84.48 77.41 21.0819.31
> > sd 43.68 40.02  5.42 4.97
> >
> >
> > Thanks again folks.
> >
> >
> > On Tue, Feb 12, 2013 at 9:45 PM, Joshua Wiley  >wrote:
> >
> >> Hi Ben,
> >>
> >> That is correct about vectorizingto some speed tests to see the
> >> effects.  They can be quite dramatic (like I have easily seen 300fold
> >> speedups from doing that).  The apply functions are essentially
> >> loops---they tend to be about the same speed as loops, though slightly
> >> less code.
> >>
> >> Compiler is nice---not it will not help already vectorized code
> >> (because vectorized code really just means code that is linked to C
> >> code that uses a compiled loop, but C is much faster than R.
> >>
> >> Sure, check out the bootstrapping (midway down) section on this page I
> >> wrote: http://www.ats.ucla.edu/stat/r/dae/melogit.htm
> >>
> >> Cheers,
> >>
> >> Josh
> >>
> >> On Tue, Feb 12, 2013 at 12:57 PM, Benjamin Caldwell
> >>  wrote:
> >>> Joshua,
> >>>
> >>> So, to your first suggestion - try to figure out whether some operation
> >>> performed on every element of the vector at once could do the same
> thing
> >> -
> >>> the answer is yes! Where can I see examples of that implemented?
> >>>
> >>> e.g. would it just be
> >>>
> >>> a <- 1:1
> >>> b <- 1:1
> >>> c <- 1:1
> >>> d <- data.frame(b,c)
> >>>
> >>> vectorize<-function(a, d) {
> >>>
> >>> f <- d[,1]+d[,2]+a
> >>> f
> >>> }
> >>>
> >>> out<-vectorize(a=a,d=d)
> >>> out
> >>>
> >>> vs
> >>>
> >>> loop<- function(a,d){
> >>>
> >>> for(i in 1:length(d[,1])){
> >>> a[i]<-d[i,1]+d[i,2]+a[i]
> >>> }
> >>> a
> >>> }
> >>>
> >>> out.l<-loop(a,d)
> >>>
> >>> out.l
> >>>
> >>> If so, it's vectorization that's the big advantage, not something
> >> mysterious
> >>> that's happening under the hood with the apply functions?
> >>>
> >>> To your second : Compiler - thanks for the tip, that's great to know!
> >>>
> >>> To your last, could you please give an example or point me to one that
> >> was
> >>> useful for you? I don't understand that well enough to use it.
> >>>
> >>> Thanks!
> >>>
> >>> Ben Caldwell
> >>>
> >>> Graduate Fellow
> >>> University of California, Berkeley
> >>> 130 Mulford Hall #3114
> >>> Berkeley, CA 94720
> >>> Office 223 Mulford Hall
> >>> (510)859-3358
> >>>
> >>>
> >>> On Mon, Feb 11, 2013 at 10:10 PM, Joshua Wiley  >
> >>> wrote:
> 
>  Hi Ben,
> 
>  I appreciate that the example is reproducible, and I understand why
>  you shared the entire project.  At the same time, that is an awful lot
>  of code for volunteers to go through and try t

Re: [R] sweave question

2013-02-13 Thread Duncan Mackay

Hi

Dan is correct

The alternative is to use a chunk to create the plot
eg
<>=
pdf("reg_tree-fig3.pdf", width = wid, height = hei)
plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
dev.off()
@

an call the file in the latex figure in the usual way

\begin{figure}[!h]
\centering
\includegraphics[width=...,%
 clip=true,%
 trim=0in 0in 0in 0in,%
 keepaspectratio=true]%
 {reg_tree-fig3.pdf}
...
\end{figure}

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au



At 09:50 14/02/2013, you wrote:

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Mark Leeds
> Sent: Wednesday, February 13, 2013 2:59 PM
> To: r-help@r-project.org
> Subject: [R] sweave question
>
> Hi Everyone: I was having trouble getting the plot size correct when
> putting a plot in an sweave document. So, I searched on the internet
> and I
> found a clever solution where the person uses
> the cat function to write latex code so he can include the cat code in
> the
> chunk and place the plot using width and height. The solution is here:
> https://stat.ethz.ch/pipermail/r-help/2009-April/195094.html.
>
> But the solution uses a backslash before the ending quotes in the cat
> statements  that might be windows relevant possibly ? I'm not sure
> about
> that part but I'm on linux and when I tried my way to mimic that
> solution
> in the latex/sweave code below ( I think it's the same solution but
> without
> the backslash on the closing quotes. I tried that also but got a
> different
> error ) , Sweave doesn't like the start of the includegraphics command.
> The
> error I get from Sweave is
>
> #===
> Error:  chunk 9 (label = fig3)
> Error : '\i' is an unrecognized escape in character string starting
> "\i"
> Execution halted
> :~/research/equity/projects/tree_returns/report>
> #=
>
> The code is below but if anyone is interested and thinks they need the
> whole file to look at the problem, I can send it. I just didn't want to
> send the whole file here. Definitely the error has to do with the chunk
> below for sure ( even though it says chunk 9 because there is no chunk
> 9
> ).  Thanks a lot to anyone who can be bothered investigating because
> I've
> spent pretty much the whole day on this and think it's
> time to surrender !! or atleast give up for now and come back
> to it
> with a fresher brain. Have a good night.
>
> # THE LATEX/SWEAVE CODE
> #
>
> cal.tree is created in a previous chunk and that's fine.
>
> <>=
> wid <- 5
> hei <- 5
> pdf("reg_tree-fig3.pdf", width = wid, height = hei)
> plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
> text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
> dev.off()
> cat("\begin{figure}[ht!]")
> cat("\begin{center}")
> cat("\includegraphics[width = ", wid, ", height = ", hei,
> "]{reg_tree-fig3}")
> cat("\end{center}")
> cat("\caption{The resulting unpruned regression tree of the california
> real
> estate data}")
> cat("\label{FIG:figthree}")
> cat("\end{figure}")
> @
>

Mark,

I am not an sweave expert, but I think the problem is actually that 
you need to double all of your backslash characters that you 
actually want to write out as a backslash.  The error message says 
that it doesn't recognize the escape character '\i'.


Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


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

2013-02-13 Thread Daniel Nordlund
Mark,

just to be clear, since R uses the backslash character as an escape character 
inside strings, then any backslash that you want to appear in your latex code 
must be escaped, i.e. it must be doubled.  But any backslash character that is 
being used as an escape character should remain as a single character.

I looked at the solution you linked to, and it looks to me like the post got a 
little garbled in transmission.  Here is what I saw.

<>=
pdf("fig1.pdf", width = wid, heigth = hei)
plot(1:10)
dev.off()
cat("\begin{figure}\")
cat("\includegraphics[width = ", wid, ", height = ", hei, "]{proj1-fig1}\"}
cat("\end{figure}")
@

In the first cat(), the "\begin{figure}\" is not going to be interpreted 
properly.  the \b will be interpreted as an escape character, and so what will 
be printed is something like this (where '_' represents the escape sequence \b 
that I didn't look up)

_egin{figure}

In addition, you want to be writing the latex commands on separate lines, which 
requires that the string be ended with '\n', i.e. a newline character. But it 
looks like the 'n' got stripped out.  Also, the second cat statement in the 
example above ends with a '}' instead of a ')'. So I suspect that the example 
should have looked like this

<>=
pdf("fig1.pdf", width = wid, heigth = hei)
plot(1:10)
dev.off()
cat("\\begin{figure}\n")
cat("\\includegraphics[width = ", wid, ", height = ", hei, "]{proj1-fig1}\n")
cat("\\end{figure}\n")
@

If I have got any of this wrong, I am sure someone will come along and correct 
me.

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA
 

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Mark Leeds
> Sent: Wednesday, February 13, 2013 4:18 PM
> To: Nordlund, Dan (DSHS/RDA)
> Cc: r-help@r-project.org
> Subject: Re: [R] sweave question
> 
> thanks dan. I'll try the double slash on both sides when I get back later
> tonight. In the solution on
> the net, he only had the backslash on the end quotes ( well there was a
> backslash at the beginning but that's a real backslash  needed for latex
> commands ). I'll let you know how it works out. thanks again.
> 
> 
> 
> 
> 
> 
> On Wed, Feb 13, 2013 at 6:50 PM, Nordlund, Dan (DSHS/RDA) <
> nord...@dshs.wa.gov> wrote:
> 
> > > -Original Message-
> > > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> > > project.org] On Behalf Of Mark Leeds
> > > Sent: Wednesday, February 13, 2013 2:59 PM
> > > To: r-help@r-project.org
> > > Subject: [R] sweave question
> > >
> > > Hi Everyone: I was having trouble getting the plot size correct when
> > > putting a plot in an sweave document. So, I searched on the internet
> > > and I
> > > found a clever solution where the person uses
> > > the cat function to write latex code so he can include the cat code in
> > > the
> > > chunk and place the plot using width and height. The solution is here:
> > > https://stat.ethz.ch/pipermail/r-help/2009-April/195094.html.
> > >
> > > But the solution uses a backslash before the ending quotes in the cat
> > > statements  that might be windows relevant possibly ? I'm not sure
> > > about
> > > that part but I'm on linux and when I tried my way to mimic that
> > > solution
> > > in the latex/sweave code below ( I think it's the same solution but
> > > without
> > > the backslash on the closing quotes. I tried that also but got a
> > > different
> > > error ) , Sweave doesn't like the start of the includegraphics
> command.
> > > The
> > > error I get from Sweave is
> > >
> > > #===
> > > Error:  chunk 9 (label = fig3)
> > > Error : '\i' is an unrecognized escape in character string starting
> > > "\i"
> > > Execution halted
> > > :~/research/equity/projects/tree_returns/report>
> > > #=
> > >
> > > The code is below but if anyone is interested and thinks they need the
> > > whole file to look at the problem, I can send it. I just didn't want
> to
> > > send the whole file here. Definitely the error has to do with the
> chunk
> > > below for sure ( even though it says chunk 9 because there is no chunk
> > > 9
> > > ).  Thanks a lot to anyone who can be bothered investigating because
> > > I've
> > > spent pretty much the whole day on this and think it's
> > > time to surrender !! or atleast give up for now and come back
> > > to it
> > > with a fresher brain. Have a good night.
> > >
> > > # THE LATEX/SWEAVE CODE
> > > #
> > >
> > > cal.tree is created in a previous chunk and that's fine.
> > >
> > > <>=
> > > wid <- 5
> > > hei <- 5
> > > pdf("reg_tree-fig3.pdf", width = wid, height = hei)
> > > plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
> > > text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
> > > dev.off()
> > > cat("\begin{figure}[ht!]")
> > > cat("\begin{center}")
> >

Re: [R] Plotting multiple xyplots in same page

2013-02-13 Thread Duncan Mackay

Hi Lisa

have a look at par.settings in ?xyplot

trellis.par.get() shows the settings

trellis.par.get()[[27]]
$left
$left$tck
[1] 1

$left$pad1
[1] 1

$left$pad2
[1] 1


$top
$top$tck
[1] 1

$top$pad1
[1] 1

$top$pad2
[1] 1


$right
$right$tck
[1] 1

$right$pad1
[1] 1

$right$pad2
[1] 1


$bottom
$bottom$tck
[1] 1

$bottom$pad1
[1] 1

$bottom$pad2
[1] 1

as an example:

par.settings = list(
layout.heights = list(main = 0,
  sub  = 0,
  axis.top = 0.2,
  top.padding  = 0,
  bottom.padding = 0))

HTH

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au




At 09:10 14/02/2013, you wrote:

Dear Rhelp,

I was able to plot 6 figures in one page.  I do need help in 
reducing the space between the title and the plot and assigning 
A,B,C,D,E,F to each figure

library(lattice)
trellis.par.set(theme = col.whitebg())
xy <- xyplot(decrease ~ treatment, OrchardSprays,
main="Some plot",
  groups = rowpos, type = "a",
  auto.key = list(x = 0.2, y = 0.9,
cex = 0.52, points = FALSE, lines = TRUE))


print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)

Thanks in advance,
Lisa



- Original Message -
From: Lisa Daniel 
To: "r-help@r-project.org" 
Cc:
Sent: Wednesday, February 13, 2013 5:28 PM
Subject: Plotting multiple xyplots in same page

Dear Rhelp,

I would like to have 6 xyplots in the same page.  Similar to 
(par(mfrow=c(3,3))

Found this example on the R archives.
library(lattice)
trellis.par.set(theme = col.whitebg())
xy <- xyplot(decrease ~ treatment, OrchardSprays,
  groups = rowpos, type = "a",
  auto.key = list(x = 0.2, y = 0.9,
cex = 0.75, points = FALSE, lines = TRUE))

print(xy, pos = c(0.0, 0.0, 0.5, 0.5), more = TRUE)
print(xy, pos = c(0.0, 0.5, 0.5, 1.0), more = TRUE)
print(xy, pos = c(0.5, 0.0, 1.0, 0.5), more = TRUE)
print(xy, pos = c(0.5, 0.5, 1.0, 1.0), more = FALSE)




When I changed the print() to:

 print(xy, pos=c(0.0,0.0,0.33,0.33),more = TRUE),
the figure was not looking good.

Also, is it possible to assign A, B, C,D, etc for each figure.



a<- rnorm(1000,0,1)
b<- rnorm(1000,0,2)
c<- rnorm(1000,0,3)
d<- rnorm(1000,0,4)
par(mfrow=c(2,2))
hist(a,main="")
title(main="A",adj=0)
hist(b,main="")
title(main="B",adj=0)
hist(c,main="")
title(main="C",adj=0)
hist(d,main="")
title(main="D",adj=0)


I tried this to xyplot, but it was not working.

Please help me.

Many thanks in advance,
Lisa.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] FW: standard error very high in maximum liklihood fitting

2013-02-13 Thread Abu Naser

I thought it was going to the r-list.







 

> Date: Wed, 13 Feb 2013 11:33:13 -0500
> From: bbol...@gmail.com
> To: likhonna...@hotmail.com
> Subject: Re: [R] standard error very high in maximum liklihood fitting
> 
>   I can't respond to e-mails off-list.  Please follow up on r-help.
> 
>   cheers
> Ben Bolker
> 
> On 13-02-13 09:46 AM, Abu Naser wrote:
> > Thank you Ben for responding my email. I tried with the small data set.
> > It was the same:
> > 
> > fit1=fitdistcens(dr8, "gumbel", start=list(a=170, b=1), optim.method=
> > "L-BFGS-B", lower = 0.0, upper = Inf)
> > 
> > estimate Std. Error
> > a 169.9770615  43631.070
> > b   0.4807869   2053.354
> > Loglikelihood:  -1.340523e-09   AIC:  4   BIC:  9.08659
> > Correlation matrix:
> >a  b
> > a  1.000 -0.9574057
> > b -0.9574057  1.000
> > 
> > I think censoring causing the problem. The following was my data:
> > 
> >left right
> > 1NA   200
> > 2NA   184
> > 3NA   185
> > 4NA   212
> > 5NA   181
> > 6NA   188
> > 7NA   184
> > 8NA   195
> > 9NA   181
> > 10   NA   183
> > 11   NA   191
> > 12   NA   214
> > 13   NA   183
> > 14   NA   193
> > 15   NA   182
> > 16   NA   194
> > 17   NA   188
> > 18   NA   202
> > 19   NA   186
> > 20   NA   185
> > 21   NA   215
> > 22   NA   183
> > 23   NA   184
> > 24   NA   184
> > 25   NA   186
> > 26   NA   183
> > 27   NA   196
> > 28   NA   195
> > 29   NA   197
> > 30   NA   181
> > 31   NA   193
> > 32   NA   183
> > 33   NA   187
> > 34   NA   192
> > 35   NA   186
> > 36   NA   186
> > 37   NA   187
> > 38   NA   182
> > 39   NA   203
> > 40   NA   182
> > 41   NA   181
> > 42   NA   183
> > 43   NA   189
> > 44   NA   185
> > 45   NA   183
> > 46   NA   193
> > 47   NA   186
> > 48   NA   182
> > 49   NA   198
> > 50   NA   189
> > 51   NA   187
> > 52   NA   190
> > 53   NA   181
> > 54   NA   192
> > 55   NA   185
> > 56   NA   190
> > 57   NA   196
> > 58   NA   181
> > 59   NA   186
> > 60   NA   182
> > 61   NA   213
> > 62   NA   181
> > 63   NA   184
> > 64   NA   189
> > 65   NA   187
> > 66   NA   182
> > 67   NA   223
> > 68   NA   184
> > 69   NA   185
> > 70   NA   185
> > 71   NA   222
> > 72   NA   188
> > 73   NA   187
> > 74   NA   196
> > 75   NA   194
> > 76   NA   181
> > 77   NA   193
> > 78   NA   185
> > 79   NA   181
> > 80   NA   181
> > 81   NA   182
> > 82   NA   184
> > 83   NA   193
> > 84   NA   209
> > 85   NA   181
> > 86   NA   183
> > 87   NA   184
> > 88   NA   186
> > 89   NA   196
> > 90   NA   198
> > 91   NA   182
> > 92   NA   202
> > 93   NA   197
> > 94   NA   217
> > 
> >  
> > 
> > 
> >> To: r-h...@stat.math.ethz.ch
> >> From: bbol...@gmail.com
> >> Date: Tue, 12 Feb 2013 16:13:27 +
> >> Subject: Re: [R] standard error very high in maximum liklihood fitting
> >>
> >> Abu Naser  hotmail.com> writes:
> >>
> >> > I have been trying to fit my data (only right censored)
> >> > with gumbel distribution using fitdistrplus. I am
> >> > getting very high standard error. I have been wondering why.
> >> > The followings are the outputs:
> >> >
> >> > fit1=fitdistcens(dr0, "gumbel", start=list(a=99, b=0.6),
> >> > optim.method= "L-BFGS-B", lower = 0.0,
> >> > upper = Inf)
> >> > > summary(fit1)
> >>
> >> [snip]
> >>
> >> > estimate Std. Error
> >> > a 97.8260371 3115.09
> >> > b 0.1115094 173.79
> >> > Loglikelihood: -9.749883e-10 AIC: 4 BIC: 21.21178
> >>
> >> [snip]
> >>
> >> Impossible to say without a reproducible example. It seems
> >> very suspicious that your log-likelihood is almost exactly zero.
> >> Do you have a very small data set?
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/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] fill colour in grid

2013-02-13 Thread Roslina Zakaria
Dear all r-users,
 
I have this code below to draw two squares, small and big square.  I would like 
to colour the small square with red and the big square with blue for example.  
I tried using polygon but fail.  Thank you so much for your help.
 
 
par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i")
plot.new()
plot.window(xlim= c(0,8), ylim=c(0,8),col="blue",lwd=3, bg=5)
axis(1)
axis(2)
title(main="The Overall Title")
title(xlab="An x-axis label")
title(ylab="A y-axis label")
box()
#segments(x0, y0, x1, y1, col = par("fg"), lty = par("lty"), lwd = par("lwd"))
segments(0, 0, 4, 0, col=1, lty = 1, lwd = 3)
segments(4, 0, 4, 4, col=2, lty = 1, lwd = 3)
segments(0, 0, 0, 4, col=3, lty = 1, lwd = 3)
segments(0, 4, 4, 4, col=2, lty = 1, lwd = 3)
segments(3, 3, 4, 3, col=5, lty = 1, lwd = 3)
segments(3, 3, 3, 4, col=5, lty = 1, lwd = 3)
polygon(c(3,4) , col="purple")
#grid(nx = NULL, ny = nx, col = "lightgray", lty = "dotted", lwd = par("lwd"), 
equilogs = TRUE)
grid(nx = 8)
[[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] sweave question

2013-02-13 Thread Yihui Xie
Other people in this thread have explained the rule of double
backslashes. I just want to add one more comment:

That clever solution was in 2009 when knitr has not come out, and I
have used this picture several times to show how much I dislike it:
http://yihui.name/en/2012/06/enjoyable-reproducible-research/

With knitr, you can easily write your big code chunk (with lots of
"cats" jumping around) in a much more compact way:

<>=
plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
@

Note the number "5" alone is not a legal LaTeX length; you should add
the unit such as "5in" or "5cm", etc. This chunk in knitr will
generate everything for you:

- the figure environment
- center the figure
- add the figure position ht!
- add the figure caption
- add figure width and height
- add the figure label fig:figthree

You, as the author, only write the R code (instead of both R and
LaTeX); other people, as the readers, only see the R code. Everything
else should go behind the scene.

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Wed, Feb 13, 2013 at 4:59 PM, Mark Leeds  wrote:
> Hi Everyone: I was having trouble getting the plot size correct when
> putting a plot in an sweave document. So, I searched on the internet and I
> found a clever solution where the person uses
> the cat function to write latex code so he can include the cat code in the
> chunk and place the plot using width and height. The solution is here:
> https://stat.ethz.ch/pipermail/r-help/2009-April/195094.html.
>
> But the solution uses a backslash before the ending quotes in the cat
> statements  that might be windows relevant possibly ? I'm not sure about
> that part but I'm on linux and when I tried my way to mimic that solution
> in the latex/sweave code below ( I think it's the same solution but without
> the backslash on the closing quotes. I tried that also but got a different
> error ) , Sweave doesn't like the start of the includegraphics command. The
> error I get from Sweave is
>
> #===
> Error:  chunk 9 (label = fig3)
> Error : '\i' is an unrecognized escape in character string starting "\i"
> Execution halted
> :~/research/equity/projects/tree_returns/report>
> #=
>
> The code is below but if anyone is interested and thinks they need the
> whole file to look at the problem, I can send it. I just didn't want to
> send the whole file here. Definitely the error has to do with the chunk
> below for sure ( even though it says chunk 9 because there is no chunk 9
> ).  Thanks a lot to anyone who can be bothered investigating because I've
> spent pretty much the whole day on this and think it's
> time to surrender !! or atleast give up for now and come back to it
> with a fresher brain. Have a good night.
>
> # THE LATEX/SWEAVE CODE
> #
>
> cal.tree is created in a previous chunk and that's fine.
>
> <>=
> wid <- 5
> hei <- 5
> pdf("reg_tree-fig3.pdf", width = wid, height = hei)
> plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
> text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
> dev.off()
> cat("\begin{figure}[ht!]")
> cat("\begin{center}")
> cat("\includegraphics[width = ", wid, ", height = ", hei,
> "]{reg_tree-fig3}")
> cat("\end{center}")
> cat("\caption{The resulting unpruned regression tree of the california real
> estate data}")
> cat("\label{FIG:figthree}")
> cat("\end{figure}")
> @
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] fill colour in grid

2013-02-13 Thread Pascal Oettli

Hi,

?rect

par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i")
plot.new()
plot.window(xlim= c(0,8), ylim=c(0,8),col="blue",lwd=3, bg=5)
axis(1)
axis(2)
title(main="The Overall Title")
title(xlab="An x-axis label")
title(ylab="A y-axis label")
box()
rect(0,0,4,4,col='blue',border=NA)
rect(3,3,4,4,col='red',border=NA)
grid(nx = 8)

The same using "polygon"

par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i")
plot.new()
plot.window(xlim= c(0,8), ylim=c(0,8),col="blue",lwd=3, bg=5)
axis(1)
axis(2)
title(main="The Overall Title")
title(xlab="An x-axis label")
title(ylab="A y-axis label")
box()
polygon(c(0,4,4,0),c(0,0,4,4),col='blue',border=NA)
polygon(c(3,4,4,3),c(3,3,4,4),col='red',border=NA)
grid(nx = 8)

HTH,
Pascal


Le 14/02/2013 10:56, Roslina Zakaria a écrit :

Dear all r-users,

I have this code below to draw two squares, small and big square.  I would like 
to colour the small square with red and the big square with blue for example.  
I tried using polygon but fail.  Thank you so much for your help.


par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i")
plot.new()
plot.window(xlim= c(0,8), ylim=c(0,8),col="blue",lwd=3, bg=5)
axis(1)
axis(2)
title(main="The Overall Title")
title(xlab="An x-axis label")
title(ylab="A y-axis label")
box()
#segments(x0, y0, x1, y1, col = par("fg"), lty = par("lty"), lwd = par("lwd"))
segments(0, 0, 4, 0, col=1, lty = 1, lwd = 3)
segments(4, 0, 4, 4, col=2, lty = 1, lwd = 3)
segments(0, 0, 0, 4, col=3, lty = 1, lwd = 3)
segments(0, 4, 4, 4, col=2, lty = 1, lwd = 3)
segments(3, 3, 4, 3, col=5, lty = 1, lwd = 3)
segments(3, 3, 3, 4, col=5, lty = 1, lwd = 3)
polygon(c(3,4) , col="purple")
#grid(nx = NULL, ny = nx, col = "lightgray", lty = "dotted", lwd = par("lwd"), 
equilogs = TRUE)
grid(nx = 8)
[[alternative HTML version deleted]]



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



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


Re: [R] Running a R file at a specific time each day

2013-02-13 Thread Greg Snow
If you are on windows then there is a task scheduler for windows.

Generally the best solutions are to use the OS tools to schedule your task,
chron or task scheduler.

If you need a solution inside of R then you can use the tclTaskSchedule
function in the tcltk2 package.


On Mon, Feb 11, 2013 at 11:51 AM, Christofer Bogaso <
bogaso.christo...@gmail.com> wrote:

> Hello again,
>
> My query may look quite generic, however at this point of time I just
> want explain my problem. I am hopeful that somebody can help me.
>
> Let say I have a script file 'Script.R'. Now I want R to run this
> script file each day at a specific time, and store the result (the
> calculation for the result are already in that script file) in excel
> (or may be csv file) for each day.
>
> Is there in possibility to achieve that?
>
> Thanks and regards,
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] Data sets online for student use

2013-02-13 Thread Greg Snow
The thread starting with this post:
https://stat.ethz.ch/pipermail/r-sig-teaching/2013q1/000534.html answers a
similar question and many of the answers there should apply here as well.


On Tue, Feb 12, 2013 at 11:51 AM, David Arnold wrote:

> All,
>
> If you have any good links for sites that contain data sets that can easily
> be accessed and copied (or downloaded) by students in introductory
> statistics, could you please share them?
>
> Thanks.
>
> David
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Data-sets-online-for-student-use-tp4658326.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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] Is there a place to put executable R scripts in new packages?

2013-02-13 Thread Greg Snow
See ?commandArgs for a way to access the arguments on the command line.
 With that you can write the FunkyCold.R script to grab the command line
arguments and run the proper function (after loading your package).  If you
give more detail on what you want to accomplish we may be able to give more
help.

Also look at ?Startup for details of what happens when R starts, I have
used this information to create desktop icons for clients (in windows) so
that they double click on the icon and a particular function runs inside of
R.


On Tue, Feb 12, 2013 at 9:09 PM, Asis Hallab  wrote:

> Dear R users,
>
> writing an R package I wonder, if there is a place to put executable R
> scripts into. So that when the package is installed one can use the
> script from the command line.
>
> Say we have e new package called FunkyR and wanted to deliver with it
> an executable called FunkyCold.R, so that from the command line, one
> could do the following:
>
> Rscript FunkyCold.R argument_1 argument_2
>
> Any hints or suggestions?
>
> Kind regards!
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] Plotting multiple xyplots in same page

2013-02-13 Thread Pascal Oettli

Hello,

Herewith is one approach:

grid1 <- rbind(OrchardSprays, OrchardSprays, OrchardSprays, 
OrchardSprays, OrchardSprays, OrchardSprays)


grid1$category <- rep(c('A','B','C','D','E','F'), each=nrow(OrchardSprays))

trellis.par.set(theme = col.whitebg())
xy <- xyplot(decrease ~ treatment | category, grid1, groups = rowpos, 
type = "a", layout=c(3,2), auto.key = list(x = 0, y = 0.9, cex = 0.52, 
points = FALSE, lines = TRUE), scales=list(x=list(alternating=1), 
y=list(alternating=1)))


xy$x.between <- 1
xy$y.between <- 1
print(xy)

HTH,
Pascal


Le 14/02/2013 08:10, Lisa Daniel a écrit :

Dear Rhelp,

I was able to plot 6 figures in one page.  I do need help in reducing the space 
between the title and the plot and assigning A,B,C,D,E,F to each figure
library(lattice)
trellis.par.set(theme = col.whitebg())
xy <- xyplot(decrease ~ treatment, OrchardSprays,
 main="Some plot",
   groups = rowpos, type = "a",
   auto.key = list(x = 0.2, y = 0.9,
 cex = 0.52, points = FALSE, lines = TRUE))


print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)

Thanks in advance,
Lisa



- Original Message -
From: Lisa Daniel 
To: "r-help@r-project.org" 
Cc:
Sent: Wednesday, February 13, 2013 5:28 PM
Subject: Plotting multiple xyplots in same page

Dear Rhelp,

I would like to have 6 xyplots in the same page.  Similar to (par(mfrow=c(3,3))
Found this example on the R archives.
library(lattice)
trellis.par.set(theme = col.whitebg())
xy <- xyplot(decrease ~ treatment, OrchardSprays,
   groups = rowpos, type = "a",
   auto.key = list(x = 0.2, y = 0.9,
 cex = 0.75, points = FALSE, lines = TRUE))

print(xy, pos = c(0.0, 0.0, 0.5, 0.5), more = TRUE)
print(xy, pos = c(0.0, 0.5, 0.5, 1.0), more = TRUE)
print(xy, pos = c(0.5, 0.0, 1.0, 0.5), more = TRUE)
print(xy, pos = c(0.5, 0.5, 1.0, 1.0), more = FALSE)




When I changed the print() to:

  print(xy, pos=c(0.0,0.0,0.33,0.33),more = TRUE),
the figure was not looking good.

Also, is it possible to assign A, B, C,D, etc for each figure.



a<- rnorm(1000,0,1)
b<- rnorm(1000,0,2)
c<- rnorm(1000,0,3)
d<- rnorm(1000,0,4)
par(mfrow=c(2,2))
hist(a,main="")
title(main="A",adj=0)
hist(b,main="")
title(main="B",adj=0)
hist(c,main="")
title(main="C",adj=0)
hist(d,main="")
title(main="D",adj=0)


I tried this to xyplot, but it was not working.

Please help me.

Many thanks in advance,
Lisa.


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

2013-02-13 Thread Murat Tasan
i'm somehow embarrassed to even ask this, but is there any built-in
method for doing this:

my_list <- list()
my_list[[1]] <- matrix(1:20, ncol = 5)
my_list[[2]] <- matrix(20:1, ncol = 5)

now, knowing that these matrices are identical in dimension, i'd like
to unfold the list to a 2x4x5 (or some other permutation of the dim
sizes) array.
i know i can initialize the array, then loop through my_list to fill
the array, but somehow this seems inelegant.
i also know i can vectorize the matrices and unlist the list, then
build the array from that single vector, but this also seems inelegant
(and an easy place to introduce errors/bugs).

i can't seem to find any built-in that handles this already... but
maybe i just haven't looked hard enough :-/

cheers,

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


Re: [R] list of matrices --> array

2013-02-13 Thread Murat Tasan
FYI - this is my current method, but somehow i just don't like it ;-)

foo <- array(NA, dim = c(4,5,length(my_list)))
for(k in 1:length(my_list)) {
  foo[,,k] <- my_list[[k]]
}

-m

On Thu, Feb 14, 2013 at 1:03 AM, Murat Tasan  wrote:
> i'm somehow embarrassed to even ask this, but is there any built-in
> method for doing this:
>
> my_list <- list()
> my_list[[1]] <- matrix(1:20, ncol = 5)
> my_list[[2]] <- matrix(20:1, ncol = 5)
>
> now, knowing that these matrices are identical in dimension, i'd like
> to unfold the list to a 2x4x5 (or some other permutation of the dim
> sizes) array.
> i know i can initialize the array, then loop through my_list to fill
> the array, but somehow this seems inelegant.
> i also know i can vectorize the matrices and unlist the list, then
> build the array from that single vector, but this also seems inelegant
> (and an easy place to introduce errors/bugs).
>
> i can't seem to find any built-in that handles this already... but
> maybe i just haven't looked hard enough :-/
>
> cheers,
>
> -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.


Re: [R] list of matrices --> array

2013-02-13 Thread arun
Hi,

May be this helps:
library(plyr)
res<-aaply(laply(my_list, as.matrix),c(2,3),function(x) x)
attr(res,"dimnames")<- NULL
 identical(res,foo)
#[1] TRUE
A.K.




- Original Message -
From: Murat Tasan 
To: r-help@r-project.org
Cc: 
Sent: Thursday, February 14, 2013 1:13 AM
Subject: Re: [R] list of matrices --> array

FYI - this is my current method, but somehow i just don't like it ;-)

foo <- array(NA, dim = c(4,5,length(my_list)))
for(k in 1:length(my_list)) {
  foo[,,k] <- my_list[[k]]
}

-m

On Thu, Feb 14, 2013 at 1:03 AM, Murat Tasan  wrote:
> i'm somehow embarrassed to even ask this, but is there any built-in
> method for doing this:
>
> my_list <- list()
> my_list[[1]] <- matrix(1:20, ncol = 5)
> my_list[[2]] <- matrix(20:1, ncol = 5)
>
> now, knowing that these matrices are identical in dimension, i'd like
> to unfold the list to a 2x4x5 (or some other permutation of the dim
> sizes) array.
> i know i can initialize the array, then loop through my_list to fill
> the array, but somehow this seems inelegant.
> i also know i can vectorize the matrices and unlist the list, then
> build the array from that single vector, but this also seems inelegant
> (and an easy place to introduce errors/bugs).
>
> i can't seem to find any built-in that handles this already... but
> maybe i just haven't looked hard enough :-/
>
> cheers,
>
> -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] spearman correlation and p-value as a matrix

2013-02-13 Thread arun
HI,

#ag data was created
bg<- as.matrix(read.table(text=" 
 Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 
Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 
Otu00218 
Gi20Jun11  0.001217    0 0.001217    0 0.00    0    0   
 0 0.001217    0    0    0    0    0 0.001217    0 
0.001217 
Gi40Jun11  0.00    0 0.00    0 0.00    0    0   
 0 0.00    0    0    0    0    0 0.00    0 
0.00 
Gi425Jun11 0.00    0 0.00    0 0.00    0    0   
 0 0.00    0    0    0    0    0 0.00    0 
0.00 
Gi45Jun11  0.00    0 0.00    0 0.001513    0    0   
 0 0.00    0    0    0    0    0 0.00    0 
0.00 
Gi475Jun11 0.00    0 0.00    0 0.00    0    0   
 0 0.00    0    0    0    0    0 0.00    0 
0.00 
Gi50Jun11  0.00    0 0.00    0 0.00    0    0   
 0 0.00    0    0    0    0    0 0.00    0 
0.00 
",sep="",header=TRUE,stringsAsFactors=F))
set.seed(128)
ag<- matrix(rnorm(30),nrow=6)
colnames(ag)<- paste("ag",1:5,sep="")
bg_ag<-expand.grid(colnames(bg),colnames(ag),stringsAsFactors=FALSE)
 attr(bg_ag,"out.attrs")<- NULL
 library(Hmisc)
#correlation
resr<-do.call(rbind,lapply(split(bg_ag,1:nrow(bg_ag)),function(x) 
{res<-rcorr(cbind(bg[,x[,1]],ag[,x[,2]]),type="spearman")$r; row.names(res)<- 
rep(paste(x[1],x[2],sep="_"),2);res}))
 head(resr)
# [,1]  [,2]
#Otu00022_ag1 1.000 0.1309307
#Otu00022_ag1 0.1309307 1.000
#Otu00029_ag1 1.000   NaN
#Otu00029_ag1   NaN 1.000
#Otu00039_ag1 1.000 0.1309307
#Otu00039_ag1 0.1309307 1.000

#p-values
resP<-do.call(rbind,lapply(split(bg_ag,1:nrow(bg_ag)),function(x) 
{res<-rcorr(cbind(bg[,x[,1]],ag[,x[,2]]),type="spearman")$P; row.names(res)<- 
rep(paste(x[1],x[2],sep="_"),2);res}))
  head(resP)
#  [,1]  [,2]
#Otu00022_ag1    NA 0.8047262
#Otu00022_ag1 0.8047262    NA
#Otu00029_ag1    NA   NaN
#Otu00029_ag1   NaN    NA
#Otu00039_ag1    NA 0.8047262
#Otu00039_ag1 0.8047262    NA

#If you need only the values
indx<-row(resr)%%2!=1
 resPnew<-as.matrix(resP[indx[,1],1])
 resrnew<-as.matrix(resr[indx[,1],1])

head(resPnew)
#  [,1]
#Otu00022_ag1 0.8047262
#Otu00029_ag1   NaN
#Otu00039_ag1 0.8047262
#Otu00042_ag1   NaN
#Otu00101_ag1 0.1583024
#Otu00105_ag1   NaN

head(resrnew)
#   [,1]
#Otu00022_ag1  0.1309307
#Otu00029_ag1    NaN
#Otu00039_ag1  0.1309307
#Otu00042_ag1    NaN
#Otu00101_ag1 -0.6546537
#Otu00105_ag1    NaN

A.K.




- Original Message -
From: Ozgul Inceoglu 
To: r-help@r-project.org
Cc: 
Sent: Wednesday, February 13, 2013 4:48 AM
Subject: [R] spearman correlation and p-value as a matrix

I have two data matrices that I want to make the correlation between each 
column from data1 and each column from data 2 and also calculate the p-value 
Matrices dont have the same size and I tried such a script.
> bg <- read.table (file.choose(), header=T, row.names) 
> bg 
> Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 
> Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 
> Otu00218 
> Gi20Jun11 0.001217 0 0.001217 0 0.00 0 0 0 0.001217 0 0 0 0 0 0.001217 0 
> 0.001217 
> Gi40Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
> 0.00 
> Gi425Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
> 0.00 
> Gi45Jun11 0.00 0 0.00 0 0.001513 0 0 0 0.00 0 0 0 0 0 0.00 0 
> 0.00 
> Gi475Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
> 0.00 
> Gi50Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
> 0.00 
ag <- read.table (file.choose(), header=T, row.names) 

for (i in 1:(ncol(bg))) 
for (j in 1:(ncol(ag))) 
print(c(i,j))
final_matrix <- matrix(rep("0",ncol(bg)*ncol(ag)),ncol=ncol(bg),nrow=ncol(ag))

cor <- cor.test(as.vector(as.matrix(bg[,i])),as.vector(as.matrix(ag[,j])), 
method="spearman")

#but the output is not matrice with all the values but a single correlation 
value

data:  bg[, i] and ag[, j] 
t = 2.2992, df = 26, p-value = 0.02978
alternative hypothesis: true correlation is not equal to 0 
95 percent confidence interval:
0.04485289 0.67986803 
sample estimates:
      cor 
0.4110515 

# How I can creat an outfile with all the correlations and p-values?

Thank you very much!
Özgül

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

Re: [R] match in dependence of 2 columns

2013-02-13 Thread Mat
thank you, this code works:

library(plyr)
join(dat1,dat2,by=c("cu.nr.","name"),type="right") 

but my dat2 frame has a lot of columns, which i don't want to match.
How can i say, that only the column "value" should be match to dat1 ?

Thank you.

Mat




--
View this message in context: 
http://r.789695.n4.nabble.com/match-in-dependence-of-2-columns-tp4658405p4658508.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] Plotting multiple xyplots in same page

2013-02-13 Thread Lisa Daniel
Dear Duncan,

Thank you.  It helped a lot.
I was able to get it correct though I couldn't get it working under 
simpleTheme() (for publication purpose).

#this gave me the correct format.
library(grid)
library(lattice)
xy <-xyplot(decrease ~ treatment, OrchardSprays,
    main= "Some plot",
    groups = rowpos, type = "a",
    page = function(n){
 grid.text(LETTERS[j],
 y = 0.95,
 x = 0.15,
 default.units = "npc",
 just = c("left"),
 gp = gpar(fontsize = 12,fontface="bold") )
   },
    par.settings = list(
 layout.heights = list(main = 1.2,
   sub  = 0,
   axis.top = 0.2,
   top.padding  = 0.1,
   bottom.padding = 0) ),
    auto.key = list(x = 0.2, y = 0.9,
    cex = 0.75, points = FALSE, lines = TRUE)) 
#pdf("trial.pdf",width=12)
#jpeg("trial.jpeg",quality=100,width=680,height=480)
j=1
print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)
#dev.off()


# I tried the same with simpleTheme(), but I am not getting it correct, (the 
lines are colored):

pset <- simpleTheme(lty = 1:8, col="black",lwd=2)  
xy <-xyplot(decrease ~ treatment, OrchardSprays,
    main= "Some plot",
    groups = rowpos, type = "a",
    page = function(n){
 grid.text(LETTERS[j],
 y = 0.95,
 x = 0.15,
 default.units = "npc",
 just = c("left"),
 gp = gpar(fontsize = 12,fontface="bold") )
   },
    par.settings = list(pset,
 layout.heights = list(main = 1.2,
   sub  = 0,
   axis.top = 0.2,
   top.padding  = 0.1,
   bottom.padding = 0) ),
    auto.key = list(x = 0.2, y = 0.9,
    cex = 0.75, points = FALSE, lines = TRUE)) 
j=1
print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)


#the output from the below code is B&W, but space between title and figure not 
corrected

pset <- simpleTheme(lty = 1:8, col="black",lwd=2)  
xy <-xyplot(decrease ~ treatment, OrchardSprays,
    main= "Some plot",
    groups = rowpos, type = "a",
    page = function(n){
 grid.text(LETTERS[j],
 y = 0.95,
 x = 0.15,
 default.units = "npc",
 just = c("left"),
 gp = gpar(fontsize = 12,fontface="bold") )
   },
    par.settings = pset,
    auto.key = list(x = 0.2, y = 0.9,
    cex = 0.75, points = FALSE, lines = TRUE)) 

j=1
print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)


Also, I would like to create a main title for the first row and second row of 
figures.
Many thanks in advance,
Lisa


- Original Message -
From: Duncan Mackay 
To: Lisa Daniel ; r-help-r-project.org 

Cc: 
Sent: Wednesday, February 13, 2013 7:53 PM
Subject: Re: [R] Plotting multiple xyplots in same page

Hi Lisa

have a look at par.settings in ?xyplot

trellis.par.get() shows the settings

trellis.par.get()[[27]]
$left
$left$tck
[1] 1

$left$pad1
[1] 1

$left$pad2
[1] 1


$top
$top$tck
[1] 1

$top$pad1
[1] 1

$top$pad2
[1] 1


$right
$right$tck
[1] 1

$right$pad1
[1] 1

$right$pad2
[1] 1


$bottom
$bottom$tck
[1] 1

$bottom$pad1
[1] 1

$bottom$pad2
[1] 1

as an example:

par.settings = list(
layout.heights = list(main = 0,
                       sub  = 0,
                       axis.top = 0.2,
                       top.padding  = 0,
                       bottom.padding = 0)    )

HTH

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au




At 09:10 14/02/2013, you wrote:
>Dear Rhelp,
>
>I was able to plot 6 figures in one page.  I do need help in 
>reducing the space between the title and

Re: [R] spearman correlation and p-value as a matrix

2013-02-13 Thread Ozgul Inceoglu
Thank you all for the answers. I really need to learn a lot. 
Bu I also discover cor2m(x, y, trim = TRUE, alpha = 0.05)
in ecodist package, which gives an output file with significant correlations.

Özgül

Yj>HI,
>
>#ag data was created
>bg<- as.matrix(read.table(text=" 
> Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 
>Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 
>Otu00218 
>Gi20Jun11  0.001217    0 0.001217    0 0.00    0    0  
>  0 0.001217    0    0    0    0    0 0.001217    0 
>0.001217 
>Gi40Jun11  0.00    0 0.00    0 0.00    0    0  
>  0 0.00    0    0    0    0    0 0.00    0 
>0.00 
>Gi425Jun11 0.00    0 0.00    0 0.00    0    0  
>  0 0.00    0    0    0    0    0 0.00    0 
>0.00 
>Gi45Jun11  0.00    0 0.00    0 0.001513    0    0  
>  0 0.00    0    0    0    0    0 0.00    0 
>0.00 
>Gi475Jun11 0.00    0 0.00    0 0.00    0    0  
>  0 0.00    0    0    0    0    0 0.00    0 
>0.00 
>Gi50Jun11  0.00    0 0.00    0 0.00    0    0  
>  0 0.00    0    0    0    0    0 0.00    0 
>0.00 
>",sep="",header=TRUE,stringsAsFactors=F))
>set.seed(128)
>ag<- matrix(rnorm(30),nrow=6)
>colnames(ag)<- paste("ag",1:5,sep="")
>bg_ag<-expand.grid(colnames(bg),colnames(ag),stringsAsFactors=FALSE)
> attr(bg_ag,"out.attrs")<- NULL
> library(Hmisc)
>#correlation
>resr<-do.call(rbind,lapply(split(bg_ag,1:nrow(bg_ag)),function(x) 
>{res<-rcorr(cbind(bg[,x[,1]],ag[,x[,2]]),type="spearman")$r; row.names(res)<- 
>rep(paste(x[1],x[2],sep="_"),2);res}))
> head(resr)
># [,1]  [,2]
>#Otu00022_ag1 1.000 0.1309307
>#Otu00022_ag1 0.1309307 1.000
>#Otu00029_ag1 1.000   NaN
>#Otu00029_ag1   NaN 1.000
>#Otu00039_ag1 1.000 0.1309307
>#Otu00039_ag1 0.1309307 1.000
>
>#p-values
>resP<-do.call(rbind,lapply(split(bg_ag,1:nrow(bg_ag)),function(x) 
>{res<-rcorr(cbind(bg[,x[,1]],ag[,x[,2]]),type="spearman")$P; row.names(res)<- 
>rep(paste(x[1],x[2],sep="_"),2);res}))
>  head(resP)
>#  [,1]  [,2]
>#Otu00022_ag1    NA 0.8047262
>#Otu00022_ag1 0.8047262    NA
>#Otu00029_ag1    NA   NaN
>#Otu00029_ag1   NaN    NA
>#Otu00039_ag1    NA 0.8047262
>#Otu00039_ag1 0.8047262    NA
>
>#If you need only the values
>indx<-row(resr)%%2!=1
> resPnew<-as.matrix(resP[indx[,1],1])
> resrnew<-as.matrix(resr[indx[,1],1])
>
>head(resPnew)
>#  [,1]
>#Otu00022_ag1 0.8047262
>#Otu00029_ag1   NaN
>#Otu00039_ag1 0.8047262
>#Otu00042_ag1   NaN
>#Otu00101_ag1 0.1583024
>#Otu00105_ag1   NaN
>
>head(resrnew)
>#   [,1]
>#Otu00022_ag1  0.1309307
>#Otu00029_ag1    NaN
>#Otu00039_ag1  0.1309307
>#Otu00042_ag1    NaN
>#Otu00101_ag1 -0.6546537
>#Otu00105_ag1    NaN
>
>A.K.
>
>
>
>
>- Original Message -
>From: Ozgul Inceoglu 
>To: r-help@r-project.org
>Cc: 
>Sent: Wednesday, February 13, 2013 4:48 AM
>Subject: [R] spearman correlation and p-value as a matrix
>
>I have two data matrices that I want to make the correlation between each 
>column from data1 and each column from data 2 and also calculate the p-value 
>Matrices dont have the same size and I tried such a script.
>> bg <- read.table (file.choose(), header=T, row.names) 
>> bg 
>> Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 
>> Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 
>> Otu00218 
>> Gi20Jun11 0.001217 0 0.001217 0 0.00 0 0 0 0.001217 0 0 0 0 0 0.001217 0 
>> 0.001217 
>> Gi40Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
>> 0.00 
>> Gi425Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 
>> 0 0.00 
>> Gi45Jun11 0.00 0 0.00 0 0.001513 0 0 0 0.00 0 0 0 0 0 0.00 0 
>> 0.00 
>> Gi475Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 
>> 0 0.00 
>> Gi50Jun11 0.00 0 0.00 0 0.00 0 0 0 0.00 0 0 0 0 0 0.00 0 
>> 0.00 
>ag <- read.table (file.choose(), header=T, row.names) 
>
>for (i in 1:(ncol(bg))) 
>for (j in 1:(ncol(ag))) 
>print(c(i,j))
>final_matrix <- matrix(rep("0",ncol(bg)*ncol(ag)),ncol=ncol(bg),nrow=ncol(ag))
>
>cor <- cor.test(as.vector(as.matrix(bg[,i])),as.vector(as.matrix(ag[,j])), 
>method="spearman")
>
>#but the output is not matrice with all the values but a single correlation 
>value
>
>data:  bg[, i] and ag[, j] 
>t = 2.2992, df = 26, p-value = 0.02978
>alternative hypothesis: true correlation is not equal to 0 
>95 percent confidence interval:
>0.04485289 0.67986803 
>sample estimates:
>      cor 
>0.4110515 
>
># How I 

Re: [R] Plotting multiple xyplots in same page

2013-02-13 Thread Lisa Daniel
Dear Duncan and Pascal,
Thank you for the response.

Duncan: 

I was able to fix the space between title and figure.  I would also like to  
have separate main titles for each row of figures in addition to the individual 
titles.

xy <-xyplot(decrease ~ treatment, OrchardSprays,
    main= "Some plot",
    groups = rowpos, type = "a",
    page = function(n){
 grid.text(LETTERS[j],
 y = 0.95,
 x = 0.15,
 default.units = "npc",
 just = c("left"),
 gp = gpar(fontsize = 12,fontface="bold") )
   },
    par.settings = c(simpleTheme(lty=1:8, 
col="black",lwd=2),list(layout.heights = list(main = 1.2,
   sub  = 0,
   axis.top = 0.2,
   top.padding  = 0.1,
   bottom.padding = 0)) ),
    auto.key = list(x = 0.2, y = 0.9,
    cex = 0.75, points = FALSE, lines = TRUE)) 
j=1
print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)

Pascal:
I would prefer not to use panels as this is for publication purpose.  


Many thanks,
Lisa





- Original Message -
From: Duncan Mackay 
To: Lisa Daniel ; r-help-r-project.org 

Cc: 
Sent: Wednesday, February 13, 2013 7:53 PM
Subject: Re: [R] Plotting multiple xyplots in same page

Hi Lisa

have a look at par.settings in ?xyplot

trellis.par.get() shows the settings

trellis.par.get()[[27]]
$left
$left$tck
[1] 1

$left$pad1
[1] 1

$left$pad2
[1] 1


$top
$top$tck
[1] 1

$top$pad1
[1] 1

$top$pad2
[1] 1


$right
$right$tck
[1] 1

$right$pad1
[1] 1

$right$pad2
[1] 1


$bottom
$bottom$tck
[1] 1

$bottom$pad1
[1] 1

$bottom$pad2
[1] 1

as an example:

par.settings = list(
layout.heights = list(main = 0,
                       sub  = 0,
                       axis.top = 0.2,
                       top.padding  = 0,
                       bottom.padding = 0)    )

HTH

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au




At 09:10 14/02/2013, you wrote:
>Dear Rhelp,
>
>I was able to plot 6 figures in one page.  I do need help in 
>reducing the space between the title and the plot and assigning 
>A,B,C,D,E,F to each figure
>library(lattice)
>trellis.par.set(theme = col.whitebg())
>xy <- xyplot(decrease ~ treatment, OrchardSprays,
>         main="Some plot",
>               groups = rowpos, type = "a",
>               auto.key = list(x = 0.2, y = 0.9,
>                 cex = 0.52, points = FALSE, lines = TRUE))
>
>
>print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
>print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
>print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
>print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
>print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
>print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)
>
>Thanks in advance,
>Lisa
>
>
>
>- Original Message -
>From: Lisa Daniel 
>To: "r-help@r-project.org" 
>Cc:
>Sent: Wednesday, February 13, 2013 5:28 PM
>Subject: Plotting multiple xyplots in same page
>
>Dear Rhelp,
>
>I would like to have 6 xyplots in the same page.  Similar to 
>(par(mfrow=c(3,3))
>Found this example on the R archives.
>library(lattice)
>trellis.par.set(theme = col.whitebg())
>xy <- xyplot(decrease ~ treatment, OrchardSprays,
>               groups = rowpos, type = "a",
>               auto.key = list(x = 0.2, y = 0.9,
>                 cex = 0.75, points = FALSE, lines = TRUE))
>
>print(xy, pos = c(0.0, 0.0, 0.5, 0.5), more = TRUE)
>print(xy, pos = c(0.0, 0.5, 0.5, 1.0), more = TRUE)
>print(xy, pos = c(0.5, 0.0, 1.0, 0.5), more = TRUE)
>print(xy, pos = c(0.5, 0.5, 1.0, 1.0), more = FALSE)
>
>
>
>
>When I changed the print() to:
>
>  print(xy, pos=c(0.0,0.0,0.33,0.33),more = TRUE),
>the figure was not looking good.
>
>Also, is it possible to assign A, B, C,D, etc for each figure.
>
>
>
>a<- rnorm(1000,0,1)
>b<- rnorm(1000,0,2)
>c<- rnorm(1000,0,3)
>d<- rnorm(1000,0,4)
>par(mfrow=c(2,2))
>hist(a,main="")
>title(main="A",adj=0)
>hist(b,main="")
>title(main="B",adj=0)
>hist(c,main="")
>title(main="C",adj=0)
>hist(d,main="")
>title(main="D",adj=0)
>
>
>I tried this to xyplot, but it was not working.
>
>Please help me.
>
>Many thanks in advance,
>Lisa.
>
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/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-p