[R] problem in finding sizes of objects using a for loop

2012-10-25 Thread Purna chander
Dear All,

I wanted to extract the sizes of all created objects. For E.g when I
created 2 objects(x and y), I got their sizes using the following
code:

 x-rnorm(1)
 y-runif(100,min=40,max=1000)
 ls()
[1] x y
 object.size(x)
80024 bytes
 object.size(y)
824 bytes

However, I was unable to get their sizes when I used a for loop in the
following way:

 objects-ls()
 for (i in seq_along(objects)){
+   print(c(objects[i],object.size(objects[i])))
+
+ }
[1] x  64
[1] y  64


The result obtained by me is wrong in second case.

I understood that variables x and y are treated as characters. But to
rectify this problem.

Regards,
Purna

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 in finding sizes of objects using a for loop

2012-10-25 Thread Jorge I Velez
Dear Purna,

You need the get() function around object[i] in order to accomplish the
same results:

# data
x-rnorm(1)
y-runif(100,min=40,max=1000)

# sizes
objects-ls()
for (i in seq_along(objects)){
   print(c(objects[i],object.size(get(objects[i]  # get() is added here
 }
[1] x 80040
[1] y   840

get() is needed because each element of objects is a character and the
object.size() function does not operates on characters, but on objects (not
your variable, the definition in R).  See ?get and ?object.size for more
information.

HTH,
Jorge.-


On Thu, Oct 25, 2012 at 5:24 PM, Purna chander  wrote:

 Dear All,

 I wanted to extract the sizes of all created objects. For E.g when I
 created 2 objects(x and y), I got their sizes using the following
 code:

  x-rnorm(1)
  y-runif(100,min=40,max=1000)
  ls()
 [1] x y
  object.size(x)
 80024 bytes
  object.size(y)
 824 bytes

 However, I was unable to get their sizes when I used a for loop in the
 following way:

  objects-ls()
  for (i in seq_along(objects)){
 +   print(c(objects[i],object.size(objects[i])))
 +
 + }
 [1] x  64
 [1] y  64


 The result obtained by me is wrong in second case.

 I understood that variables x and y are treated as characters. But to
 rectify this problem.

 Regards,
 Purna

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

2012-10-25 Thread Tammy Ma

Dear R user,

I have been setting up the models for predicting the volume based on the price 
information of own product and competitive products. one option is to use 
instrumental variable to break price into two parts: one part that might be 
correlated with error term, and the another part that is not. 
But now I met the problem of choosing instumental variables. I have searched 
many papers. it has been mentioned that cost can be used as one instrumental 
variable for the price. yes. I can use cost for own price. but how about the 
competitive price's instrumental variables? I don't know their 
cost information at all except their price information and market share. I will 
be really appreciated if someone can suggest me the possible choices of 
instrumental variables for the competitive price?

Thanks in advance.

Kind regards,
Tammy
  
[[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] correlated events in time series

2012-10-25 Thread james.foadi
Apologies in advance for the basic nature of my question.
I've never worked with time series, but I am, at present, dealing
with evolution in time of certain scalar quantities.

By looking at the plots, scalar quantity vs time, for several of these
quantities, I am observing a correlation of events happening at specific,
non-regularly spaced instants of time. The fact of observing them in all
plots, to me means that they are due to some kind of objective physical
cause.

My question is: are there well known and effective methods in time series 
analysis
to extract such occurrences from multiple series? Is there any package in R 
that deals
with this?

Kind regards,

J

-- 
This e-mail and any attachments may contain confidential...{{dropped:8}}

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


Re: [R] Defining categories

2012-10-25 Thread PIKAL Petr
Hi

Maybe also findInterval can be used

dat1$cat-findInterval(dat1$V1, 1:6, rightmost.closed = T, all.inside = T)

It is said to be more efficient than cut.

Regards
Petr



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of arun
 Sent: Thursday, October 25, 2012 3:32 AM
 To: Jorge I Velez; bibek sharma
 Cc: R help
 Subject: Re: [R] Defining categories
 
 Hi,
  (Jorge: Thanks for the suggestion.)
 cut? will be much easier.
 
 dat1-read.table(text=
 2.880556
 0.616667
 5.08
 0.858333
 0.47
 2.936111
 4.258333
 0.258333
 2.03
 2.58
 1.09
 0.447222
 1.87
 0.080556
 4.03
 4.116667
 1.63
 2.147222
 ,sep=,header=FALSE)
  dat1$Categ-cut(dat1$V1,breaks=c(0,1,2,3,4,5,6))
 #Either
 
 library(car)
 dat1$Categ-
 recode(dat1$Categ,'(0,1]'=1;'(1,2]'=2;'(2,3]'=3;'(3,4]'=4;'(4,5]'=5;'(
 5,6]'=6)
 #or
 dat1$Categ-as.numeric(gsub(.*\\,(\\d+).*,\\1,dat1$Categ))
 #formats the Categ column.
 head(dat1)
 #    V1 Categ
 #1 2.880556 3
 #2 0.616667 1
 #3 5.08 6
 #4 0.858333 1
 #5 0.47 1
 #6 2.936111 3
 A.K.
 
 
 
 
 
 
 
 From: Jorge I Velez jorgeivanve...@gmail.com
 To: arun smartpink...@yahoo.com
 Cc: bibek sharma mbhpat...@gmail.com; R help r-help@r-project.org
 Sent: Wednesday, October 24, 2012 7:27 PM
 Subject: Re: [R] Defining categories
 
 
 See ?cut for a simpler way of doing this.
 HTH,
 Jorge.-
 
 
 
 On Thu, Oct 25, 2012 at 10:02 AM, arun  wrote:
 
 Hi,
 May be this:
 dat1-read.table(text=
 
 2.880556
 0.616667
 5.08
 0.858333
 0.47
 2.936111
 4.258333
 0.258333
 2.03
 2.58
 1.09
 0.447222
 1.87
 0.080556
 4.03
 4.116667
 1.63
 2.147222
 ,sep=,header=FALSE)
 dat1$category-ifelse(dat1$V1=1 dat1$V10,1,ifelse(dat1$V11 
 dat1$V1=2,2,ifelse(dat1$V12dat1$V1=3,3,ifelse(dat1$V13dat1$V1=4,
 4,ifelse(dat1$V14dat1$V1=5,5,6)
 
 
  head(dat1)
 #    V1 category
 #1 2.880556    3
 #2 0.616667    1
 #3 5.08    6
 #4 0.858333    1
 #5 0.47    1
 #6 2.936111    3
 A.K.
 
 
 
 
 - Original Message -
 From: bibek sharma 
 To: r-help@r-project.org
 Cc:
 Sent: Wednesday, October 24, 2012 6:52 PM
 Subject: [R] Defining categories
 
 Hello R user,
 
 Data below represent year in decimal. I would like to catagorize it
 in such a way that any valye [0,1] goes to catagory 1 , (1,2] goes to
 catagory 2 and so on..
 Any suggestion how it can be done with if else statement or any other
 way?
 
 2.880556
 0.616667
 5.08
 0.858333
 0.47
 2.936111
 4.258333
 0.258333
 2.03
 2.58
 1.09
 0.447222
 1.87
 0.080556
 4.03
 4.116667
 1.63
 2.147222
 
 Thank you for  your help.
 Bibek
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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

2012-10-25 Thread Purna chander
Dear All,


My main objective was to compute the distance of 10 vectors from a
set having 900 other vectors. I've a file named seq_vec containing
10 records and 256 columns.
While computing, the memory was not sufficient and resulted in error
cannot allocate vector of size 152.1Mb

So I've approached the problem in the following:
Rather than reading the data completely at a time, I read the data in
chunks of 2 records using scan() function. After reading each
chunk, I've computed distance of each of these vectors with a set of
another vectors.

Even though I was successful in computing the distances for first 3
chunks, I obtained similar error (cannot allocate vector of size
102.3Mb).

Q) Here what I could not understand is, how come memory become
insufficient when dealing with 4th chunk?
Q) Suppose if i computed a matrix 'm' during calculation associated
with chunk1, then is this matrix not replaced when I again compute 'm'
when dealing with chunk 2?


Regards,
Purna

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


Re: [R] Defining categories

2012-10-25 Thread Jorge I Velez
Thank you Dr. Pikal for this alternative.
Best,
Jorge.-

Sent from my phone. Please excuse my brevity and misspelling.

On Oct 25, 2012, at 8:29 PM, PIKAL Petr petr.pi...@precheza.cz wrote:

 Hi

 Maybe also findInterval can be used

 dat1$cat-findInterval(dat1$V1, 1:6, rightmost.closed = T, all.inside = T)

 It is said to be more efficient than cut.

 Regards
 Petr



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of arun
 Sent: Thursday, October 25, 2012 3:32 AM
 To: Jorge I Velez; bibek sharma
 Cc: R help
 Subject: Re: [R] Defining categories

 Hi,
  (Jorge: Thanks for the suggestion.)
 cut? will be much easier.

 dat1-read.table(text=
 2.880556
 0.616667
 5.08
 0.858333
 0.47
 2.936111
 4.258333
 0.258333
 2.03
 2.58
 1.09
 0.447222
 1.87
 0.080556
 4.03
 4.116667
 1.63
 2.147222
 ,sep=,header=FALSE)
  dat1$Categ-cut(dat1$V1,breaks=c(0,1,2,3,4,5,6))
 #Either

 library(car)
 dat1$Categ-
 recode(dat1$Categ,'(0,1]'=1;'(1,2]'=2;'(2,3]'=3;'(3,4]'=4;'(4,5]'=5;'(
 5,6]'=6)
 #or
 dat1$Categ-as.numeric(gsub(.*\\,(\\d+).*,\\1,dat1$Categ))
 #formats the Categ column.
 head(dat1)
 #V1 Categ
 #1 2.880556 3
 #2 0.616667 1
 #3 5.08 6
 #4 0.858333 1
 #5 0.47 1
 #6 2.936111 3
 A.K.






 
 From: Jorge I Velez jorgeivanve...@gmail.com
 To: arun smartpink...@yahoo.com
 Cc: bibek sharma mbhpat...@gmail.com; R help r-help@r-project.org
 Sent: Wednesday, October 24, 2012 7:27 PM
 Subject: Re: [R] Defining categories


 See ?cut for a simpler way of doing this.
 HTH,
 Jorge.-



 On Thu, Oct 25, 2012 at 10:02 AM, arun  wrote:

 Hi,
 May be this:
 dat1-read.table(text=

 2.880556
 0.616667
 5.08
 0.858333
 0.47
 2.936111
 4.258333
 0.258333
 2.03
 2.58
 1.09
 0.447222
 1.87
 0.080556
 4.03
 4.116667
 1.63
 2.147222
 ,sep=,header=FALSE)
 dat1$category-ifelse(dat1$V1=1 dat1$V10,1,ifelse(dat1$V11 
 dat1$V1=2,2,ifelse(dat1$V12dat1$V1=3,3,ifelse(dat1$V13dat1$V1=4,
 4,ifelse(dat1$V14dat1$V1=5,5,6)


  head(dat1)
 #V1 category
 #1 2.8805563
 #2 0.6166671
 #3 5.086
 #4 0.8583331
 #5 0.471
 #6 2.9361113
 A.K.




 - Original Message -
 From: bibek sharma 
 To: r-help@r-project.org
 Cc:
 Sent: Wednesday, October 24, 2012 6:52 PM
 Subject: [R] Defining categories

 Hello R user,

 Data below represent year in decimal. I would like to catagorize it
 in such a way that any valye [0,1] goes to catagory 1 , (1,2] goes to
 catagory 2 and so on..
 Any suggestion how it can be done with if else statement or any other
 way?

 2.880556
 0.616667
 5.08
 0.858333
 0.47
 2.936111
 4.258333
 0.258333
 2.03
 2.58
 1.09
 0.447222
 1.87
 0.080556
 4.03
 4.116667
 1.63
 2.147222

 Thank you for  your help.
 Bibek

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


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

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

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


Re: [R] correlated events in time series

2012-10-25 Thread Michael Weylandt
Yes, but you'll need to learn vector (multivariate) time series methods. See, 
perhaps firstly, B Pfaff's book and corresponding R packages. It's dense, but 
not too long and will get you going the right way. Terms like VAR and VECM will 
help guide your googling

Michael 

On Oct 25, 2012, at 8:34 AM, james.fo...@diamond.ac.uk wrote:

 Apologies in advance for the basic nature of my question.
 I've never worked with time series, but I am, at present, dealing
 with evolution in time of certain scalar quantities.
 
 By looking at the plots, scalar quantity vs time, for several of these
 quantities, I am observing a correlation of events happening at specific,
 non-regularly spaced instants of time. The fact of observing them in all
 plots, to me means that they are due to some kind of objective physical
 cause.
 
 My question is: are there well known and effective methods in time series 
 analysis
 to extract such occurrences from multiple series? Is there any package in R 
 that deals
 with this?
 
 Kind regards,
 
 J
 
 -- 
 This e-mail and any attachments may contain confidential...{{dropped:8}}
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] cut point in ROC

2012-10-25 Thread Soheila Khodakarim
var1

var2

var3

var4

var5

var6

var7

var8

var9

var10

gold

2

3

1

2

4

0

1

4

4

3

2

2

4

2

4

3

4

2

4

4

4

2

3

3

0

0

4

1

0

2

4

4

2

1

4

0

3

2

0

0

2

4

4

2

3

4

0

2

2

0

0

0

3

4

2

2

2

3

2

2

0

0

0

2

4

2

2

4

1

1

2

0

0

3

3

3

2

3

4

1

4

0

0

0

0

3

4

2

3

1

0

2

2

1

0

2

3

3

2

0

3

1

1

1

1

2

1

2

3

2

1

1

0

1

0

0

0

0

1

2

1

1

1

0

0

0

0

0

0

2

2

1

1

2

0

0

0

0

0

0

2

1

1

1

1

0

0

0

0

0

0

2

2

1

0

1

1

0

1

0

0

0

0

3

1

1

2

0

1

0

0

0

0

1

1

1

1

2

1

0

0

0

0

0

1

1

1

1

2

0

1

0

0

0

0

1

0

1

0

0

0

0

1

0

0

0

2

2

1

0

2

0

1

0

0

0

0

1

2

1



Dear All

I try to find a diagnosis test instead of the gold standard.

The gold standard is based on 10 vars.

Now, I try to find a new test based on several vars.

For example, based on 3 or 4 vars.

There are a lot of choices to test, I am confused.

I will be happy if you guide me.

Best Regards,

Soheila

[[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] Changing radii line type in radial plots

2012-10-25 Thread Jim Lemon

On 10/25/2012 05:06 AM, bwone wrote:

I am using the package plotrix radial.plot(). Yes, radial.plot() has a line
type argument, lty, but that is for the polygons or the radial lines, not
the radii or axes of the radial plot.unless I am doing something wrong.


Hi bwone,
No, there is no way to change the line type of the grid in radial.plot 
at the moment. If you need to have different line types, you could 
change two lines in the function:


polygon(xpos,ypos,border=grid.col,col=grid.bg)
to
polygon(xpos,ypos,border=grid.col,col=grid.bg,lty=my.lty)

if(show.radial.grid) segments(0,0,xpos,ypos,col=grid.col)
to
if(show.radial.grid) segments(0,0,xpos,ypos,col=grid.col,lty=my.lty)

I might be persuaded to add yet another argument to the function if 
anyone else wants different line types.


Jim

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


Re: [R] [r] How to pick colums from a ragged array?

2012-10-25 Thread PIKAL Petr
Sorry, forgot to cc to rhelp

Petr


 -Original Message-
 From: PIKAL Petr
 Sent: Thursday, October 25, 2012 11:19 AM
 To: 'Stuart Leask'; arun (smartpink...@yahoo.com)
 Subject: RE: [r] How to pick colums from a ragged array?
 
 Hi
 
 If I understand correctly you now want only to identify rows for which
 for a given ID, two or more first or last DATEs are same but DG is
 different and put TRUE/FALSE to new column
 
 fff-function(data) {
 
 data$Identify - FALSE
 
 testfirst - function(x) (x[1,DATE]==x[2,DATE]) 
 (x[1,DG]!=x[2,DG]) testlast - function(x) {
 (x[nrow(x),DATE]==x[nrow(x)-1,DATE])  (x[nrow(x),DG]!=x[nrow(x)-
 1,DG])
 }
 
 
 sel - as.numeric(names(which(unlist(sapply(split(data,data[,1]),
 testfirst)
 
 sel - c(sel, as.numeric(names(which(unlist(sapply(split(data,
 data[,1]), testlast))
 
 data[data[,1] %in% sel,Identify] - TRUE data }
 
 I slightly modified my code to get rid of necessary user selection of
 first or last variant and put both together, add a new column and
 extended testing functions to evaluate DG and look if they are the same
 or different.
 
 Does it suit to your purpose?
 
 Regards
 Petr
 
 
 
  -Original Message-
  From: Stuart Leask [mailto:stuart.le...@nottingham.ac.uk]
  Sent: Wednesday, October 24, 2012 5:25 PM
  To: arun (smartpink...@yahoo.com); PIKAL Petr; Rui Barradas
  (ruipbarra...@sapo.pt)
  Subject: RE: [r] How to pick colums from a ragged array?
 
  Arun, Petr, Rui, many thanks for your help, and the functions you
 have
  written.
 
  You'll recall I wanted to remove these first (or last) duplicates,
  because they represented instances where two different diagnoses (in
  this case, variable DG, value 1, 2, 3, 4 or 5) had been recorded on
  the same day - so I can't say which was 'first' (or 'last').
 
  Your functions have revealed something I wasn't expecting: In some
  cases, the diagnoses recorded on the duplicated DATEs are the same!
  This is a surprise to me, but probably reflects someone going to two
  different departments in a clinic, and both departments submit data.
 I
  have to say that crazy things like this are often a feature of real
  data, which I'm sure you've come across yourselves.
 
  Of course, I don't want to remove records in which I can determine an
  unambiguous 'first diagnosis'.
 
  You have all put in so much effort on my behalf, I'm ashamed to ask,
  but I wonder if any of the functions you've written could do this
 with
  a little more Indexing and the 'duplicate' function So the function
  should only exclude an ID, having identified a first (or last) DATE
  duplicate, the DGs for these two dates are different.
 
  Test dataset:
 
  ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323
  ,547,794,814,814,814,814,814,814,841,841,841,841,841
  ,841,841,841,841,910,910,910,910,910,910,999,1019,1019
  ,1019)
 
  DATE -
   c(20060821,20061207,20080102,20090904,20040205,20040205,2005
   ,20060111,20071119,20080107,20080407,20080521,20080521,20041005
   ,20070905,20020814,20021125,20040429,20040429,20071205,20071205
   ,20050421,20050421,20060428,20060602,20060816,20061025,20061129
   ,20070112,20070514, 19870508,20040205,20040205, 20080521,20080521
   ,20091224,20050503,19870508,19870508,19880330)
 
  DG-
 
 c(1,2,1,1,4,4,3,2,3,2,1,2,3,2,1,2,2,2,2,2,2,1,2,1,1,1,1,1,1,4,3,3,3,4,
  3
  ,2,2,2,1,1)
 
  id.d-data.frame(ID,DATE,DG)
  id.d
 
  # Considering Ruis  getRepeat function:
 
  g.r-getRepeat(id.d)# defaults to first = TRUE getRepeat(id.d,
  first = FALSE)  to get the last ones
  g.rr-do.call(rbind, g.r) # put the data into a matrix
 
  # I can remove the date duplicates with:
  g.rr[rep(!duplicated(g.rr)[(1:(dim(g.rr)[1]/2))*2],each=2),]
 
  I'm not sure how to add this to your suggestions, Arun  Petr...
 
 
  Stuart
 
 
  -Original Message-
  From: PIKAL Petr [mailto:petr.pi...@precheza.cz]
  Sent: 23 October 2012 15:24
  To: Stuart Leask
  Subject: RE: [r] How to pick colums from a ragged array?
 
  Hi
 
  I assumed that id.d is data frame
 
  id.d - data.frame (ID,DATE )
 
  and
 
  fff(id.d)
 
  works for me
 
  Petr
 
 
   -Original Message-
   From: Stuart Leask [mailto:stuart.le...@nottingham.ac.uk]
   Sent: Tuesday, October 23, 2012 3:13 PM
   To: PIKAL Petr
   Subject: RE: [r] How to pick colums from a ragged array?
  
   Hi Petr.
   I see what you mean it should do, but when I run it I get an error
   (see below).
   Stuart
  
  
ID - c(58,58,58,58,167,167,323,323,323,323,323,323,323
   + ,547,794,814,814,814,814,814,814,841,841,841,841,841
   + ,841,841,841,841,910,910,910,910,910,910,999,1019,1019
   + ,1019)
   
DATE -
   +  c(20060821,20061207,20080102,20090904,20040205,20040205,2005
   +  ,20060111,20071119,20080107,20080407,20080521,20080711,20041005
   +  ,20070905,20020814,20021125,20040429,20040429,20071205,20080227
   +  ,20050421,20050421,20060428,20060602,20060816,20061025,20061129
   +  ,20070112,20070514, 19870508,20040205,20040205,
 

Re: [R] How to quit R script return to R prompt

2012-10-25 Thread Bart Joosen
you can see it goes wrong at:
 barplot(xtab(`profits,data=Forbes2000)) 

You typed a ` without closing it:
barplot(xtab(`profits`,data=Forbes2000)) 

anyway: pushing the escape button should also return you to the R-prompt (at
least on a Windows platform)






--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-quit-R-script-return-to-R-prompt-tp4647376p4647382.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] Expression in legend of plot

2012-10-25 Thread stat.kk
I would like to have an expression f^(-1)(x) in a legend of plot. For this I
used expression(f^{-1}(x)), but  variable is always in exponent. How could I
change it in order to (x) be in a line, not in exponent?
Thank you for your responses!



--
View this message in context: 
http://r.789695.n4.nabble.com/Expression-in-legend-of-plot-tp4647393.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] How to quit R script return to R prompt

2012-10-25 Thread amiteshtiwari18
Hi 
can you please tell me how to quit R script  return to R prompt.
As i tried following but still cannot able to return on to R prompt..

R barplot(Forbes2000$profits)
R barplot(xtab(`profits,data=Forbes2000))
+ barplot(xtab(~profits,data=Forbes2000))
+ )
+ Q()
+ ?barplots
+ 
+ 
+ 
+ 
+ barplot?
+ ?
+ ??
+ 
+ stop()
+ exit()
+ 
+ 
+ ctrl+c
+ q()
+ 
I'm beginner in R  trying to learn

Thanks  Regards

Amitesh



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-quit-R-script-return-to-R-prompt-tp4647376.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] parallel processing with foreach

2012-10-25 Thread pxs101220
Hi,

I am trying to  parallel computing with foreach function, but not able to
get the result. I know that in parallel processing, all result is collected
in list format, but I am not able to get input there.
Any help is really appreciated.


esf.m -foreach (i = 1:n.s, .combine=rbind) %dopar%  {
  EV - as.data.frame(eig$vectors[,1:n.candid[i]])
  colnames(EV) - paste(EV, 1:NCOL(EV), sep=)

  r25.esf.f - lm(y ~ x1 + x2 +., data = EV)
  assign(paste(r25.esf., i, sep=), stepwise.forward(r25.esf.f, lm(y ~ x1
+ x2, data = EV), 0.1, verbose = F))}



--
View this message in context: 
http://r.789695.n4.nabble.com/parallel-processing-with-foreach-tp4647381.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] equation solver

2012-10-25 Thread pina
Dear Berend,

Many thanks for the advice. I'll try to work with these packages and I hope
to find a solution.

again, many thanks

Pina.



--
View this message in context: 
http://r.789695.n4.nabble.com/equation-solver-tp4647287p4647388.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] [r] How to pick colums from a ragged array?

2012-10-25 Thread arun
Hi Stuart,

So, I guess my result (below) serves the purpose!
A.K.




- Original Message -
From: Stuart Leask stuart.le...@nottingham.ac.uk
To: arun smartpink...@yahoo.com
Cc: 
Sent: Thursday, October 25, 2012 3:13 AM
Subject: RE: [r] How to pick colums from a ragged array?

Even confusing myself now, serves me right for replying late at night!

** If DGs are the same, then the first (or last) diagnosis is unambiguous even 
if date is duplicated - so I can use the data.**

Consider we want INCLUDE.FIRST to look at first dates.
Duplicate dates: 167, 323,814, 841, 910 1019
AND This dup is the first date: 167, 841, 1019
AND This dup has different DGs: 841 1019
= give all rows of 841 and 1019  FALSE.
(All other rows TRUE)

Now consider we want INCLUDE.LAST to look at last dates.
Duplicate dates: 167, 323,814, 841, 910 1019
AND This dup is the last date: 167, 323, 814
AND This dup has different DGs: 323
= give all rows of 323 FALSE.
(All others TRUE)

Of course, I'm happy to run a function twice, either one with a 'first/last' 
switch, or one that
assumes initial order of sort by DATE determines whether you end up with first 
or last date duplicates.



-Original Message-
From: arun [mailto:smartpink...@yahoo.com]
Sent: 24 October 2012 22:59
To: Stuart Leask
Subject: Re: [r] How to pick colums from a ragged array?

Hi Stuart,
So, 167 should be FALSE eventhough DG is same because it comes under 
earliest/first date, but TRUE for 814 because it comes under latest/last date.  
167 comes under both cases.
Let me try to make sense of that:

I am just pasting my earlier solution and its results again to see whether we 
are on the same page:
res1- data.frame(flag=tapply(id.d[,2],id.d[,1],FUN=function(x) 
head(duplicated(x)|duplicated(x,fromLast=TRUE),1)|tail(duplicated(x)|duplicated(x,fromLast=TRUE),1)))
res2-id.d[id.d[,1]%in%names(res1[res1$flag==TRUE,])(duplicated(id.d[,1:2])|duplicated(id.d[,1:2],fromLast=TRUE)),]
res3-res2[!res2$ID%in% 
res2[duplicated(res2)|duplicated(res2,fromLast=TRUE),]$ID,]
id.d1-id.d
bad-id.d1[id.d1$ID%in%res3$ID,]
bad$INCLUDE-FALSE
res4-merge(id.d1,bad,all=TRUE)
res4$INCLUDE[is.na(res4$INCLUDE)]-TRUE
res4
     ID     DATE DG INCLUDE
1    58 20060821  1    TRUE
2    58 20061207  2    TRUE
3    58 20080102  1    TRUE
4    58 20090904  1    TRUE
5   167 20040205  4    TRUE
6   167 20040205  4    TRUE
7   323 2005  3   FALSE
8   323 20060111  2   FALSE
9   323 20071119  3   FALSE
10  323 20080107  2   FALSE
11  323 20080407  1   FALSE
12  323 20080521  2   FALSE
13  323 20080521  3   FALSE
14  547 20041005  2    TRUE
15  794 20070905  1    TRUE
16  814 20020814  2    TRUE
17  814 20021125  2    TRUE
18  814 20040429  2    TRUE
19  814 20040429  2    TRUE
20  814 20071205  2    TRUE
21  814 20071205  2    TRUE
22  841 20050421  1   FALSE
23  841 20050421  2   FALSE
24  841 20060428  1   FALSE
25  841 20060602  1   FALSE
26  841 20060816  1   FALSE
27  841 20061025  1   FALSE
28  841 20061129  1   FALSE
29  841 20070112  1   FALSE
30  841 20070514  4   FALSE
31  910 19870508  3    TRUE
32  910 20040205  3    TRUE
33  910 20040205  3    TRUE
34  910 20080521  3    TRUE
35  910 20080521  4    TRUE
36  910 20091224  2    TRUE
37  999 20050503  2    TRUE
38 1019 19870508  1   FALSE
39 1019 19870508  2   FALSE
40 1019 19880330  1   FALSE
A.K.





- Original Message -
From: Stuart Leask stuart.le...@nottingham.ac.uk
To: arun smartpink...@yahoo.com; Rui Barradas ruipbarra...@sapo.pt
Cc: R help r-help@r-project.org
Sent: Wednesday, October 24, 2012 5:40 PM
Subject: RE: [r] How to pick colums from a ragged array?

I mis-typed, missing an if. I think you've got it, but let me try again:

The function should:
-  put FALSE in a column for every instance of an ID IF ( that ID has a first 
(or last) DATE duplicated ) AND IF (the DGs for the duplicated dates are 
different).

So for the earliest/first date function, INCLUDE should be TRUE, apart from 
FALSE for _all_ the instances of IDs 167, 841 and 1019 For the latest/last date 
function, INCLUDE should be TRUE, apart from FALSE for all the instances of ID  
323.

Stuart

-Original Message-
From: arun [mailto:smartpink...@yahoo.com]
Sent: 24 October 2012 21:30
To: Rui Barradas
Cc: R help; Stuart Leask
Subject: Re: [r] How to pick colums from a ragged array?

Hi,

According to the OP So the function should only exclude an ID, having 
identified a first (or last) DATE duplicate, the DGs for these two dates are 
different.
Rui:
By running your modified function (using dte - tapply(x[,2], x[,1], FUN = 
function(x) duplicated(fun(x, 2),fromLast = TRUE))),

id.d$INCLUDE - !(rm1 | rm2)
head(id.d)
#     ID     DATE DG INCLUDE
#1    58 20060821  1    TRUE
#2    58 20061207  2    TRUE
#3    58 20080102  1    TRUE
#4    58 20090904  1    TRUE
#5   167 20040205  4   FALSE
#6   167 20040205  4   FALSE

For #167, DGs are same.  Not sure whether to exclude it or not.


My modified solution is similar but I am excluding 167 and 814.



Re: [R] Expression in legend of plot

2012-10-25 Thread Rui Barradas

Hello,

Use an asterisk to put a space between the exponent an (x).

plot(1, main =  expression(f^{-1}*(x)))

Hope this helps,

Rui Barradas
Em 25-10-2012 12:21, stat.kk escreveu:

I would like to have an expression f^(-1)(x) in a legend of plot. For this I
used expression(f^{-1}(x)), but  variable is always in exponent. How could I
change it in order to (x) be in a line, not in exponent?
Thank you for your responses!



--
View this message in context: 
http://r.789695.n4.nabble.com/Expression-in-legend-of-plot-tp4647393.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] Defining categories

2012-10-25 Thread arun
HI Petr,

Thanks for sharing the function.  True, very efficient than cut.

dat1$cat-findInterval(dat1$V1, 1:6, rightmost.closed = T, all.inside = T)
  ^^^
 #  May be the interval is 0:6.
dat1$cat1-findInterval(dat1$V1, 1:6, rightmost.closed = T, all.inside = T)
 dat1$cat2-findInterval(dat1$V1, 0:6, rightmost.closed = T, all.inside = T)
 head(dat1)
#    V1 cat1 cat2
#1 2.880556    2    3
#2 0.616667    1    1
#3 5.08    5    6
#4 0.858333    1    1
#5 0.47    1    1
#6 2.936111    2    3
A.K.




- Original Message -
From: PIKAL Petr petr.pi...@precheza.cz
To: arun smartpink...@yahoo.com; Jorge I Velez jorgeivanve...@gmail.com; 
bibek sharma mbhpat...@gmail.com
Cc: R help r-help@r-project.org
Sent: Thursday, October 25, 2012 5:29 AM
Subject: RE: [R] Defining categories

Hi

Maybe also findInterval can be used

dat1$cat-findInterval(dat1$V1, 1:6, rightmost.closed = T, all.inside = T)

It is said to be more efficient than cut.

Regards
Petr



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of arun
 Sent: Thursday, October 25, 2012 3:32 AM
 To: Jorge I Velez; bibek sharma
 Cc: R help
 Subject: Re: [R] Defining categories
 
 Hi,
  (Jorge: Thanks for the suggestion.)
 cut? will be much easier.
 
 dat1-read.table(text=
 2.880556
 0.616667
 5.08
 0.858333
 0.47
 2.936111
 4.258333
 0.258333
 2.03
 2.58
 1.09
 0.447222
 1.87
 0.080556
 4.03
 4.116667
 1.63
 2.147222
 ,sep=,header=FALSE)
  dat1$Categ-cut(dat1$V1,breaks=c(0,1,2,3,4,5,6))
 #Either
 
 library(car)
 dat1$Categ-
 recode(dat1$Categ,'(0,1]'=1;'(1,2]'=2;'(2,3]'=3;'(3,4]'=4;'(4,5]'=5;'(
 5,6]'=6)
 #or
 dat1$Categ-as.numeric(gsub(.*\\,(\\d+).*,\\1,dat1$Categ))
 #formats the Categ column.
 head(dat1)
 #    V1 Categ
 #1 2.880556 3
 #2 0.616667 1
 #3 5.08 6
 #4 0.858333 1
 #5 0.47 1
 #6 2.936111 3
 A.K.
 
 
 
 
 
 
 
 From: Jorge I Velez jorgeivanve...@gmail.com
 To: arun smartpink...@yahoo.com
 Cc: bibek sharma mbhpat...@gmail.com; R help r-help@r-project.org
 Sent: Wednesday, October 24, 2012 7:27 PM
 Subject: Re: [R] Defining categories
 
 
 See ?cut for a simpler way of doing this.
 HTH,
 Jorge.-
 
 
 
 On Thu, Oct 25, 2012 at 10:02 AM, arun  wrote:
 
 Hi,
 May be this:
 dat1-read.table(text=
 
 2.880556
 0.616667
 5.08
 0.858333
 0.47
 2.936111
 4.258333
 0.258333
 2.03
 2.58
 1.09
 0.447222
 1.87
 0.080556
 4.03
 4.116667
 1.63
 2.147222
 ,sep=,header=FALSE)
 dat1$category-ifelse(dat1$V1=1 dat1$V10,1,ifelse(dat1$V11 
 dat1$V1=2,2,ifelse(dat1$V12dat1$V1=3,3,ifelse(dat1$V13dat1$V1=4,
 4,ifelse(dat1$V14dat1$V1=5,5,6)
 
 
  head(dat1)
 #    V1 category
 #1 2.880556    3
 #2 0.616667    1
 #3 5.08    6
 #4 0.858333    1
 #5 0.47    1
 #6 2.936111    3
 A.K.
 
 
 
 
 - Original Message -
 From: bibek sharma 
 To: r-help@r-project.org
 Cc:
 Sent: Wednesday, October 24, 2012 6:52 PM
 Subject: [R] Defining categories
 
 Hello R user,
 
 Data below represent year in decimal. I would like to catagorize it
 in such a way that any valye [0,1] goes to catagory 1 , (1,2] goes to
 catagory 2 and so on..
 Any suggestion how it can be done with if else statement or any other
 way?
 
 2.880556
 0.616667
 5.08
 0.858333
 0.47
 2.936111
 4.258333
 0.258333
 2.03
 2.58
 1.09
 0.447222
 1.87
 0.080556
 4.03
 4.116667
 1.63
 2.147222
 
 Thank you for  your help.
 Bibek
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.


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


Re: [R] List of multidimensional arrays

2012-10-25 Thread Loukia Spineli
x and y are the frequencies of missing participants in the intervention and
the control treatment respectively! vector t contains the code of the
interventions (we have 11 interventions). I re-attach the PDF with some
small modifications. I am trying to create a list, where each list element
is a vector of different length arrays that contain 2by2 matrices. To be
more specific there are 11 treatments that are compared with placebo (we
have 11 comparisons) and each comparison is studied by a different number
of trials and each trial has a different number of missing participants in
both arms. The length of the list is equal to the number of comparisons. In
each comparison the number of arrays is equal to the number of trials that
study this comparison. For instance 4 trials compare PAR with placebo. So,
for this comparison we have 4 arrays and each array has a length equal to
the producy of the number of participants in each arm. These arrays contain
2x2 matrices.

I have attached a document with the data and the code. I cannot create the
list results the way I have described above. It creates only the  matrices
for the first array (that has length equal to 135) of the first comparison
leaving the rest 10 comparisons NULL.

On Wed, Oct 24, 2012 at 5:17 PM, Richard M. Heiberger r...@temple.eduwrote:

 I am looking at your pdf file.

 it doesn't match your description.

 There are no missing values in the vectors
 x, y, t.
 Each vector has length 55 which is not a multiple of 4,
 so we don't know where the 2x2 matrices come from.

 The code doesn't run.  There are are too many }.
 PDF files are formatted and are not ascii.

 Please send your code in ascii text in the body of the email.
 Please pick it up from your email and paste it into
 a fresh R session to be sure that it works.

 Perhaps consrtruct manually an example of what you want the answer to look
 like.

 Rich



 On Wed, Oct 24, 2012 at 3:51 AM, Loukia Spineli spinelilouki...@gmail.com
  wrote:

 Dear all,

 I am trying to create a list, where each list element is a vector of
 different length arrays that contain 2by2 matrices. To be more specific
 there are 11 treatments that are compared with placebo (we have 11
 comparisons) and each comparison is studied by a different number of
 trials
 and each trial has a different number of missing participants in both
 arms.
 The length of the list is equal to the number of comparisons. In each
 comparison the number of arrays is equal to the number of trials that
 study
 this comparison. For instance 4 trials compare PAR with placebo. So, for
 this comparison we have 4 arrays and each array has a length equal to the
 producy of the number of participants in each arm. These arrays contain
 2x2
 matrices.

 I have attached a document with the data and the code. I cannot create the
 list results the way I have described above. It creates only the  matrices
 for the first array (that has length equal to 135) of the first comparison
 leaving the rest 10 comparisons NULL.
 Any suggestion would be  really helpful

 Thank you in advance,
 Loukia

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





List of multidimensional arrays.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] Kaplan Meier Post Hoc?

2012-10-25 Thread Terry Therneau
No, you didn't miss anything in the survival package.  I've never found post-hoc tests 
interesting so have little motivation to add such (and a very long to do list of things 
I would like to add).


If you simply must have them, why not do all pairwise tests?

chisq - matrix(0., 4,4)
for (i in 1:4) {
for (j in (1:4)[-i]) {
 temp - survdiff(Surv(time, status) ~ group, data=mydata,
 subset=(group %in% (unique(group))[c(i,j)]))
 chisq[i,j] - temp$chisq
 }
}

Terry Therneau

On 10/25/2012 05:00 AM, r-help-requ...@r-project.org wrote:

This is more of a general question without data.  After doing 'survdiff',
from the 'survival' package, on strata including four groups (so 4 curves
on a Kaplan Meier curve) you get a chi squared p-value whether to reject
the null hypothesis or not.  Is there a method to followup with pairwise
testing on the respective groups?  I have searched the library but have
come up with nothing.  Perhaps I am mistaken in something here.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 in finding sizes of objects using a for loop

2012-10-25 Thread arun
Hi,
 You can also use lapply() or sapply() without the get() function.

 list1-list(x=x,y=y)
 sapply(list1,object.size)
#    x y 
#80040   840 
 do.call(rbind,lapply(list1,object.size))
  # [,1]
#x 80040
#y   840

A.K.







- Original Message -
From: Jorge I Velez jorgeivanve...@gmail.com
To: Purna chander chander...@gmail.com
Cc: r-help r-help@r-project.org
Sent: Thursday, October 25, 2012 2:40 AM
Subject: Re: [R] problem in finding sizes of objects using a for loop

Dear Purna,

You need the get() function around object[i] in order to accomplish the
same results:

# data
x-rnorm(1)
y-runif(100,min=40,max=1000)

# sizes
objects-ls()
for (i in seq_along(objects)){
   print(c(objects[i],object.size(get(objects[i]  # get() is added here
}
[1] x     80040
[1] y   840

get() is needed because each element of objects is a character and the
object.size() function does not operates on characters, but on objects (not
your variable, the definition in R).  See ?get and ?object.size for more
information.

HTH,
Jorge.-


On Thu, Oct 25, 2012 at 5:24 PM, Purna chander  wrote:

 Dear All,

 I wanted to extract the sizes of all created objects. For E.g when I
 created 2 objects(x and y), I got their sizes using the following
 code:

  x-rnorm(1)
  y-runif(100,min=40,max=1000)
  ls()
 [1] x y
  object.size(x)
 80024 bytes
  object.size(y)
 824 bytes

 However, I was unable to get their sizes when I used a for loop in the
 following way:

  objects-ls()
  for (i in seq_along(objects)){
 +   print(c(objects[i],object.size(objects[i])))
 +
 + }
 [1] x  64
 [1] y  64


 The result obtained by me is wrong in second case.

 I understood that variables x and y are treated as characters. But to
 rectify this problem.

 Regards,
 Purna

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


    [[alternative HTML version deleted]]

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


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


Re: [R] Expression in legend of plot

2012-10-25 Thread Bert Gunter
... and note that the { ,} are unnecessary:

 plot(1, main =  bquote(f^-1*(x)))

-- Bert

On Thu, Oct 25, 2012 at 4:32 AM, Rui Barradas ruipbarra...@sapo.pt wrote:
 Hello,

 Use an asterisk to put a space between the exponent an (x).

 plot(1, main =  expression(f^{-1}*(x)))

 Hope this helps,

 Rui Barradas
 Em 25-10-2012 12:21, stat.kk escreveu:

 I would like to have an expression f^(-1)(x) in a legend of plot. For this
 I
 used expression(f^{-1}(x)), but  variable is always in exponent. How could
 I
 change it in order to (x) be in a line, not in exponent?
 Thank you for your responses!



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Expression-in-legend-of-plot-tp4647393.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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] bugs and misfeatures in polr(MASS).... fixed!

2012-10-25 Thread tjb
This could well be out of date because I have not paid any attention to the
official POLR code in a year or more. Attached is fixed-polr.R.

cheers,
Tim

On Wed, Oct 24, 2012 at 10:38 PM, ahs [via R] 
ml-node+s789695n4647311...@n4.nabble.com wrote:

 Great!
 You can skip my question about s0 though, I found where it is being used,
 but I still struggle with the code and convergence problem.

 I also found something here
 http://biostat.mc.vanderbilt.edu/wiki/pub/Main/CharlesDupontStuff/newPolr.R
 that seems like someone tried to fix it, but with this code I get mu
 starting values out of range, nor do I get it right when I try to force
 starting values.

 If you got your code to work fine, you might have the answer to my
 problem. If you want, maybe you could post your whole *fixed-polr.R*? :-)



 I also can't see where the new object s0 is used in the old code?

 --
  If you reply to this email, your message will be added to the discussion
 below:

 http://r.789695.n4.nabble.com/bugs-and-misfeatures-in-polr-MASS-fixed-tp3024677p4647311.html
  To unsubscribe from bugs and misfeatures in polr(MASS) fixed!, click
 herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=3024677code=dGltb3RoeS5iZW5oYW1AdXFjb25uZWN0LmVkdS5hdXwzMDI0Njc3fDE5NTE2NDMxMjk=
 .
 NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml



fixed-polr.R (28K) 
http://r.789695.n4.nabble.com/attachment/4647403/0/fixed-polr.R




-
Tim J. Benham
--
View this message in context: 
http://r.789695.n4.nabble.com/bugs-and-misfeatures-in-polr-MASS-fixed-tp3024677p4647403.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

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


Re: [R] cut point in ROC

2012-10-25 Thread Bhupendrasinh Thakre
Please use dput while supplying data. 

Best Regards,

Bhupendrasinh Thakre
Sent from my iPhone

On Oct 25, 2012, at 5:31 AM, Soheila Khodakarim lkhodaka...@gmail.com wrote:

 var1
 
 var2
 
 var3
 
 var4
 
 var5
 
 var6
 
 var7
 
 var8
 
 var9
 
 var10
 
 gold
 
 2
 
 3
 
 1
 
 2
 
 4
 
 0
 
 1
 
 4
 
 4
 
 3
 
 2
 
 2
 
 4
 
 2
 
 4
 
 3
 
 4
 
 2
 
 4
 
 4
 
 4
 
 2
 
 3
 
 3
 
 0
 
 0
 
 4
 
 1
 
 0
 
 2
 
 4
 
 4
 
 2
 
 1
 
 4
 
 0
 
 3
 
 2
 
 0
 
 0
 
 2
 
 4
 
 4
 
 2
 
 3
 
 4
 
 0
 
 2
 
 2
 
 0
 
 0
 
 0
 
 3
 
 4
 
 2
 
 2
 
 2
 
 3
 
 2
 
 2
 
 0
 
 0
 
 0
 
 2
 
 4
 
 2
 
 2
 
 4
 
 1
 
 1
 
 2
 
 0
 
 0
 
 3
 
 3
 
 3
 
 2
 
 3
 
 4
 
 1
 
 4
 
 0
 
 0
 
 0
 
 0
 
 3
 
 4
 
 2
 
 3
 
 1
 
 0
 
 2
 
 2
 
 1
 
 0
 
 2
 
 3
 
 3
 
 2
 
 0
 
 3
 
 1
 
 1
 
 1
 
 1
 
 2
 
 1
 
 2
 
 3
 
 2
 
 1
 
 1
 
 0
 
 1
 
 0
 
 0
 
 0
 
 0
 
 1
 
 2
 
 1
 
 1
 
 1
 
 0
 
 0
 
 0
 
 0
 
 0
 
 0
 
 2
 
 2
 
 1
 
 1
 
 2
 
 0
 
 0
 
 0
 
 0
 
 0
 
 0
 
 2
 
 1
 
 1
 
 1
 
 1
 
 0
 
 0
 
 0
 
 0
 
 0
 
 0
 
 2
 
 2
 
 1
 
 0
 
 1
 
 1
 
 0
 
 1
 
 0
 
 0
 
 0
 
 0
 
 3
 
 1
 
 1
 
 2
 
 0
 
 1
 
 0
 
 0
 
 0
 
 0
 
 1
 
 1
 
 1
 
 1
 
 2
 
 1
 
 0
 
 0
 
 0
 
 0
 
 0
 
 1
 
 1
 
 1
 
 1
 
 2
 
 0
 
 1
 
 0
 
 0
 
 0
 
 0
 
 1
 
 0
 
 1
 
 0
 
 0
 
 0
 
 0
 
 1
 
 0
 
 0
 
 0
 
 2
 
 2
 
 1
 
 0
 
 2
 
 0
 
 1
 
 0
 
 0
 
 0
 
 0
 
 1
 
 2
 
 1
 
 
 
 Dear All
 
 I try to find a diagnosis test instead of the gold standard.
 
 The gold standard is based on 10 vars.
 
 Now, I try to find a new test based on several vars.
 
 For example, based on 3 or 4 vars.
 
 There are a lot of choices to test, I am confused.
 
 I will be happy if you guide me.
 
 Best Regards,
 
 Soheila
 
[[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] How to quit R script return to R prompt

2012-10-25 Thread S Ellison
 

 You typed a ` without closing it:
 barplot(xtab(`profits`,data=Forbes2000)) 
 
 anyway: pushing the escape button should also return you to 
 the R-prompt (at least on a Windows platform)

But why is the OP using a backtick at all? It's not necessary in this instance 
(and in fact it's very rarely necessary at all unless you have used a 
syntactically invalid name with something silly like spaces in it). See ?Quotes 
for a little more detail on what ` does.

Also, xtab should possibly be xtabs, and the first argument to that is a 
one-sided formula, not a vector:

 library(HSAUR)
 barplot(xtabs( ~ profits,data=Forbes2000)) 

should work fine.

***
This email and any attachments are confidential. Any use...{{dropped:8}}

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


Re: [R] List of multidimensional arrays

2012-10-25 Thread Berend Hasselman

You were asked to provide R code in ascii text.
Also use dput to get the objects into a mail.

Nobody is going to make the effort to copy from your pdf. I certainly will not.

Berend

On 25-10-2012, at 13:45, Loukia Spineli wrote:

 x and y are the frequencies of missing participants in the intervention and
 the control treatment respectively! vector t contains the code of the
 interventions (we have 11 interventions). I re-attach the PDF with some
 small modifications. I am trying to create a list, where each list element
 is a vector of different length arrays that contain 2by2 matrices. To be
 more specific there are 11 treatments that are compared with placebo (we
 have 11 comparisons) and each comparison is studied by a different number
 of trials and each trial has a different number of missing participants in
 both arms. The length of the list is equal to the number of comparisons. In
 each comparison the number of arrays is equal to the number of trials that
 study this comparison. For instance 4 trials compare PAR with placebo. So,
 for this comparison we have 4 arrays and each array has a length equal to
 the producy of the number of participants in each arm. These arrays contain
 2x2 matrices.
 
 I have attached a document with the data and the code. I cannot create the
 list results the way I have described above. It creates only the  matrices
 for the first array (that has length equal to 135) of the first comparison
 leaving the rest 10 comparisons NULL.
 
 On Wed, Oct 24, 2012 at 5:17 PM, Richard M. Heiberger r...@temple.eduwrote:
 
 I am looking at your pdf file.
 
 it doesn't match your description.
 
 There are no missing values in the vectors
 x, y, t.
 Each vector has length 55 which is not a multiple of 4,
 so we don't know where the 2x2 matrices come from.
 
 The code doesn't run.  There are are too many }.
 PDF files are formatted and are not ascii.
 
 Please send your code in ascii text in the body of the email.
 Please pick it up from your email and paste it into
 a fresh R session to be sure that it works.
 
 Perhaps consrtruct manually an example of what you want the answer to look
 like.
 
 Rich
 
 
 
 On Wed, Oct 24, 2012 at 3:51 AM, Loukia Spineli spinelilouki...@gmail.com
 wrote:
 
 Dear all,
 
 I am trying to create a list, where each list element is a vector of
 different length arrays that contain 2by2 matrices. To be more specific
 there are 11 treatments that are compared with placebo (we have 11
 comparisons) and each comparison is studied by a different number of
 trials
 and each trial has a different number of missing participants in both
 arms.
 The length of the list is equal to the number of comparisons. In each
 comparison the number of arrays is equal to the number of trials that
 study
 this comparison. For instance 4 trials compare PAR with placebo. So, for
 this comparison we have 4 arrays and each array has a length equal to the
 producy of the number of participants in each arm. These arrays contain
 2x2
 matrices.
 
 I have attached a document with the data and the code. I cannot create the
 list results the way I have described above. It creates only the  matrices
 for the first array (that has length equal to 135) of the first comparison
 leaving the rest 10 comparisons NULL.
 Any suggestion would be  really helpful
 
 Thank you in advance,
 Loukia
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 
 List of multidimensional 
 arrays.pdf__
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] List of multidimensional arrays

2012-10-25 Thread Berend Hasselman
Loukia,

Please send your replies to the R-help list. I am CC'ing this to the R-help 
list.

On 25-10-2012, at 15:30, Loukia Spineli wrote:

 Dear Berend,
 
 I am not familiar at all with ascii text. If you could suggest me a good link 
 to learn about it, then it would be really helpful!

If that is so, then how are you making your R code or R script?
You must be using a plain text editor but we don't know your version of R, your 
OS, or anything else.
If you are only using an R console you should look in the documentation of your 
system to find out how to work with plain text.

Berend

 Best wishes,
 Loukia
 
 On Thu, Oct 25, 2012 at 4:23 PM, Berend Hasselman b...@xs4all.nl wrote:
 
 You were asked to provide R code in ascii text.
 Also use dput to get the objects into a mail.
 
 Nobody is going to make the effort to copy from your pdf. I certainly will 
 not.
 
 Berend
 
 On 25-10-2012, at 13:45, Loukia Spineli wrote:
 
  x and y are the frequencies of missing participants in the intervention and
  the control treatment respectively! vector t contains the code of the
  interventions (we have 11 interventions). I re-attach the PDF with some
  small modifications. I am trying to create a list, where each list element
  is a vector of different length arrays that contain 2by2 matrices. To be
  more specific there are 11 treatments that are compared with placebo (we
  have 11 comparisons) and each comparison is studied by a different number
  of trials and each trial has a different number of missing participants in
  both arms. The length of the list is equal to the number of comparisons. In
  each comparison the number of arrays is equal to the number of trials that
  study this comparison. For instance 4 trials compare PAR with placebo. So,
  for this comparison we have 4 arrays and each array has a length equal to
  the producy of the number of participants in each arm. These arrays contain
  2x2 matrices.
 
  I have attached a document with the data and the code. I cannot create the
  list results the way I have described above. It creates only the  matrices
  for the first array (that has length equal to 135) of the first comparison
  leaving the rest 10 comparisons NULL.
 
  On Wed, Oct 24, 2012 at 5:17 PM, Richard M. Heiberger 
  r...@temple.eduwrote:
 
  I am looking at your pdf file.
 
  it doesn't match your description.
 
  There are no missing values in the vectors
  x, y, t.
  Each vector has length 55 which is not a multiple of 4,
  so we don't know where the 2x2 matrices come from.
 
  The code doesn't run.  There are are too many }.
  PDF files are formatted and are not ascii.
 
  Please send your code in ascii text in the body of the email.
  Please pick it up from your email and paste it into
  a fresh R session to be sure that it works.
 
  Perhaps consrtruct manually an example of what you want the answer to look
  like.
 
  Rich
 
 
 
  On Wed, Oct 24, 2012 at 3:51 AM, Loukia Spineli spinelilouki...@gmail.com
  wrote:
 
  Dear all,
 
  I am trying to create a list, where each list element is a vector of
  different length arrays that contain 2by2 matrices. To be more specific
  there are 11 treatments that are compared with placebo (we have 11
  comparisons) and each comparison is studied by a different number of
  trials
  and each trial has a different number of missing participants in both
  arms.
  The length of the list is equal to the number of comparisons. In each
  comparison the number of arrays is equal to the number of trials that
  study
  this comparison. For instance 4 trials compare PAR with placebo. So, for
  this comparison we have 4 arrays and each array has a length equal to the
  producy of the number of participants in each arm. These arrays contain
  2x2
  matrices.
 
  I have attached a document with the data and the code. I cannot create the
  list results the way I have described above. It creates only the  matrices
  for the first array (that has length equal to 135) of the first comparison
  leaving the rest 10 comparisons NULL.
  Any suggestion would be  really helpful
 
  Thank you in advance,
  Loukia
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
  List of multidimensional 
  arrays.pdf__
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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, 

Re: [R] List of multidimensional arrays

2012-10-25 Thread Loukia Spineli
 Thank you very much Berend!:)

On Thu, Oct 25, 2012 at 4:37 PM, Berend Hasselman b...@xs4all.nl wrote:

 Loukia,

 Please send your replies to the R-help list. I am CC'ing this to the
 R-help list.

 On 25-10-2012, at 15:30, Loukia Spineli wrote:

  Dear Berend,
 
  I am not familiar at all with ascii text. If you could suggest me a good
 link to learn about it, then it would be really helpful!

 If that is so, then how are you making your R code or R script?

You must be using a plain text editor but we don't know your version of R,
 your OS, or anything else.
 If you are only using an R console you should look in the documentation of
 your system to find out how to work with plain text.

 Berend

  Best wishes,
  Loukia
 
  On Thu, Oct 25, 2012 at 4:23 PM, Berend Hasselman b...@xs4all.nl wrote:
 
  You were asked to provide R code in ascii text.
  Also use dput to get the objects into a mail.
 
  Nobody is going to make the effort to copy from your pdf. I certainly
 will not.
 
  Berend
 
  On 25-10-2012, at 13:45, Loukia Spineli wrote:
 
   x and y are the frequencies of missing participants in the
 intervention and
   the control treatment respectively! vector t contains the code of the
   interventions (we have 11 interventions). I re-attach the PDF with some
   small modifications. I am trying to create a list, where each list
 element
   is a vector of different length arrays that contain 2by2 matrices. To
 be
   more specific there are 11 treatments that are compared with placebo
 (we
   have 11 comparisons) and each comparison is studied by a different
 number
   of trials and each trial has a different number of missing
 participants in
   both arms. The length of the list is equal to the number of
 comparisons. In
   each comparison the number of arrays is equal to the number of trials
 that
   study this comparison. For instance 4 trials compare PAR with placebo.
 So,
   for this comparison we have 4 arrays and each array has a length equal
 to
   the producy of the number of participants in each arm. These arrays
 contain
   2x2 matrices.
  
   I have attached a document with the data and the code. I cannot create
 the
   list results the way I have described above. It creates only the
  matrices
   for the first array (that has length equal to 135) of the first
 comparison
   leaving the rest 10 comparisons NULL.
  
   On Wed, Oct 24, 2012 at 5:17 PM, Richard M. Heiberger r...@temple.edu
 wrote:
  
   I am looking at your pdf file.
  
   it doesn't match your description.
  
   There are no missing values in the vectors
   x, y, t.
   Each vector has length 55 which is not a multiple of 4,
   so we don't know where the 2x2 matrices come from.
  
   The code doesn't run.  There are are too many }.
   PDF files are formatted and are not ascii.
  
   Please send your code in ascii text in the body of the email.
   Please pick it up from your email and paste it into
   a fresh R session to be sure that it works.
  
   Perhaps consrtruct manually an example of what you want the answer to
 look
   like.
  
   Rich
  
  
  
   On Wed, Oct 24, 2012 at 3:51 AM, Loukia Spineli 
 spinelilouki...@gmail.com
   wrote:
  
   Dear all,
  
   I am trying to create a list, where each list element is a vector of
   different length arrays that contain 2by2 matrices. To be more
 specific
   there are 11 treatments that are compared with placebo (we have 11
   comparisons) and each comparison is studied by a different number of
   trials
   and each trial has a different number of missing participants in both
   arms.
   The length of the list is equal to the number of comparisons. In each
   comparison the number of arrays is equal to the number of trials that
   study
   this comparison. For instance 4 trials compare PAR with placebo. So,
 for
   this comparison we have 4 arrays and each array has a length equal
 to the
   producy of the number of participants in each arm. These arrays
 contain
   2x2
   matrices.
  
   I have attached a document with the data and the code. I cannot
 create the
   list results the way I have described above. It creates only the
  matrices
   for the first array (that has length equal to 135) of the first
 comparison
   leaving the rest 10 comparisons NULL.
   Any suggestion would be  really helpful
  
   Thank you in advance,
   Loukia
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
   http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  
  
  
   List of multidimensional
 arrays.pdf__
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/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 

Re: [R] List of multidimensional arrays

2012-10-25 Thread Richard M. Heiberger
With effort I re-inserted the line feeds in your code that the
pdf file deleted.
There is an error in your code

Error in 0:(x[t == i][l]) (from #9) : NA/NaN argument


 x[t == i]
[1] 8 2 9
 l
[1] 4


On Thu, Oct 25, 2012 at 7:45 AM, Loukia Spineli
spinelilouki...@gmail.comwrote:

 x and y are the frequencies of missing participants in the intervention
 and the control treatment respectively! vector t contains the code of the
 interventions (we have 11 interventions). I re-attach the PDF with some
 small modifications. I am trying to create a list, where each list
 element is a vector of different length arrays that contain 2by2 matrices.
 To be more specific there are 11 treatments that are compared with placebo
 (we have 11 comparisons) and each comparison is studied by a different
 number of trials and each trial has a different number of missing
 participants in both arms. The length of the list is equal to the number of
 comparisons. In each comparison the number of arrays is equal to the number
 of trials that study this comparison. For instance 4 trials compare PAR
 with placebo. So, for this comparison we have 4 arrays and each array has a
 length equal to the producy of the number of participants in each arm.
 These arrays contain 2x2 matrices.

 I have attached a document with the data and the code. I cannot create the
 list results the way I have described above. It creates only the  matrices
 for the first array (that has length equal to 135) of the first comparison
 leaving the rest 10 comparisons NULL.

 On Wed, Oct 24, 2012 at 5:17 PM, Richard M. Heiberger r...@temple.eduwrote:

 I am looking at your pdf file.

 it doesn't match your description.

 There are no missing values in the vectors
 x, y, t.
 Each vector has length 55 which is not a multiple of 4,
 so we don't know where the 2x2 matrices come from.

 The code doesn't run.  There are are too many }.
 PDF files are formatted and are not ascii.

 Please send your code in ascii text in the body of the email.
 Please pick it up from your email and paste it into
 a fresh R session to be sure that it works.

 Perhaps consrtruct manually an example of what you want the answer to
 look like.

 Rich



 On Wed, Oct 24, 2012 at 3:51 AM, Loukia Spineli 
 spinelilouki...@gmail.com wrote:

 Dear all,

 I am trying to create a list, where each list element is a vector of
 different length arrays that contain 2by2 matrices. To be more specific
 there are 11 treatments that are compared with placebo (we have 11
 comparisons) and each comparison is studied by a different number of
 trials
 and each trial has a different number of missing participants in both
 arms.
 The length of the list is equal to the number of comparisons. In each
 comparison the number of arrays is equal to the number of trials that
 study
 this comparison. For instance 4 trials compare PAR with placebo. So, for
 this comparison we have 4 arrays and each array has a length equal to the
 producy of the number of participants in each arm. These arrays contain
 2x2
 matrices.

 I have attached a document with the data and the code. I cannot create
 the
 list results the way I have described above. It creates only the
  matrices
 for the first array (that has length equal to 135) of the first
 comparison
 leaving the rest 10 comparisons NULL.
 Any suggestion would be  really helpful

 Thank you in advance,
 Loukia

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

2012-10-25 Thread Richard M. Heiberger
Please use this model to send your data and code

 mydata - data.frame(x, y, fx, fy)
 head(mydata)  ## just the first 6 rows are displayed on screen
   x y fx fy
1  4 3 37 40
2  4 3 21 20
3  0 0 65 50
4 12 0 91 49
5  1 5 22 20
6  2 3  6 10
 dump(mydata, )
mydata -
structure(list(x = c(4, 4, 0, 12, 1, 2, 0, 2, 6, 1, 0, 20, 6,
5, 20, 0, 0, 0, 4, 1, 0, 16, 0, 9, 7, 11, 0, 2, 3, 0, 10, 2,
1, 0, 3, 6, 4, 0, 20, 11, 1, 8, 0, 6, 15, 0, 2, 5, 2, 6, 24,
1, 11, 6, 9), y = c(3, 3, 0, 0, 5, 3, 0, 5, 4, 2, 0, 20, 6, 1,
18, 0, 0, 3, 3, 1, 0, 4, 0, 13, 7, 12, 0, 2, 2, 0, 2, 4, 0, 4,
2, 5, 0, 0, 23, 8, 0, 14, 0, 9, 20, 0, 2, 0, 2, 2, 14, 4, 1,
4, 7), fx = c(37, 21, 65, 91, 22, 6, 31, 41, 27, 5, 77, 33, 90,
26, 35, 35, 34, 30, 13, 24, 107, 122, 33, 18, 34, 23, 27, 8,
81, 6, 9, 38, 44, 18, 30, 37, 96, 8, 53, 56, 10, 71, 26, 36,
24, 73, 27, 46, 85, 46, 117, 17, 45, 51, 67), fy = c(40, 20,
50, 49, 20, 10, 36, 48, 39, 7, 72, 38, 71, 2, 69, 7, 7, 32, 32,
32, 34, 17, 26, 25, 140, 132, 36, 15, 35, 23, 19, 35, 35, 38,
30, 38, 103, 13, 61, 48, 17, 74, 33, 44, 28, 94, 24, 52, 70,
47, 118, 21, 52, 59, 84)), .Names = c(x, y, fx, fy), row.names =
c(NA,
-55L), class = data.frame)


Now the reader can pick up the mydata -  
lines and paste them into the R session and reproduce what
you want us to see.

On Thu, Oct 25, 2012 at 9:53 AM, Richard M. Heiberger r...@temple.eduwrote:

 With effort I re-inserted the line feeds in your code that the
 pdf file deleted.
 There is an error in your code

 Error in 0:(x[t == i][l]) (from #9) : NA/NaN argument

 
  x[t == i]
 [1] 8 2 9
  l
 [1] 4
 

 On Thu, Oct 25, 2012 at 7:45 AM, Loukia Spineli spinelilouki...@gmail.com
  wrote:

 x and y are the frequencies of missing participants in the intervention
 and the control treatment respectively! vector t contains the code of the
 interventions (we have 11 interventions). I re-attach the PDF with some
 small modifications. I am trying to create a list, where each list
 element is a vector of different length arrays that contain 2by2 matrices.
 To be more specific there are 11 treatments that are compared with placebo
 (we have 11 comparisons) and each comparison is studied by a different
 number of trials and each trial has a different number of missing
 participants in both arms. The length of the list is equal to the number of
 comparisons. In each comparison the number of arrays is equal to the number
 of trials that study this comparison. For instance 4 trials compare PAR
 with placebo. So, for this comparison we have 4 arrays and each array has a
 length equal to the producy of the number of participants in each arm.
 These arrays contain 2x2 matrices.

 I have attached a document with the data and the code. I cannot create
 the list results the way I have described above. It creates only the
  matrices for the first array (that has length equal to 135) of the first
 comparison leaving the rest 10 comparisons NULL.

 On Wed, Oct 24, 2012 at 5:17 PM, Richard M. Heiberger r...@temple.eduwrote:

 I am looking at your pdf file.

 it doesn't match your description.

 There are no missing values in the vectors
 x, y, t.
 Each vector has length 55 which is not a multiple of 4,
 so we don't know where the 2x2 matrices come from.

 The code doesn't run.  There are are too many }.
 PDF files are formatted and are not ascii.

 Please send your code in ascii text in the body of the email.
 Please pick it up from your email and paste it into
 a fresh R session to be sure that it works.

 Perhaps consrtruct manually an example of what you want the answer to
 look like.

 Rich



 On Wed, Oct 24, 2012 at 3:51 AM, Loukia Spineli 
 spinelilouki...@gmail.com wrote:

 Dear all,

 I am trying to create a list, where each list element is a vector of
 different length arrays that contain 2by2 matrices. To be more specific
 there are 11 treatments that are compared with placebo (we have 11
 comparisons) and each comparison is studied by a different number of
 trials
 and each trial has a different number of missing participants in both
 arms.
 The length of the list is equal to the number of comparisons. In each
 comparison the number of arrays is equal to the number of trials that
 study
 this comparison. For instance 4 trials compare PAR with placebo. So, for
 this comparison we have 4 arrays and each array has a length equal to
 the
 producy of the number of participants in each arm. These arrays contain
 2x2
 matrices.

 I have attached a document with the data and the code. I cannot create
 the
 list results the way I have described above. It creates only the
  matrices
 for the first array (that has length equal to 135) of the first
 comparison
 leaving the rest 10 comparisons NULL.
 Any suggestion would be  really helpful

 Thank you in advance,
 Loukia

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

[R] Plot lmer model with Effects package

2012-10-25 Thread Marte Lilleeng
Hi everyone!
I have a simple model that i would like to plot with 95% CIs.
It is like follows:
m1-lmer(Richness~Grazing+I(Grazing^2)+(1|Plot),family=poisson)

By using the effects package I get two plots, one for the linear term
and one for the squared term.
Q1: Can I get all in one? I.e. with one line for the whole model?
Q2: Can I also visualize the random effects?

I would be very happy for your answers!

-- 
Mvh Marte S. Lilleeng

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

2012-10-25 Thread Tagmarie
Hello, 
I have a data frame somewhat like that: 

myframe - data.frame (ID=c(Ernie, Ernie, Ernie, Bert, Bert,
Bert), Timestamp=c(24.09.2012 09:00, 24.09.2012 10:00, 24.09.2012
11:00), Hunger=c(1,1,1,2,2,1) )
myframestime - as.POSIXct (strptime(as.character(myframe$Timestamp),
%d.%m.%Y %H:%M), tz=GMT)
myframe2 - cbind (myframe,myframestime)
myframe2$Timestamp - NULL  
myframe2

I want to add an additional column at the right and get in each row a value
which shows the mean of hunger of the last two hours. 

Does anyone know how that works? That would be very helpful. 



--
View this message in context: 
http://r.789695.n4.nabble.com/mean-of-a-value-of-the-last-2-hours-tp4647415.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] Egarch (1,1) with Student t distribution in RExcel

2012-10-25 Thread Dheeraj Pandey
Hi
I want to implement Egarch (1,1) with t distribution model using RExcel and VBA.
May I know the syntax.
Following is the code that I 'm using.

rinterface.RRun 
spec=ugarchspec(variance.model=list(model=(eGARCH),garchOrder=c(1,1)), 
mean.model=list(armaOrder=c(1,1), arfima=FALSE), distribution.model=(std))
rinterface.RRun fit = ugarchfit(Data = b, spec = spec)
rinterface.RRun output=sigma(fit)

Please let me know the error and it's solution.

Thanks
Dheeraj


[[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] Expression in legend of plot

2012-10-25 Thread stat.kk
So easy solution..., thank you very much :)



--
View this message in context: 
http://r.789695.n4.nabble.com/Expression-in-legend-of-plot-tp4647393p4647397.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] After sorting a dataframe by date

2012-10-25 Thread MacQueen, Don
As David said, you sorted by Date.

But sorting by rownames is not really the point. The point is that
rownames are not line numbers.

The rownames were assigned when the data frame was created, and then
preserved when you sorted.  Sometimes, rownames contain meaningful
information that is associated with the data in that row, and therefore
must be sorted along with the rows.

If you want to change the row names to be analogous to line numbers after
sorting you can do, for example,

   rownames(sorted.df) - seq(nrow(sorted.df))




-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 10/23/12 9:34 AM, martiny my2...@outlook.com wrote:

HI,
I have created a dataframe df and try to sort it by its date using the
order() as below:

df-read.csv(constr,header=T)
  sorted.df-df[order(as.Date(df$Date), decreasing = F),]
  print(sorted.df)

The dataframe was sorted, but the output from the command console shows
reserved line order..rather than starting at 1it does not really
affect my result, but I want to understand why is that...

  Date   Open   HighLow  Close   Volume Adj.Close
252 2011-01-03 325.64 330.26 324.84 329.57 15897800328.16
251 2011-01-04 332.44 332.50 328.15 331.29 11038600329.87
250 2011-01-05 329.55 334.34 329.50 334.00  9125700332.57
249 2011-01-06 334.72 335.25 332.90 333.73 10729600332.30
248 2011-01-07 333.99 336.35 331.90 336.12 11140400334.68
247 2011-01-10 338.83 343.23 337.17 342.45 1602340.99
246 2011-01-11 344.88 344.96 339.47 341.64 15861000340.18
245 2011-01-12 343.25 344.43 342.00 344.42 10806800342.95
244 2011-01-13 345.16 346.64 343.85 345.68 10599300344.20
...
...
3   2011-12-28 406.89 408.25 401.34 402.64  8166500400.92
2   2011-12-29 403.40 405.65 400.51 405.12  7713500403.39
1   2011-12-30 403.51 406.28 403.49 405.00  6416500403.27

Any advice would be highly appreciated.



--
View this message in context:
http://r.789695.n4.nabble.com/After-sorting-a-dataframe-by-date-tp4647173.
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] trying ti use a function in aggregate

2012-10-25 Thread Sally_roman
Hi -I am using R v 2.13.0.  I am trying to use the aggregate function to
calculate the percent at length for each Trip_id and CommonName.  Here is a
small subset of the data.  
   Trip_id  Vessel   CommonName Length Count
1  230SunlightShad,American 19 1
2  230SunlightShad,American 20 1
3  230SunlightShad,American 21 1
4  230SunlightShad,American 23 1
5  230SunlightShad,American 26 1
6  230SunlightShad,American 27 1
7  230SunlightShad,American 30 2
8  230SunlightShad,American 33 1
9  230SunlightShad,American 34 1
10 230SunlightShad,American 37 1
11 230Sunlight Herring,Blueback 20 1
12 230Sunlight Herring,Blueback 21 2
13 230Sunlight Herring,Blueback 22 5
14 230Sunlight Herring,Blueback 26 1
15 230Sunlight  Alewife 17 1
16 230Sunlight  Alewife 18 1
17 230Sunlight  Alewife 20 2
18 230Sunlight  Alewife 21 4
19 230Sunlight  Alewife 2216
20 230Sunlight  Alewife 2322
21 230Sunlight  Alewife 2416
22 230Sunlight  Alewife 25 4
23 230Sunlight  Alewife 26 1
24 230Sunlight  Alewife 27 2
25 230Sunlight  Alewife 28 2
26 231 Western VentureShad,American 23 1
27 231 Western VentureShad,American 24 1
28 231 Western VentureShad,American 25 1
29 231 Western VentureShad,American 28 2
30 231 Western VentureShad,American 29 2

My code is:
myfun-function (x) x/sum(x)
b-with(data,aggregate(x=list(Percent=Count),by=list(Trip_id=Trip_id,Length=Length,Species=CommonName),
FUN=myfun))

My issue is that the percent is not be calculated by Trip_id and CommonName. 
The result is that each row has a percent of 1 indicating that myfun is not
dividing by the sum of counts with a Trip_id/CommonName group.  Any help
would be appreciated.
Thank you 





--
View this message in context: 
http://r.789695.n4.nabble.com/trying-ti-use-a-function-in-aggregate-tp4647414.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] Egarch (1,1) with Student t distribution in RExcel

2012-10-25 Thread Dheeraj Pandey
How Can I  run all these codes in VBA using RExcel
library(rugarch)

spec=ugarchspec(variance.model=list(model=sGARCH,garchOrder=c(1,1)), 
mean.model=list(armaOrder=c(1,1), arfima=FALSE), distribution.model=std)

fit=ugarchfit(data=d, spec=spec)

z=sigma(fit)


Dheeraj

[[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] help appending randomly selected observation based on criteria

2012-10-25 Thread csmeredith
Hello, 
I wrote a request yesterday on how to select a random observation that met
certain criteria. I think mostly I have it  figured out, but I can't figure
out how to append the observations. The output just has one observation in
it. 

Any help would be appreciated, 
thanks.
Christy

setwd (C:/christy/roads/)
roads=read.csv(streamland23.csv)

for (i in 1:nrow (roads)){
Sitetype= roads$Sitetype[i]
yr=roads$REACH_Yr[i]
initRchid=roads$RchID[i]
huc1=roads$HUC[i]


sample.df - function(df, n) df[sample(nrow(df), n), , drop = FALSE] 

selected=sample.df(roads[roads$HUC == huc1, ], 1) 

selectedb=selected
selectedb$oldrch=initRchid

write.csv(selectedb,file=outhuc3.csv,append=TRUE)

}




--
View this message in context: 
http://r.789695.n4.nabble.com/randomly-select-another-observation-with-same-grouping-factor-and-year-value-do-for-every-record-in-e-tp4647351p4647420.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] mean of a value of the last 2 hours

2012-10-25 Thread arun
Hi,
May be this helps:
 new1-with(myframe2,aggregate(cbind(Hunger,myframestime),by=list(ID=ID), 
function(x) mean(tail(x,2[,1:2]
 merge(myframe2,new1,by=ID,all=TRUE)
# ID Hunger.x    myframestime Hunger.y
#1  Bert    2 2012-09-24 09:00:00  1.5
#2  Bert    2 2012-09-24 10:00:00  1.5
#3  Bert    1 2012-09-24 11:00:00  1.5
#4 Ernie    1 2012-09-24 09:00:00  1.0
#5 Ernie    1 2012-09-24 10:00:00  1.0
#6 Ernie    1 2012-09-24 11:00:00  1.0
A.K.




- Original Message -
From: Tagmarie ramga...@gmx.net
To: r-help@r-project.org
Cc: 
Sent: Thursday, October 25, 2012 10:35 AM
Subject: [R] mean of a value of the last 2 hours

Hello, 
I have a data frame somewhat like that: 

myframe - data.frame (ID=c(Ernie, Ernie, Ernie, Bert, Bert,
Bert), Timestamp=c(24.09.2012 09:00, 24.09.2012 10:00, 24.09.2012
11:00), Hunger=c(1,1,1,2,2,1) )
myframestime - as.POSIXct (strptime(as.character(myframe$Timestamp),
%d.%m.%Y %H:%M), tz=GMT)
myframe2 - cbind (myframe,myframestime)
myframe2$Timestamp - NULL  
myframe2

I want to add an additional column at the right and get in each row a value
which shows the mean of hunger of the last two hours. 

Does anyone know how that works? That would be very helpful. 



--
View this message in context: 
http://r.789695.n4.nabble.com/mean-of-a-value-of-the-last-2-hours-tp4647415.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] parallel processing with foreach

2012-10-25 Thread Peter Langfelder
It seems you don't quite understand how foreach works. foreach (..)
%dopar% { ... } takes the last value from each of the second {...}
evaluations and feeds them to the .combine function (in your case
rbind()). Since your last call in the %dopar% {...} block is assign(),
you are not getting anything meaningful.

Make the last value a vector that you want to be rbind-ed to the result.

HTH,

Peter

On Thu, Oct 25, 2012 at 1:47 AM, pxs101220 pxs101...@utdallas.edu wrote:
 Hi,

 I am trying to  parallel computing with foreach function, but not able to
 get the result. I know that in parallel processing, all result is collected
 in list format, but I am not able to get input there.
 Any help is really appreciated.


 esf.m -foreach (i = 1:n.s, .combine=rbind) %dopar%  {
   EV - as.data.frame(eig$vectors[,1:n.candid[i]])
   colnames(EV) - paste(EV, 1:NCOL(EV), sep=)

   r25.esf.f - lm(y ~ x1 + x2 +., data = EV)
   assign(paste(r25.esf., i, sep=), stepwise.forward(r25.esf.f, lm(y ~ x1
 + x2, data = EV), 0.1, verbose = F))}



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/parallel-processing-with-foreach-tp4647381.html
 Sent from the R help mailing list archive at Nabble.com.

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

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


Re: [R] Egarch (1,1) with Student t distribution in RExcel

2012-10-25 Thread David Winsemius

On Oct 25, 2012, at 8:00 AM, Dheeraj Pandey wrote:

 How Can I  run all these codes in VBA using RExcel
 library(rugarch)

I predict there are a very small number (possibly zero) of persons reading this 
list that are both Excel coders and users of that package. You might consider 
posting it on the mailing list where RExcel is supported and so more 
cross-functional eyes and brains would be seeing it.


(And when you do post again, please avoid double posting.)
-- 
David.
 spec=ugarchspec(variance.model=list(model=sGARCH,garchOrder=c(1,1)), 
 mean.model=list(armaOrder=c(1,1), arfima=FALSE), distribution.model=std)
 
 fit=ugarchfit(data=d, spec=spec)
 
 z=sigma(fit)
 
 
 Dheeraj
 
   [[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, MD
Alameda, CA, USA

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


Re: [R] How to quit R script return to R prompt

2012-10-25 Thread David Winsemius

On Oct 25, 2012, at 6:00 AM, S Ellison wrote:

 
 
 You typed a ` without closing it:
 barplot(xtab(`profits`,data=Forbes2000)) 
 
 anyway: pushing the escape button should also return you to 
 the R-prompt (at least on a Windows platform)

Also on Macs.

 
 But why is the OP using a backtick at all?

There was suggestive evidence in the rest of his post that his shift key is 
wonky and he did mean to type a tilde.

 It's not necessary in this instance (and in fact it's very rarely necessary 
 at all unless you have used a syntactically invalid name with something silly 
 like spaces in it). See ?Quotes for a little more detail on what ` does.
 
 Also, xtab should possibly be xtabs, and the first argument to that is a 
 one-sided formula, not a vector:
 
 library(HSAUR)
 barplot(xtabs( ~ profits,data=Forbes2000)) 

Actually any unmatched single or double quote would have the same effect. 
Similar conundrums occur when Turing machines of any sort are reading input 
data where unmatched quotes result in huge missing gaps as line after line of 
perfectly useful data gets gathered up into one ungodly large single character 
element. (The human brain is thus demonstrated not to be a Turing machine.)


 
 should work fine.
 


David Winsemius, MD
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] mean of a value of the last 2 hours

2012-10-25 Thread Rui Barradas

Hello,

Or


ct - cut(myframe2$myframestime, breaks = 2 hour)
ave(myframe2$Hunger, ct)

And assign the output of 'ave' to a new column.

Hope this helps,

Rui Barradas
Em 25-10-2012 15:50, arun escreveu:

Hi,
May be this helps:
  new1-with(myframe2,aggregate(cbind(Hunger,myframestime),by=list(ID=ID), 
function(x) mean(tail(x,2[,1:2]
  merge(myframe2,new1,by=ID,all=TRUE)
# ID Hunger.xmyframestime Hunger.y
#1  Bert2 2012-09-24 09:00:00  1.5
#2  Bert2 2012-09-24 10:00:00  1.5
#3  Bert1 2012-09-24 11:00:00  1.5
#4 Ernie1 2012-09-24 09:00:00  1.0
#5 Ernie1 2012-09-24 10:00:00  1.0
#6 Ernie1 2012-09-24 11:00:00  1.0
A.K.




- Original Message -
From: Tagmarie ramga...@gmx.net
To: r-help@r-project.org
Cc:
Sent: Thursday, October 25, 2012 10:35 AM
Subject: [R] mean of a value of the last 2 hours

Hello,
I have a data frame somewhat like that:

myframe - data.frame (ID=c(Ernie, Ernie, Ernie, Bert, Bert,
Bert), Timestamp=c(24.09.2012 09:00, 24.09.2012 10:00, 24.09.2012
11:00), Hunger=c(1,1,1,2,2,1) )
myframestime - as.POSIXct (strptime(as.character(myframe$Timestamp),
%d.%m.%Y %H:%M), tz=GMT)
myframe2 - cbind (myframe,myframestime)
myframe2$Timestamp - NULL
myframe2

I want to add an additional column at the right and get in each row a value
which shows the mean of hunger of the last two hours.

Does anyone know how that works? That would be very helpful.



--
View this message in context: 
http://r.789695.n4.nabble.com/mean-of-a-value-of-the-last-2-hours-tp4647415.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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] arima.sim

2012-10-25 Thread J Toll
Hi,

For the sake of completeness, I thought I might follow up my email
from earlier in the month with what I found out by digging into the
code.  The answer to my earlier question perhaps should have been
obvious to me from the Usage description from the documentation.

In the three examples I originally included, the difference between a1
and the other two AR(1) models (i.e. a2 and a3) is the sd parameter
for start.innov.  In a1, the sd for innov is set to 0.1, but the sd
for start.innov remains the default parameter for rnorm (i.e. sd = 1).
 In a2 and a3, by passing in sd as an additional argument via ...,
this sd is used by both innov and start.innov.  So a1 is equivalent
to:

set.seed(2012)
a4 - arima.sim(list(order = c(1, 0, 0), ar = 0.5),
n = 250,
innov = rnorm(n = 250, mean = 0, sd = 0.1),
n.start = 10,
start.innov = rnorm(n = 10, mean = 0, sd = 1))

Whereas, a2 and a3 are equivalent to:

set.seed(2012)
a5 - arima.sim(list(order = c(1, 0, 0), ar = 0.5),
n = 250,
innov = rnorm(n = 250, mean = 0, sd = 0.1),
n.start = 10,
start.innov = rnorm(n = 10, mean = 0, sd = 0.1))

The only difference being the sd used by start.innov.  Of course this
leads to an additional question, which is, why might someone choose to
use differing values for sd in innov and start.innov?  I'd love to
hear any insight into this as I'm still learning to use this tool.
Thanks.


James


On Mon, Oct 8, 2012 at 9:23 AM, J Toll jct...@gmail.com wrote:
 Hi,

 I have been using arima.sim from the stats package recently, and I'm
 wondering why I get different results when using what seem to be the
 same parameters. For example, I've given examples of three different
 ways to run arima.sim with what I believe are the same parameters.
 It's my understanding from the R documentation that rnorm is the
 default function for rand.gen if not provided in innov.  So it would
 seem that there's quite a bit of redundancy in the assignment to a1.
 My expectation is that a1, a2, and a3 should be identical.  It turns
 out that a1 is only partially identical to a2 and a3.  The first 56
 values of a1 are different from a2 and a3, but the rest are the same.
 What is it that makes an explicit declaration of the innov parameters
 different from using the defaults?  At this point, my best guess is
 that this might have something to do with n.start and the length of
 the burn-in period.  Any suggestions as to why all three of these
 aren't the same?  Thanks.

 James

 set.seed(2012)
 a1 - arima.sim(list(order = c(1, 0, 0), ar = 0.5), n = 250, innov =
 rnorm(n = 250, mean = 0, sd = 0.1))
 summary(a1)
 Min.  1st Qu.   Median Mean  3rd Qu. Max.
 -0.45630 -0.11060 -0.03225 -0.02525  0.05484  0.27120

 set.seed(2012)
 a2 - arima.sim(list(order = c(1, 0, 0), ar = 0.5), n = 250, sd = 0.1)
 summary(a2)
 Min.  1st Qu.   Median Mean  3rd Qu. Max.
 -0.31830 -0.10200 -0.03016 -0.02174  0.05593  0.27120

 set.seed(2012)
 a3 - arima.sim(list(ar = 0.5), n = 250, sd = 0.1)
 summary(a3)
 Min.  1st Qu.   Median Mean  3rd Qu. Max.
 -0.31830 -0.10200 -0.03016 -0.02174  0.05593  0.27120

 a1 == a2
 Time Series:
 Start = 1
 End = 250
 Frequency = 1
   [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
  [22] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
  [43] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
  [64]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
 TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
  [85]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
 TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE

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


Re: [R] Plot lmer model with Effects package

2012-10-25 Thread Ben Bolker
Marte Lilleeng mlilleeng at gmail.com writes:

 

 
 [snip]

 I have a simple model that i would like to plot with 95% CIs.
 It is like follows:
 m1-lmer(Richness~Grazing+I(Grazing^2)+(1|Plot),family=poisson)
 
 By using the effects package I get two plots, one for the linear term
 and one for the squared term.
 Q1: Can I get all in one? I.e. with one line for the whole model?
 Q2: Can I also visualize the random effects?

  It would probably be best to send this to the r-sig-mixed-models list.
You may want to look at the code at http://glmm.wikidot.com/faq for
generating predictions and confidence intervals from lmer fits.

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


Re: [R] mean of a value of the last 2 hours

2012-10-25 Thread S Ellison
  I want to add an additional column at the right and get in 
 each row a value which shows the mean of hunger of the last two hours.

Isn't that just a moving average?

if so, see 
http://stackoverflow.com/questions/743812/calculating-moving-average-in-r, 
which mentions zoo for RollingMeans, TTR for MovingAverages, forecast for ma 
and a possible solution using filter. One of those might help.

S Ellison

***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 in finding sizes of objects using a for loop

2012-10-25 Thread jim holtman
Here is a function I use to get the size of objects:

Here is an example output:

 my.ls()
 Size Mode
allStores   7,303,224 list
convertedStores 0 NULL
f.createCluster40,508 function
x  41,672 list
**Total 7,385,404  ---




my.ls - function (pos = 1, sorted = FALSE, envir = as.environment(pos))
{
.result - sapply(ls(envir = envir, all.names = TRUE),
function(..x) object.size(eval(as.symbol(..x),
envir = envir)))
if (sorted) {
.result - rev(sort(.result))
}
.ls - as.data.frame(rbind(as.matrix(.result), `**Total` = sum(.result)))
names(.ls) - Size
.ls$Size - formatC(.ls$Size, big.mark = ,, digits = 0,
format = f)
.ls$Mode - c(unlist(lapply(rownames(.ls)[-nrow(.ls)], function(x)
mode(eval(as.symbol(x),
envir = envir, ---)
.ls
}


On Thu, Oct 25, 2012 at 2:24 AM, Purna chander chander...@gmail.com wrote:
 Dear All,

 I wanted to extract the sizes of all created objects. For E.g when I
 created 2 objects(x and y), I got their sizes using the following
 code:

 x-rnorm(1)
 y-runif(100,min=40,max=1000)
 ls()
 [1] x y
 object.size(x)
 80024 bytes
 object.size(y)
 824 bytes

 However, I was unable to get their sizes when I used a for loop in the
 following way:

 objects-ls()
 for (i in seq_along(objects)){
 +   print(c(objects[i],object.size(objects[i])))
 +
 + }
 [1] x  64
 [1] y  64


 The result obtained by me is wrong in second case.

 I understood that variables x and y are treated as characters. But to
 rectify this problem.

 Regards,
 Purna

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 in finding sizes of objects using a for loop

2012-10-25 Thread David Winsemius

On Oct 25, 2012, at 10:56 AM, jim holtman wrote:

 Here is a function I use to get the size of objects:
 
 Here is an example output:
 
 my.ls()
 Size Mode
 allStores   7,303,224 list
 convertedStores 0 NULL
 f.createCluster40,508 function
 x  41,672 list
 **Total 7,385,404  ---

That's far more elegant that the one I use; 

getsizes -  function() {z - sapply(ls(envir=globalenv()), 
function(x) object.size(get(x)))
   (tmp - as.matrix(rev(sort(z))[1:10]))}
getsizes()

Only returns the sorted-by-size matrix of the largest ten objects, but 
modifying it to return all of them should be trivial.

-- 
david.


 
 
 my.ls - function (pos = 1, sorted = FALSE, envir = as.environment(pos))
 {
.result - sapply(ls(envir = envir, all.names = TRUE),
 function(..x) object.size(eval(as.symbol(..x),
envir = envir)))
if (sorted) {
.result - rev(sort(.result))
}
.ls - as.data.frame(rbind(as.matrix(.result), `**Total` = sum(.result)))
names(.ls) - Size
.ls$Size - formatC(.ls$Size, big.mark = ,, digits = 0,
format = f)
.ls$Mode - c(unlist(lapply(rownames(.ls)[-nrow(.ls)], function(x)
 mode(eval(as.symbol(x),
envir = envir, ---)
.ls
 }
 
 
 On Thu, Oct 25, 2012 at 2:24 AM, Purna chander chander...@gmail.com wrote:
 Dear All,
 
 I wanted to extract the sizes of all created objects. For E.g when I
 created 2 objects(x and y), I got their sizes using the following
 code:
 
 x-rnorm(1)
 y-runif(100,min=40,max=1000)
 ls()
 [1] x y
 object.size(x)
 80024 bytes
 object.size(y)
 824 bytes
 
 However, I was unable to get their sizes when I used a for loop in the
 following way:
 
 objects-ls()
 for (i in seq_along(objects)){
 +   print(c(objects[i],object.size(objects[i])))
 +
 + }
 [1] x  64
 [1] y  64
 
 
 The result obtained by me is wrong in second case.
 
 I understood that variables x and y are treated as characters. But to
 rectify this problem.
 
 Regards,
 Purna
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
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] Change to daily digest

2012-10-25 Thread Mohamed Radhouane Aniba
Hello folks,

I am currently receiving a lot of emails from the list which proves that this 
is a very important place to get good feedbacks and tips and that the community 
is here to help .. Excellent thing.
I am not though able to login to my subscriber space to change the email 
reception into daily digest, or I am not looking to the right place, if someone 
can point me to the right URL that would be very appreciated.

Cheers

Rad

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


Re: [R] trying ti use a function in aggregate

2012-10-25 Thread Rui Barradas

Hello,
Try the following.
(I've changed your function a bit. And named the data.frame 'dat', not 
'data', which is an R function.)



myfun - function (x) ifelse(sum(x) == 0, 0, x/sum(x))

aggregate(Count ~ Trip_id + Length + CommonName, data = dat, myfun)

The output shows that each and every group corresponds to a single row 
of the original df. The 1's represent 100%, myfun _is_ dividing by 
sum(Count) Trip_id/Length/CommonName group. If you want just 
Trip_id/CommonName, use


aggregate(Count ~ Trip_id + CommonName, data = dat, myfun)


Or use your instruction without 'Length' in the by list:

b - with(dat, aggregate(x=list(Percent=Count),
by=list(Trip_id=Trip_id, Species=CommonName),
FUN = myfun))
b
  Trip_id  SpeciesPercent
1 230  Alewife 0.01408451
2 230 Herring,Blueback 0.
3 230Shad,American 0.09090909
4 231Shad,American 0.14285714

As you can see, the results are the same, with different output colnames.


Hope this helps,

Rui Barradas

Em 25-10-2012 15:19, Sally_roman escreveu:

Hi -I am using R v 2.13.0.  I am trying to use the aggregate function to
calculate the percent at length for each Trip_id and CommonName.  Here is a
small subset of the data.
Trip_id  Vessel   CommonName Length Count
1  230SunlightShad,American 19 1
2  230SunlightShad,American 20 1
3  230SunlightShad,American 21 1
4  230SunlightShad,American 23 1
5  230SunlightShad,American 26 1
6  230SunlightShad,American 27 1
7  230SunlightShad,American 30 2
8  230SunlightShad,American 33 1
9  230SunlightShad,American 34 1
10 230SunlightShad,American 37 1
11 230Sunlight Herring,Blueback 20 1
12 230Sunlight Herring,Blueback 21 2
13 230Sunlight Herring,Blueback 22 5
14 230Sunlight Herring,Blueback 26 1
15 230Sunlight  Alewife 17 1
16 230Sunlight  Alewife 18 1
17 230Sunlight  Alewife 20 2
18 230Sunlight  Alewife 21 4
19 230Sunlight  Alewife 2216
20 230Sunlight  Alewife 2322
21 230Sunlight  Alewife 2416
22 230Sunlight  Alewife 25 4
23 230Sunlight  Alewife 26 1
24 230Sunlight  Alewife 27 2
25 230Sunlight  Alewife 28 2
26 231 Western VentureShad,American 23 1
27 231 Western VentureShad,American 24 1
28 231 Western VentureShad,American 25 1
29 231 Western VentureShad,American 28 2
30 231 Western VentureShad,American 29 2

My code is:
myfun-function (x) x/sum(x)
b-with(data,aggregate(x=list(Percent=Count),by=list(Trip_id=Trip_id,Length=Length,Species=CommonName),
FUN=myfun))

My issue is that the percent is not be calculated by Trip_id and CommonName.
The result is that each row has a percent of 1 indicating that myfun is not
dividing by the sum of counts with a Trip_id/CommonName group.  Any help
would be appreciated.
Thank you





--
View this message in context: 
http://r.789695.n4.nabble.com/trying-ti-use-a-function-in-aggregate-tp4647414.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] trying ti use a function in aggregate

2012-10-25 Thread arun
Hi,
May be this helps:
dat1-read.table(text=
 Trip_id  Vessel  CommonName Length Count
1  230    Sunlight    ShadAmerican    19    1
2  230    Sunlight    ShadAmerican    20    1
3  230    Sunlight    ShadAmerican    21    1
4  230    Sunlight    ShadAmerican    23    1
5  230    Sunlight    ShadAmerican    26    1
6  230    Sunlight    ShadAmerican    27    1
7  230    Sunlight    ShadAmerican    30    2
8  230    Sunlight    ShadAmerican    33    1
9  230    Sunlight    ShadAmerican    34    1
10    230    Sunlight    ShadAmerican    37    1
11    230    Sunlight HerringBlueback    20    1
12    230    Sunlight HerringBlueback    21    2
13    230    Sunlight HerringBlueback    22    5
14    230    Sunlight HerringBlueback    26    1
15    230    Sunlight  Alewife    17    1
16    230    Sunlight  Alewife    18    1
17    230    Sunlight  Alewife    20    2
18    230    Sunlight  Alewife    21    4
19    230    Sunlight  Alewife    22    16
20    230    Sunlight  Alewife    23    22
21    230    Sunlight  Alewife    24    16
22    230    Sunlight  Alewife    25    4
23    230    Sunlight  Alewife    26    1
24    230    Sunlight  Alewife    27    2
25    230    Sunlight  Alewife    28    2
26    231 Western_Venture    ShadAmerican    23    1
27    231 Western_Venture    ShadAmerican    24    1
28    231 Western_Venture    ShadAmerican    25    1
29    231 Western_Venture    ShadAmerican    28    2
30    231 Western_Venture    ShadAmerican    29    2
,sep=,header=TRUE,stringsAsFactors=FALSE)

with(dat1,aggregate(Count,by=list(Trip_id=Trip_id,Species=CommonName),function(x)
 x/sum(x)))
  Trip_id Species
1 230 Alewife
2 230 HerringBlueback
3 230    ShadAmerican
4 231    ShadAmerican
  
 x
#1 0.01408451, 0.01408451, 0.02816901, 0.05633803, 0.22535211, 0.30985915, 
0.22535211, 0.05633803, 0.01408451, 0.02816901, 0.02816901
#2
 0.111, 0.222, 0.556, 0.111
#3 0.09090909, 0.09090909, 0.09090909, 0.09090909, 0.09090909, 
0.09090909, 0.18181818, 0.09090909, 0.09090909, 0.09090909
#4  
0.1428571, 0.1428571, 0.1428571, 0.2857143, 0.2857143
#or 
library(plyr)
res-ddply(dat1,.(Trip_id=Trip_id,Vessel=Vessel,CommonName=CommonName), 
summarize, Count/sum(Count))
colnames(res)[4]-value
head(res)
#  Trip_id   Vessel CommonName  value
#1 230 Sunlight    Alewife 0.01408451
#2 230 Sunlight    Alewife 0.01408451
#3 230 Sunlight    Alewife 0.02816901
#4 230 Sunlight    Alewife 0.05633803
#5 230 Sunlight    Alewife 0.22535211
#6 230 Sunlight    Alewife 0.30985915


A.K.






- Original Message -
From: Sally_roman sro...@umassd.edu
To: r-help@r-project.org
Cc: 
Sent: Thursday, October 25, 2012 10:19 AM
Subject: [R] trying ti use a function in aggregate

Hi -I am using R v 2.13.0.  I am trying to use the aggregate function to
calculate the percent at length for each Trip_id and CommonName.  Here is a
small subset of the data.  
   Trip_id          Vessel       CommonName Length Count
1      230        Sunlight    Shad,American     19     1
2      230        Sunlight    Shad,American     20     1
3      230        Sunlight    Shad,American     21     1
4      230        Sunlight    Shad,American     23     1
5      230        Sunlight    Shad,American     26     1
6      230        Sunlight    Shad,American     27     1
7      230        Sunlight    Shad,American     30     2
8      230        Sunlight    Shad,American     33     1
9      230        Sunlight    Shad,American     34     1
10     230        Sunlight    Shad,American     37     1
11     230        Sunlight Herring,Blueback     20     1
12     230        Sunlight Herring,Blueback     21     2
13     230        Sunlight Herring,Blueback     22     5
14     230        Sunlight Herring,Blueback     26     1
15     230        Sunlight          Alewife     17     1
16     230        Sunlight          Alewife     18     1
17     230        Sunlight          Alewife     20     2
18     230        Sunlight          Alewife     21     4
19     230        Sunlight          Alewife     22    16
20     230        Sunlight          Alewife     23    22
21     230        Sunlight          Alewife     24    16
22     230        Sunlight          Alewife     25     4
23     230        Sunlight          Alewife     26     1
24     230        Sunlight          Alewife     27     2
25     230        Sunlight          Alewife     28     2
26     231 Western Venture    

Re: [R] Change to daily digest

2012-10-25 Thread Mohamed Radhouane Aniba
Which one ? :)


On Oct 25, 2012, at 2:34 PM, R. Michael Weylandt michael.weyla...@gmail.com 
michael.weyla...@gmail.com wrote:

 
 
 On Oct 25, 2012, at 7:30 PM, Mohamed Radhouane Aniba arad...@gmail.com 
 wrote:
 
 Hello folks,
 
 I am currently receiving a lot of emails from the list which proves that 
 this is a very important place to get good feedbacks and tips and that the 
 community is here to help .. Excellent thing.
 I am not though able to login to my subscriber space to change the email 
 reception into daily digest, or I am not looking to the right place, if 
 someone can point me to the right URL that would be very appreciated.
 
 Cheers
 
 Rad
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 
  follow this link
 
 RMW
 
 
 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] mean of a value of the last 2 hours

2012-10-25 Thread Felipe Carrillo
Or using ddply from plyr,
 
library(plyr)
myframe - data.frame (ID=c(Ernie, Ernie, Ernie, Bert, Bert,
Bert), Timestamp=c(24.09.2012 09:00, 24.09.2012 10:00, 24.09.2012
11:00), Hunger=c(1,1,1,2,2,1) )
myframe
myframestime - as.POSIXct (strptime(as.character(myframe$Timestamp),
%d.%m.%Y %H:%M), tz=GMT)
myframestime
myframe2 - cbind (myframe,myframestime)
myframe2
ddply(myframe2,.(ID),summarise,Last2=mean(tail(Hunger,2)))


Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: Tagmarie ramga...@gmx.net
To: r-help@r-project.org 
Sent: Thursday, October 25, 2012 7:35 AM
Subject: [R] mean of a value of the last 2 hours

Hello, 
I have a data frame somewhat like that: 

myframe - data.frame (ID=c(Ernie, Ernie, Ernie, Bert, Bert,
Bert), Timestamp=c(24.09.2012 09:00, 24.09.2012 10:00, 24.09.2012
11:00), Hunger=c(1,1,1,2,2,1) )
myframestime - as.POSIXct (strptime(as.character(myframe$Timestamp),
%d.%m.%Y %H:%M), tz=GMT)
myframe2 - cbind (myframe,myframestime)
myframe2$Timestamp - NULL  
myframe2

I want to add an additional column at the right and get in each row a value
which shows the mean of hunger of the last two hours. 

Does anyone know how that works? That would be very helpful. 



--
View this message in context: 
http://r.789695.n4.nabble.com/mean-of-a-value-of-the-last-2-hours-tp4647415.html
Sent from the R help mailing list archive at Nabble.com.

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



[[alternative HTML version deleted]]

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


Re: [R] Change to daily digest

2012-10-25 Thread R. Michael Weylandt michael.weyla...@gmail.com


On Oct 25, 2012, at 7:30 PM, Mohamed Radhouane Aniba arad...@gmail.com wrote:

 Hello folks,
 
 I am currently receiving a lot of emails from the list which proves that this 
 is a very important place to get good feedbacks and tips and that the 
 community is here to help .. Excellent thing.
 I am not though able to login to my subscriber space to change the email 
 reception into daily digest, or I am not looking to the right place, if 
 someone can point me to the right URL that would be very appreciated.
 
 Cheers
 
 Rad
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help

 follow this link

RMW


 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] trying ti use a function in aggregate

2012-10-25 Thread Jean V Adams
Sally,

It's great that you provided data and code.  To make it even more 
user-friendly for R-help readers, supply your data as Rcode, using (for 
example) the dput() function.

The reason you were getting all 1s with your code, is that you had told it 
to aggregate by trip, LENGTH, and species.  But the data are already 
summarized by trip, LENGTH, and species, so your myfun() function is 
calculating the count/count=1 for each row.  You could get rid of LENGTH 
to use your myfun() function, but the results aren't pretty ...

with(data, aggregate(data.frame(Total=Count), data.frame(Trip_id, 
CommonName), myfun))

Instead, I suggest you can use the aggregate function to calculate the 
total counts, then merge these totals with your original data to calculate 
the proportions.

# small subset of data
data - structure(list(Trip_id = c(230L, 230L, 230L, 230L, 230L, 230L, 
230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 
230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 231L, 231L, 231L, 
231L, 231L), Vessel = c(Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Western Venture, Western Venture, 
Western Venture, Western Venture, Western Venture), CommonName = 
c(Shad,American, 
Shad,American, Shad,American, Shad,American, Shad,American, 
Shad,American, Shad,American, Shad,American, Shad,American, 
Shad,American, Herring,Blueback, Herring,Blueback, 
Herring,Blueback, 
Herring,Blueback, Alewife, Alewife, Alewife, Alewife, 
Alewife, Alewife, Alewife, Alewife, Alewife, Alewife, 
Alewife, Shad,American, Shad,American, Shad,American, 
Shad,American, Shad,American), Length = c(19L, 20L, 21L, 
23L, 26L, 27L, 30L, 33L, 34L, 37L, 20L, 21L, 22L, 26L, 17L, 18L, 
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 23L, 24L, 25L, 28L, 
29L), Count = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 
5L, 1L, 1L, 1L, 2L, 4L, 16L, 22L, 16L, 4L, 1L, 2L, 2L, 1L, 1L, 
1L, 2L, 2L)), .Names = c(Trip_id, Vessel, CommonName, Length, 
Count), row.names = c(NA, -30L), class = data.frame)

# calculate the total count for each trip and Species
agg - with(data, aggregate(data.frame(Total=Count), data.frame(Trip_id, 
CommonName), sum))

# combine the totals with the full data frame
data2 - merge(data, agg)

# then calculate proportions
data2$Prop - data2$Count/data2$Total

data2


Jean



Sally_roman sro...@umassd.edu wrote on 10/25/2012 09:19:57 AM:
 
 Hi -I am using R v 2.13.0.  I am trying to use the aggregate function to
 calculate the percent at length for each Trip_id and CommonName.  Here 
is a
 small subset of the data. 
Trip_id  Vessel   CommonName Length Count
 1  230SunlightShad,American 19 1
 2  230SunlightShad,American 20 1
 3  230SunlightShad,American 21 1
 4  230SunlightShad,American 23 1
 5  230SunlightShad,American 26 1
 6  230SunlightShad,American 27 1
 7  230SunlightShad,American 30 2
 8  230SunlightShad,American 33 1
 9  230SunlightShad,American 34 1
 10 230SunlightShad,American 37 1
 11 230Sunlight Herring,Blueback 20 1
 12 230Sunlight Herring,Blueback 21 2
 13 230Sunlight Herring,Blueback 22 5
 14 230Sunlight Herring,Blueback 26 1
 15 230Sunlight  Alewife 17 1
 16 230Sunlight  Alewife 18 1
 17 230Sunlight  Alewife 20 2
 18 230Sunlight  Alewife 21 4
 19 230Sunlight  Alewife 2216
 20 230Sunlight  Alewife 2322
 21 230Sunlight  Alewife 2416
 22 230Sunlight  Alewife 25 4
 23 230Sunlight  Alewife 26 1
 24 230Sunlight  Alewife 27 2
 25 230Sunlight  Alewife 28 2
 26 231 Western VentureShad,American 23 1
 27 231 Western VentureShad,American 24 1
 28 231 Western VentureShad,American 25 1
 29 231 Western VentureShad,American 28 2
 30 231 Western VentureShad,American 29 2
 
 My code is:
 myfun-function (x) x/sum(x)
 b-with(data,aggregate(x=list(Percent=Count),by=list
 (Trip_id=Trip_id,Length=Length,Species=CommonName),
 FUN=myfun))
 
 My issue is that the percent is not be calculated by Trip_id and 
CommonName. 
 The result is that each row has a percent of 1 indicating that myfun is 
not
 dividing by the sum of counts with a Trip_id/CommonName group.  Any help
 would be appreciated.
 Thank you 


Re: [R] trying ti use a function in aggregate

2012-10-25 Thread arun
Hi,
Try this:
dat1$Percent-unlist(tapply(dat1$Count,list(dat1$Trip_id,dat1$CommonName),function(x)
 x/sum(x)))
head(dat1)
#  Trip_id   Vessel   CommonName Length Count    Percent
#1 230 Sunlight ShadAmerican 19 1 0.01408451
#2 230 Sunlight ShadAmerican 20 1 0.01408451
#3 230 Sunlight ShadAmerican 21 1 0.02816901
#4 230 Sunlight ShadAmerican 23 1 0.05633803
#5 230 Sunlight ShadAmerican 26 1 0.22535211
#6 230 Sunlight ShadAmerican 27 1 0.30985915

I also have a doubt from your first email. 

 I am trying to use the aggregate function to
calculate the percent at length for each Trip_id and CommonName. 

So, I am thinking you need the percentage of length.  If that is the case,
res1-with(dat1,aggregate(Count,by=list(Trip_id=Trip_id,CommonName=CommonName),function(x)
 length(x)))
library(plyr) 
res1$Percent-ddply(res1,.(Trip_id),summarize,x/sum(x))[,2]
 res1
#  Trip_id  CommonName  x Percent
#1 230 Alewife 11    0.44
#2 230 HerringBlueback  4    0.16
#3 230    ShadAmerican 10    0.40
#4 231    ShadAmerican  5    1.00
 A.K.







From: Sally A Roman sro...@umassd.edu
To: arun smartpink...@yahoo.com 
Sent: Thursday, October 25, 2012 12:44 PM
Subject: Re: [R] trying ti use a function in aggregate


Thank you for your help.  Your code does what I need it to, but the output that 
I need is
Trip_id, Vessel, CommonName, Length, Percent.  When I run your functions there 
is no length output.  Do you have any suggestions on how to get the Length 
variable into the output?
Thanks again- Sally



From: arun smartpink...@yahoo.com
To: Sally_roman sro...@umassd.edu
Cc: R help r-help@r-project.org
Sent: Thursday, October 25, 2012 12:04:23 PM
Subject: Re: [R] trying ti use a function in aggregate

Hi,
May be this helps:
dat1-read.table(text=
 Trip_id  Vessel  CommonName Length Count
1  230    Sunlight    ShadAmerican    19    1
2  230    Sunlight    ShadAmerican    20    1
3  230    Sunlight    ShadAmerican    21    1
4  230    Sunlight    ShadAmerican    23    1
5  230    Sunlight    ShadAmerican    26    1
6  230    Sunlight    ShadAmerican    27    1
7  230    Sunlight    ShadAmerican    30    2
8  230    Sunlight    ShadAmerican    33    1
9  230    Sunlight    ShadAmerican    34    1
10    230    Sunlight    ShadAmerican    37    1
11    230    Sunlight HerringBlueback    20    1
12    230    Sunlight HerringBlueback    21    2
13    230    Sunlight HerringBlueback    22    5
14    230    Sunlight HerringBlueback    26    1
15    230    Sunlight  Alewife    17    1
16    230    Sunlight  Alewife    18    1
17    230    Sunlight  Alewife    20    2
18    230    Sunlight  Alewife    21    4
19    230    Sunlight  Alewife    22    16
20    230    Sunlight  Alewife    23    22
21    230    Sunlight  Alewife    24    16
22    230    Sunlight  Alewife    25    4
23    230    Sunlight  Alewife    26    1
24    230    Sunlight  Alewife    27    2
25    230    Sunlight  Alewife    28    2
26    231 Western_Venture    ShadAmerican    23    1
27    231 Western_Venture    ShadAmerican    24    1
28    231 Western_Venture    ShadAmerican    25    1
29    231 Western_Venture    ShadAmerican    28    2
30    231 Western_Venture    ShadAmerican    29    2
,sep=,header=TRUE,stringsAsFactors=FALSE)

with(dat1,aggregate(Count,by=list(Trip_id=Trip_id,Species=CommonName),function(x)
 x/sum(x)))
  Trip_id Species
1 230 Alewife
2 230 HerringBlueback
3 230    ShadAmerican
4 231    ShadAmerican
  
 x
#1 0.01408451, 0.01408451, 0.02816901, 0.05633803, 0.22535211, 0.30985915, 
0.22535211, 0.05633803, 0.01408451, 0.02816901, 0.02816901
#2
 0.111, 0.222, 0.556, 0.111
#3 0.09090909, 0.09090909, 0.09090909, 0.09090909, 0.09090909, 
0.09090909, 0.18181818, 0.09090909, 0.09090909, 0.09090909
#4  
0.1428571, 0.1428571, 0.1428571, 0.2857143, 0.2857143
#or 
library(plyr)
res-ddply(dat1,.(Trip_id=Trip_id,Vessel=Vessel,CommonName=CommonName), 
summarize, Count/sum(Count))
colnames(res)[4]-value
head(res)
#  Trip_id   Vessel CommonName  value
#1 230 Sunlight    Alewife 0.01408451
#2 230 Sunlight    Alewife 0.01408451
#3 230 Sunlight    Alewife 0.02816901
#4 230 Sunlight    Alewife 0.05633803
#5 230 Sunlight    Alewife 0.22535211
#6 230 Sunlight    Alewife 0.30985915


A.K.






- 

[R] How to extract auc, specificity and sensitivity

2012-10-25 Thread Adel Powell
I am running my code in a loop and it does not work but when I run it
outside the loop I get the values I want.

n - 1000; # Sample size

fitglm - function(sigma,tau){
x - rnorm(n,0,sigma)
intercept - 0
beta - 0
ystar - intercept+beta*x
z - rbinom(n,1,plogis(ystar))
xerr - x + rnorm(n,0,tau)
model-glm(z ~ xerr, family=binomial(logit))
int-coef(model)[1]
slope-coef(model)[2]
pred-predict(model)

result-ifelse(pred.5,1,0)

accuracy-length(which(result==z))/length(z)
accuracy

rocpreds-prediction(result,z)
auc-performance(rocpreds,auc)@y.values
sentiv-performance(rocpreds,sens)@y.values
sentiv-slot(fp,y.values)[[1]]
sentiv-sentiv[2]
sentiv
specs-performance(rocpreds,spec)@y.values
specs-slot(fp2,y.values)[[1]]
specs-specs[2]
specs
output-c(int,slope,.5,accuracy,auc,sentiv,specs)

names(output)-c(Intercept,Slope,CutPoint,Accuracy,AUC,Sentivity,Specificity)
return(output)

}

y-fitglm(.05,1)
y


The code runs without the sentiv and specs but when I remove the loop i can
get the sensitivity and spec. values ???

[[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 extract auc, specificity and sensitivity

2012-10-25 Thread Berend Hasselman

On 25-10-2012, at 21:28, Adel Powell wrote:

 I am running my code in a loop and it does not work but when I run it
 outside the loop I get the values I want.
 
 n - 1000; # Sample size
 
 fitglm - function(sigma,tau){
x - rnorm(n,0,sigma)
intercept - 0
beta - 0
ystar - intercept+beta*x
z - rbinom(n,1,plogis(ystar))
xerr - x + rnorm(n,0,tau)
model-glm(z ~ xerr, family=binomial(logit))
int-coef(model)[1]
slope-coef(model)[2]
pred-predict(model)
 
result-ifelse(pred.5,1,0)
 
accuracy-length(which(result==z))/length(z)
accuracy
 
rocpreds-prediction(result,z)
auc-performance(rocpreds,auc)@y.values
sentiv-performance(rocpreds,sens)@y.values
sentiv-slot(fp,y.values)[[1]]
sentiv-sentiv[2]
sentiv
specs-performance(rocpreds,spec)@y.values
specs-slot(fp2,y.values)[[1]]
specs-specs[2]
specs
output-c(int,slope,.5,accuracy,auc,sentiv,specs)
 
 names(output)-c(Intercept,Slope,CutPoint,Accuracy,AUC,Sentivity,Specificity)

A missing  before Specificity?

return(output)
 
 }
 
 y-fitglm(.05,1)
 y
 

Running this after correction of the missing   one gets en error

Error in fitglm(0.05, 1) : could not find function prediction

How are you using a loop?
Your example is not reproducible.

Berend


 
 The code runs without the sentiv and specs but when I remove the loop i can
 get the sensitivity and spec. values ???
 
   [[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] How to extract auc, specificity and sensitivity

2012-10-25 Thread Berend Hasselman


Your code is still not runnable.
It gives the error message

Error in fitglm(0.05, 1) : could not find function prediction

Berend

On 25-10-2012, at 21:55, Adel Powell wrote:

 I think I have corrected it. Can you tell me are my spec and sens values 
 correct
 n - 1000; # Sample size
  
 fitglm - function(sigma,tau){
 x - rnorm(n,0,sigma)
 intercept - 0
 beta - 0
 ystar - intercept+beta*x
 z - rbinom(n,1,plogis(ystar))
 xerr - x + rnorm(n,0,tau)  
 model-glm(z ~ xerr, family=binomial(logit))
 int-coef(model)[1]
 slope-coef(model)[2]
 pred-predict(model)
 
 result-ifelse(pred.5,1,0)  
 
 accuracy-length(which(result==z))/length(z)
 accuracy
 
 rocpreds-prediction(result,z)
 auc-performance(rocpreds,auc)@y.values
 fp-performance(rocpreds,sens)
 sentiv-slot(fp,y.values)[[1]]
 sentiv-sentiv[2]
 sentiv
 fp2-performance(rocpreds,spec)
 specs-slot(fp2,y.values)[[1]]
 specs-specs[2]
 specs
 output-c(int,slope,.5,accuracy,auc,sentiv,specs)
 
 names(output)-c(Intercept,Slope,CutPoint,Accuracy,AUC,Sentivity,Specificity)
 return(output)
 
 }
 
 y-fitglm(.05,1)
 y
 
 
 On Thu, Oct 25, 2012 at 3:43 PM, Berend Hasselman b...@xs4all.nl wrote:
 
 On 25-10-2012, at 21:28, Adel Powell wrote:
 
  I am running my code in a loop and it does not work but when I run it
  outside the loop I get the values I want.
 
  n - 1000; # Sample size
 
  fitglm - function(sigma,tau){
 x - rnorm(n,0,sigma)
 intercept - 0
 beta - 0
 ystar - intercept+beta*x
 z - rbinom(n,1,plogis(ystar))
 xerr - x + rnorm(n,0,tau)
 model-glm(z ~ xerr, family=binomial(logit))
 int-coef(model)[1]
 slope-coef(model)[2]
 pred-predict(model)
 
 result-ifelse(pred.5,1,0)
 
 accuracy-length(which(result==z))/length(z)
 accuracy
 
 rocpreds-prediction(result,z)
 auc-performance(rocpreds,auc)@y.values
 sentiv-performance(rocpreds,sens)@y.values
 sentiv-slot(fp,y.values)[[1]]
 sentiv-sentiv[2]
 sentiv
 specs-performance(rocpreds,spec)@y.values
 specs-slot(fp2,y.values)[[1]]
 specs-specs[2]
 specs
 output-c(int,slope,.5,accuracy,auc,sentiv,specs)
 
  names(output)-c(Intercept,Slope,CutPoint,Accuracy,AUC,Sentivity,Specificity)
 
 A missing  before Specificity?
 
 return(output)
 
  }
 
  y-fitglm(.05,1)
  y
 
 
 Running this after correction of the missing   one gets en error
 
 Error in fitglm(0.05, 1) : could not find function prediction
 
 How are you using a loop?
 Your example is not reproducible.
 
 Berend
 
 
 
  The code runs without the sentiv and specs but when I remove the loop i can
  get the sensitivity and spec. values ???
 
[[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 

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


[R] Estimating credit card default probabilities.

2012-10-25 Thread Keith Weintraub
Folks,
I am working on a credit card defaults and transition probabilities. For 
example a single credit card account could be in a number of states: 
up-to-date, 30, 60, 90 days in arrears or in default.

* Are there packages in R that do estimation of the transition probabilities 
given historical cohort defaults?
* Any pointers to papers specific to this type of estimation?
* Simulation of future paths of defaults.

I know this is not strictly an R question so please feel free to slam me.

Afterwards I would appreciate any pointers you might have.

Thanks much for your time,
KW

--


[[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] Change to daily digest

2012-10-25 Thread Ben Bolker
Mohamed Radhouane Aniba aradwen at gmail.com writes:

 
 Which one ? :)
 

https://stat.ethz.ch/mailman/listinfo/r-help

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


Re: [R] How to extract auc, specificity and sensitivity

2012-10-25 Thread Adel Powell
 n - 10; # Sample size

 fitglm - function(sigma,tau){
+ x - rnorm(n,0,sigma)
+ intercept - 0
+ beta - 0
+ ystar - intercept+beta*x
+ z - rbinom(n,1,plogis(ystar))
+ xerr - x + rnorm(n,0,tau)
+ model-glm(z ~ xerr, family=binomial(logit))
+ int-coef(model)[1]
+ slope-coef(model)[2]
+ pred-predict(model)
+
+ result-ifelse(pred.5,1,0)
+
+ accuracy-length(which(result==z))/length(z)
+ accuracy
+
+ rocpreds-prediction(result,z)
+ auc-performance(rocpreds,auc)@y.values
+ fp-performance(rocpreds,sens)
+ sentiv-slot(fp,y.values)[[1]]
+ sentiv-sentiv[2]
+ sentiv
+ fp2-performance(rocpreds,spec)
+ specs-slot(fp2,y.values)[[1]]
+ specs-specs[2]
+ specs
+ output-c(int,slope,.5,accuracy,auc,sentiv,specs)
+
names(output)-c(Intercept,Slope,CutPoint,Accuracy,AUC,Sentivity,Specificity)
+ return(output)
+
+ }

 y-fitglm(2,1)
 y
$Intercept
[1] 1.335284

$Slope
[1] 0.1562984

$CutPoint
[1] 0.5

$Accuracy
[1] 0.8

$AUC
[1] 0.5

$Sentivity
[1] 1

$Specificity
[1] 0



Don't get error message but wrong values

On Thu, Oct 25, 2012 at 4:05 PM, Berend Hasselman b...@xs4all.nl wrote:



 Your code is still not runnable.
 It gives the error message

 Error in fitglm(0.05, 1) : could not find function prediction

 Berend

 On 25-10-2012, at 21:55, Adel Powell wrote:

  I think I have corrected it. Can you tell me are my spec and sens values
 correct
  n - 1000; # Sample size
 
  fitglm - function(sigma,tau){
  x - rnorm(n,0,sigma)
  intercept - 0
  beta - 0
  ystar - intercept+beta*x
  z - rbinom(n,1,plogis(ystar))
  xerr - x + rnorm(n,0,tau)
  model-glm(z ~ xerr, family=binomial(logit))
  int-coef(model)[1]
  slope-coef(model)[2]
  pred-predict(model)
 
  result-ifelse(pred.5,1,0)
 
  accuracy-length(which(result==z))/length(z)
  accuracy
 
  rocpreds-prediction(result,z)
  auc-performance(rocpreds,auc)@y.values
  fp-performance(rocpreds,sens)
  sentiv-slot(fp,y.values)[[1]]
  sentiv-sentiv[2]
  sentiv
  fp2-performance(rocpreds,spec)
  specs-slot(fp2,y.values)[[1]]
  specs-specs[2]
  specs
  output-c(int,slope,.5,accuracy,auc,sentiv,specs)
 
 names(output)-c(Intercept,Slope,CutPoint,Accuracy,AUC,Sentivity,Specificity)
  return(output)
 
  }
 
  y-fitglm(.05,1)
  y
 
 
  On Thu, Oct 25, 2012 at 3:43 PM, Berend Hasselman b...@xs4all.nl wrote:
 
  On 25-10-2012, at 21:28, Adel Powell wrote:
 
   I am running my code in a loop and it does not work but when I run it
   outside the loop I get the values I want.
  
   n - 1000; # Sample size
  
   fitglm - function(sigma,tau){
  x - rnorm(n,0,sigma)
  intercept - 0
  beta - 0
  ystar - intercept+beta*x
  z - rbinom(n,1,plogis(ystar))
  xerr - x + rnorm(n,0,tau)
  model-glm(z ~ xerr, family=binomial(logit))
  int-coef(model)[1]
  slope-coef(model)[2]
  pred-predict(model)
  
  result-ifelse(pred.5,1,0)
  
  accuracy-length(which(result==z))/length(z)
  accuracy
  
  rocpreds-prediction(result,z)
  auc-performance(rocpreds,auc)@y.values
  sentiv-performance(rocpreds,sens)@y.values
  sentiv-slot(fp,y.values)[[1]]
  sentiv-sentiv[2]
  sentiv
  specs-performance(rocpreds,spec)@y.values
  specs-slot(fp2,y.values)[[1]]
  specs-specs[2]
  specs
  output-c(int,slope,.5,accuracy,auc,sentiv,specs)
  
  
 names(output)-c(Intercept,Slope,CutPoint,Accuracy,AUC,Sentivity,Specificity)
 
  A missing  before Specificity?
 
  return(output)
  
   }
  
   y-fitglm(.05,1)
   y
  
 
  Running this after correction of the missing   one gets en error
 
  Error in fitglm(0.05, 1) : could not find function prediction
 
  How are you using a loop?
  Your example is not reproducible.
 
  Berend
 
 
  
   The code runs without the sentiv and specs but when I remove the loop
 i can
   get the sensitivity and spec. values ???
  
 [[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] Estimating credit card default probabilities.

2012-10-25 Thread Bert Gunter
You might have better luck posting on stats.stackexchange.com, a
statistical help list.

-- Bert

On Thu, Oct 25, 2012 at 1:08 PM, Keith Weintraub kw1...@gmail.com wrote:
 Folks,
 I am working on a credit card defaults and transition probabilities. For 
 example a single credit card account could be in a number of states: 
 up-to-date, 30, 60, 90 days in arrears or in default.

 * Are there packages in R that do estimation of the transition probabilities 
 given historical cohort defaults?
 * Any pointers to papers specific to this type of estimation?
 * Simulation of future paths of defaults.

 I know this is not strictly an R question so please feel free to slam me.

 Afterwards I would appreciate any pointers you might have.

 Thanks much for your time,
 KW

 --


 [[alternative HTML version deleted]]

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] R5: Lock a class field from within a method?

2012-10-25 Thread Johannes Graumann
David Winsemius wrote:

 
 On Oct 24, 2012, at 2:14 AM, Johannes Graumann wrote:
 
 Hello,

 testclass - setRefClass(
  testclass,
  fields = list(testfield = logical),
  methods = list(validate=function(){testfield-TRUE}))

 test - testclass$new()
 test$testfield
 logical(0)
 test$validate()
 test$testfield
 [1] TRUE

 Works just fine for me.

 I would love to be able to do something like

 testclass - setRefClass(
  testclass,
  fields = list(testfield = logical),
  methods = list(validate=function(){
 testfield-TRUE
 .self$lock(testfield)
  }))

 but am unabel to achieve that. Can anyone point out how to go about
 rendering a field immutable after execution of a specific method?

 
 The fact that you used only lock in your code and I am unable to
 find such a function makes me wonder whether that was an implicit
 psuedo-code effort and that you do not know about:
 
 ?lockBinding

lockbinding does in fact what I want, but your statement about pseudo-code 
is not entirely correct ... try the following (?setRefClass will light the 
way).

 testclass - setRefClass(
   testclass,
   fields = list(testfield = logical))
 testclass$lock(testfield)
 test - testclass$new()
 test$testfield - TRUE
 test$testfield - FALSE

I was assuming to be able to have access to the lock method from a class 
instance as well (rather than just in the class definition) ... Is that 
indeed impossible?

Cheers, Joh

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


[R] How generate random numbers from given vector???

2012-10-25 Thread Rlotus
I wanna generate random numbers from a vector...

for example number-c(0,1,3,4,5,6,8)
 so
 
rsidp-function(x){
i=0
for (i in seq(1:x))

{y-sample(number,x, replace=T)}
return(y)
}
 so all random numbers have to be from vector number;
so if I type rsidp(5). it has to give me 5 random numbers except 2,7,9
(because they are not in the vector numbers). help me plz with it (((







--
View this message in context: 
http://r.789695.n4.nabble.com/How-generate-random-numbers-from-given-vector-tp4647447.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] ifelse reformulation

2012-10-25 Thread arun
Hi,

Did you mean this?
group1-c(40,50,60,70)
#or
group2-c(50,var1,var2,60)

In either of the above cases, when you check
str(group1) # all are converted to character.
# chr [1:4] 40 50 60 70

 str(group2)
# chr [1:4] 50 var1 var2 60

Suppose, I am comparing the test1 dataset (x4: x6 columns) with group2
 apply(test1,1,function(x) ifelse(x[5:7]%in%group2,0,1)) # 2nd row is 50 for x4 
column
   #  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#[1,] 1 0 1 1 1 1 1 1 1  1  1  1  1  1  1
#[2,] 1 1 1 1 1 1 1 1 1  1  1  1  1  1  1
#[3,] 1 1 1 1 1 1 1 1 1  1  1  1  1  1  1

# final result
as.vector(apply(test1,1,function(x) ifelse(any(x[5:7]%in%group2),0,1)))
# [1] 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1

I guess it works.

BTW, in my previous reply, I made a mistake
as.vector(apply(test1,1,function(x) ifelse(any(x[4:6]%in%group),0,1)))  
   ^^^ 
It should be 5:7.
group-c(40,50,60,70)
as.vector(apply(test1,1,function(x) ifelse(any(x[5:7]%in%group),0,1)))
 #[1] 1 0 1 1 1 1 0 1 1 1 1 1 0 1 1

ifelse(test1$x4==40|test1$x4==50|test1$x4==60|test1$x4==70|test1$x5==40|test1$x5==50|test1$x5==60|test1$x5==70|test1$x6==40|test1$x6==50|test1$x6==60|test1$x7==70,0,1)
# [1] 1 0 1 1 1 1 0 1 1 1 1 1 0 1 1

 as.vector(apply(test1,1,function(x) 
ifelse(any(x[5:7]==40|x[5:7]==50|x[5:7]==60|x[5:7]==70),0,1)))
 #[1] 1 0 1 1 1 1 0 1 1 1 1 1 0 1 1


A.K.


















- Original Message -
From: brunosm brunos...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Thursday, October 25, 2012 12:55 PM
Subject: Re: [R] ifelse reformulation

Arun, thank you very much... but a new problem arose...

What if... in the variable group that i want to compare, there is numeric
and non numeric types?

Or, if you think its better, can i have two variables, one numeric and one
non numeric, and made the comparision?

Best regards,

Bruno

2012/10/12 arun kirshna [via R] ml-node+s789695n4645988...@n4.nabble.com

 HI,
 Try this:
 test1-read.table(text=
    id x1 x2 x3 x4 x5 x6 x7
 1   1 36 26 21 32 31 27 31
 2   2 45 21 46 50 22 36 29
 3   3 49 47 35 44 33 31 46
 4   4 42 32 38 28 39 45 32
 5   5 29 42 39 48 25 35 34
 6   6 39 31 30 37 46 43 44
 7   7 41 40 25 23 42 40 24
 8   8 27 29 47 34 26 38 28
 9   9 25 35 29 36 43 34 23
 10 10 24 44 37 26 27 46 22
 11 11 38 50 32 49 37 24 40
 12 12 20 34 48 25 30 41 36
 13 13 26 46 20 40 29 20 43
 14 14 33 37 49 31 47 30 30
 15 15 43 39 27 35 48 47 27
 ,sep=,header=TRUE)
 count40-
 ifelse(test1$x1==40|test1$x2==40|test1$x3==40|test1$x4==40|test1$x5==40|test1$x6==40|test1$x7==40,0,1)

 count40
  #[1] 1 1 1 1 1 1 0 1 1 1 0 1 0 1 1
 #if you want to get the same result,
  apply(test1,1,function(x) ifelse(any(x==40),0,1))
 # 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
  #1  1  1  1  1  1  0  1  1  1  0  1  0  1  1
 A.K.





 --
  If you reply to this email, your message will be added to the discussion
 below:
 http://r.789695.n4.nabble.com/ifelse-reformulation-tp4645981p4645988.html
  To unsubscribe from ifelse reformulation, click 
herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4645981code=YnJ1bm9zbTg3QGdtYWlsLmNvbXw0NjQ1OTgxfDIwMjc4MjE3MDg=
 .
 NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml





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

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


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


Re: [R] trying ti use a function in aggregate

2012-10-25 Thread Sally_roman
Hi Jean - Thank you for your help. The code worked great. 

- Original Message -

From: Jean V Adams [via R] ml-node+s789695n4647444...@n4.nabble.com 
To: Sally_roman sro...@umassd.edu 
Sent: Thursday, October 25, 2012 2:48:45 PM 
Subject: Re: trying ti use a function in aggregate 

Sally, 

It's great that you provided data and code. To make it even more 
user-friendly for R-help readers, supply your data as Rcode, using (for 
example) the dput() function. 

The reason you were getting all 1s with your code, is that you had told it 
to aggregate by trip, LENGTH, and species. But the data are already 
summarized by trip, LENGTH, and species, so your myfun() function is 
calculating the count/count=1 for each row. You could get rid of LENGTH 
to use your myfun() function, but the results aren't pretty ... 

with(data, aggregate(data.frame(Total=Count), data.frame(Trip_id, 
CommonName), myfun)) 

Instead, I suggest you can use the aggregate function to calculate the 
total counts, then merge these totals with your original data to calculate 
the proportions. 

# small subset of data 
data - structure(list(Trip_id = c(230L, 230L, 230L, 230L, 230L, 230L, 
230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 
230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 231L, 231L, 231L, 
231L, 231L), Vessel = c(Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Western Venture, Western Venture, 
Western Venture, Western Venture, Western Venture), CommonName = 
c(Shad,American, 
Shad,American, Shad,American, Shad,American, Shad,American, 
Shad,American, Shad,American, Shad,American, Shad,American, 
Shad,American, Herring,Blueback, Herring,Blueback, 
Herring,Blueback, 
Herring,Blueback, Alewife, Alewife, Alewife, Alewife, 
Alewife, Alewife, Alewife, Alewife, Alewife, Alewife, 
Alewife, Shad,American, Shad,American, Shad,American, 
Shad,American, Shad,American), Length = c(19L, 20L, 21L, 
23L, 26L, 27L, 30L, 33L, 34L, 37L, 20L, 21L, 22L, 26L, 17L, 18L, 
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 23L, 24L, 25L, 28L, 
29L), Count = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 
5L, 1L, 1L, 1L, 2L, 4L, 16L, 22L, 16L, 4L, 1L, 2L, 2L, 1L, 1L, 
1L, 2L, 2L)), .Names = c(Trip_id, Vessel, CommonName, Length, 
Count), row.names = c(NA, -30L), class = data.frame) 

# calculate the total count for each trip and Species 
agg - with(data, aggregate(data.frame(Total=Count), data.frame(Trip_id, 
CommonName), sum)) 

# combine the totals with the full data frame 
data2 - merge(data, agg) 

# then calculate proportions 
data2$Prop - data2$Count/data2$Total 

data2 


Jean 



Sally_roman  [hidden email]  wrote on 10/25/2012 09:19:57 AM: 
 
 Hi -I am using R v 2.13.0. I am trying to use the aggregate function to 
 calculate the percent at length for each Trip_id and CommonName. Here 
is a 

 small subset of the data. 
 Trip_id Vessel CommonName Length Count 
 1 230 Sunlight Shad,American 19 1 
 2 230 Sunlight Shad,American 20 1 
 3 230 Sunlight Shad,American 21 1 
 4 230 Sunlight Shad,American 23 1 
 5 230 Sunlight Shad,American 26 1 
 6 230 Sunlight Shad,American 27 1 
 7 230 Sunlight Shad,American 30 2 
 8 230 Sunlight Shad,American 33 1 
 9 230 Sunlight Shad,American 34 1 
 10 230 Sunlight Shad,American 37 1 
 11 230 Sunlight Herring,Blueback 20 1 
 12 230 Sunlight Herring,Blueback 21 2 
 13 230 Sunlight Herring,Blueback 22 5 
 14 230 Sunlight Herring,Blueback 26 1 
 15 230 Sunlight Alewife 17 1 
 16 230 Sunlight Alewife 18 1 
 17 230 Sunlight Alewife 20 2 
 18 230 Sunlight Alewife 21 4 
 19 230 Sunlight Alewife 22 16 
 20 230 Sunlight Alewife 23 22 
 21 230 Sunlight Alewife 24 16 
 22 230 Sunlight Alewife 25 4 
 23 230 Sunlight Alewife 26 1 
 24 230 Sunlight Alewife 27 2 
 25 230 Sunlight Alewife 28 2 
 26 231 Western Venture Shad,American 23 1 
 27 231 Western Venture Shad,American 24 1 
 28 231 Western Venture Shad,American 25 1 
 29 231 Western Venture Shad,American 28 2 
 30 231 Western Venture Shad,American 29 2 
 
 My code is: 
 myfun-function (x) x/sum(x) 
 b-with(data,aggregate(x=list(Percent=Count),by=list 
 (Trip_id=Trip_id,Length=Length,Species=CommonName), 
 FUN=myfun)) 
 
 My issue is that the percent is not be calculated by Trip_id and CommonName. 
 The result is that each row has a percent of 1 indicating that myfun is 
not 
 dividing by the sum of counts with a Trip_id/CommonName group. Any help 
 would be appreciated. 
 Thank you 

[[alternative HTML version deleted]] 

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





If you reply to this email, your message will be added to 

Re: [R] trying ti use a function in aggregate

2012-10-25 Thread arun
HI,
In my previous solution, the order got messed up.  I should have ordered the 
columns.
Try this:
dat1-read.table(text=
 Trip_id  Vessel  CommonName Length Count
1  230    Sunlight    ShadAmerican    19    1
2  230    Sunlight    ShadAmerican    20    1
3  230    Sunlight    ShadAmerican    21    1
4  230    Sunlight    ShadAmerican    23    1
5  230    Sunlight    ShadAmerican    26    1
6  230    Sunlight    ShadAmerican    27    1
7  230    Sunlight    ShadAmerican    30    2
8  230    Sunlight    ShadAmerican    33    1
9  230    Sunlight    ShadAmerican    34    1
10    230    Sunlight    ShadAmerican    37    1
11    230    Sunlight HerringBlueback    20    1
12    230    Sunlight HerringBlueback    21    2
13    230    Sunlight HerringBlueback    22    5
14    230    Sunlight HerringBlueback    26    1
15    230    Sunlight  Alewife    17    1
16    230    Sunlight  Alewife    18    1
17    230    Sunlight  Alewife    20    2
18    230    Sunlight  Alewife    21    4
19    230    Sunlight  Alewife    22    16
20    230    Sunlight  Alewife    23    22
21    230    Sunlight  Alewife    24    16
22    230    Sunlight  Alewife    25    4
23    230    Sunlight  Alewife    26    1
24    230    Sunlight  Alewife    27    2
25    230    Sunlight  Alewife    28    2
26    231 Western_Venture    ShadAmerican    23    1
27    231 Western_Venture    ShadAmerican    24    1
28    231 Western_Venture    ShadAmerican    25    1
29    231 Western_Venture    ShadAmerican    28    2
30    231 Western_Venture    ShadAmerican    29    2
,sep=,header=TRUE,stringsAsFactors=FALSE)
dat2-dat1[order(dat1$Trip_id,dat1$Vessel,dat1$CommonName,dat1$Length,dat1$Count),]
dat3-dat2
dat3$Prop-unlist(tapply(dat3$Count,list(dat3$Trip_id,dat3$CommonName),function(x)
 x/sum(x)))


#Jean's method:

agg - with(dat2, aggregate(data.frame(Total=Count), data.frame(Trip_id,
CommonName), sum))
# combine the totals with the full data frame
data2 - merge(dat2, agg)
# then calculate proportions
data2$Prop - data2$Count/data2$Total
data3-data2[,-6]
data4-data3[,c(1,3,2,4:6)]
rownames(dat3)-1:nrow(dat3)
 identical(dat3,data4)
#[1] TRUE

head(dat3)
#  Trip_id   Vessel CommonName Length Count   Prop
#1 230 Sunlight    Alewife 17 1 0.01408451
#2 230 Sunlight    Alewife 18 1 0.01408451
#3 230 Sunlight    Alewife 20 2 0.02816901
#4 230 Sunlight    Alewife 21 4 0.05633803
#5 230 Sunlight    Alewife 22    16 0.22535211
#6 230 Sunlight    Alewife 23    22 0.30985915
 head(data4)
#  Trip_id   Vessel CommonName Length Count   Prop
#1 230 Sunlight    Alewife 17 1 0.01408451
#2 230 Sunlight    Alewife 18 1 0.01408451
#3 230 Sunlight    Alewife 20 2 0.02816901
#4 230 Sunlight    Alewife 21 4 0.05633803
#5 230 Sunlight    Alewife 22    16 0.22535211
#6 230 Sunlight    Alewife 23    22 0.30985915
A.K.





- Original Message -
From: Jean V Adams jvad...@usgs.gov
To: Sally_roman sro...@umassd.edu
Cc: r-help@r-project.org
Sent: Thursday, October 25, 2012 2:45 PM
Subject: Re: [R] trying ti use a function in aggregate

Sally,

It's great that you provided data and code.  To make it even more 
user-friendly for R-help readers, supply your data as Rcode, using (for 
example) the dput() function.

The reason you were getting all 1s with your code, is that you had told it 
to aggregate by trip, LENGTH, and species.  But the data are already 
summarized by trip, LENGTH, and species, so your myfun() function is 
calculating the count/count=1 for each row.  You could get rid of LENGTH 
to use your myfun() function, but the results aren't pretty ...

with(data, aggregate(data.frame(Total=Count), data.frame(Trip_id, 
CommonName), myfun))

Instead, I suggest you can use the aggregate function to calculate the 
total counts, then merge these totals with your original data to calculate 
the proportions.

# small subset of data
data - structure(list(Trip_id = c(230L, 230L, 230L, 230L, 230L, 230L, 
230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 
230L, 230L, 230L, 230L, 230L, 230L, 230L, 230L, 231L, 231L, 231L, 
231L, 231L), Vessel = c(Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, Sunlight, 
Sunlight, Sunlight, Sunlight, Western Venture, Western Venture, 
Western Venture, Western Venture, Western Venture), CommonName = 
c(Shad,American, 
Shad,American, Shad,American, Shad,American, Shad,American, 
Shad,American, Shad,American, Shad,American, Shad,American, 
Shad,American, Herring,Blueback, Herring,Blueback, 

Re: [R] How to extract auc, specificity and sensitivity

2012-10-25 Thread Adel Powell
n - 10; # Sample size

fitglm - function(sigma,tau){
x - rnorm(n,0,sigma)
intercept - 0
beta - 0
ystar - intercept+beta*x
z - rbinom(n,1,plogis(ystar))
xerr - x + rnorm(n,0,tau)
model-glm(z ~ xerr, family=binomial(logit))
int-coef(model)[1]
slope-coef(model)[2]
pred-predict(model)

result-ifelse(pred.5,1,0)

accuracy-length(which(result==z))/length(z)
accuracy

rocpreds-prediction(result,z)
auc-performance(rocpreds,auc)@y.values
fp-performance(rocpreds,sens)
sentiv-slot(fp,y.values)[[1]]
sentiv-sentiv[2]
sentiv
fp2-performance(rocpreds,spec)
specs-slot(fp2,y.values)[[1]]
specs-specs[2]
specs
output-c(int,slope,.5,accuracy,auc,sentiv,specs)

names(output)-c(Intercept,Slope,CutPoint,Accuracy,AUC,Sentivity,Specificity)
return(output)

}

y-fitglm(2,1)
y


I corrected the code. I am put everything in a loop because I am running
monte carlo reps outside of this later.

It works but the value returned is wrong.

Here is the manual manipulation:

* x - rnorm(10,0,2)*
* *

* intercept - 0*
* *

* beta - 5*
* *

* ystar - intercept+beta*x*
* *

* ystar*

 [1]  16.5436337   7.7740329 -10.1653928  -2.8338118 -21.5410780   2.6902171
5.1156558   5.0729933 -10.8556430   0.9208434

* test - plogis(ystar)*
* *

* test*

 [1] 9.99e-01 9.995797e-01 3.847772e-05 5.552417e-02 4.413963e-10
9.364469e-01 9.940338e-01 9.937753e-01 1.929504e-05 7.152139e-01

* z - rbinom(10,1,plogis(ystar))*
* *

* z*

 [1] 1 1 0 0 0 1 1 1 0 1

* xerr - x + rnorm(10,0,1) *
* *

* xerr*

 [1]  0.5610573  3.1741687 -2.3915066 -0.2546224 -4.1790037 -1.4387786
 1.4211227
-1.1141176 -1.6230087  0.7595021

* model-glm(z ~ xerr, family=binomial(logit))*
* *

* model*



Call:  glm(formula = z ~ xerr, family = binomial(logit))



Coefficients:

(Intercept) xerr

  1.5001.309

* int-coef(model)[1]*
* *

* slope-coef(model)[2]*
* *

*  pred1-predict(model)*
* *

* pred2-predict(model,type=response)*
* *

* pred1*

  1   2   3   4   5
6
7   8   9  10

 2.23478077  5.65499178 -1.62972799  1.16716581 -3.96932102 -0.38273530
3.36049056  0.04220225 -0.62386760  2.49451832

* pred2*

 1  2  3  4  5  6
7
8  9 10

0.90332965 0.99651221 0.16386763 0.76263234 0.01853617 0.40546735
0.96644669 0.51054900 0.34890234 0.92375664

* result-ifelse(pred2.5,1,0) *
* *

* result*

 1  2  3  4  5  6  7  8  9 10

 1  1  0  1  0  0  1  1  0  1

* accuracy-length(which(result==z))/length(z)*
* *

*  accuracy*

[1] 0.8

* rocpreds-prediction(result,z)*
* *

* rocpreds*

* auc-performance(rocpreds,auc)@y.values*
* *

* auc*

[[1]]

[1] 0.7916667

*  fp-performance(rocpreds,sens)*
* *

* sentiv-slot(fp,y.values)[[1]]*
* *

* sentiv-sentiv[2]*
* *

* sentiv*

[1] 0.833


* *

*  fp2-performance(rocpreds,spec)*
* *

* specs-slot(fp2,y.values)[[1]]*
* *

* specs*

[1] 1.00 0.75 0.00

* specs-specs[2]*
* *

* specs*

[1] 0.75
On Thu, Oct 25, 2012 at 3:43 PM, Berend Hasselman b...@xs4all.nl wrote:


 On 25-10-2012, at 21:28, Adel Powell wrote:

  I am running my code in a loop and it does not work but when I run it
  outside the loop I get the values I want.
 
  n - 1000; # Sample size
 
  fitglm - function(sigma,tau){
 x - rnorm(n,0,sigma)
 intercept - 0
 beta - 0
 ystar - intercept+beta*x
 z - rbinom(n,1,plogis(ystar))
 xerr - x + rnorm(n,0,tau)
 model-glm(z ~ xerr, family=binomial(logit))
 int-coef(model)[1]
 slope-coef(model)[2]
 pred-predict(model)
 
 result-ifelse(pred.5,1,0)
 
 accuracy-length(which(result==z))/length(z)
 accuracy
 
 rocpreds-prediction(result,z)
 auc-performance(rocpreds,auc)@y.values
 sentiv-performance(rocpreds,sens)@y.values
 sentiv-slot(fp,y.values)[[1]]
 sentiv-sentiv[2]
 sentiv
 specs-performance(rocpreds,spec)@y.values
 specs-slot(fp2,y.values)[[1]]
 specs-specs[2]
 specs
 output-c(int,slope,.5,accuracy,auc,sentiv,specs)
 
 
 names(output)-c(Intercept,Slope,CutPoint,Accuracy,AUC,Sentivity,Specificity)

 A missing  before Specificity?

 return(output)
 
  }
 
  y-fitglm(.05,1)
  y
 

 Running this after correction of the missing   one gets en error

 Error in fitglm(0.05, 1) : could not find function prediction

 How are you using a loop?
 Your example is not reproducible.

 Berend


 
  The code runs without the sentiv and specs but when I remove the loop i
 can
  get the sensitivity and spec. values ???
 
[[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]]


Re: [R] trying ti use a function in aggregate

2012-10-25 Thread arun
Hi Rui,

I thought the OP was looking for something like this:   May be I am wrong. 
dat2-dat1[order(dat1$Trip_id,dat1$Vessel,dat1$CommonName,dat1$Length,dat1$Count),]
dat3-dat2
dat3$Prop-unlist(tapply(dat3$Count,list(dat3$Trip_id,dat3$CommonName),function(x)
 x/sum(x)))
 head(dat3)
#  Trip_id   Vessel CommonName Length Count   Prop
#1 230 Sunlight    Alewife 17 1 0.01408451
#2 230 Sunlight    Alewife 18 1 0.01408451
#3 230 Sunlight    Alewife 20 2 0.02816901
#4 230 Sunlight    Alewife 21 4 0.05633803
#5 230 Sunlight    Alewife 22    16 0.22535211
#6 230 Sunlight    Alewife 23    22 0.30985915
A.K.




- Original Message -
From: Rui Barradas ruipbarra...@sapo.pt
To: Sally_roman sro...@umassd.edu
Cc: r-help@r-project.org
Sent: Thursday, October 25, 2012 11:59 AM
Subject: Re: [R] trying ti use a function in aggregate

Hello,
Try the following.
(I've changed your function a bit. And named the data.frame 'dat', not 
'data', which is an R function.)


myfun - function (x) ifelse(sum(x) == 0, 0, x/sum(x))

aggregate(Count ~ Trip_id + Length + CommonName, data = dat, myfun)

The output shows that each and every group corresponds to a single row 
of the original df. The 1's represent 100%, myfun _is_ dividing by 
sum(Count) Trip_id/Length/CommonName group. If you want just 
Trip_id/CommonName, use

aggregate(Count ~ Trip_id + CommonName, data = dat, myfun)


Or use your instruction without 'Length' in the by list:

b - with(dat, aggregate(x=list(Percent=Count),
by=list(Trip_id=Trip_id, Species=CommonName),
FUN = myfun))
b
   Trip_id          Species    Percent
1     230          Alewife 0.01408451
2     230 Herring,Blueback 0.
3     230    Shad,American 0.09090909
4     231    Shad,American 0.14285714

As you can see, the results are the same, with different output colnames.


Hope this helps,

Rui Barradas

Em 25-10-2012 15:19, Sally_roman escreveu:
 Hi -I am using R v 2.13.0.  I am trying to use the aggregate function to
 calculate the percent at length for each Trip_id and CommonName.  Here is a
 small subset of the data.
     Trip_id          Vessel       CommonName Length Count
 1      230        Sunlight    Shad,American     19     1
 2      230        Sunlight    Shad,American     20     1
 3      230        Sunlight    Shad,American     21     1
 4      230        Sunlight    Shad,American     23     1
 5      230        Sunlight    Shad,American     26     1
 6      230        Sunlight    Shad,American     27     1
 7      230        Sunlight    Shad,American     30     2
 8      230        Sunlight    Shad,American     33     1
 9      230        Sunlight    Shad,American     34     1
 10     230        Sunlight    Shad,American     37     1
 11     230        Sunlight Herring,Blueback     20     1
 12     230        Sunlight Herring,Blueback     21     2
 13     230        Sunlight Herring,Blueback     22     5
 14     230        Sunlight Herring,Blueback     26     1
 15     230        Sunlight          Alewife     17     1
 16     230        Sunlight          Alewife     18     1
 17     230        Sunlight          Alewife     20     2
 18     230        Sunlight          Alewife     21     4
 19     230        Sunlight          Alewife     22    16
 20     230        Sunlight          Alewife     23    22
 21     230        Sunlight          Alewife     24    16
 22     230        Sunlight          Alewife     25     4
 23     230        Sunlight          Alewife     26     1
 24     230        Sunlight          Alewife     27     2
 25     230        Sunlight          Alewife     28     2
 26     231 Western Venture    Shad,American     23     1
 27     231 Western Venture    Shad,American     24     1
 28     231 Western Venture    Shad,American     25     1
 29     231 Western Venture    Shad,American     28     2
 30     231 Western Venture    Shad,American     29     2

 My code is:
 myfun-function (x) x/sum(x)
 b-with(data,aggregate(x=list(Percent=Count),by=list(Trip_id=Trip_id,Length=Length,Species=CommonName),
 FUN=myfun))

 My issue is that the percent is not be calculated by Trip_id and CommonName.
 The result is that each row has a percent of 1 indicating that myfun is not
 dividing by the sum of counts with a Trip_id/CommonName group.  Any help
 would be appreciated.
 Thank you





 --
 View this message in context: 
 http://r.789695.n4.nabble.com/trying-ti-use-a-function-in-aggregate-tp4647414.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 

Re: [R] List of multidimensional arrays

2012-10-25 Thread pinki751
hello,
I want to make a two dimensional matrix from the data table.That data
table has three column 1st is userid,2nditemid and 3rd is rating
corresponding to the itemid given by userid.I want to make a m*n matrix in
which 'm' is userid and 'n' to be itemid .That 2D matrix should b filled
with that corresponding rating for that itemid for that userid. please help
me out. 



--
View this message in context: 
http://r.789695.n4.nabble.com/List-of-multidimensional-arrays-tp4647286p4647458.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] List of multidimensional arrays

2012-10-25 Thread Richard M. Heiberger
You are very lucky.  This question was answered last week in
https://stat.ethz.ch/pipermail/r-help/2012-October/326597.html

For the future, please read the posting guide referenced below and include
an example of your
data and the result of the calculation you would like to see.

Please use R-help directly and not the nabble interface.

On Thu, Oct 25, 2012 at 4:21 PM, pinki751 raj4technol...@gmail.com wrote:

 hello,
 I want to make a two dimensional matrix from the data table.That data
 table has three column 1st is userid,2nditemid and 3rd is rating
 corresponding to the itemid given by userid.I want to make a m*n matrix in
 which 'm' is userid and 'n' to be itemid .That 2D matrix should b filled
 with that corresponding rating for that itemid for that userid. please help
 me out.



 --
 View this message in context:
 http://r.789695.n4.nabble.com/List-of-multidimensional-arrays-tp4647286p4647458.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


Re: [R] How generate random numbers from given vector???

2012-10-25 Thread arun

Hi, 
Try this: 
number1-c(0,1,3,4,5,6,8) 
 rsidp-function(x){ 
 y-sample(x,5,replace=TRUE) 
 y 
 } 
 rsidp(number1) 
#[1] 3 0 6 8 4 
 rsidp(number1) 
#[1] 1 8 8 6 4 
 rsidp(number1) 
#[1] 8 3 6 6 6 
A.K. 


- Original Message -
From: Rlotus yerl...@hotmail.com
To: r-help@r-project.org
Cc: 
Sent: Thursday, October 25, 2012 3:24 PM
Subject: [R] How generate random numbers from given vector???

I wanna generate random numbers from a vector...

for example number-c(0,1,3,4,5,6,8)
so

rsidp-function(x){
    i=0
    for (i in seq(1:x))

    {y-sample(number,x, replace=T)}
    return(y)
}
so all random numbers have to be from vector number;
so if I type rsidp(5). it has to give me 5 random numbers except 2,7,9
(because they are not in the vector numbers). help me plz with it (((







--
View this message in context: 
http://r.789695.n4.nabble.com/How-generate-random-numbers-from-given-vector-tp4647447.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] How generate random numbers from given vector???

2012-10-25 Thread Rlotus
thank u so much! i got it.



--
View this message in context: 
http://r.789695.n4.nabble.com/How-generate-random-numbers-from-given-vector-tp4647447p4647469.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] How to draw the graph???

2012-10-25 Thread Rlotus
I have his code. I wanna draw the graph according to x and y. But at the end
when I run the code it gives me only one dot...it is strange cuz from
the loop it has to give 20 dots. Help me plz to draw a graph(((

for (i in seq(1:20))
{rsidpVector= rsidp(1)  
x-mean(rsidpVector)
y-length(number)
plot(y,x,ylab=sample mean,xlab=sample size)
print (rsidpVector)
print(x)

}


rsidp-function(x){
i=0
{y-sample(number,x), replace=TRUE}
return(y)
}




--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-draw-the-graph-tp4647464.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] Demo code

2012-10-25 Thread Rlotus
I have code in R. I need also demo code of my output and demo code of code. I
dont know what is demo. An d how to create it...can you tell how to do that
plz. thank you.



--
View this message in context: 
http://r.789695.n4.nabble.com/Demo-code-tp4647471.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] error bars

2012-10-25 Thread Johnson, Franklin Theodore
Hello R-help,



I am using R version 2.15.1.

I upgraded from R version 2.13 a few months back.



Previously, I was able to plot error bars on an xy scatter plot using the 
errbar function:

errbar(RAEthylene$TIME,RAEthylene$AVE,RAEthylene$AVE+RAEthylene$STD,RAEthylene$AVE-RAEthylene$STD,add
 = TRUE,lty=2,pch=17);



Today, I went to update my plot.

However, in R version 2.15.1 I get error code saying that this function cannot 
be found:

Error: could not find function errbar

I would perfer to avoid using the xy.error.bars-function(x, y, xbar, ybar) 
coding for these error bars, as I have many data to put on one plot.

I've searched the .pdf file for R 2.15.1 version and cannot find any updates 
for this function.

Do I have to reinstall version 2.13 again??

I need to generate these plots today!!



Please advise.

Regards,

Franklin

[[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] system is computationally singular: reciprocal condition number

2012-10-25 Thread langvince
Hi folks,

I know, this is a fairly common question and I am really disappointed that I
could not find a solution.
I am trying to calculate Mahanalobis distances in a data frame, where I have
several hundreds groups and several hundreds of variables.

Whatever I do, however I subset it I get the system is computationally
singular: reciprocal condition number error.
I know what it means and I know what should be the problem, but there is no
way this is a singular matrix.

I have uploaded the input file to my ftp: 
http://mkk.szie.hu/dep/talt/lv/CentInpDuplNoHeader.txt
It is a tab delimited txt file with no headers.

I tried the StatMatch Mahanalobis function and also this function:

mahal_dist -function (data, nclass, nvariable) {
  dist - matrix(0, nclass, nclass)
 n=0
 w - cov(data)
 print(w)
   for(i in 1:nclass)  {

for(c in 1:nclass){
diffl - vector(length = nvariable)
 for(l in 1:nvariable){
 diffl[l]=abs(data[i,l]-data[c,l])
 
}
  ###  matrixes
print(diffl)
 dist[i,c]= (t(diffl))%*%(solve(w))%*%(diffl)   
   }
 
 n=n+1
print(n)
 }
  return(dist)
sqrt_dist - sqrt(dist)
print(sqrt_dist)  }  


I have a deadline for this project (not a homework:)), and I could always
use this codes, so I thought I will be able to quit the calculations short,
but now I am just lost.

I would really appreciate any help.

Thanks for any help



--
View this message in context: 
http://r.789695.n4.nabble.com/system-is-computationally-singular-reciprocal-condition-number-tp4647472.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How generate random numbers from given vector???

2012-10-25 Thread Rui Barradas

Hello,

You don't need the loop, the sample() argument 'size' is there for that. 
See 'sample.


number - c(0,1,3,4,5,6,8)
rsidp - function(n) sample(number, n, replace = TRUE)
rsidp(5)

Hope this helps,

Rui Barradas
Em 25-10-2012 20:24, Rlotus escreveu:

I wanna generate random numbers from a vector...

for example number-c(0,1,3,4,5,6,8)
  so
  
rsidp-function(x){

i=0
for (i in seq(1:x))

{y-sample(number,x, replace=T)}
return(y)
}
  so all random numbers have to be from vector number;
so if I type rsidp(5). it has to give me 5 random numbers except 2,7,9
(because they are not in the vector numbers). help me plz with it (((







--
View this message in context: 
http://r.789695.n4.nabble.com/How-generate-random-numbers-from-given-vector-tp4647447.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] system is computationally singular: reciprocal condition number

2012-10-25 Thread Bert Gunter
1. I don't know what StatMatch is. Try using stats::mahalanobis.

2. It's the covariance matrix that is **numerically** singular and
can't be inverted. Why do you claim that there's no way this could
be true when there are hundreds of variables (= dimensions).

3. Try calculating the svd of your matrix and see what you get if you
haven't already done so.

Cheers,
Bert

On Thu, Oct 25, 2012 at 4:14 PM, langvince la...@purdue.edu wrote:
 Hi folks,

 I know, this is a fairly common question and I am really disappointed that I
 could not find a solution.
 I am trying to calculate Mahanalobis distances in a data frame, where I have
 several hundreds groups and several hundreds of variables.

 Whatever I do, however I subset it I get the system is computationally
 singular: reciprocal condition number error.
 I know what it means and I know what should be the problem, but there is no
 way this is a singular matrix.

 I have uploaded the input file to my ftp:
 http://mkk.szie.hu/dep/talt/lv/CentInpDuplNoHeader.txt
 It is a tab delimited txt file with no headers.

 I tried the StatMatch Mahanalobis function and also this function:

 mahal_dist -function (data, nclass, nvariable) {
   dist - matrix(0, nclass, nclass)
  n=0
  w - cov(data)
  print(w)
for(i in 1:nclass)  {

 for(c in 1:nclass){
 diffl - vector(length = nvariable)
  for(l in 1:nvariable){
  diffl[l]=abs(data[i,l]-data[c,l])

 }
   ###  matrixes
 print(diffl)
  dist[i,c]= (t(diffl))%*%(solve(w))%*%(diffl)
}

  n=n+1
 print(n)
  }
   return(dist)
 sqrt_dist - sqrt(dist)
 print(sqrt_dist)  }


 I have a deadline for this project (not a homework:)), and I could always
 use this codes, so I thought I will be able to quit the calculations short,
 but now I am just lost.

 I would really appreciate any help.

 Thanks for any help



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/system-is-computationally-singular-reciprocal-condition-number-tp4647472.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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] How to draw the graph???

2012-10-25 Thread David Winsemius

On Oct 25, 2012, at 2:24 PM, Rlotus wrote:

 I have his code. I wanna draw the graph according to x and y. But at the end
 when I run the code it gives me only one dot...it is strange cuz from
 the loop it has to give 20 dots. Help me plz to draw a graph(((
 
 for (i in seq(1:20))
 {rsidpVector= rsidp(1)
 x-mean(rsidpVector)
 y-length(number)
 plot(y,x,ylab=sample mean,xlab=sample size)
 print (rsidpVector)
 print(x)
 
 }
 
 
 rsidp-function(x){
   i=0
   {y-sample(number,x), replace=TRUE}
   return(y)
 }
 
 

Set up the plot before the loo and then use the points function inside the 
loop. 

 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/How-to-draw-the-graph-tp4647464.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, MD
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] Z score

2012-10-25 Thread Vedant Sharma
Hi Arun,

Thank you !  Very much appreciated.
[Only added t() at the end to preserve the original orientation.]

Also, many thanks to Rui Barradas.

Cheers,
Ved




On Thu, Oct 25, 2012 at 12:06 PM, arun smartpink...@yahoo.com wrote:



 Hi Ved,

 Sorry, I didn't test it well enough at that time.

 In your example file,
  #there were NAs
 MyFile1 - read.csv( text=
 Names,'Sample_1','Sample_2','Sample_3'
 Gene_1,87,77,88
 Gene_2,98,22,34
 Gene_3,33,43,33
 Gene_4,78,,81
 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= )


 #Here, the apply() function outputs a list when I remove the NA from the
 last row.
  apply(MyFile1,1,function(x) x[!is.na(x)]) #outputs a list
 #$Gene_1
 #Sample_1 Sample_2 Sample_3
  # 87   77   88

 #$Gene_2
 #Sample_1 Sample_2 Sample_3
  # 98   22   34

 #$Gene_3
 #Sample_1 Sample_2 Sample_3
  # 33   43   33

 #$Gene_4
 #Sample_1 Sample_3
  # 78   81

 # Without NAs
 MyFile2 - read.csv( text=
 Names,'Sample_1','Sample_2','Sample_3'
 Gene_1,87,77,88
 Gene_2,98,22,34
 Gene_3,33,43,33
 Gene_4,78,48,81
 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= )

 apply(dat3,1,function(x) x[!is.na(x)]) # the output is a matrix
 # Gene_1 Gene_2 Gene_3 Gene_4
 #Sample_1 87 98 33 78
 #Sample_2 77 22 43 48
 #Sample_3 88 34 33 81
 is.matrix(apply(dat3,1,function(x) x[!is.na(x)]) )
 #[1] TRUE

 #Consider another case
 MyFile3 - read.csv( text=
 Names,'Sample_1','Sample_2','Sample_3'
 Gene_1,87,77,88
 Gene_2,,22,34
 Gene_3,33,43,33
 Gene_4,78,,81
 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= )

 t(sapply(lapply(apply(MyFile3,1,function(x) x[!is.na(x)]),function(x)
 (x-mean(x))/sd(x)),function(x) x[colnames(MyFile3)] )) #works because the
 apply() output is a list
 #Sample_1   Sample_2   Sample_3
 #Gene_1  0.4931970 -1.1507929  0.6575959
 #Gene_2 NA -0.7071068  0.7071068
 #Gene_3 -0.5773503  1.1547005 -0.5773503
 #Gene_4 -0.7071068 NA  0.7071068


 #Yet another case:
 MyFile4 - read.csv( text=
 Names,'Sample_1','Sample_2','Sample_3'
 Gene_1,87,77
 Gene_2,,22,34
 Gene_3,33,,33
 Gene_4,78,,81
 , header=TRUE, row.names=1, as.is=TRUE, quote=', na.strings= )
  apply(MyFile4,1,function(x) x[!is.na(x)]) #output is a matrix because
 equal number of NAs were present in each row
 # Gene_1 Gene_2 Gene_3 Gene_4
 #[1,] 87 22 33 78
 #[2,] 77 34 33 81
 t(sapply(lapply(apply(MyFile4,1,function(x) x[!is.na(x)]),function(x)
 (x-mean(x))/sd(x)),function(x) x[colnames(MyFile4)] )) #doesn't work



 #In your dataset, there were no NAs
 dat1-read.csv(Bcl2_With_expressions.csv,sep=\t,row.names=1)
 MyFile-dat1[,-1]

  str(apply(MyFile,1,function(x) x[!is.na(x)])) # a matrix
 # num [1:29, 1:18] 10.48 10.96 9.28 11.1 10.95 ...
  #- attr(*, dimnames)=List of 2
  # ..$ : chr [1:29] ALL2 MLL8 ALL42 MLL5 ...
  # ..$ : chr [1:18] BAX BCL2L15 BCL2 BMF ...

 #In this case,
 either
  res2-apply(MyFile,1,function(x) (x-mean(x))/sd(x))

 #or

  res1-apply(apply(MyFile,1,function(x) x[!is.na(x)]),2,function(x)
 (x-mean(x))/sd(x)) #works


  identical(res1,res2)
 #[1] TRUE

  head(res1,2)
  #  BAX   BCL2L15 BCL2BMFBAD  MCL1
 BCL2L1
 #ALL2 0.1216373 -0.215256 1.040758 -0.4078606 -0.2427741 0.6967070
 -0.1054749
 #MLL8 0.6565878 -1.446252 1.052566 -0.1825442 -0.2312166 0.9882503
 -0.9687260
   #  BOK BCL2A1BCL2L14   BAK1  BBC3BCL2L11
 #ALL2 -0.1465807  0.5353133 -0.1772439 -0.3751981 0.6341806 -1.2432273
 #MLL8  0.2918296 -0.8466821  0.3088331 -1.4025846 0.7056799  0.9944288
   #  BID NOXA1BIK  HRKBCL2L2
 #ALL2 -2.2961643 0.2105960 -0.9195998 -0.001731806 1.6691590
 #MLL8 -0.5103087 0.3433778  1.2352986 -0.568548518 0.3674839


 Hope it helps
 A.K.







 
 From: Vedant Sharma vedantg...@gmail.com
 To: arun smartpink...@yahoo.com
 Sent: Wednesday, October 24, 2012 7:56 PM
 Subject: Re: [R] Z score


 Hello Arun,

 Thank you. I could manage to get the answer.

 However, this particular code, however, doesn't seem to work when I try to
 read from a .csv file (as attached). And, I am inquisitive to find out the
 reason !

 MyFile - read.csv (file.choose(), header=T, row.names=1)
 MyFile - MyFile [,-1]
 res2-t(sapply(lapply(apply(MyFile,1,function(x) x[!is.na(x)]),function(x)
 (x-mean(x))/sd(x)),function(x) x[colnames(MyFile)] ))

 Thanks again !!

 Cheers,
 Ved

 =


 On Wed, Oct 24, 2012 at 9:53 PM, arun smartpink...@yahoo.com wrote:

 Hi,
 
 In cases, with more sample columns, you could also use this:
  res2-t(sapply(lapply(apply(MyFile,1,function(x) x[!is.na(x)]),function(x)
 (x-mean(x))/sd(x)),function(x) x[colnames(MyFile)] ))
 res2
 
  #Sample_1   Sample_2   Sample_3
 #Gene_1  0.4931970 -1.1507929  0.6575959

Re: [R] error bars

2012-10-25 Thread David Winsemius

On Oct 25, 2012, at 2:45 PM, Johnson, Franklin Theodore wrote:

 Hello R-help,
 
 
 
 I am using R version 2.15.1.
 
 I upgraded from R version 2.13 a few months back.
 
 
 
 Previously, I was able to plot error bars on an xy scatter plot using the 
 errbar function:
 
 errbar(RAEthylene$TIME,RAEthylene$AVE,RAEthylene$AVE+RAEthylene$STD,RAEthylene$AVE-RAEthylene$STD,add
  = TRUE,lty=2,pch=17);
 
 
 
 Today, I went to update my plot.
 
 However, in R version 2.15.1 I get error code saying that this function 
 cannot be found:
 
 Error: could not find function errbar
 
 I would perfer to avoid using the xy.error.bars-function(x, y, xbar, ybar) 
 coding for these error bars, as I have many data to put on one plot.
 
 I've searched the .pdf file for R 2.15.1 version and cannot find any updates 
 for this function.
 
 Do I have to reinstall version 2.13 again??

There is no base::errbar function. You probably were using a package and have 
not yet reinstalled that package under the new version of R. When I run 
sos::findFn('errbar') I see two packages (Hmisc and sfsmisc) with a function of 
that name.

-- 

David Winsemius, MD
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] system is computationally singular: reciprocal condition number

2012-10-25 Thread David Winsemius

On Oct 25, 2012, at 4:41 PM, Bert Gunter wrote:

 1. I don't know what StatMatch is. Try using stats::mahalanobis.
 
 2. It's the covariance matrix that is **numerically** singular and
 can't be inverted. Why do you claim that there's no way this could
 be true when there are hundreds of variables (= dimensions).
 
 3. Try calculating the svd of your matrix and see what you get if you
 haven't already done so.

This was crossposted to StackOverflow where Josh O'Brien has responded that his 
code using svd()  shows the matrix to be highly collinear.  This is the upper 
left corner of the correlation matrix:

  V1  V2  V3   V4  V5 
V11.  0.97250825  0.93390424  0.918813118  0.89705917  
V20.97250825  1.  0.97118079  0.954020724  0.93992361 
V30.93390424  0.97118079  1.  0.991508026  0.97602188  
V40.91881312  0.95402072  0.99150803  1.0  0.98837387  
V50.89705917  0.93992361  0.97602188  0.988373865  1. 

 length( which(cor(mat)==1) )
[1] 374

Just looking at it should give a good idea why. I can see bands of columns that 
are identically zero.

-- 
david.

 Cheers,
 Bert
 
 On Thu, Oct 25, 2012 at 4:14 PM, langvince la...@purdue.edu wrote:
 Hi folks,
 
 I know, this is a fairly common question and I am really disappointed that I
 could not find a solution.
 I am trying to calculate Mahanalobis distances in a data frame, where I have
 several hundreds groups and several hundreds of variables.
 
 Whatever I do, however I subset it I get the system is computationally
 singular: reciprocal condition number error.
 I know what it means and I know what should be the problem, but there is no
 way this is a singular matrix.
 
 I have uploaded the input file to my ftp:
 http://mkk.szie.hu/dep/talt/lv/CentInpDuplNoHeader.txt
 It is a tab delimited txt file with no headers.
 
 I tried the StatMatch Mahanalobis function and also this function:
 
 mahal_dist -function (data, nclass, nvariable) {
  dist - matrix(0, nclass, nclass)
 n=0
 w - cov(data)
 print(w)
   for(i in 1:nclass)  {
 
for(c in 1:nclass){
diffl - vector(length = nvariable)
 for(l in 1:nvariable){
 diffl[l]=abs(data[i,l]-data[c,l])
 
}
  ###  matrixes
print(diffl)
 dist[i,c]= (t(diffl))%*%(solve(w))%*%(diffl)
   }
 
 n=n+1
print(n)
 }
  return(dist)
sqrt_dist - sqrt(dist)
 print(sqrt_dist)  }
 
 
 I have a deadline for this project (not a homework:)), and I could always
 use this codes, so I thought I will be able to quit the calculations short,
 but now I am just lost.
 
 I would really appreciate any help.
 
 Thanks for any help
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/system-is-computationally-singular-reciprocal-condition-number-tp4647472.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.
 
 
 
 -- 
 
 Bert Gunter
 Genentech Nonclinical Biostatistics
 
 Internal Contact Info:
 Phone: 467-7374
 Website:
 http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] How generate random numbers from given vector???

2012-10-25 Thread Muhuri, Pradip (SAMHSA/CBHSQ)

Hello,

The other options is to use the sample() function.

test2 - matrix (rep(sample(number1, size = 5), times=3), nrow=3)


Pradip Muhuri


From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Rui Barradas [ruipbarra...@sapo.pt]
Sent: Thursday, October 25, 2012 7:19 PM
To: Rlotus
Cc: r-help@r-project.org
Subject: Re: [R] How generate random numbers from given vector???

Hello,

You don't need the loop, the sample() argument 'size' is there for that.
See 'sample.

number - c(0,1,3,4,5,6,8)
rsidp - function(n) sample(number, n, replace = TRUE)
rsidp(5)

Hope this helps,

Rui Barradas
Em 25-10-2012 20:24, Rlotus escreveu:
 I wanna generate random numbers from a vector...

 for example number-c(0,1,3,4,5,6,8)
   so

 rsidp-function(x){
   i=0
   for (i in seq(1:x))

   {y-sample(number,x, replace=T)}
   return(y)
 }
   so all random numbers have to be from vector number;
 so if I type rsidp(5). it has to give me 5 random numbers except 2,7,9
 (because they are not in the vector numbers). help me plz with it (((







 --
 View this message in context: 
 http://r.789695.n4.nabble.com/How-generate-random-numbers-from-given-vector-tp4647447.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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 generate random numbers from given vector???

2012-10-25 Thread Jorge I Velez
You can also just replicate() as follows:

# x is the vector
# s is the size of the sample
# B is the number of samples
# ... arguments passed to sample()
f - function(x, s, B, ...) replicate(B, sample(x, s, ...))
f(x, 3, 10, TRUE)
f(x, 3, 10, FALSE)

 HTH,
Jorge.-


On Fri, Oct 26, 2012 at 12:05 PM, Muhuri, Pradip (SAMHSA/CBHSQ) 
pradip.muh...@samhsa.hhs.gov wrote:


 Hello,

 The other options is to use the sample() function.

 test2 - matrix (rep(sample(number1, size = 5), times=3), nrow=3)


 Pradip Muhuri

 
 From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On
 Behalf Of Rui Barradas [ruipbarra...@sapo.pt]
 Sent: Thursday, October 25, 2012 7:19 PM
 To: Rlotus
 Cc: r-help@r-project.org
 Subject: Re: [R] How generate random numbers from given vector???

 Hello,

 You don't need the loop, the sample() argument 'size' is there for that.
 See 'sample.

 number - c(0,1,3,4,5,6,8)
 rsidp - function(n) sample(number, n, replace = TRUE)
 rsidp(5)

 Hope this helps,

 Rui Barradas
 Em 25-10-2012 20:24, Rlotus escreveu:
  I wanna generate random numbers from a vector...
 
  for example number-c(0,1,3,4,5,6,8)
so
 
  rsidp-function(x){
i=0
for (i in seq(1:x))
 
{y-sample(number,x, replace=T)}
return(y)
  }
so all random numbers have to be from vector number;
  so if I type rsidp(5). it has to give me 5 random numbers except
 2,7,9
  (because they are not in the vector numbers). help me plz with it (((
 
 
 
 
 
 
 
  --
  View this message in context:
 http://r.789695.n4.nabble.com/How-generate-random-numbers-from-given-vector-tp4647447.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-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] system is computationally singular: reciprocal condition number

2012-10-25 Thread Thomas Lumley
On Fri, Oct 26, 2012 at 12:14 PM, langvince la...@purdue.edu wrote:

 Whatever I do, however I subset it I get the system is computationally
 singular: reciprocal condition number error.
 I know what it means and I know what should be the problem, but there is no
 way this is a singular matrix.

 I have uploaded the input file to my ftp:
 http://mkk.szie.hu/dep/talt/lv/CentInpDuplNoHeader.txt
 It is a tab delimited txt file with no headers.

It's a singular matrix.  The data matrix has rank 300 according to
either qr() or svd().  The 301st singular value is about ten orders of
magnitude smaller than the 300th one.

The problem is the rounding of the values -- if you take 372 vectors
in 380-dimensional space they should be linearly independent, but if
you force them to lie on a relatively coarse grid there are quite
likely to be linear dependencies.  When I add random noise in the
fourth decimal place, the matrix stops being singular.

 -thomas


-thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

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

2012-10-25 Thread Charles Determan Jr
A general question that I have been pursuing for some time but have set
aside.  When finishing some analysis, I can have multiple matrices that
have specific column names.  Ideally, I would like to combine these
separate matrices for a final output as a csv file.

A generic example:

Matrix 1
var1A  var1B  var1C
x  x   x
x  x   x

Matrix 2
var2A  var2B  var2C
x  x   x
x  x   x

I would like a final exportable matrix or dataframe or whichever format is
most workable.

Matrix 3
var1A  var1B  var1C
x  x   x
x  x   x

var2A  var2B  var2C
x  x   x
x  x   x

However, no matter which function I try reports an error that the column
names are not the same.

Any insights would be appreciated.
Thanks as always,
Charles

[[alternative HTML version deleted]]

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


Re: [R] How to draw the graph???

2012-10-25 Thread Rlotus
plot(y,x, ylab=sample mean,xlab=sample size) 
 
for (i in seq(1:20))
 {rsidpVector= rsidp(1)
 x-mean(rsidpVector)
 y-length(number) 
print (rsidpVector)
 print(x) 

sorry, but how i can use points function in the loop?



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-draw-the-graph-tp4647464p4647482.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] Merge matrices with different column names

2012-10-25 Thread Jeff Newmiller
If they have the same number of rows, you can use cbind() to create one object 
to write out.
---
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.

Charles Determan Jr deter...@umn.edu wrote:

A general question that I have been pursuing for some time but have set
aside.  When finishing some analysis, I can have multiple matrices that
have specific column names.  Ideally, I would like to combine these
separate matrices for a final output as a csv file.

A generic example:

Matrix 1
var1A  var1B  var1C
x  x   x
x  x   x

Matrix 2
var2A  var2B  var2C
x  x   x
x  x   x

I would like a final exportable matrix or dataframe or whichever format
is
most workable.

Matrix 3
var1A  var1B  var1C
x  x   x
x  x   x

var2A  var2B  var2C
x  x   x
x  x   x

However, no matter which function I try reports an error that the
column
names are not the same.

Any insights would be appreciated.
Thanks as always,
Charles

   [[alternative HTML version deleted]]

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

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


Re: [R] system is computationally singular: reciprocal condition number

2012-10-25 Thread langvince
Hey Bert, 

thanks for your fast reply. Yes, based on  svd it is singular.  The no way
statement was because of the source of the dataset. I would not expect that.
I never used the stats Maha dist calc, but after giving it a shot, not a
surprise still singular.
Any idea how to manipulate the data to have it run, or other idea to solve
the problem?

thanks



--
View this message in context: 
http://r.789695.n4.nabble.com/system-is-computationally-singular-reciprocal-condition-number-tp4647472p4647483.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] system is computationally singular: reciprocal condition number

2012-10-25 Thread langvince
Hey David, 

my answers are delayed here, although I am not using my gmail email
address:)

Yep thats right, those bands of zeros are one of the most important values
to define one group, and have a nice distance from the rest of the groups
:). I cannot really get rid of those, I bet it would not help if I would
change all of them to a really small (but same) value.

Thanks
 



--
View this message in context: 
http://r.789695.n4.nabble.com/system-is-computationally-singular-reciprocal-condition-number-tp4647472p4647486.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] Generate two bell curves

2012-10-25 Thread phantastic
How do I generate two bell curves, both with the same mean but different
standard deviations? I used to have a script for it but I lost it.

Thanks.



--
View this message in context: 
http://r.789695.n4.nabble.com/Generate-two-bell-curves-tp4647488.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] wanna create all points.....

2012-10-25 Thread Rlotus
Plz help me ;(( I lost 7 hours for thinking and doing this code ;( I need to
create points.20 points(dots). All these dots have to be in one graph...
when i run this codeit gives me only one dote.

number- (0,2,3,4,5,6,8)

for (i in seq(1:20))
{rsidpVector=rsidp(i)
mean(rsidpVector)
plot (length(rsidpVector), mean(rsidpVector), ylab=sample mean, xlab=
sample size)
}

rsidp- function(x){
i+0
{y-sample(number,x,replace = TRUE)}
return(y)
}



--
View this message in context: 
http://r.789695.n4.nabble.com/wanna-create-all-points-tp4647494.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] how to make simulation faster

2012-10-25 Thread stats12
Dear R users,

I need to run 1000 simulations to find maximum likelihood estimates.  I
print my output as a vector. However, it is taking too long. I am running 50
simulations at a time and it is taking me 30 minutes. Once I tried to run
200 simulations at once, after 2 hours I stopped it and saw that only about
40 of them are simulated in those 2 hours. Is there any way to make my
simulations faster? (I can post my code if needed, I'm just looking for
general ideas here). Thank you in advance. 



--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-make-simulation-faster-tp4647492.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] wanna create all points.....

2012-10-25 Thread Rlotus
One dote..and its a last dote of the loop ;(



--
View this message in context: 
http://r.789695.n4.nabble.com/wanna-create-all-points-tp4647494p4647495.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] Interpreting and visualising lme results

2012-10-25 Thread Santini Silvana
Dear R users,
I have used the following function (in blue) aiming to find the linear 
regression between MOE and XLA and nesting my data by Species. I have obtained 
the following results (in green).
model4-lme(MOE~XLA, random = ~ XLA|Species, method=ML)summary(model4)
Linear mixed-effects model fit by maximum likelihood Data: NULL         AIC     
BIC   logLik  -1.040187 8.78533 6.520094
Random effects: Formula: ~XLA | Species Structure: General positive-definite, 
Log-Cholesky parametrization            StdDev       Corr  (Intercept) 
1.944574e-01 (Intr)XLA         6.134158e-06 -0.884Residual    1.636428e-01      
 
Fixed effects: MOE ~ XLA                 Value  Std.Error DF   t-value 
p-value(Intercept) 3.0558697 0.15075939 32 20.269847  0.XLA         
0.005 0.0335 32  0.150811  0.8811 Correlation:     (Intr)XLA -0.861
Standardized Within-Group Residuals:       Min         Q1        Med         Q3 
       Max -1.8354171 -0.4704322  0.1414749  0.5500273  1.5950338 
Number of Observations: 38Number of Groups: 5 
I have read that large correlation values such as,Correlation:     (Intr)XLA 
-0.861reflect an ill-conditioned model, in addition XLA does not have an 
effect on the model p=0.88. These results are not logic when I look at my data 
and therefore I think I am missing something in the model? It would be very 
helpful if someone has some tips on this? In addition, I was wondering if 
somebody knows what is the best way to visualise this kind of data (nested 
data)?
Thank you very much for any help and time.


[[alternative HTML version deleted]]

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


Re: [R] How to draw the graph???

2012-10-25 Thread David Winsemius

On Oct 25, 2012, at 5:14 PM, Rlotus wrote:

 plot(y,x, ylab=sample mean,xlab=sample size) 
 
 for (i in seq(1:20))
 {rsidpVector= rsidp(1)
 x-mean(rsidpVector)
 y-length(number) 
 print (rsidpVector)
 print(x) 
 
 sorry, but how i can use points function in the loop?

Tested code provided in response to reproducible examples. The points function 
will not redraw a new plot with each iteration. It might be the case that you 
do not even need a loop, but you have not described the problem yet. 

-- 

David Winsemius, MD
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] Generate two bell curves

2012-10-25 Thread peter dalgaard

On Oct 26, 2012, at 03:17 , phantastic wrote:

 How do I generate two bell curves, both with the same mean but different
 standard deviations? I used to have a script for it but I lost it.
 
 Thanks.

curve(, from=..., to=...)
curve(, add=TRUE)

If you plot the tallest one first, you won't need to diddle the ylim setting.


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


  1   2   >