Re: [R] Mean using different group for a real r beginner

2013-05-17 Thread arun
Hi,
Try either:
tolerance - 
read.csv(http://www.ats.ucla.edu/stat/r/examples/alda/data/tolerance1.txt;) 

 aggregate(exposure~male,data=tolerance,mean)
 # male exposure
#1    0 1.246667
#2    1 1.12
#or
 library(plyr)
 ddply(tolerance,.(male),summarize,exposure=mean(exposure))
#  male exposure
#1    0 1.246667
#2    1 1.12
#or 

with(tolerance,tapply(exposure,list(male),FUN=mean))
#   0    1 
#1.246667 1.12 

#or

 with(tolerance,by(exposure,list(male),mean))
#: 0
#[1] 1.246667
# 
#: 1
#[1] 1.12
#or

 library(data.table)
 tolerance1- data.table(tolerance)
 tolerance1[,list(exposure=mean(exposure)),by=male]
#   male exposure
#1:    0 1.246667
#2:    1 1.12
#or
sapply(split(tolerance,tolerance$male),function(x) mean(x$exposure))
#   0    1 
#1.246667 1.12 

#or
library(psych)
 describeBy(tolerance$exposure,tolerance$male,mat=TRUE)[c(2,5)]
#   group1 mean
#11  0 1.246667
#12  1 1.12

#or
library(doBy)
summaryBy(exposure~male,data=tolerance,FUN=mean)
 # male exposure.mean
#1    0  1.246667
#2    1  1.12



A.K.




Hi there, 

I'm new to R and I think I have hard time getting used to it. 
Before asking my question, I looked on several websites, and while they 
have many  informations about it,  I did not find clear answer to my 
question. 

So, first of all, I use a web-based data set : 

tolerance - 
read.csv(http://www.ats.ucla.edu/stat/r/examples/alda/data/tolerance1.txt;) 

RIght now, I'm able to calculate the mean of the variable 
exposure. However, I'm unable to find a parsimonious way of obtaining 
the mean of exposure, separately for male == 0 and male == 1. The only 
solution I have, for the moment, is: 


tolerance_male = tolerance [male ==0, c (1:8)] 
exposure_male = tolerance_male$exposure 
mean (tolerance_male$exposure) 


tolerance_female = tolerance [male ==1, c (1:8)] 
exposure_female = tolerance_female$exposure 
mean (exposure_female) 

While this method work well for a simple calculation, it'll be 
quite unhelpful for more complicated analysis. So, I don't know if 
someone has a simpler way to do it. 

Thank you!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 use character in C code?

2013-05-17 Thread Jan van der Laan


Characters in R are zero terminated (although I couldn't find that in 
the R extensions manual). So, you could use:



void dealWithCharacter(char **chaine, int *size){
  Rprintf(The string is '%s'\n, chaine[0]);
}

Jan



On 05/10/2013 03:51 PM, cgenolin wrote:

Hi the list,
I include some C code in a R function using .C. The argument is a
character.
I find how to acces to the characters one by one:
--- 8 --- C 
void dealWithCharacter(char **chaine, int *size){
  int i=0;
  for(i=0;i*size;i++){
Rprintf(Le caractere %i est %c\n,i,chaine[0][i]);
  };
}
--- 8 -- R -
ch - zerta
.C(dealWithCharacter,as.character(ch),as.integer(nchar(ch)))
--- 8 --

But is it possible to acces to the full word at once?

Christophe


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Find the indices of non-NA elements of a sequence

2013-05-17 Thread jpm miao
Hi,

  I have a sequence whose 1st, 3rd, 4th, 6th are non-NAs. How could I let R
return 1,3,4,6, the indices?

  I know only how to find the non-NA elements. Thanks,

Miao

 test-c(2,NA,6,8,NA,12)
 test[is.na(test)==FALSE]
[1]  2  6  8 12

[[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] convert a data.frame to matrix

2013-05-17 Thread peter dalgaard

On May 17, 2013, at 01:59 , David Winsemius wrote:

 
 On May 16, 2013, at 1:46 PM, Hermann Norpois wrote:
 
 Hello,
 
 I fail to tranfer data from a dataframe to a matrix.
 
 jam is from a dataframe (and belongs still to the class dataframe) and
 should look like m (see below).
 
 jam
 vec1 vec3  d1  d2
 1  172  173 223 356
 dput (jam)
 structure(list(vec1 = 172L, vec3 = 173L, d1 = 223L, d2 = 356L), .Names =
 c(vec1,
 vec3, d1, d2), row.names = 1L, class = data.frame)
 m  #THIS IS THE AIM
[,1] [,2]
 [1,]  172  223
 [2,]  173  356
 
 dput (m)
 structure(c(172, 173, 223, 356), .Dim = c(2L, 2L))
 
 How can I transform jam to m?
 
 jam - structure(list(vec1 = 172L, vec3 = 173L, d1 = 223L, d2 = 356L), .Names 
 =
 c(vec1,
 vec3, d1, d2), row.names = 1L, class = data.frame)
 jm - data.matrix(jam)
 dim(jm) - c(2,2) # re-dimension a matrix with column-major order
 jm
 
 [,1] [,2]
 [1,]  172  223
 [2,]  173  356

also

 matrix(unlist(jam),2)
 [,1] [,2]
[1,]  172  223
[2,]  173  356


-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] Find the indices of non-NA elements of a sequence

2013-05-17 Thread Berend Hasselman

On 17-05-2013, at 08:36, jpm miao miao...@gmail.com wrote:

 Hi,
 
  I have a sequence whose 1st, 3rd, 4th, 6th are non-NAs. How could I let R
 return 1,3,4,6, the indices?
 
  I know only how to find the non-NA elements. Thanks,
 
 Miao
 
 test-c(2,NA,6,8,NA,12)
 test[is.na(test)==FALSE]
 [1]  2  6  8 12


?which

which(!is.na(test))

Berend

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

2013-05-17 Thread Sparks, John James
Dear R Helpers,

I need help with a slightly unusual situation in which I am trying to
select some columns from a data frame.  I know how to use the subset
statement with column names as in:


x=as.data.frame(matrix(c(1,2,3,
1,2,3,
1,2,2,
1,2,2,
1,1,1),ncol=3,byrow=T))

all.cols-colnames(x)
to.keep-all.cols[1:2]

Kept-subset(x,select=to.keep)
Kept

However, if I want to select some columns based on a selection of the most
important variables from a random forest then I find myself stuck.  The
example below demonstrates the problem.


library(randomForest)

data(mtcars)
mtcars.rf - randomForest(mpg ~ ., data=mtcars,importance=TRUE)
Importance-data.frame(mtcars.rf$importance)
Importance



MSEImportance-head(Importance[order(Importance$X.IncMSE,
decreasing=TRUE),],3)
MSEVars-row.names(MSEImportance)
MSEVars-data.frame(MSEVars,stringsAsFactors = FALSE)
colnames(MSEVars)-Vars

NodeImportance-head(Importance[order(Importance$IncNodePurity,decreasing=TRUE),],
3)
NodeVars-row.names(NodeImportance)
NodeVars-data.frame(NodeVars,stringsAsFactors = FALSE)
colnames(NodeVars)-Vars


ImportantVars-rbind(MSEVars,NodeVars)
ImportantVars-unique(ImportantVars)
nrow(ImportantVars)
ImportantVars-as.character(ImportantVars)
ImportantVars
CarsVarsKept-subset(mtcars,select=ImportantVars)
Error in `[.data.frame`(x, r, vars, drop = drop) :
  undefined columns selected

Any help on how to select these columns from the data frame would be most
appreciated.

--John J. Sparks, Ph.D.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] peering inside functions in a package?

2013-05-17 Thread Barry Rowlingson
On Fri, May 17, 2013 at 2:56 AM, Seth Myers sjmyers3...@gmail.com wrote:

 Let's say I would like to look inside the function corBrownian in library
 (ape).  When I type in the function name I get the following, which is not
 nearly the detail that goes into this function.  I am wondering how to
 begin cracking this function open (and others) so I can learn more about it
 and perhaps code my own corClass one day.  Thanks.

  corBrownian
 function (value = 1, phy, form = ~1)
 {
 if (!inherits(phy, phylo))
 stop(object \phy\ is not of class \phylo\)
 attr(value, formula) - form
 attr(value, fixed) - TRUE
 attr(value, tree) - phy
 class(value) - c(corBrownian, corPhyl, corStruct)
 value
 }
 environment: namespace:ape


Your premise is wrong! This is exactly all that goes into the corBrownian
function. All that it does is create a thing with some values and most
importantly, a set of class attributes.

 It's via that class attribute that your corBrownian objects get their
behaviour via _method_ functions.  If you download the source code for ape
from CRAN and have a look in PGLS.R you will see a bunch of functions such
as Initialize.corPhyl and corMatrix.corBrownian which are methods for
Initialize and corMatrix for corPhyl classes and corBrownian classes
respectively.

 So when you come to use one of these correlation structures, the calling
code doesn't care how the correlation structure computes its correlation
matrix, it just calls the corMatrix function and the object-oriented magic
calls the specific one for that specific class of model.

 So in ape, all the phylogenetic correlation classes are initialised with
Initialize.corPhyl and the Brownian one has corMatrix.corBrownian as the
method for computing its correlation matrix. You can see the source code
for these methods by typing their names on the R command line. Sometimes
methods aren't exported and aren't so easily visible on the command line,
leading to frustration. Download the source package for complete
satisfaction.

 The help for ?corClasses in the nlme package has a bit more help, but you
might do well to read the source code of how these methods are created in
the ape package, especially if you are going to be creating a variation on
these phylo-classes.

 Good luck. I tried and failed to write a new corClass for nlme a few years
back.

corBlimey.

Barry

[[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] Rcmdr Bug?

2013-05-17 Thread Pascal Oettli
Hi,

Which command? But I would say that the first row is imported as column
names.

Regards,
Pascal



2013/5/17 Knut Krueger r...@knut-krueger.de

 may be it is a bug:
 if a excel file is not containing headlines the first data row will not be
 imported

 Knut

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html 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] Find the indices of non-NA elements of a sequence

2013-05-17 Thread Pascal Oettli
Hi,

For example:

 which(complete.cases(test))
[1] 1 3 4 6

Probably a more elegant way exists.

Regards,
Pascal


2013/5/17 jpm miao miao...@gmail.com

 Hi,

   I have a sequence whose 1st, 3rd, 4th, 6th are non-NAs. How could I let R
 return 1,3,4,6, the indices?

   I know only how to find the non-NA elements. Thanks,

 Miao

  test-c(2,NA,6,8,NA,12)
  test[is.na(test)==FALSE]
 [1]  2  6  8 12

 [[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] read excel files problem [was] Rcmdr Bug

2013-05-17 Thread Knut Krueger
Am 17.05.2013 09:09, schrieb Pascal Oettli:
 Hi,

 Which command? But I would say that the first row is imported as 
 column names.

maybe its a general problem of importing excel files.
First of all I am using only sheeets with headlines ;_) but Students do 
sometimes not. ;-)

So
gdata - read.xls is importing sheets default with header=TRUE (its 
possible to set it false)  if not the fist row is interpreted as 
X+VAlue) means f.e X12.5 thats nearly OK anybody can see that there is a 
value.
readWorksheet the same with header but the name of the Column is Col1 
newbies will not realize that there is a value missing

and R-C commander  has no header Option and the first value will changed 
to F1.

Maybe it would be good to give out a warning in all import functions if 
header is not set explicit to TRUE f.e
Warning: First datarow is used as headlines additionally:  output of 
names(dataset)

- follow up to r-de...@r-project.org


 Regards,
 Pascal



 2013/5/17 Knut Krueger r...@knut-krueger.de mailto:r...@knut-krueger.de

 may be it is a bug:
 if a excel file is not containing headlines the first data row
 will not be imported

 Knut

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




-- 
 Achtung ---
#
# Rückantwortadresse ist RH-Help Group
#
 Achtung ---


[[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] Selecting A List of Columns

2013-05-17 Thread Pascal Oettli
Hello,

It works for me if I replace

 ImportantVars - as.character(ImportantVars)

by

 ImportantVars - ImportantVars$Vars

Hope this helps,
Pascal




2013/5/17 Sparks, John James jspa...@uic.edu

 Dear R Helpers,

 I need help with a slightly unusual situation in which I am trying to
 select some columns from a data frame.  I know how to use the subset
 statement with column names as in:


 x=as.data.frame(matrix(c(1,2,3,
 1,2,3,
 1,2,2,
 1,2,2,
 1,1,1),ncol=3,byrow=T))

 all.cols-colnames(x)
 to.keep-all.cols[1:2]

 Kept-subset(x,select=to.keep)
 Kept

 However, if I want to select some columns based on a selection of the most
 important variables from a random forest then I find myself stuck.  The
 example below demonstrates the problem.


 library(randomForest)

 data(mtcars)
 mtcars.rf - randomForest(mpg ~ ., data=mtcars,importance=TRUE)
 Importance-data.frame(mtcars.rf$importance)
 Importance



 MSEImportance-head(Importance[order(Importance$X.IncMSE,
 decreasing=TRUE),],3)
 MSEVars-row.names(MSEImportance)
 MSEVars-data.frame(MSEVars,stringsAsFactors = FALSE)
 colnames(MSEVars)-Vars


 NodeImportance-head(Importance[order(Importance$IncNodePurity,decreasing=TRUE),],
 3)
 NodeVars-row.names(NodeImportance)
 NodeVars-data.frame(NodeVars,stringsAsFactors = FALSE)
 colnames(NodeVars)-Vars


 ImportantVars-rbind(MSEVars,NodeVars)
 ImportantVars-unique(ImportantVars)
 nrow(ImportantVars)
 ImportantVars-as.character(ImportantVars)
 ImportantVars
 CarsVarsKept-subset(mtcars,select=ImportantVars)
 Error in `[.data.frame`(x, r, vars, drop = drop) :
   undefined columns selected

 Any help on how to select these columns from the data frame would be most
 appreciated.

 --John J. Sparks, Ph.D.

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

2013-05-17 Thread Elaine Kuo
Hello

I am using package Hmisc to calculate the pearson correlation and the
significant level for the matrix of t_i and t_r. (temperature minimum and
temperature range)

However, I have difficulty interpreting the result, even after checking the
manual.
Please kindly help to indicate if the p-value is zero.
Thank you in advance.
Elaine

The code
 library(Hmisc)
 rcorr(as.matrix(datat), type=pearson) # type can be pearson or spearman


The result is
 t_i   t_r
t_i  1.00 -0.89
t_r -0.89  1.00

n= 4873


P
t_i t_r
t_i  0
t_r  0



[[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] Selecting A List of Columns

2013-05-17 Thread peter dalgaard

On May 17, 2013, at 12:02 , peter dalgaard wrote:

 
 On May 17, 2013, at 08:51 , Sparks, John James wrote:
 
 Dear R Helpers,
 
 I need help with a slightly unusual situation in which I am trying to
 select some columns from a data frame.  I know how to use the subset
 statement with column names as in:
 
 Notice that subset() is a convenience function for command line use. The 
 non-standard evaluation tricks in it tend to become inconveniences if you try 
 to use subset() in a function (I can say that, I wrote the blasted thing...). 
 Just use normal subseting functions instead and everything behaves much more 
 predictably. If ImportantVars is a vector of column names, use
 
 mtcars[ImportantVars] 
 
 (or mtcars[,ImportantVars], which also works for matrices).
 


Oups, Pascal has the right end of the stick. The above is correct, but the If 
is important: You need a character vector of names, and that's not what is in 
ImportantVars.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] Selecting A List of Columns

2013-05-17 Thread peter dalgaard

On May 17, 2013, at 08:51 , Sparks, John James wrote:

 Dear R Helpers,
 
 I need help with a slightly unusual situation in which I am trying to
 select some columns from a data frame.  I know how to use the subset
 statement with column names as in:

Notice that subset() is a convenience function for command line use. The 
non-standard evaluation tricks in it tend to become inconveniences if you try 
to use subset() in a function (I can say that, I wrote the blasted thing...). 
Just use normal subseting functions instead and everything behaves much more 
predictably. If ImportantVars is a vector of column names, use

mtcars[ImportantVars] 

(or mtcars[,ImportantVars], which also works for matrices).


 
 
 x=as.data.frame(matrix(c(1,2,3,
1,2,3,
1,2,2,
1,2,2,
1,1,1),ncol=3,byrow=T))
 
 all.cols-colnames(x)
 to.keep-all.cols[1:2]
 
 Kept-subset(x,select=to.keep)
 Kept
 
 However, if I want to select some columns based on a selection of the most
 important variables from a random forest then I find myself stuck.  The
 example below demonstrates the problem.
 
 
 library(randomForest)
 
 data(mtcars)
 mtcars.rf - randomForest(mpg ~ ., data=mtcars,importance=TRUE)
 Importance-data.frame(mtcars.rf$importance)
 Importance
 
 
 
 MSEImportance-head(Importance[order(Importance$X.IncMSE,
 decreasing=TRUE),],3)
 MSEVars-row.names(MSEImportance)
 MSEVars-data.frame(MSEVars,stringsAsFactors = FALSE)
 colnames(MSEVars)-Vars
 
 NodeImportance-head(Importance[order(Importance$IncNodePurity,decreasing=TRUE),],
 3)
 NodeVars-row.names(NodeImportance)
 NodeVars-data.frame(NodeVars,stringsAsFactors = FALSE)
 colnames(NodeVars)-Vars
 
 
 ImportantVars-rbind(MSEVars,NodeVars)
 ImportantVars-unique(ImportantVars)
 nrow(ImportantVars)
 ImportantVars-as.character(ImportantVars)
 ImportantVars
 CarsVarsKept-subset(mtcars,select=ImportantVars)
 Error in `[.data.frame`(x, r, vars, drop = drop) :
  undefined columns selected
 
 Any help on how to select these columns from the data frame would be most
 appreciated.
 
 --John J. Sparks, Ph.D.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


[R] Repeating sequence elements

2013-05-17 Thread Stefan Petersson
I want to create a sequence, repeating each element according to a vector.

I have this:

v - c(4, 4, 4, 3, 3, 2)

And want to create this:

1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5 6 6

TIA

  // s

R version 3.0.0 (2013-04-03)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

[[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] peering inside functions in a package?

2013-05-17 Thread Duncan Murdoch

On 13-05-16 9:56 PM, Seth Myers wrote:

Let's say I would like to look inside the function corBrownian in library
(ape).  When I type in the function name I get the following, which is not
nearly the detail that goes into this function.  I am wondering how to
begin cracking this function open (and others) so I can learn more about it
and perhaps code my own corClass one day.  Thanks.


corBrownian

function (value = 1, phy, form = ~1)
{
 if (!inherits(phy, phylo))
 stop(object \phy\ is not of class \phylo\)
 attr(value, formula) - form
 attr(value, fixed) - TRUE
 attr(value, tree) - phy
 class(value) - c(corBrownian, corPhyl, corStruct)
 value
}
environment: namespace:ape


That's it.  Why do you think something is missing?

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 could I see the source code of functions in an R package?

2013-05-17 Thread Duncan Murdoch

On 13-05-17 12:01 AM, David Winsemius wrote:

Do this search with your favorite search tool

Accessing the sources ligges

(Uwe Ligges is the author of a comprehensive article on the topic in R News.)



That article is also linked from the R help system.  After help.start(), 
look for technical papers.  It's one of those.


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] Repeating sequence elements

2013-05-17 Thread Rui Barradas

Hello,

At an R prompt, type

?rep

Then use

v - c(4, 4, 4, 3, 3, 2)
rep(1:6, v)


Hope this helps,

Rui Barradas

Em 17-05-2013 11:53, Stefan Petersson escreveu:

I want to create a sequence, repeating each element according to a vector.

I have this:

v - c(4, 4, 4, 3, 3, 2)

And want to create this:

1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5 6 6

TIA

   // s

R version 3.0.0 (2013-04-03)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

[[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] Repeating sequence elements

2013-05-17 Thread Jorge I Velez
Try

rep(1:length(v), v)

HTH,
Jorge.-



On Fri, May 17, 2013 at 8:53 PM, Stefan Petersson ste...@inizio.se wrote:

 I want to create a sequence, repeating each element according to a vector.

 I have this:

 v - c(4, 4, 4, 3, 3, 2)

 And want to create this:

 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5 6 6

 TIA

   // s

 R version 3.0.0 (2013-04-03)
 Platform: x86_64-pc-linux-gnu (64-bit)

 locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C LC_NAME=C
 [9] LC_ADDRESS=C LC_TELEPHONE=C
 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

 [[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] Rcmdr Bug?

2013-05-17 Thread John Fox
Dear Knut,

This is really more a limitation than a bug. Like most of the dialogs in the 
Rcmdr, the dialog to read Excel files uses existing facilities in R and R 
packages. I'll see whether it's possible to add an option to read a data set 
without variable names. The obvious workaround is to add a row of variable 
names to the spreadsheet.

Best,
 John


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

On Fri, 17 May 2013 07:40:51 +0200
 Knut Krueger r...@knut-krueger.de wrote:
 may be it is a bug:
 if a excel file is not containing headlines the first data row will not be 
 imported
 
 Knut
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Repeating sequence elements

2013-05-17 Thread arun
Hi,
rep(seq_along(v),v)
 #[1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5 6 6
A.K.



- Original Message -
From: Stefan Petersson ste...@inizio.se
To: r-help@r-project.org
Cc: 
Sent: Friday, May 17, 2013 6:53 AM
Subject: [R] Repeating sequence elements

I want to create a sequence, repeating each element according to a vector.

I have this:

v - c(4, 4, 4, 3, 3, 2)

And want to create this:

1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5 6 6

TIA

  // s

R version 3.0.0 (2013-04-03)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

    [[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] A function that can modify an object? Or at least shows principles how to modify an object?

2013-05-17 Thread Adams, Jean
To make it easier for R-help readers to help you, please  you provide the
before UUU[2] data using the dput() function.

dput(UUU[2])

Jean


On Thu, May 16, 2013 at 11:12 AM, Aldi a...@dsgmail.wustl.edu wrote:

 Hi, If I have an R object UUU, where the second element is U2, based on
 g column of my.table

 my.table of UUU is:
 mmm ggg   gindex   map   Info
 aaa123   U1   1   1 1
 aaa124   U1   1   2 1
 bbb1378U2   2   1 1
 bbbU2   2   2 0
 bbb1389U2   2   3 1
 ccc  Z3   3   1 1
 ccc3Z3   3   2 0
 ccc  Z3   3   3 1
 ccc5Z3   3   4 0

 Before (see Before) the analysis I had dropped those mmm rows from
 my.table of UUU that had Info==0, thus not included in the analysis.
 After (see After) analysis found that I need to add bbb (in the second
 position, as defined by map) for U2, ccc and ccc for Z3 and s.o.
 The bbb, does not have any info in general, but a collaborator is
 saying that he needs the bbb for documentation in the UUU object.
 A solution is to rerun the analysis, but the list is very long, the
 analysis will take 1 day. Is there any ready function that can modify an
 object? Or at least shows principles how to modify an object?
 I have labeled elements of U2 as (e) which needs an NA in the second
 position; (d) needs a name bbb as a second column and as a second row
 and correspondingly in its rows and columns use value 1.0; NO change for
 (c); adding 0.0 in the second position for (b); and NO change for (a). (see
 After) Thank you in advance, Aldi

 Before:
 ===
  UUU[2]
 $U2
 $U1$scores (e)
 [1]  -1.946707 -57.970488

 $U2$cov (d)
 bbb1378   bbb1379
 bbb1378  1.10362564 -0.01222695
 bbb1379 -0.01222695 26.88805020

 $U2$n (c)
 [1] 1802

 $U1$maf   (b)
 [1] 0.0002774695 0.0077691454

 $U2$sey (a)
 [1] 13.3867

 After:
 =
  UUU[2]
 $U2
 $U2$scores (e)
 [1]  -1.946707 NA -57.970488

 $U2$cov (d)
 bbb1378  bbb bbb1379
 bbb1378  1.10362564  1.0  -0.01222695
 bbb  1.0  1.0  1.0
 bbb1379 -0.01222695  1.0  26.88805020

 $U2$n (c)
 [1] 1802

 $U2$maf   (b)
 [1] 0.0002774695  0.0  0.0077691454

 $U2$sey (a)
 [1] 13.3867

 --

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html 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] n in pglm() and relogit()

2013-05-17 Thread f . leyendecker84

   Dear all,

   How do I obtain the number of countries that my panel models estimated by
   pglm()  and  relogit() (the latter one is in the Zelig library) use? I
   couldn't find any information on that in the help files.

   Thank you very much in advance.

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

2013-05-17 Thread l. calciano
Hello!

I'm
using the NLPCA to reduce the
dimensionality of nine variables
(4 nominal /
3 ordinal /2 numeric)
to obtain the object-scores to be used as dependent variable in a regression 
model.

I'm using the package homals (http://www.jstatsoft.org/v31/i04/paper).



The output is:

Call: homals (date = date, Ndim = 1, rank = 1, level = c (numerical, rep 
(ordinal, 3), numerical,
rep (nominal, 4), active = TRUE)

Loss: 0.0002050824

Eigenvalues​​: D1 0.0212



I'm having
the following questions:

1)
Is it best to consider Ndim = rank = 1 or Ndim = rank = max (rank)  to reduce 
the dimensionality of data?

2) Is there a command to automatically calculate
the proportion of variance explained
by the first component? Otherwise, how can I calculate it by hand?3) Is it 
necessary to standardize numeric variables before perfoming homals?



If anyone
has any thoughts for this, responses would be greatly appreciated.

Thanks.

Lucia

  
  
[[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] Using grubbs test for residuals to find outliers

2013-05-17 Thread Karthik Srinivasan
Hi,

I am a new user of R.
This is a conceptual doubt regarding screeing out outliers from the dataset
in regression.

I read up that Cook's distance can be used and if we want to remove
influential observations, we can use the metric (4/n) (n=no of
observations) to remove any outliers.

I also came across Grubb's test to identify outliers in univariate distns.
(assumed normal) but i was not able to find contexts in Regression where
Grubb's test is used (may be I didn't search enough)

Is it a good idea to find out Cook's distance and identify outliers.
Perform the Grubb's test for each of these outliers and then delete them?

Right now, I am only using Cook's distance in my problem but I am uncertain
as repeating the procedure with the new datasets (after removing influential
observations) subsequently still keeps showing outliers in the plots.
One reason maybe, i have only 50 data tuples and around 10 input variables
in the Multiple regression equation.

Am I going wrong in my fundamentals while using this approach.

Thanks and regards,

Karthik Srinivasan
M.Mgt - Business Analytics
Indian Institute of Science, Bangalore

[[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] Contour lines in a persp plot

2013-05-17 Thread Matthew
Thanks a lot, that is all i want. If someone is interessed, see the code
below

panel.3d.contour - 
function(x, y, z, rot.mat, distance, 
 nlevels = 20, zlim.scaled, ...) # les3 points de suspension
pour dire les autres paramètres sont ceux données par défaut
{
add.line - trellis.par.get(add.line)
panel.3dwire(x, y, z, rot.mat, distance, 
 zlim.scaled = zlim.scaled, ...)
clines - 
contourLines(x, y, matrix(z, nrow = length(x), byrow = TRUE),
 nlevels = nlevels)
for (ll in clines) {
m - ltransform3dto3d(rbind(ll$x, ll$y, zlim.scaled[2]), 
  rot.mat, distance)
panel.lines(m[1,], m[2,], col = add.line$col,
lty = add.line$lty, lwd = add.line$lwd)
}
}


fn-function(x,y){sin(x)+2*y} #this looks like a corrugated tin roof

x-seq(from=1,to=100,by=2) #generates a list of x values to sample
y-seq(from=1,to=100,by=2) #generates a list of y values to sample

z-outer(x,y,FUN=fn) #applies the funct. across the combos of x and y


wireframe(z,zlim = c(1, 300), nlevels = 10,
  aspect = c(1, 0.5), panel.aspect = 0.6,
  panel.3d.wireframe = panel.3d.contour,
   shade = FALSE ,
  screen = list(z = 20, x = -60))



--
View this message in context: 
http://r.789695.n4.nabble.com/Contour-lines-in-a-persp-plot-tp4667220p4667309.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] Log scales

2013-05-17 Thread Emily Gleeson

Dear All,

I have a query about using log scales for filled.contour plots. I have 
used log values on the x and y axes but labelled the axes with their 
linear (non-log) values. I's like to do the same with the contour 
values. I want the range to go from -100% to +100%. To use log I just 
added 1000 to the % values before taking the log. I'd like the original 
% values to appear on the contour lines and in the contour colourbar 
labelling.


I'd appreciate any suggestions you have.

Many thanks,
Emily Gleeson



*
This e-mail and any files transmitted with it are confid...{{dropped:9}}

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

2013-05-17 Thread Peter Craig

Dear colleagues (especially those with an understanding of the inner
workings of R),

For some years, I have been using R's fft (Fast Fourier Transform)
routines from within C code as part of an R package.

With R-3.0.1, fft_factor and fft_work are no longer available as entry
points declared in R_ext/Applic.h and this is documented in the
Changelog but I lack the skill/knowledge to track down the reason for
the change.

Does anyone know if (i) there is an alternative route to the fft
routines; (ii) there is a reason not to use them; (iii) one should use
some other routines instead?

Thanks for any help given,

Peter Craig

-- 
##
| E-mail:   p.s.cr...@durham.ac.uk Telephone: +44-191-3343076 (Work) |
| Fax:  +44-191-3343051   +44-191-3737415 (Home) |
||
| WWW:   |
||
|   http://www.dur.ac.uk/research/directory/staff/?mode=staffid=455 |
||
| Snail:Peter Craig, Dept. of Math. Sciences, Univ. of Durham,   |
|   South Road, Durham DH1 3LE, England  |
##

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] zigzag confidence interval in a plot

2013-05-17 Thread Ozgul Inceoglu
Dear All,

When I plot the values and linear regression line for one data set, it is fine. 
But for another one I see zigzags, when I plot the confidence interval

cd
Depth   CHAOsep12RNA
9,94804
25,06   1476,83
40,04   1540,561404
50,11   1575,17
52,46   349,22
54,92   1941,5
57,29   1053,507042
60,11   1535,1
70,04   2244,963303
79,97   1954,507042
100,31  2679,140625


 plot(cd$CHAOsep12RNA,cd$Depth, ylim = rev(range(0:100)), xlab=CHAO, 
 ylab=Depth, pch=15, las=2, main=Sep12-RNA, cex.main=1)
 lmR - lm(cd$Depth~cd$CHAOsep12RNA)
 abline(lmR)
pconfR - predict(lmR,interval=confidence)
matlines(cd$CHAOsep12RNA,pconfR[,c(lwr,upr)], col=1, lty=2)

I also tried

 newx - seq(min(cd$CHAOsep12RNA), max(cd$CHAOsep12RNA), length.out=11)
 a - predict(lmR, newdata=data.frame(CHAO=newx), interval=c(confidence))
 plot(cd$CHAOsep12RNA,cd$Depth, ylim = rev(range(0:100)), xlab=CHAO, 
 ylab=Depth, pch=15, las=2, main=Sep12-RNA, cex.main=1)
 abline(lmR)
 lines(cd$CHAOsep12RNA, a[,2], lty=2)

But I see both cases kind of zigzags. What can it be the reason? thank you!

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


Re: [R] R looping help

2013-05-17 Thread Adams, Jean
It's difficult to see where your error is when you provide no accompanying
data for us to test your code out on (X?  Y?  Stand?).

However, it looks like you are making your code more complex than it needs
to be.  Are you simply trying to a fit a separate linear regression to each
subset of your data identified by a unique standID?  If so, you can do so
like this:

# a fake version of your data
mydata - data.frame(standID=rep(1:5, rep(20, 5)), X=rnorm(100),
Y=rnorm(100))

# split the data up by stand ID
standlist - split(mydata, mydata$standID)

# fit a regression to each stand and save some results
standEst1 - lapply(standlist, function(df) {
fit - summary(lm(Y ~ X, data=df))
 co - coef(fit)
intercept - co[1, 1]
slope - co[2, 1]
 pValue - co[2, 4]
mse - fit$sigma^2
rSquare - fit$r.squared
 c(standID=df$standID[1], intercept=intercept, slope=slope, mse=mse,
rSquare=rSquare, pValue=pValue)
})

# convert the results to a data frame
standEstimates - data.frame(do.call(rbind, standEst1))

Jean



On Thu, May 16, 2013 at 5:17 AM, rishard or...@uclive.ac.nz wrote:

 Hey I'm not really sure what I should put on here, but I am having trouble
 with my R code.  I am trying to get the p-values, R^2s etc for a number of
 different groups of variables that are all in one dataset.

 This is the code:

 #Stand counter
 st-1
 #Collections
 stands-numeric(67)
 slopes-numeric(67)
 intercepts-numeric(67)
 mses-numeric(67)
 rsquares-numeric(67)
 pValues-numeric(67)
 #Start lists for X and Y values within each stand
 xi-numeric(0)
 yi-numeric(0)
 #Set the first element to the starting X and Y values
 xi[1]=X[1]
 yi[1]=Y[1]
 #Start looping working through your data, record by record
 for (i in 2:length(X)) {
   #If you are in the same stand as on the last record, continue to
   #collect X and Y values
   if(Stand[i]==Stand[i-1]) {
 xi=cbind(xi,X[i])
 yi=cbind(yi,Y[i])
   } else {
 #If a new stand is encountered make your linear model and
 #collect statistics
 model-lm(yi~xi)
 stands[st]-Stand[i-1]
 intercepts[st]-model$coefficients[1]
 slopes[st]-model$coefficients[2]
 mses[st]-sum(resid(model)^2)/(length(xi)-2)
 ssr-var(yi)*(length(xi)-1)-sum(resid(model)^2)
 rsquares[st]-ssr/(var(yi)*(length(xi)-1))
 fRatio-ssr/mses[st]
 pValues[st]-1-pf(fRatio,1,length(xi)-2)
 #Increment the stand number, zero the within stand collections,
 #and start again
 st-st+1
 xi-numeric(0)
 yi-numeric(0)
 xi[1]=X[i]
 yi[1]=Y[i]
   }
 }
 #Make your data set

 standEstimates-data.frame(standID=stands,intercept=intercepts,slop=slopes,mse=mses,rSquare=rsquares,pValue=pValues)

 The standEstimate outputs look like this:

 standID intercept   slopmse rSquare pValue
 1   6833319.2470NA  0   NA  NA
 2   756 708.7470NA  0   NA  NA
 3   795 508.2290NA  0   NA  NA
 4   1249503.1460NA  0   NA  NA
 5   1331703.0620NA  0   NA  NA
 6   1417747.7620NA  0   NA  NA
 7   4715549.3400NA  0   NA  NA
 8   4850603.9940NA  0   NA  NA
 9   2105573.3270NA  0   NA  NA
 Etc etc

 and I get these warnings:

 1: In rsquares[st] - ssr/(var(yi) * (length(xi) - 1)) :
   number of items to replace is not a multiple of replacement length
 2: In pValues[st] - 1 - pf(fRatio, 1, length(xi) - 2) :
   number of items to replace is not a multiple of replacement length
 3: In rsquares[st] - ssr/(var(yi) * (length(xi) - 1)) :
   number of items to replace is not a multiple of replacement length
 4: In pValues[st] - 1 - pf(fRatio, 1, length(xi) - 2) :
   number of items to replace is not a multiple of replacement length
 5: In rsquares[st] - ssr/(var(yi) * (length(xi) - 1)) :
   number of items to replace is not a multiple of replacement length
 6: In pValues[st] - 1 - pf(fRatio, 1, length(xi) - 2) :
   number of items to replace is not a multiple of replacement length
 7: In rsquares[st] - ssr/(var(yi) * (length(xi) - 1)) :
   number of items to replace is not a multiple of replacement length
 8: In pValues[st] - 1 - pf(fRatio, 1, length(xi) - 2) :
   number of items to replace is not a multiple of replacement length
 9: In rsquares[st] - ssr/(var(yi) * (length(xi) - 1)) :
   number of items to replace is not a multiple of replacement length
 10: In pValues[st] - 1 - pf(fRatio, 1, length(xi) - 2) :
   number of items to replace is not a multiple of replacement length
 11: In rsquares[st] - ssr/(var(yi) * (length(xi) - 1)) :
   number of items to replace is not a multiple of replacement length
 12: In pValues[st] - 1 - pf(fRatio, 1, length(xi) - 2) :
   number of items to replace is not a multiple of replacement length
 13: In rsquares[st] - ssr/(var(yi) * (length(xi) - 1)) :
   number of items to replace is not a multiple of replacement length
 

Re: [R] Rcmdr Bug?

2013-05-17 Thread Knut Krueger

Am 17.05.2013 13:36, schrieb John Fox:

Dear Knut,

This is really more a limitation than a bug. Like most of the dialogs in the 
Rcmdr, the dialog to read Excel files uses existing facilities in R and R 
packages. I'll see whether it's possible to add an option to read a data set 
without variable names. The obvious workaround is to add a row of variable 
names to the spreadsheet.

dear John,
indeed I would never use an excel sheet without variable names ... but 
students do and then the statistics are wrong 
As I mentioned in the other answer it would be fine to add a hint that 
the first row is used as variable name ... for the students ;-)


Knut

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

2013-05-17 Thread Mario Garrido
Hello,
I want to stop receiveng mails from R help forum,
thanks.

This is my data :
Mario Garrido Escudero
Dpto. de Biología Animal, Ecología, Parasitología, Edafología y Qca.
Agrícola
Fac. de Farmacia
Campus Unamuno
Universidad de Salamanca

gaiarr...@usal.es

[[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] out of the mailing list

2013-05-17 Thread Pascal Oettli
Hello,

It is not the correct procedure. Go to the bottom of the following webpage
to unsubscribe.
https://stat.ethz.ch/mailman/listinfo/r-help

Regards,
Pascal



2013/5/17 Mario Garrido gaiarr...@usal.es

 Hello,
 I want to stop receiveng mails from R help forum,
 thanks.

 This is my data :
 Mario Garrido Escudero
 Dpto. de Biología Animal, Ecología, Parasitología, Edafología y Qca.
 Agrícola
 Fac. de Farmacia
 Campus Unamuno
 Universidad de Salamanca

 gaiarr...@usal.es

 [[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] update an array of plots in 'real-time' without drawing lags

2013-05-17 Thread Martin Batholdy
Hi,

I know R is not made for this, but I still wanted to ask if there are 
possibilities to do this;


I repeatedly collect data from a database for a given time interval.
Now I would like to monitor the change of this data with some nice plots.

I actually have to draw 15 plots to get the whole picture.
Now I can write a loop that, for a given time interval, updates the data and 
plots them using one quartz window that is split into subparts with the layout 
function.

However, since I redraw every plot every time, the drawing takes some time and 
it is not an instant update that I see.
The plots are slowly redrawn from the upper left corner of the quartz window to 
the bottom right.


That makes me wonder;
Is there a way to buffer the graphical device before updating it?
Or are there any other solutions for R that enables to smoothly plot / 
visualize data in 'real-time'?


I am grateful for any suggestions!

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

2013-05-17 Thread kende jan
Hello everyone,

I am trying to undertake an item bifactor analysis of graded response data from 
a questionnaire. I am using the mirt package, especially the bfactor 
function.My dataset is called data.items, it contains about 2000 observations 
and 31 variables (variables represent the items in the questionnaire). The 
items follow a Likert scale format and represent a level of satisfaction, 
missing values are coded as NA). I am having trouble at the beginning of my 
analysis, during the exploratory model fitting. The syntax and the error 
message are as follows:

 bfactor(data.items,model=9)
Error in ESTIMATION(data = data, model = model, group = rep(all, nrow(data)), 
 : 
  index out of bounds

I get the same error when i try with: bfactor(data.items,9,itemtype=graded) 
or  bfactor(data.items,9,prev.cor=cor)
where cor is the correlationmatrix that i compute without the missing values.

If someone have an idea to suggest, do not hesitate.

Thank you.

[[alternative HTML version deleted]]

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


Re: [R] how to calculate the mean in a period of time?

2013-05-17 Thread arun


Hi,
Try this:
 dat1$idx-with(dat1,ifelse(is.na(delais)|delais45  
delais20, 1,ifelse(delais60  
delais=45,2,ifelse(delais=90  delais=60,3,NA
dat1$idx1-c(dat1$idx[-head(dat1$idx,1)],1)

library(zoo)
res1-do.call(rbind,lapply(split(dat1,dat1$patient_id),function(x) 
{x$idx[as.logical(cumsum(is.na(x$idx)))]-NA; x1-x[!is.na(x$idx),]; 
x1[,6:8]-na.locf(x1[,6:8]);x1$idx1[is.na(x1$idx1)]-1; 
x2-x1[rep(seq_len(nrow(x1)),x1$idx1),]; 
x2$delais[duplicated(x2$delais,fromLast=FALSE)]-0; 
x2$t-seq(0,nrow(x2)-1,1);x2[,-c(8:9)]}))
 row.names(res1)- 1:nrow(res1)
 res2- res1[,c(1:3,8,4:7)]
 res2
#   patient_id number responsed_at t delais scores1 scores2 scores3
#1   1  1   2010-05-26 0 NA 2.6 0.5 0.7
#2   1  2   2010-07-07 1 42 2.5 0.5 0.7
#3   1  3   2010-08-14 2 38 2.3 0.5 0.7
#4   1  3   2010-08-14 3  0 2.3 0.5 0.7
#5   1  4   2010-10-01 4 48 2.5 0.7 0.6
#6   1  4   2010-10-01 5  0 2.5 0.7 0.6
#7   1  4   2010-10-01 6  0 2.5 0.7 0.6
#8   1  5   2010-12-01 7 61 2.5 0.7 0.6
#9   2  1   2011-07-19 0 NA 2.5 0.8 0.5
#10  2  1   2011-07-19 1  0 2.5 0.8 0.5
#11  2  1   2011-07-19 2  0 2.5 0.8 0.5
#12  2  2   2011-09-22 3 65 2.6 0.8 0.5
#13  2  3   2011-10-26 4 34 2.7 0.8 0.5
#14  3  1   2011-07-17 0 NA 2.8 0.5 0.6
A.K.


From: GUANGUAN LUO guanguan...@gmail.com
To: arun smartpink...@yahoo.com 
Sent: Friday, May 17, 2013 9:33 AM
Subject: Re: how to calculate the mean in a period of time?



Hello, 
Thank you for your help
the lines added to the tables are the precedent lines but not the followed 
lines, if i just change x2-x1[rep(seq_len(nrow(x1)-1), is that ok? and so the 
delais should be changed too, isn't it?


GG


2013/5/17 arun smartpink...@yahoo.com

Hi,
No problem.

Arun







From: GUANGUAN LUO guanguan...@gmail.com
To: arun smartpink...@yahoo.com
Sent: Friday, May 17, 2013 4:19 AM

Subject: Re: how to calculate the mean in a period of time?



Ah, yes, that is the wrong thing i have written. Thank you so much. the output 
which you have got is right.
Thanks a lot.
GG


2013/5/16 arun smartpink...@yahoo.com

Hi,
The output you showed is not clear especially the for the scores3,

  2                         2           2011-09-22    3     65            2.6 
      0.8            0.8
2                        3             2011-10-26   4      34            2.7  
   0.8            0.8
3                        1             2011-07-17    0     NA           2.8   
   0.5             0.6
In the input data, the scores3 column didn't had 0.8.


This is what I got:
dat1- read.table(text=

patient_id  number  responsed_at  delais  scores1   scores2   
scores3
 1  1    2010-05-26 NA   2.6  
 0.5    0.7  
 1  2 2010-07-07 42    2.5
   NA   NA   
 1   3    2010-08-14 38    2.3
   NA   NA  
 1   4    2010-10-01  48    2.5   
    0.7   0.6
 1   5    2010-12-01  61    2.5   
    NA   NA
2    1    2011-07-19  NA   2.5
   0.8    0.5
2 2   2011-09-22  65    2.6   
    NA    NA
2    3 2011-10-26  34    2.7  
    NA    NA
3    1 2011-07-17 NA   2.8
  0.5 0.6
3    2    2011-10-30  103   2.6   
   NA NA
3 3  2011-12-23    54    2.5  
    NA NA
,sep=,header=TRUE,stringsAsFactors=FALSE)

 dat1$idx-with(dat1,ifelse(is.na(delais)|delais45  delais20, 
1,ifelse(delais60  delais=45,2,ifelse(delais=90  delais=60,3,NA
library(zoo)
res-do.call(rbind,lapply(split(dat1,dat1$patient_id),function(x) 
{x$idx[as.logical(cumsum(is.na(x$idx)))]-NA; x1-x[!is.na(x$idx),]; 
x1[,6:8]-na.locf(x1[,6:8]);x2-x1[rep(seq_len(nrow(x1)),x1$idx),]; 
x2$delais[duplicated(x2$delais,fromLast=TRUE)]-0; 
x2$t-seq(0,nrow(x2)-1,1);x2}))


row.names(res)- 1:nrow(res)
 res1- res[,c(1:3,9,4:7)]
res1
#   patient_id number responsed_at t delais scores1 scores2 scores3
#1   1  1   2010-05-26 0 NA 2.6 0.5 0.7
#2   1  2   2010-07-07 1 42 2.5 0.5 0.7
#3   1  3   2010-08-14 2 38 2.3 0.5 0.7
#4   1  4   

[R] Error with adehabitatHR and kernelbb

2013-05-17 Thread Rémi Lesmerises
Dear all,

I'm trying to get a Brownian bridge kernel (kernelbb) for each combination of 
two consecutive animal locations (see commands below) and put them, with a 
loop, inside a list. It works well at the beginning but after 42 runs, it 
appears the following warning :


Error in seq.default(yli[1], yli[2], by = diff(xg[1:2])) : 
  invalid (to - from)/by in seq(.)

I looked at the coordinates, at the id, at the time of the run 43 and it's all 
good...

I looked on the net and it happened to only one person and there was no answer 
to his post. 

Someone could help me?

## commands

BBtraj - list()
for (i in 1:(nrow(loc@data)-1)) {
BBtraj[[i]] - kernelbb(as.ltraj(loc@coords[i:(i+1),], 
date=loc@data$time[i:(i+1)], id = as.character(loc@data$id[i:(i+1)]),
typeII = TRUE), sig1=as.numeric(as.character(loc@data$sig1[i])), sig2= 5, grid 
= 1000)
}

 
Rémi Lesmerises, biol. M.Sc.,
Candidat Ph.D. en Biologie
Université du Québec à Rimouski
remilesmeri...@yahoo.ca

[[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] R and libre office base

2013-05-17 Thread Johan Lassen
Dear community . I would like to connect r to libre office base. Does
anyone know if and how this can be done? I think of the pendant to rodbc
for libre office. I am using windows 7.
Thanks in advance and best regards johan

[[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] R and libre office base

2013-05-17 Thread Marc Schwartz
On May 17, 2013, at 9:47 AM, Johan Lassen johanlas...@gmail.com wrote:

 Dear community . I would like to connect r to libre office base. Does
 anyone know if and how this can be done? I think of the pendant to rodbc
 for libre office. I am using windows 7.
 Thanks in advance and best regards johan



As an FYI, there is an R list just for database access related issues:

  https://stat.ethz.ch/mailman/listinfo/r-sig-db

Both OpenOffice and LibreOffice use HSQLDB, which is a java based database. 
There are no ODBC connections supported by HSQLDB. However, I believe that some 
have had success with JDBC and there is the ODB package on CRAN 
(http://cran.r-project.org/web/packages/ODB/).

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] points overlay axis

2013-05-17 Thread Jonathan Phillips
Apologies to John - I should have thought to give an example.  However, xpd
is what I was looking for.  Thanks for the help!


On 14 May 2013 14:55, David Carlson dcarl...@tamu.edu wrote:

 Let's try again after restraining Outlook's desire to use html.

 set.seed(42)
 dat - matrix(c(runif(48), 0, 0), 25, 2, byrow=TRUE)

 # Complete plot symbol on axes, but axis on top
 plot(dat, xaxs=i, yaxs=i, pch=16, col=red, xpd=TRUE)

 # Complete plot symbol on axes with symbol on top
 plot(dat, xaxs=i, yaxs=i, type=n)
 points(dat, xaxs=i, yaxs=i, pch=16, col=red, xpd=TRUE)

 
 David L Carlson
 Associate Professor of Anthropology
 Texas AM University
 College Station, TX 77840-4352

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On
 Behalf Of John Kane
 Sent: Tuesday, May 14, 2013 7:47 AM
 To: Jonathan Phillips; r-help@r-project.org
 Subject: Re: [R] points overlay axis

 Probably but since we don't know what you are doing, it is very hard to
 give
 any advice.

 Please read this for a start
 https://github.com/hadley/devtools/wiki/Reproducibility and give us a
 clear
 statement of the problem

 Thanks

 John Kane
 Kingston ON Canada


  -Original Message-
  From: 994p...@gmail.com
  Sent: Tue, 14 May 2013 13:34:35 +0100
  To: r-help@r-project.org
  Subject: [R] points overlay axis
 
  Hi,
  I'm trying to do quite a simple task, but I'm stuck.
 
  I've set xaxs = 'i' as I want the origin to be (0,0), but
  unfortunately I have points that are sat on the axis.  R draws the
  axis over the points, which hides the points somewhat and looks
 unsightly.
  Is there any way of getting a point to be drawn over the axis?
 
  Thanks,
  Jon Phillips
 
[[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.

 
 FREE ONLINE PHOTOSHARING - Share your photos online with your friends and
 family!
 Visit http://www.inbox.com/photosharing to find out more!

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



[[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] max length of a factor variable

2013-05-17 Thread bennose
Technically this is correct for raw R functionality.

in practice various modules impose their own limits on variables so you have
to check.
For example the coxreg package truncates all variables to 16 characters.

for example the test below
 res
Call:
coxreg(formula = Surv(vtime, vstatus) ~
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1_fx1 + 
alt_const_fx1 + alt_const_fx2 + strata(vstrata), data = aggregate)

Covariate   Mean   Coef Rel.Risk   S.E.Wald p
abcdefghijklmnop   -0.000NANA 0.000NA 
alt_const_fx1  -0.045 0.132 1.141 0.044 0.002 
alt_const_fx2  -0.024 0.011 1.011 0.045 0.801 




--
View this message in context: 
http://r.789695.n4.nabble.com/max-length-of-a-factor-variable-tp2715509p4667332.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] zigzag confidence interval in a plot

2013-05-17 Thread Peter Ehlers

On 2013-05-17 06:03, Ozgul Inceoglu wrote:

Dear All,

When I plot the values and linear regression line for one data set, it is fine. 
But for another one I see zigzags, when I plot the confidence interval


cd

Depth   CHAOsep12RNA
9,94804
25,06   1476,83
40,04   1540,561404
50,11   1575,17
52,46   349,22
54,92   1941,5
57,29   1053,507042
60,11   1535,1
70,04   2244,963303
79,97   1954,507042
100,31  2679,140625



plot(cd$CHAOsep12RNA,cd$Depth, ylim = rev(range(0:100)), xlab=CHAO, ylab=Depth, 
pch=15, las=2, main=Sep12-RNA, cex.main=1)
lmR - lm(cd$Depth~cd$CHAOsep12RNA)
abline(lmR)

pconfR - predict(lmR,interval=confidence)
matlines(cd$CHAOsep12RNA,pconfR[,c(lwr,upr)], col=1, lty=2)

I also tried


newx - seq(min(cd$CHAOsep12RNA), max(cd$CHAOsep12RNA), length.out=11)
a - predict(lmR, newdata=data.frame(CHAO=newx), interval=c(confidence))
plot(cd$CHAOsep12RNA,cd$Depth, ylim = rev(range(0:100)), xlab=CHAO, ylab=Depth, 
pch=15, las=2, main=Sep12-RNA, cex.main=1)
abline(lmR)
lines(cd$CHAOsep12RNA, a[,2], lty=2)


But I see both cases kind of zigzags. What can it be the reason? thank you!



Sort your dataframe by x-values (CHAOsep12RNA).

Peter Ehlers

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] zigzag confidence interval in a plot

2013-05-17 Thread Rui Barradas

Hello,

Try the following.


lmR - lm(cd$Depth ~ cd$CHAOsep12RNA)
pconfR - predict(lmR,interval=confidence)
pcR - pconfR[order(pconfR[, 1]), ]  # Add this line

plot(cd$CHAOsep12RNA,cd$Depth, ylim = rev(range(0:100)), xlab=CHAO, 
ylab=Depth, pch=15, las=2, main=Sep12-RNA, cex.main=1)

abline(lmR)
matlines(sort(cd$CHAOsep12RNA), pcR[,c(lwr, upr)], col=1, lty=2) # 
changed



Hope this helps,

Rui Barradas

Em 17-05-2013 14:03, Ozgul Inceoglu escreveu:

Dear All,

When I plot the values and linear regression line for one data set, it is fine. 
But for another one I see zigzags, when I plot the confidence interval


cd

Depth   CHAOsep12RNA
9,94804
25,06   1476,83
40,04   1540,561404
50,11   1575,17
52,46   349,22
54,92   1941,5
57,29   1053,507042
60,11   1535,1
70,04   2244,963303
79,97   1954,507042
100,31  2679,140625



plot(cd$CHAOsep12RNA,cd$Depth, ylim = rev(range(0:100)), xlab=CHAO, ylab=Depth, 
pch=15, las=2, main=Sep12-RNA, cex.main=1)
lmR - lm(cd$Depth~cd$CHAOsep12RNA)
abline(lmR)

pconfR - predict(lmR,interval=confidence)
matlines(cd$CHAOsep12RNA,pconfR[,c(lwr,upr)], col=1, lty=2)

I also tried


newx - seq(min(cd$CHAOsep12RNA), max(cd$CHAOsep12RNA), length.out=11)
a - predict(lmR, newdata=data.frame(CHAO=newx), interval=c(confidence))
plot(cd$CHAOsep12RNA,cd$Depth, ylim = rev(range(0:100)), xlab=CHAO, ylab=Depth, 
pch=15, las=2, main=Sep12-RNA, cex.main=1)
abline(lmR)
lines(cd$CHAOsep12RNA, a[,2], lty=2)


But I see both cases kind of zigzags. What can it be the reason? thank you!



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problem with ordiellipse coloured factor in Vegan

2013-05-17 Thread John Kane
No data.  The list tends to strip out many kinds of attachements including csv 
files. I'd suggest trying .txt or parking the data at someplace like 
[url=http://www.mediafire.com/][b]MediaFire[/b][/url] or
Dropbox [url=https://www.dropbox.com/][b]Dropbox[/b][/url]

John Kane
Kingston ON Canada


 -Original Message-
 From: suparna.mitra...@gmail.com
 Sent: Fri, 17 May 2013 11:56:52 +0800
 To: r-help@r-project.org
 Subject: [R] Problem with ordiellipse coloured factor in Vegan
 
 Hello R experts,
   I am trying to plot ordiellipse for my data but the col according to
 factors.
 
 Metabolites_raw= read.csv(file.choose(), head = TRUE) #file
 21Metabolites.csv
 
 Metabolites_t=t(Metabolites_raw[,2:82])
 
 ord - metaMDS(Metabolites_t, distance=bray)
 
 symbol=as.numeric(Metab_metadata$LandType)
 
 col.list - c(red,slategray,seagreen,cyan,pink,brown,black,
 blue,yellow,magenta)
 
  palette(col.list)
 
  plot(ord$points, col = Metab_metadata$Day+2,pch=symbol,
 xlim=c(-0.3,0.35))
 
 legend(.28,.25, c(0, 8, 16),fill = c(2, 10,18))
 
 # draw dispersion ellipses around data points
 
 groupz -c(2,10,18)
 
 for(i in seq(groupz)) {
 
 ordiellipse(ord, Metab_metadata$Day, kind = sd, label =
 T,col=groupz[i],
 show.groups=groupz[i])
 
 }
 
 Now here I get the error
 
 Error in text.default(...) : no coordinates were supplied (But sometimes
 same code works. I am not sure what am I doing wrong.)
 
 Data files are attached.
 
 Any help will be really great.
 
 Thanks,
 
 Mitra
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks  orcas 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.


Re: [R] pearson correlation significant level

2013-05-17 Thread Jose Iparraguirre
Dear Elaine,

One of the elements you obtain the P matrix, which is the matrix of  asymptotic 
p-values. In your case, you get that the asymptotic p-value of the association 
between t_i and t_r is 0. That is, there would exist a perfect association 
(look also at the first result, the matrix of correlations: the correlation 
coefficient between these variables is 1).
Hope this helps,
José


Prof. José Iparraguirre
Chief Economist
Age UK

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Elaine Kuo
Sent: 17 May 2013 10:40
To: r-help@r-project.org
Subject: [R] pearson correlation significant level

Hello

I am using package Hmisc to calculate the pearson correlation and the 
significant level for the matrix of t_i and t_r. (temperature minimum and 
temperature range)

However, I have difficulty interpreting the result, even after checking the 
manual.
Please kindly help to indicate if the p-value is zero.
Thank you in advance.
Elaine

The code
 library(Hmisc)
 rcorr(as.matrix(datat), type=pearson) # type can be pearson or 
 spearman


The result is
 t_i   t_r
t_i  1.00 -0.89
t_r -0.89  1.00

n= 4873


P
t_i t_r
t_i  0
t_r  0



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

Please donate to the Syria Crisis Appeal by text or online:

To donate £5 by mobile, text SYRIA to 70800.  To donate online, please visit 

http://www.ageinternational.org.uk/syria

Over one million refugees are desperately in need of water, food, healthcare, 
warm clothing, 
blankets and shelter; Age International urgently needs your support to help 
affected older refugees.


Age International is a subsidiary charity of Age UK and a member of the 
Disasters Emergency Committee (DEC).  
The DEC launches and co-ordinates national fundraising appeals for public 
donations on behalf of its member agencies.

Texts cost £5 plus one standard rate message.  Age International will receive a 
minimum of £4.96.  
More info at ageinternational.org.uk/SyriaTerms



 

---
Age UK is a registered charity and company limited by guarantee, (registered 
charity number 1128267, registered company number 6825798). 
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed 
Representative of Age UK Enterprises Limited, Age UK is an Introducer 
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth 
Access for the purposes of introducing potential annuity and health 
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit 
Solutions Limited and Simplyhealth Access are all authorised and 
regulated by the Financial Services Authority. 
--

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are 
addressed. If you receive a message in error, please advise the sender and 
delete immediately.

Except where this email is sent in the usual course of our business, any 
opinions expressed in this email are those of the author and do not 
necessarily reflect the opinions of Age UK or its subsidiaries and associated 
companies. Age UK monitors all e-mail transmissions passing 
through its network and may block or modify mails which are deemed to be 
unsuitable.

Age Concern England (charity number 261794) and Help the Aged (charity number 
272786) and their trading and other associated companies merged 
on 1st April 2009.  Together they have formed the Age UK Group, dedicated to 
improving the lives of people in later life.  The three national 
Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help 
the Aged in these nations to form three registered charities: 
Age Scotland, Age NI, Age Cymru.




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

2013-05-17 Thread Manta
Hi all,

I have a vector of numbers, and to be able to pass it to RMySQL and use the
IN clause I need to have this vector to be a single list numeric and comma
separated.

I saw the post below but it is about strings, which I do not need (I cannot
pass strings in this SQL query, I need something like ' where ASSETT in
(1,2,3,4,5)'

http://stackoverflow.com/questions/6347356/creating-a-comma-separated-vector


Any clue?



--
View this message in context: 
http://r.789695.n4.nabble.com/Comma-separated-vector-tp4667340.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] Comma separated vector

2013-05-17 Thread jim holtman
is this what you want

 x - c(1, 2, 3, 4, 5)
 paste0(where ASSETT in (, paste(x, collapse = ','), ))
[1] where ASSETT in (1,2,3,4,5)




On Fri, May 17, 2013 at 11:46 AM, Manta mantin...@libero.it wrote:

 Hi all,

 I have a vector of numbers, and to be able to pass it to RMySQL and use the
 IN clause I need to have this vector to be a single list numeric and comma
 separated.

 I saw the post below but it is about strings, which I do not need (I cannot
 pass strings in this SQL query, I need something like ' where ASSETT in
 (1,2,3,4,5)'


 http://stackoverflow.com/questions/6347356/creating-a-comma-separated-vector


 Any clue?



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Comma-separated-vector-tp4667340.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.




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

[[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] Comma separated vector

2013-05-17 Thread Jeff Newmiller
You are wrong... since the SQL query you wish to create is itself a string.

Of course, you cannot send a SQL fragment such as you used as an example, so be 
sure to form a complete, syntactically correct SQL statement before giving it 
to your database query function.

Oh, and if you need more assistance with this topic, then you should probably 
post in the R-sig-DB mailing list. Please also keep in mind that the actual SQL 
syntax used for your specific database is basically off-topic in any R forum, 
so you may need other help resources as well.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Manta mantin...@libero.it wrote:

Hi all,

I have a vector of numbers, and to be able to pass it to RMySQL and use
the
IN clause I need to have this vector to be a single list numeric and
comma
separated.

I saw the post below but it is about strings, which I do not need (I
cannot
pass strings in this SQL query, I need something like ' where ASSETT in
(1,2,3,4,5)'

http://stackoverflow.com/questions/6347356/creating-a-comma-separated-vector


Any clue?



--
View this message in context:
http://r.789695.n4.nabble.com/Comma-separated-vector-tp4667340.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] Problems using lmer {lme4}

2013-05-17 Thread Andrea Goijman
Dear R list,

I'm attaching a sample of my data which consists on the presence/absence
(punto6, binomial n=5 occasions)
of different species (sp), on different sites (site) within routes
('route).

First, I want to be able to find if there is autocorrelation of the
response variable between
the sites within each route. For this I start testing 2 models, but when I
try to run the second model,
to test for the random effects of sites within routes R stops working!

I'm not being able to find out why r is crashing... and whay am I doing
wrong.

Thanks!

Andrea

###
#dput(d)

d-structure(list(site = structure(c(55L, 56L, 57L, 58L, 59L, 60L,
55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L,
56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L,
57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 229L, 230L,
231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L,
230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L,
229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L,
234L, 229L, 230L, 231L, 232L, 233L, 234L, 331L, 332L, 333L, 334L,
335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L,
334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L,
333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L,
332L, 333L, 334L, 335L, 336L, 389L, 390L, 391L, 392L, 393L, 394L,
389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L,
394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L,
393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L,
392L, 393L, 394L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L,
207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L,
206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L,
205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L,
210L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L,
167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L,
166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L,
165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 247L,
248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L,
247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L,
252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L,
251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L), .Label = c(102-1,
102-2, 102-3, 102-4, 102-5, 102-6, 1023-1, 1023-2,
1023-3, 1023-4, 1023-5, 1023-6, 1027-1, 1027-2, 1027-3,
1027-4, 1027-5, 1027-6, 1028-1, 1028-2, 1028-3, 1028-4,
1028-5, 1028-6, 1032-1, 1032-2, 1032-3, 1032-4, 1032-5,
1032-6, 1034-1, 1034-2, 1034-3, 1034-4, 1034-5, 1034-6,
1036-1, 1036-2, 1036-3, 1036-4, 1036-5, 1036-6, 1041-1,
1041-2, 1041-3, 1041-4, 1041-5, 1041-6, 1046-1, 1046-2,
1046-3, 1046-4, 1046-5, 1046-6, 105-1, 105-2, 105-3,
105-4, 105-5, 105-6, 107-1, 107-2, 107-3, 107-4,
107-5, 107-6, 108-1, 108-2, 108-3, 108-4, 108-5,
108-6, 1101-1, 1101-2, 1101-3, 1101-4, 1101-5, 1101-6,
1104-1, 1104-2, 1104-3, 1104-4, 1104-5, 1104-6, 1108-1,
1108-2, 1108-3, 1108-4, 1108-5, 1108-6, 111-1, 111-2,
111-3, 111-4, 111-5, 111-6, 1113-1, 1113-2, 1113-3,
1113-4, 1113-5, 1113-6, 1116-1, 1116-2, 1116-3, 1116-4,
1116-5, 1116-6, 1121-1, 1121-2, 1121-3, 1121-4, 1121-5,
1121-6, 1204-1, 1204-2, 1204-3, 1204-4, 1204-5, 1204-6,
1205-1, 1205-2, 1205-3, 1205-4, 1205-5, 1205-6, 1207-1,
1207-2, 1207-3, 1207-4, 1207-5, 1207-6, 1212-1, 1212-2,
1212-3, 1212-4, 1212-5, 1212-6, 202-1, 202-2, 202-3,
202-4, 202-5, 202-6, 205-1, 205-2, 205-3, 205-4,
205-5, 205-6, 207-1, 207-2, 207-3, 207-4, 207-5,
207-6, 208-1, 208-2, 208-3, 208-4, 208-5, 208-6,
211-1, 211-2, 211-3, 211-4, 211-5, 211-6, 213-1,
213-2, 213-3, 213-4, 213-5, 213-6, 214-1, 214-2,
214-3, 214-4, 214-5, 214-6, 217-1, 217-2, 217-3,
217-4, 217-5, 217-6, 218-1, 218-2, 218-3, 218-4,
218-5, 218-6, 219-1, 219-2, 219-3, 219-4, 219-5,
219-6, 223-1, 223-2, 223-3, 223-4, 223-5, 223-6,
302-1, 302-2, 302-3, 302-4, 302-5, 302-6, 305-1,
305-2, 305-3, 305-4, 305-5, 305-6, 308-1, 308-2,
308-3, 308-4, 308-5, 308-6, 311-1, 311-2, 311-3,
311-4, 311-5, 311-6, 401-1, 401-2, 401-3, 401-4,
401-5, 401-6, 402-1, 402-2, 402-3, 402-4, 402-5,
402-6, 405-1, 405-2, 405-3, 405-4, 405-5, 405-6,
407-1, 407-2, 407-3, 407-4, 407-5, 407-6, 408-1,
408-2, 408-3, 408-4, 408-5, 408-6, 410-1, 410-2,
410-3, 410-4, 410-5, 410-6, 411-1, 411-2, 411-3,
411-4, 411-5, 411-6, 414-1, 414-2, 414-3, 414-4,
414-5, 414-6, 416-1, 416-2, 416-3, 416-4, 416-5,
416-6, 417-1, 417-2, 417-3, 417-4, 417-5, 417-6,
420-1, 420-2, 420-3, 420-4, 420-5, 420-6, 423-1,
423-2, 423-3, 423-4, 423-5, 423-6, 501-1, 501-2,
501-3, 501-4, 501-5, 501-6, 502-1, 502-2, 502-3,
502-4, 502-5, 502-6, 504-1, 504-2, 504-3, 504-4,
504-5, 504-6, 505-1, 505-2, 505-3, 505-4, 505-5,
505-6, 507-1, 507-2, 507-3, 507-4, 507-5, 507-6,
508-1, 508-2, 508-3, 508-4, 508-5, 508-6, 511-1,
511-2, 511-3, 511-4, 511-5, 511-6, 602-1, 602-2,
602-3, 602-4, 602-5, 602-6, 604-1, 604-2, 604-3,
604-4, 604-5, 604-6, 605-1, 

[R] inverse for formula transformations on LHS

2013-05-17 Thread Paul Johnson
This is an R formula handling question. It arose in class. We were working
on the Animals data in the MASS package. In order to see a relationship,
you need to log brain and body weight.  It's a fun one for teaching
regression, if you did not try it yet.  There are outliers too!

Students wanted to make a predicted value plot in the non-logged values of
y, for comparison, and I wondered if I couldn't automate this somehow for
them.

It made me wonder how R manages formulae and if a transformation like
log(y) can be be mechanically inverted.

So we have something concrete to talk about, suppose x and y are variables
in dat, a person fits

m1 - lm(log(y) ~ log(x), data = dat)

termplot shows log(y) on the vertical.  What if I want y on the vertical?
Similarly, predict gives values on the log(y) scale, there's no argument
like type = untransformed.

I want my solution to be a bit general, so that it would give back
predicted y for formulae like

sqrt(y)

or

exp(y)

or

log(y + d)

or whatever other math people might throw in there.

Here's what I can tell so far about R's insides.  The formula handler makes
a list out of the formula, I can get that from the terms object that the
model generates. The formula list has ~ as element 1, and log(x)
becomes element [[2]].

Where in the R source code can I see how R looks at the symbol log(y) and
discerns that there is a variable y that needs to be logged? If I could
understand that, and if R has a table of inverse functions, then maybe I
could see what to do.

If you have ideas, I'm very grateful if you share them.

pj
-- 
Paul E. Johnson
Professor, Political Science  Assoc. Director
1541 Lilac Lane, Room 504  Center for Research Methods
University of Kansas University of Kansas
http://pj.freefaculty.org   http://quant.ku.edu

[[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] Problems using lmer {lme4}

2013-05-17 Thread Bert Gunter
It would be better to post this on the r-sig-mixed-models list, I think.

-- Bert

On Fri, May 17, 2013 at 10:02 AM, Andrea Goijman
agoij...@cnia.inta.gov.ar wrote:
 Dear R list,

 I'm attaching a sample of my data which consists on the presence/absence
 (punto6, binomial n=5 occasions)
 of different species (sp), on different sites (site) within routes
 ('route).

 First, I want to be able to find if there is autocorrelation of the
 response variable between
 the sites within each route. For this I start testing 2 models, but when I
 try to run the second model,
 to test for the random effects of sites within routes R stops working!

 I'm not being able to find out why r is crashing... and whay am I doing
 wrong.

 Thanks!

 Andrea

 ###
 #dput(d)

 d-structure(list(site = structure(c(55L, 56L, 57L, 58L, 59L, 60L,
 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L,
 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L,
 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 229L, 230L,
 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L,
 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L,
 229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L,
 234L, 229L, 230L, 231L, 232L, 233L, 234L, 331L, 332L, 333L, 334L,
 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L,
 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L,
 333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L,
 332L, 333L, 334L, 335L, 336L, 389L, 390L, 391L, 392L, 393L, 394L,
 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L,
 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L,
 393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L,
 392L, 393L, 394L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L,
 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L,
 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L,
 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L,
 210L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L,
 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L,
 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L,
 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 247L,
 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L,
 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L,
 252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L,
 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L), .Label = c(102-1,
 102-2, 102-3, 102-4, 102-5, 102-6, 1023-1, 1023-2,
 1023-3, 1023-4, 1023-5, 1023-6, 1027-1, 1027-2, 1027-3,
 1027-4, 1027-5, 1027-6, 1028-1, 1028-2, 1028-3, 1028-4,
 1028-5, 1028-6, 1032-1, 1032-2, 1032-3, 1032-4, 1032-5,
 1032-6, 1034-1, 1034-2, 1034-3, 1034-4, 1034-5, 1034-6,
 1036-1, 1036-2, 1036-3, 1036-4, 1036-5, 1036-6, 1041-1,
 1041-2, 1041-3, 1041-4, 1041-5, 1041-6, 1046-1, 1046-2,
 1046-3, 1046-4, 1046-5, 1046-6, 105-1, 105-2, 105-3,
 105-4, 105-5, 105-6, 107-1, 107-2, 107-3, 107-4,
 107-5, 107-6, 108-1, 108-2, 108-3, 108-4, 108-5,
 108-6, 1101-1, 1101-2, 1101-3, 1101-4, 1101-5, 1101-6,
 1104-1, 1104-2, 1104-3, 1104-4, 1104-5, 1104-6, 1108-1,
 1108-2, 1108-3, 1108-4, 1108-5, 1108-6, 111-1, 111-2,
 111-3, 111-4, 111-5, 111-6, 1113-1, 1113-2, 1113-3,
 1113-4, 1113-5, 1113-6, 1116-1, 1116-2, 1116-3, 1116-4,
 1116-5, 1116-6, 1121-1, 1121-2, 1121-3, 1121-4, 1121-5,
 1121-6, 1204-1, 1204-2, 1204-3, 1204-4, 1204-5, 1204-6,
 1205-1, 1205-2, 1205-3, 1205-4, 1205-5, 1205-6, 1207-1,
 1207-2, 1207-3, 1207-4, 1207-5, 1207-6, 1212-1, 1212-2,
 1212-3, 1212-4, 1212-5, 1212-6, 202-1, 202-2, 202-3,
 202-4, 202-5, 202-6, 205-1, 205-2, 205-3, 205-4,
 205-5, 205-6, 207-1, 207-2, 207-3, 207-4, 207-5,
 207-6, 208-1, 208-2, 208-3, 208-4, 208-5, 208-6,
 211-1, 211-2, 211-3, 211-4, 211-5, 211-6, 213-1,
 213-2, 213-3, 213-4, 213-5, 213-6, 214-1, 214-2,
 214-3, 214-4, 214-5, 214-6, 217-1, 217-2, 217-3,
 217-4, 217-5, 217-6, 218-1, 218-2, 218-3, 218-4,
 218-5, 218-6, 219-1, 219-2, 219-3, 219-4, 219-5,
 219-6, 223-1, 223-2, 223-3, 223-4, 223-5, 223-6,
 302-1, 302-2, 302-3, 302-4, 302-5, 302-6, 305-1,
 305-2, 305-3, 305-4, 305-5, 305-6, 308-1, 308-2,
 308-3, 308-4, 308-5, 308-6, 311-1, 311-2, 311-3,
 311-4, 311-5, 311-6, 401-1, 401-2, 401-3, 401-4,
 401-5, 401-6, 402-1, 402-2, 402-3, 402-4, 402-5,
 402-6, 405-1, 405-2, 405-3, 405-4, 405-5, 405-6,
 407-1, 407-2, 407-3, 407-4, 407-5, 407-6, 408-1,
 408-2, 408-3, 408-4, 408-5, 408-6, 410-1, 410-2,
 410-3, 410-4, 410-5, 410-6, 411-1, 411-2, 411-3,
 411-4, 411-5, 411-6, 414-1, 414-2, 414-3, 414-4,
 414-5, 414-6, 416-1, 416-2, 416-3, 416-4, 416-5,
 416-6, 417-1, 417-2, 417-3, 417-4, 417-5, 417-6,
 420-1, 420-2, 420-3, 420-4, 420-5, 420-6, 423-1,
 423-2, 423-3, 423-4, 423-5, 423-6, 501-1, 501-2,
 501-3, 501-4, 501-5, 501-6, 502-1, 502-2, 502-3,
 502-4, 502-5, 502-6, 504-1, 504-2, 504-3, 504-4,
 504-5, 504-6, 505-1, 

Re: [R] Problems using lmer {lme4}

2013-05-17 Thread agoijman
Thanks! I didn't know about that list. I forwarded my question  there

Andrea
Bert Gunter wrote
 It would be better to post this on the r-sig-mixed-models list, I think.
 
 -- Bert
 
 On Fri, May 17, 2013 at 10:02 AM, Andrea Goijman
 lt;

 agoijman@.gov

 gt; wrote:
 Dear R list,

 I'm attaching a sample of my data which consists on the presence/absence
 (punto6, binomial n=5 occasions)
 of different species (sp), on different sites (site) within routes
 ('route).

 First, I want to be able to find if there is autocorrelation of the
 response variable between
 the sites within each route. For this I start testing 2 models, but when
 I
 try to run the second model,
 to test for the random effects of sites within routes R stops working!

 I'm not being able to find out why r is crashing... and whay am I doing
 wrong.

 Thanks!

 Andrea

 ###
 #dput(d)

 d-structure(list(site = structure(c(55L, 56L, 57L, 58L, 59L, 60L,
 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L,
 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L,
 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 229L, 230L,
 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L,
 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L,
 229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L,
 234L, 229L, 230L, 231L, 232L, 233L, 234L, 331L, 332L, 333L, 334L,
 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L,
 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L,
 333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L,
 332L, 333L, 334L, 335L, 336L, 389L, 390L, 391L, 392L, 393L, 394L,
 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L,
 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L,
 393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L,
 392L, 393L, 394L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L,
 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L,
 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L,
 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L,
 210L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L,
 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L,
 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L,
 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 247L,
 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L,
 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L,
 252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L,
 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L), .Label = c(102-1,
 102-2, 102-3, 102-4, 102-5, 102-6, 1023-1, 1023-2,
 1023-3, 1023-4, 1023-5, 1023-6, 1027-1, 1027-2, 1027-3,
 1027-4, 1027-5, 1027-6, 1028-1, 1028-2, 1028-3, 1028-4,
 1028-5, 1028-6, 1032-1, 1032-2, 1032-3, 1032-4, 1032-5,
 1032-6, 1034-1, 1034-2, 1034-3, 1034-4, 1034-5, 1034-6,
 1036-1, 1036-2, 1036-3, 1036-4, 1036-5, 1036-6, 1041-1,
 1041-2, 1041-3, 1041-4, 1041-5, 1041-6, 1046-1, 1046-2,
 1046-3, 1046-4, 1046-5, 1046-6, 105-1, 105-2, 105-3,
 105-4, 105-5, 105-6, 107-1, 107-2, 107-3, 107-4,
 107-5, 107-6, 108-1, 108-2, 108-3, 108-4, 108-5,
 108-6, 1101-1, 1101-2, 1101-3, 1101-4, 1101-5, 1101-6,
 1104-1, 1104-2, 1104-3, 1104-4, 1104-5, 1104-6, 1108-1,
 1108-2, 1108-3, 1108-4, 1108-5, 1108-6, 111-1, 111-2,
 111-3, 111-4, 111-5, 111-6, 1113-1, 1113-2, 1113-3,
 1113-4, 1113-5, 1113-6, 1116-1, 1116-2, 1116-3, 1116-4,
 1116-5, 1116-6, 1121-1, 1121-2, 1121-3, 1121-4, 1121-5,
 1121-6, 1204-1, 1204-2, 1204-3, 1204-4, 1204-5, 1204-6,
 1205-1, 1205-2, 1205-3, 1205-4, 1205-5, 1205-6, 1207-1,
 1207-2, 1207-3, 1207-4, 1207-5, 1207-6, 1212-1, 1212-2,
 1212-3, 1212-4, 1212-5, 1212-6, 202-1, 202-2, 202-3,
 202-4, 202-5, 202-6, 205-1, 205-2, 205-3, 205-4,
 205-5, 205-6, 207-1, 207-2, 207-3, 207-4, 207-5,
 207-6, 208-1, 208-2, 208-3, 208-4, 208-5, 208-6,
 211-1, 211-2, 211-3, 211-4, 211-5, 211-6, 213-1,
 213-2, 213-3, 213-4, 213-5, 213-6, 214-1, 214-2,
 214-3, 214-4, 214-5, 214-6, 217-1, 217-2, 217-3,
 217-4, 217-5, 217-6, 218-1, 218-2, 218-3, 218-4,
 218-5, 218-6, 219-1, 219-2, 219-3, 219-4, 219-5,
 219-6, 223-1, 223-2, 223-3, 223-4, 223-5, 223-6,
 302-1, 302-2, 302-3, 302-4, 302-5, 302-6, 305-1,
 305-2, 305-3, 305-4, 305-5, 305-6, 308-1, 308-2,
 308-3, 308-4, 308-5, 308-6, 311-1, 311-2, 311-3,
 311-4, 311-5, 311-6, 401-1, 401-2, 401-3, 401-4,
 401-5, 401-6, 402-1, 402-2, 402-3, 402-4, 402-5,
 402-6, 405-1, 405-2, 405-3, 405-4, 405-5, 405-6,
 407-1, 407-2, 407-3, 407-4, 407-5, 407-6, 408-1,
 408-2, 408-3, 408-4, 408-5, 408-6, 410-1, 410-2,
 410-3, 410-4, 410-5, 410-6, 411-1, 411-2, 411-3,
 411-4, 411-5, 411-6, 414-1, 414-2, 414-3, 414-4,
 414-5, 414-6, 416-1, 416-2, 416-3, 416-4, 416-5,
 416-6, 417-1, 417-2, 417-3, 417-4, 417-5, 417-6,
 420-1, 420-2, 420-3, 420-4, 420-5, 420-6, 423-1,
 423-2, 423-3, 423-4, 423-5, 423-6, 501-1, 501-2,
 501-3, 501-4, 501-5, 

Re: [R] update an array of plots in 'real-time' without drawing lags

2013-05-17 Thread David Winsemius

On May 17, 2013, at 7:04 AM, Martin Batholdy wrote:

 Hi,
 
 I know R is not made for this, but I still wanted to ask if there are 
 possibilities to do this;
 
 
 I repeatedly collect data from a database for a given time interval.
 Now I would like to monitor the change of this data with some nice plots.
 
 I actually have to draw 15 plots to get the whole picture.
 Now I can write a loop that, for a given time interval, updates the data and 
 plots them using one quartz window that is split into subparts with the 
 layout function.
 
 However, since I redraw every plot every time, the drawing takes some time 
 and it is not an instant update that I see.

It is not clear whether this is an asynchronous process that uses new data to 
draw some of the plots but not others. 

 The plots are slowly redrawn from the upper left corner of the quartz window 
 to the bottom right.
 
 
 That makes me wonder;
 Is there a way to buffer the graphical device before updating it?
 Or are there any other solutions for R that enables to smoothly plot / 
 visualize data in 'real-time'?

You can split 'screens' on a graphics device to which you can send plotting 
output. You already know that you can construct 'layout's. You can have 
multiple interactive output devices.

The split-screen method is incompatible with layout.

?Devices
?dev.cur
?screen

-- 

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] Error with adehabitatHR and kernelbb

2013-05-17 Thread David Winsemius

On May 17, 2013, at 7:44 AM, Rémi Lesmerises wrote:

 Dear all,
 
 I'm trying to get a Brownian bridge kernel (kernelbb) for each combination of 
 two consecutive animal locations (see commands below) and put them, with a 
 loop, inside a list. It works well at the beginning but after 42 runs, it 
 appears the following warning :
 
 
 Error in seq.default(yli[1], yli[2], by = diff(xg[1:2])) : 
  invalid (to - from)/by in seq(.)
 
 I looked at the coordinates, at the id, at the time of the run 43 and it's 
 all good...
 
 I looked on the net and it happened to only one person and there was no 
 answer to his post. 

I wonder if that posting (like yours)  had no data on which to display the 
problem or to test potential solutions? I would think you would want to post 
any setup objects and then data for items 40-45.

 
 Someone could help me?
 
 ## commands
 
 BBtraj - list()
 for (i in 1:(nrow(loc@data)-1)) {
 BBtraj[[i]] - kernelbb(as.ltraj(loc@coords[i:(i+1),], 
 date=loc@data$time[i:(i+1)], id = as.character(loc@data$id[i:(i+1)]),
 typeII = TRUE), sig1=as.numeric(as.character(loc@data$sig1[i])), sig2= 5, 
 grid = 1000)
 }
 
-- 


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] pearson correlation significant level

2013-05-17 Thread Peter Ehlers

On 2013-05-17 08:37, Jose Iparraguirre wrote:

Dear Elaine,

One of the elements you obtain the P matrix, which is the matrix of  asymptotic 
p-values. In your case, you get that the asymptotic p-value of the association 
between t_i and t_r is 0. That is, there would exist a perfect association 
(look also at the first result, the matrix of correlations: the correlation 
coefficient between these variables is 1).
Hope this helps,
José



Actually, the coefficient is -0.89.
Not surprisingly, with n = 4873, this indicates a significant
correlation.
For details of the t-test involved in the calculation, see any
intro stats text or look at the code of cor.test.default().

Peter Ehlers



Prof. José Iparraguirre
Chief Economist
Age UK

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Elaine Kuo
Sent: 17 May 2013 10:40
To: r-help@r-project.org
Subject: [R] pearson correlation significant level

Hello

I am using package Hmisc to calculate the pearson correlation and the 
significant level for the matrix of t_i and t_r. (temperature minimum and 
temperature range)

However, I have difficulty interpreting the result, even after checking the 
manual.
Please kindly help to indicate if the p-value is zero.
Thank you in advance.
Elaine

The code

library(Hmisc)
rcorr(as.matrix(datat), type=pearson) # type can be pearson or
spearman



The result is
  t_i   t_r
t_i  1.00 -0.89
t_r -0.89  1.00

n= 4873


P
 t_i t_r
t_i  0
t_r  0





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

Please donate to the Syria Crisis Appeal by text or online:

To donate £5 by mobile, text SYRIA to 70800.  To donate online, please visit

http://www.ageinternational.org.uk/syria

Over one million refugees are desperately in need of water, food, healthcare, 
warm clothing,
blankets and shelter; Age International urgently needs your support to help 
affected older refugees.


Age International is a subsidiary charity of Age UK and a member of the 
Disasters Emergency Committee (DEC).
The DEC launches and co-ordinates national fundraising appeals for public 
donations on behalf of its member agencies.

Texts cost £5 plus one standard rate message.  Age International will receive a 
minimum of £4.96.
More info at ageinternational.org.uk/SyriaTerms





---
Age UK is a registered charity and company limited by guarantee, (registered 
charity number 1128267, registered company number 6825798).
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed 
Representative of Age UK Enterprises Limited, Age UK is an Introducer
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth 
Access for the purposes of introducing potential annuity and health
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit 
Solutions Limited and Simplyhealth Access are all authorised and
regulated by the Financial Services Authority.
--

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are
addressed. If you receive a message in error, please advise the sender and 
delete immediately.

Except where this email is sent in the usual course of our business, any 
opinions expressed in this email are those of the author and do not
necessarily reflect the opinions of Age UK or its subsidiaries and associated 
companies. Age UK monitors all e-mail transmissions passing
through its network and may block or modify mails which are deemed to be 
unsuitable.

Age Concern England (charity number 261794) and Help the Aged (charity number 
272786) and their trading and other associated companies merged
on 1st April 2009.  Together they have formed the Age UK Group, dedicated to 
improving the lives of people in later life.  The three national
Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help 
the Aged in these nations to form three registered charities:
Age Scotland, Age NI, Age Cymru.




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



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


Re: [R] Error with adehabitatHR and kernelbb

2013-05-17 Thread Rémi Lesmerises



This is the problematic data, especially the line 43, but when I removed that 
line, it bugs at line 62 and so on.

          sig1                    time                        id     UTMnorthin 
UTMeasting
40      4.5766      2012.05.30 08:00:00     Ade-55419576     390052
41      4.5766      2012.05.30 10:00:00     Ade-55419581     390058
42      4.5766      2012.05.30 12:00:00     Ade-55419560     390045 
43      4.5766      2012.05.30 14:00:00     Ade-55419574     390051
44      4.5766      2012.05.30 16:00:00     Ade-55419490     390051
45      4.5766      2012.05.30 18:00:00     Ade-55419435     390293
46      4.5766      2012.05.30 20:00:00     Ade-55419661     390876
47      4.5766      2012.05.30 22:00:00     Ade-55419934     390673
48      4.5766      2012.05.31 02:00:00     Ade-55420636     389777
49      4.5766      2012.06.05 02:00:00     Ade-75419275     391206
50      4.5766      2012.06.05 04:00:00     Ade-75419276     391202

This is a data frame so before the loop (see commands in the previous mail 
below), I transform with the following commands:

coordinates(fece)-~UTMeasting+UTMnorthin
fece@data$time - as.POSIXct(strptime(as.character(fece@data$time),%Y.%m.%d 
%H:%M:%S))


Rémi Lesmerises, biol. M.Sc.,
PH.D candidate
Université du Québec à Rimouski


 De : David Winsemius dwinsem...@comcast.net
À : Rémi Lesmerises remilesmeri...@yahoo.ca 
Cc : r-help@r-project.org r-help@r-project.org 
Envoyé le : vendredi 17 mai 2013 13h53
Objet : Re: [R] Error with adehabitatHR and kernelbb



On May 17, 2013, at 7:44 AM, Rémi Lesmerises wrote:

 Dear all,
 
 I'm trying to get a Brownian bridge kernel (kernelbb) for each combination of 
 two consecutive animal locations (see commands below) and put them, with a 
 loop, inside a list. It works well at the beginning but after 42 runs, it 
 appears the following warning :
 
 
 Error in seq.default(yli[1], yli[2], by = diff(xg[1:2])) : 
  invalid (to - from)/by in seq(.)
 
 I looked at the coordinates, at the id, at the time of the run 43 and it's 
 all good...
 
 I looked on the net and it happened to only one person and there was no 
 answer to his post. 

I wonder if that posting (like yours)  had no data on which to display the 
problem or to test potential solutions? I would think you would want to post 
any setup objects and then data for items 40-45.

 
 Someone could help me?
 
 ## commands
 
 BBtraj - list()
 for (i in 1:(nrow(loc@data)-1)) {
 BBtraj[[i]] - kernelbb(as.ltraj(loc@coords[i:(i+1),], 
 date=loc@data$time[i:(i+1)], id = as.character(loc@data$id[i:(i+1)]),
 typeII = TRUE), sig1=as.numeric(as.character(loc@data$sig1[i])), sig2= 5, 
 grid = 1000)
 }
 
-- 


David Winsemius
Alameda, CA, USA
[[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] Problems using lmer {lme4}

2013-05-17 Thread Patrick Coulombe
Hi Andrea,

I'm not exactly sure what you're trying to do, but you've included a
random effect for a site coefficient that's not even in your list of
fixed effects... you're basically allowing the coefficient for site to
vary across routes, but you're never including the coefficient in the
first place. Given the appropriate nested structure (I haven't looked
at your data), a model that should run would be:

m2 - lmer(cbind(punto6,5) ~ sp + site + (site|route) ,family=binomial,data = d)

The problem here is I'm not sure this is what you mean to do... If you
could way simplify your example (for example, by including a small
number of mock observations with only the relevant variables, in a
table instead of in R syntax), that would be helpful.

Patrick

2013/5/17 Andrea Goijman agoij...@cnia.inta.gov.ar:
 Dear R list,

 I'm attaching a sample of my data which consists on the presence/absence
 (punto6, binomial n=5 occasions)
 of different species (sp), on different sites (site) within routes
 ('route).

 First, I want to be able to find if there is autocorrelation of the
 response variable between
 the sites within each route. For this I start testing 2 models, but when I
 try to run the second model,
 to test for the random effects of sites within routes R stops working!

 I'm not being able to find out why r is crashing... and whay am I doing
 wrong.

 Thanks!

 Andrea

 ###
 #dput(d)

 d-structure(list(site = structure(c(55L, 56L, 57L, 58L, 59L, 60L,
 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L,
 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L,
 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 229L, 230L,
 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L,
 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L,
 229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L,
 234L, 229L, 230L, 231L, 232L, 233L, 234L, 331L, 332L, 333L, 334L,
 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L,
 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L,
 333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L,
 332L, 333L, 334L, 335L, 336L, 389L, 390L, 391L, 392L, 393L, 394L,
 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L,
 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L,
 393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L,
 392L, 393L, 394L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L,
 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L,
 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L,
 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L,
 210L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L,
 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L,
 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L,
 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 247L,
 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L,
 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L,
 252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L,
 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L), .Label = c(102-1,
 102-2, 102-3, 102-4, 102-5, 102-6, 1023-1, 1023-2,
 1023-3, 1023-4, 1023-5, 1023-6, 1027-1, 1027-2, 1027-3,
 1027-4, 1027-5, 1027-6, 1028-1, 1028-2, 1028-3, 1028-4,
 1028-5, 1028-6, 1032-1, 1032-2, 1032-3, 1032-4, 1032-5,
 1032-6, 1034-1, 1034-2, 1034-3, 1034-4, 1034-5, 1034-6,
 1036-1, 1036-2, 1036-3, 1036-4, 1036-5, 1036-6, 1041-1,
 1041-2, 1041-3, 1041-4, 1041-5, 1041-6, 1046-1, 1046-2,
 1046-3, 1046-4, 1046-5, 1046-6, 105-1, 105-2, 105-3,
 105-4, 105-5, 105-6, 107-1, 107-2, 107-3, 107-4,
 107-5, 107-6, 108-1, 108-2, 108-3, 108-4, 108-5,
 108-6, 1101-1, 1101-2, 1101-3, 1101-4, 1101-5, 1101-6,
 1104-1, 1104-2, 1104-3, 1104-4, 1104-5, 1104-6, 1108-1,
 1108-2, 1108-3, 1108-4, 1108-5, 1108-6, 111-1, 111-2,
 111-3, 111-4, 111-5, 111-6, 1113-1, 1113-2, 1113-3,
 1113-4, 1113-5, 1113-6, 1116-1, 1116-2, 1116-3, 1116-4,
 1116-5, 1116-6, 1121-1, 1121-2, 1121-3, 1121-4, 1121-5,
 1121-6, 1204-1, 1204-2, 1204-3, 1204-4, 1204-5, 1204-6,
 1205-1, 1205-2, 1205-3, 1205-4, 1205-5, 1205-6, 1207-1,
 1207-2, 1207-3, 1207-4, 1207-5, 1207-6, 1212-1, 1212-2,
 1212-3, 1212-4, 1212-5, 1212-6, 202-1, 202-2, 202-3,
 202-4, 202-5, 202-6, 205-1, 205-2, 205-3, 205-4,
 205-5, 205-6, 207-1, 207-2, 207-3, 207-4, 207-5,
 207-6, 208-1, 208-2, 208-3, 208-4, 208-5, 208-6,
 211-1, 211-2, 211-3, 211-4, 211-5, 211-6, 213-1,
 213-2, 213-3, 213-4, 213-5, 213-6, 214-1, 214-2,
 214-3, 214-4, 214-5, 214-6, 217-1, 217-2, 217-3,
 217-4, 217-5, 217-6, 218-1, 218-2, 218-3, 218-4,
 218-5, 218-6, 219-1, 219-2, 219-3, 219-4, 219-5,
 219-6, 223-1, 223-2, 223-3, 223-4, 223-5, 223-6,
 302-1, 302-2, 302-3, 302-4, 302-5, 302-6, 305-1,
 305-2, 305-3, 305-4, 305-5, 305-6, 308-1, 308-2,
 308-3, 308-4, 308-5, 308-6, 311-1, 311-2, 311-3,
 311-4, 311-5, 311-6, 

Re: [R] pearson correlation significant level

2013-05-17 Thread Don McKenzie
Just stating the obvious that Peter left unsaid:  The OP calculated a  
matrix, whose diagonal is the correlations between each variable and  
itself, with the off-diagonal entries being the ones of interest.


On 17-May-13, at 11:06 AM, Peter Ehlers wrote:


On 2013-05-17 08:37, Jose Iparraguirre wrote:

Dear Elaine,

One of the elements you obtain the P matrix, which is the matrix  
of  asymptotic p-values. In your case, you get that the asymptotic  
p-value of the association between t_i and t_r is 0. That is,  
there would exist a perfect association (look also at the first  
result, the matrix of correlations: the correlation coefficient  
between these variables is 1).

Hope this helps,
José



Actually, the coefficient is -0.89.
Not surprisingly, with n = 4873, this indicates a significant
correlation.
For details of the t-test involved in the calculation, see any
intro stats text or look at the code of cor.test.default().

Peter Ehlers



Prof. José Iparraguirre
Chief Economist
Age UK

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- 
project.org] On Behalf Of Elaine Kuo

Sent: 17 May 2013 10:40
To: r-help@r-project.org
Subject: [R] pearson correlation significant level

Hello

I am using package Hmisc to calculate the pearson correlation and  
the significant level for the matrix of t_i and t_r. (temperature  
minimum and temperature range)


However, I have difficulty interpreting the result, even after  
checking the manual.

Please kindly help to indicate if the p-value is zero.
Thank you in advance.
Elaine

The code

library(Hmisc)
rcorr(as.matrix(datat), type=pearson) # type can be pearson or
spearman



The result is
  t_i   t_r
t_i  1.00 -0.89
t_r -0.89  1.00

n= 4873


P
 t_i t_r
t_i  0
t_r  0





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

Please donate to the Syria Crisis Appeal by text or online:

To donate £5 by mobile, text SYRIA to 70800.  To donate online,  
please visit


http://www.ageinternational.org.uk/syria

Over one million refugees are desperately in need of water, food,  
healthcare, warm clothing,
blankets and shelter; Age International urgently needs your  
support to help affected older refugees.



Age International is a subsidiary charity of Age UK and a member  
of the Disasters Emergency Committee (DEC).
The DEC launches and co-ordinates national fundraising appeals for  
public donations on behalf of its member agencies.


Texts cost £5 plus one standard rate message.  Age International  
will receive a minimum of £4.96.

More info at ageinternational.org.uk/SyriaTerms





---
Age UK is a registered charity and company limited by guarantee,  
(registered charity number 1128267, registered company number  
6825798).
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H  
9NA.


For the purposes of promoting Age UK Insurance, Age UK is an  
Appointed Representative of Age UK Enterprises Limited, Age UK is  
an Introducer
Appointed Representative of JLT Benefit Solutions Limited and  
Simplyhealth Access for the purposes of introducing potential  
annuity and health
cash plans customers respectively.  Age UK Enterprises Limited,  
JLT Benefit Solutions Limited and Simplyhealth Access are all  
authorised and

regulated by the Financial Services Authority.
--

This email and any files transmitted with it are confidential and  
intended solely for the use of the individual or entity to whom  
they are
addressed. If you receive a message in error, please advise the  
sender and delete immediately.


Except where this email is sent in the usual course of our  
business, any opinions expressed in this email are those of the  
author and do not
necessarily reflect the opinions of Age UK or its subsidiaries and  
associated companies. Age UK monitors all e-mail transmissions  
passing
through its network and may block or modify mails which are deemed  
to be unsuitable.


Age Concern England (charity number 261794) and Help the Aged  
(charity number 272786) and their trading and other associated  
companies merged
on 1st April 2009.  Together they have formed the Age UK Group,  
dedicated to improving the lives of people in later life.  The  
three national
Age Concerns in Scotland, Northern Ireland and Wales have also  
merged with Help the Aged in these nations to form three  
registered charities:

Age Scotland, Age NI, Age Cymru.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting- 
guide.html

and provide commented, minimal, 

Re: [R] Error with adehabitatHR and kernelbb

2013-05-17 Thread Rémi Lesmerises
There was some mistakes in my previous sending. The following are correct.

This is the problematic data, especially the line 43, but when I removed that 
line, it bugs at line 62 and so on.


          sig1                    time                        id       
UTMnorthin  UTMeasting
40      4.5766      2012.05.30 08:00:00     Ade-5   5419576     390052
41      4.5766      2012.05.30 10:00:00     Ade-5   5419581     390058
42      4.5766      2012.05.30 12:00:00     Ade-5   5419560     390045 
43      4.5766      2012.05.30 14:00:00     Ade-5   5419574     390051
44      4.5766      2012.05.30 16:00:00     Ade-5   5419490     390051
45      4.5766      2012.05.30 18:00:00     Ade-5   5419435     390293
46      4.5766      2012.05.30 20:00:00     Ade-5   5419661     390876
47      4.5766      2012.05.30 22:00:00     Ade-5   5419934     390673
48      4.5766      2012.05.31 02:00:00     Ade-5   5420636     389777
49      4.5766      2012.06.05 02:00:00     Ade-7   5419275     391206
50      4.5766      2012.06.05 04:00:00     Ade-7   5419276     391202

This is a data frame so before the loop (see commands in the previous mail 
below), I transform with the following commands:

coordinates(fece)-~UTMeasting+UTMnorthin
loc@data$time - as.POSIXct(strptime(as.character(loc@data$time),%Y.%m.%d 
%H:%M:%S))


Rémi Lesmerises, biol. M.Sc.,
PH.D candidate
Université du Québec à Rimouski


De : David Winsemius dwinsem...@comcast.net
À : Rémi Lesmerises remilesmeri...@yahoo.ca 
Cc : r-help@r-project.org r-help@r-project.org 
Envoyé le : vendredi 17 mai 2013 13h53
Objet : Re: [R] Error with adehabitatHR and kernelbb



On May 17, 2013, at 7:44 AM, Rémi Lesmerises wrote:

 Dear all,
 
 I'm trying to get a Brownian bridge kernel (kernelbb) for each combination of 
 two consecutive animal locations (see commands below) and put them, with a 
 loop, inside a list. It works well at the beginning but after 42 runs, it 
 appears the following warning :
 
 
 Error in seq.default(yli[1], yli[2], by = diff(xg[1:2])) : 
  invalid (to - from)/by in seq(.)
 
 I looked at the coordinates, at the id, at the time of the run 43 and it's 
 all good...
 
 I looked on the net and it happened to only one person and there was no 
 answer to his post. 

I wonder if that posting (like yours)  had no data on which to display the 
problem or to test potential solutions? I would think you would want to post 
any setup objects and then data for items 40-45.

 
 Someone could help me?
 
 ## commands
 
 BBtraj - list()
 for (i in 1:(nrow(loc@data)-1)) {
 BBtraj[[i]] - kernelbb(as.ltraj(loc@coords[i:(i+1),], 
 date=loc@data$time[i:(i+1)], id = as.character(loc@data$id[i:(i+1)]),
 typeII = TRUE), sig1=as.numeric(as.character(loc@data$sig1[i])), sig2= 5, 
 grid = 1000)
 }
 
-- 


David Winsemius
Alameda, CA, USA
    [[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] #Keeping row names when using as.data.frame.matrix

2013-05-17 Thread Tim
#question I have the following data set:

Date-c(9/7/2010,9/7/2010,9/7/2010,9/7/2010,9/7/2010,9/7/2010,9/8/2010)

EstimatedQuantity-c(3535,2772,3279,3411,3484,3274,3305)

ScowNo-c(4001,3002,4002,BR 8,4002,BR 8,4001)

dataset- data.frame(EstimatedQuantity,Date,ScowNo)

#I'm trying to convert the data set into a contingency table and then back
into a regular data frame:


xtabdata-as.data.frame.matrix(xtabs(EstimatedQuantity~Date+ScowNo,data=dataset),
 row.names=(dataset$Date),optional=F)

#I'm trying to keep the row names (in xtabsdata) as the dates.
#But the row names keep coming up as integers.
#How can I preserve the row names as dates when
#the table is converted back to a data frame?




--
View this message in context: 
http://r.789695.n4.nabble.com/Keeping-row-names-when-using-as-data-frame-matrix-tp4667344.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] time-series aggregation of information

2013-05-17 Thread Chirag Maru
I have following data for which I need to calculate the weighted aggregate 
value of the parameter at each time.

Date,Parameter,Weight
2012-01-31,90,200
2012-01-31,80,400
2012-01-31,70,500
2012-01-31,60,800
2012-02-29,120,220
2012-02-29,110,410
2012-02-29,75,520
2012-02-29,65,840
2012-03-31,115,210
2012-03-31,100,405
2012-03-31,70,500
2012-03-31,60,800

So for the above sample the solution looks like:

Date,Weighted Parameter
2012-01-31,70
2012-02-29,82.96482412
2012-03-31,77.10182768

Could I potentially use tapply / aggregate for this?  Would like to avoid a for 
loop if possible.

Thank you!





The information transmitted is intended solely for the individual or entity to 
which it is addressed and may contain confidential and/or privileged material. 
Any review, retransmission, dissemination or other use of or taking action in 
reliance upon this information by persons or entities other than the intended 
recipient is prohibited. If you have received this email in error please 
contact the sender and delete the material from any computer.

Any information contained herein is neither an offer to sell nor a solicitation 
to buy any interest in any investment fund. An offer can only be made by the 
approved offering memorandum, which contains important information concerning 
risk factors and other material information and must be read carefully before 
any decision to invest is made. Securities and derivatives trading are 
speculative and involve a risk of substantial loss. Past results are not 
necessarily indicative of future performance.

All incoming and outgoing e-mails are archived and may be reviewed and/or 
produced at the request of regulators or in connection with civil litigation. 
IRON Holdings, LLC. accepts no liability for any errors or omissions arising as 
a result of transmission.

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

2013-05-17 Thread masumeh akhgar
Hello,

I fail to tranfer data from a dataframe to a matrix.

var is from a dataframe (and belongs still to the class dataframe) and
should look like m (see below).

 var
  vec1 vec3  d1  d2
1  172  173 223 356
 dput (var)
structure(list(vec1 = 172L, vec3 = 173L, d1 = 223L, d2 = 356L), .Names =
c(vec1,
vec3, d1, d2), row.names = 1L, class = data.frame)
 m  #THIS IS THE AIM
 [,1] [,2]
[1,]  172  223
[2,]  173  356

 dput (m)
structure(c(172, 173, 223, 356), .Dim = c(2L, 2L))

How can I transform var to m?
Thanks
akhgar

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

2013-05-17 Thread masumeh akhgar
hi deer all
Estimate KM survival probabilities for each categories of RX means
‘treatment’ and ‘placebo’ separately
 surv.Rx-survfit(Surv(SURVT,STATUS)~strata(RX),data=rem.data)
when write that command. it doesnt run.
what should i do?
thanks

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


Re: [R] help

2013-05-17 Thread Kevin E. Thorpe

On 05/17/2013 02:34 PM, masumeh akhgar wrote:

hi deer all
Estimate KM survival probabilities for each categories of RX means
‘treatment’ and ‘placebo’ separately

surv.Rx-survfit(Surv(SURVT,STATUS)~strata(RX),data=rem.data)

when write that command. it doesnt run.
what should i do?
thanks



What do you mean it doesn't run?  Is there an error message?  What is 
it?  Also, you do not need to put RX in strata() in the survfit() function.



--
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] #Keeping row names when using as.data.frame.matrix

2013-05-17 Thread David Winsemius

On May 17, 2013, at 9:46 AM, Tim wrote:

 #question I have the following data set:
 
 Date-c(9/7/2010,9/7/2010,9/7/2010,9/7/2010,9/7/2010,9/7/2010,9/8/2010)
 
 EstimatedQuantity-c(3535,2772,3279,3411,3484,3274,3305)
 
 ScowNo-c(4001,3002,4002,BR 8,4002,BR 8,4001)
 
 dataset- data.frame(EstimatedQuantity,Date,ScowNo)
 
 #I'm trying to convert the data set into a contingency table and then back
 into a regular data frame:
 
 
 xtabdata-as.data.frame.matrix(xtabs(EstimatedQuantity~Date+ScowNo,data=dataset),
 row.names=(dataset$Date),optional=F)
 
 #I'm trying to keep the row names (in xtabsdata) as the dates.
 #But the row names keep coming up as integers.
 #How can I preserve the row names as dates when
 #the table is converted back to a data frame?

It's a factor-problem (see the FAQ …. read all of section 7, i'm too lazy to 
look it up again.):

xtabdata-as.data.frame.matrix(xtabs(EstimatedQuantity~Date+ScowNo,data=dataset),
  row.names=sort( unique( as.character(dataset$Date))), optional=F)

 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Keeping-row-names-when-using-as-data-frame-matrix-tp4667344.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.

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

2013-05-17 Thread Berend Hasselman

On 17-05-2013, at 20:15, masumeh akhgar akhgar.masu...@gmail.com wrote:

 Hello,
 
 I fail to tranfer data from a dataframe to a matrix.
 
 var is from a dataframe (and belongs still to the class dataframe) and
 should look like m (see below).
 
 var
  vec1 vec3  d1  d2
 1  172  173 223 356
 dput (var)
 structure(list(vec1 = 172L, vec3 = 173L, d1 = 223L, d2 = 356L), .Names =
 c(vec1,
 vec3, d1, d2), row.names = 1L, class = data.frame)
 m  #THIS IS THE AIM
 [,1] [,2]
 [1,]  172  223
 [2,]  173  356
 
 dput (m)
 structure(c(172, 173, 223, 356), .Dim = c(2L, 2L))
 
 How can I transform var to m?
 Thanks
 akhgar


This question appears to be an almost exact copy of this: 
http://r.789695.n4.nabble.com/convert-a-data-frame-to-matrix-td4667256.html

See the answers there.

Spam?

Berend

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


Re: [R] help

2013-05-17 Thread John Kane
m  -  as.matrix(var)

John Kane
Kingston ON Canada


 -Original Message-
 From: akhgar.masu...@gmail.com
 Sent: Fri, 17 May 2013 22:45:22 +0430
 To: r-help@r-project.org
 Subject: [R] help
 
 Hello,
 
 I fail to tranfer data from a dataframe to a matrix.
 
 var is from a dataframe (and belongs still to the class dataframe) and
 should look like m (see below).
 
 var
   vec1 vec3  d1  d2
 1  172  173 223 356
 dput (var)
 structure(list(vec1 = 172L, vec3 = 173L, d1 = 223L, d2 = 356L), .Names =
 c(vec1,
 vec3, d1, d2), row.names = 1L, class = data.frame)
 m  #THIS IS THE AIM
  [,1] [,2]
 [1,]  172  223
 [2,]  173  356
 
 dput (m)
 structure(c(172, 173, 223, 356), .Dim = c(2L, 2L))
 
 How can I transform var to m?
 Thanks
 akhgar
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


Share photos  screenshots in seconds...
TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if1
Works in all emails, instant messengers, blogs, forums and social networks.

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

2013-05-17 Thread David Winsemius

On May 17, 2013, at 11:48 AM, Chirag Maru wrote:

 I have following data for which I need to calculate the weighted aggregate 
 value of the parameter at each time.
 
 Date,Parameter,Weight
 2012-01-31,90,200
 2012-01-31,80,400
 2012-01-31,70,500
 2012-01-31,60,800
 2012-02-29,120,220
 2012-02-29,110,410
 2012-02-29,75,520
 2012-02-29,65,840
 2012-03-31,115,210
 2012-03-31,100,405
 2012-03-31,70,500
 2012-03-31,60,800
 
 So for the above sample the solution looks like:
 
 Date,Weighted Parameter
 2012-01-31,70
 2012-02-29,82.96482412
 2012-03-31,77.10182768
 
 Could I potentially use tapply / aggregate for this?  Would like to avoid a 
 for loop if possible.

 by(dat, dat[1], FUN=function(d) weighted.mean(d[[Parameter]], 
 w=d[[Weight]]) )
Date: 2012-01-31
[1] 70
 
Date: 2012-02-29
[1] 82.96482
 
Date: 2012-03-31
[1] 77.10183

It's a bit of a shame that there is no as.data.frame.by function. You can 
create a dataframe from the by object with as.data.frame.table with the only 
defect in the naming of the second column

as.data.frame.table(by(dat, dat[1], FUN=function(d) 
weighted.mean(d[[Parameter]], w=d[[Weight]]) ))

Date Freq
1 2012-01-31 70.0
2 2012-02-29 82.96482
3 2012-03-31 77.10183

 setNames(as.data.frame.table(by(dat, dat[1], FUN=function(d) 
weighted.mean(d[[Parameter]], w=d[[Weight]]) )), 
  c(Dts, wtdmeans))
 Dts wtdmeans
1 2012-01-31 70.0
2 2012-02-29 82.96482
3 2012-03-31 77.10183


-- 

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

2013-05-17 Thread masumeh akhgar
hi all
this command used tt function for all variables.
How can i define a different function for each variable?
  exCox.all-coxph(Surv(SURVT,STATUS) ~
RX+LOGWBC+SEX+tt(RX)+tt(LOGWBC)+tt(SEX),
data=rem.data,tt=function(x,t,...) log(t)*x))
thank you

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

2013-05-17 Thread arun
Hi,
May be this helps:
dat- read.table(text=
Date,Parameter,Weight
2012-01-31,90,200
2012-01-31,80,400
2012-01-31,70,500
2012-01-31,60,800
2012-02-29,120,220
2012-02-29,110,410
2012-02-29,75,520
2012-02-29,65,840
2012-03-31,115,210
2012-03-31,100,405
2012-03-31,70,500
2012-03-31,60,800
,sep=,,header=TRUE,stringsAsFactors=FALSE)
library(plyr)
 ddply(dat,.(Date), summarize, wtdmeans=weighted.mean(Parameter,Weight))
#    Date wtdmeans
#1 2012-01-31 70.0
#2 2012-02-29 82.96482
#3 2012-03-31 77.10183
A.K.




- Original Message -
From: Chirag Maru chirag.m...@ironfinancial.com
To: r-help@R-project.org r-help@r-project.org
Cc: 
Sent: Friday, May 17, 2013 2:48 PM
Subject: [R] time-series aggregation of information

I have following data for which I need to calculate the weighted aggregate 
value of the parameter at each time.

Date,Parameter,Weight
2012-01-31,90,200
2012-01-31,80,400
2012-01-31,70,500
2012-01-31,60,800
2012-02-29,120,220
2012-02-29,110,410
2012-02-29,75,520
2012-02-29,65,840
2012-03-31,115,210
2012-03-31,100,405
2012-03-31,70,500
2012-03-31,60,800

So for the above sample the solution looks like:

Date,Weighted Parameter
2012-01-31,70
2012-02-29,82.96482412
2012-03-31,77.10182768

Could I potentially use tapply / aggregate for this?  Would like to avoid a for 
loop if possible.

Thank you!





The information transmitted is intended solely for the individual or entity to 
which it is addressed and may contain confidential and/or privileged material. 
Any review, retransmission, dissemination or other use of or taking action in 
reliance upon this information by persons or entities other than the intended 
recipient is prohibited. If you have received this email in error please 
contact the sender and delete the material from any computer.

Any information contained herein is neither an offer to sell nor a solicitation 
to buy any interest in any investment fund. An offer can only be made by the 
approved offering memorandum, which contains important information concerning 
risk factors and other material information and must be read carefully before 
any decision to invest is made. Securities and derivatives trading are 
speculative and involve a risk of substantial loss. Past results are not 
necessarily indicative of future performance.

All incoming and outgoing e-mails are archived and may be reviewed and/or 
produced at the request of regulators or in connection with civil litigation. 
IRON Holdings, LLC. accepts no liability for any errors or omissions arising as 
a result of transmission.

    [[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] help

2013-05-17 Thread David Winsemius

On May 17, 2013, at 11:55 AM, masumeh akhgar wrote:

 hi all
 this command used tt function for all variables.
 How can i define a different function for each variable?
 exCox.all-coxph(Surv(SURVT,STATUS) ~
 RX+LOGWBC+SEX+tt(RX)+tt(LOGWBC)+tt(SEX),
 data=rem.data,tt=function(x,t,...) log(t)*x))

After reading the help page it seems pretty clear that the 'tt' argument has a 
very special purpose and that it is not designed to inserting transformations 
of anything other than time-related transformations. Applying a tt() function 
to 'logwbc' or to 'SEX' makes no sense at all. In the help page the `tt` 
function is applied to the age variable and is intended to advance a subject's 
age value forward as they …. wait for it…. age (used now as an English verb 
rather than a numeric value). Other transformations would need to be built in 
the usual manner in the formula or by constructing transformed variables in the 
input dataset.

-- 

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] Bivariate - multivariate linear regression

2013-05-17 Thread Jesse Gervais
Hi there,



I want to do several bivariate linear regressions and, than, do a
multivariate linear regression including only variables significantly
associated *(p  0.15)* with y in bivariate analysis, without having to
look manually to those p values.



So, here what I got for the moment.



First, I use this data set:



tolerance - read.csv(
http://www.ats.ucla.edu/stat/r/examples/alda/data/tolerance1.txt;).



Second, I used this command, allowing me to extract p-values later:



lmp - function (modelobject) {

if (class(modelobject) != lm) stop(Not an object of class
'lm' )

f - summary(modelobject)$fstatistic

p - pf(f[1],f[2],f[3],lower.tail=F)

attributes(p) - NULL

return(p)}



Third, I did my bivariate linear regressions:



fit   = lm(exposure~tol11, data = tolerance)

fit_2 = lm(exposure~tol12, data= tolerance)

fit_3 = lm(exposure~tol13, data= tolerance)

fit_4 = lm(exposure~tol14, data= tolerance)

fit_5 = lm(exposure~tol15, data= tolerance)



Fourth, I extracted p-values:



lmp(fit)

lmp(fit_2)

lmp(fit_3)

lmp(fit_4)

lmp(fit_5)



Firth, I confirmed that p-values were OK (just to be sure, it's the first
time I used the above procedure) :



summary (fit)

summary (fit_2)

summary (fit_3)

summary (fit_4)

summary (fit_5)



And now, I’m, I don’t know what to do.



The multivariate linear regression (if all variables were included) is:



fit_multi = lm (exposure ~ tol11 + tol12 + tol13 + tol14 + tol15, data=
tolerance)



I would like to be able to do something like:


fit_multi = lm (exposure ~ tol11 [include only if  lmp( fit)  0.15] +
tol12 [include only if  lmp(fit_2)  0.15]  + tol13 [include only if
lmp(fit_3)  0.15] + tol14 [include only if lmp(fit_4)  0.15]  +
tol15 [include
only if lmp(fit_4)  0.15], data= tolerance)



Any idea?



Thank you!

[[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] formatting column names of data frame

2013-05-17 Thread Patrick Leyshock
Is there any way to format the headers of data frames, for printing?

I am using Sweave to generate formatted reports.  In Sweave, I read in a
data.frame:

  result - read.table(path.to.table);

then display it:

  print.data.frame(result);

This gives me what I expect in the eventual final output:

RecordAverage  Maximum
1   34  899
2   14  15
3   433 1003
... ... ...

What I am hoping to do is distinguish one or more of the column headers,
for example, I want Average or Maximum to be bold, underlined, etc.,
just some way to make the column name stand out visually.

Any idea if this is possible?  Any suggestions appreciated.

[[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] image and color gradient

2013-05-17 Thread Hermann Norpois
Hello,

I have a nice function that makes an image of an matrix
e.g.:
qt[1:3,1:3]
 rs655246 rs943795 rs955612
rs655246   NA   NA   NA
rs943795 9.610070e-04   NA   NA
rs955612 5.555616e-05 7.915982e-07   NA


myimage - function(x, cex.axis = 0.7, ...){
  opar - par(mar=c(5,4,4,6),
  pty ='s')
  on.exit(par(opar))
  image(x, axes = FALSE, ...)
  ats - 0:(nrow(x)-1)/(nrow(x)-1)
  axis(1, at=ats, lab=rownames(x), cex.axis=cex.axis, las=2)
  axis(4, at=ats, lab=colnames(x), cex.axis=cex.axis, las=2)
  box()
}

The ranges in my matrix are from 1 to 1e-08. But in my image there is no
difference between, for instance 1e-05 and 1e-06 or -07 etc.

How can I ameliorate my function myimage to do so. I guess it has something
to do with breaks but I do not understand how to handle.
Thanks
Hermann

[[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] inverse for formula transformations on LHS

2013-05-17 Thread Roger Koenker
Paul,

Inverting log(y)  is just the beginning of the problem,  after that you need to
teach predict.lm()  that E(y |x) = exp(x'betahat + .5*sigmahat^2) and then 
further
lessons are required to get it to understand how to adapt its confidence and
prediction bands…  and then you need to generalize all of this to other
transformations.  Quite a project!

Best,
Roger

Roger Koenker
rkoen...@illinois.edu




On May 17, 2013, at 12:21 PM, Paul Johnson wrote:

 This is an R formula handling question. It arose in class. We were working
 on the Animals data in the MASS package. In order to see a relationship,
 you need to log brain and body weight.  It's a fun one for teaching
 regression, if you did not try it yet.  There are outliers too!
 
 Students wanted to make a predicted value plot in the non-logged values of
 y, for comparison, and I wondered if I couldn't automate this somehow for
 them.
 
 It made me wonder how R manages formulae and if a transformation like
 log(y) can be be mechanically inverted.
 
 So we have something concrete to talk about, suppose x and y are variables
 in dat, a person fits
 
 m1 - lm(log(y) ~ log(x), data = dat)
 
 termplot shows log(y) on the vertical.  What if I want y on the vertical?
 Similarly, predict gives values on the log(y) scale, there's no argument
 like type = untransformed.
 
 I want my solution to be a bit general, so that it would give back
 predicted y for formulae like
 
 sqrt(y)
 
 or
 
 exp(y)
 
 or
 
 log(y + d)
 
 or whatever other math people might throw in there.
 
 Here's what I can tell so far about R's insides.  The formula handler makes
 a list out of the formula, I can get that from the terms object that the
 model generates. The formula list has ~ as element 1, and log(x)
 becomes element [[2]].
 
 Where in the R source code can I see how R looks at the symbol log(y) and
 discerns that there is a variable y that needs to be logged? If I could
 understand that, and if R has a table of inverse functions, then maybe I
 could see what to do.
 
 If you have ideas, I'm very grateful if you share them.
 
 pj
 -- 
 Paul E. Johnson
 Professor, Political Science  Assoc. Director
 1541 Lilac Lane, Room 504  Center for Research Methods
 University of Kansas University of Kansas
 http://pj.freefaculty.org   http://quant.ku.edu
 
   [[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] Problems using lmer {lme4}

2013-05-17 Thread Andrea Goijman
Hi Patrick,

Thanks for you reply. I tried adding site fixed effect as you told me, but
the program failed again (R stopped working).
Basically, what I am trying to do is to test for auto-correlation between
sites within routes. My survey takes place in routes, but each route is
divided in segments (or sites), and the presence of the species is
monitored at a site level.
A simple table for one species only would be as follows:

  Route site Visit1 Visit2 Visit3 Visit4 Visit5 #detections (punto6)  1 1-1
1 0 0 0 1 2  1 1-2 1 1 1 1 0 4  1 1-3 0 1 1 1 1 4  1 1-4 0 1 1 0 0 2  1 1-5
1 0 0 0 1 2  2 2-1 0 0 1 1 1 3  2 2-2 1 1 1 1 1 5  2 2-3 0 0 0 1 0 1  2 2-4
0 0 1 1 1 3  2 2-5 0 0 1 0 1 2  3 3-1 1 1 0 1 0 3  3 3-2 1 0 1 1 1 4  3 3-3
1 0 1 1 1 4  3 3-4 0 1 1 1 0 3  3 3-5 0 0 0 1 1 2


On Fri, May 17, 2013 at 2:15 PM, Patrick Coulombe 
patrick.coulo...@gmail.com wrote:

 Hi Andrea,

 I'm not exactly sure what you're trying to do, but you've included a
 random effect for a site coefficient that's not even in your list of
 fixed effects... you're basically allowing the coefficient for site to
 vary across routes, but you're never including the coefficient in the
 first place. Given the appropriate nested structure (I haven't looked
 at your data), a model that should run would be:

 m2 - lmer(cbind(punto6,5) ~ sp + site + (site|route)
 ,family=binomial,data = d)

 The problem here is I'm not sure this is what you mean to do... If you
 could way simplify your example (for example, by including a small
 number of mock observations with only the relevant variables, in a
 table instead of in R syntax), that would be helpful.

 Patrick

 2013/5/17 Andrea Goijman agoij...@cnia.inta.gov.ar:
  Dear R list,
 
  I'm attaching a sample of my data which consists on the presence/absence
  (punto6, binomial n=5 occasions)
  of different species (sp), on different sites (site) within routes
  ('route).
 
  First, I want to be able to find if there is autocorrelation of the
  response variable between
  the sites within each route. For this I start testing 2 models, but when
 I
  try to run the second model,
  to test for the random effects of sites within routes R stops working!
 
  I'm not being able to find out why r is crashing... and whay am I doing
  wrong.
 
  Thanks!
 
  Andrea
 
  ###
  #dput(d)
 
  d-structure(list(site = structure(c(55L, 56L, 57L, 58L, 59L, 60L,
  55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L,
  56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L,
  57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 229L, 230L,
  231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L,
  230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L,
  229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L,
  234L, 229L, 230L, 231L, 232L, 233L, 234L, 331L, 332L, 333L, 334L,
  335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L,
  334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L,
  333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L,
  332L, 333L, 334L, 335L, 336L, 389L, 390L, 391L, 392L, 393L, 394L,
  389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L,
  394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L,
  393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L,
  392L, 393L, 394L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L,
  207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L,
  206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L,
  205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L,
  210L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L,
  167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L,
  166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L,
  165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 247L,
  248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L,
  247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L,
  252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L,
  251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L), .Label = c(102-1,
  102-2, 102-3, 102-4, 102-5, 102-6, 1023-1, 1023-2,
  1023-3, 1023-4, 1023-5, 1023-6, 1027-1, 1027-2, 1027-3,
  1027-4, 1027-5, 1027-6, 1028-1, 1028-2, 1028-3, 1028-4,
  1028-5, 1028-6, 1032-1, 1032-2, 1032-3, 1032-4, 1032-5,
  1032-6, 1034-1, 1034-2, 1034-3, 1034-4, 1034-5, 1034-6,
  1036-1, 1036-2, 1036-3, 1036-4, 1036-5, 1036-6, 1041-1,
  1041-2, 1041-3, 1041-4, 1041-5, 1041-6, 1046-1, 1046-2,
  1046-3, 1046-4, 1046-5, 1046-6, 105-1, 105-2, 105-3,
  105-4, 105-5, 105-6, 107-1, 107-2, 107-3, 107-4,
  107-5, 107-6, 108-1, 108-2, 108-3, 108-4, 108-5,
  108-6, 1101-1, 1101-2, 1101-3, 1101-4, 1101-5, 1101-6,
  1104-1, 1104-2, 1104-3, 1104-4, 1104-5, 1104-6, 1108-1,
  1108-2, 1108-3, 1108-4, 1108-5, 1108-6, 111-1, 111-2,
  111-3, 111-4, 111-5, 111-6, 1113-1, 1113-2, 1113-3,
  1113-4, 

Re: [R] image and color gradient

2013-05-17 Thread David Winsemius

On May 17, 2013, at 12:58 PM, Hermann Norpois wrote:

 Hello,
 
 I have a nice function that makes an image of an matrix
 e.g.:
 qt[1:3,1:3]
 rs655246 rs943795 rs955612
 rs655246   NA   NA   NA
 rs943795 9.610070e-04   NA   NA
 rs955612 5.555616e-05 7.915982e-07   NA
 

If you had used dput to offer that test case I would have tested my 
suggestions. As it is I will simply suggest:

... ,  breaks=10^-(0:8), ...

You will need to specify the colors to match the breaks.

 
 myimage - function(x, cex.axis = 0.7, ...){
  opar - par(mar=c(5,4,4,6),
  pty ='s')
  on.exit(par(opar))
  image(x, axes = FALSE, ...)
  ats - 0:(nrow(x)-1)/(nrow(x)-1)
  axis(1, at=ats, lab=rownames(x), cex.axis=cex.axis, las=2)
  axis(4, at=ats, lab=colnames(x), cex.axis=cex.axis, las=2)
  box()
 }
 
 The ranges in my matrix are from 1 to 1e-08. But in my image there is no
 difference between, for instance 1e-05 and 1e-06 or -07 etc.
 
 How can I ameliorate my function myimage to do so. I guess it has something
 to do with breaks but I do not understand how to handle.
 Thanks
 Hermann
 
   [[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] formatting column names of data frame

2013-05-17 Thread Rainer Schuermann
Have you tried xtable?

library( xtable )
x - structure(list(Record = 1:3, Average = c(34L, 14L, 433L), Maximum = 
c(899L, 
15L, 1003L)), .Names = c(Record, Average, Maximum), class = data.frame, 
row.names = c(NA, 
-3L))
x - xtable( x )
print( x )
% latex table generated in R 2.15.2 by xtable 1.7-1 package 

 
% Fri May 17 22:22:00 2013  

 
\begin{table}[ht]   

 
\centering  

 
\begin{tabular}{}   

 
  \hline

 
  Record  Average  Maximum \\

 
  \hline

 
11   34  899 \\  

 
  22   14   15 \\

 
  33  433  1003 \\   

 
   \hline   

 
\end{tabular}   

 
\end{table} 





On Friday 17 May 2013 12:53:12 Patrick Leyshock wrote:
 Is there any way to format the headers of data frames, for printing?
 
 I am using Sweave to generate formatted reports.  In Sweave, I read in a
 data.frame:
 
   result - read.table(path.to.table);
 
 then display it:
 
   print.data.frame(result);
 
 This gives me what I expect in the eventual final output:
 
 RecordAverage  Maximum
 1   34  899
 2   14  15
 3   433 1003
 ... ... ...
 
 What I am hoping to do is distinguish one or more of the column headers,
 for example, I want Average or Maximum to be bold, underlined, etc.,
 just some way to make the column name stand out visually.
 
 Any idea if this is possible?  Any suggestions appreciated.
 
   [[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] #Keeping row names when using as.data.frame.matrix

2013-05-17 Thread arun


Hi,
library(plyr)
res-dcast(dataset,Date~ScowNo,sum,value.var=EstimatedQuantity)
 rownames(res)- res[,1]
res[,-1]
# 3002 4001 4002 BR 8
#9/7/2010 2772 3535 6763 6685
#9/8/2010    0 3305    0    0
A.K.

- Original Message -
From: Tim t...@mde.state.md.us
To: r-help@r-project.org
Cc: 
Sent: Friday, May 17, 2013 12:46 PM
Subject: [R] #Keeping row names when using as.data.frame.matrix

#question I have the following data set:

Date-c(9/7/2010,9/7/2010,9/7/2010,9/7/2010,9/7/2010,9/7/2010,9/8/2010)

EstimatedQuantity-c(3535,2772,3279,3411,3484,3274,3305)

ScowNo-c(4001,3002,4002,BR 8,4002,BR 8,4001)

dataset- data.frame(EstimatedQuantity,Date,ScowNo)

#I'm trying to convert the data set into a contingency table and then back
into a regular data frame:

        
xtabdata-as.data.frame.matrix(xtabs(EstimatedQuantity~Date+ScowNo,data=dataset),
         row.names=(dataset$Date),optional=F)

#I'm trying to keep the row names (in xtabsdata) as the dates.
#But the row names keep coming up as integers.
#How can I preserve the row names as dates when
#the table is converted back to a data frame?




--
View this message in context: 
http://r.789695.n4.nabble.com/Keeping-row-names-when-using-as-data-frame-matrix-tp4667344.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] filter rows by value

2013-05-17 Thread Ye Lin
Hey All,

I want to delete rows based on the last 2 digits on the value in one column
but I dont know how to do that.

Suppose my data looks like this:

Var   Time
1   51
2  151
3   251
*4234*
*5   331*
6351

I want to delete the rows that the value in column Time, the last 2 digit
is not 51, in this case the rows highlighted will be removed.

Thanks for your help!

[[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] filter rows by value

2013-05-17 Thread Rui Barradas

Hello,

Try the following.


dat - read.table(text = 
Var   Time
1   51
2  151
3   251
4234
5   331
6351
, header = TRUE)

dat[dat$Time %% 100 == 51, ]



Em 17-05-2013 22:01, Ye Lin escreveu:

Hey All,

I want to delete rows based on the last 2 digits on the value in one column
but I dont know how to do that.

Suppose my data looks like this:

Var   Time
1   51
2  151
3   251
*4234*
*5   331*
6351

I want to delete the rows that the value in column Time, the last 2 digit
is not 51, in this case the rows highlighted will be removed.

Thanks for your help!

[[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] Bivariate - multivariate linear regression

2013-05-17 Thread Peter Ehlers

On 2013-05-17 12:45, Jesse Gervais wrote:

Hi there,



I want to do several bivariate linear regressions and, than, do a
multivariate linear regression including only variables significantly
associated *(p  0.15)* with y in bivariate analysis, without having to
look manually to those p values.



So, here what I got for the moment.



First, I use this data set:



tolerance - read.csv(
http://www.ats.ucla.edu/stat/r/examples/alda/data/tolerance1.txt;).



Second, I used this command, allowing me to extract p-values later:



lmp - function (modelobject) {

 if (class(modelobject) != lm) stop(Not an object of class
'lm' )

 f - summary(modelobject)$fstatistic

 p - pf(f[1],f[2],f[3],lower.tail=F)

 attributes(p) - NULL

 return(p)}



Third, I did my bivariate linear regressions:



fit   = lm(exposure~tol11, data = tolerance)

fit_2 = lm(exposure~tol12, data= tolerance)

fit_3 = lm(exposure~tol13, data= tolerance)

fit_4 = lm(exposure~tol14, data= tolerance)

fit_5 = lm(exposure~tol15, data= tolerance)



Fourth, I extracted p-values:



lmp(fit)

lmp(fit_2)

lmp(fit_3)

lmp(fit_4)

lmp(fit_5)



Firth, I confirmed that p-values were OK (just to be sure, it's the first
time I used the above procedure) :



summary (fit)

summary (fit_2)

summary (fit_3)

summary (fit_4)

summary (fit_5)



And now, I’m, I don’t know what to do.



The multivariate linear regression (if all variables were included) is:



fit_multi = lm (exposure ~ tol11 + tol12 + tol13 + tol14 + tol15, data=
tolerance)



I would like to be able to do something like:


fit_multi = lm (exposure ~ tol11 [include only if  lmp( fit)  0.15] +
tol12 [include only if  lmp(fit_2)  0.15]  + tol13 [include only if
lmp(fit_3)  0.15] + tol14 [include only if lmp(fit_4)  0.15]  +
tol15 [include
only if lmp(fit_4)  0.15], data= tolerance)



Any idea?



(Thanks for providing reproducible code!)

It seems to me that you're just missing two things:

1. a way to determine the names of the variables to be included
   in the multiple (not 'multivariate' to be nitpicky) regression;

2. a way to build the formula for the multiple regression once
   you know which predictors to include.

To get the variables:

  varnames - names(tolerance)[2:6]
  pvec - c(lmp(fit), lmp(fit_2), lmp(fit_3), lmp(fit_4), lmp(fit_5))
  use - varnames[pvec  0.15]
  use
  #[1] tol14 tol15

To construct the formula:

  rhs - paste(use, collapse =  + )
  form - paste(exposure ~, rhs)

And then use it:

  fit_multi - lm(formula = form, data = tolerance)

Peter Ehlers

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

2013-05-17 Thread arun


Hi,
dat1- read.table(text=
Var  Time
1  51
2  151
3  251
4    234
5  331
6    351
,sep=,header=TRUE)
dat1[!is.na(match(gsub(.*(\\d{2})$,\\1,dat1$Time),51)),]
#  Var Time
#1   1   51
#2   2  151
#3   3  251
#6   6  351
#or
dat1[substr(dat1$Time,nchar(dat1$Time)-1,nchar(dat1$Time))==51,]
#  Var Time
#1   1   51
#2   2  151
#3   3  251
#6   6  351

#or 
library(stringr)

dat1[str_detect(dat1$Time,51$),]
#  Var Time
#1   1   51
#2   2  151
#3   3  251
#6   6  351
#or
dat1[grepl(51$,dat1$Time),]
#  Var Time
#1   1   51
#2   2  151
#3   3  251
#6   6  351
#or
 dat1[str_sub(dat1$Time, start=-2)%in%51,]
  Var Time
#1   1   51
#2   2  151
#3   3  251
#6   6  351
A.K.


- Original Message -
From: Ye Lin ye...@lbl.gov
To: R help r-help@r-project.org
Cc: 
Sent: Friday, May 17, 2013 5:01 PM
Subject: [R] filter rows by value

Hey All,

I want to delete rows based on the last 2 digits on the value in one column
but I dont know how to do that.

Suppose my data looks like this:

Var   Time
1           51
2          151
3           251
*4            234*
*5           331*
6            351

I want to delete the rows that the value in column Time, the last 2 digit
is not 51, in this case the rows highlighted will be removed.

Thanks for your help!

    [[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] filter rows by value

2013-05-17 Thread Ye Lin
it works!Thanks!


On Fri, May 17, 2013 at 2:28 PM, Rui Barradas ruipbarra...@sapo.pt wrote:

 Hello,

 Try the following.


 dat - read.table(text = 

 Var   Time
 1   51
 2  151
 3   251
 4234
 5   331
 6351
 , header = TRUE)

 dat[dat$Time %% 100 == 51, ]



 Em 17-05-2013 22:01, Ye Lin escreveu:

 Hey All,

 I want to delete rows based on the last 2 digits on the value in one
 column
 but I dont know how to do that.

 Suppose my data looks like this:

 Var   Time
 1   51
 2  151
 3   251
 *4234*
 *5   331*

 6351

 I want to delete the rows that the value in column Time, the last 2
 digit
 is not 51, in this case the rows highlighted will be removed.

 Thanks for your help!

 [[alternative HTML version deleted]]

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html 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 with adehabitatHR and kernelbb

2013-05-17 Thread Michael Sumner
I presume it's related to the fact that the X coordinate is duplciated
in the two records, and the grid generated by adehabitatHR is a single
column,

Here's a test:
require(adehabitatHR)
m - matrix(c(5419574  ,390051, 5419490   ,  390051), ncol = 2,
byrow = TRUE)
 tt - as.POSIXct(c(2012-05-30 14:00:00, 2012-05-30 16:00:00))
id - c(Ade=5, Ade-5)

x - kernelbb(as.ltraj(m, date = tt, id = id, typeII=TRUE), sig1 =
4.5766, sig2 = 5, grid = 1000)

This degenerate Y dimension affects downstream methods (like image),
and I'd say this is worth reporting to the package author as an issue:

dim(x[[1]])
[1] 10001
 dim(x[[2]])
[1] 10001

The clue comes from points2grid in sp:
Warning messages:
1: In points2grid(points, tolerance, round) :
  cell size from constant coordinate 2 possibly taken from other coordinate


You could override the auto-generated grid by passing in your own,
probably something you will want anyway so that your collection share
the same extent and resolution. See ?kernelbb, the grid argument can
be a Spatial object rather than a pixel size.

I would really wonder about what is the point in generating summaries
from single line-segments, but that is off-topic I guess.

Cheers, Mike.


On Sat, May 18, 2013 at 4:47 AM, Rémi Lesmerises
remilesmeri...@yahoo.ca wrote:
 There was some mistakes in my previous sending. The following are correct.

 This is the problematic data, especially the line 43, but when I removed that 
 line, it bugs at line 62 and so on.


   sig1timeid   
 UTMnorthin  UTMeasting
 40  4.5766  2012.05.30 08:00:00 Ade-5   5419576 390052
 41  4.5766  2012.05.30 10:00:00 Ade-5   5419581 390058
 42  4.5766  2012.05.30 12:00:00 Ade-5   5419560 390045
 43  4.5766  2012.05.30 14:00:00 Ade-5   5419574 390051
 44  4.5766  2012.05.30 16:00:00 Ade-5   5419490 390051
 45  4.5766  2012.05.30 18:00:00 Ade-5   5419435 390293
 46  4.5766  2012.05.30 20:00:00 Ade-5   5419661 390876
 47  4.5766  2012.05.30 22:00:00 Ade-5   5419934 390673
 48  4.5766  2012.05.31 02:00:00 Ade-5   5420636 389777
 49  4.5766  2012.06.05 02:00:00 Ade-7   5419275 391206
 50  4.5766  2012.06.05 04:00:00 Ade-7   5419276 391202

 This is a data frame so before the loop (see commands in the previous mail 
 below), I transform with the following commands:

coordinates(fece)-~UTMeasting+UTMnorthin
loc@data$time - as.POSIXct(strptime(as.character(loc@data$time),%Y.%m.%d 
%H:%M:%S))


 Rémi Lesmerises, biol. M.Sc.,
 PH.D candidate
 Université du Québec à Rimouski

 
 De : David Winsemius dwinsem...@comcast.net
 À : Rémi Lesmerises remilesmeri...@yahoo.ca
 Cc : r-help@r-project.org r-help@r-project.org
 Envoyé le : vendredi 17 mai 2013 13h53
 Objet : Re: [R] Error with adehabitatHR and kernelbb



 On May 17, 2013, at 7:44 AM, Rémi Lesmerises wrote:

 Dear all,

 I'm trying to get a Brownian bridge kernel (kernelbb) for each combination 
 of two consecutive animal locations (see commands below) and put them, with 
 a loop, inside a list. It works well at the beginning but after 42 runs, it 
 appears the following warning :


 Error in seq.default(yli[1], yli[2], by = diff(xg[1:2])) :
  invalid (to - from)/by in seq(.)

 I looked at the coordinates, at the id, at the time of the run 43 and it's 
 all good...

 I looked on the net and it happened to only one person and there was no 
 answer to his post.

 I wonder if that posting (like yours)  had no data on which to display the 
 problem or to test potential solutions? I would think you would want to post 
 any setup objects and then data for items 40-45.


 Someone could help me?

 ## commands

 BBtraj - list()
 for (i in 1:(nrow(loc@data)-1)) {
 BBtraj[[i]] - kernelbb(as.ltraj(loc@coords[i:(i+1),], 
 date=loc@data$time[i:(i+1)], id = as.character(loc@data$id[i:(i+1)]),
 typeII = TRUE), sig1=as.numeric(as.character(loc@data$sig1[i])), sig2= 5, 
 grid = 1000)
 }

 --


 David Winsemius
 Alameda, CA, USA
 [[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.




-- 
Michael Sumner
Hobart, Australia
e-mail: mdsum...@gmail.com

__
R-help@r-project.org mailing list

[R] Heterogeneous negative binomial

2013-05-17 Thread Joseph Hilbe
I have seen several queries about parameterizing the negative binomial scale
parameter. This is called 

the heterogeneous negative binomial. I have written a function called
nbinomial which is in the 

msme package on CRAN. Type ?nbinomial to see the help file.  The default
model is a negative binomial 

for which the dispersion parameter is directly related to mu, which is how
Stata, SAS, SPSS, Limdep, and

so forth parameterize the negative binomial. The direct parameterization
make sense in that the more 

variation or correlation there is in a Poisson model,  the greater is the
value of the dispersion parameter 

which is adjusting for the excessive variation. With this parameterization
the dispersion parameter is 

directly related to both mu, as well as the dispersion statistic, or Pearson
Chi2/(residual DOF).  

A dispersion parameter of 0 is Poisson, which is equidispersed. When the
dispersion parameter for 

other mixture models such as generalized Poisson and Poisson inverse
Gaussian is zero, the models 

reduce to Poisson. 

 

I also provide an option so that the output is similar to glm.nb, for which
the dispersion parameter 

is indirectly related to the mean.  

 

I have also provided the abililty of nbinomial to parameterize the
dispersion parameter, providing 

Coefficients, SEs, CIs etc for the predictors of the dispersion, as there
are coefficients etc for the mean 

parameter. 

  The output look nearly identical to glm.nb, except that I also display a
summary of Pearson residuals, 

As well as the null and residual Pearson Chi2, and dispersion statistic.
The dispersion parameter is listed 

At the bottom of the table of coefficients, with SE, Z, p-value and
confidence intervals. You may select 

any variable(s) in the data to be a predictor(s) of the dispersion.
Predictors of the dispersion parameter, 

if positive and significant, indicate that they influence the extra
variability of diswhich likely have a bearn 

 

  I also provide a number of saved post-estimation statistics when nbinomial
is run, which the analyst 

may use in additional analysis. 

The function is one of a number of functions that are included in Hilbe and
Robinson, Methods of Statistical 

Model Estimation, Chapman   Hall/CRC, which is due to be published in the
next two weeks. The msme 

Package should be thought of as an adjunct package to the COUNT package,
which is on CRAN and provides 

the data sets, functions and a host of scripts for Hilbe, Negative Binomial
Regression, 2nd edition, Cambridge 

University Press (2011). 

 

Best, J. Hilbe

 



Joseph M. Hilbe, PhD

Emer Prof, Univ of Hawaii  Adj Prof of Statistics,  Arizona St Univ;

SSA Program, NASA/Jet Propulsion Laboratory, Caltech

President, International Astrostatistics Association

Coordinating editor, Cambridge Univ Press Series on Predictive Analytics 

 

Email: hi...@asu.edu  or jhi...@aol.com

URL: http://works.bepress.com/joseph_hilbe/

 


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