Re: [R] Namibia becoming NA

2010-07-18 Thread Joshua Wiley
Hi Suresh,

I think you will need to use read.table() rather than the read.csv()
wrapper for it.  Try:

input - read.table(file = padded.csv, sep = ,, header = TRUE,
na.strings = NULL)

HTH,

Josh

On Sat, Jul 17, 2010 at 10:47 PM, Suresh Singh singh@osu.edu wrote:
 I have a data file in which one of the columns is country code and NA is the
 code for Namibia.
 When I read the data file using read.csv, NA for Namibia is being treated as
 null or NA

 How can I prevent this from happening?

 I tried the following but it didn't work
 input - read.csv(padded.csv,header = TRUE,as.is = c(code2))

 thanks,
 Suresh

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




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] Help with a problem

2010-07-18 Thread Stephan Kolassa

Hi all,

zoo::rollmean() is a nice idea. But if I understand Mike correctly, he 
wants 5 out of any 7 consecutive logicals to be TRUE, where these 5 do 
not necessarily need to be consecutive themselves. (remaining open 
question: could, e.g., the condition on c1 be TRUE for rows 1,2,3,4,5 
and on c2 for rows 3,4,5,6,7, or would it need to be TRUE for the same 
rows?). Then something like this would make sense:


any(rollmean(dat$c1=100,7)=5/7-.01  rollmean(dat$c2=8,7)=5/7-.01))

or

any(rollmean(dat$c1=100,7)=5/7-.01  dat$c2=8,7)=5/7-.01))

depending on the open question above.

The -.01 above may be necessary in light of FAQ 7.31.

HTH,
Stephan



Joshua Wiley schrieb:

Hi Michael,

The days in your example do not look continuous (at least from my
thinking), so you may have extra requirements in mind, but take a look
at this code.  My general thought was first to turn each column into a
logical vector (c1 = 100 and c2 = 8).  Taking advantage of the fact
that R treats TRUE as 1 and FALSE as 0, compute a rolling mean.  If
(and only if) 5 consecutive values are TRUE, the mean will be 1.  Next
I added the rolling means for each column, and then tested whether any
were 2 (i.e., 1 + 1).

Cheers,

Josh

###
#Load required package
library(zoo)

#Your data with ds converted to Date
#from dput()
dat -
structure(list(ds = structure(c(14702, 14729, 14730, 14731, 14732,
14733, 14734, 14735, 14736, 14737, 14738, 14739, 14740, 14741,
14742, 14743, 14744), class = Date), c1 = c(100L, 11141L, 3L,
7615L, 6910L, 5035L, 3007L, 4L, 8335L, 2897L, 6377L, 3177L, 7946L,
8705L, 9030L, 8682L, 8440L), c2 = c(0L, 15L, 16L, 14L, 17L, 3L,
15L, 14L, 17L, 13L, 17L, 17L, 15L, 0L, 16L, 16L, 1L)), .Names = c(ds,
c1, c2), row.names = c(NA, -17L), class = data.frame)

#Order by ds
dat - dat[order(dat$ds), ]

yourvar - 0

#Test that 5 consecutive values from c1 AND c2 meet requirements
if(any(
 c(rollmean(dat$c1 = 100, 5) + rollmean(dat$c2 = 8, 5)) == 2)
   ) {yourvar - 1}

###

On Sat, Jul 17, 2010 at 2:38 PM, Michael Hess mlh...@med.umich.edu wrote:

Sorry for not being clear.

In the dataset there are around 100 or so days of data (in the case also rows 
of data)

I need to make sure that the person meets that c1 is at least 100 AND c2 is at 
least 8 for 5 of 7 continuous days.

I will play with what I have and see if I can find out how to do this.

Thanks for the help!

Michael


Stephan Kolassa  07/17/10 4:50 PM 

Mike,

I am slightly unclear on what you want to do. Do you want to check rows
1 and 7 or 1 *to* 7? Should c1 be at least 100 for *any one* or *all*
rows you are looking at, and same for c2?

You can sort your data like this:
data - data[order(data$ds),]

Type ?order for help. But also do this for added enlightenment...:

library(fortunes)
fortune(dog)

Next, your analysis on the sorted data frame. As I said, I am not
entirely clear on what you are looking at, but the following may solve
your problem with choices 1 to 7 and any one above.

foo - 0
for ( ii in 1:(nrow(data)-8) ) {
  if (any(data$c1[ii+seq(0,6)]=100)  any(data$c2[ii+seq(0,6)]=8)) {
foo - 1
break
  }
}

The variable foo should contain what you want it to. Look at ?any
(and, if this does not do what you want it to, at ?all) for further info.

No doubt this could be vectorized, but I think the loop is clear enough.

Good luck!
Stephan



Michael Hess schrieb:

Hello R users,

I am a researcher at the University of Michigan looking for a solution to an R 
problem.  I have loaded my data in from a mysql database and it looks like this


data

   ds c1 c2
1  2010-04-03100   0
2  2010-04-30  11141  15
3  2010-05-01  3  16
4  2010-05-02   7615  14
5  2010-05-03   6910  17
6  2010-05-04   5035  3
7  2010-05-05   3007  15
8  2010-05-06   4  14
9  2010-05-07   8335  17
10 2010-05-08   2897  13
11 2010-05-09   6377  17
12 2010-05-10   3177  17
13 2010-05-11   7946  15
14 2010-05-12   8705  0
15 2010-05-13   9030  16
16 2010-05-14   8682  16
17 2010-05-15   8440  15


What I am trying to do is sort by ds, and take rows 1,7, see if c1 is at least 
100 AND c2 is at least 8. If it is not, start with check rows 2,8 and if not 
there 3,9until it loops over the entire file.   If it finds a set that 
matches, set a new variable equal to 1, if never finds a match, set it equal to 
0.

I have done this in stata but on this project we are trying to use R.  Is this 
something that can be done in R, if so, could someone point me in the correct 
direction.

Thanks,

Michael Hess
University of Michigan
Health System

**
Electronic Mail is not secure, may not be read every day, and should not be 
used for urgent or sensitive issues

__

Re: [R] Namibia becoming NA

2010-07-18 Thread Ted Harding
On 18-Jul-10 05:47:03, Suresh Singh wrote:
 I have a data file in which one of the columns is country code and NA
 is the
 code for Namibia.
 When I read the data file using read.csv, NA for Namibia is being
 treated as
 null or NA
 
 How can I prevent this from happening?
 
 I tried the following but it didn't work
 input - read.csv(padded.csv,header = TRUE,as.is = c(code2))
 
 thanks,
 Suresh

I suppose this was bound to happen, and in my view it represent
a bit of a mess! With a test file temp.csv:

  Code,Country
  DE,Germany
  IT,Italy
  NA,Namibia
  FR,France

  X - read.csv(temp.csv)
  X
  Code Country
  # 1   DE Germany
  # 2   IT   Italy
  # 3 NA Namibia
  # 4   FR  France
  which(is.na(X))
  # [1] 3

exactly as Suresh describes. It does not help to surround the NA
in temp.csv with quotes:

  Code,Country
  DE,Germany
  IT,Italy
  NA,Namibia
  FR,France

leads to exactly the same result. And I have tried every variation
I can think of of as.is and colClasses, still with exactly the
same result!

Conclusion: If an entry in a data file is intended to become the
character value NA, there seems to be no way of reading it in
directly. This should not be so: it should be preventable!

As a cure, assuming that no other value in the Country Code is
actually missing (and so should be NA), then (with Suresh's
naming) I would suggest, subsequent to reading in the file,
something like the following. The complication is that the variable
code2 is now a factor, and you cannot simply assign a character
value NA to its NA value -- you will get an error message.
Hence:

  ix - which(is.na(input$code2))
  Y  - as.character(input$code2)
  Y[ix] - NA
  input$code2) - factor(Y)

The corresponding code for my test example is:

  ix - which(is.na(X$Code))
  Y  - as.character(X$Code)
  Y[ix] - NA
  X$Code - factor(Y)

  X
  #   Code Country
  # 1   DE Germany
  # 2   IT   Italy
  # 3   NA Namibia
  # 4   FR  France
  which(is.na(X))
  # integer(0)

So that works.

There ought to be an option in read.csv() and friends which suppresses
the conversion of a string NA found in input into an NA value.
Maybe there is -- but, if so, it is not visible in the documentation!

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 18-Jul-10   Time: 09:25:05
-- XFMail --

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


Re: [R] Namibia becoming NA

2010-07-18 Thread Berwin A Turlach
G'day Ted,

On Sun, 18 Jul 2010 09:25:09 +0100 (BST)
(Ted Harding) ted.hard...@manchester.ac.uk wrote:

 On 18-Jul-10 05:47:03, Suresh Singh wrote:
  I have a data file in which one of the columns is country code and
  NA is the
  code for Namibia.
  When I read the data file using read.csv, NA for Namibia is being
  treated as
  null or NA
  
  How can I prevent this from happening?
  
  I tried the following but it didn't work
  input - read.csv(padded.csv,header = TRUE,as.is = c(code2))
  
  thanks,
  Suresh
 
 I suppose this was bound to happen, and in my view it represent
 a bit of a mess! With a test file temp.csv:
 
   Code,Country
   DE,Germany
   IT,Italy
   NA,Namibia
   FR,France

Thanks for providing an example.

 leads to exactly the same result. And I have tried every variation
 I can think of of as.is and colClasses, still with exactly the
 same result!

Did you think of trying some variations of na.strings? ;-) 

IMO, the simplest way of coding missing values in CSV files is to have
two consecutive commas; not some code (whether NA, 99, 999, -1, ...)
between them.

 Conclusion: If an entry in a data file is intended to become the
 character value NA, there seems to be no way of reading it in
 directly. This should not be so: it should be preventable!

It is, through simple use of the na.strings argument:

R X - read.csv(temp.csv, na.strings=)
R X
  Code Country
1   DE Germany
2   IT   Italy
3   NA Namibia
4   FR  France
R which(is.na(X))
integer(0)

HTH.

Cheers,

Berwin

== Full address 
Berwin A Turlach  Tel.: +61 (8) 6488 3338 (secr)
School of Maths and Stats (M019)+61 (8) 6488 3383 (self)
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway   
Crawley WA 6009e-mail: ber...@maths.uwa.edu.au
Australiahttp://www.maths.uwa.edu.au/~berwin

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


Re: [R] Continuing on with a loop when there's a failure

2010-07-18 Thread Josh B
Oops, forgot to add the line:

library(Design)

#the lrm function is in the Design library

...but even when I load the Design library, the loop still doesn't work. It 
stops after failing on the second run of the loop:

 results
y1 y2 y3
[1,] 0.6976063 NA NA

(The third run through the loop should have succeeded and left numeric output 
in 
the matrix called results, but it did not).





To: Peter Konings peter.l.e.koni...@gmail.com
Cc: R Help r-help@r-project.org
Sent: Sun, July 18, 2010 12:25:42 PM
Subject: Re: [R] Continuing on with a loop when there's a failure


Hello Peter,

I tried your suggestion, but I was still not able to get it to work. Would you 
mind looking at my code again? Here's what I'm trying:

x - read.table(textConnection(y1 y2 y3 x1 x2
indv.1 bagels donuts bagels 4 6
indv.2 donuts donuts donuts 5 1
indv.3 donuts donuts donuts 1 10
indv.4 donuts donuts donuts 10 9
indv.5 bagels donuts bagels 0 2
indv.6 bagels donuts bagels 2 9
indv.7 bagels donuts bagels 8 5
indv.8 bagels donuts bagels 4 1
indv.9 donuts donuts donuts 3 3
indv.10 bagels donuts bagels 5 9
indv.11 bagels donuts bagels 9 10
indv.12 bagels donuts bagels 3 1
indv.13 donuts donuts donuts 7 10
indv.14 bagels donuts bagels 2 10
indv.15 bagels donuts bagels 9 6), header = TRUE)

results - matrix(nrow = 1,  ncol = 3)
colnames(results) - c(y1, y2, y3)

for (i in 1:2) {
mod.poly3 - try(lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x))
if(class(mod.poly3) == 'try-error')
{results[1,i] - NA}
else {mod.poly3 - lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x)
results[1,i] - anova(mod.poly3)[1,3]
}
}


...and here's the output:

 results
 y1 y2 y3
[1,] NA NA NA

[[elided Yahoo spam]]




From: Peter Konings  peter.l.e.koni...@gmail.com

Sent: Tue, July 13, 2010 5:45:17 PM
Subject: Re: [R] Continuing on with a loop when there's a failure

Hi Josh,

Test the class of the resulting object. If it is 'try-error' fill your result 
with NA or do some other error handling.

result - try(somemodel)
if(class(result) == 'try-error')
{
# some error handling
} else {
# whatever happens if the result is ok
}

HTH
Peter.




In my opinion the try and tryCatch commands are written and documented rather
poorly. Thus I am not sure what to program exactly.

For instance, I could query mod.poly3 and use an if/then statement to proceed,
but querying mod.poly3 is weird. For instance, here's the output when it fails:

 mod.poly3 - try(lrm(x[,2] ~ pol(x1, 3) + pol(x2, 3), data=x))

Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol, weights =
weights,  :

 NA/NaN/Inf in foreign function call (arg 1)
 mod.poly3
[1] Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol, weights 
=
weights,  : \n  NA/NaN/Inf in foreign function call (arg 1)\n
attr(,class)
[1] try-error

...and here's the output when it succeeds:
 mod.poly3 - try(lrm(x[,1] ~ pol(x1, 3) + pol(x2, 3), data=x))
 mod.poly3

Logistic Regression Model

lrm(formula = x[, 1] ~ pol(x1, 3) + pol(x2, 3), data = x)


Frequencies of Responses
bagels donuts
   10  5

  Obs  Max Deriv Model L.R.   d.f.  P  C
   15  4e-04   3.37  6 0.7616   0.76
  Dxy  Gamma  Tau-a R2  Brier  g
 0.52   0.52  0.248  0.279  0.183  1.411
   gr gp
  4.1  0.261

 Coef S.E.Wald Z P
Intercept -5.68583 5.23295 -1.09  0.2772
x1 1.87020 2.14635  0.87  0.3836
x1^2  -0.42494 0.48286 -0.88  0.3788
x1^3   0.02845 0.03120  0.91  0.3618
x2 3.49560 3.54796  0.99  0.3245
x2^2  -0.94888 0.82067 -1.16  0.2476
x2^3   0.06362 0.05098  1.25  0.2121

...so what exactly would I query to design my if/then statement?






From: David Winsemius dwinsem...@comcast.net
To: David Winsemius dwinsem...@comcast.net

Sent: Tue, July 13, 2010 9:09:04 AM

Subject: Re: [R] Continuing on with a loop when there's a failure



On Jul 13, 2010, at 9:04 AM, David Winsemius wrote:


 On Jul 13, 2010, at 8:47 AM, Josh B wrote:

 Thanks again, David.

[[elided Yahoo spam]]


(BTW, it did work.)

 Here's what I'm trying now:

 for (i in 1:2) {
mod.poly3 - try(lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x))
results[1,i] - anova(mod.poly3)[1,3]
 }

 You need to do some programming.

(Or I suppose you could wrap both the lrm and the anova calls in try.)

 You did not get an error from the lrm but rather from the anova call because
you tried to give the results of the try function to anova without first
checking to see if an error had occurred.

 --David.

 Here's what happens (from the console):

 Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol, weights =
weights,  :
  NA/NaN/Inf in foreign function call (arg 1)
 Error in UseMethod(anova) :
  no applicable method for 'anova' applied to an object of class 

Re: [R] Continuing on with a loop when there's a failure

2010-07-18 Thread Josh B
Hello Peter,

I tried your suggestion, but I was still not able to get it to work. Would you 
mind looking at my code again? Here's what I'm trying:

x - read.table(textConnection(y1 y2 y3 x1 x2
indv.1 bagels donuts bagels 4 6
indv.2 donuts donuts donuts 5 1
indv.3 donuts donuts donuts 1 10
indv.4 donuts donuts donuts 10 9
indv.5 bagels donuts bagels 0 2
indv.6 bagels donuts bagels 2 9
indv.7 bagels donuts bagels 8 5
indv.8 bagels donuts bagels 4 1
indv.9 donuts donuts donuts 3 3
indv.10 bagels donuts bagels 5 9
indv.11 bagels donuts bagels 9 10
indv.12 bagels donuts bagels 3 1
indv.13 donuts donuts donuts 7 10
indv.14 bagels donuts bagels 2 10
indv.15 bagels donuts bagels 9 6), header = TRUE)

results - matrix(nrow = 1, ncol = 3)
colnames(results) - c(y1, y2, y3)

for (i in 1:2) {
mod.poly3 - try(lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x))
if(class(mod.poly3) == 'try-error')
{results[1,i] - NA}
else {mod.poly3 - lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x)
results[1,i] - anova(mod.poly3)[1,3]
}
}


...and here's the output:

 results
 y1 y2 y3
[1,] NA NA NA

The results matrix is empty!




From: Peter Konings peter.l.e.koni...@gmail.com

Sent: Tue, July 13, 2010 5:45:17 PM
Subject: Re: [R] Continuing on with a loop when there's a failure

Hi Josh,

Test the class of the resulting object. If it is 'try-error' fill your result 
with NA or do some other error handling.

result - try(somemodel)
if(class(result) == 'try-error')
{
# some error handling
} else {
# whatever happens if the result is ok
}

HTH
Peter.




In my opinion the try and tryCatch commands are written and documented rather
poorly. Thus I am not sure what to program exactly.

For instance, I could query mod.poly3 and use an if/then statement to proceed,
but querying mod.poly3 is weird. For instance, here's the output when it fails:

 mod.poly3 - try(lrm(x[,2] ~ pol(x1, 3) + pol(x2, 3), data=x))

Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol, weights =
weights,  :

 NA/NaN/Inf in foreign function call (arg 1)
 mod.poly3
[1] Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol, weights 
=
weights,  : \n  NA/NaN/Inf in foreign function call (arg 1)\n
attr(,class)
[1] try-error

...and here's the output when it succeeds:
 mod.poly3 - try(lrm(x[,1] ~ pol(x1, 3) + pol(x2, 3), data=x))
 mod.poly3

Logistic Regression Model

lrm(formula = x[, 1] ~ pol(x1, 3) + pol(x2, 3), data = x)


Frequencies of Responses
bagels donuts
   10  5

  Obs  Max Deriv Model L.R.   d.f.  P  C
   15  4e-04   3.37  6 0.7616   0.76
  Dxy  Gamma  Tau-a R2  Brier  g
 0.52   0.52  0.248  0.279  0.183  1.411
   gr gp
  4.1  0.261

 Coef S.E.Wald Z P
Intercept -5.68583 5.23295 -1.09  0.2772
x1 1.87020 2.14635  0.87  0.3836
x1^2  -0.42494 0.48286 -0.88  0.3788
x1^3   0.02845 0.03120  0.91  0.3618
x2 3.49560 3.54796  0.99  0.3245
x2^2  -0.94888 0.82067 -1.16  0.2476
x2^3   0.06362 0.05098  1.25  0.2121

...so what exactly would I query to design my if/then statement?






From: David Winsemius dwinsem...@comcast.net
To: David Winsemius dwinsem...@comcast.net

Sent: Tue, July 13, 2010 9:09:04 AM

Subject: Re: [R] Continuing on with a loop when there's a failure



On Jul 13, 2010, at 9:04 AM, David Winsemius wrote:


 On Jul 13, 2010, at 8:47 AM, Josh B wrote:

 Thanks again, David.

[[elided Yahoo spam]]


(BTW, it did work.)

 Here's what I'm trying now:

 for (i in 1:2) {
mod.poly3 - try(lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x))
results[1,i] - anova(mod.poly3)[1,3]
 }

 You need to do some programming.

(Or I suppose you could wrap both the lrm and the anova calls in try.)

 You did not get an error from the lrm but rather from the anova call because
you tried to give the results of the try function to anova without first
checking to see if an error had occurred.

 --David.

 Here's what happens (from the console):

 Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol, weights =
weights,  :
  NA/NaN/Inf in foreign function call (arg 1)
 Error in UseMethod(anova) :
  no applicable method for 'anova' applied to an object of class try-error

 ...so I still can't make my results matrix. Could I ask you for some 
specific
code to make this work? I'm not that familiar with the syntax for try or
tryCatch, and the help files for them are pretty bad, in my humble opinion.

 I should clarify that I actually don't care about the failed runs per se. I
just want R to keep going in spite of them and give me my results matrix.

 From: David Winsemius dwinsem...@comcast.net


 Cc: R Help r-help@r-project.org
 Sent: Mon, July 12, 2010 8:09:03 PM
 Subject: Re: [R] Continuing on with a loop when there's a failure


 On Jul 12, 2010, at 6:18 PM, Josh B wrote:

Re: [R] sort file names in numerical order

2010-07-18 Thread Duncan Mackay

Hi

Yes it is possible- one way is:

fileNames[order(sprintf(%02s, sub([[:upper:]],, fileNames)))]
[1] A1  B1  A2  B2  A10 B10

Regards

Duncan

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

At 06:47 18/07/2010, you wrote:



 I get some file names by list.files().
 These names are in  alphabetical order.
 I want to change it to logical numeric  order.
 Example:
  fileNames - c(A10, A1, A2, B1, B2,  B10)
  sort(fileNames)
 [1] A1  A10 A2  B1   B10 B2
 I want to have:
 A1  A2 A10 B1 B2 B10

 Is  this possible?

Greetings.  I see that you've gotten an elegant solution to your problem.
I've appended a poor-man's solution, which I generated more for my own
edification than for yours.

-- Mike


## modified file names, changed to exhibit sorting on letters
fileNames - c(A10, B10, A1, A2, B1, B2); fileNames

## use regular expressions to pick off letters, numbers
fnLet - gsub((^[^0-9]+).*$, \\1, fileNames); fnLet
fnNum - gsub(^[^0-9]+(.*)$, \\1, fileNames); fnNum

## need to force numeric sorting of the numbers
fnNum - as.numeric(fnNum)

## find the order of the numbers, for later use in subsetting
fnNumOrd - order(fnNum); fnNumOrd

## pack all the relevant information into a data frame, then select from that
fnPieces - data.frame(fnLet, fnNum, fileNames, stringsAsFactors=FALSE);
fnPieces

## partial sort by numbers only (gives new df)
dfPartialSort - fnPieces[fnNumOrd, ]; dfPartialSort

## find the order of the names, then select from new df with that
fnLetOrd - order(dfPartialSort[, 1]); fnLetOrd
dfFullSort - dfPartialSort[fnLetOrd, ]; dfFullSort

## the file names have gone along for the ride, so pick them off now
sortedFileNames - dfFullSort$fileNames; sortedFileNames

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

2010-07-18 Thread Peter Dalgaard
Berwin A Turlach wrote:

 Did you think of trying some variations of na.strings? ;-) 
 
 IMO, the simplest way of coding missing values in CSV files is to have
 two consecutive commas; not some code (whether NA, 99, 999, -1, ...)
 between them.

Yes. Arguably, na.strings=NULL should be the default (and na= for
write.csv) since delimited formats are (mainly) for communicating with
external programs, which are not likely to use the NA code (unless it is
for Namibia, North America, Noradrenalin, Niels Andersen, etc.)

However, back compatibility (including that with files written with R's
own write.csv) probably precludes changing anything at this point.
Notice that read.csv and friends do pass ... to read.table, so it is
easy to override the default setting.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


[R] R graphic help

2010-07-18 Thread Timothy O'Brien
Dear All,

I've done some searching, but to no avail --

I'm plotting x-y data via the plot command, and the log=x command.

The graphed x values are in scientific notation (1e-02 1e-01 1e+00 etc).
Might you have some idea on how I can get the plot to uses the x values
(0.01 0.10 1.0 10.0 etc) instead?  A related Q - where might a good place to
search for such answers?  I've tried using Google searches and reading some
posted Manuals but ...

Thanks,
Tim O'Brien

[[alternative HTML version deleted]]

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


Re: [R] R graphic help

2010-07-18 Thread baptiste auguie
Hi,

There may be a simpler way but try this,

plot(10^jitter(seq(-2,4,length=10)), 1:10, log=x, xaxt=n)
axis(1, at = axTicks(1),labels = format(axTicks(1),scientific=FALSE))

HTH,

baptiste

On 18 July 2010 10:58, Timothy O'Brien teobr...@gmail.com wrote:
 Dear All,

 I've done some searching, but to no avail --

 I'm plotting x-y data via the plot command, and the log=x command.

 The graphed x values are in scientific notation (1e-02 1e-01 1e+00 etc).
 Might you have some idea on how I can get the plot to uses the x values
 (0.01 0.10 1.0 10.0 etc) instead?  A related Q - where might a good place to
 search for such answers?  I've tried using Google searches and reading some
 posted Manuals but ...

 Thanks,
 Tim O'Brien

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

2010-07-18 Thread Jim Lemon

On 07/18/2010 06:58 PM, Timothy O'Brien wrote:

Dear All,

I've done some searching, but to no avail --

I'm plotting x-y data via the plot command, and the log=x command.

The graphed x values are in scientific notation (1e-02 1e-01 1e+00 etc).
Might you have some idea on how I can get the plot to uses the x values
(0.01 0.10 1.0 10.0 etc) instead?  A related Q - where might a good place to
search for such answers?  I've tried using Google searches and reading some
posted Manuals but ...


Hi Tim,
The scipen option is the one usually recommended for this. R works out 
how to print a number in a way that is (hopefully) maximally informative 
and minimally long. By penalizing this method, you can suppress 
scientific notation most of the time:


print(10)
[1] 1e+05
options(scipen=4)
print(10)
[1] 10

On the R home page is an option Search. The first search listed is Jon 
Baron's searchable archive messages, functions, etc. and is a good place 
to start. In this case, you would have to take two steps - see the 
scipen option mentioned and then look at the options help page. 
Usually you will get the answer straight from the search, _if_ you 
choose the correct search terms (life is never simple).


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] Continuing on with a loop when there's a failure

2010-07-18 Thread David Winsemius


On Jul 18, 2010, at 4:25 AM, Josh B wrote:


Hello Peter,

I tried your suggestion, but I was still not able to get it to work.  
Would you

mind looking at my code again? Here's what I'm trying:

x - read.table(textConnection(y1 y2 y3 x1 x2
indv.1 bagels donuts bagels 4 6
indv.2 donuts donuts donuts 5 1
indv.3 donuts donuts donuts 1 10
indv.4 donuts donuts donuts 10 9
indv.5 bagels donuts bagels 0 2
indv.6 bagels donuts bagels 2 9
indv.7 bagels donuts bagels 8 5
indv.8 bagels donuts bagels 4 1
indv.9 donuts donuts donuts 3 3
indv.10 bagels donuts bagels 5 9
indv.11 bagels donuts bagels 9 10
indv.12 bagels donuts bagels 3 1
indv.13 donuts donuts donuts 7 10
indv.14 bagels donuts bagels 2 10
indv.15 bagels donuts bagels 9 6), header = TRUE)


closeAllConnections()



results - matrix(nrow = 1, ncol = 3)
colnames(results) - c(y1, y2, y3)


require(rms)  # or Design
for (i in 1:2) {
   mod.poly3 - try(lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x),  
silent=TRUE)

   if(class(mod.poly3)[1] != 'try-error')
   {results[1,i] - anova(mod.poly3)[1,3]}

}

 results
y1 y2 y3
[1,] 0.6976063 NA NA




...and here's the output:


results

y1 y2 y3
[1,] NA NA NA

The results matrix is empty!




From: Peter Konings peter.l.e.koni...@gmail.com

Sent: Tue, July 13, 2010 5:45:17 PM
Subject: Re: [R] Continuing on with a loop when there's a failure

Hi Josh,

Test the class of the resulting object. If it is 'try-error' fill  
your result

with NA or do some other error handling.

result - try(somemodel)
if(class(result) == 'try-error')
{
# some error handling
} else {
# whatever happens if the result is ok
}

HTH
Peter.




In my opinion the try and tryCatch commands are written and  
documented rather

poorly. Thus I am not sure what to program exactly.

For instance, I could query mod.poly3 and use an if/then statement  
to proceed,
but querying mod.poly3 is weird. For instance, here's the output  
when it fails:



mod.poly3 - try(lrm(x[,2] ~ pol(x1, 3) + pol(x2, 3), data=x))


Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol,  
weights =

weights,  :

NA/NaN/Inf in foreign function call (arg 1)

mod.poly3
[1] Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol =  
tol, weights

=

weights,  : \n  NA/NaN/Inf in foreign function call (arg 1)\n
attr(,class)
[1] try-error

...and here's the output when it succeeds:

mod.poly3 - try(lrm(x[,1] ~ pol(x1, 3) + pol(x2, 3), data=x))
mod.poly3


Logistic Regression Model

lrm(formula = x[, 1] ~ pol(x1, 3) + pol(x2, 3), data = x)


Frequencies of Responses
bagels donuts
 10  5

Obs  Max Deriv Model L.R.   d.f.  P  C
 15  4e-04   3.37  6 0.7616   0.76
Dxy  Gamma  Tau-a R2  Brier  g
   0.52   0.52  0.248  0.279  0.183  1.411
 gr gp
4.1  0.261

   Coef S.E.Wald Z P
Intercept -5.68583 5.23295 -1.09  0.2772
x1 1.87020 2.14635  0.87  0.3836
x1^2  -0.42494 0.48286 -0.88  0.3788
x1^3   0.02845 0.03120  0.91  0.3618
x2 3.49560 3.54796  0.99  0.3245
x2^2  -0.94888 0.82067 -1.16  0.2476
x2^3   0.06362 0.05098  1.25  0.2121

...so what exactly would I query to design my if/then statement?






From: David Winsemius dwinsem...@comcast.net
To: David Winsemius dwinsem...@comcast.net

Sent: Tue, July 13, 2010 9:09:04 AM

Subject: Re: [R] Continuing on with a loop when there's a failure



On Jul 13, 2010, at 9:04 AM, David Winsemius wrote:



On Jul 13, 2010, at 8:47 AM, Josh B wrote:


Thanks again, David.


[[elided Yahoo spam]]


(BTW, it did work.)


Here's what I'm trying now:

for (i in 1:2) {
  mod.poly3 - try(lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x))
  results[1,i] - anova(mod.poly3)[1,3]
}


You need to do some programming.


(Or I suppose you could wrap both the lrm and the anova calls in  
try.)


You did not get an error from the lrm but rather from the anova  
call because
you tried to give the results of the try function to anova without  
first

checking to see if an error had occurred.

--David.


Here's what happens (from the console):

Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol,  
weights =

weights,  :
NA/NaN/Inf in foreign function call (arg 1)
Error in UseMethod(anova) :
no applicable method for 'anova' applied to an object of class  
try-error


...so I still can't make my results matrix. Could I ask you for  
some

specific
code to make this work? I'm not that familiar with the syntax for  
try or
tryCatch, and the help files for them are pretty bad, in my  
humble opinion.


I should clarify that I actually don't care about the failed runs  
per se. I
just want R to keep going in spite of them and give me my results  
matrix.


From: David Winsemius dwinsem...@comcast.net




Cc: R Help r-help@r-project.org
Sent: Mon, July 12, 2010 8:09:03 PM
Subject: Re: [R] Continuing on 

Re: [R] sort file names in numerical order

2010-07-18 Thread David Winsemius

Another option:

require(gtools)
?mixedsort

 mixedsort(fileNames)
[1] A1  A2  A10 B1  B2  B10

--  
 David


On Jul 18, 2010, at 5:16 AM, Duncan Mackay wrote:


Hi

Yes it is possible- one way is:

fileNames[order(sprintf(%02s, sub([[:upper:]],, fileNames)))]
[1] A1  B1  A2  B2  A10 B10

Regards

Duncan

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

At 06:47 18/07/2010, you wrote:



 I get some file names by list.files().
 These names are in  alphabetical order.
 I want to change it to logical numeric  order.
 Example:
  fileNames - c(A10, A1, A2, B1, B2,  B10)
  sort(fileNames)
 [1] A1  A10 A2  B1   B10 B2
 I want to have:
 A1  A2 A10 B1 B2 B10

 Is  this possible?

Greetings.  I see that you've gotten an elegant solution to your  
problem.
I've appended a poor-man's solution, which I generated more for my  
own

edification than for yours.

-- Mike


## modified file names, changed to exhibit sorting on letters
fileNames - c(A10, B10, A1, A2, B1, B2); fileNames

## use regular expressions to pick off letters, numbers
fnLet - gsub((^[^0-9]+).*$, \\1, fileNames); fnLet
fnNum - gsub(^[^0-9]+(.*)$, \\1, fileNames); fnNum

## need to force numeric sorting of the numbers
fnNum - as.numeric(fnNum)

## find the order of the numbers, for later use in subsetting
fnNumOrd - order(fnNum); fnNumOrd

## pack all the relevant information into a data frame, then select  
from that
fnPieces - data.frame(fnLet, fnNum, fileNames,  
stringsAsFactors=FALSE);

fnPieces

## partial sort by numbers only (gives new df)
dfPartialSort - fnPieces[fnNumOrd, ]; dfPartialSort

## find the order of the names, then select from new df with that
fnLetOrd - order(dfPartialSort[, 1]); fnLetOrd
dfFullSort - dfPartialSort[fnLetOrd, ]; dfFullSort

## the file names have gone along for the ride, so pick them off  
now

sortedFileNames - dfFullSort$fileNames; sortedFileNames

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


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


David Winsemius, MD
West Hartford, CT

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


Re: [R] loop troubles

2010-07-18 Thread David Winsemius


On Jul 17, 2010, at 9:09 PM, Joe P King wrote:


Hi all, I appreciate the help this list has given me before. I have a
question which has been perplexing me. I have been working on doing a
Bayesian calculating inserting studies sequentially after using a
non-informative prior to get a meta-analysis type result. I created a
function using three iterations of this, my code is below. I insert  
prior
mean and precision (I add precision manually because I want it to be  
zero
but if I include zero as prior variance I get an error cant divide  
by zero.
Now my question is instead of having the three iterations below, is  
there
anyway to create a loop, the only problem is I want to have elements  
from
the previous posterior to be the new prior and now I cant figure out  
how to

do the code below in a loop.


Perhaps if you set the problem up with vectors, it would become more  
obvious how to do it with indexing or loops:


n -  c(5, 10, 15)
ybar - c(12,12,14)  # and so on...

--
David

The data below is dummy data, I used a starting
mu of 1, and starting precision of 0.



bayes.analysis.treat-function(mu0,p0){

n1 = 5

n2 = 10

n3 = 15

ybar1 = 12

ybar2 = 13

ybar3 = 14

sd1 = 2

sd2 = 3

sd3 = 4

#posterior 1

var1 = sd1^2 #sample variance

p1 = n1/var1 #sample precision

p1n = p0+p1

mu1 = ((p0)/(p1n)*mu0)+((p1)/(p1n))*ybar1

sigma1 = 1/sqrt(p1n)

#posterior 2

var2 = sd2^2 #sample variance

p2 = n2/var2 #sample precision

p2n = p1n+p2

mu2 = ((p1n)/(p2n)*mu1)+((p2)/(p2n))*ybar2

sigma2 = 1/sqrt(p2n)

#posterior 3

var3 = sd3^2 #sample variance

p3 = n3/var3 #sample precision

p3n = p2n+p3

mu3 = ((p2n)/(p3n)*mu2)+((p3)/(p3n))*ybar3

sigma3 = 1/sqrt(p3n)

posterior-cbind(rbind(mu1,mu2,mu3),rbind(sigma1,sigma2,sigma3))

rownames(posterior)-c(Posterior 1, Posterior 2, Posterior 3)

colnames(posterior)-c(Mu, SD)

return(posterior)}



---

Joe King, M.A.

Ph.D. Student

University of Washington - Seattle

206-913-2912

mailto:j...@joepking.com j...@joepking.com

---

Never throughout history has a man who lived a life of ease left a  
name

worth remembering. --Theodore Roosevelt




[[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
West Hartford, CT

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


Re: [R] loop troubles

2010-07-18 Thread Joe P King
I tried that, this is what I tried, but I only get it to do one iteration
and then it wont cycle back. I am not sure how to tell it how to look at the
previous precision to add to the current new sample precision to get the new
precision. This is my first try at a loop so I am not sure if I am doing
anything right, sorry about the elementary question.

n=c(5,10,15)
ybar=c(12,13,14)
sd=c(2,3,4)
mutotals-matrix(nrow=length(n), ncol=1)
mu=1;p0=0
for (i in 1:length(n)){
  var = sd[i]^2 #sample variance
  p = n[i]/var #sample precision
  p0[i]= i
  pn = p0[i]+p[i]
  mu.out = ((p0[i])/(pn)*mu[i])+((p)/(pn))*ybar[i]
  sigma[i] = 1/sqrt(pn[i])
  mutotals[i,]-mu.out[i]
}

Joe King
206-913-2912
j...@joepking.com
Never throughout history has a man who lived a life of ease left a name
worth remembering. --Theodore Roosevelt



-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Sunday, July 18, 2010 5:36 AM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] loop troubles


On Jul 17, 2010, at 9:09 PM, Joe P King wrote:

 Hi all, I appreciate the help this list has given me before. I have a
 question which has been perplexing me. I have been working on doing a
 Bayesian calculating inserting studies sequentially after using a
 non-informative prior to get a meta-analysis type result. I created a
 function using three iterations of this, my code is below. I insert  
 prior
 mean and precision (I add precision manually because I want it to be  
 zero
 but if I include zero as prior variance I get an error cant divide  
 by zero.
 Now my question is instead of having the three iterations below, is  
 there
 anyway to create a loop, the only problem is I want to have elements  
 from
 the previous posterior to be the new prior and now I cant figure out  
 how to
 do the code below in a loop.

Perhaps if you set the problem up with vectors, it would become more  
obvious how to do it with indexing or loops:

n -  c(5, 10, 15)
ybar - c(12,12,14)  # and so on...

-- 
David
 The data below is dummy data, I used a starting
 mu of 1, and starting precision of 0.



 bayes.analysis.treat-function(mu0,p0){

 n1 = 5

 n2 = 10

 n3 = 15

 ybar1 = 12

 ybar2 = 13

 ybar3 = 14

 sd1 = 2

 sd2 = 3

 sd3 = 4

 #posterior 1

 var1 = sd1^2 #sample variance

 p1 = n1/var1 #sample precision

 p1n = p0+p1

 mu1 = ((p0)/(p1n)*mu0)+((p1)/(p1n))*ybar1

 sigma1 = 1/sqrt(p1n)

 #posterior 2

 var2 = sd2^2 #sample variance

 p2 = n2/var2 #sample precision

 p2n = p1n+p2

 mu2 = ((p1n)/(p2n)*mu1)+((p2)/(p2n))*ybar2

 sigma2 = 1/sqrt(p2n)

 #posterior 3

 var3 = sd3^2 #sample variance

 p3 = n3/var3 #sample precision

 p3n = p2n+p3

 mu3 = ((p2n)/(p3n)*mu2)+((p3)/(p3n))*ybar3

 sigma3 = 1/sqrt(p3n)

 posterior-cbind(rbind(mu1,mu2,mu3),rbind(sigma1,sigma2,sigma3))

 rownames(posterior)-c(Posterior 1, Posterior 2, Posterior 3)

 colnames(posterior)-c(Mu, SD)

 return(posterior)}



 ---

 Joe King, M.A.

 Ph.D. Student

 University of Washington - Seattle

 206-913-2912

 mailto:j...@joepking.com j...@joepking.com

 ---

 Never throughout history has a man who lived a life of ease left a  
 name
 worth remembering. --Theodore Roosevelt




   [[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
West Hartford, CT

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


Re: [R] slplot issue

2010-07-18 Thread Peter Ehlers

It's truly amazing how many people asking for help
can't be bothered to report what add-on packages they're
using. Shawn's query is a particularly egregious case:
slplot is mentioned in pkg:ccmn, which can be found on
CRAN, but which depends on pkg:pcaMethods which is on
Bioconductor. And pcaMethods has slplot().

Please, folks, do tell us what packages you are using!

[Now, I'm having trouble with the pemqzrsTawYY function;
can anybody help? :)]

  -Peter Ehlers

On 2010-07-17 16:32, Dennis Murphy wrote:

In which package would one find slplot? It's not in any of the 1800+
packages on my system...

Dennis


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


Re: [R] loop troubles

2010-07-18 Thread David Winsemius


On Jul 18, 2010, at 9:12 AM, Joe P King wrote:

I tried that, this is what I tried, but I only get it to do one  
iteration
and then it wont cycle back. I am not sure how to tell it how to  
look at the
previous precision to add to the current new sample precision to get  
the new

precision.


And I'm not exactly sure what you are trying to do since I found your  
problem statement insufficiently precise, but    if you have a  
vector, p and an index in a loop is i, then the previous p is  
just p[i-1]. Sometimes you can get constructs like the following to  
accomplish an indexed assignment:


p[2:length(n)] -a*p[1:(length(n)-1)]



This is my first try at a loop so I am not sure if I am doing
anything right, sorry about the elementary question.

n=c(5,10,15)
ybar=c(12,13,14)
sd=c(2,3,4)
mutotals-matrix(nrow=length(n), ncol=1)
mu=1;p0=0
for (i in 1:length(n)){
 var = sd[i]^2 #sample variance
 p = n[i]/var #sample precision


At this point you seem to be using p as a constant

 p0[i]= i


Comments might help to figure out why you are doing each of htese steps.


 pn = p0[i]+p[i]


Wouldn't pn need to be indexed as well? And now you seem to be using  
p as a vector but haven't extended it with c() or some other  
function, so on the second iteration it should fail.




 mu.out = ((p0[i])/(pn)*mu[i])+((p)/(pn))*ybar[i]
 sigma[i] = 1/sqrt(pn[i])
 mutotals[i,]-mu.out[i]
}


I get:
Error in sigma[i] = 1/sqrt(pn[i]) : object 'sigma' not found

You are not reporting the error messages this throws (which should  
have made it apparent that you needed to do some further setup of the  
data structures you are using, not just with p, pn, but also  
sigma. )




Joe King
206-913-2912
j...@joepking.com
Never throughout history has a man who lived a life of ease left a  
name

worth remembering. --Theodore Roosevelt



-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: Sunday, July 18, 2010 5:36 AM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] loop troubles


On Jul 17, 2010, at 9:09 PM, Joe P King wrote:


Hi all, I appreciate the help this list has given me before. I have a
question which has been perplexing me. I have been working on doing a
Bayesian calculating inserting studies sequentially after using a
non-informative prior to get a meta-analysis type result. I created a
function using three iterations of this, my code is below. I insert
prior
mean and precision (I add precision manually because I want it to be
zero
but if I include zero as prior variance I get an error cant divide
by zero.
Now my question is instead of having the three iterations below, is
there
anyway to create a loop, the only problem is I want to have elements
from
the previous posterior to be the new prior and now I cant figure out
how to
do the code below in a loop.


Perhaps if you set the problem up with vectors, it would become more
obvious how to do it with indexing or loops:

n -  c(5, 10, 15)
ybar - c(12,12,14)  # and so on...

--
David

The data below is dummy data, I used a starting
mu of 1, and starting precision of 0.



bayes.analysis.treat-function(mu0,p0){

n1 = 5

n2 = 10

n3 = 15

ybar1 = 12

ybar2 = 13

ybar3 = 14

sd1 = 2

sd2 = 3

sd3 = 4

#posterior 1

var1 = sd1^2 #sample variance

p1 = n1/var1 #sample precision

p1n = p0+p1

mu1 = ((p0)/(p1n)*mu0)+((p1)/(p1n))*ybar1

sigma1 = 1/sqrt(p1n)

#posterior 2

var2 = sd2^2 #sample variance

p2 = n2/var2 #sample precision

p2n = p1n+p2

mu2 = ((p1n)/(p2n)*mu1)+((p2)/(p2n))*ybar2

sigma2 = 1/sqrt(p2n)

#posterior 3

var3 = sd3^2 #sample variance

p3 = n3/var3 #sample precision

p3n = p2n+p3

mu3 = ((p2n)/(p3n)*mu2)+((p3)/(p3n))*ybar3

sigma3 = 1/sqrt(p3n)

posterior-cbind(rbind(mu1,mu2,mu3),rbind(sigma1,sigma2,sigma3))

rownames(posterior)-c(Posterior 1, Posterior 2, Posterior 3)

colnames(posterior)-c(Mu, SD)

return(posterior)}



---

Joe King, M.A.

Ph.D. Student

University of Washington - Seattle

206-913-2912

mailto:j...@joepking.com j...@joepking.com

---

Never throughout history has a man who lived a life of ease left a
name
worth remembering. --Theodore Roosevelt




[[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
West Hartford, CT

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


David Winsemius, MD
West Hartford, CT

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

Re: [R] Identify points (was Plot error)

2010-07-18 Thread James Platt
This is exactly what I want as I will have several thousand data  
points on the final graph i make, so the scroll over option is ideal.


I've read the TeachingDemos pdf, I'm working on a Mac so Cannot use  
HWidentify. I have installed and loaded the TeachingDemos package but  
im having trouble loading the tkrplot package after installing it  
won't load.


 library(tcltk)
Loading Tcl/Tk interface ... Error : .onLoad failed in loadNamespace()  
for 'tcltk', details:

  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared library '/Library/Frameworks/ 
R.framework/Resources/library/tcltk/libs/i386/tcltk.so':
  dlopen(/Library/Frameworks/R.framework/Resources/library/tcltk/libs/ 
i386/tcltk.so, 10): Library not loaded: /usr/local/lib/libtcl8.5.dylib
  Referenced from: /Library/Frameworks/R.framework/Resources/library/ 
tcltk/libs/i386/tcltk.so

  Reason: image not found
Error: package/namespace load failed for 'tcltk'

Cheers,

James


On 17 Jul 2010, at 18:12, Peter Ehlers wrote:


On 2010-07-17 9:50, James Platt wrote:

The other question I have:

Is there any way to link the data point on the graph to the name of a
row

i.e in my table:

name value_1 value_2
bill   14
ben  2   2
jane 3   1

I click on the data point at 2,2 and it would read out ben



Check out HWidentify or HTKidentify in pkg:TeachingDemos.

 -Peter Ehlers




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


Re: [R] Help with a problem

2010-07-18 Thread jim holtman
You can also use 'embed' to create a list of indices you can use to do the test:

 dat
   dsc1 c2
1  2010-04-03   100  0
2  2010-04-30 11141 15
3  2010-05-01 3 16
4  2010-05-02  7615 14
5  2010-05-03  6910 17
6  2010-05-04  5035  3
7  2010-05-05  3007 15
8  2010-05-06 4 14
9  2010-05-07  8335 17
10 2010-05-08  2897 13
11 2010-05-09  6377 17
12 2010-05-10  3177 17
13 2010-05-11  7946 15
14 2010-05-12  8705  0
15 2010-05-13  9030 16
16 2010-05-14  8682 16
17 2010-05-15  8440  1
 # create index to check against
 indx - embed(seq(nrow(dat)), 7)
 result - apply(indx, 1, function(x){
+ # whatever condition you want
+ sum(dat$c1[x] = 5000  dat$c2[x]  0)
+ })

 result
 [1] 4 4 4 4 4 3 3 3 4 4 5



On Sun, Jul 18, 2010 at 3:06 AM, Stephan Kolassa stephan.kola...@gmx.de wrote:
 Hi all,

 zoo::rollmean() is a nice idea. But if I understand Mike correctly, he wants
 5 out of any 7 consecutive logicals to be TRUE, where these 5 do not
 necessarily need to be consecutive themselves. (remaining open question:
 could, e.g., the condition on c1 be TRUE for rows 1,2,3,4,5 and on c2 for
 rows 3,4,5,6,7, or would it need to be TRUE for the same rows?). Then
 something like this would make sense:

 any(rollmean(dat$c1=100,7)=5/7-.01  rollmean(dat$c2=8,7)=5/7-.01))

 or

 any(rollmean(dat$c1=100,7)=5/7-.01  dat$c2=8,7)=5/7-.01))

 depending on the open question above.

 The -.01 above may be necessary in light of FAQ 7.31.

 HTH,
 Stephan



 Joshua Wiley schrieb:

 Hi Michael,

 The days in your example do not look continuous (at least from my
 thinking), so you may have extra requirements in mind, but take a look
 at this code.  My general thought was first to turn each column into a
 logical vector (c1 = 100 and c2 = 8).  Taking advantage of the fact
 that R treats TRUE as 1 and FALSE as 0, compute a rolling mean.  If
 (and only if) 5 consecutive values are TRUE, the mean will be 1.  Next
 I added the rolling means for each column, and then tested whether any
 were 2 (i.e., 1 + 1).

 Cheers,

 Josh

 ###
 #Load required package
 library(zoo)

 #Your data with ds converted to Date
 #from dput()
 dat -
 structure(list(ds = structure(c(14702, 14729, 14730, 14731, 14732,
 14733, 14734, 14735, 14736, 14737, 14738, 14739, 14740, 14741,
 14742, 14743, 14744), class = Date), c1 = c(100L, 11141L, 3L,
 7615L, 6910L, 5035L, 3007L, 4L, 8335L, 2897L, 6377L, 3177L, 7946L,
 8705L, 9030L, 8682L, 8440L), c2 = c(0L, 15L, 16L, 14L, 17L, 3L,
 15L, 14L, 17L, 13L, 17L, 17L, 15L, 0L, 16L, 16L, 1L)), .Names = c(ds,
 c1, c2), row.names = c(NA, -17L), class = data.frame)

 #Order by ds
 dat - dat[order(dat$ds), ]

 yourvar - 0

 #Test that 5 consecutive values from c1 AND c2 meet requirements
 if(any(
  c(rollmean(dat$c1 = 100, 5) + rollmean(dat$c2 = 8, 5)) == 2)
   ) {yourvar - 1}

 ###

 On Sat, Jul 17, 2010 at 2:38 PM, Michael Hess mlh...@med.umich.edu
 wrote:

 Sorry for not being clear.

 In the dataset there are around 100 or so days of data (in the case also
 rows of data)

 I need to make sure that the person meets that c1 is at least 100 AND c2
 is at least 8 for 5 of 7 continuous days.

 I will play with what I have and see if I can find out how to do this.

 Thanks for the help!

 Michael

 Stephan Kolassa  07/17/10 4:50 PM 

 Mike,

 I am slightly unclear on what you want to do. Do you want to check rows
 1 and 7 or 1 *to* 7? Should c1 be at least 100 for *any one* or *all*
 rows you are looking at, and same for c2?

 You can sort your data like this:
 data - data[order(data$ds),]

 Type ?order for help. But also do this for added enlightenment...:

 library(fortunes)
 fortune(dog)

 Next, your analysis on the sorted data frame. As I said, I am not
 entirely clear on what you are looking at, but the following may solve
 your problem with choices 1 to 7 and any one above.

 foo - 0
 for ( ii in 1:(nrow(data)-8) ) {
  if (any(data$c1[ii+seq(0,6)]=100)  any(data$c2[ii+seq(0,6)]=8)) {
    foo - 1
    break
  }
 }

 The variable foo should contain what you want it to. Look at ?any
 (and, if this does not do what you want it to, at ?all) for further info.

 No doubt this could be vectorized, but I think the loop is clear enough.

 Good luck!
 Stephan



 Michael Hess schrieb:

 Hello R users,

 I am a researcher at the University of Michigan looking for a solution
 to an R problem.  I have loaded my data in from a mysql database and it
 looks like this

 data

           ds c1 c2
 1  2010-04-03        100           0
 2  2010-04-30      11141          15
 3  2010-05-01      3          16
 4  2010-05-02       7615          14
 5  2010-05-03       6910          17
 6  2010-05-04       5035          3
 7  2010-05-05       3007          15
 8  2010-05-06       4          14
 9  2010-05-07       8335          17
 10 2010-05-08       2897          13
 11 2010-05-09       6377          17
 12 2010-05-10       3177          17
 13 2010-05-11       7946          15
 14 2010-05-12       8705    

[R] Giovanna Jonalasinio è fuori ufficio, Out of Office

2010-07-18 Thread Giovanna . Jonalasinio


Risposta automatica dal 18/7/10 fino al 27/7/10

I'm not in Rome and I won't read my email regularly untill the 27th of July

Non sono a Roma e leggerò la posta sporadicamente fino al 27 luglio
[[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] Identify points (was Plot error)

2010-07-18 Thread David Winsemius


On Jul 18, 2010, at 9:43 AM, James Platt wrote:

This is exactly what I want as I will have several thousand data  
points on the final graph i make, so the scroll over option is ideal.


I've read the TeachingDemos pdf, I'm working on a Mac so Cannot use  
HWidentify.


Not true.

I have installed and loaded the TeachingDemos package but im having  
trouble loading the tkrplot package after installing it won't load.


 library(tcltk)


In the Mac GUI Package Installer, I cannot even find a package by that  
name. However, then running the HWidentify example after  
require(Teaching Demos),  tcltk does get loaded as well as X11, making  
me think you need to provide further information such as that  
requested in the Posting Guide. You may also want to review the  
material in the R for Mac OS X FAQ.


--
David.

 sessionInfo()
R version 2.11.1 Patched (2010-06-14 r52281)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] tkrplot_0.0-18TeachingDemos_2.6 gtools_2.6.2
[4] Design_2.3-0  Hmisc_3.8-1   survival_2.35-8
[7] lattice_0.18-8

loaded via a namespace (and not attached):
[1] cluster_1.12.3 grid_2.11.1tools_2.11.1

Loading Tcl/Tk interface ... Error : .onLoad failed in  
loadNamespace() for 'tcltk', details:

 call: dyn.load(file, DLLpath = DLLpath, ...)
 error: unable to load shared library '/Library/Frameworks/ 
R.framework/Resources/library/tcltk/libs/i386/tcltk.so':
 dlopen(/Library/Frameworks/R.framework/Resources/library/tcltk/libs/ 
i386/tcltk.so, 10): Library not loaded: /usr/local/lib/libtcl8.5.dylib
 Referenced from: /Library/Frameworks/R.framework/Resources/library/ 
tcltk/libs/i386/tcltk.so

 Reason: image not found
Error: package/namespace load failed for 'tcltk'
On 17 Jul 2010, at 18:12, Peter Ehlers wrote:


On 2010-07-17 9:50, James Platt wrote:

The other question I have:

Is there any way to link the data point on the graph to the name  
of a

row

i.e in my table:

name value_1 value_2
bill   14
ben  2   2
jane 3   1

I click on the data point at 2,2 and it would read out ben



Check out HWidentify or HTKidentify in pkg:TeachingDemos.

-Peter Ehlers



David Winsemius, MD
West Hartford, CT

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


[R] producing biplot of canonical correlation analysis

2010-07-18 Thread elaine kuo
Dear List,

I would like to obtain biplot containing arrows and variable labels.
However, after checking the previous message and package CCA and function
anacor,
my attempt remains an open question.

Please kindly advise code or package I might miss to achieve it.

Thank you.

Elaine

[[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] Identify points (was Plot error)

2010-07-18 Thread Peter Ehlers

You can always use the identify() function which will
leave the id of the point on the plot; see ?identify.

But you do eventually have to sort out your Mac problem.
Sorry, I can't help with that.

  -Peter Ehlers

On 2010-07-18 7:43, James Platt wrote:

This is exactly what I want as I will have several thousand data points
on the final graph i make, so the scroll over option is ideal.

I've read the TeachingDemos pdf, I'm working on a Mac so Cannot use
HWidentify. I have installed and loaded the TeachingDemos package but im
having trouble loading the tkrplot package after installing it won't load.

  library(tcltk)
Loading Tcl/Tk interface ... Error : .onLoad failed in loadNamespace()
for 'tcltk', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared library
'/Library/Frameworks/R.framework/Resources/library/tcltk/libs/i386/tcltk.so':

dlopen(/Library/Frameworks/R.framework/Resources/library/tcltk/libs/i386/tcltk.so,
10): Library not loaded: /usr/local/lib/libtcl8.5.dylib
Referenced from:
/Library/Frameworks/R.framework/Resources/library/tcltk/libs/i386/tcltk.so
Reason: image not found
Error: package/namespace load failed for 'tcltk'

Cheers,

James



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


Re: [R] re. Mathematica and R

2010-07-18 Thread Erich Neuwirth
The wiki on rcom.univie.ac.at
in section
R(D)COM, rcom, and other software systems
has an example how to use R from within Mathematica on Windows.
You will need to install statconnDCOM and rcom
available from the same site.


On Jul 17, 2010, at 1:06 PM, Alan Kelly wrote:

 David - information on calling R from within Mathematica can be found at the
 following link:
 http://www.mofeel.net/1164-comp-soft-sys-math-mathematica/13022.aspx
 HTH,
 Alan Kelly
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

--
Erich Neuwirth
Didactic Center for Computer Science and Institute for Scientific Computing
University of Vienna





[[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] heatmap.2 - change column row locations; angle / rotate

2010-07-18 Thread Karl Brand

Esteemed R user's,

I'm struggling to achieve some details of a heatmap using heatmap.2():

1. Change label locations, for both rows  columns from the default 
right  bottom, to left and top.
Can this be done within heatmap.2()? Or do i need to suppress this 
default behavior (how) and call a new function to relabel (what) 
specifying locations?


2. Change the angle of the labels.
By default column labels are 90deg anti-clock-wise from horizontal. How 
to bring them back to horizontal? Or better, rotate 45deg clock-wise 
from horizontal (ie., rotate 135deg a.clock.wise from default)?


Any suggestions or pointers to helpful resources greatly appreciated,

Karl

--
Karl Brand
Department of Genetics
Erasmus MC
Dr Molewaterplein 50
3015 GE Rotterdam
T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268

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

2010-07-18 Thread mauede
I installed package plotrix because reading its vignette it looks like it can 
help me solve a legend problem.
The package instaleed correctly on my Mac OS/X 10.5.8
But I cannot reproduce the examples centered on function lgendg.
 library(plotrix)
 plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1),type=n, 
+ main=Test of grouped legend function) 
 legendg(0.5,0.8,c(one,two,three),pch=list(1,2:3,4:6), 
+ col=list(2,3:4,5:7)) 
Error: could not find function legendg

My problem with the regular R legend function is that I cannot indicate in 
the legend the line plotted by the command abline
Here is the code. Attached is the plot. Any suggestion is welcome. Thank you.
Maura


x11(width=10,heigh=8)
plot(NN,LB,xlim=c(1,300),ylim=c(0,3),
 main=Intrinsic Dimensionality of 1D 
Helix,font.main=2,cex.main=2,col.main=red,
 xlab=Number of Nearest-Neighbors,ylab=Estimated  
Dimension,col.lab=red,cex.lab=1,font.lab=2,
 xaxt=n,yaxt=n,pch=19,col=red4)
axis(1,at=NN[1:40],labels=NN[1:40],cex.lab=1,cex.axis=0.8,col.axis=blue,lwd.ticks=0.5,col.ticks
 =gray3)
axis(2,at=c(0,0.5,1,1.5,2,2.5,3,3.5,4),labels=c(0,0.5,1,1.5,2,2.5,3,3.5,4),cex.lab=1,cex.axis=0.8,
 col.axis=blue,lwd.ticks=0.5,col.ticks =gray3)
lines(NN,McG,pch=18,col=green)
lines(NN,PBJD,pch=20,col=magenta1)
points(NN,GRPR,pch=18,col=cyan) 
abline(h=1,pch= 1,lty=1,col=black) 
legend(topright,legend = 
c(Levina-Bickel,MacKay-Ghahramani,Pettis-Bailey-Jain-Dubes,Grassberger-Procaccia,Helix
 Dimension),
   text.width = strwidth(Pettis-Bailey-Jain-Dubes),pch = c(19,18,20,18,1),
   col = c(red4,green,magenta1,cyan,black),text.col = 
black,lty=c(-1,-1,-1,1),
   bg =snow)

















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


[R] NA preserved in logical call - I don't understand this behavior because NA is not equal to 0

2010-07-18 Thread stephen sefick
I am confused by the behavior of the below piece of code.  The NAs are
making it past the logical call ==0.  I am sure that I am missing
something.  I just don't understand this behavior.  Thanks for your
help in advance.


code###
left - (structure(list(measurment_num = c(2, 2.2, 2.4, 2.6, 2.8, 2.82,
3, NA, NA, NA), bankfull_depths_m = c(1.29, 1.28, 1.23, 0.18,
-0.05, 0, -0.09, NA, NA, NA)), .Names = c(measurment_num, bankfull_depths_m
), row.names = c(10L, 11L, 12L, 13L, 14L, 20L, 15L, 16L, 17L,
18L), class = data.frame))

if(sum(left[,bankfull_depths_m]==0, na.rm=TRUE) == 1){
left_min - left[left[,bankfull_depths_m]==0, measurment_num]
}

left
##

-- 
Stephen Sefick

| Auburn University                                   |
| Department of Biological Sciences           |
| 331 Funchess Hall                                  |
| Auburn, Alabama                                   |
| 36849                                                    |
|___|
| sas0...@auburn.edu                             |
| http://www.auburn.edu/~sas0025             |
|___|

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                -K. Mullis

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


[R] log transformation

2010-07-18 Thread jarry


Hi,

I am reading an article in which, first, some given p-results are
obtained, and, second, these are afterwards transformed and expressed as the
NEGATIVE base-10 logarithm of the p-value. 

My question is if anyone could indicate how is such transformation achieved
with R and how are they expressed exponentially, as in for example 1.8E-18.

Thank you!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/log-transformation-tp2293162p2293162.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] Reading files with varying number of columns

2010-07-18 Thread Tim Clark
Dear R list,
I am trying to read files with a varying number of columns and can't figure out 
how to get them in the proper format.  Some rows have five value and some have 
seven.  Is there a way to read them in so that two empty columns are added to 
every row that has only five values?  An example of the data follows.  Thanks!  
Tim

46,B,00301,2004-02-03,11:59:16
46,B,00301,2004-02-03,12:03:43
46,B,00301,2004-02-03,12:39:17
46,B,00301,2004-02-03,23:07:28
43,C,00232,2004-02-04,07:39:57,-1.5,meters
44,A,00230,2004-02-04,07:44:59
44,A,00230,2004-02-04,07:46:19
44,A,00230,2004-02-04,07:48:24
44,A,00230,2004-02-04,07:49:12
43,C,00232,2004-02-04,07:53:08,2.5,meters
44,A,00230,2004-02-04,07:54:34
44,A,00230,2004-02-04,07:55:08
43,C,00232,2004-02-04,07:56:18,2.9,meters
43,C,00232,2004-02-04,07:56:39,2.5,meters
46,B,00301,2004-02-04,08:00:49
43,C,00232,2004-02-04,08:02:12,-1.1,meters
43,C,00232,2004-02-04,08:04:01,2.2,meters
43,C,00232,2004-02-04,08:04:26,3.3,meters
43,C,00232,2004-02-04,08:40:26,2.9,meters
43,C,00232,2004-02-04,08:41:04,-2.2,meters
43,C,00232,2004-02-04,08:42:44,2.2,meters
43,C,00232,2004-02-04,08:44:31,2.9,meters
44,A,00231,2004-02-04,09:04:43
44,A,00231,2004-02-04,09:10:30
44,A,00231,2004-02-04,09:12:08
44,A,00231,2004-02-04,09:13:32
44,A,00231,2004-02-04,09:14:06
43,C,00232,2004-02-04,09:18:24,0.4,meters
43,C,00232,2004-02-04,09:20:13,2.5,meters
44,A,00231,2004-02-04,09:21:04
44,A,00231,2004-02-04,09:22:53
44,A,00231,2004-02-04,09:25:32
44,A,00231,2004-02-04,09:29:31
44,A,00231,2004-02-04,09:30:05
43,C,00232,2004-02-04,09:53:25,2.5,meters
43,C,00232,2004-02-04,09:53:53,1.5,meters
46,B,00301,2004-02-04,22:16:24
46,B,00301,2004-02-04,22:19:32
46,B,00258,2004-02-04,23:44:01
46,B,00258,2004-02-04,23:44:28


 Tim Clark

Marine Ecologist
National Park of American Samoa
Pago Pago, American Samoa  96799




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


Re: [R] package plotrix

2010-07-18 Thread Uwe Ligges



On 18.07.2010 17:59, mau...@alice.it wrote:

I installed package plotrix because reading its vignette it looks like it can help me 
solve a legend problem.
The package instaleed correctly on my Mac OS/X 10.5.8
But I cannot reproduce the examples centered on function lgendg.



You mean legendg.



library(plotrix)
plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1),type=n,

+ main=Test of grouped legend function)

legendg(0.5,0.8,c(one,two,three),pch=list(1,2:3,4:6),

+ col=list(2,3:4,5:7))
Error: could not find function legendg



That works for me. Try to upgrade bopth R and plotrix if you have not 
already.





My problem with the regular R legend function is that I cannot indicate in the legend 
the line plotted by the command abline
Here is the code. Attached is the plot. Any suggestion is welcome. Thank you.
Maura


x11(width=10,heigh=8)
plot(NN,LB,xlim=c(1,300),ylim=c(0,3),
  main=Intrinsic Dimensionality of 1D 
Helix,font.main=2,cex.main=2,col.main=red,
  xlab=Number of Nearest-Neighbors,ylab=Estimated  
Dimension,col.lab=red,cex.lab=1,font.lab=2,
 xaxt=n,yaxt=n,pch=19,col=red4)
axis(1,at=NN[1:40],labels=NN[1:40],cex.lab=1,cex.axis=0.8,col.axis=blue,lwd.ticks=0.5,col.ticks
 =gray3)
axis(2,at=c(0,0.5,1,1.5,2,2.5,3,3.5,4),labels=c(0,0.5,1,1.5,2,2.5,3,3.5,4),cex.lab=1,cex.axis=0.8,
 col.axis=blue,lwd.ticks=0.5,col.ticks =gray3)
lines(NN,McG,pch=18,col=green)
lines(NN,PBJD,pch=20,col=magenta1)
points(NN,GRPR,pch=18,col=cyan)
abline(h=1,pch= 1,lty=1,col=black)
legend(topright,legend = 
c(Levina-Bickel,MacKay-Ghahramani,Pettis-Bailey-Jain-Dubes,Grassberger-Procaccia,Helix
 Dimension),
text.width = strwidth(Pettis-Bailey-Jain-Dubes),pch = 
c(19,18,20,18,1),
   col = c(red4,green,magenta1,cyan,black),text.col = 
black,lty=c(-1,-1,-1,1),
   bg =snow)






We do not have the data nor do we see the figure, hence this is not 
reproducible for us.


Uwe Ligges

















e tutti i telefonini TIM!
Vai su



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Eliminating case numbers in a dendrogram

2010-07-18 Thread Holger Steinmetz

Hi folks,

I conducted a hierarchical cluster analysis. As I wanted to illustrate the
result, I created a dendrogram with the code

plot(as.dendrogram(fit),sub=,xlab=,ylab=Heterogeneity,nodePar =
list(lab.cex=.5,pch=NA,xlab=))

However, the dendrogram contains the case numbers and, as I have N = 300,
looks not very nice.

Can anybody tell me how to prevent the case numbers?

Thanks in advance
Holger
http://r.789695.n4.nabble.com/file/n2293207/Dendrogram.jpeg 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Eliminating-case-numbers-in-a-dendrogram-tp2293207p2293207.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] NA preserved in logical call - I don't understand this behavior because NA is not equal to 0

2010-07-18 Thread Uwe Ligges



On 18.07.2010 18:02, stephen sefick wrote:

I am confused by the behavior of the below piece of code.  The NAs are
making it past the logical call ==0.  I am sure that I am missing
something.  I just don't understand this behavior.  Thanks for your
help in advance.


code###
left- (structure(list(measurment_num = c(2, 2.2, 2.4, 2.6, 2.8, 2.82,
3, NA, NA, NA), bankfull_depths_m = c(1.29, 1.28, 1.23, 0.18,
-0.05, 0, -0.09, NA, NA, NA)), .Names = c(measurment_num, bankfull_depths_m
), row.names = c(10L, 11L, 12L, 13L, 14L, 20L, 15L, 16L, 17L,
18L), class = data.frame))

if(sum(left[,bankfull_depths_m]==0, na.rm=TRUE) == 1){
left_min- left[left[,bankfull_depths_m]==0, measurment_num]
}



NA == 0 is ??? -- NA!

Use is.na() to check for missing values.


Uwe Ligges







left
##



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


Re: [R] Reading files with varying number of columns

2010-07-18 Thread Uwe Ligges

See argument fill in ?read.table

Uwe Ligges


On 18.07.2010 12:14, Tim Clark wrote:

Dear R list,
I am trying to read files with a varying number of columns and can't figure out
how to get them in the proper format.  Some rows have five value and some have
seven.  Is there a way to read them in so that two empty columns are added to
every row that has only five values?  An example of the data follows.  Thanks!
Tim


46,B,00301,2004-02-03,11:59:16
46,B,00301,2004-02-03,12:03:43
46,B,00301,2004-02-03,12:39:17
46,B,00301,2004-02-03,23:07:28
43,C,00232,2004-02-04,07:39:57,-1.5,meters
44,A,00230,2004-02-04,07:44:59
44,A,00230,2004-02-04,07:46:19
44,A,00230,2004-02-04,07:48:24
44,A,00230,2004-02-04,07:49:12
43,C,00232,2004-02-04,07:53:08,2.5,meters
44,A,00230,2004-02-04,07:54:34
44,A,00230,2004-02-04,07:55:08
43,C,00232,2004-02-04,07:56:18,2.9,meters
43,C,00232,2004-02-04,07:56:39,2.5,meters
46,B,00301,2004-02-04,08:00:49
43,C,00232,2004-02-04,08:02:12,-1.1,meters
43,C,00232,2004-02-04,08:04:01,2.2,meters
43,C,00232,2004-02-04,08:04:26,3.3,meters
43,C,00232,2004-02-04,08:40:26,2.9,meters
43,C,00232,2004-02-04,08:41:04,-2.2,meters
43,C,00232,2004-02-04,08:42:44,2.2,meters
43,C,00232,2004-02-04,08:44:31,2.9,meters
44,A,00231,2004-02-04,09:04:43
44,A,00231,2004-02-04,09:10:30
44,A,00231,2004-02-04,09:12:08
44,A,00231,2004-02-04,09:13:32
44,A,00231,2004-02-04,09:14:06
43,C,00232,2004-02-04,09:18:24,0.4,meters
43,C,00232,2004-02-04,09:20:13,2.5,meters
44,A,00231,2004-02-04,09:21:04
44,A,00231,2004-02-04,09:22:53
44,A,00231,2004-02-04,09:25:32
44,A,00231,2004-02-04,09:29:31
44,A,00231,2004-02-04,09:30:05
43,C,00232,2004-02-04,09:53:25,2.5,meters
43,C,00232,2004-02-04,09:53:53,1.5,meters
46,B,00301,2004-02-04,22:16:24
46,B,00301,2004-02-04,22:19:32
46,B,00258,2004-02-04,23:44:01
46,B,00258,2004-02-04,23:44:28



  Tim Clark

Marine Ecologist
National Park of American Samoa
Pago Pago, American Samoa  96799




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Eliminating case numbers in a dendrogram

2010-07-18 Thread Uwe Ligges



On 18.07.2010 19:02, Holger Steinmetz wrote:


Hi folks,

I conducted a hierarchical cluster analysis. As I wanted to illustrate the
result, I created a dendrogram with the code

plot(as.dendrogram(fit),sub=,xlab=,ylab=Heterogeneity,nodePar =
list(lab.cex=.5,pch=NA,xlab=))

However, the dendrogram contains the case numbers and, as I have N = 300,
looks not very nice.

Can anybody tell me how to prevent the case numbers?


You do not want any labels???

In that case, see argument leaflab in ?plot.dendrogram

Uwe Ligges



Thanks in advance
Holger
http://r.789695.n4.nabble.com/file/n2293207/Dendrogram.jpeg


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


Re: [R] NA preserved in logical call - I don't understand this behavior because NA is not equal to 0

2010-07-18 Thread David Winsemius


On Jul 18, 2010, at 12:02 PM, stephen sefick wrote:


I am confused by the behavior of the below piece of code.  The NAs are
making it past the logical call ==0.  I am sure that I am missing
something.  I just don't understand this behavior.  Thanks for your
help in advance.


code###
left - (structure(list(measurment_num = c(2, 2.2, 2.4, 2.6, 2.8,  
2.82,

3, NA, NA, NA), bankfull_depths_m = c(1.29, 1.28, 1.23, 0.18,
-0.05, 0, -0.09, NA, NA, NA)), .Names = c(measurment_num,  
bankfull_depths_m

), row.names = c(10L, 11L, 12L, 13L, 14L, 20L, 15L, 16L, 17L,
18L), class = data.frame))

if(sum(left[,bankfull_depths_m]==0, na.rm=TRUE) == 1){
left_min - left[left[,bankfull_depths_m]==0, measurment_num]
}

left


Why aren't you looking at left_min? That is what the code is supposed  
to be changing. I do not get an error and left_min[1] (now) =='s  2.82.


Regarding why there are the 3 NA's, ... you need to look at the  
documentation for Extract in the section very appropriately entitled:

NAs in indexing

I have been bitten by that behavior more times than I care to admit  
and I am not the only person that thinks that aspect of the R language  
is badly designed. See Aniko Szabo's comments:


http://radfordneal.wordpress.com/2008/09/21/design-flaws-in-r-3-%E2%80%94-zero-subscripts/

The problem is in data.frame[ and any NA in a logical vector will  
return a row of NA's. This can be avoid by wrapping which() around the  
logical vector which seems entirely wasteful or using subset().



David Winsemius, MD
West Hartford, CT

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


Re: [R] Continuing on with a loop when there's a failure

2010-07-18 Thread David Winsemius


On Jul 18, 2010, at 12:28 PM, Josh B wrote:

Thanks very much again David for your helpful answers. However, the  
code STILL does not appear to be working properly!


Even though the third time through the loop *should* work, it  
appears that R has given up after the second time through the loop.  
What I mean is: although y2 causes the lrm function to fail, y3 is a  
kosher variable. If the loop continues on, it should give data for  
the model with y3.


Right, but your loop index only went to 2!!! Your design, not mine.

--
David.


But if you look at the matrix called results, it returns NA for  
the third spot corresponding to the model of y3:


results
y1 y2 y3
[1,] 0.6976063 NA NA

If you run y3 in isolation, rather than through the loop, you can  
see that it should work and contribute data to the matrix called  
results:


mod.poly3 - lrm(x[,3] ~ pol(x1, 3) + pol(x2, 3), data=x)
anova(mod.poly3)[1,3]
[1] 0.6976063

Any ideas?

From: David Winsemius dwinsem...@comcast.net
To: Josh B josh...@yahoo.com
Cc: Peter Konings peter.l.e.koni...@gmail.com; R Help r-help@r-project.org 


Sent: Sun, July 18, 2010 3:33:07 PM
Subject: Re: [R] Continuing on with a loop when there's a failure


On Jul 18, 2010, at 4:25 AM, Josh B wrote:

 Hello Peter,

 I tried your suggestion, but I was still not able to get it to  
work. Would you

 mind looking at my code again? Here's what I'm trying:

 x - read.table(textConnection(y1 y2 y3 x1 x2
 indv.1 bagels donuts bagels 4 6
 indv.2 donuts donuts donuts 5 1
 indv.3 donuts donuts donuts 1 10
 indv.4 donuts donuts donuts 10 9
 indv.5 bagels donuts bagels 0 2
 indv.6 bagels donuts bagels 2 9
 indv.7 bagels donuts bagels 8 5
 indv.8 bagels donuts bagels 4 1
 indv.9 donuts donuts donuts 3 3
 indv.10 bagels donuts bagels 5 9
 indv.11 bagels donuts bagels 9 10
 indv.12 bagels donuts bagels 3 1
 indv.13 donuts donuts donuts 7 10
 indv.14 bagels donuts bagels 2 10
 indv.15 bagels donuts bagels 9 6), header = TRUE)

closeAllConnections()


 results - matrix(nrow = 1, ncol = 3)
 colnames(results) - c(y1, y2, y3)

require(rms)  # or Design
for (i in 1:2) {
  mod.poly3 - try(lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x),  
silent=TRUE)

  if(class(mod.poly3)[1] != 'try-error')
  {results[1,i] - anova(mod.poly3)[1,3]}

}

 results
y1 y2 y3
[1,] 0.6976063 NA NA



 ...and here's the output:

 results
y1 y2 y3
 [1,] NA NA NA

 The results matrix is empty!



 
 From: Peter Konings peter.l.e.koni...@gmail.com

 Sent: Tue, July 13, 2010 5:45:17 PM
 Subject: Re: [R] Continuing on with a loop when there's a failure

 Hi Josh,

 Test the class of the resulting object. If it is 'try-error' fill  
your result

 with NA or do some other error handling.

 result - try(somemodel)
 if(class(result) == 'try-error')
 {
 # some error handling
 } else {
 # whatever happens if the result is ok
 }

 HTH
 Peter.




 In my opinion the try and tryCatch commands are written and  
documented rather

 poorly. Thus I am not sure what to program exactly.

 For instance, I could query mod.poly3 and use an if/then  
statement to proceed,
 but querying mod.poly3 is weird. For instance, here's the output  
when it fails:


 mod.poly3 - try(lrm(x[,2] ~ pol(x1, 3) + pol(x2, 3), data=x))

 Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol,  
weights =

 weights,  :

 NA/NaN/Inf in foreign function call (arg 1)
 mod.poly3
 [1] Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol =  
tol, weights

 =
 weights,  : \n  NA/NaN/Inf in foreign function call (arg 1)\n
 attr(,class)
 [1] try-error

 ...and here's the output when it succeeds:
 mod.poly3 - try(lrm(x[,1] ~ pol(x1, 3) + pol(x2, 3), data=x))
 mod.poly3

 Logistic Regression Model

 lrm(formula = x[, 1] ~ pol(x1, 3) + pol(x2, 3), data = x)


 Frequencies of Responses
 bagels donuts
  10  5

Obs  Max Deriv Model L.R.  d.f.  P  C
  15  4e-04  3.37  60.7616  0.76
Dxy  Gamma  Tau-aR2  Brier  g
0.52  0.52  0.248  0.279  0.183  1.411
  grgp
4.1  0.261

CoefS.E.Wald Z P
 Intercept -5.68583 5.23295 -1.09  0.2772
 x11.87020 2.14635  0.87  0.3836
 x1^2  -0.42494 0.48286 -0.88  0.3788
 x1^3  0.02845 0.03120  0.91  0.3618
 x23.49560 3.54796  0.99  0.3245
 x2^2  -0.94888 0.82067 -1.16  0.2476
 x2^3  0.06362 0.05098  1.25  0.2121

 ...so what exactly would I query to design my if/then statement?




 

 From: David Winsemius dwinsem...@comcast.net
 To: David Winsemius dwinsem...@comcast.net

 Sent: Tue, July 13, 2010 9:09:04 AM

 Subject: Re: [R] Continuing on with a loop when there's a failure



 On Jul 13, 2010, at 9:04 AM, David Winsemius wrote:


 On Jul 13, 2010, at 8:47 AM, Josh B wrote:

 Thanks again, David.

 [[elided Yahoo spam]]


 (BTW, it did work.)

 Here's what I'm 

Re: [R] Toggle between the various pages for multi-page figures

2010-07-18 Thread Uwe Ligges



On 16.07.2010 18:38, mahesh samtani wrote:

Hello,

I am a new R user having transitioned over from S-plus recently. I have a
question that is probably very trivial but I am having trouble finding a
solution. In S-plus, graphic pages are created as tabs when multi-page
figures are created. I have shown the R code for xpose.VPC (a function
within library xpose4 for R) where I want the figure from each Strata (STRT)
to displayed on a different page. When I run the code, the pages just zoom
by and I was wondering if I could toggle between the various pages. I can
only export the last of the 8 pages that are created with the code below
(and I wish to export all 8 pages not just the last one):





In order to export:
Better start the appropriate graphics device (such as pdf()) before you 
start plotting and when finished plotting ask R to dev.off(). All your 
graphics are collected in the file(s) in the end which is a bit device 
dependent. See you favorite device's help page for details.


Uwe Ligges




xpose.VPC (vpc.info=vpc1/vpc_results.csv, vpctab=vpc1/vpctab1,

PI=NULL, by=STRT, PI.ci=area, PI.real=TRUE,type=n,

PI.limits=c(0.05,0.95),*layout=c(1,1,8)*,xlb=Time
(week),ylb=Concentration (ng/mL),

scales = list(x = list(at=seq(0,3360,by=336)  ,
labels=seq(0,20,by=2 )),

  y =
list(at=log(c(.3,1,3,7.5,20,50,150)), labels=c(.3,1,3,7.5,20,50,150)) ))



Please help,

MNS

[[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] Error using the mi package

2010-07-18 Thread Uwe Ligges

Since we do not have the data and cannot reproduce:
What about sending a reproducible example to the mi maintainer in the 
first step?


Best,
Uwe Ligges


On 15.07.2010 16:48, Andrew Miles wrote:

I'm trying to impute data using the mi package, but after running
through almost the entire first round of imputations (which takes quite
a while), it throws this error (I'll include the whole output prior to
the error for context). Does anyone know what is causing it, or how I
can fix it?

More specifically, how can I tell what is throwing the error so I know
what to fix? Is it a problem with a variable? With the formula I am
using for imputations?

Beginning Multiple Imputation ( Thu Jul 15 09:10:33 2010 ):
Iteration 1
Imputation 1 : min.func* Tenure* Salary* Housing* ord_stat* rural_now*
a3* a7* a8* a9* a10* a12* a13* a14* a15* a16* a17a* a17b* a17c* a17d*
a17e* a17f* a18* a21* b1a* b1b* b1c* b1d* b1e* b1f* b1g* b1h* b1i* b3a*
b3b* b3c* b3d* b3e* b3f* b3g* b4a* b4b* b4c* b4d* b4e* b4f* b4g* b4h*
b4i* b4j* b4k* b4l* b4m* b4n* b4o* b4p* b5a* b5b* b5c* b5d* b5e* b5f*
b5g* b5h* b5i* b5j* b5k* b5l* b5m* b5n* b5o* b6a* b6b* b6c* b6d* b6e*
b6f* b6g* b6h* b6i* b6j* b6k* b6l* b7a* b7b* b7c* b7d* b7e* b7f* b7g*
b7h* b7i* b7j* b7k* b9b* b10a* b10b* b13a* b13b* b13c* b14* c3* c4* c5*
c12a* c12b* c12c* c12d* c12e* c12f* c19* d1* d2* d3* d6* d7a* d7b* d7c*
d7d* d7e* d7f* d7g* d7h* d7i* d8a* d8b* d8c* d8d* d8e* d8f* d8g* d8h*
d8i* d9a* d9b* d9c* d9d* d9e* d10a* d10b* d10c* d10d* d10e* d10f* d11*
d13* d14* e1* e2* e3* e5* e6* f2* f3a* f3b* f3c* f3d* f3e* f4* f6* f7*
f8* f9* f12* f14* f15* f16* f20* f21* f22* f23* f25* g2* g3* g6* g8* g9*
g12* g13* g15* g17* g18* g22* g25* g26* g27* g28* g31* g34* g43* g55*
g58* g59* g60* g61* g63* g65* g68a* g68b* g69* g70* g71* g91* g92* g93*
g94* g95*
Error in AveVar[s, i, ] - c(avevar.mean, avevar.sd) :
number of items to replace is not a multiple of replacement length

And here is what traceback() gives:
  traceback()
3: .local(object, ...)
2: mi(imp.data, info = info2, n.iter = 6, preprocess = FALSE)
1: mi(imp.data, info = info2, n.iter = 6, preprocess = FALSE)

Andrew Miles

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

2010-07-18 Thread Uwe Ligges

Why do you think R-help is a mailing list about LaTeX?

Best,
Uwe Ligges



On 13.07.2010 23:05, Felipe Carrillo wrote:

Hi:
My head is spinning with this latex doc so hopefully after I align my tables to
the left of the page
my headache are going to be over. I always use:
\hspace*{-0.1in}
to move my figures horizontally to the left margin of the page but the table
below doesn't move at all,
but instead it gets sideways. Not sure if \begin{landscape} has something to do
with it or is just me.
I  hope someone could lend some help on this matter.

\documentclass[11pt]{article}
\usepackage{longtable,verbatim}
\usepackage{longtable,pdflscape,graphicx}
\usepackage{fmtcount,hyperref} % displaying latex counters
  %\usepackage[top=0.2inch, bottom=0.2inch, left=2cm, right=2cm]{geometry}
\usepackage{fullpage}
\usepackage{ctable}
\title{United States Department of the Interior}
\begin{document}
  %\setlength{\topmargin}{-1inch} % Just an example
\setkeys{Gin}{width=1\textwidth} % makes all the graphics scales
\maketitle
echo=F,results=hide=
reportDF- structure(list(IDDate = c(3/12/2010, 3/13/2010, 3/14/2010,
3/15/2010), FirstRunoftheYear = c(33 (119 ? 119), n (0 ? 0), 893 (110 ?
146),
140 (111 ? 150)), SecondRunoftheYear = c(33 (71 ? 71), n (0 ? 0),
337 (67 ? 74), 140 (68 ? 84)), ThirdRunoftheYear = c(890 (32 ? 47),
n (0 ? 0), 10,602 (32 ? 52), 2,635 (34 ? 66)), FourthRunoftheYear = c(0 (
? ),
n (0 ? 0), 0 ( ? ), 0 ( ? )), LastRunoftheYear = c(0 ( ? ), n (0 ? 0),
0 ( ? ), 0 ( ? ))), .Names = c(IDDate, First Run of the Year, Second
Run of the Year,
Third Run of the Year, Fourth Run of the Year, Last Run of the Year),
row.names = c(NA, 4L), class = data.frame)
@
\begin{landscape}
\begin{table}[!tbp]
\begin{center}
\begin{tabular}{ll}\hline\hline
\multicolumn{1}{c}{IDDate}
\multicolumn{1}{c}{First Run of the Year}
\multicolumn{1}{c}{Second Run of the Year}
\multicolumn{1}{c}{Third Run of the Year}
\multicolumn{1}{c}{Fourth Run of the Year}
\multicolumn{1}{c}{Last Run of the Year}\tabularnewline
\hline
13/12/201033 (119 ? 119)33 (71 ? 71)890 (32 ? 47)0 ( ? )0 ( ?
)\tabularnewline
23/13/2010n (0 ? 0)n (0 ? 0)n (0 ? 0)n (0 ? 0)n (0 ? 0)\tabularnewline
33/14/2010893 (110 ? 146)337 (67 ? 74)10,602 (32 ? 52)0 ( ? )0 ( ?
)\tabularnewline
43/15/2010140 (111 ? 150)140 (68 ? 84)2,635 (34 ? 66)0 ( ? )0 ( ?
)\tabularnewline
\hline
\end{tabular}
\end{center}
\end{table}\end{landscape}
\end{document}

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA




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


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


Re: [R] Correct function name for text display of S4 object

2010-07-18 Thread Uwe Ligges



On 13.07.2010 03:35, Andrew Liu wrote:

Hello,

I am working on an R package for storing order book data. I currently
have a display method that has the following output (ob is an S4 object):


display(ob)


Current time is 09:35:02

Price Ask Size

--

11.42 900

11.41 1,400

11.40 1,205

11.39 1,600

11.38 400

--

2,700 11.36

1,100 11.35

1,100 11.34

1,600 11.33

700 11.32

--

Bid Size Price

The package already has show, summary, and plot methods.

Is there a more conventional name than display for the above output, or
is display as good as any other name?


Well, if show/print and summary are already dong different things, then 
go with a new name 


Uwe Ligges




Thanks,

Andrew

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


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


Re: [R] latex table question

2010-07-18 Thread Felipe Carrillo
I' ve seen latex questions being solved here that's why I sent my question
to this list but someone already told me about the latex forum so the same 
question has already been solved there, Sorry about that.

 



- Original Message 
 From: Uwe Ligges lig...@statistik.tu-dortmund.de
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Cc: r-h...@stat.math.ethz.ch
 Sent: Sun, July 18, 2010 10:24:39 AM
 Subject: Re: [R] latex table question
 
 Why do you think R-help is a mailing list about LaTeX?
 
 Best,
 Uwe Ligges
 
 
 
 On 13.07.2010 23:05, Felipe Carrillo wrote:
  Hi:
  My head is spinning with this latex doc so hopefully after I align my 
  tables 
to
  the left of the page
  my headache are going to be over. I always use:
  \hspace*{-0.1in}
  to move my figures horizontally to the left margin of the page but the table
  below doesn't move at all,
  but instead it gets sideways. Not sure if \begin{landscape} has something 
  to 
do
  with it or is just me.
  I  hope someone could lend some help on this matter.
 
  \documentclass[11pt]{article}
  \usepackage{longtable,verbatim}
  \usepackage{longtable,pdflscape,graphicx}
  \usepackage{fmtcount,hyperref} % displaying latex counters
   %\usepackage[top=0.2inch, bottom=0.2inch, left=2cm, right=2cm]{geometry}
  \usepackage{fullpage}
  \usepackage{ctable}
  \title{United States Department of the Interior}
  \begin{document}
   %\setlength{\topmargin}{-1inch} % Just an example
  \setkeys{Gin}{width=1\textwidth} % makes all the graphics scales
  \maketitle
  echo=F,results=hide=
  reportDF- structure(list(IDDate = c(3/12/2010, 3/13/2010, 3/14/2010,
  3/15/2010), FirstRunoftheYear = c(33 (119 ? 119), n (0 ? 0), 893 
  (110 
?
  146),
  140 (111 ? 150)), SecondRunoftheYear = c(33 (71 ? 71), n (0 ? 0),
  337 (67 ? 74), 140 (68 ? 84)), ThirdRunoftheYear = c(890 (32 ? 47),
  n (0 ? 0), 10,602 (32 ? 52), 2,635 (34 ? 66)), FourthRunoftheYear = 
c(0 (
  ? ),
  n (0 ? 0), 0 ( ? ), 0 ( ? )), LastRunoftheYear = c(0 ( ? ), n (0 ? 
0),
  0 ( ? ), 0 ( ? ))), .Names = c(IDDate, First Run of the Year, 
Second
  Run of the Year,
  Third Run of the Year, Fourth Run of the Year, Last Run of the Year),
  row.names = c(NA, 4L), class = data.frame)
  @
  \begin{landscape}
  \begin{table}[!tbp]
  \begin{center}
  \begin{tabular}{ll}\hline\hline
  \multicolumn{1}{c}{IDDate}
  \multicolumn{1}{c}{First Run of the Year}
  \multicolumn{1}{c}{Second Run of the Year}
  \multicolumn{1}{c}{Third Run of the Year}
  \multicolumn{1}{c}{Fourth Run of the Year}
  \multicolumn{1}{c}{Last Run of the Year}\tabularnewline
  \hline
  13/12/201033 (119 ? 119)33 (71 ? 71)890 (32 ? 47)0 ( ? )0 ( ?
  )\tabularnewline
  23/13/2010n (0 ? 0)n (0 ? 0)n (0 ? 0)n (0 ? 0)n (0 ? 0)\tabularnewline
  33/14/2010893 (110 ? 146)337 (67 ? 74)10,602 (32 ? 52)0 ( ? )0 ( ?
  )\tabularnewline
  43/15/2010140 (111 ? 150)140 (68 ? 84)2,635 (34 ? 66)0 ( ? )0 ( ?
  )\tabularnewline
  \hline
  \end{tabular}
  \end{center}
  \end{table}\end{landscape}
  \end{document}
 
  Felipe D. Carrillo
  Supervisory Fishery Biologist
  Department of the Interior
  US Fish  Wildlife Service
  California, USA
 
 
 
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 




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


Re: [R] log transformation

2010-07-18 Thread Ben Bolker
jarry jarryjarry58 at hotmail.com writes:

 
 
 Hi,
 
 I am reading an article in which, first, some given p-results are
 obtained, and, second, these are afterwards transformed and expressed as the
 NEGATIVE base-10 logarithm of the p-value. 
 
 My question is if anyone could indicate how is such transformation achieved
 with R and how are they expressed exponentially, as in for example 1.8E-18.
 

  ?? presumably 

 -log10(pvalue)

  ??

  so a p-value of 1.8e-18 (i.e., 1.8 times 10^-18) would correspond to
a value of 17.74

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


[R] R: package plotrix

2010-07-18 Thread mauede

-Messaggio originale-
Da: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Inviato: dom 18/07/2010 18.58
A: mau...@alice.it
Cc: j...@bitwrit.com.au; r-h...@stat.math.ethz.ch
Oggetto: Re: [R] package plotrix
 


On 18.07.2010 17:59, mau...@alice.it wrote:
 I installed package plotrix because reading its vignette it looks like it can 
 help me solve a legend problem.
 The package instaleed correctly on my Mac OS/X 10.5.8
 But I cannot reproduce the examples centered on function lgendg.


You mean legendg.

Yes. Sorry for my typo.

 library(plotrix)
 plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1),type=n,
 + main=Test of grouped legend function)
 legendg(0.5,0.8,c(one,two,three),pch=list(1,2:3,4:6),
 + col=list(2,3:4,5:7))
 Error: could not find function legendg


That works for me. Try to upgrade bopth R and plotrix if you have not 
already.
I am running R 2.9.2 on my Mac OS/X 10.5.8
I always feel uncomfortable with upgrades.  
Shall I uninstall R 2.9.2 in advance of instaling the ew bversion for Mac ?
I ave no reason for keeping two versions. 


 My problem with the regular R legend function is that I cannot indicate in 
 the legend the line plotted by the command abline
 Here is the code. Attached is the plot. Any suggestion is welcome. Thank you.
 Maura


 x11(width=10,heigh=8)
 plot(NN,LB,xlim=c(1,300),ylim=c(0,3),
   main=Intrinsic Dimensionality of 1D 
 Helix,font.main=2,cex.main=2,col.main=red,
   xlab=Number of Nearest-Neighbors,ylab=Estimated  
 Dimension,col.lab=red,cex.lab=1,font.lab=2,
xaxt=n,yaxt=n,pch=19,col=red4)
 axis(1,at=NN[1:40],labels=NN[1:40],cex.lab=1,cex.axis=0.8,col.axis=blue,lwd.ticks=0.5,col.ticks
  =gray3)
 axis(2,at=c(0,0.5,1,1.5,2,2.5,3,3.5,4),labels=c(0,0.5,1,1.5,2,2.5,3,3.5,4),cex.lab=1,cex.axis=0.8,
col.axis=blue,lwd.ticks=0.5,col.ticks =gray3)
 lines(NN,McG,pch=18,col=green)
 lines(NN,PBJD,pch=20,col=magenta1)
 points(NN,GRPR,pch=18,col=cyan)
 abline(h=1,pch= 1,lty=1,col=black)
 legend(topright,legend = 
 c(Levina-Bickel,MacKay-Ghahramani,Pettis-Bailey-Jain-Dubes,Grassberger-Procaccia,Helix
  Dimension),
 text.width = strwidth(Pettis-Bailey-Jain-Dubes),pch = 
 c(19,18,20,18,1),
  col = c(red4,green,magenta1,cyan,black),text.col = 
 black,lty=c(-1,-1,-1,1),
  bg =snow)





We do not have the data nor do we see the figure, hence this is not 
reproducible for us.

Actually I attached the TIFF plot that I am attaching again.

Thank you .
Maura 

Uwe Ligges



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


Re: [R] R: package plotrix

2010-07-18 Thread Uwe Ligges



On 18.07.2010 19:57, David Winsemius wrote:


On Jul 18, 2010, at 1:32 PM, mau...@alice.it wrote:



-Messaggio originale-
Da: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Inviato: dom 18/07/2010 18.58
A: mau...@alice.it
Cc: j...@bitwrit.com.au; r-h...@stat.math.ethz.ch
Oggetto: Re: [R] package plotrix



On 18.07.2010 17:59, mau...@alice.it wrote:

I installed package plotrix because reading its vignette it looks
like it can help me solve a legend problem.
The package instaleed correctly on my Mac OS/X 10.5.8
But I cannot reproduce the examples centered on function lgendg.



You mean legendg.

Yes. Sorry for my typo.


library(plotrix)
plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1),type=n,

+ main=Test of grouped legend function)

legendg(0.5,0.8,c(one,two,three),pch=list(1,2:3,4:6),

+ col=list(2,3:4,5:7))
Error: could not find function legendg



That works for me. Try to upgrade bopth R and plotrix if you have not
already.
I am running R 2.9.2 on my Mac OS/X 10.5.8
I always feel uncomfortable with upgrades.
Shall I uninstall R 2.9.2 in advance of instaling the ew bversion for
Mac ?


No need to do so. The appropriate 2.11.1 folders will be created in the
R.framework folder and the links in the Current folder will be updated.




This is ancient, hence please upgrade anyway - and you have still not 
reported your plotrix version nor if you updated the package.






I ave no reason for keeping two versions.



My problem with the regular R legend function is that I cannot
indicate in the legend the line plotted by the command abline
Here is the code. Attached is the plot. Any suggestion is welcome.
Thank you.
Maura


x11(width=10,heigh=8)
plot(NN,LB,xlim=c(1,300),ylim=c(0,3),
main=Intrinsic Dimensionality of 1D
Helix,font.main=2,cex.main=2,col.main=red,
xlab=Number of Nearest-Neighbors,ylab=Estimated
Dimension,col.lab=red,cex.lab=1,font.lab=2,
xaxt=n,yaxt=n,pch=19,col=red4)
axis(1,at=NN[1:40],labels=NN[1:40],cex.lab=1,cex.axis=0.8,col.axis=blue,lwd.ticks=0.5,col.ticks
=gray3)
axis(2,at=c(0,0.5,1,1.5,2,2.5,3,3.5,4),labels=c(0,0.5,1,1.5,2,2.5,3,3.5,4),cex.lab=1,cex.axis=0.8,

col.axis=blue,lwd.ticks=0.5,col.ticks =gray3)
lines(NN,McG,pch=18,col=green)
lines(NN,PBJD,pch=20,col=magenta1)
points(NN,GRPR,pch=18,col=cyan)
abline(h=1,pch= 1,lty=1,col=black)
legend(topright,legend =
c(Levina-Bickel,MacKay-Ghahramani,Pettis-Bailey-Jain-Dubes,Grassberger-Procaccia,Helix
Dimension),
text.width = strwidth(Pettis-Bailey-Jain-Dubes),pch =
c(19,18,20,18,1),
col = c(red4,green,magenta1,cyan,black),text.col =
black,lty=c(-1,-1,-1,1),
bg =snow)






We do not have the data nor do we see the figure, hence this is not
reproducible for us.

Actually I attached the TIFF plot that I am attaching again.


Re-read the Posting Guide. It specifies what can be attached and TIFF
files are NOT in the list of acceptable types. Uwe might have gotten a
copy but the rest of us did not.




No, the tiff probably did not pass our e-mail filters at all.

Best,
Uwe Ligges

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Import of specific column of many space-delimited text files

2010-07-18 Thread LogLord

Hi,

I have about 300 space-delimited text files and from each file I want to
import one specific column into R to create a data frame where all imported
columns are included.
Is there a smart way to do so?

Thanks!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Import-of-specific-column-of-many-space-delimited-text-files-tp2293273p2293273.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] NA preserved in logical call - I don't understand this behavior because NA is not equal to 0

2010-07-18 Thread Hadley Wickham
 The problem is in data.frame[ and any NA in a logical vector will return a
 row of NA's. This can be avoid by wrapping which() around the logical vector
 which seems entirely wasteful or using subset().

The basic philosophy that causes this behaviour is sensible in my
opinion: missing values must always be handled explicitly.  Sure it's
a bit of a hassle, but it being explicit prevents you from making
major errors in an analysis.

In my opinion, the flaw is that R doesn't apply this philosophy
entirely consistently: I think factor and table should default to
exclude = NULL.

Hadley


-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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


Re: [R] Import of specific column of many space-delimited text files

2010-07-18 Thread Joshua Wiley
Hi,

There might be better ways, but here's something that might help you
get started.  Obviously you'll need to tweak a lot of things.  If your
files do not have a uniform number of columns and the column you want
is not always in the same position, it may be easier to just read it
all in and then extract the column by name ocne they are in R.

# a little sample data
var1 var2 var3
54 6326 45
66 3452 44
52 5436 43
64 7865 48
54 6534 44

#how you can read in just one column
read.table(clipboard, header = TRUE, sep =  ,
 colClasses = c(NULL, integer, NULL))

#Grab a files in your WD that have .txt in them
file.names - grep(.txt, list.files(), value = TRUE)

#Initialize a list to store all the file you read in
mydata - vector(list, length = length(file.names))

#Read in data files and assign them to your list
for(i in seq_along(file.names)) {
  mydata[[i]] - read.table(file = file.names[i], sep =  ,
colClasses = c(NULL, integer, NULL))
}


Cheers,

Josh


On Sun, Jul 18, 2010 at 11:22 AM, LogLord nils.sch...@web.de wrote:

 Hi,

 I have about 300 space-delimited text files and from each file I want to
 import one specific column into R to create a data frame where all imported
 columns are included.
 Is there a smart way to do so?

 Thanks!
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Import-of-specific-column-of-many-space-delimited-text-files-tp2293273p2293273.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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] NA preserved in logical call - I don't understand this behavior because NA is not equal to 0

2010-07-18 Thread David Winsemius


On Jul 18, 2010, at 2:52 PM, Hadley Wickham wrote:

The problem is in data.frame[ and any NA in a logical vector will  
return a
row of NA's. This can be avoid by wrapping which() around the  
logical vector

which seems entirely wasteful or using subset().


The basic philosophy that causes this behaviour is sensible in my
opinion: missing values must always be handled explicitly.  Sure it's
a bit of a hassle, but it being explicit prevents you from making
major errors in an analysis.


How does this apply to the treatment of logical indexing in the  
function data.frame[ ? The returned value is not expected to have  
the same number of rows as the source object and the profusion of  
duplicate NA rows serves what purpose? Wouldn't it be more consistent  
to have the constructs:


dfrm[which(logical_vector), ]
dfrm[logical_vector , ]

 return the same object?



In my opinion, the flaw is that R doesn't apply this philosophy
entirely consistently: I think factor and table should default to
exclude = NULL.

Hadley


--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/


David Winsemius, MD
West Hartford, CT

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


Re: [R] Import of specific column of many space-delimited text files

2010-07-18 Thread LogLord

That worked perfectly well. 
Thanks a lot!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Import-of-specific-column-of-many-space-delimited-text-files-tp2293273p2293342.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] loop troubles

2010-07-18 Thread Joe P King
This is the latest code I have been trying, but it when I try to turn the
vectors of SD into a vector of variances, it turns into a scalar.

n=c(NULL,13,89,50)
ybar=c(NULL,1.58,1.26,0.80)
sd=c(NULL,2.19,4.18,5.47)
mu=1;sigma=1;p0=0;var1=NULL;p=NULL;pn=NULL
for (i in 2:length(n)){
  var1[i] = sd[i]^2 #sample variance
  p[i] = n[i]/var1[i] #sample precision
  p0=p[i-1]
  pn[i] = p0[i]+p[i]
  mu[i] = ((p0[i])/(pn[i])*mu[i])+((p[i])/(pn[i]))*ybar[i]
  sigma[i] = 1/sqrt(pn[i])
  mutotals[i,]-mu[i]
}

Joe King
206-913-2912
j...@joepking.com
Never throughout history has a man who lived a life of ease left a name
worth remembering. --Theodore Roosevelt



-Original Message-
From: Joe P King [mailto:j...@joepking.com] 
Sent: Sunday, July 18, 2010 6:13 AM
To: 'r-help@r-project.org'
Subject: RE: [R] loop troubles

I tried that, this is what I tried, but I only get it to do one iteration
and then it wont cycle back. I am not sure how to tell it how to look at the
previous precision to add to the current new sample precision to get the new
precision. This is my first try at a loop so I am not sure if I am doing
anything right, sorry about the elementary question.

n=c(5,10,15)
ybar=c(12,13,14)
sd=c(2,3,4)
mutotals-matrix(nrow=length(n), ncol=1)
mu=1;p0=0
for (i in 1:length(n)){
  var = sd[i]^2 #sample variance
  p = n[i]/var #sample precision
  p0[i]= i
  pn = p0[i]+p[i]
  mu.out = ((p0[i])/(pn)*mu[i])+((p)/(pn))*ybar[i]
  sigma[i] = 1/sqrt(pn[i])
  mutotals[i,]-mu.out[i]
}

Joe King
206-913-2912
j...@joepking.com
Never throughout history has a man who lived a life of ease left a name
worth remembering. --Theodore Roosevelt



-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Sunday, July 18, 2010 5:36 AM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] loop troubles


On Jul 17, 2010, at 9:09 PM, Joe P King wrote:

 Hi all, I appreciate the help this list has given me before. I have a
 question which has been perplexing me. I have been working on doing a
 Bayesian calculating inserting studies sequentially after using a
 non-informative prior to get a meta-analysis type result. I created a
 function using three iterations of this, my code is below. I insert  
 prior
 mean and precision (I add precision manually because I want it to be  
 zero
 but if I include zero as prior variance I get an error cant divide  
 by zero.
 Now my question is instead of having the three iterations below, is  
 there
 anyway to create a loop, the only problem is I want to have elements  
 from
 the previous posterior to be the new prior and now I cant figure out  
 how to
 do the code below in a loop.

Perhaps if you set the problem up with vectors, it would become more  
obvious how to do it with indexing or loops:

n -  c(5, 10, 15)
ybar - c(12,12,14)  # and so on...

-- 
David
 The data below is dummy data, I used a starting
 mu of 1, and starting precision of 0.



 bayes.analysis.treat-function(mu0,p0){

 n1 = 5

 n2 = 10

 n3 = 15

 ybar1 = 12

 ybar2 = 13

 ybar3 = 14

 sd1 = 2

 sd2 = 3

 sd3 = 4

 #posterior 1

 var1 = sd1^2 #sample variance

 p1 = n1/var1 #sample precision

 p1n = p0+p1

 mu1 = ((p0)/(p1n)*mu0)+((p1)/(p1n))*ybar1

 sigma1 = 1/sqrt(p1n)

 #posterior 2

 var2 = sd2^2 #sample variance

 p2 = n2/var2 #sample precision

 p2n = p1n+p2

 mu2 = ((p1n)/(p2n)*mu1)+((p2)/(p2n))*ybar2

 sigma2 = 1/sqrt(p2n)

 #posterior 3

 var3 = sd3^2 #sample variance

 p3 = n3/var3 #sample precision

 p3n = p2n+p3

 mu3 = ((p2n)/(p3n)*mu2)+((p3)/(p3n))*ybar3

 sigma3 = 1/sqrt(p3n)

 posterior-cbind(rbind(mu1,mu2,mu3),rbind(sigma1,sigma2,sigma3))

 rownames(posterior)-c(Posterior 1, Posterior 2, Posterior 3)

 colnames(posterior)-c(Mu, SD)

 return(posterior)}



 ---

 Joe King, M.A.

 Ph.D. Student

 University of Washington - Seattle

 206-913-2912

 mailto:j...@joepking.com j...@joepking.com

 ---

 Never throughout history has a man who lived a life of ease left a  
 name
 worth remembering. --Theodore Roosevelt




   [[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
West Hartford, CT

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


Re: [R] loop troubles

2010-07-18 Thread David Winsemius


On Jul 18, 2010, at 4:21 PM, Joe P King wrote:

This is the latest code I have been trying, but it when I try to  
turn the

vectors of SD into a vector of variances, it turns into a scalar.

n=c(NULL,13,89,50)
ybar=c(NULL,1.58,1.26,0.80)
sd=c(NULL,2.19,4.18,5.47)
mu=1;sigma=1;p0=0;var1=NULL;p=NULL;pn=NULL


If you are going to passing values to the above using indices then  
they should be defined as vectors of the appropriate length. It would  
not be absolutely necessary to to so , but if you don't, then you need  
to extend them using the c() function, which you do not seem to have  
caught onto yet.




for (i in 2:length(n)){
 var1[i] = sd[i]^2 #sample variance
 p[i] = n[i]/var1[i] #sample precision
 p0=p[i-1]
 pn[i] = p0[i]+p[i]
 mu[i] = ((p0[i])/(pn[i])*mu[i])+((p[i])/(pn[i]))*ybar[i]
 sigma[i] = 1/sqrt(pn[i])
 mutotals[i,]-mu[i]
}

Joe King
206-913-2912
j...@joepking.com
Never throughout history has a man who lived a life of ease left a  
name

worth remembering. --Theodore Roosevelt



-Original Message-
From: Joe P King [mailto:j...@joepking.com]
Sent: Sunday, July 18, 2010 6:13 AM
To: 'r-help@r-project.org'
Subject: RE: [R] loop troubles

I tried that, this is what I tried, but I only get it to do one  
iteration
and then it wont cycle back. I am not sure how to tell it how to  
look at the
previous precision to add to the current new sample precision to get  
the new
precision. This is my first try at a loop so I am not sure if I am  
doing

anything right, sorry about the elementary question.

n=c(5,10,15)
ybar=c(12,13,14)
sd=c(2,3,4)
mutotals-matrix(nrow=length(n), ncol=1)
mu=1;p0=0
for (i in 1:length(n)){
 var = sd[i]^2 #sample variance
 p = n[i]/var #sample precision
 p0[i]= i
 pn = p0[i]+p[i]
 mu.out = ((p0[i])/(pn)*mu[i])+((p)/(pn))*ybar[i]
 sigma[i] = 1/sqrt(pn[i])
 mutotals[i,]-mu.out[i]
}

Joe King
206-913-2912
j...@joepking.com
Never throughout history has a man who lived a life of ease left a  
name

worth remembering. --Theodore Roosevelt



-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: Sunday, July 18, 2010 5:36 AM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] loop troubles


On Jul 17, 2010, at 9:09 PM, Joe P King wrote:


Hi all, I appreciate the help this list has given me before. I have a
question which has been perplexing me. I have been working on doing a
Bayesian calculating inserting studies sequentially after using a
non-informative prior to get a meta-analysis type result. I created a
function using three iterations of this, my code is below. I insert
prior
mean and precision (I add precision manually because I want it to be
zero
but if I include zero as prior variance I get an error cant divide
by zero.
Now my question is instead of having the three iterations below, is
there
anyway to create a loop, the only problem is I want to have elements
from
the previous posterior to be the new prior and now I cant figure out
how to
do the code below in a loop.


Perhaps if you set the problem up with vectors, it would become more
obvious how to do it with indexing or loops:

n -  c(5, 10, 15)
ybar - c(12,12,14)  # and so on...

--
David

The data below is dummy data, I used a starting
mu of 1, and starting precision of 0.



bayes.analysis.treat-function(mu0,p0){

n1 = 5

n2 = 10

n3 = 15

ybar1 = 12

ybar2 = 13

ybar3 = 14

sd1 = 2

sd2 = 3

sd3 = 4

#posterior 1

var1 = sd1^2 #sample variance

p1 = n1/var1 #sample precision

p1n = p0+p1

mu1 = ((p0)/(p1n)*mu0)+((p1)/(p1n))*ybar1

sigma1 = 1/sqrt(p1n)

#posterior 2

var2 = sd2^2 #sample variance

p2 = n2/var2 #sample precision

p2n = p1n+p2

mu2 = ((p1n)/(p2n)*mu1)+((p2)/(p2n))*ybar2

sigma2 = 1/sqrt(p2n)

#posterior 3

var3 = sd3^2 #sample variance

p3 = n3/var3 #sample precision

p3n = p2n+p3

mu3 = ((p2n)/(p3n)*mu2)+((p3)/(p3n))*ybar3

sigma3 = 1/sqrt(p3n)

posterior-cbind(rbind(mu1,mu2,mu3),rbind(sigma1,sigma2,sigma3))

rownames(posterior)-c(Posterior 1, Posterior 2, Posterior 3)

colnames(posterior)-c(Mu, SD)

return(posterior)}




David Winsemius, MD
West Hartford, CT

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


Re: [R] Continuing on with a loop when there's a failure

2010-07-18 Thread Josh B
Thanks very much again David for your helpful answers. However, the code STILL 
does not appear to be working properly!

Even though the third time through the loop *should* work, it appears that R 
has 
given up after the second time through the loop. What I mean is: although y2 
causes the lrm function to fail, y3 is a kosher variable. If the loop continues 
on, it should give data for the model with y3. But if you look at the matrix 
called results, it returns NA for the third spot corresponding to the model 
of 
y3:

results
y1 y2 y3
[1,] 0.6976063 NA NA

If you run y3 in isolation, rather than through the loop, you can see that it 
should work and contribute data to the matrix called results:

mod.poly3 - lrm(x[,3] ~ pol(x1, 3) + pol(x2, 3), data=x)
anova(mod.poly3)[1,3]
[1] 0.6976063


Any ideas?




From: David Winsemius dwinsem...@comcast.net

Cc: Peter Konings peter.l.e.koni...@gmail.com; R Help r-help@r-project.org
Sent: Sun, July 18, 2010 3:33:07 PM
Subject: Re: [R] Continuing on with a loop when there's a failure


On Jul 18, 2010, at 4:25 AM, Josh B wrote:

 Hello Peter,
 
 I tried your suggestion, but I was still not able to get it to work. Would you
 mind looking at my code again? Here's what I'm trying:
 
 x - read.table(textConnection(y1 y2 y3 x1 x2
 indv.1 bagels donuts bagels 4 6
 indv.2 donuts donuts donuts 5 1
 indv.3 donuts donuts donuts 1 10
 indv.4 donuts donuts donuts 10 9
 indv.5 bagels donuts bagels 0 2
 indv.6 bagels donuts bagels 2 9
 indv.7 bagels donuts bagels 8 5
 indv.8 bagels donuts bagels 4 1
 indv.9 donuts donuts donuts 3 3
 indv.10 bagels donuts bagels 5 9
 indv.11 bagels donuts bagels 9 10
 indv.12 bagels donuts bagels 3 1
 indv.13 donuts donuts donuts 7 10
 indv.14 bagels donuts bagels 2 10
 indv.15 bagels donuts bagels 9 6), header = TRUE)

closeAllConnections()

 
 results - matrix(nrow = 1, ncol = 3)
 colnames(results) - c(y1, y2, y3)

require(rms)  # or Design
for (i in 1:2) {
   mod.poly3 - try(lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x), silent=TRUE)
   if(class(mod.poly3)[1] != 'try-error')
   {results[1,i] - anova(mod.poly3)[1,3]}

}

 results
y1 y2 y3
[1,] 0.6976063 NA NA

 
 
 ...and here's the output:
 
 results
 y1 y2 y3
 [1,] NA NA NA
 
[[elided Yahoo spam]]
 
 
 
 
 From: Peter Konings peter.l.e.koni...@gmail.com
 
 Sent: Tue, July 13, 2010 5:45:17 PM
 Subject: Re: [R] Continuing on with a loop when there's a failure
 
 Hi Josh,
 
 Test the class of the resulting object. If it is 'try-error' fill your result
 with NA or do some other error handling.
 
 result - try(somemodel)
 if(class(result) == 'try-error')
 {
 # some error handling
 } else {
 # whatever happens if the result is ok
 }
 
 HTH
 Peter.
 
 
 
 
 In my opinion the try and tryCatch commands are written and documented rather
 poorly. Thus I am not sure what to program exactly.
 
 For instance, I could query mod.poly3 and use an if/then statement to 
proceed,
 but querying mod.poly3 is weird. For instance, here's the output when it 
fails:
 
 mod.poly3 - try(lrm(x[,2] ~ pol(x1, 3) + pol(x2, 3), data=x))
 
 Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol, weights =
 weights,  :
 
 NA/NaN/Inf in foreign function call (arg 1)
 mod.poly3
 [1] Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol, 
weights
 =
 weights,  : \n  NA/NaN/Inf in foreign function call (arg 1)\n
 attr(,class)
 [1] try-error
 
 ...and here's the output when it succeeds:
 mod.poly3 - try(lrm(x[,1] ~ pol(x1, 3) + pol(x2, 3), data=x))
 mod.poly3
 
 Logistic Regression Model
 
 lrm(formula = x[, 1] ~ pol(x1, 3) + pol(x2, 3), data = x)
 
 
 Frequencies of Responses
 bagels donuts
  10  5
 
 Obs  Max Deriv Model L.R.   d.f.  P  C
  15  4e-04   3.37  6 0.7616   0.76
 Dxy  Gamma  Tau-a R2  Brier  g
0.52   0.52  0.248  0.279  0.183  1.411
  gr gp
 4.1  0.261
 
Coef S.E.Wald Z P
 Intercept -5.68583 5.23295 -1.09  0.2772
 x1 1.87020 2.14635  0.87  0.3836
 x1^2  -0.42494 0.48286 -0.88  0.3788
 x1^3   0.02845 0.03120  0.91  0.3618
 x2 3.49560 3.54796  0.99  0.3245
 x2^2  -0.94888 0.82067 -1.16  0.2476
 x2^3   0.06362 0.05098  1.25  0.2121
 
 ...so what exactly would I query to design my if/then statement?
 
 
 
 
 
 
 From: David Winsemius dwinsem...@comcast.net
 To: David Winsemius dwinsem...@comcast.net
 
 Sent: Tue, July 13, 2010 9:09:04 AM
 
 Subject: Re: [R] Continuing on with a loop when there's a failure
 
 
 
 On Jul 13, 2010, at 9:04 AM, David Winsemius wrote:
 
 
 On Jul 13, 2010, at 8:47 AM, Josh B wrote:
 
 Thanks again, David.
 
 [[elided Yahoo spam]]
 
 
 (BTW, it did work.)
 
 Here's what I'm trying now:
 
 for (i in 1:2) {
   mod.poly3 - try(lrm(x[,i] ~ pol(x1, 3) + pol(x2, 3), data=x))
   

[R] any one knowing how to install library (equate)?

2010-07-18 Thread ying_chen wang
I was told to go to packages on the tool bar and select 'install packages'.
Then choose library (equate).

My R is version 2.11. I tried multiple times with different locations of R
within US. Yet, I didn't see library(equate) being offered in the packages.

Thanks.

Grace

[[alternative HTML version deleted]]

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


Re: [R] R: package plotrix

2010-07-18 Thread David Winsemius


On Jul 18, 2010, at 1:32 PM, mau...@alice.it wrote:



-Messaggio originale-
Da: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Inviato: dom 18/07/2010 18.58
A: mau...@alice.it
Cc: j...@bitwrit.com.au; r-h...@stat.math.ethz.ch
Oggetto: Re: [R] package plotrix



On 18.07.2010 17:59, mau...@alice.it wrote:
I installed package plotrix because reading its vignette it looks  
like it can help me solve a legend problem.

The package instaleed correctly on my Mac OS/X 10.5.8
But I cannot reproduce the examples centered on function lgendg.



You mean legendg.

Yes. Sorry for my typo.


library(plotrix)
plot(0.5,0.5,xlim=c(0,1),ylim=c(0,1),type=n,

+ main=Test of grouped legend function)

legendg(0.5,0.8,c(one,two,three),pch=list(1,2:3,4:6),

+ col=list(2,3:4,5:7))
Error: could not find function legendg



That works for me. Try to upgrade bopth R and plotrix if you have not
already.
I am running R 2.9.2 on my Mac OS/X 10.5.8
I always feel uncomfortable with upgrades.
Shall I uninstall R 2.9.2 in advance of instaling the ew bversion  
for Mac ?


No need to do so. The appropriate 2.11.1 folders will be created in  
the R.framework folder and the links in the Current folder will be  
updated.




I ave no reason for keeping two versions.


My problem with the regular R legend function is that I cannot  
indicate in the legend the line plotted by the command abline
Here is the code. Attached is the plot. Any suggestion is welcome.  
Thank you.

Maura


x11(width=10,heigh=8)
plot(NN,LB,xlim=c(1,300),ylim=c(0,3),
 main=Intrinsic Dimensionality of 1D  
Helix,font.main=2,cex.main=2,col.main=red,
 xlab=Number of Nearest-Neighbors,ylab=Estimated   
Dimension,col.lab=red,cex.lab=1,font.lab=2,

 xaxt=n,yaxt=n,pch=19,col=red4)
axis 
(1 
,at 
= 
NN 
[1 
: 
40 
],labels 
= 
NN 
[1 
:40],cex.lab=1,cex.axis=0.8,col.axis=blue,lwd.ticks=0.5,col.ticks  
=gray3)
axis 
(2 
,at 
= 
c 
(0,0.5,1,1.5,2,2.5,3,3.5,4 
),labels=c(0,0.5,1,1.5,2,2.5,3,3.5,4),cex.lab=1,cex.axis=0.8,

 col.axis=blue,lwd.ticks=0.5,col.ticks =gray3)
lines(NN,McG,pch=18,col=green)
lines(NN,PBJD,pch=20,col=magenta1)
points(NN,GRPR,pch=18,col=cyan)
abline(h=1,pch= 1,lty=1,col=black)
legend(topright,legend = c(Levina-Bickel,MacKay- 
Ghahramani,Pettis-Bailey-Jain-Dubes,Grassberger- 
Procaccia,Helix Dimension),
   text.width = strwidth(Pettis-Bailey-Jain-Dubes),pch =  
c(19,18,20,18,1),
	   col = c(red4,green,magenta1,cyan,black),text.col =  
black,lty=c(-1,-1,-1,1),

   bg =snow)






We do not have the data nor do we see the figure, hence this is not
reproducible for us.

Actually I attached the TIFF plot that I am attaching again.


Re-read the Posting Guide. It specifies what can be attached and TIFF  
files are NOT in the list of acceptable types. Uwe might have gotten a  
copy but the rest of us did not.


--

David Winsemius, MD
West Hartford, CT

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


[R] Question from day2 beginner

2010-07-18 Thread maxcheese

Hello, I just started learning R and have a very basic question:

When I try ar model and extract residuals it returns Null.  Could someone
explain what's going on here?  Does that mean the model is null?  But it
seems residual has a length=# observation of the original series according
to the model summary.  I am learning it by myself and have no one to ask
here so please allow me to ask this very basic question...  Thank you very
much. 

 summary(ar(logrvar, aic=TRUE))

 Length Class  Mode 
order1  -none- numeric  
ar  40  -none- numeric  
var.pred 1  -none- numeric  
x.mean   1  -none- numeric  
aic 44  -none- numeric  
n.used   1  -none- numeric  
order.max1  -none- numeric  
partialacf  43  -none- numeric  
resid20731  -none- numeric  
method   1  -none- character
series   1  -none- character
frequency1  -none- numeric  
call 3  -none- call 
asy.var.coef  1600  -none- numeric  

 resid(ar(logrvar, aic=TRUE))
NULL
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Question-from-day2-beginner-tp2293221p2293221.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] Reading files with varying number of columns

2010-07-18 Thread Tim Clark
Thanks for the suggestion.  I had read fill but didn't pick up on the 
details.  It only uses the first five columns to determine column dimensions, 
so 
it ignored my last two columns.  Specifying col.names with fill=TRUE did the 
trick!

Aloha,

Tim


 




- Original Message 
From: Uwe Ligges lig...@statistik.tu-dortmund.de
To: Tim Clark mudiver1...@yahoo.com
Cc: r-help@r-project.org
Sent: Sun, July 18, 2010 6:03:47 AM
Subject: Re: [R] Reading files with varying number of columns

See argument fill in ?read.table

Uwe Ligges


On 18.07.2010 12:14, Tim Clark wrote:
 Dear R list,
 I am trying to read files with a varying number of columns and can't figure 
out
 how to get them in the proper format.  Some rows have five value and some have
 seven.  Is there a way to read them in so that two empty columns are added to
 every row that has only five values?  An example of the data follows.  Thanks!
 Tim

 46,B,00301,2004-02-03,11:59:16
 46,B,00301,2004-02-03,12:03:43
 46,B,00301,2004-02-03,12:39:17
 46,B,00301,2004-02-03,23:07:28
 43,C,00232,2004-02-04,07:39:57,-1.5,meters
 44,A,00230,2004-02-04,07:44:59
 44,A,00230,2004-02-04,07:46:19
 44,A,00230,2004-02-04,07:48:24
 44,A,00230,2004-02-04,07:49:12
 43,C,00232,2004-02-04,07:53:08,2.5,meters
 44,A,00230,2004-02-04,07:54:34
 44,A,00230,2004-02-04,07:55:08
 43,C,00232,2004-02-04,07:56:18,2.9,meters
 43,C,00232,2004-02-04,07:56:39,2.5,meters
 46,B,00301,2004-02-04,08:00:49
 43,C,00232,2004-02-04,08:02:12,-1.1,meters
 43,C,00232,2004-02-04,08:04:01,2.2,meters
 43,C,00232,2004-02-04,08:04:26,3.3,meters
 43,C,00232,2004-02-04,08:40:26,2.9,meters
 43,C,00232,2004-02-04,08:41:04,-2.2,meters
 43,C,00232,2004-02-04,08:42:44,2.2,meters
 43,C,00232,2004-02-04,08:44:31,2.9,meters
 44,A,00231,2004-02-04,09:04:43
 44,A,00231,2004-02-04,09:10:30
 44,A,00231,2004-02-04,09:12:08
 44,A,00231,2004-02-04,09:13:32
 44,A,00231,2004-02-04,09:14:06
 43,C,00232,2004-02-04,09:18:24,0.4,meters
 43,C,00232,2004-02-04,09:20:13,2.5,meters
 44,A,00231,2004-02-04,09:21:04
 44,A,00231,2004-02-04,09:22:53
 44,A,00231,2004-02-04,09:25:32
 44,A,00231,2004-02-04,09:29:31
 44,A,00231,2004-02-04,09:30:05
 43,C,00232,2004-02-04,09:53:25,2.5,meters
 43,C,00232,2004-02-04,09:53:53,1.5,meters
 46,B,00301,2004-02-04,22:16:24
 46,B,00301,2004-02-04,22:19:32
 46,B,00258,2004-02-04,23:44:01
 46,B,00258,2004-02-04,23:44:28


  Tim Clark

 Marine Ecologist
 National Park of American Samoa
 Pago Pago, American Samoa  96799




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

2010-07-18 Thread Arnaud Trébaol
Hi all,


I am working for my master's thesis and I need to do a neural network to
forecast stock market price, with also external inputs like technical
indicators.
I would like to know which function and package of R are more suitable for
this study.


Thanks a lot for your response,


Arnaud TREBAOL.

-- 
Arnaud Trébaol
T.I.M.E. Student
Ecole Centrale de Lille (09)
Politecnico di Milano (10)

Mail : arnaud.treb...@centraliens-lille.org
Tel1 : +33 (0)6 76 46 42 92
Tel2 : +39 327 280 57 68

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

2010-07-18 Thread Corey Sparks

I'd start with the nnet library
type:
?nnet

CS

-
Corey Sparks, PhD
Assistant Professor
Department of Demography and Organization Studies
University of Texas at San Antonio
501 West Durango Blvd
Monterey Building 2.270C
San Antonio, TX 78207
210-458-3166
corey.sparks 'at' utsa.edu
https://rowdyspace.utsa.edu/users/ozd504/www/index.htm
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Neural-Network-tp2293366p2293369.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] simple loop(?) analysing subsets

2010-07-18 Thread karmakiller

Hi All,

I have a large data set with many columns of data. One of these columns is a
species identifier and the remainder are variables such as temperature or
mass. Currently I am carrying out a single regression on subsets of the data
set, e.g. separated data sets with only the data from one species at a time.
I have been searching for a thread that will help me to understand how best
to repeat this process for each different species identifier in that
variable column. I can’t seem to find one that is similar to what I am
trying to do. It might be the case that I am not looking for the right thing
or that I do not fully understand the process.

How do I run a simple loop that produces a regression for each species as
identified in the variable species id, which is one column in the large data
set that I am using?

Simple regression that I wish to repeat

data- read.table(…/STUDY.txt,header=T)
names(data)
model- with(data,{lm(o2con~bm)})
summary(model)


sample data set

species id  o2con   bm
1   0.5 5
1   0.6 2
1   0.4 4
1   0.4 2
1   0.5 3
2   0.3 7
2   0.4 8
2   0.5 3
2   0.7 4
2   0.9 2
3   0.3 6
3   0.7 2
3   0.4 1
3   0.3 7
5   0.3 2
5   0.6 1
5   0.9 7
5   0.2 5

I would be very grateful for some help with this. I really like using R and
I can usually figure out what I want to do but I have been trying to figure
this out for a while now and I am getting nowhere. 

Thank you.

-- 
View this message in context: 
http://r.789695.n4.nabble.com/simple-loop-analysing-subsets-tp2293383p2293383.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] any one knowing how to install library (equate)?

2010-07-18 Thread Duncan Murdoch

On 18/07/2010 2:57 PM, ying_chen wang wrote:

I was told to go to packages on the tool bar and select 'install packages'.
Then choose library (equate).

My R is version 2.11. I tried multiple times with different locations of R
within US. Yet, I didn't see library(equate) being offered in the packages.



You should ask the person who told you that for better instructions.

Duncan Murdoch

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


Re: [R] simple loop(?) analysing subsets

2010-07-18 Thread Joshua Wiley
Hello,

Take a look at ?by

Something like:

by(data, data[ , species id], function(x) {lm(o2con ~ bm, data = x)})

As an aside, it can be a bit cumbersome to deal with spaces in a
variables name (because it has to be quoted then).  Also since data is
a function, something like mydata might make it easier to keep code
straight.

HTH,

Josh


On Sun, Jul 18, 2010 at 2:29 PM, karmakiller roisinmoria...@gmail.com wrote:

 Hi All,

 I have a large data set with many columns of data. One of these columns is a
 species identifier and the remainder are variables such as temperature or
 mass. Currently I am carrying out a single regression on subsets of the data
 set, e.g. separated data sets with only the data from one species at a time.
 I have been searching for a thread that will help me to understand how best
 to repeat this process for each different species identifier in that
 variable column. I can’t seem to find one that is similar to what I am
 trying to do. It might be the case that I am not looking for the right thing
 or that I do not fully understand the process.

 How do I run a simple loop that produces a regression for each species as
 identified in the variable species id, which is one column in the large data
 set that I am using?

 Simple regression that I wish to repeat

 data- read.table(…/STUDY.txt,header=T)
 names(data)
 model- with(data,{lm(o2con~bm)})
 summary(model)


 sample data set

 species id      o2con       bm
 1               0.5         5
 1               0.6         2
 1               0.4         4
 1               0.4         2
 1               0.5         3
 2               0.3         7
 2               0.4         8
 2               0.5         3
 2               0.7         4
 2               0.9         2
 3               0.3         6
 3               0.7         2
 3               0.4         1
 3               0.3         7
 5               0.3         2
 5               0.6         1
 5               0.9         7
 5               0.2         5

 I would be very grateful for some help with this. I really like using R and
 I can usually figure out what I want to do but I have been trying to figure
 this out for a while now and I am getting nowhere.

 Thank you.

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/simple-loop-analysing-subsets-tp2293383p2293383.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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] any one knowing how to install library (equate)?

2010-07-18 Thread Joshua Wiley
Hi Grace,

I'm using the UCLA mirror and this code installs equate fine for me.

#install the package (note that the quoted name)
install.packages(equate)

#load the package
library(equate)

It also looks like the packages has passed the CRAN checks for all
OSes, so availability is probably not an issue.

Best regards,

Josh

On Sun, Jul 18, 2010 at 11:57 AM, ying_chen wang
gracedrop.w...@gmail.com wrote:
 I was told to go to packages on the tool bar and select 'install packages'.
 Then choose library (equate).

 My R is version 2.11. I tried multiple times with different locations of R
 within US. Yet, I didn't see library(equate) being offered in the packages.

 Thanks.

 Grace

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




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] Inserting an image into a PDF file

2010-07-18 Thread Paul Murrell

Hi


On 12/07/2010 4:33 a.m., Marc Schwartz wrote:

On Jul 11, 2010, at 10:51 AM, David Winsemius wrote:



On Jul 11, 2010, at 11:06 AM, Dennis Fisher wrote:


Colleagues,

I am creating a PDF document from R using pdf(), the document contains text / 
images created with R.  I also have an image in either PDF / TIFF / JPEG format 
(in this case, a scanned image saved as a file).

I would like to insert the image into the PDF file.  Any ideas on how to 
accomplish this?


http://www.stat.auckland.ac.nz/~paul/Talks/import.pdf



(OS X, R 2.11.1)




Just to offer an additional option since Dennis is on OSX, if you are on 10.6.x 
(Snow Leopard), you can view this YouTube video:

   http://www.youtube.com/watch?v=zF_WgXAfMP0

which describes how to combine/insert pages from multiple document types that 
OSX' Preview can open.

If you are on Leopard (10.5.x), the drag and drop behavior, as noted in the 
above video, is somewhat different and you may wish to view this page:

   
http://macintoshhowto.com/leopard/how-to-merge-pdf-files-with-preview-in-leopard.html

This presumes that you want the scanned image on a separate page, rather than 
combined on the same page as your pdf() output. Since PDF is a native format on 
OSX, you can take advantage of built-in functionality to manipulate these files.

Of course using Sweave is yet another option.


Also see the new rasterImage() and grid.raster() functions in R 2.11.*

Paul


HTH,

Marc Schwartz

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


--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

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


Re: [R] re. Mathematica and R

2010-07-18 Thread Erich Neuwirth
The wiki on rcom.univie.ac.at
in section
R(D)COM, rcom, and other software systems
has an example how to use R from within Mathematica on Windows.
You will need to install statconnDCOM and rcom
available from the same site.
On Jul 17, 2010, at 1:06 PM, Alan Kelly wrote:

 David - information on calling R from within Mathematica can be found at the
 following link:
 http://www.mofeel.net/1164-comp-soft-sys-math-mathematica/13022.aspx
 HTH,
 Alan Kelly
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

--
Erich Neuwirth
Didactic Center for Computer Science and Institute for Scientific Computing
University of Vienna





[[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 with Reshaping from Wide to Long

2010-07-18 Thread jlwoodard

Hi Phil and Jeff,
Thanks so much for taking the time to help me solve this issue!  Both
approaches work perfectly.  Each of your approaches helped me learn more
about what R can do.   I really appreciate your help!

Very best regards,

John
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-Reshaping-from-Wide-to-Long-tp2292462p2293463.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] specifying column names in a vector of characters and the use?

2010-07-18 Thread Seth

Hi,

What I would like to do is have a data.frame with column names and have
these column names stored as strings in another vector.  Then I would like
to be able to access the data.fram columns via referencing the vector of
names.  The code below shows the last few executions that failed to retrieve
the values for column named X1.  Seth


 table.1-cbind(c(1,2,3,2,2),c(0,9,0,7,9),c(7,5,9,8,8))
 table.1
 [,1] [,2] [,3]
[1,]107
[2,]295
[3,]309
[4,]278
[5,]298
 
 table.1-data.frame(table.1)
 table.1
  X1 X2 X3
1  1  0  7
2  2  9  5
3  3  0  9
4  2  7  8
5  2  9  8
 hold-c(X1,X2,X3)
 hold
[1] X1 X2 X3
 table.1$X1
[1] 1 2 3 2 2
 hold[1]
[1] X1
 table.1$hold[1] # FROM HERE DOWN ARE MY ATTEMPTS TO ACCESS X1
NULL
 table.1$(hold[1])
Error: unexpected '(' in table.1$(
 table.1$get(hold[1])
Error: attempt to apply non-function
 table.1$(get(hold[1]))
Error: unexpected '(' in table.1$(
 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/specifying-column-names-in-a-vector-of-characters-and-the-use-tp2293494p2293494.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] specifying column names in a vector of characters and the use?

2010-07-18 Thread Erik Iverson

Hello,


What I would like to do is have a data.frame with column names and have
these column names stored as strings in another vector.  Then I would like
to be able to access the data.fram columns via referencing the vector of
names.  The code below shows the last few executions that failed to retrieve
the values for column named X1.  Seth



table.1-cbind(c(1,2,3,2,2),c(0,9,0,7,9),c(7,5,9,8,8))
table.1

  [,1] [,2] [,3]
[1,]107
[2,]295
[3,]309
[4,]278
[5,]298


See easier way to construct your object below.

snip

[1] X1

table.1$hold[1] # FROM HERE DOWN ARE MY ATTEMPTS TO ACCESS X1

NULL

table.1$(hold[1])

Error: unexpected '(' in table.1$(

table.1$get(hold[1])

Error: attempt to apply non-function

table.1$(get(hold[1]))

Error: unexpected '(' in table.1$(


You need to index with ?[

Here is a complete example:

table.1- data.frame(X1 = c(1,2,3,2,2),
 X2 = c(0,9,0,7,9),
 X3 = c(7,5,9,8,8))

hold - names(table.1)

## to return a data.frame
table.1[hold[1]]

## to return a vector
table.1[[hold[1]]]

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


Re: [R] specifying column names in a vector of characters and the use?

2010-07-18 Thread Simon Blomberg

Try:

table.1[[hold[1]]]

Cheers,

Simon.


On 19/07/10 12:09, Seth wrote:

Hi,

What I would like to do is have a data.frame with column names and have
these column names stored as strings in another vector.  Then I would like
to be able to access the data.fram columns via referencing the vector of
names.  The code below shows the last few executions that failed to retrieve
the values for column named X1.  Seth


   

table.1-cbind(c(1,2,3,2,2),c(0,9,0,7,9),c(7,5,9,8,8))
table.1
 

  [,1] [,2] [,3]
[1,]107
[2,]295
[3,]309
[4,]278
[5,]298
   

table.1-data.frame(table.1)
table.1
 

   X1 X2 X3
1  1  0  7
2  2  9  5
3  3  0  9
4  2  7  8
5  2  9  8
   

hold-c(X1,X2,X3)
hold
 

[1] X1 X2 X3
   

table.1$X1
 

[1] 1 2 3 2 2
   

hold[1]
 

[1] X1
   

table.1$hold[1] # FROM HERE DOWN ARE MY ATTEMPTS TO ACCESS X1
 

NULL
   

table.1$(hold[1])
 

Error: unexpected '(' in table.1$(
   

table.1$get(hold[1])
 

Error: attempt to apply non-function
   

table.1$(get(hold[1]))
 

Error: unexpected '(' in table.1$(
   
 


--
Simon Blomberg, BSc (Hons), PhD, MAppStat.
Lecturer and Consultant Statistician
School of Biological Sciences
The University of Queensland
St. Lucia Queensland 4072
Australia
T: +61 7 3365 2506
email: S.Blomberg1_at_uq.edu.au
http://www.uq.edu.au/~uqsblomb/

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem

Statistics is the grammar of science - Karl Pearson.

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


Re: [R] specifying column names in a vector of characters and the use?

2010-07-18 Thread David Winsemius


On Jul 18, 2010, at 10:09 PM, Seth wrote:



Hi,

What I would like to do is have a data.frame with column names and  
have
these column names stored as strings in another vector.  Then I  
would like
to be able to access the data.fram columns via referencing the  
vector of
names.  The code below shows the last few executions that failed to  
retrieve

the values for column named X1.  Seth



table.1-cbind(c(1,2,3,2,2),c(0,9,0,7,9),c(7,5,9,8,8))
table.1

[,1] [,2] [,3]
[1,]107
[2,]295
[3,]309
[4,]278
[5,]298


table.1-data.frame(table.1)
table.1

 X1 X2 X3
1  1  0  7
2  2  9  5
3  3  0  9
4  2  7  8
5  2  9  8

hold-c(X1,X2,X3)
hold

[1] X1 X2 X3

table.1$X1

[1] 1 2 3 2 2

hold[1]

[1] X1

table.1$hold[1] # FROM HERE DOWN ARE MY ATTEMPTS TO ACCESS X1

NULL


Try instead:

table.1[ , hold[1] ]

The $ formalism does not evaluate its argument, but the [ function  
does.


--
David.

table.1$(hold[1])

Error: unexpected '(' in table.1$(

table.1$get(hold[1])

Error: attempt to apply non-function

table.1$(get(hold[1]))

Error: unexpected '(' in table.1$(



--
View this message in context: 
http://r.789695.n4.nabble.com/specifying-column-names-in-a-vector-of-characters-and-the-use-tp2293494p2293494.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] Question about KLdiv and large datasets

2010-07-18 Thread Ralf B
Is the 'eps' argument part of KLdiv (was not able to find that in the
help pages) or part of a general environment (such as the graphics
parameters 'par' ) ? I am asking so that I can read about it what it
actually does to resolve the question you already raised about its
reliability...

Ralf

On Fri, Jul 16, 2010 at 10:41 AM, Peter Ehlers ehl...@ucalgary.ca wrote:
 On 2010-07-16 7:56, Ralf B wrote:

 Hi all,

 when running KL on a small data set, everything is fine:

 require(flexmix)
 n- 20
 a- rnorm(n)
 b- rnorm(n)
 mydata- cbind(a,b)
 KLdiv(mydata)

 however, when this dataset increases

 require(flexmix)
 n- 1000
 a- rnorm(n)
 b- rnorm(n)
 mydata- cbind(a,b)
 KLdiv(mydata)


 KL seems to be not defined. Can somebody explain what is going on?

 Thanks,
 Ralf

 Ralf,

 You can adjust the 'eps=' argument. But I don't know
 what this will do to the reliability of the results.

 KLdiv(mydata, eps = 1e-7)

  -Peter Ehlers


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


[R] Cramer-von Mises test

2010-07-18 Thread Sean Carmody
I have found the Kolmogorov-Smirnov (ks.test) and Anderson-Darling
(ad.test in package ADGofTest)
goodness of fit tests, but was wondering whether there's a package
implementing the Cramer-von Mises
test for a general distribution (i.e. not just the one for the normal
distribution in the nortest package).
Any suggestions?

Regards,
Sean.

-- 
Sean Carmody
Twitter: http://twitter.com/seancarmody
Stable: http://mulestable.net/sean

The Stubborn Mule
Blog: http://www.stubbornmule.net
Forum: http://mulestable.net/

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

2010-07-18 Thread Xin Ge
Hi All,

Can anyone please suggest me from where should I start to learn about 'how
to connect to access db' ?

How if someone has some written code and I can go over that to understand
and make necessary changes... any help would be highly appreciated,

-- 
Xin Ge.

[[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] Connecting to MS Access database

2010-07-18 Thread Wensui Liu
Hey Xin
this is a piece I copied from my blog.

library(RODBC)
mdbConnect-odbcConnectAccess(C:\\temp\\demo.mdb)
sqlTables(mdbConnect)
demo-sqlFetch(mdbConnect, tblDemo)
odbcClose(mdbConnect)
rm(demo)


On Mon, Jul 19, 2010 at 12:05 AM, Xin Ge xingemaill...@gmail.com wrote:
 Hi All,

 Can anyone please suggest me from where should I start to learn about 'how
 to connect to access db' ?

 How if someone has some written code and I can go over that to understand
 and make necessary changes... any help would be highly appreciated,

 --
 Xin Ge.

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




-- 
==
WenSui Liu
wens...@paypal.com
statcompute.spaces.live.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] Question about KLdiv and large datasets

2010-07-18 Thread Peter Ehlers

I just answered this but realize that I did so off-list.
So, for completeness, here's what I said:

I think I see the problem. From ?KLdiv, you're getting the
modeltools help page. What you need is the flexmix help
page for KLdiv. Just get to the flexmix index page
(you can do ?flexmix and then click on the 'Index' link at
the bottom). Then select KLdiv-method. Here you will find
the eps argument described. Its default value is eps=10^-4
and the description says:

eps Probabilities below this threshold are replaced by this 
threshold for numerical stability.


It's this comment that makes me doubt the reliability for
very small eps values.

Cheers,
Peter


On 2010-07-18 20:50, Ralf B wrote:

Is the 'eps' argument part of KLdiv (was not able to find that in the
help pages) or part of a general environment (such as the graphics
parameters 'par' ) ? I am asking so that I can read about it what it
actually does to resolve the question you already raised about its
reliability...

Ralf

On Fri, Jul 16, 2010 at 10:41 AM, Peter Ehlersehl...@ucalgary.ca  wrote:

On 2010-07-16 7:56, Ralf B wrote:


Hi all,

when running KL on a small data set, everything is fine:

require(flexmix)
n- 20
a- rnorm(n)
b- rnorm(n)
mydata- cbind(a,b)
KLdiv(mydata)

however, when this dataset increases

require(flexmix)
n- 1000
a- rnorm(n)
b- rnorm(n)
mydata- cbind(a,b)
KLdiv(mydata)


KL seems to be not defined. Can somebody explain what is going on?

Thanks,
Ralf


Ralf,

You can adjust the 'eps=' argument. But I don't know
what this will do to the reliability of the results.

KLdiv(mydata, eps = 1e-7)

  -Peter Ehlers



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


Re: [R] simple loop(?) analysing subsets

2010-07-18 Thread Dennis Murphy
Hi:

Time to jack up your level of R knowledge, courtesy of the apply family.

The 'R way' to do what you want is to split the data by species into list
components, run lm() on each component and save the resulting lm objects in
a list. The next trick is to figure out how to extract what you want, which
may require a bit more ingenuity in delving into aRcana :)

-
Aside:
To reinforce Joshua's point, variable names with spaces not explicitly
enclosed in quotes is bad practice, especially when someone who wants to
help tries to copy and paste your data into his/her R session:

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
:
  line 1 did not have 4 elements

R expected four columns of data, but you provided three. In the future, it's
a good idea to include your data example with dput(), which outputs

dput(d)
structure(list(species = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 5L, 5L, 5L, 5L), o2con = c(0.5, 0.6, 0.4,
0.4, 0.5, 0.3, 0.4, 0.5, 0.7, 0.9, 0.3, 0.7, 0.4, 0.3, 0.3, 0.6,
0.9, 0.2), bm = c(5L, 2L, 4L, 2L, 3L, 7L, 8L, 3L, 4L, 2L, 6L,
2L, 1L, 7L, 2L, 1L, 7L, 5L)), .Names = c(species, o2con,
bm), class = data.frame, row.names = c(NA, -18L))

This is easily copied and pasted into anyone's R sessionbut I digress.
--

Calling your data frame d, here's how to run the same regression model on
all species:

# Create a function to perform the modeling, taking a data frame df as input
f - function(df) lm(o2con ~ bm, data = df)

# Use lapply() to apply the function to each 'split' of the data, by
species:
v - lapply(split(d, d$species), f)

# v is a list object, where each component of the list is an lm object,
# which itself is a list. In other words, it's a list of lists. do.call() is
a
# very useful function that applies a function to components of a list.
# rbind and cbind are commonly used to slurp together common elements
# from each component of a list.

# Pulling out the coefficients from each model:
 do.call(rbind, lapply(v, coef))
  (Intercept)  bm
1   0.5176471 -0.01176471
2   0.9253731 -0.07611940
3   0.5942308 -0.04230769
5   0.3351648  0.04395604

# Extract the r-squared values from each model:
g - function(m) summary(m)$r.squared
 do.call(rbind, lapply(v, g))
[,1]
1 0.03361345
2 0.66932578
3 0.43291592
5 0.14652015

# But you have to be careful...e.g., since you have unequal sample sizes per
species,
 do.call(cbind, lapply(v, resid))
1   23  5
1  0.04117647 -0.09253731 -0.040384615 -0.1230769
2  0.10588235  0.08358209  0.190384615  0.2208791
3 -0.07058824 -0.19701493 -0.151923077  0.2571429
4 -0.09411765  0.07910448  0.001923077 -0.3549451
5  0.01764706  0.12686567 -0.040384615 -0.1230769
Warning message:
In function (..., deparse.level = 1)  :
  number of rows of result is not a multiple of vector length (arg 3)

Notice how the first residual is recycled in each of groups 3 and 5. That's
a potential gotcha.

This gives you a small glimpse into the power that R can deliver in data
analysis.

HTH,
Dennis

On Sun, Jul 18, 2010 at 2:29 PM, karmakiller roisinmoria...@gmail.comwrote:


 Hi All,

 I have a large data set with many columns of data. One of these columns is
 a
 species identifier and the remainder are variables such as temperature or
 mass. Currently I am carrying out a single regression on subsets of the
 data
 set, e.g. separated data sets with only the data from one species at a
 time.
 I have been searching for a thread that will help me to understand how best
 to repeat this process for each different species identifier in that
 variable column. I can’t seem to find one that is similar to what I am
 trying to do. It might be the case that I am not looking for the right
 thing
 or that I do not fully understand the process.

 How do I run a simple loop that produces a regression for each species as
 identified in the variable species id, which is one column in the large
 data
 set that I am using?

 Simple regression that I wish to repeat

 data- read.table(…/STUDY.txt,header=T)
 names(data)
 model- with(data,{lm(o2con~bm)})
 summary(model)


 sample data set

 species id  o2con   bm
 1   0.5 5
 1   0.6 2
 1   0.4 4
 1   0.4 2
 1   0.5 3
 2   0.3 7
 2   0.4 8
 2   0.5 3
 2   0.7 4
 2   0.9 2
 3   0.3 6
 3   0.7 2
 3   0.4 1
 3   0.3 7
 5   0.3 2
 5   0.6 1
 5   0.9 7
 5   0.2 5

 I would be very grateful for some help with this. I really like using R and
 I can usually figure out what I want to do but I have been trying to figure
 this out for a while now and I am getting nowhere.

 Thank you.

 --
 View this 

Re: [R] Cramer-von Mises test

2010-07-18 Thread Peter Ehlers

On 2010-07-18 22:04, Sean Carmody wrote:

I have found the Kolmogorov-Smirnov (ks.test) and Anderson-Darling
(ad.test in package ADGofTest)
goodness of fit tests, but was wondering whether there's a package
implementing the Cramer-von Mises
test for a general distribution (i.e. not just the one for the normal
distribution in the nortest package).
Any suggestions?


Sean,
Here's one way you can investigate this yourself:
1. install and load package 'sos';
2. issue: findFn(Cramer-von Mises test)
   or, for a little wider scope: findFn(Cramer-von Mises)
(in place of 'findFn', you can use '???')

  -Peter Ehlers



Regards,
Sean.


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


Re: [R] simple loop(?) analysing subsets

2010-07-18 Thread Joshua Wiley
Not to hijack the thread, but for my edification, what are the
advantages/disadvantages of split() + lapply() compared to by()?

Josh

On Sun, Jul 18, 2010 at 9:50 PM, Dennis Murphy djmu...@gmail.com wrote:
 Hi:

 Time to jack up your level of R knowledge, courtesy of the apply family.

 The 'R way' to do what you want is to split the data by species into list
 components, run lm() on each component and save the resulting lm objects in
 a list. The next trick is to figure out how to extract what you want, which
 may require a bit more ingenuity in delving into aRcana :)

 -
 Aside:
 To reinforce Joshua's point, variable names with spaces not explicitly
 enclosed in quotes is bad practice, especially when someone who wants to
 help tries to copy and paste your data into his/her R session:

 Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
 :
  line 1 did not have 4 elements

 R expected four columns of data, but you provided three. In the future, it's
 a good idea to include your data example with dput(), which outputs

 dput(d)
 structure(list(species = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
 2L, 3L, 3L, 3L, 3L, 5L, 5L, 5L, 5L), o2con = c(0.5, 0.6, 0.4,
 0.4, 0.5, 0.3, 0.4, 0.5, 0.7, 0.9, 0.3, 0.7, 0.4, 0.3, 0.3, 0.6,
 0.9, 0.2), bm = c(5L, 2L, 4L, 2L, 3L, 7L, 8L, 3L, 4L, 2L, 6L,
 2L, 1L, 7L, 2L, 1L, 7L, 5L)), .Names = c(species, o2con,
 bm), class = data.frame, row.names = c(NA, -18L))

 This is easily copied and pasted into anyone's R sessionbut I digress.
 --

 Calling your data frame d, here's how to run the same regression model on
 all species:

 # Create a function to perform the modeling, taking a data frame df as input
 f - function(df) lm(o2con ~ bm, data = df)

 # Use lapply() to apply the function to each 'split' of the data, by
 species:
 v - lapply(split(d, d$species), f)

 # v is a list object, where each component of the list is an lm object,
 # which itself is a list. In other words, it's a list of lists. do.call() is
 a
 # very useful function that applies a function to components of a list.
 # rbind and cbind are commonly used to slurp together common elements
 # from each component of a list.

 # Pulling out the coefficients from each model:
 do.call(rbind, lapply(v, coef))
  (Intercept)          bm
 1   0.5176471 -0.01176471
 2   0.9253731 -0.07611940
 3   0.5942308 -0.04230769
 5   0.3351648  0.04395604

 # Extract the r-squared values from each model:
 g - function(m) summary(m)$r.squared
 do.call(rbind, lapply(v, g))
        [,1]
 1 0.03361345
 2 0.66932578
 3 0.43291592
 5 0.14652015

 # But you have to be careful...e.g., since you have unequal sample sizes per
 species,
 do.call(cbind, lapply(v, resid))
            1           2            3          5
 1  0.04117647 -0.09253731 -0.040384615 -0.1230769
 2  0.10588235  0.08358209  0.190384615  0.2208791
 3 -0.07058824 -0.19701493 -0.151923077  0.2571429
 4 -0.09411765  0.07910448  0.001923077 -0.3549451
 5  0.01764706  0.12686567 -0.040384615 -0.1230769
 Warning message:
 In function (..., deparse.level = 1)  :
  number of rows of result is not a multiple of vector length (arg 3)

 Notice how the first residual is recycled in each of groups 3 and 5. That's
 a potential gotcha.

 This gives you a small glimpse into the power that R can deliver in data
 analysis.

 HTH,
 Dennis

 On Sun, Jul 18, 2010 at 2:29 PM, karmakiller roisinmoria...@gmail.comwrote:


 Hi All,

 I have a large data set with many columns of data. One of these columns is
 a
 species identifier and the remainder are variables such as temperature or
 mass. Currently I am carrying out a single regression on subsets of the
 data
 set, e.g. separated data sets with only the data from one species at a
 time.
 I have been searching for a thread that will help me to understand how best
 to repeat this process for each different species identifier in that
 variable column. I can’t seem to find one that is similar to what I am
 trying to do. It might be the case that I am not looking for the right
 thing
 or that I do not fully understand the process.

 How do I run a simple loop that produces a regression for each species as
 identified in the variable species id, which is one column in the large
 data
 set that I am using?

 Simple regression that I wish to repeat

 data- read.table(…/STUDY.txt,header=T)
 names(data)
 model- with(data,{lm(o2con~bm)})
 summary(model)


 sample data set

 species id      o2con       bm
 1               0.5         5
 1               0.6         2
 1               0.4         4
 1               0.4         2
 1               0.5         3
 2               0.3         7
 2               0.4         8
 2               0.5         3
 2               0.7         4
 2               0.9         2
 3               0.3         6
 3               0.7         2
 3               0.4         1
 3               0.3         7
 5               0.3         2
 5               0.6         1
 5               0.9         7
 

Re: [R] Cramer-von Mises test

2010-07-18 Thread Sean Carmody
Thanks Peter...I hadn't some across the sos package before, but I'm
sure I'll be putting it to good use from now on!

Sean.

On Mon, Jul 19, 2010 at 2:55 PM, Peter Ehlers ehl...@ucalgary.ca wrote:
 On 2010-07-18 22:04, Sean Carmody wrote:

 I have found the Kolmogorov-Smirnov (ks.test) and Anderson-Darling
 (ad.test in package ADGofTest)
 goodness of fit tests, but was wondering whether there's a package
 implementing the Cramer-von Mises
 test for a general distribution (i.e. not just the one for the normal
 distribution in the nortest package).
 Any suggestions?

 Sean,
 Here's one way you can investigate this yourself:
 1. install and load package 'sos';
 2. issue: findFn(Cramer-von Mises test)
   or, for a little wider scope: findFn(Cramer-von Mises)
 (in place of 'findFn', you can use '???')

  -Peter Ehlers


 Regards,
 Sean.





-- 
Sean Carmody
Twitter: http://twitter.com/seancarmody
Stable: http://mulestable.net/sean

The Stubborn Mule
Blog: http://www.stubbornmule.net
Forum: http://mulestable.net/

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