Re: [R] Function try and Results of a program

2010-09-04 Thread David Winsemius


On Sep 4, 2010, at 6:10 AM, Evgenia wrote:



Hello, users.

Dear users,

***I have a function f to simulate data from a model (example  
below used

only to show my problems)

f-function(n,mean1){
a-matrix(rnorm(n, mean1 , sd = 1),ncol=5)
b-matrix(runif(n),ncol=5)
data-rbind(a,b)
out-data
out}

*I want to simulate 1000 datasets (here only 5) so I use
S-list()

for (i in 1:5){
S[[i]]-f(n=10,mean1=0)}

**I have a very complicated function  for estimation of a model  
which I

want to apply to Each one of the above simulated datasets

fun-function(data){data-as.matrix(data)
sink(' Example.txt',append=TRUE)
 cat(\n***\nEstimation
\n\nDataset Sim : ,
   i )
d-data%*%t(data)
s-solve(d)
print(s)
out-list (s,d)
out
}
results-list()
for(i in 1:5){
tmp - try(fun(data=S[[i]]))
results[[i]] - ifelse(is(tmp,try-error),NA,tmp)
}

My problem is that results have only the 1st element of the  
result lists

of fun (i.e. only although tmp gives me both s and d.


Two problems:
One:  is the misguided use of unmatched sink calls resulting in an  
accumulation of diversions of the R output. If your run that at the  
console you need to type sink() five times to get any response back  
from the console.


Two: the misguided use of ifelse when you should be using if () 
{}else{} to test a single condition and execute conditional  
assignment. ifelse if for working with vectors, not with lists.


Suggestions:
use the append = TRUE parameter to sink and unsink at the end of that  
function


I'm not sure about how you are using the test for error but since you  
did not construct any errors I cannot really be too sure. If it is  
working  for you then use this instead:


if (is(tmp,try-error) ){results[[i]] - NA} else{results[[i]] - tmp}

--
David.




Thanks

Evgenia


--
View this message in context: 
http://r.789695.n4.nabble.com/Function-try-and-Results-of-a-program-tp2526621p2526621.html
Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
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] Function try and Results of a program

2010-09-04 Thread David Winsemius


On Sep 4, 2010, at 12:41 PM, Evgenia wrote:



David,

your suggestion about try works  perfect for me.

I still have a problem with sink. Could you explain me better your
suggestion?



When you sink to a file, you will continue sending console output to  
that file until you issue sink(). And every time you do it it creates  
an extra layer of redirection (the help page calls these diversions)  
that will need to be undone to get back to regular console behavior.


?sink # yes, one needs to R~all~TM

If you wanted a record of what that function was doing you would need  
to:


a) initialize the file with append=FALSE outside the loop (not sure if  
you need to do that, but it does help to get rid of earlier failed  
efforts as well

b) open the sink file with append=TRUE inside the function
c) cat() the two matrices separately since lists cannot be cat()- 
ted,,, and

d)unsink with sink() at the end of the function.


 sink(example.txt, append=FALSE); cat(\n ); sink() #blank line to  
initialize


 fun-function(data){ data-as.matrix(data)
  sink(example.txt, append=TRUE); cat(\nEstimate : , i, \n )
  d-data%*%t(data); cat(d= \n,d, \n)
  s-solve(d);   cat(s= \n,s, \n)
  out-list(s=s,d=d);  sink()
  return(out)
 }



View this message in context: 
http://r.789695.n4.nabble.com/Function-try-and-Results-of-a-program-tp2526621p2526822.html
Sent from the R help mailing list archive at Nabble.com.

--

David Winsemius, MD
West Hartford, CT


#
An unfortunate effect of Nabble use is that it leads one to believe  
that the entire world sees your earlier postings:

#-
f-function(n,mean1){
a-matrix(rnorm(n, mean1 , sd = 1),ncol=5)
b-matrix(runif(n),ncol=5)
data-rbind(a,b)
out-data
out}

*I want to simulate 1000 datasets (here only 5) so I use
S-list()

for (i in 1:5){
S[[i]]-f(n=10,mean1=0)}

**I have a very complicated function  for estimation of a model  
which I

want to apply to Each one of the above simulated datasets

fun-function(data){data-as.matrix(data)
sink(' Example.txt',append=TRUE)
 cat(\n***\nEstimation
\n\nDataset Sim : ,
   i )
d-data%*%t(data)
s-solve(d)
print(s)
out-list (s,d)
out
}
results-list()
for(i in 1:5){
tmp - try(fun(data=S[[i]]))
results[[i]] - ifelse(is(tmp,try-error),NA,tmp)
}

My problem is that results have only the 1st element of the result  
lists

of fun (i.e. only although tmp gives me both s and d.

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


Re: [R] What solve() does?

2010-09-04 Thread David Winsemius


On Sep 4, 2010, at 2:29 PM, Petar Milin wrote:


Thank you so much! This is very useful!
Any thoughts about how to run Gaussian elimination?


Do some searching?

RSiteSearch(gaussian elimination, restrict = c(Rhelp10, Rhelp08,  
Rhelp02, functions  ) )


 returns (among other things) a link to a John Fox post from 2005:

http://finzi.psych.upenn.edu/R/Rhelp02/archive/49950.html

--
David.


Best,
PM

On 04/09/10 20:23, Paul Johnson wrote:
On Wed, Sep 1, 2010 at 5:36 AM, Petar Milinpmi...@ff.uns.ac.rs   
wrote:



Hello!
Can anyone explain me what solve() function does: Gaussian  
elimination or
iterative, numeric solve? In addition, I would need both the  
Gaussian
elimination and iterative solution for the course. Are the two  
built in R?


Thanks!




PM


Hello, Petar:

I think you are assuming that solve uses an elementary linear algebra
paper and pencil procedure, but I don't think it does.  In a  
digital

computer, those things are not precise, and I think the folks here
will even say you shouldn't use solve to get an inverse, but I can't
remember all of the details.

To see how solve works ...

Let me show you a trick I just learned. Read

?solve

notice it is a generic method, meaning it does not actually do the
calculations for you. Rather, there are specific implementations for
different types of cases. To find the implementations, run

methods(solve)

I get:



methods(solve)


[1] solve.default solve.qr

Then if you want to read HOW solve does what it does (which I think
was your question), run this:



solve.default


or



solve.qr


In that code, you will see the chosen procedure depends on the linear
algebra libraries you make available.  I'm no expert on the details,
but it appears QR decomposition is the preferred method.  You can  
read

about that online or in numerical algebra books.






__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] non-zero exit status error when install GenomeGraphs

2010-09-04 Thread David Winsemius
(Caveat: I am not a bioc user.) The error messages suggest that you  
are missing dependencies. I looked at the documentation for  
GenomeGraphs and it does not list any dependencies, but I have no way  
of knowing how careful or knowledgeable the authors may or may not  
have bben when they composed that document. The fact that you are  
posting to the wrong mailing list and are not including what version  
of linux (although there is a hint it may be RedHat5) you are running  
suggests you could be fairly new at this.


Is biocLite the correct function for installing a bioc package? It  
appears it may be, but I'm wondering if there is an argument for  
dependencies as there is in install.packages() that you need to set to  
TRUE? If biocLite has a ,... in its argument list (and the error  
message suggests that it does) then you may get better results with  
the same call with an addition of dependencies=TRUE.


Or you could first install the packages that are reported missing: XML  
and biomaRt, and then try again as you did before.


Links to the bioc mailing lists can be found here:

http://www.bioconductor.org/help/index.html

--
David.



On Sep 4, 2010, at 4:07 PM, chen chao wrote:


Hi,

I am trying to install GenomeGraphs package from bioconductor, but  
failed by
a non-zero exit error. From the error message, it seems that there  
is a

shared library problem. Any suggestion on fixing it? Thanks so much.


sessionInfo()

R version 2.10.1 (2009-12-14)
x86_64-unknown-linux-gnu

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

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

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

source(http://bioconductor.org/biocLite.R;)

   biocLite(GenomeGraphs)Warning messages:
1: In safeSource() : Redefining 'biocinstall'
2: In safeSource() : Redefining 'biocinstallPkgGroups'
3: In safeSource() : Redefining 'biocinstallRepos'

   biocLite(GenomeGraphs)

Using R version 2.10.1, biocinstall version 2.5.11.
Installing Bioconductor version 2.5 packages:
[1] GenomeGraphs
Please wait...

Warning in install.packages(pkgs = pkgs, repos = repos, ...) :
 argument 'lib' is missing: using
'/cchome/cchen1/R/x86_64-unknown-linux-gnu-li
brary/2.10'
trying URL '
http://www.bioconductor.org/packages/2.5/bioc/src/contrib/GenomeGrap
hs_1.6.0.tar.gz'
Content type 'application/x-gzip' length 585078 bytes (571 Kb)
opened URL
==
downloaded 571 Kb

* installing *source* package 'GenomeGraphs' ...
** R
** data
** inst
** preparing package for lazy loading
Error in dyn.load(file, DLLpath = DLLpath, ...) :
 unable to load shared library
'/apps/rhel5/x86_64/R/R-2.10.1//lib64/R/library/
XML/libs/XML.so':
 libxmlsec1.so.1: cannot open shared object file: No such file or  
directory

Error : .onLoad failed in 'loadNamespace' for 'XML'
Error : package 'biomaRt' could not be loaded
ERROR: lazy loading failed for package 'GenomeGraphs'
* removing
'/userhom2/3/cchen1/R/x86_64-unknown-linux-gnu-library/2.10/GenomeGra
phs'

The downloaded packages are in
   '/tmp/Rtmp3wsJxw/downloaded_packages'
Warning message:
In install.packages(pkgs = pkgs, repos = repos, ...) :
 installation of package 'GenomeGraphs' had non-zero exit status




--
Chen, Chao
Psychiatry
University of Chicago
924 E 57th St, Chicago, IL 60637
U. S. A.
MOE Key Laboratory of Contemporary Anthropology and Center for
Evolutionary Biology,
School of Life Sciences and Institutes of Biomedical Sciences,
Fudan University
220# Handan Road, Shanghai (200433)
P.R.China

[[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] Please explain do.call in this context, or critique to stack this list faster

2010-09-04 Thread David Winsemius
:
## http://stackoverflow.com/questions/tagged/r
## I started to type in the question and 3 plausible answers
## popped up before I could finish.

## The terse answer is:
shortAnswer - do.call(rbind,mylist)

## That's the right answer, see:

shortAnswer == dataComplete
## But I don't understand why it works.

## More importantly, I don't know if it is fastest, or best.
## It is certainly less error prone than dataComplete

## First, make a bigger test case and use system.time to evaluate

phony - function(i){
 data.frame(w=rnorm(1000), x=rnorm(1000),y=rnorm(1000),z=rnorm(1000))
}
mylist - lapply(1:1000, phony)


### First, try the terse way
system.time( shortAnswer - do.call(rbind, mylist) )


### Second, try the complete way:
m - 1000
nr - nrow(df1)
nc - ncol(df1)

system.time(
  dataComplete - as.data.frame(matrix(0, nrow = nr*m, ncol = nc))
 )

system.time(
  for (j in  1:m) dataComplete[(((j-1)*nr) + 1):(j*nr), ] -  
mylist[[j]]

)


## On my Thinkpad T62 dual core, the shortAnswer approach takes  
about

## three times as long:


##  system.time( bestAnswer - do.call(rbind,mylist) )
##user  system elapsed
##  14.270   1.170  15.433

##  system.time(
## +dataComplete - as.data.frame(matrix(0, nrow = nr*m, ncol =  
nc))

## +  )
##user  system elapsed
##   0.000   0.000   0.006

##  system.time(
## + for (j in  1:m) dataComplete[(((j-1)*nr) + 1):(j*nr), ] -  
mylist[[j]]

## + )
##user  system elapsed
##   4.940   0.050   4.989


## That makes the do.call way look slow, and I said hey,
## our stupid for loop at the beginning may not be so bad.
## Wrong. It is a disaster.  Check this out:


##  resultDF - phony(1)
##  system.time(
## + for (i in 2:1000) resultDF - rbind(resultDF, mylist[[i]])
## +)
##user  system elapsed
## 159.740   4.150 163.996


--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

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


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] Linear Logistic Regression - Understanding the output (and possibly the test to use!)

2010-09-04 Thread David Winsemius


On Sep 4, 2010, at 6:53 PM, st...@wittongilbert.free-online.co.uk wrote:

Hi I know asking which test to use is frowned upon on this list...  
so please do read on for at least a couple on sentences...


I have some multivariate data slit as follows

Tumour Site (one of 5 categories) #
Chemo Schedule (one of 3 cats) ##
Cycle (one of 3 cats*) ##
Dose (one of 3 cats*) #

*These are actually integers but for all our other analysis so far  
we have grouped them into logical bands of categories.


The dependant variable is Reaction or No Reaction

I have individually analysed each of the independant variables  
against Reaction/No Reaction using ChiSq and Fisher Tests. Those  
marked ## produced p values less than 0.05, and those marked #  
produce p values close to 0.05.


We believe that Cycle is the crucial piece of data - the others just  
appear to be different because there are more early cycles in  
certain groups than others.


SO - I believe what I need to do is a Linear Logistic Regression on  
the 4 independant variables. And I'm expecting it to show that the  
tumour site, schedule and dose don't matter, only the cycle matters.  
Done a lot of reading and I'm clueless!!


I think I want to do something like:

glm (reaction ~ site + sched + cycle + dose, data=mydata,  
family=poisson)



I am then expecting to see some very long output with lots of  
numbers... ...my question is TWO fold -


1. is glm the right thing to use before I waste my time


Yes, but if your outcome variable is binomial then the family argument  
should be  binomial. (And if you thought it should be poisson,  
then why below did you use gaussian???


and 2. how do I interpret the result!


Result? What result? I do see any description of your data, nor any  
code.


(I'm kind of expect a lecture here as I'm really looking for a nice  
snappy 'p0.05 means this variable is the one having the influence'  
type answer and I suspect I'm going to be told thats not possible...!


I think you need to consult a statistician or someone who has taken  
the time to read that statistical mumbo jumbo you don't want to  
learn. This mailing list is not set up to be a tutorial site.


(Re your request below: Some years ago I saw one of those programmed  
learning texts by Kleinbaum on logistic regression. Maybe you could  
read it and see if it makes your consulting sessions go more smoothly.)


http://www.bookfinder.com/search/?author=kleinbaumtitle=logistic+regressionlang=enisbn=submit=Begin+searchnew_used=*destination=uscurrency=USDmode=basicst=srac=qr

I have a couple of Kleinbaum's (et al) other texts and find them to be  
well written and reasoned, so I suspect the citation above would be as  
accessible as any.




To be clear the example given in the docs is:


library(MASS)


snipped an example that was not relevant to logistic regression


---
Either can someone point me to a decent place that would explain  
what the means or provide me some pointers? i.e. which of the  
variables has the influence on the outcome in the anorexia data?


Please don't shout!! happy to be pointed to a reference but would  
prefer one in common english not some stats mumbo jumbo!


Calum


--

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] How can I fixe convergence=1 in optim

2010-09-04 Thread David Winsemius


On Sep 4, 2010, at 4:18 PM, Sally Luo wrote:


Hi R users,

I am using the optim funciton to maximize a log likelihood  
function.  My

code is as follows:

p-optim(c(-0.2392925,0.4653128,-0.8332286, 0.0657, -0.0031,  
-0.00245,

3.366, 0.5885, -0.8,
  0.0786,-0.00292,-0.00081, 3.266, -0.3632, -0.49, 
0.1856,

0.00394, -0.00193, -0.889, 0.5379, -0.63,
  0.213, 0.00338, -0.00026, -0.8912, -0.3023, -0.56), f,  
method

=BFGS, hessian =TRUE, y=y,X=X,W=W)
After I ran the code, I got the following results:
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~~

p

$par
[1]  2.235834e-02  1.282826e-01 -3.786014e-01  7.422526e-02   
3.037931e-02

-2.570156e-03  3.365872e+00  2.618893e-01 -1.987859e-06
[10]  7.970083e-02  2.878574e-03 -1.391019e-03  3.265966e+00  
-4.153697e-01

-3.185684e-03  1.833200e-01 -7.247683e-03 -3.156813e-03
[19] -8.889219e-01  6.208612e-01  2.678643e-04  2.183787e-01   
2.715062e-02

2.943905e-04 -8.913260e-01 -5.100482e-01 -3.477559e-04

$value
[1] -932.1423

$counts
function gradient
   1439  100

$convergence
[1] 1
$message
NULL

$hessian  ( I omitted the approximation results for the hessian here  
to save

space)
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~ 
~~


The error code 1 for convergence shown above means that the  
iteration limit
maxit had been reached.  How can I fix this problem and achieve  
convergence
for my optimization problem?  Can I increase the number of maxit so  
that

convergence might occur?


I am wondering how you expect us to guess at the answer? You are the  
one who know what f is and you are the one who has the option of  
increasing maxit. If the question is how to increase maxit, then the  
answer is perhaps as easy as:


?optim

--

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] Linear Logistic Regression - Understanding the output (and possibly the test to use!)

2010-09-05 Thread David Winsemius


On Sep 5, 2010, at 6:06 AM, st...@wittongilbert.free-online.co.uk wrote:


David Winsemius wrote:


1. is glm the right thing to use before I waste my time


Yes, but if your outcome variable is binomial then the family  
argument should be  binomial. (And if you thought it should  
be poisson, then why below did you use gaussian???
Used gaussian below because it was the example from the docs.  Thats  
not my data, its example data which was not binomial.




and 2. how do I interpret the result!


Result? What result? I do see any description of your data, nor any  
code.
I didn't provide MY DATA because I thought that would complicate  
things even further.  So I was hoping for some advice on how to  
interpret the result of the example data so that I could then apply  
that to my data.   I haven't even tried to run my data as I couldn't  
see what the output of the examples was trying to tell me.


I didn't think that providing commentary on ols regression results was  
going to be that germane to setting up and running logistic  
regression. Why haven't you tried a Google search for tutorials. When  
I did that I found:


http://www.ats.ucla.edu/stat/r/dae/logit.htm

Surely there are others.

--
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] converting string vector to integer/numeric vector

2010-09-05 Thread David Winsemius


On Sep 5, 2010, at 8:48 AM, rajesh j wrote:


Hi,

Is it possible to convert a string vector to integer or numeric  
vector? In
my situation I receive data in a string vector and have to convert  
it based

on a given type.


Can you give an example? I don't understand either what sort of  
conversion you desire or what you mean by convert it based on a given  
type.


There are a couple of function you may want to consider but I am  
having difficulty convincing myself they answer the problem posed:


?charToRaw
?stroi

 strtoi(charToRaw(123 this is a string), base=16)   # convert to  
decimal ASCII
 [1]  49  50  51  32 116 104 105 115  32 105 115  32  97  32 115 116  
114 105 110 103


--

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] converting string vector to integer/numeric vector

2010-09-05 Thread David Winsemius

On Sep 5, 2010, at 9:22 AM, rajesh j wrote:

 for e.g., I get the following as a string vector
 int 4 5 6
 after reading the first element, I have to convert this to a integer  
 vector

But what is the right answer?  And what number of items are possble  
per line?  And what are the other possible type identifiers? We need  
an example that has enough complexity to allow testing.

-- 
David.



 On Sun, Sep 5, 2010 at 6:44 PM, David Winsemius dwinsem...@comcast.net 
  wrote:

 On Sep 5, 2010, at 8:48 AM, rajesh j wrote:

 Hi,

 Is it possible to convert a string vector to integer or numeric  
 vector? In
 my situation I receive data in a string vector and have to convert  
 it based
 on a given type.

 Can you give an example? I don't understand either what sort of  
 conversion you desire or what you mean by convert it based on a  
 given type.

 There are a couple of function you may want to consider but I am  
 having difficulty convincing myself they answer the problem posed:

 ?charToRaw
 ?stroi

  strtoi(charToRaw(123 this is a string), base=16)   # convert to  
 decimal ASCII
  [1]  49  50  51  32 116 104 105 115  32 105 115  32  97  32 115 116  
 114 105 110 103

 -- 

 David Winsemius, MD
 West Hartford, CT




 -- 
 Rajesh.J



David Winsemius, MD
West Hartford, CT


[[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] converting string vector to integer/numeric vector

2010-09-05 Thread David Winsemius
So there is one item per line and the task is to recognize the strings  
INT and NUM and create variables with numeric type and


INT=c(2,3,4)
NUM=c(2.37, 4.56)  # ???

I worry that is not a full description of the task  if there be  
more than just two variable names and if all the INTs have the same  
name, then they will get overwritten   but perhaps you have  
specified the problem completely, so here goes:


 txt - textConnection('INT
+ 2
+ 3
+ 4
+
+ NUM
+ 2.37
+ 4.56')
 indat - read.table(txt, stringsAsFactors=FALSE)

 indat$nflag - as.numeric(indat$V1)
 cumsum(is.na(indat$nflag))
[1] 1 1 1 1 2 2 2

 by(indat$V1, cumsum(is.na(indat$nflag)), function(x)  
assign(as.character(x[1]), as.numeric(x[-1]) ,envir = .GlobalEnv) )

cumsum(is.na(indat$nflag)): 1
[1] 1 3 4
-
cumsum(is.na(indat$nflag)): 2
[1] 2 5
 INT
[1] 1 3 4
 NUM
[1] 2 5
.



On Sep 5, 2010, at 9:33 AM, rajesh j wrote:

The string vector actually comes as a part of a list, and the vector  
is named int, and the numbers are strings. I then have to make it  
a vector that is still called int and has 4,5,6 etc. the types are  
either integer or numeric. The number of items in the vector is  
unknown.


here's an example,

a list has vectors

INT
2
3
4

NUM
2.37
4.56



On Sun, Sep 5, 2010 at 6:56 PM, David Winsemius dwinsem...@comcast.net 
 wrote:


On Sep 5, 2010, at 9:22 AM, rajesh j wrote:


for e.g., I get the following as a string vector
int 4 5 6
after reading the first element, I have to convert this to a  
integer vector


But what is the right answer?  And what number of items are possble  
per line?  And what are the other possible type identifiers? We need  
an example that has enough complexity to allow testing.


--
David.




On Sun, Sep 5, 2010 at 6:44 PM, David Winsemius dwinsem...@comcast.net 
 wrote:


On Sep 5, 2010, at 8:48 AM, rajesh j wrote:

Hi,

Is it possible to convert a string vector to integer or numeric  
vector? In
my situation I receive data in a string vector and have to convert  
it based

on a given type.

Can you give an example? I don't understand either what sort of  
conversion you desire or what you mean by convert it based on a  
given type.


There are a couple of function you may want to consider but I am  
having difficulty convincing myself they answer the problem posed:


?charToRaw
?stroi

 strtoi(charToRaw(123 this is a string), base=16)   # convert to  
decimal ASCII
 [1]  49  50  51  32 116 104 105 115  32 105 115  32  97  32 115  
116 114 105 110 103


--

David Winsemius, MD
West Hartford, CT




--
Rajesh.J




David Winsemius, MD
West Hartford, CT




--
Rajesh.J




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] converting string vector to integer/numeric vector

2010-09-05 Thread David Winsemius


On Sep 5, 2010, at 10:47 AM, rajesh j wrote:

I'm sorry. you seem to have misunderstood my data representation for  
input.


Because you did not follow the Posting Guide's advice regarding  
producing examples using valid R code. You give me text; I work on text.


#-
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
#

I am going to change the name of the variable to cc because c is a  
unfortunate name for a variable, since it is also the name of a  
crucial function.



Here's what I have
cc-list(INT=c(1,2,3),NUM=c(2.34,4.56,6.78))
I need
c-list(INT=c(1,2,3),NUM=c(2.34,4.56,6.78))


 cc - lapply(cc, as.numeric)
 cc
$INT
[1] 1 2 3

$NUM
[1] 2.34 4.56 6.78


--
David.




On Sun, Sep 5, 2010 at 7:57 PM, David Winsemius dwinsem...@comcast.net 
 wrote:
So there is one item per line and the task is to recognize the  
strings INT and NUM and create variables with numeric type and


INT=c(2,3,4)
NUM=c(2.37, 4.56)  # ???

I worry that is not a full description of the task  if there be  
more than just two variable names and if all the INTs have the same  
name, then they will get overwritten   but perhaps you have  
specified the problem completely, so here goes:


 txt - textConnection('INT

+ 2
+ 3
+ 4
+
+ NUM
+ 2.37
+ 4.56')
 indat - read.table(txt, stringsAsFactors=FALSE)

 indat$nflag - as.numeric(indat$V1)
 cumsum(is.na(indat$nflag))
[1] 1 1 1 1 2 2 2

 by(indat$V1, cumsum(is.na(indat$nflag)), function(x)  
assign(as.character(x[1]), as.numeric(x[-1]) ,envir = .GlobalEnv) )

cumsum(is.na(indat$nflag)): 1
[1] 1 3 4
-
cumsum(is.na(indat$nflag)): 2
[1] 2 5
 INT
[1] 1 3 4
 NUM
[1] 2 5
.




On Sep 5, 2010, at 9:33 AM, rajesh j wrote:

The string vector actually comes as a part of a list, and the vector  
is named int, and the numbers are strings. I then have to make it  
a vector that is still called int and has 4,5,6 etc. the types are  
either integer or numeric. The number of items in the vector is  
unknown.


here's an example,

a list has vectors

INT
2
3
4

NUM
2.37
4.56



On Sun, Sep 5, 2010 at 6:56 PM, David Winsemius dwinsem...@comcast.net 
 wrote:


On Sep 5, 2010, at 9:22 AM, rajesh j wrote:

for e.g., I get the following as a string vector
int 4 5 6
after reading the first element, I have to convert this to a integer  
vector


But what is the right answer?  And what number of items are possble  
per line?  And what are the other possible type identifiers? We need  
an example that has enough complexity to allow testing.


--
David.



On Sun, Sep 5, 2010 at 6:44 PM, David Winsemius dwinsem...@comcast.net 
 wrote:


On Sep 5, 2010, at 8:48 AM, rajesh j wrote:

Hi,

Is it possible to convert a string vector to integer or numeric  
vector? In
my situation I receive data in a string vector and have to convert  
it based

on a given type.

Can you give an example? I don't understand either what sort of  
conversion you desire or what you mean by convert it based on a  
given type.


There are a couple of function you may want to consider but I am  
having difficulty convincing myself they answer the problem posed:


?charToRaw
?stroi

 strtoi(charToRaw(123 this is a string), base=16)   # convert to  
decimal ASCII
 [1]  49  50  51  32 116 104 105 115  32 105 115  32  97  32 115 116  
114 105 110 103


--


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] dirichlet models

2010-09-05 Thread David Winsemius


On Sep 5, 2010, at 10:53 AM, Donald Braman wrote:


Does anyone know of a package (or workaround) for fitting a dirichlet
distribution by maximum likelihood?


Searching:

RSiteSearch(fitting dirichlet distribution maximum likelihood)

(Rapidly) produces this candidate:

http://finzi.psych.upenn.edu/R/library/VGAM/html/dirichlet.html



(I'm looking for something like this: http://repec.org/bocode/d/dirifit.html 
,
that allows for both dependent variables summing to 1  predictive  
variables

of any sort.)

Don


--
Donald Braman


--
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] Greek symbols (again but more complicated)

2010-09-05 Thread David Winsemius


On Sep 5, 2010, at 11:41 AM, John Helly wrote:


Hi.

I'm trying to get 'mu' to show up as a Greek symbol but, despite  
trying every example I could find, can't get it to work.  Any  
insights would be welcome.


This is what I'm using that works, but displays mu with the letter u.

plotTimeXMastPAR - qplot(DT,MastPAR, data=A, xlab = , ylab =  
quote(PAR (uE ~m^-2 ~s^-1)), geom=line) +  
opts(legend.position=none)




I suppose most readers will know by now that qplot is part of ggplot2,  
but it would be better manners to include the require() statement that  
would identify the non-base package, as would inclusion of a working  
example:


require(ggplot2)

qplot(mpg, wt, data=mtcars, ylab=expression(PAR*(mu*E~m^-2~s^-1)))

or
qplot(mpg, wt, data=mtcars, ylab=quote(PAR*(mu*E~m^-2~s^-1)))


This is an attempt to get mu to look right but it does not work.  It  
doesn't fail but nothing inside the expression statement gets  
displayed.


plotTimeXMastPAR - qplot(DT,MastPAR, data=A, xlab = , ylab =  
c(PAR, expression(mu, quote(E ~m^-2 ~s^-1))), geom=line) +  
opts(legend.position=none)


Cheers.
--
John Helly, UCSD / San Diego Supercomputer Center / Scripps  
Institution of Oceanography, Climate, Atmospheric Science, and  
Physical Oceanography / +01 760 840 8660 mobile / stonesteps  
(Skype) / stonesteps7 (iChat) / /www.sdsc.edu/~hellyj


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

2010-09-05 Thread David Winsemius


On Sep 5, 2010, at 1:21 PM, Aks Ism wrote:


Hi,

I've looked at previous discussions and did not get anything. I want  
to be

able to append to a list in a loop. Is this possible?


Of course:

?c

?[[

--
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] Need Help .RData in Mac OS X, Please

2010-09-05 Thread David Winsemius


On Sep 5, 2010, at 12:50 PM, Chunhao wrote:



Hi R Users,
I was accidentally save R file when I quit R program. I try to  
delete but I
am not sure the R saved file was successfuly delete or not. Now  
everyt time

when I open the R, it always appears

[R.app GUI 1.34 (5589) i386-apple-darwin9.8.0]

[Workspace restored from /Users/ctu/.RData]

I have read google, R help and Nabble but I still can't solve this  
problem.


Search on either the R_SIG-MAC list or in Google for show dotted  
files. Apply that method to your working directory, delete the  
invisible .RData file, and then decide whether you want to revert to  
the default Finder behavior.


One citation:
http://artofgeek.com/2009/09/16/toggle-display-of-hidden-files-in-finder-with-keyboard-shortcut/

I have globally changed my system to show dotted files, but not  
everyone feels safe doing so.


At the terminal window I have entered:

defaults write com.apple.Finder AppleShowAllFiles YES

 . and then pt-click-hold on Dock-Finder-icon, choose relaunch

Or you could open a Terminal window which will by default open in / 
Users/ctu/ and type:


 rm .RData

--

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] appending to a list

2010-09-05 Thread David Winsemius


On Sep 5, 2010, at 10:11 PM, Aks Ism wrote:


No, I mean dynamically. Like list.push_back


Not sure what you mean by dynamically and my Google search for the  
unspecified function list.push_back uncovered a C++ function that is  
at least as complex as what I believe would be the equivalent R  
function. I think you need to expand your discussion and your  
executable R examples before people are going to understand what you  
are thinking (but not writing).


mylist - c(mylist, my.element)

c() simply adds an element and R requires that you assign it if it is  
to be preserved.


Perhaps you mean something like this:

ll - list();
for (i in 1:20) {
   my.element - scan();
   ll - c(ll, my.element);
   if (is.na(my.element)){return(ll);break}}


--
David.


On Mon, Sep 6, 2010 at 1:01 AM, David Winsemius dwinsem...@comcast.net 
 wrote:


On Sep 5, 2010, at 1:21 PM, Aks Ism wrote:

Hi,

I've looked at previous discussions and did not get anything. I want  
to be

able to append to a list in a loop. Is this possible?

Of course:

?c

?[[

--
David Winsemius, MD
West Hartford, CT




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] extracting x,y coordinates from a contour plot

2010-09-05 Thread David Winsemius


On Sep 5, 2010, at 11:48 PM, Charles Annis, P.E. wrote:

Requisite info: R version 2.11.1 (2010-05-31) running on a 64 bit HP  
Windows

7 machine.


Doubt that makes much of a difference here.

I have used contour() for several years.  Now I would like to  
extract from a
contour plot the x, y coordinates of a contour z=constant.  This  
seems as

though it would be straight-forward but I've been unsuccessful in my
searches of CRAN.


Suggest you read the help page for contour and the pages to which it  
links as well as working the examples. The answer is illustrated in  
the examples on that page.



Can anyone provide a hint?


 x - 10*1:nrow(volcano)
 y - 10*1:ncol(volcano)
 xy160 - contourLines(x, y, volcano, nlevels=1, levels=160)
 str(xy160)
List of 2
 $ :List of 3
  ..$ level: num 160
  ..$ x: num [1:165] 110 108 105 102 103 ...
  ..$ y: num [1:165] 295 300 310 320 330 ...
 $ :List of 3
  ..$ level: num 160
  ..$ x: num [1:31] 270 263 262 260 260 ...
  ..$ y: num [1:31] 310 320 330 340 350 ...

--
David.

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] Correct coefficients from treatment contrasts?

2010-09-06 Thread David Winsemius


On Sep 6, 2010, at 4:03 AM, B W wrote:

Snipped out formatting detritus and added back many missing speces.

-Hello,I am trying to take the information from the summary of my  
best fit logisticregression model for the occurrence of a high  
elevation plant spp. and create the appropriate equation that will  
calculate probability of occurrence, given the data. My predictors  
include both continuous variables (slope and a second  
orderpolynomial of elevation) and a discrete variable for aspect  
(warm and cool). I have left unchanged the default contrasts option,  
so I believe that thefollowing coefficients were created using  
treatment contrasts.  My question how can I take this summary output  
and create the logistic equation that will allow me to calculate  
probability of occurrence. My interests are touse this to spatially  
display this info in a GIS environment.


I think you should:

-- Read the Posting Guide where you should learn that this is a plain  
text mailing list and that you need to change the configuration of  
your mail client.


-- Read the help page and read other documentation regarding the use  
of the predict function.


I have made adraft equation (shown below) that uses the coefficients  
from this summaryoutput, but this appears to be incorrect – values  
always return zeroprobabilities. Presumably I need to adjust the  
values in some way – but I am unclear as to how to proceed.  
Anyguidance would be appreciated!



 summary (


Call:glm(formula= Po ~ Slope + poly(Elevation, 2) + Aspect_2, family  
= quasibinomial) DevianceResiduals: Min  1Q   Median
3Q Max  -1.0532  -0.4167 -0.2760  -0.1823   3.3376


Coefficients:  Estimate Std. Error t valuePr(| 
t|)(Intercept)  -4.577707   0.222406 -20.583   2e-16 ***



Slope 0.039959   0.003593 11.121   2e-16 ***



poly(Elevation,2)1   8.050898   5.601956  1.437   0.1508



poly(Elevation,2)2 -37.694521   6.297806  -5.985 2.39e-09 ***



Aspect_2w 0.429229   0.174760  2.456   0.0141 *  ---


You may get predictions at the original data points with:

pred  predict(model.Slope.Elevation.Aspect)

 (1/ (1 +  exp(-1 * (-4.577707 + 0.039959*Slope + 8.050898 *  
poly(Elevation, 2)1 + -37.694521 * poly(Elevation, 2)2 + 0.429229*  
Aspect_2w)


Brendan Wilson
2530 Alexis Road
Shoreacres BC
Canada  V1N 4P6
Ph: 1.250.359.5905



[[alternative HTML version deleted]]


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] Aggregating the matrices

2010-09-06 Thread David Winsemius


On Sep 6, 2010, at 9:56 AM, Sergey Goriatchev wrote:


Hello everyone.

Say we have the following:

a - matrix(c(-75, 3, 5, 9, 2, 3, 5), nrow=1, dim=list(06092010,
c(ES, PT, Z , CF, GX, ST, EO)))
b - matrix(c(-5, 2, 4, 12, 5), nrow=1, dim=list(06092010, c(PT,
CF, AT, EM, ST)))
d - cbind(a, b)

I want to calculate sums of the columns that have similar column names
and then output this summary
What I want to have is an array that looks like:

ES  PT Z  CF...
-75  -2  5  11...

I tried the following, but it did not work:
aggregate(d, list(colnames(d)), sum)


ES is not in the duplicated column names so perhaps your English  
specification is not what you meant:

 d
  ES PT Z  CF GX ST EO PT CF AT EM ST
06092010 -75  3  5  9  2  3  5 -5  2  4 12  5

 dupled - colnames(d)[duplicated(colnames(d))]
 sapply(dupled, function(x) sum( d[, x]))
PT CF ST
 3  9  3

If you wanted simple a sum over unique column names then it would have  
been somewhat simpler (no need to construct a duplicated set):


 sapply(unique(colnames(d)), function(x) sum( d[, x]))
 ES  PT  Z   CF  GX  ST  EO  AT  EM
-75   3   5   9   2   3   5   4  12



How can I achieve my objective?

Thank you in advance.

Sergey

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

2010-09-06 Thread David Winsemius


On Sep 5, 2010, at 10:32 AM, Daniele Sluijters wrote:


Hello,

I'm sorry to just pop-up on the mailing list like this and ask a  
relatively non-R related question but I had no idea whom else to  
contact on this matter.
I'm working on a completely different port of an application to OS X  
which requires GTK and through Google'ing stumbled on a rather  
recent GTK installer for Mac at: http://r.research.att.com/


I was wondering if anyone here knows how GTK and its dependencies  
were packaged into that pkg? It'd be a lifesaver if someone could  
point me in the right direction.


Again, sorry for the non-R related question but this place seemed  
like the only option.


The is an R-SIG-Mac mailing list. It's webpage is at the top of the  
SIG entries on:

http://www.r-project.org/mail.html

I suspect that Simon Urbanek, who maintains the ATT webpages and very  
probably created that package, sometimes reads rhelp but I'm not sure  
on what schedule. You might see if he makes his email address  
available on those pages.


--

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] Aggregate certain rows in a matrix

2010-09-06 Thread David Winsemius


On Sep 6, 2010, at 10:47 AM, Dimitris Rizopoulos wrote:


one way is the following:

M - cbind(c(1,1,1,1,2,2,3,3,3,3), c(2,2,2,3,4,4,4,5,5,6),
   c(1,2,3,4,5,6,7,8,9,10))

ind - do.call(paste, c(as.data.frame(M[, 1:2], sep = \r)))
M[, 3] - ave(M[, 3], ind, FUN = sum)
unique(M)


I had been working on a similar approach with ave( ,paste(), sum)  
inside a datafrmae, but I liked your approach of setting up the  
results of the paste operation as a vector outside of M. (Skips the  
dataframe operation I was using.) The above solution is destructive,  
so I constructed this similar alternative that returns the results  
without altering M:


 cbind(M, ave(M[ , 3], list(M[,1], M[,2]), FUN=sum))[
   !duplicated(M[,1:2]),  
c(1,2,4)]

 [,1] [,2] [,3]
[1,]126
[2,]134
[3,]24   11
[4,]347
[5,]35   17
[6,]36   10





I hope it helps.

Best,
Dimitris


On 9/6/2010 4:29 PM, Kennedy wrote:


Hi,

I have a matrix that looks like this

  a- c(1,1,1,1,2,2,3,3,3,3)
  b- c(2,2,2,3,4,4,4,5,5,6)
  c- c(1,2,3,4,5,6,7,8,9,10)
  M- matrix(nr=10,nc=3)
  M[,1]- a
  M[,2]- b
  M[,3]- c


M

  [,1] [,2] [,3]
 [1,]121
 [2,]122
 [3,]123
 [4,]134
 [5,]245
 [6,]246
 [7,]347
 [8,]358
 [9,]359
[10,]36   10

I want to reduce the matrix according to the following: If the  
values of the
two first columns are the same in two or more rows the values in  
the third
column of the corresponding rows should be added and only one of  
the rows

should be keept. Hence the matrix M above should look like this

  1 2 6
  1 3 4
  2 4 11
  3 4 7
  3 5 17
  3 6 10


Thank you

Henrik





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

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

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


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] WriteXLS problem

2010-09-06 Thread David Winsemius


On Sep 6, 2010, at 12:25 PM, Kenneth Roy Cabrera Torres wrote:


Thank you Ivan for you answer:
El lun, 06-09-2010 a las 18:11 +0200, Ivan Calandra escribió:

Hi,

Are you sure you used the correct syntax and object names? It might  
just

be because of that...(reading the error messages)

Im sure, because it works with write.csv or write.table.


Sure? You are making the incorrect assumption that those write  
functions have the same syntax. At least for WriteXLS that assumption  
is false. The help page clearly states that the objects need to be  
quoted rather than being referred to by their naked names. The error  
you are getting with your second option suggests to me that you  
offered an unquoted name of an object.


You can offer a vector of quoted names of dataframes to WriteXLS and  
each named dataframe will be converted to a worksheet within the  
workbook.


--
David.


There is another function, xlsReadWrite::write.xls(), that I like a  
lot:

it is really easy to use and does not require Perl or Python.

Unfortunately it works on windows, and I am in a non windows platform
(ubuntu).

Thank you for you advice and help.

Kenneth


HTH,
Ivan

Le 9/6/2010 18:03, Kenneth Roy Cabrera Torres a crit :

Hi R users:

I don't know if you have had the following problem trying to
export to an xls format file in a non windows platform.

I try to use the following packages:
1. dataframes2xls (version 0.4.4) (with phyton 2.7 and 3.1)
2. WriteXLS (version 1.9.0) (with perl and testPerl working)

Even xlsx package that take too long and do not finish.

The data frame I try to export has 269363 row and 116 columns.
In the first one (dataframe2xls) I get this message:

Traceback (most recent call last):
 File
C:/PROGRA~2/R/R-211~1.1PA/library/dataframes2xls/python/ 
csv2xls.py,

line 18, inmodule
import pyexcelerator
File
C:\PROGRA~2\R\R-211~1.1PA\library\dataframes2xls\python 
\pyexcelerator

\__init__.py,
line 12, inmodule  from Workbook import Workbook
File
C:\PROGRA~2\R\R-211~1.1PA\library\dataframes2xls\python 
\pyexcelerator

\Workbook.py,
line 526 boundsheets_len +=  
len(BIFFRecords.BoundSheetRecord(0x00L,

sheet.hidden, sheet.name).get())
^
SyntaxError: invalid syntax

Using the second option I get this message:

Error en get(as.character(i)),envr=envir) :
  objeto '089' no encontrado

Object '089' not found.

Im using this R platform:
sessionInfo()
R version 2.11.1 Patched (2010-08-30 r52848)
Platform: x86_64-unknown-linux-gnu (64-bit)

Locale:
LC_CTYPE=es_CO.UTF-8

Is the only solution to export to .csv and then
to .xls format with other program like openoffice?

Thank you for your help and advice.

Kenneth

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



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


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


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] poisson distribution

2010-09-06 Thread David Winsemius


On Sep 6, 2010, at 1:13 PM, tamas barjak wrote:


Hello!

I need some help.
How I know it to draw the formula of the poisson distribution?

expr-expression(P(xi == k) == frac(lambda^k, factorial(k))*e^- 
lambda) ---

not good


?plotmath

(Do not see factorial as a plotmath function

Try:

expr-expression(P(xi == k) == frac(lambda^k, k*!)*e^-lambda)



on the screen the  k!  not the Poisson Formula, but factorial(k)

Thanx!


-- David.

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


Re: [R] Failure to aggregate

2010-09-06 Thread David Winsemius


On Sep 6, 2010, at 12:15 PM, Dimitri Shvorob wrote:



I have a (very big - 1.5 rows) dataframe with a (POSIXt  POSIXlt)  
column h

(hour). Surprisingly, I cannot calculate a simple aggregate over the
dataframe.


n.h1 = sqldf(select distinct h, count(*) from x group by h)

Error in sqliteExecStatement(con, statement, bind.data) :
 RS-DBI driver: (error in statement: no such table: x)
In addition: Warning message:
In value[[3L]](cond) : RAW() can only be applied to a 'raw', not a  
'double'



n.h2 = aggregate(x$price, by = x$h, FUN = nrow)


A vector argument (x$price) would only have one row (at most).

nrow(c(1,2)
NULL


Error in names(y) - c(names(by), names(x)) :
 'names' attribute [10] must be the same length as the vector [2]


Try:

tapply(x$price, by = x$h, FUN = length)

--
David.

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


Re: [R] how to change the xlab name?

2010-09-06 Thread David Winsemius


On Sep 6, 2010, at 2:07 PM, tooblue wrote:



I simply put,  plot(density(), main=, + xlab = XXX), it  
says that

I have an unexpected = in it.


It may be a case of a confused parser. You have an extraneous + in  
there:


  = rnorm(100)
 plot(density(), main=,  xlab = XXX)  # works

If on the other hand you wanted to construct a more complex title then  
you will probably need to read the expression and bquote help pages  
and submit a more descriptive problem statement.


--
David.

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


Re: [R] two questions

2010-09-06 Thread David Winsemius
The usual least-squares methods are fairly robust to departures from  
normality. Furthermore, it is the residuals that are assumed to be  
normally distributed (not the marginal distributions that you are  
probably looking at) , so it does not sound as though you have yet  
examined the data properly. Tell us what the descriptive stats (say  
the means, variance, 10th and 90th percentiles) are on the residuals  
within cells cross-classified by the gender and city-of-birth  
variables (say the means, variance, 10th and 90th percentiles).


On Sep 6, 2010, at 4:34 PM, Iasonas Lamprianou wrote:



Dear friends, two questions

(1) does anyone know if there are any non-parametric equivalents of  
the two-way ANOVA in R? I have an ordinal non-normally distributed  
dependent variable and two factors (gender and city of birth).  
Normally, one would try a two-way anova, but if R has any non- 
parametric equivalents, that might be great.


There is an entire task view page on robust methods if you decide to  
press on with this quest.


(2) Also, if the interaction of gender and city of birth is  
statistically significant, which post-hoc tests should I run?


How many cities are we talking about?


Thanks

Jason


Dr. Iasonas Lamprianou


--

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] WriteXLS problem

2010-09-06 Thread David Winsemius


On Sep 6, 2010, at 8:09 PM, Dejian Zhao wrote:

The maximum number of rows in excel 2003 or below is 65535, less  
than your number of rows, so if you export your data into xls  
files, probably you cannot see all your data in excel. Exel 2007 can  
hold as many as 1048575 lines, thus xlsx file is a better choice.


The maximum number of rows in more editions of Excel.2003 was  
increased to a million. You may be correct about the Perl module that  
underlies WriteXLS, however. Here is an extract from the CPAN page for  
that module:


http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel/lib/Spreadsheet/WriteExcel.pm#LIMITATIONS

LIMITATIONS
The following limits are imposed by Excel:

Description Limit --- --
 Maximum number of chars in a string 32767
 Maximum number of columns 256
 Maximum number of rows 65536
 Maximum chars in a sheet name 31
 Maximum chars in a header/footer 254
The minimum file size is 6K due to the OLE overhead. The maximum file  
size is approximately 7MB (7087104 bytes) of BIFF data. This can be  
extended by installing Takanori Kawai's OLE::Storage_Lite module http://search.cpan.org/search?dist=OLE-Storage_Lite 
 see the bigfile.pl example in the examples directory of the distro.


--
David






On 2010-9-7 0:03, Kenneth Roy Cabrera Torres wrote:

Hi R users:

I don't know if you have had the following problem trying to
export to an xls format file in a non windows platform.

I try to use the following packages:
1. dataframes2xls (version 0.4.4) (with phyton 2.7 and 3.1)
2. WriteXLS (version 1.9.0) (with perl and testPerl working)

Even xlsx package that take too long and do not finish.

The data frame I try to export has 269363 row and 116 columns.
In the first one (dataframe2xls) I get this message:

Traceback (most recent call last):
 File
C:/PROGRA~2/R/R-211~1.1PA/library/dataframes2xls/python/csv2xls.py,
line 18, inmodule
import pyexcelerator
File
C:\PROGRA~2\R\R-211~1.1PA\library\dataframes2xls\python 
\pyexcelerator

\__init__.py,
line 12, inmodule  from Workbook import Workbook
File
C:\PROGRA~2\R\R-211~1.1PA\library\dataframes2xls\python 
\pyexcelerator

\Workbook.py,
line 526 boundsheets_len +=  
len(BIFFRecords.BoundSheetRecord(0x00L,

sheet.hidden, sheet.name).get())
^
SyntaxError: invalid syntax

Using the second option I get this message:

Error en get(as.character(i)),envr=envir) :
  objeto '089' no encontrado

Object '089' not found.

Im using this R platform:
sessionInfo()
R version 2.11.1 Patched (2010-08-30 r52848)
Platform: x86_64-unknown-linux-gnu (64-bit)

Locale:
LC_CTYPE=es_CO.UTF-8

Is the only solution to export to .csv and then
to .xls format with other program like openoffice?

Thank you for your help and advice.

Kenneth

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] how to combine several subsets?

2010-09-06 Thread David Winsemius


On Sep 6, 2010, at 9:22 PM, tooblue wrote:



I simply put,

NEVER=subset(infants$bwt,ISNO1)
UNTILPREGNANT=subset(infants$bwt, ISNO2)
ONCENOTNOW=subset(infants$bwt, ISNO3)


and I wanna combine those three.
I do it like
ISNO=NEVERUNTILPREGNANTONCENOTNOW


The  operator does not do concatenation, but rather returns a  
logical vector. You may have had your mind adversely affected by  
excessive exposure to Excel.


Hopefully you did not do just that at the command line. I could  
imagine thinking that might work as part of the subset argument to  
subset, but it would be through the use of the or operator, |:


ALL - subset(infants$bwt, ISNO1| ISNO2| ISNO3)

If they were dataframes, you could also have done:

ALL -  rbind(NEVER, UNTILPREGNANT, ONCENOTNOW)

But below you suggested they might be vectors; if so, why not:

ALL -  c(NEVER, UNTILPREGNANT, ONCENOTNOW)



and R tells me
1: In NEVER  UNTILPREGNANT :
 longer object length is not a multiple of shorter object length
2: In NEVER  UNTILPREGNANT  ONCENOTNOW :
 longer object length is not a multiple of shorter object length

I'm confused coz these are not objects, but a list of sets of numbers.


They really _must_ be objects since you assigned a result to those  
names.


(Greater clarity would occur if you offered at least str(NEVER)

--
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] Prediction and confidence intervals from predict.drc

2010-09-06 Thread David Winsemius


On Sep 6, 2010, at 7:54 PM, Brant Inman wrote:


R-helpers,

I am using the package drc to fit a 4 parameter logistic model.   
When I

use the predict function to get prediction on a new dataset, I am not
getting the requested confidence or prediction intervals.  Any idea  
what

is going on?  Here is code to reproduce the problem:

---

library(drc)

# Fit model to existing dataset in package
spinach.model - drm(SLOPE~DOSE, data = spinach, fct = LL.4())


(Comparing to the predict example code.) You did not specify a CURVE  
argument. Not sure what effect that would have.


#Generate new fake dataset
newdt - data.frame(matrix(c(seq(0, 150, 0.1), rep(NA, 1501)), ncol=2,
byrow=F))
colnames(newdt) - c('DOSE', 'SLOPE')


You did not include a CURVE variable. But this provokes nary a  
complaint. I wondered if the estimates may be an unlabeled mixture  
from the 5 CURVEs


#Use predict function to get prediction and confidence intervals
pred - predict(spinach.model, interval='prediction', newdata=newdt)


You did not specify CURVE. The example uses one:
predict(spinach.model1, data.frame(dose=2, CURVE=c(1, 2, 3)),  
interval = prediction)

With your object:

 head(predict(spinach.model, data.frame(dose=2, CURVE=c(1)),
+ interval = prediction))
Prediction  Lower  Upper
 0.3500492 -0.2790351  0.9791336

With the original example:
 predict(spinach.model1, data.frame(dose=2, CURVE=c(1, 2, 3)),
+ interval = confidence)
 Prediction Lower Upper
[1,]  0.9048476 0.8552178 0.9544775
[2,]  0.4208307 0.3626741 0.4789873
[3,]  0.5581673 0.4971838 0.6191509

With your object
 predict(spinach.model, data.frame(dose=2, CURVE=c(1)),
+ interval = confidence)
Prediction  Lower  Upper
 0.3500492  0.2673464  0.4327521


conf - predict(spinach.model, interval='confidence', newdata=newdt)
head(pred); head(conf)

---

Examining the output shows the point estimates but not the intervals.
Would like the intervals.


I am using the most recent versions of R and drc on Windows XP.

Thanks,

Brant
[[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] Saving fits (glm, nls) without data

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 11:02 AM, Johann Hibschman wrote:


Is there any package that assists in saving and reconstituting glm and
nls fits without bringing along the accompanying data?  A quick search
on CRAN didn't turn up anything.

If not, how do other people deal with saving the coefficients of model
fits?

For example, I've run a glm fit that has 23 coefficents on data set  
that

had 193,008 rows, by the time the fit was called.  When I save the
resulting fit object, I get a 491 MB object, which suggests that it's
pulling along all sorts of junk in the environment, as 23*193k*8 is  
only

34 MB.  Even so, I would prefer to only save the coefficients


Have you read through the Value section of glm's help page?

...and

?coef


and the
Hessian, not the fit data set.


I'm not sure about whether there will be a Hessian in a glm object.  
Have you run str() on your objects. It's likely that the residuals,  
fitted.values, weights, prior.weights, and linear.predictors are going  
to be fairly large. You could use lapply to run object.size to see  
whether I have missed any. When I do that on hte first help page  
example, it is the model component that is the second largest, but its  
inclusion is optional. The largest compenent is family but I suspect  
that is a family of functions and would not increase in size with  
larger models.


Is there anything I can do?  If I want to save several fits, 490 MB a
shot starts to add up very quickly.  If I just save the  
coefficients, I
have to manually hack up an object that I can then run 'predict' on  
when

I want to evaluate the model, and that feels very error-prone.


The predict.glm function is visible so you can just type its name to  
see the code. It appears that the section of the code that does the  
work is fairly short. This is my nomination for what happens in most  
cases:


if (!se.fit) {# not generally invoked with se.fit=TRUE
}
else {
pred - predict.lm(object, newdata, se.fit, scale = 1,
type = ifelse(type == link, response, type),
terms = terms, na.action = na.action)
switch(type, response = {
pred - family(object)$linkinv(pred)
}, link = , terms = )
}

So maybe you should write a predict function that would work on a  
reduced glm object that has a class name of your choosing.


--

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] boundary correction - univariate kernel density estimation

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 12:04 PM, sbillin2 wrote:



Hey,

Does anyone know of a package in R that provides univariate kernel
density estimation with boundary correction ?



What? you don't believe that tunneling occurs at finite barriers?

or how to easily extend an existing bivariate kernel density  
estimation

function (e.g. lambdahat in the spatialkernel package) with boundary
corrections to allow univariate density estimation?


When this question has been (multiply) posed in the past, the  
suggested answer has been to use package logspline.





--

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] a^c(1:3)

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 12:35 PM, Feng Li wrote:


Dear R,

I have two small questions confused me recently. Now assume I have a  
matrix

a, like this,


a - matrix(1:6, 2, 3)
a

[,1] [,2] [,3]
[1,]135
[2,]246

I sometimes need each row of a raised to a different exponent. So  
I do a

trick like this,


a^c(2, 3)

[,1] [,2] [,3]
[1,]19   25
[2,]8   64  216

My first question is that if it is possible to do this trick column  
wise?


Most questions of this sort are answerable by thinking of R matrices  
as folded vectors. The folding occurs columnwise (unlike Matlab), so  
for this problem:



 a^rep(c(2, 3, 4), each=nrow(a)) #  the exponents become 2,2,3,3,4,4
 [,1] [,2] [,3]
[1,]1   27  625
[2,]4   64 1296



or:

 a^matrix(c(2, 3, 4), byrow=TRUE, nrow=2, ncol=3)
 [,1] [,2] [,3]
[1,]1   27  625
[2,]4   64 1296

Just out of curiosity, of course I know there are other ways of  
doing this.


And the second question is why I get such result when I put another  
element

in the exponent part like this,


Because argument recycling makes the exponents 2,3,4,2,3,4 and they  
are applied folded column wise



a^c(2, 3, 4)

[,1] [,2] [,3]
[1,]1   81  125
[2,]8   16 1296



BTW, I have a 64bit R version (2.11) for Linux. Any advice would be
appreciated.



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] remove accents in strings

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 1:35 PM, Matt Shotwell wrote:


If you know the encoding of the string, or if its encoding is the
current locale encoding, then you can use the iconv function to  
convert

the string to ASCII. Something like:

iconv(accented.string, to=ASCII//TRANSLIT)

While 7-bit ASCII does not permit accented characters, extended (8- 
bit)

ASCII does. Hence, I'm not sure this will work. But it's worth a try.


 tst - c(à, è, ì, ò, ù , À, È, Ì, Ò, Ù, á,  
é, í, ó, ú, ý , Á, É, Í, Ó, Ú, Ý)

 iconv(tst, to=ASCII//TRANSLIT)
 [1] `a `e `i `o `u `A `E `I `O `U 'a 'e 'i  
'o 'u 'y

[17] 'A 'E 'I 'O 'U 'Y
 gsub(`|\\', , iconv(tst, to=ASCII//TRANSLIT))
 [1] a e i o u A E I O U a e i o u y  
A E I O

[21] U Y

Notice that the accent acute gets converted to a single quote and  
therefore needs to be dbl-\-ed to get recognized in an R regex pattern.


On a Mac with: locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

--
David.


-Matt

On Tue, 2010-09-07 at 13:04 -0400, lamack lamack wrote:

Dear all, there is a R function to remove all accents in strings?

best regards.

JL



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


--
Matthew S. Shotwell
Graduate Student
Division of Biostatistics and Epidemiology
Medical University of South Carolina

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

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 2:29 PM, Matt Shotwell wrote:


Weird, my (Ubuntu, s don't tell Dirk) iconv doesn't add the
backticks or single quotes.



I don't see any promise in the help page that iconv should substitute  
anything for the accents. It just says each OS may have its own  
behavior and suggest that you are accessing glibc while I am using  
libiconv and warns to expect different results.


--
David.


tst - c(à, è, ì, ò, ù , À, È, Ì, Ò, Ù, á,

+ é, í, ó, ú, ý , Á, É, Í, Ó, Ú, Ý)

iconv(tst, to=ASCII//TRANSLIT)
[1] a e i o u A E I O U a e i o u y  
A

E I
[20] O U Y

By the way, I'll take this moment to remind anyone interested that R
still has trouble with embedded zeros in character strings. I may be
abusing terminology, but I think that makes R 8-bit dirty.

-Matt

On Tue, 2010-09-07 at 14:01 -0400, David Winsemius wrote:

On Sep 7, 2010, at 1:35 PM, Matt Shotwell wrote:


If you know the encoding of the string, or if its encoding is the
current locale encoding, then you can use the iconv function to
convert
the string to ASCII. Something like:

iconv(accented.string, to=ASCII//TRANSLIT)

While 7-bit ASCII does not permit accented characters, extended (8-
bit)
ASCII does. Hence, I'm not sure this will work. But it's worth a  
try.



tst - c(à, è, ì, ò, ù , À, È, Ì, Ò, Ù, á,

é, í, ó, ú, ý , Á, É, Í, Ó, Ú, Ý)

iconv(tst, to=ASCII//TRANSLIT)

 [1] `a `e `i `o `u `A `E `I `O `U 'a 'e 'i
'o 'u 'y
[17] 'A 'E 'I 'O 'U 'Y

gsub(`|\\', , iconv(tst, to=ASCII//TRANSLIT))

 [1] a e i o u A E I O U a e i o u y
A E I O
[21] U Y

Notice that the accent acute gets converted to a single quote and
therefore needs to be dbl-\-ed to get recognized in an R regex  
pattern.


On a Mac with: locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8



--
Matthew S. Shotwell
Graduate Student
Division of Biostatistics and Epidemiology
Medical University of South Carolina



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] Saving fits (glm, nls) without data

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 2:53 PM, Johann Hibschman wrote:


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


On Sep 7, 2010, at 11:02 AM, Johann Hibschman wrote:

Even so, I would prefer to only save the coefficients


Have you read through the Value section of glm's help page?

...and

?coef


I have; it's easy to get the coefficients. The part I'm struggling  
with
is reconstituting an operational glm object given the coefficient  
vector

and the formula.

Really, I was hoping that someone had already done this work, so I  
could

stop trying re-create the right kind of term object, while making sure
it doesn't hold on to a pointer to an environment with a lot of data  
in

it, etc., etc..


I was assuming you could take all the code work that was already  
tested and trim out the non essential code and arguments let it work  
on a new class.



The predict.glm function is visible so you can just type its name to
see the code. It appears that the section of the code that does the
work is fairly short. This is my nomination for what happens in most
cases:



if (!se.fit) {# not generally invoked with se.fit=TRUE

if (missing(newdata)) {  # forgot this clause in first post

   }
   else {
   pred - predict.lm(object, newdata, se.fit, scale = 1,
   type = ifelse(type == link, response, type),
   terms = terms, na.action = na.action)
   switch(type, response = {
   pred - family(object)$linkinv(pred)
   }, link = , terms = )
   }


I agree.  That reduces the problem to confecting a working lm object,
given a formula and coefficients.  Unfortunately, I haven't yet  
figured

out how to do that.


And I was thinking one would start with the glm object and just set  
the unnecessary leaves of the list to NULL.





So maybe you should write a predict function that would work on a
reduced glm object that has a class name of your choosing.


I'm trying to get this to work, but I haven't figured out yet how to
generate the X matrix properly from the formula and the coefficients.
I'm sure I can eventually get it, but it's annoying.


I don't think you need to do anything other than construct a proper  
newdata argument and feed it and your stripped down object to a  
modified predict.sml_glm function. And it could very well be that all  
you need to do is rename the predict.glm code and give it the proper  
arguments. I do not see a need to recreate an X matrix for the  
newdata, since the code to do that is already in predict.lm(). I  
suppose I could be wrong, since I have not done it myself. I just got  
my employer to buy more memory.




The whole model whereby fit objects keep around their data so you  
don't

have to provide it on a few calls just seems like a mistake.

-Johann



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] Saving fits (glm, nls) without data

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 3:16 PM, David Winsemius wrote:



On Sep 7, 2010, at 2:53 PM, Johann Hibschman wrote:


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


On Sep 7, 2010, at 11:02 AM, Johann Hibschman wrote:

Even so, I would prefer to only save the coefficients


Have you read through the Value section of glm's help page?

...and

?coef


I have; it's easy to get the coefficients. The part I'm struggling  
with
is reconstituting an operational glm object given the coefficient  
vector

and the formula.

Really, I was hoping that someone had already done this work, so I  
could
stop trying re-create the right kind of term object, while making  
sure
it doesn't hold on to a pointer to an environment with a lot of  
data in

it, etc., etc..


I was assuming you could take all the code work that was already  
tested and trim out the non essential code and arguments let it work  
on a new class.




Just tested my theory and it seems to be holding up. Took the example  
on the predict help page, set three of the variable length components  
not needed in the predict operations to NULL and the code still runs  
fine. It does not appear that either predict.glm or predict.lm check  
to see if there are any missing components:


 ldose - rep(0:5, 2)
 numdead - c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16)
 sex - factor(rep(c(M, F), c(6, 6)))
 SF - cbind(numdead, numalive=20-numdead)
 budworm.lg - glm(SF ~ sex*ldose, family=binomial)
 budworm.lg[residuals] - NULL
 budworm.lg[linear.predictors] - NULL
 budworm.lg[fitted.values] - NULL
 plot(c(1,32), c(0,1), type = n, xlab = dose,
+  ylab = prob, log = x)
 text(2^ldose, numdead/20, as.character(sex))
 ld - seq(0, 5, 0.1)
 lines(2^ld, predict(budworm.lg, data.frame(ldose=ld,
+sex=factor(rep(M, length(ld)), levels=levels(sex))),
+type = response))

Also took out y, qr, weights, and prior.weights
 budworm.lg[y] - NULL
 budworm.lg[weights] - NULL
 budworm.lg[prior.weights] - NULL
 budworm.lg[qr] - NULL
... And it continue to perform without throwing an error.

--

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] Help with decimal points

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 4:38 PM, Amit Patel wrote:

I have found a little problem with an R script. I am trying to merge  
some data
and am finding something unusual going on. As shown below I am  
trying to
assign (MatchedValues[Value2,Value]) to  (ClusteredData[k,Value])  
which are two

separate dataframes.

1) By the following command you can see that the value im transferring
is 481844.03


MatchedValues[Value2,Value]

[1] 481844.03
6618 Levels: 1.00E+07 1.01E+07 1.02E+07 1.04E+07 1.05E+07 1.06E 
+07 ... Raw


This shows you that MatchValues' column eval(Value) is a factor  
represented internally by one of 6618 integers with various level  
labels. The label of the item in row eval(Value2) is 481844.03. The  
label is a character object.




2) But when I try to replace the values using the command i get a  
value of 4420



ClusteredData[k,Value] - MatchedValues[Value2,Value]



ClusteredData[k,Value]

[1] 4420


3) So what am I not doing. How can I keep that same value of 481844.03
I have tried


Read FAQ 7.10:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f

--
David.




as.double(MatchedValues[Value2,Value])

[1] 4420


as.numeric(MatchedValues[Value2,Value])

[1] 4420


--

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] change the for loops with lapply

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 5:43 PM, Changbin Du wrote:


cv.fold-function(i, size=3, rang=0.3){
  cat('Fold ', i, '\n')
  out.fold.c -((i-1)*c.each.part +1):(i*c.each.part)
  out.fold.n -((i-1)*n.each.part +1):(i*n.each.part)

 train.cv - n.cc[-out.fold.c, c(2:2401, 2417)]
  train.nv - n.nn[-out.fold.n, c(2:2401, 2417)]

  train.v-rbind(train.cv, train.nv) #training data for feature
selection

   # grow tree
fit.dimer - rpart(as.factor(out) ~ ., method=class, data=train.v)
at-grep(leaf, fit.dimer$frame[, var], value=FALSE,  
ignore.case=TRUE)

varr-as.character(unique(fit.dimer$frame[-at, var]))

  train.cc - n.cc[-out.fold.c,]
  valid.cc - n.cc[out.fold.c,]

  train.nn - n.nn[-out.fold.n,]
  valid.nn - n.nn[out.fold.n,]

  train-rbind(train.cc, train.nn) #training data
  valid-rbind(valid.cc, valid.nn) # validation data

#creat data set contains the following variables
myvar-names(gh9_h) %in% c(varr, out)

  train-train[myvar] # update training set
  valid-valid[myvar]

nnet.fit-nnet(as.factor(out) ~ ., data=train,  size=size, rang=rang,
decay=5e-4, maxit=500)  # model fitting

  #get the validation error
mc-table(valid$out, predict(nnet.fit, valid, type=class))  
#confusion

matrix

  fp-mc[1,2]/sum(mc[1,]) #false positive
  fn- mc[2,1]/sum(mc[2,]) #false negative
 accuracy.r-1-(mc[1,2]+mc[2,1])/sum(mc) #total accuracy rate

return(c(fp, fn, accuracy.r))

  }

result.fun - lapply(1:2, cv.fold(i, size=5, rang=0.3))

I got the following error message:

*Error in match.fun(FUN) :
 'cv.fold(i, size = 5, rang = 0.3)' is not a function, character or  
symbol


Generally when one is passing an atomic vector argument to a function  
one would use sapply (but it may be a distinction withou a difference  
here.) ... and furthermore the additional arguments would be given as  
named constants:


?sapply

Perhaps (untested):

 result.fun - sapply(1:2, cv.fold, size=5, rang=0.3))

or perhaps:

result.fun - sapply(1:2, function(i) cv.fold(i, size=5, rang=0.3))


As always the provision of a working example, perhaps even from one of  
the help pages, would allow testing, and it's always good manners to  
specify which package has non-base functions:


 ?n.cc
No documentation for 'n.cc' in specified packages and libraries:
you could try '??n.cc'
 ?rpart
No documentation for 'rpart' in specified packages and libraries:
you could try '??rpart'
 ?train
No documentation for 'train' in specified packages and libraries:
you could try '??train'

(I have suspicions which packages they come from, but one never  
knows)


--
David.




I do want to change the size and rang parameters some time.

*
Can anyone help me this this?  Thanks so much!


--
Sincerely,
Changbin



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] problem with max in a function

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 9:06 PM, stephen sefick wrote:


s - 1.00
max(s)


 sprintf(%.2f, max(s))
[1] 1.00 @ as a string/character object


returns 1

is there anyway that I can get it to return 1.00.  I am using the
results of this max statement in a grep statement and it returns the
wrong numbers,  I will provide more information and code if it would
make more sense in context.

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

A big computer, a complex algorithm and a long time does not equal  
science.


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

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 7:51 PM, lord12 wrote:



For each arima model, can you output an associated confidence  
interval for

the predicted value at each time point?


?arima0

arima0 will return ... a list with components pred, the  
predictions, and se, the estimated standard errors as time series  
when se.fit = TRUE.

--
View this message in context: 
http://r.789695.n4.nabble.com/R-time-series-analysis-tp2527513p2530595.html

--

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] multiple graphs

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 8:02 PM, moleps wrote:


Dear all,

I´m trying to create multiple graphs on the same page, but they are  
all stacked on top of each other.


My code:


par(mfrow=c(2,2))
a-list(levels(bar$h.r)[c(1,3,6)])
print(a)

lapply(a,function(x){
a-subset(bar,h.r==x)
with(a, cdplot(wh~Age,ylab=x))
#plot.new()
})

The plot.new command doesnt help...

Any ideas??


?layout  # assuming that the undescribed plotting function is base  
graphics. Some plotting functions are hard coded and are able to  
defeat the usual formatting options.


--
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] R time series analysis

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 9:33 PM, David Winsemius wrote:



On Sep 7, 2010, at 7:51 PM, lord12 wrote:



For each arima model, can you output an associated confidence  
interval for

the predicted value at each time point?


?arima0

arima0 will return ... a list with components pred, the  
predictions, and se, the estimated standard errors as time series  
when se.fit = TRUE.


See also:

predict.Arima {stats}


--
View this message in context: 
http://r.789695.n4.nabble.com/R-time-series-analysis-tp2527513p2530595.html

--

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
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem with max in a function

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 9:37 PM, stephen sefick wrote:


Here is a striped down example that is not working


That dreadful phrase... is not working. When the ESP package comes  
to fruition, life will be so easy. Until then ... the English language  
is necessary. Where am we supposed to be looking. Did I miss you  
saying which of those (unprinted) objects we should be fixing.



because of the 1.00
to 1.  Any help would be greatly appreciated.

measure_bkf - (structure(list(measurment_num = c(0, 0.2, 0.4, 0.6,
0.8, 1, 1.2,
1.4, 1.6, 1.8, 2, 2.2, 2.2, 2.4, 2.6, 2.8), bankfull_depths_m =  
c(-0.15,

-0.09, -0.00998, 0.06, 0.13, 0.26, 0.36, 0.46, 0.56,
0.61, 0.85, 0.93, 0.93, 0.97, 1, 1)), .Names = c(measurment_num,
bankfull_depths_m), row.names = c(32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 29L, 12L, 13L, 14L), class = data.frame))



measure_bkf_not_zero - measure_bkf[grep([^0],
measure_bkf[,bankfull_depths_m]),]

bkf_min - grep(min(measure_bkf_not_zero[,bankfull_depths_m]),
measure_bkf_not_zero[,bankfull_depths_m])

bkf_max - grep(max(measure_bkf_not_zero[,bankfull_depths_m]),
measure_bkf_not_zero[,bankfull_depths_m])

bkf_min - ifelse(length(bkf_min)1, bkf_min[1], bkf_min)
bkf_max - ifelse(length(bkf_max)1, bkf_max[1], bkf_max)

#s - with(measure_bkf_not_zero, approx(measurment_num,
bankfull_depths_m,
xout=seq(measure_bkf_not_zero[bkf_min,measurment_num],
measure_bkf_not_zero[bkf_max,measurment_num], length=2000)))
#int_bkf - with(s, x[which.min(y[y0])])

s - with(measure_bkf_not_zero[bkf_min:bkf_max,],
approxfun(bankfull_depths_m, measurment_num), ties=mean)

int_bkf - s(0)



On Tue, Sep 7, 2010 at 8:28 PM, David Winsemius dwinsem...@comcast.net 
 wrote:


On Sep 7, 2010, at 9:06 PM, stephen sefick wrote:


s - 1.00
max(s)



sprintf(%.2f, max(s))

[1] 1.00 @ as a string/character object


returns 1

is there anyway that I can get it to return 1.00.  I am using the
results of this max statement in a grep statement and it returns the
wrong numbers,  I will provide more information and code if it would
make more sense in context.

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

A big computer, a complex algorithm and a long time does not equal
science.

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






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

A big computer, a complex algorithm and a long time does not equal  
science.


  -Robert Gentleman


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] problem with max in a function

2010-09-07 Thread David Winsemius


On Sep 7, 2010, at 10:05 PM, stephen sefick wrote:


I'm sorry.  In the

bkf_max - grep(max(measure_bkf_not_zero[,bankfull_depths_m]),
measure_bkf_not_zero[,bankfull_depths_m])

it is giving the indexes for 1 5 10 15 16


And it was supposed to yield ... what?


I think this is because grep encounters a 1 with either 0.


Huh?


or nothing
in front of it.  I would like to find the max and then then the
closest (leftmost) which is why the ifelse statment follows.


grep is for working with character vectors. It seems to work when  
given numerics as patterns, but with floating point representations it  
seems really dangerous. I'm rather amazed you got anything vaguely  
useful. (And see further negative comments on that strategy below.)   
If you want the max of a numeric vector, then use max or which.max if  
you want the index. If you want the next largest then use max( vector[- 
which.max(vector)] ). So as Jim Holtman's tag line says: what problem  
are you trying to solve?





Again, I am sorry for being vague.  I get wrapped up in a problem and
forget that I need to communicate.

kindest regards,

Stephen

On Tue, Sep 7, 2010 at 8:48 PM, David Winsemius dwinsem...@comcast.net 
 wrote:


On Sep 7, 2010, at 9:37 PM, stephen sefick wrote:


Here is a striped down example that is not working


That dreadful phrase... is not working. When the ESP package  
comes to
fruition, life will be so easy. Until then ... the English language  
is
necessary. Where am we supposed to be looking. Did I miss you  
saying which

of those (unprinted) objects we should be fixing.


because of the 1.00
to 1.  Any help would be greatly appreciated.

measure_bkf - (structure(list(measurment_num = c(0, 0.2, 0.4, 0.6,
0.8, 1, 1.2,
1.4, 1.6, 1.8, 2, 2.2, 2.2, 2.4, 2.6, 2.8), bankfull_depths_m =  
c(-0.15,

-0.09, -0.00998, 0.06, 0.13, 0.26, 0.36, 0.46, 0.56,
0.61, 0.85, 0.93, 0.93, 0.97, 1, 1)), .Names = c(measurment_num,
bankfull_depths_m), row.names = c(32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 29L, 12L, 13L, 14L), class =  
data.frame))




measure_bkf_not_zero - measure_bkf[grep([^0],
measure_bkf[,bankfull_depths_m]),]


You have constructed an odd pattern with the square brackets around  
caret-zero. Per the regex page: A character class is a list of  
characters enclosed between [ and ] which matches any single character  
in that list; unless the first character of the list is the caret ^,  
when it matches any character not in the list You are trying to find  
any number with a non-zero in a numeric vector? That seems to be what  
happened.





bkf_min - grep(min(measure_bkf_not_zero[,bankfull_depths_m]),
measure_bkf_not_zero[,bankfull_depths_m])

bkf_max - grep(max(measure_bkf_not_zero[,bankfull_depths_m]),
measure_bkf_not_zero[,bankfull_depths_m])

bkf_min - ifelse(length(bkf_min)1, bkf_min[1], bkf_min)
bkf_max - ifelse(length(bkf_max)1, bkf_max[1], bkf_max)

#s - with(measure_bkf_not_zero, approx(measurment_num,
bankfull_depths_m,
xout=seq(measure_bkf_not_zero[bkf_min,measurment_num],
measure_bkf_not_zero[bkf_max,measurment_num], length=2000)))
#int_bkf - with(s, x[which.min(y[y0])])

s - with(measure_bkf_not_zero[bkf_min:bkf_max,],
approxfun(bankfull_depths_m, measurment_num), ties=mean)

int_bkf - s(0)



On Tue, Sep 7, 2010 at 8:28 PM, David Winsemius dwinsem...@comcast.net 


wrote:


On Sep 7, 2010, at 9:06 PM, stephen sefick wrote:


s - 1.00
max(s)



sprintf(%.2f, max(s))


[1] 1.00 @ as a string/character object


returns 1

is there anyway that I can get it to return 1.00.  I am using the
results of this max statement in a grep statement and it returns  
the
wrong numbers,  I will provide more information and code if it  
would

make more sense in context.

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

A big computer, a complex algorithm and a long time does not  
equal

science.

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

Re: [R] Regression using mapply?

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 7:34 AM, Philipp Kunze wrote:


Hi,
I have huge matrices in which the response variable is in the first
column and the regressors are in the other columns. What I wanted to  
do

now is something like this:

#this is just to get an example-matrix
DataMatrix - rep(1,1000);
Disturbance - rnorm(900);
DataMatrix[101:1000] - DataMatrix[101:1000]+Disturbance;
DataMatrix - matrix(DataMatrix,ncol=10,nrow=100);

#estimate univariate linear model with each regressor-column, response
in the first column

for(i in 2:10){
result - lm(DataMatrix[,1]~DataMatrix[,i])
}


result - apply(DataMatrix[,2:10], 2, function (x) lm(DataMatrix[, 
1]~x) )


Which would have the added advantage that result would not be  
overwritten for iterations 3:10, which is what your code would have  
done. result will be a list of 9 models which might be a bit  
unweildy, so you might consider something like


result - apply(DataMatrix[,2:10], 2, function (x)  
coef( lm(DataMatrix[,1]~x) ) )

result

When you do so,  you uncover a fatal flaw in your strategy, which  
suggests you have not even done this once on your data or simulations.


--
David.



Is there any way to get rid of the for-loop using mapply (or some  
other

function)?

--
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] How to change font size in plot() function

2010-09-08 Thread David Winsemius

That is one method, but he should also review:

?par

where he will discover that cex.main is a parameter that could be used  
from within the plot function.



FMH had written, by Peng, C had failed to include context:


Could someone please advice me the way to change the size of the  
title and x and
y-label in plot() function. I've tried to use 'font' and  
'font.main' call in

plot() function, but it didn't make any changes in terms of the size.


On Sep 8, 2010, at 7:46 AM, Peng, C wrote:



try:

?title
--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-change-font-size-in-plot-function-tp2531127p2531161.html
Sent from the R help mailing list archive at Nabble.com.


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] Checking if the distribution follow a power law

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 10:34 AM, NatsumiYotsumoto wrote:


Dear all.


I'm using igraph package, and do a research about network analysis.

With power.law.fit from igraph package, it seems that we can fit a  
power law

distribution to some data.


But, I want to know how to judge whether the network distribution  
follows a

power law or not.


In order to determine whether something is from distribution A or not- 
A, one needs to have a sensible way of characterizing or considering  
what would be in the range of distributions in the not-A.  
Unfortunately for your question, the range of possible distributions  
is infinite. That means it would always be possible to have a better  
fitting distribution than what ever is distribution A.  If you have  
alternatives to the power-law that you want to put to the test, then  
now is the time to offer them.


My guess is that you do not, so I will offer alternatives:

Alt A:
a) read the citations in the email you cited, especially Newman then ...
b) set up a histogram of your data using hist with logarithmic or  
geometric progression of the breaks argument.
c) as a check on you exponent estimate, calculate alpha and se(alpha)  
as on pg 4-5 of that citation.


Alt B:
require(sos)
???fitting pareto
???fitting power network   # and proceed from there

--
David.


Does anyone know the way to do this?

Thanks for any help.

Daigo

p.s.

Also,  I tried several ways such as

http://www.mail-archive.com/r-h...@stat.math.ethz.ch/msg62520.html

and I got results like this:

Profiling...

  2.5 %   97.5 %

2.393297 2.412650

What do these suggest?

please tell me about this if someone knows.


--

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] try-error can not be test. Why?

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 1:18 PM, telm8 wrote:



Hi,

I am having some strange problem with detecting try-error. From  
what I

have read so far the following statement:


try( log(a) ) == try-error


should yield TRUE, however, it yields FALSE. I can not figure out  
why. Can

someone help?



 class(try( log(a), silent=TRUE )) == try-error
[1] TRUE





Many thanks
--
View this message in context: 
http://r.789695.n4.nabble.com/try-error-can-not-be-test-Why-tp2531675p2531675.html
Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
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] Replace NAs in one column with data from another column

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 2:24 PM, Joshua Wiley wrote:


Hi Jakob,

You can use is.na() to create an index of which rows in column 3 are
missing data, and then select these from column 1.  Here is a simple
example:

dat - data.frame(V1 = 1:5, V3 = c(1, NA, 3, 4,  NA))
dat$new - dat$V3
my.na - is.na(dat$V3)
dat$new[my.na] - dat$V1[my.na]

dat

This should be quite fast.  I broke the steps up to be explicit, but
you can readily simplify them.


I was about to post something similar except I was going to avoid the  
$ operator thinking, incorrectly as it turned out, that it would be  
faster. I also include the Holtman/Rizopoulos suggestion of ifelse().  
I was also surprised that ifelse is the winning strategy:


dat[4] - dat[3]; idx -is.na(dat[, 3])
dat[is.na(dat[, 3]), 4] - dat[is.na(dat[, 3]), 1]

 benchmark(meth.ifelse = {dat$z.new - ifelse(is.na(dat$V3), dat$V1,  
dat$V3)},

+  meth.dlr.sign={dat$new - dat$V3
+  my.na - is.na(dat$V3)
+  dat$new[my.na] - dat$V1[my.na]},
+  meth.index ={dat[4] - dat[3]; idx -is.na(dat[, 3])
+  dat[idx, 4] - dat[idx, 1]},
+ meth.forloop ={for (i in 1:nrow(dat)){
+ if (is.na(dat[i,3])==TRUE){
+ dat[i,4]- dat[i,1]}
+ else{
+ dat[i,4]- dat[i,3]} }
+ },
+ replications=5000, columns = c(test, replications, elapsed,
+  relative, user.self) )
   test replications elapsed  relative user.self
2 meth.dlr.sign 5000   0.502  1.081897 0.501
4  meth.forloop 5000   6.419 13.834052 6.409
1   meth.ifelse 5000   0.464  1.00 0.463
3meth.index 5000   2.908  6.267241 2.904

--
David.


HTH,

Josh

On Wed, Sep 8, 2010 at 11:17 AM, Jakob Hedegaard
jakob.hedega...@agrsci.dk wrote:

Hi list,

I have a data frame (m) with 169221 rows and 10 columns and would  
like to make a new column containing the content of column 3 but  
replace the NAs in column 3 with the data in column 1 (from the  
same row as the NA in column 3). Column 1 has data in all rows.


My first attempt was:

for (i in 1:169221){
if (is.na(m[i,3])==TRUE){
m[i,11] - as.character(m[i,1])}
else{
m[i,11] - as.character(m[i,3])}
}

Works - but takes too long time.
I would appreciate alternative solutions.

Best regards, Jakob



--

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] subbing a string vector for another string vector

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 4:45 PM, jlemaitre wrote:



I have a data frame with two columns:
  url.img   patt.url
1http://$IMAGE_ID$www.url.com/image.jpg
2$IMAGE_ID$  http://www.blah.com/image.gif
...

I want to replace $IMAGE_ID$ with the corresponding entry in the  
pattern

column such that the result would appear as follows:


A) Drop the use of the name pattern because it is the argument name  
for regex functions. Name it something else like patt.url.  
Furthermore image is also a function name so use somehting more  
specific there too, say url.img


B) use grep(grep-pattern, df$url.img) to identify the rows of  
patt.url you want to assemble.


Perhaps:

df[ grep(\\$IMAGE\\_ID\\$, df$url.img), patt.url]




url
http://www.url.com/image.jpg
http://www.blah.com/image.gif

Using something like   gsub(,image,pattern) doesn't work
because it only takes uses the first entry in pattern as the  
replacement

for all image entries:

url
http://www.url.com/image.jpg
www.url.com/image.jpg

Please help.
Thanks.




--
View this message in context: 
http://r.789695.n4.nabble.com/subbing-a-string-vector-for-another-string-vector-tp2532005p2532005.html
Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
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] Newbie cross tabulation issue

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 6:40 PM, Jonathan Finlay wrote:

hi, i'm new in R and i need some help. Please, ¿do you know a  
function how
can process cross tables for many variables and show the result in  
one table

who look like this?:

++
|-- |X variable   |
|- | Xop1 | Xop2 | Xop3|.|
++
|Yvar1 | Total | %row..|
| |  Op1 |  %row..|
| |  Op2 |  %row..|
|+---+
|Yvar2 | Op1 |  %row..|
| | Op2 |  %row...|
++
|Yvar3 | Op1 |  %row..|
| | Op2 |  %row...|
| | Op3 |  %row...|
|+---+

Like a pivot table!



?table
?xtabs

... and if you want all those dashes, dots, pluses and pipes   
cluttering up your output a la SAS, then there is:


gmodels::Crosstable

--
David.


thanks a lot.

--
Jonathan.

[[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] coxph and ordinal variables?

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 6:43 PM, Min-Han Tan wrote:


Dear R-help members,

Apologies - I am posting on behalf of a colleague, who is a little  
puzzled
as STATA and R seem to be yielding different survival estimates for  
the same
dataset when treating a variable as ordinal. Ordered() is used  to  
represent
an ordinal variable) I understand that R's coxph (by default) uses  
the Efron

approximation, whereas STATA uses (by default) the Breslow. but we did
compare using the same approximations. I am wondering if this is a  
result of

how coxph manages an ordered factor?

Essentially, this is a survival dataset using tumor grade (1, 2, 3  
and 4) as

the risk factor. This is more of an 'ordinal' variable, rather than a
continuous variable. For the same data set of 399 patients, when  
treating

the vector of tumor grade as a continuous variable (range of 1 to 4),
testing the Efron and the Breslow approximations yield the same  
result in

both R and STATA.

However, when Hist_Grade_4 grp is converted into an ordered factor  
using
ordered(), and the same scripts are applied, rather different  
results are
obtained, relative to the STATA output. This is tested across the  
different

approximations, with consistent results. The comparison using Efron
approximation and ordinal data is is below.


Are you sure you want an ordered factor? In R this means you will be  
creating linear, quadratic and cubic contrasts. Notice the L, Q and C  
designations on the coefficients. That certainly does not look to be  
comparable to what you are getting from Stata. My suggestion would be  
to create an un-ordered factor in R and see whether you get results  
more in line with Stata's output when applied to your data.


--
David.


Your advice is very much appreciated!

Min-Han

Apologies below for the slightly malaligned output.

STATA output

. xi:stcox i.Hist_Grade_4grp, efr
i.Hist_Grade_~p   _IHist_Grad_1-4 (naturally coded; _IHist_Grad_1
omitted)

   failure _d:  FFR_censor
 analysis time _t:  FFR_month

Iteration 0:   log likelihood =  -1133.369
Iteration 1:   log likelihood = -1129.4686
Iteration 2:   log likelihood = -1129.3196
Iteration 3:   log likelihood = -1129.3191
Refining estimates:
Iteration 0:   log likelihood = -1129.3191

Cox regression -- Efron method for ties

No. of subjects =  399 Number of obs   =
399
No. of failures =  218
Time at risk=  9004.484606
 LR chi2(3)  =
8.10
Log likelihood  =   -1129.3191 Prob  chi2 =
0.0440

--
_t | Haz. Ratio   Std. Err.  zP|z| [95% Conf.
Interval]
- 
+

_IHist_Gra~2 |   1.408166   .3166876 1.52   0.128 .9062001
2.188183
_IHist_Gra~3 |1.69506   .3886792 2.30   0.021 1.081443
2.656847
_IHist_Gra~4 |   2.540278   .9997843 2.37   0.018  1.17455
5.49403



R Output using

summary ( coxph( Surv(FFR_month,FFR_censor) ~ Hist_Grade_4grp,

method=c(breslow)))

summary ( coxph( Surv(FFR_month,FFR_censor) ~ Hist_Grade_4grp,

method=c(exact)))

summary ( coxph( Surv(FFR_month,FFR_censor) ~ Hist_Grade_4grp,

method=c(efron)))



n=399 (21 observations deleted due to missingness)

   coef exp(coef) se(coef) z Pr(|z|)
Hist_Grade_4grp.L 0.66685   1.94809  0.26644 2.503   0.0123 *
Hist_Grade_4grp.Q 0.03113   1.03162  0.20842 0.149   0.8813
Hist_Grade_4grp.C 0.08407   1.08771  0.13233 0.635   0.5252
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

exp(coef) exp(-coef) lower .95 upper .95
Hist_Grade_4grp.L 1.948 0.51331.1556 3.284
Hist_Grade_4grp.Q 1.032 0.96930.6857 1.552
Hist_Grade_4grp.C 1.088 0.91940.8392 1.410

Rsquare= 0.02   (max possible= 0.997 )
Likelihood ratio test= 8.1  on 3 df,   p=0.044
Wald test= 8.02  on 3 df,   p=0.0455
Score (logrank) test = 8.2  on 3 df,   p=0.04202

[[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] Newbie cross tabulation issue

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 7:32 PM, Jonathan Finlay wrote:

Thanks David, gmodels::Crosstable partially work because can show  
only 1 x 1

tablen
CrossTable(x,y,...)
I need something how can process at less 1 variable in X an 10 in Y.


I hope you mean only two factors and an n x m table.



Thanks for your help.


--
Jonathan.

[[alternative HTML version deleted]]

--

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] problem with outer

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 6:59 PM, tuggi wrote:



hello,

tank you very very much. it solves my first problem. i hope you can  
help me

also with the second problem.
it was like this.


p_11=seq(0,1,0.1)
p_12=seq(0,1,0.1)
then i get also this error message:
Error in rmultinom(n - q + 1, size = 1, prob = rbind(p_11, p_12, (1  
-  :

 non-positive probability


It seems to be a very informative error message. The first element of  
seq(0,1,0.1) is going to be zero and rmultinom doesn't accept non-zero  
probabilities. If you would explain what you _were_ trying to  
accomplish it might be possible to say more, but without some  
explication we would be stumbling around in the dark. Furthermore I  
wonder whether you really meant to offer a matrix to rmultinom for  
probabilities? The help page says prob should be a vector.


OK, I will stumble around:
If you want one random draw one one item from into n-q+1 equally  
probable bins, then wouldn't you use:


rmultinom(n - q + 1, size = 1, prob = rep(0.1, 10) )
 rmultinom(1, size = 1, prob = rep(0.1, 10) )
  [,1]
 [1,]0
 [2,]0
 [3,]0
 [4,]0
 [5,]0
 [6,]0
 [7,]0
 [8,]0
 [9,]1
[10,]0

If you want 10 draws:

  rmultinom(10, size = 1, prob = rep(0.1, 10) )
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]100000000 1
 [2,]000000000 0
 [3,]011000000 0
 [4,]000100000 0
 [5,]000000001 0
 [6,]000000000 0
 [7,]000011000 0
 [8,]000000100 0
 [9,]000000010 0
[10,]000000000 0

And if you want 1 sample of 100 items:
  rmultinom(1, size = 100, prob = rep(0.1, 10) )
  [,1]
 [1,]   10
 [2,]   10
 [3,]   12
 [4,]   12
 [5,]8
 [6,]   11
 [7,]9
 [8,]6
 [9,]7
[10,]   15

But as I said that's a WAG at where you might be having problems.

--
David.



i try to solve this problem with a if  order like this:

p_11=seq(0,1,0.1)
p_12=seq(0,1,0.1)
guete = function(p_11,p_12) { if(p_11+p_121)
set.seed(1000)
S_vek=matrix(0,nrow=N,ncol=1)
for(i in 1:N) {
X_0=rmultinom(q-1,size=1,prob=p_0)
X_1=rmultinom(n-q+1,size=1,prob=cbind(p_11,p_12,(1-p_11-p_12)))
N_0=apply(X_0[,(n-2*k-L+1):(n-k-L)],1,sum)
N_1=apply(X_1[,(n-q-k+2):(n-q+1)],1,sum)
S_vek[i]=((sum(((N_1-k*cbind(p_11,p_12,(1-p_11-p_12)))^2)/ 
k*cbind(p_11,p_12,(1-p_11-p_12/(sum(((N_0-k*p_0)^2)/k*p_0)))-1

}
1-mean(f_1=S_vek  S_vek =f_2)
}


f=outer(p_11,p_12,Vectorize(guete))

but i get the error message:
Error  in rmultinom(n - q + 1, size = 1, prob = cbind(p_11, p_12, (1  
-  :

 non-positive probability.

thank for your helps.
Tuggi


--
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532157.html
Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
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] on error execute:

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 7:37 PM, jcress410 wrote:



So, i've been writing code in R interfacing with mysql, its been fun  
and the

documentation has been useful, learning quite a bit.

the only annoying thing i've been encountering is while coding/ 
debugging, my
session gets clogged, especially with sql connections.  At the end  
of the
code i dbDisconnect, but when the script is stopped by an error, the  
session

stays open.

Usually i'll remember to ls() and dbDisconnect at console manually,  
though,

sometimes I forget and wind up with a bunch of extra connections.

A couple of questions:

First: is there a way to tell R to execute some commands before  
dumping back

to console on error,


?options

error:
	either a function or an expression governing the handling of non- 
catastrophic errors  snipped rest of paragraph


and/or

second: is there a way to capture error messages and continue  
executing?


?try



Sorry if this has been addressed already, but, even aided by the new  
awesome

google i haven't been able to find it.
--



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] try-error can not be test. Why?

2010-09-08 Thread David Winsemius


On Sep 8, 2010, at 11:46 PM, Philippe Grosjean wrote:


On 08/09/10 19:25, David Winsemius wrote:


On Sep 8, 2010, at 1:18 PM, telm8 wrote:



Hi,

I am having some strange problem with detecting try-error. From  
what I

have read so far the following statement:


try( log(a) ) == try-error


should yield TRUE, however, it yields FALSE. I can not figure out  
why.

Can
someone help?



 class(try( log(a), silent=TRUE )) == try-error
[1] TRUE


This is perfectly correct in this case, but while we are mentioning  
a test on the class of an object, the better syntax is:


 inherits(try(log(a)), try-error)

In a more general context, class may be defined with multiple  
strings (R way of subclassing S3 objects). For instance, this does  
not work:


 if (class(Sys.time()) == POSIXct) ok else not ok

... because the class of a `POSIXct' object is defined as:  
c(POSIXt, POSIXct). This works:


 if (inherits(Sys.time(), POSIXct)) ok else not ok

Alternate valid tests would be (but a little bit less readable):

 if (any(class(Sys.time()) == POSIXct)) ok else not ok

or, by installing the operators package, a less conventional, but  
cleaner code:


 install.packages(operators)
 library(operators)
 if (Sys.time() %of% POSIXct) ok else not ok


I have also used if (try-error %in% class(try(log(a))) ) { } else  
{ }, but the inherits() form looks at the very least less clunky.




Best,

Philippe Grosjean


Many thanks
--
View this message in context:
http://r.789695.n4.nabble.com/try-error-can-not-be-test-Why-tp2531675p2531675.html

Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Determine Bounds of Current Graph

2010-09-09 Thread David Winsemius


On Sep 9, 2010, at 10:07 AM, Isamoor wrote:

I'm having trouble determining the bounds of my current graph.  I  
know how
to set the bounds up front (ylim  xlim in most cases), but I would  
rather

be able to dynamically see what was chosen to use in later code.

Example:

library(maps)
map('state','Indiana')
map.axes()


?par

 bounds - par(usr)
 bounds
[1] -88.12964 -84.77184  37.74583  41.82082


??Something that lets me know the y-axis is from ~38 to ~42 and  
store this

information into a vector

Is there some way to query what the bounds of the current graph are?

Thanks!



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] Calculating with tolerances (error propagation)

2010-09-09 Thread David Winsemius


On Sep 9, 2010, at 6:50 AM, Jan private wrote:


Hello Bernardo,

-
If I understood  your problem this script solve your problem:

q-0.15 + c(-.1,0,.1)
h-10 + c(-.1,0,.1)
5*q*h
[1]  2.475  7.500 12.625
-

OK, this solves the simple example.
But what if the example is not that simple. E.g.

P = 5 * q/h

Here, to get the maximum tolerances for P, we need to divide the  
maximum
value for q by the minimum value for h, and vice versa. Is there any  
way

to do this automatically, without thinking about every single step?

There is a thing called interval arithmetic (I saw it as an Octave
package) which would do something like this.

I would have thought that tracking how a (measuring) error propagates
through a complex calculation would be a standard problem of
statistics?? In other words, I am looking for a data type which is a
number with a deviation +- somehow attached to it, with binary  
operators

that automatically knows how to handle the deviation.

Thank you,  
Jan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Calculating with tolerances (error propagation)

2010-09-09 Thread David Winsemius


On Sep 9, 2010, at 6:50 AM, Jan private wrote:


Hello Bernardo,

-
If I understood  your problem this script solve your problem:

q-0.15 + c(-.1,0,.1)
h-10 + c(-.1,0,.1)
5*q*h
[1]  2.475  7.500 12.625
-

OK, this solves the simple example.
But what if the example is not that simple. E.g.

P = 5 * q/h

Here, to get the maximum tolerances for P, we need to divide the  
maximum

value for q by the minimum value for h, and vice versa.


Have you considered the division by zero problems?


Is there any way
to do this automatically, without thinking about every single step?

There is a thing called interval arithmetic (I saw it as an Octave
package) which would do something like this.


(Sorry for the blank reply posting. Serum caffeine has not yet reached  
optimal levels.)


Is it possible that interval arithmetic would produce statistically  
incorrect tolerance calculation, and that be why it has not been added  
to R? Those tolerance intervals are presumably some sort of  
(unspecified) prediction intervals (i.e. contain 95% or 63% or some  
fraction of a large sample) and combinations under mathematical  
operations are not going to be properly derived by c( min(XY),  
max(XY) ) since those are not calculated with any understanding of  
combining variances of functions on random variables.


--
David.


I would have thought that tracking how a (measuring) error propagates
through a complex calculation would be a standard problem of
statistics??


In probability theory, anyway.


In other words, I am looking for a data type which is a
number with a deviation +- somehow attached to it, with binary  
operators

that automatically knows how to handle the deviation.


There is the suite of packages that represent theoretic random  
variables and support mathematical operations on them.


See distrDoc and the rest of that suite.

--
David.


Thank you,  
Jan

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

2010-09-09 Thread David Winsemius


On Sep 8, 2010, at 7:32 PM, Jonathan Finlay wrote:

Thanks David, gmodels::Crosstable partially work because can show  
only 1 x 1

tablen
CrossTable(x,y,...)
I need something how can process at less 1 variable in X an 10 in Y.


A further thought (despite a lack of clarification on what your data  
situation really is.). The strong tendency in R is not to attempt  
replication of formats in SAS that were developed in an era of dot- 
matrix printers, but to target modern output devices. As such most of  
the table output facilities with any degree of sophistication have  
LaTeX or HTML as targets.


RSiteSearch(html tables) produces over 1000 links although they have  
many that are not for multiway tables where multi is greater than R  
x C. RSiteSearch(latex tables) produces many fewer.  You may want to  
look at xtable, Sweave, odfWeave, the various HTML utilities, and  
Harrell's Hmisc::summary.formula


--

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] Newbie cross tabulation issue

2010-09-09 Thread David Winsemius


On Sep 9, 2010, at 11:20 AM, David Winsemius wrote:



On Sep 8, 2010, at 7:32 PM, Jonathan Finlay wrote:

Thanks David, gmodels::Crosstable partially work because can show  
only 1 x 1

tablen
CrossTable(x,y,...)
I need something how can process at less 1 variable in X an 10 in Y.


A further thought (despite a lack of clarification on what your data  
situation really is.). The strong tendency in R is not to attempt  
replication of formats in SAS that were developed in an era of dot- 
matrix printers, but to target modern output devices. As such most  
of the table output facilities with any degree of sophistication  
have LaTeX or HTML as targets.


RSiteSearch(html tables) produces over 1000 links although they  
have many that are not for multiway tables where multi is greater  
than R x C. RSiteSearch(latex tables) produces many fewer.  You  
may want to look at xtable, Sweave, odfWeave, the various HTML  
utilities, and Harrell's Hmisc::summary.formula


Perhaps my final thought. It has none of the dividing lines, but  
ftable is the standard method for displaying flat contingency  
tables for greater than two dimensions. Try the examples on the help  
page. If you wanted to add all that +---+-ing window dressing you  
could concievable start with its code using:


getAnywhere(ftable.default)

 and stick in the needed cat() statements. You can see how the  
author of CrossTables proceeded by just typing the function name  
without quotes:


CrossTables

--
David.




--

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
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Newbie cross tabulation issue

2010-09-09 Thread David Winsemius


On Sep 9, 2010, at 2:14 PM, Marc Schwartz wrote:


On Sep 9, 2010, at 12:59 PM, Jonathan Finlay wrote:

Ok friends, I tried but I not know! I'm a Linux SysAdmin and  
Stadistical and

i working to migrate all the software in my workplace to free or open
software. The OS was easy, ofimatic suite too, multimedia and  
graphics you
know, everything was relatively easy. But i work with SPSS and I  
produce
tables from polls with CTABLES and FRECUENCIES tables. In my  
migration party
I think R is the best option but need replace SPSS functions and  
procedures.

I know that sucks but it's.

In the attach you will see an example with a short output like I  
need,
please I'm starting with R and i 'm study but i need to find  
something to

replace this frecuently output while grows my experience in R.

This is the syntaxis used:

FREQUENCIES
 VARIABLES= REGION
/ORDER=  ANALYSIS .

CTABLES
  /VLABELS VARIABLES=zona V1 V3 V4 V5 V6 V7 V8  v51
  DISPLAY=DEFAULT
  /TABLE ZONA  [C] +V1 [C] +V3 [C] +V4 [C] +V5 [C] +V6 [C] +V7 [C]  
+V8 [C]

BY v51
  [C][ROWPCT.COUNT  COMMA40.1, TOTALS[COLPCT.COUNT  COMMA40.1]]
  /SLABELS VISIBLE=NO
  /CATEGORIES VARIABLES=ZONA ORDER=A KEY=VALUE EMPTY=INCLUDE  
TOTAL=YES

LABEL='Total'
  POSITION=BEFORE
  /CATEGORIES VARIABLES= V1 V3 V4 V5 V6 V7 V8
  ORDER=A KEY=VALUE EMPTY=EXCLUDE
  /CATEGORIES VARIABLES=v51 ORDER=D KEY=VALUE EMPTY=INCLUDE TOTAL=YES
LABEL='Frecuencia'
  POSITION=AFTER
  /TITLES
  TITLE='  '.

R is grand, great and biggest.

Thanks for all.



I would recommend getting a copy of Bob Muenchen's book:

 R for SAS and SPSS Users
 http://sites.google.com/site/r4statistics/the-books/r4sas-spss

There is a free smaller version here:

 http://sites.google.com/site/r4statistics/free-version

and you can get a full copy from Amazon.com:

 http://www.amazon.com/SAS-SPSS-Users-Statistics-Computing/dp/0387094172

That would be the best place to start, relative to moving from SPSS  
to R.


Part of the challenge is not just replicating SPSS code and output  
in R, but understanding the conceptual differences between the two,  
so that you can take advantage of R's approach/philosophy in  
conducting data analysis.




Another place to get useful code is the UCLA Statistical Computing  
website. At one time that group was very negative about using R, but I  
think the feedback or demand has reversed that attitude and there are  
now quite a few worked examples of common task in which SAS, SPSS,  
Stata and R are applied using the same data.


http://www.ats.ucla.edu/stat/dae/

--
David.


HTH,

Marc Schwartz



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] sequeeze a data frame

2010-09-09 Thread David Winsemius


On Sep 9, 2010, at 5:47 PM, array chip wrote:


Hi, suppose I have a data frame as below:

dat- 
cbind 
(expand 
.grid 
(id=c(1,2,3),time=c(0,3,6),mode=c('R','L'),rep=(1:3)),y=rnorm(54))



I kind of want to squeeze the data frame into a new one with  
averaged y over
rep for the same id, time and mode. taking average is easy with  
tapply:


tapply(dat$y, list(dat$id, dat$time, dat$mode), mean)


Try:

dat$avg.y - ave(dat$y, dat$id, dat$time, dat$mode, FUN=mean)

?ave

The syntax of ave is different than tapply or by. The grouping  
factors are not presented as a list and the FUN argument comes after  
the ,..., so it needs to be named if different than the default of  
mean.




But I want the result to be in the same format as dat. Certainly,  
we always
can transform the result (array) into the data frame using a lot of  
codes. But

is there a simple way to do this?

Thanks


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] URL error when trying to use help function in R [Sec: UNOFFICIAL]

2010-09-09 Thread David Winsemius


On Sep 9, 2010, at 6:34 PM, Gosse, Michelle wrote:


Greetings,

I am using R version 2.11.1 on a Dell computer, via a VMware  
connection to a remote server. My browser version is IE  
8.0.6001.18702 and the OS is some corporate version of Microsoft XP.


I'm trying to learn more about the tapply function , so I typed ? 
tapply into the command line. This opened up a browser window with  
url http://127.0.0.1:28138/library/base/html/tapply.html which is  
giving me an error message.
I receive the same problem when trying for help on other commands,  
e.g. ?table http://127.0.0.1:28138/library/base/html/table.html and ? 
log http://127.0.0.1:28138/library/base/html/Log.html


I did a whois on 127.0.0.1


That should always be your own computer. The browser is trying to  
reach a server on itself over port 28138 and either the port is  
blocked or you don't have the documentation at that location.



via www.geektools.comhttp://www.geektools.com and got the  
information boxed below, which suggests I'm not going where I am  
supposed to be going when I ask for help.


I suppose you could use that terminology, but you should check the  
specification of the browser entry in your options(). Does the  
remote server have the documentation in a library directory? Can you  
get the sysadmin for that device to give you the locations of the files?


?options
options()$browser  # would at least tell you where you system thinks  
it should be going.


If you restrict Baron's help search to only this year's questions  
containing help server browser you get:

http://search.r-project.org/cgi-bin/namazu.cgi?query=help+server+browsermax=100result=normalsort=scoreidxname=functionsidxname=Rhelp10

--
David.


I'm assuming this problem is associated with my VMware link to the  
server.


Is anyone else running this type of connection through to R and, if  
so, could they please advise how to remove the issue? I've been able  
to bring in my data table fine, and do some commands on it, the  
issue so far appears related only to help files. I'm assuming this  
is because the help files call a URL that, in my case, appears to be  
incorrect (whereas the R commands are not calling a URL and  
therefore are working fine).


I found this earlier thread: https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14155 
 however, the commentary says the bug was fixed.



Final results obtained from whois.arin.net.
Results:
#
# The following results may also be obtained via:
# http://whois.arin.net/rest/nets;q=127.0.0.1?showDetails=trueshowARIN=false
#

NetRange: 127.0.0.0 - 127.255.255.255
CIDR: 127.0.0.0/8
OriginAS:
NetName: SPECIAL-IPV4-LOOPBACK-IANA-RESERVED
NetHandle: NET-127-0-0-0-1
Parent:
NetType: IANA Special Use
Comment: This block is assigned for use as the Internet
Comment: host loopback address. Datagrams sent to
Comment: addresses anywhere within this block loops back
Comment: inside the host. Many implementation only
Comment: support this for 127.0.0.1. This block was
Comment: assigned by the IETF in the Standard document,
Comment: RFC 1122 and is further documented in the Best
Comment: Current Practice document RFC 5735. These
Comment: documents can be found at:
Comment: http://www.rfc-editor.org/rfc/rfc1122.txt
Comment: http://www.rfc-editor.org/rfc/rfc5735.txt
RegDate:
Updated: 2010-04-14
Ref: http://whois.arin.net/rest/net/NET-127-0-0-0-1

[extraneous detail here deleted]

Thanks in advance,
Michelle

Michelle Gosse
Consumer and Social Sciences
Food Standards Australia New Zealand
108 The Terrace
Wellington
New Zealand
ph: 0064-4-978-5652
email: michelle.go...@foodstandards.govt.nzmailto:michelle.go...@foodstandards.govt.nz 




**
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.clearswift.com
**



[[alternative HTML version deleted]]

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


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] survfit question

2010-09-09 Thread David Winsemius


On Sep 9, 2010, at 8:50 PM, andre bedon wrote:

I am attempting to graph a Kaplan Meier estimate for some claims  
using the survfit function. However, I was wondering if it is  
possible to plot a cdf of the kaplan meier rather than the survival  
function. Here is some of my code:


It's not really the cdf of the KM since the KM is just an estimator.  
Yeah, I know, picky, picky.



library(survival)
Surv(claimj,censorj==0)


I'm reasonably sure you need to assign that to something (unless its  
purpose is just to test the syntax.)



survfit(Surv(claimj,censorj==0)~1)
surv.all-survfit(Surv(claimj,censorj==0)~1)
summary(surv.all)
plot(surv.all)
I would really appreciate any assistance. Thank you.


The survival function is just 1 minus the CDF, (and vice versa). You  
didn't provide any data, but we can use the aml dataframe in survival:


library(survival)
surv.all-survfit(Surv(time,status)~1, data=aml)
str(surv.all)   # x-coord is time and S_KM(t) is surv
plot(surv.all$time, 1-surv.all$surv, type=s, ylim=c(0,1))

So that's the KM estimator of the CDF. Doesn't inherit the nice  
features of the plot.survfit function, though. It's also going to be  
more messy if you have two/+ groups


--

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] Calculating with tolerances (error propagation)

2010-09-10 Thread David Winsemius


On Sep 9, 2010, at 10:57 AM, David Winsemius wrote:



On Sep 9, 2010, at 6:50 AM, Jan private wrote:


Hello Bernardo,

-
If I understood  your problem this script solve your problem:

q-0.15 + c(-.1,0,.1)
h-10 + c(-.1,0,.1)
5*q*h
[1]  2.475  7.500 12.625
-

OK, this solves the simple example.
But what if the example is not that simple. E.g.

P = 5 * q/h

Here, to get the maximum tolerances for P, we need to divide the  
maximum

value for q by the minimum value for h, and vice versa.
Is there any way
to do this automatically, without thinking about every single step?

There is a thing called interval arithmetic (I saw it as an Octave
package) which would do something like this.


(Sorry for the blank reply posting. Serum caffeine has not yet  
reached optimal levels.)


Is it possible that interval arithmetic would produce statistically  
incorrect tolerance calculation, and that be why it has not been  
added to R? Those tolerance intervals are presumably some sort of  
(unspecified) prediction intervals (i.e. contain 95% or 63% or some  
fraction of a large sample) and combinations under mathematical  
operations are not going to be properly derived by c( min(XY),  
max(XY) ) since those are not calculated with any understanding of  
combining variances of functions on random variables.


There is a function, propagate, in the qpcR package that does  
incorporate statistical principles in handling error propagation.  
Thanks to the author, Dr. rer. nat. Andrej-Nikolai Spiess, for drawing  
it to my attention (and of course for writing it.). It appears that it  
should handle the data situation offered with only minor  
modifications. The first example is vary similar to your (more  
difficult) ratio problem.

 install.packages(pkgs=qpcR, type=source)
# binary install did not succeed on my Mac, but installing from source  
produced no errors or warnings.

 require(qpcR)
 q- c( 0.15 , .1)
 h-c( 10  , .1)
 EXPR - expression(5*q/h)
 DF - cbind(q, h)
 res - propagate(expr = EXPR, data = DF, type = stat,
+  do.sim = TRUE, verbose = TRUE)
 res$summary
   Sim PermProp
Mean0.07500751  NaN  0.0750
s.d.0.05001970   NA  0.05000562
Median  0.07445724   NA  NA
MAD 0.04922935   NA  NA
Conf.lower -0.02332498   NA -0.02300922
Conf.upper  0.17475818   NA  0.17300922

(My only suggestion for enhancement would be a print or summary method  
that did not output every single simulated value.)


Three methods for error propagation estimation are included: a) Monte- 
Carlo simulation using sampling from the data, b) Permutation, and c)  
Gaussian errors calculated via a Taylor series expansion. There is a  
rich set of worked examples. It appears to be capable of meeting a  
wide variety of challenges.


--
David.



--
David.


I would have thought that tracking how a (measuring) error propagates
through a complex calculation would be a standard problem of
statistics??


In probability theory, anyway.


In other words, I am looking for a data type which is a
number with a deviation +- somehow attached to it, with binary  
operators

that automatically knows how to handle the deviation.


There is the suite of packages that represent theoretic random  
variables and support mathematical operations on them.


See distrDoc and the rest of that suite.




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] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as variable ?

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 9:42 AM, Hadley Wickham wrote:


I'm having trouble parsing this. What exactly do you want to do?
1 - Put a list as an element of a data.frame. That's quite  
convenient for my pricing function.


I think this is a really bad idea. data.frames are not meant to be
used in this way. Why not use a list of lists?


It can be very convenient, but I suspect the original poster is
confused about the different between vectors and lists.


I wouldn't be surprised if someone were confused, since my reading of  
some (but not all) of the help documents has led me to think that  
lists _were_ vectors, just not vectors of atomic mode. And one oft- 
illustrated method for creating a list is:  alist -  
vector(mode=list, length=10). I am perhaps less confused than I was  
two years ago but my confusion about all the possible permutations of  
mode, typeof, expression, formula, and class and the extraction  
methods therefrom definitely persists. I think the authors of the  
documentation are of divided opinion or usage on this topic.


Best;
David.




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.


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] convert 1, 10, and 100 to 0001, 0010, 0100 etc.

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 4:05 PM, Nick Matzke wrote:


Hi,

Is there an easy way to convert numbers into a form such that they  
all have the same number of digits?


e.g.:
1, 10, and 100

...become...

0001, 0010, 0100 etc.


 sprintf(%05.0f, 100)
[1] 00100

 sprintf(%04.0f, 100)
[1] 0100




I ask because I am producing a large number of files that need to  
sort consistently by filename.  Currently I get this kind of sorting:


filename1
filename10
filename11
filename12
filename13
filename14
filename15
filename16
filename17
filename18
filename19
filename2
filename20
filename21
...etc..

which is annoying.  Ideally I'd have:

filename0001
filename0002
filename0003
filename0004
filename0005
filename0006
filename0007
filename0008
filename0009
filename0010
filename0011
...etc..

Basically I want to produce strings like 0010 without an elaborate  
hack.


Thanks!
Nick




--

Nicholas J. Matzke
Ph.D. Candidate, Graduate Student Researcher
Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Graduate Student Instructor, IB200A
Principles of Phylogenetics: Systematics
http://ib.berkeley.edu/courses/ib200a/index.shtml

Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: 
http://ib.berkeley.edu/people/students/person_detail.php?person=370
Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html
Lab phone: 510-643-6299
Dept. fax: 510-643-6264
Cell phone: 510-301-0179
Email: mat...@berkeley.edu

Mailing address:
Department of Integrative Biology
3060 VLSB #3140
Berkeley, CA 94720-3140

-
[W]hen people thought the earth was flat, they were wrong. When  
people thought the earth was spherical, they were wrong. But if you  
think that thinking the earth is spherical is just as wrong as  
thinking the earth is flat, then your view is wronger than both of  
them put together.


Isaac Asimov (1989). The Relativity of Wrong. The Skeptical  
Inquirer, 14(1), 35-44. Fall 1989.

http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm

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


David Winsemius, MD
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] Solver in R

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 5:35 PM, Chien-Pang Chin wrote:


Hi all:



I'm looking for a package that similar to solver in MS. All I need  
is find a

r to satisfy R0=sum( , where t are from 1 to n and Xt are come from
another formula.

The most package I found were to max or min the obj. function. Is  
there any

package can do it?


If you minimize R0 - sum(r * Xt ), you should get your answer.

--
David.


Thanks.

 Peter



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] Solver in R

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 5:44 PM, David Winsemius wrote:



On Sep 10, 2010, at 5:35 PM, Chien-Pang Chin wrote:


Hi all:



I'm looking for a package that similar to solver in MS. All I need  
is find a

r to satisfy R0=sum( , where t are from 1 to n and Xt are come from
another formula.

The most package I found were to max or min the obj. function. Is  
there any

package can do it?


If you minimize , you should get your answer.


Ooops, sorry. Make that:

abs( R0 - sum(r * Xt ) )  # or

( R0 - sum(r * Xt ) )^2




--
David.


Thanks.

Peter



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
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Where to find R-help options web page

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 6:10 PM, Frank Harrell wrote:



Thanks for your note Ista.  I had seen that page.  I don't see on it  
where

you can modify your subscription characteristics.  I'd like to remain
subscribed but not have e-mail delivered; that way I can just see  
messages
in nabble.  It may be that I'm misunderstanding how to use nabble  
(and to be

able to post on it).



I will admit that it often takes two or three looks for me each time I  
do it, but it _is_ on that page. Search for:


To unsubscribe from R-help, get a password reminder, or change your  
subscription options enter your subscription email address: 


The entry box is just below that sentence. The button gets you to a  
page where you enter your pwd.


When I use Nabble I try to remember to include context with the  
quotes button. It's kind of a clunky interface.




Frank

-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Where-to-find-R-help-options-web-page-tp2535123p2535148.html
Sent from the R help mailing list archive at Nabble.com.


--

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] Formatting of time strings

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 6:41 PM, Dennis Fisher wrote:


Colleagues,

(OS X, R: 11.1)

I am stuck on what should be a simple problem.

I have time elements in numeric form (e.g., 14050.5).  I want to  
convert these to HH:MM (e.g., 12:00).  I can do this with brute  
force (7 commands) but I suspect that it can be accomplished with a  
single command.  Any help would be appreciated.




?DateTimeClasses   #  POSIXct objects are internally the number of  
seconds past the origin


 as.POSIXct(14050.5, origin=1970-01-01)
[1] 1970-01-01 03:54:10 EST

# see ?strptime for format specs

 format(as.POSIXct(14050.5, origin=1970-01-01), format=%H:%M)  #  
which returns character vector

[1] 03:54

 str(format(as.POSIXct(14050.5 +(1:10)*3600, origin=1970-01-01),  
format=%H:%M ) )

 chr [1:10] 04:54 05:54 06:54 07:54 ...


Thanks.

Dennis


Dennis Fisher MD
P  (The P Less Than Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.com

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


David Winsemius, MD
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] Greek letter included in a character vector

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 7:58 PM, Judith Flores wrote:


Hello,

  In the past I have used expression to include greek letters in  
axis labels,
but this time I need to include the greek letter as part of a  
legend. Basically,
I need to create the following vector to rename the levels of a  
factor:


c(Interferon-gamma, IL-10, IL-5), where gamma obviously  
needs to be
printed as the greek letter gamma. I have tried  
expression(IFN-*gramma), but

it only works when it is isolated, not as part of a vector.



An example would have been nice. You should note that expressions are  
vectors of mode expression and that is what text and legend functions  
expect. The other thing I have learned is that quoting items  
unnecessarily inside expression() generally causes more harm than  
good. Learn to use plotmath syntax and separate items with ~ and  
*. A comma (outside a quoted string) separates individual expression  
items.


x - seq(-pi, pi, len = 65)
plot(x, sin(x), type = l, ylim = c(-1.2, 1.8), col = 3, lty = 2)
points(x, cos(x), pch = 3, col = 4)
lines(x, tan(x), type = b, lty = 1, pch = 4, col = 6)
title(legend(..., lty = c(2, -1, 1), pch = c(-1,3,4), merge = TRUE),
  cex.main = 1.1)
legend(-1, 1.9, expression(Interferon-gamma, IL-10, IL-5), col =  
c(3,4,6),

   text.col = green4, lty = c(2, -1, 1), pch = c(-1, 3, 4),
   merge = TRUE, bg = 'gray90')

Also look at plotmath-paste:

legend(-1, 1.9, expression(paste(Interferon,-,gamma), IL-10, IL-5),  
col = c(3,4,6),

text.col = green4, lty = c(2, -1, 1), pch = c(-1, 3, 4),
merge = TRUE, bg = 'gray90')

--

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] convert 1, 10, and 100 to 0001, 0010, 0100 etc.

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 9:25 PM, Peng, C wrote:



These are character values. Is there any way to get 001, 010, ...,  
as actual

numeric values?


 001
[1] 1
 0100
[1] 100
 001 == 1
[1] TRUE
 0100 == 100
[1] TRUE


--
View this message in context: 
http://r.789695.n4.nabble.com/convert-1-10-and-100-to-0001-0010-0100-etc-tp2535023p2535296.html
Sent from the R help mailing list archive at Nabble.com.



--
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] Is there a bisection method in R?

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 8:35 PM, huang min wrote:


uniroot


 ... is not a bisection method.



On Sat, Sep 11, 2010 at 6:10 AM, Gregory Gentlemen 
gregory_gentle...@yahoo.ca wrote:


Dear fellow R-users,

Is there a function that does the bisection method? I was unable to  
find

one.

Thanks in advance.
Gregory


--
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] convert 1, 10, and 100 to 0001, 0010, 0100 etc.

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 10:05 PM, Peng, C wrote:



I mean to display 001,010, ..., as there are.  In other words,  
whether there

is a function, say func(), such that func(001,010) displays 001, 010.


Not hard to construct one, but does not behave properly in the sub- 
unity decimal range. Not surprising. It did better in the range of  
values from the integer class than I thought it would.


 func4 - function(x) cat(sprintf(%05.0f, x))
 func4(10)
00010
 func5 - function(x) cat(sprintf(%05.0f, x))
 func5(100)
00100
 func5(10)
10
 func5(1)
1
 func5(0.001)
0
 func5(-3)
-0003
 func5(-300)
-300

--
David.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] acceptable filetypes was Re: coxph and ordinal variables?

2010-09-10 Thread David Winsemius


On Sep 10, 2010, at 10:32 PM, Paul Johnson wrote:


Hi, everybody

On Wed, Sep 8, 2010 at 5:43 PM, Min-Han Tan minhan.scie...@gmail.com 
 wrote:



David said my R code text attachment got rejected by the mailing list.

Pooh.   I don't think that's nice.  I don't see anything in the
posting guide about a limit on text attachments.


 Paul: It's not in the Posting Guide but it is in the Mailing list  
information page:


Furthermore, most binary e-mail attachments are not accepted, i.e.,  
they are removed from the posting completely. As an exception, we  
allow application/pdf, application/postscript, and image/png (and x- 
tar and gzip on R-devel). You can use text/plain as well, or simply  
paste text into your message instead. 


And as I said the filter is very dumb. filename.R files are  
intercepted but the very same file with the name filename.txt will  
be passed through intact. Now I would agree if you said those  
directions were ambiguous and even possibly misleading, but it did  
lead me to successful interactions with the mailserver in the past, so  
I decided it wasn't worth a complaint. As I understand it the amount  
of control that the list maintainers exert over the server behavior is  
pretty limited.


--
David.




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


Re: [R] Argument lib is missing

2010-09-11 Thread David Winsemius


On Sep 11, 2010, at 6:29 AM, khush  wrote:


Dear all,

I have installed R using yum install R-2.9.  I am able to use R for  
general
functions but when I installed some library say gplots I am getting  
the

below error.


install.packages(gplots)

Warning in install.packages(gplots) :
 argument 'lib' is missing: using
'/home/fedora/R/i386-redhat-linux-gnu-library/2.11'


That warning should not cause much problem.


Warning: unable to access index for repository
http://cran.csdb.cn/src/contrib


From time to time it happens that repositories are unavailable. I  
just checked and at the moment that repository is available. You could  
try again. (Or you could have tried another repository at that time.  
Trying another repository might make sense even now, since the version  
of gplots at that repository is fairly outdated. The current version  
is 2.8.0 and the one at csdb.cn is 2.7.1 from May 2009. There have  
been several revisions since that date.)



Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
 package ‘gplots’ is not available

any suggestion will be appreciable.

Thank you
Khush


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] Latex fonts in R graphics

2010-09-11 Thread David Winsemius


On Sep 11, 2010, at 7:18 AM, KARAVASILIS GEORGE wrote:


Hello, R users.
I am trying to embed Computer modern fonts to an R plot and I get  
the following error.


CM - Type1Font(CM,
+  c(paste(cm-lgc/fonts/afm/public/cm-lgc/,
+ c(fcmr8a.afm, fcmb8a.afm, fcmri8a.afm, fcmbi8a.afm),  
sep=),

+ ./cmsyase.afm))
 pdf(cm.pdf, width=3, height=3, family=CM)
 plot(1:length(y), y, xlab=ss, ylab=expression(x[2]))  ## for any  
vector y

 dev.off()
null device
 1
 embedFonts(cm.pdf, outfile=cmembed.pdf, fontpaths=c(cm-lgc/ 
fonts/type1/public/cm-lgc, .))
Error in embedFonts(cm.pdf, outfile = cmembed.pdf, fontpaths =  
c(cm-lgc/fonts/type1/public/cm-lgc,  :
 status -1 in running command 'gswin32c.exe -dNOPAUSE -dBATCH -q - 
dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=C: 
\DOCUME~1\user\LOCALS~1\Temp\RtmpccEtgV\Rembed28163716 -sFONTPATH=cm- 
lgc/fonts/type1/public/cm-lgc;.  cm.pdf'

In addition: Warning message:
In system(cmd) : gswin32c.exe not found


Operating system: Windows XP, SP2.
cm-lgc has been unzipped in the working directory  C:/Program Files/ 
R/R-2.10.1 and the AFM, PFB files are also in same directory.


The error message is telling us that you do not have Ghostscript  
installed properly. While you are at it, you should probably updated R  
as well.


--
David


Any help?

--

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] for loop

2010-09-11 Thread David Winsemius


On Sep 11, 2010, at 8:39 AM, Peng, C wrote:



or:

k=0
for (i in 1:k) if(k0) print(i)


Because of the way the : operator works, I would have tested k =1

 k=0.5
 for (i in 1:k) if (k0){print(i)}
[1] 1

But Gabor's suggestion to use seq_len(k) is cleaner, anyway.

--

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] Argument lib is missing

2010-09-11 Thread David Winsemius


On Sep 11, 2010, at 8:02 AM, David Winsemius wrote:



On Sep 11, 2010, at 6:29 AM, khush  wrote:


Dear all,

I have installed R using yum install R-2.9.  I am able to use R for  
general
functions but when I installed some library say gplots I am getting  
the

below error.


install.packages(gplots)

Warning in install.packages(gplots) :
argument 'lib' is missing: using
'/home/fedora/R/i386-redhat-linux-gnu-library/2.11'


That warning should not cause much problem.


Or maybe it would. I just noticed that you said you were using an  
ancient version of R and that library location is for the current  
version. You probably need to get advice from a fellow Redhat user if  
you want to run an outdated version. Installing packages for the  
current version is not going to be very successful. There is a  
repository of packages for older systems and you can find the link at  
the bottom of the package list on CRAN.


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

Look for the Archive link.




Warning: unable to access index for repository
http://cran.csdb.cn/src/contrib


From time to time it happens that repositories are unavailable. I  
just checked and at the moment that repository is available. You  
could try again. (Or you could have tried another repository at that  
time. Trying another repository might make sense even now, since the  
version of gplots at that repository is fairly outdated. The current  
version is 2.8.0 and the one at csdb.cn is 2.7.1 from May 2009.  
There have been several revisions since that date.)



Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
package ‘gplots’ is not available

any suggestion will be appreciable.

Thank you
Khush


David Winsemius, MD
West Hartford, CT



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

2010-09-11 Thread David Winsemius


On Sep 11, 2010, at 9:50 AM, Gregory Ryslik wrote:


Hi Everyone,

I am implementing a special case of Random forests. At one point, I  
have a list of which I then sample for replacement. So if the list  
is 100 elements, I get 100 elements some of them duplicates. How can  
I easily get the elements that were not included in the list? I  
realize i can do this with a for loop by going through each element  
and checking if it's in the list but I am wondering if there is a  
faster way.


?setdiff
?%in%





--

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] approxfun-problems (yleft and yright ignored)

2010-09-11 Thread David Winsemius


On Sep 11, 2010, at 10:04 AM, Martin Maechler wrote:


SW == Samuel Wuest wue...@tcd.ie
   on Thu, 26 Aug 2010 14:34:26 +0100 writes:


   SW Hi Greg,
   SW thanks for the suggestion:

   SW I have attached some small dataset that can be used to  
reproduce the

   SW odd behavior of the approxfun-function.

   SW If it gets stripped off my email, it can also be downloaded at:
   SW http://bioinf.gen.tcd.ie/approx.data.Rdata

   SW Strangely, the problem seems specific to the data structure  
in my
   SW expression set, when I use simulated data, everything worked  
fine.


   SW Here is some code that I run and resulted in the strange  
output that I

   SW have described in my initial post:


### load the data: a list called approx.data
load(file=approx.data.Rdata)
### contains the slots x, y, input
names(approx.data)

   SW [1] x y input

### with y ranging between 0 and 1
range(approx.data$y)

   SW [1] 0 1
### compare ranges of x and input-x values (the latter is a small  
subset of 500 data points):

range(approx.data$x)

   SW [1] 3.098444 7.268812

range(approx.data$input)

   SW [1]  3.329408 13.026700



### generate the interpolation function (warning message benign)
interp - approxfun(approx.data$x, approx.data$y, yleft=1,  
yright=0, rule=2)

   SW Warning message:
   SW In approxfun(approx.data$x, approx.data$y, yleft = 1, yright  
= 0,  :

   SW collapsing to unique 'x' values


### apply to input-values
y.out - sapply(approx.data$input, interp)

### still I find output values 1, even though yleft=1:
range(y.out)

   SW [1] 0.00 7.207233

#-- on another  64 bit Mac -
 load(file=approx.data.Rdata)
 names(approx.data)
[1] x y input
 range(approx.data$y)
[1] 0 1
 range(approx.data$x)
[1] 3.098444 7.268812

 interp - approxfun(approx.data$x, approx.data$y, yleft=1,  
yright=0, rule=2)

Warning message:
In approxfun(approx.data$x, approx.data$y, yleft = 1, yright = 0,  :
  collapsing to unique 'x' values
 y.out - sapply(approx.data$input, interp)
 range(y.out)
[1] -5.143958e+284   9.816907e-01

 interp
function (v)
.C(R_approxfun, as.double(x), as.double(y), as.integer(n),
xout = as.double(v), as.integer(length(v)), as.integer(method),
as.double(yleft), as.double(yright), as.double(f), NAOK = TRUE,
PACKAGE = stats)$xout
environment: 0x1598c91b8

# attempt to offer yright and yledft in the sapply call failed
 y.out - sapply(approx.data$input, interp, yright=0, yleft=1)
Error in FUN(c(6.99984458535897, 4.85139079147721, 7.58922165833,  
10.8135863246057,  :

  unused argument(s) (yright = 0, yleft = 1)

#Create yright and yleft in the calling environment:

 yright=0; yleft=1
 y.out - sapply(approx.data$input, interp)
 range(y.out)
[1] 0.000 0.9816907

Now it works as expected.


It seems to me that the yleft and yright values may not be properly  
incorporated into the constructed function.



 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] grid  splines   stats graphics  grDevices
[6] utils datasets  methods   base

other attached packages:
 [1] gplots_2.8.0 caTools_1.10 bitops_1.0-4.1
 [4] gdata_2.8.0  gtools_2.6.2 sos_1.2-9
 [7] brew_0.1-1   qpcR_1.3-2   minqa_1.1.9
[10] Rcpp_0.8.5   nlme_3.1-96  cluster_1.12.3
[13] rgl_0.91 minpack.lm_1.1-4 MASS_7.3-6
[16] chron_2.3-35 maps_2.1-4   gmodels_2.15.0
[19] rbenchmark_0.3   data.table_1.5   rms_3.0-0
[22] Hmisc_3.8-1  survival_2.35-8  plyr_1.1
[25] lattice_0.18-8

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

--
David Winsemius




I get completely different (and correct) results,
by the way the *same* you have in the bug report you've
submitted
(https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14377)
and which does *not* show any bug:


range(y.out)

[1] 0.000 0.9816907

Of course, I do believe that you've seen the above problems,
-- on 64-bit Mac ? as you report in sessionInfo() ? --
but I cannot reproduce them.

And also, you seem yourself to be able to get different results
for the same data... what are the circumstances?

Regards,
Martin Maechler, ETH Zurich



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] xlab with text and expression

2010-09-11 Thread David Winsemius


On Sep 11, 2010, at 11:07 AM, threshold wrote:



Dear R users, say
plot(rnorm(1)~rnorm(1), xlab=paste('abc', expression(x=1)),


plot(rnorm(1)~rnorm(1), xlab=expression(abc~x = 1))

# or if you are uncertain whether abc is a plotmath-special then this  
also works


plot(rnorm(1)~rnorm(1), xlab=expression(abc~x = 1))



I want proper sign of weak inequality not just '='

will appreciate!
robert
--



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] confidence bands for a quasipoisson glm

2010-09-11 Thread David Winsemius


On Sep 11, 2010, at 3:15 PM, Maik Rehnus wrote:


Dear all,

I have a quasipoisson glm for which I need confidence bands in a  
graphic:


gm6 - glm(num_leaves ~  b_dist_min_new, family = quasipoisson, data  
= beva)

summary(gm6)

library('VIM')
b_dist_min_new - as.numeric(prepare(beva$dist_min,  
scaling=classical, transformation=logarithm)).


My first steps for the solution are following:

range(b_dist_min_new)
x - seq(-1.496, 1.839, by=0.01)
newdat - data.frame(b_dist_min_new=x)
y - predict(gm6, newdata=newdat, type=response)
plot(x,y, type=l, ylim=c(0,15), lty=2, xlab=Distance [scaled  
log.], ylab=Number of used plant, las=1)


ilogit-function(x) exp(x)/(1 + exp(x))
logit -function(x) log(x/(1 - x))

newdat$logitpred - predict(gm6, newdata=newdat, type=link)


I'm puzzled. You specified that model as quasipoisson and are now  
treating it as if it were  logistic? The link is going to be log(),  
nicht wahr?


newdat$sepred - predict(gm6, newdata=newdat, type=link,  
se.fit=TRUE)$se.fit

newdat$logitlower - newdat$logitpred-1.96 * newdat$sepred
newdat$logitupper - newdat$logitpred+1.96 * newdat$sepred


I'm not familiar with ilogit (sounds very useful assuming it to be an  
inverse logit), but if one were taking a first stab at an inverse  
function for quasipoisson wouldn't that be exp()?



newdat$upper - ilogit(newdat$logitupper)
newdat$lower - ilogit(newdat$logitlower)
lines(x, newdat$lower, lty=3)
lines(x, newdat$upper, lty=3).

In this way I could find a positive correlation. But my created  
confidence bands on the graph don't touch my regression line. Could  
it be a technical problem or is it a mistake in the calculation?


I am new here and I hope you can help to solve my problem. I could  
not find any answers for quasipoisson glm on internet.


Best regards

Maik



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] scalable delimiters in plotmath

2010-09-11 Thread David Winsemius


On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote:


On 2010-09-11 16:14, Dennis Murphy wrote:

Hi Baptiste,

You need to use the symbol(\nnn) concept, where nnn denotes the  
octal
symbol number. For  it's 074 and for  it's 076. This little test  
seemed to

work:

plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076)))

HTH,
Dennis


It's a matter of taste, but I would use \341 and \361.
However, these are still not scalable, AFAICS.


Not exactly scalable angles, but you can fake it:

plot(1, 1, main =  
expression(symbol(\341)~scriptstyle( atop(x,y) )~symbol(\361)),  
cex.main=3)


scriptstyle shrinks the inner atop() material, and since I tested on a  
Mac it should work for Baptiste.


--
David.


 -Peter Ehlers



On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie
baptiste.aug...@googlemail.com  wrote:


What do people use to show angle bracketsin R graphics? Have I
missed something obvious?

Thanks,

baptiste

On 9 September 2010 17:57, baptiste auguie
baptiste.aug...@googlemail.com  wrote:

Dear list,

I read in ?plotmath that I can use bgroup to draw scalable  
delimiters
such as [ ] and ( ). The same technique fails withhowever,  
and I

cannot find a workaround,

grid.text(expression(bgroup(,atop(x,y),)))

Error in bgroup(, atop(x, y),) : invalid group delimiter

Regards,

baptiste

sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-apple-darwin9.8.0


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] create a '3D line plot'

2010-09-12 Thread David Winsemius


On Sep 12, 2010, at 10:12 AM, Karl Brand wrote:


Esteemed useRs and developeRs,

I need to create a  '3D line plot' (proper name?) of which an  
excellent example can be viewed here:


http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg


Set up blank plot region with proper ranges for x and ylim that could  
be say 0:60 with the intent of scaling your 50 individual y ranges to  
0-10

Scale your y values to be within 0-10
Fill plot area black:
Draw from top down using polygon with white lines at cex=2 and black  
fill.

Then something along these lines:
for(ilevel in 0:50){ polygon(x,yscaled+50-ilevel, col=black,  
border=white, lwd=2)}


#--- tested code
opar - par(bg=black)
 set.seed(1)
 Ldens - vector(mode=list, 50)
 for(i in 1:50) {
   Ldens[[i]] - density(rnorm(100), from=-3,to=3)
  with(Ldens[[i]], polygon(x=c(x[c(1, 1:512, 512)]), y= c(0, 50-i 
+20*y[1:512], 0),

   col=black, border=white))
 }
par(opar)
#-


Got any data?

--
David.




I have some experience using the rgl package to create 3D PCA plots,  
but have no idea where to start for an image like this.


I'd really appreciate suggestions  help on how might achieve this  
using R,


Karl

--
Karl Brand

--

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] reshape matrix entities to columns

2010-09-12 Thread David Winsemius


On Sep 12, 2010, at 10:45 AM, Natasha Asar wrote:


Greeting R helpers J
I am not familiar with R but I have to use it to analyze data set  
that I have

(30,000 20,000)
I want to change the structure of the dataset and I am wondering how  
that might

be possible in R
A main data looks like this:  some entities are empty
AgeNo. AgeNo. AgeNo.
Center1 5  2  8   7

Center2  10   7  20
9  4  10
But what I want the data to look like is
Age1  2  3
4  5  6  7  8
9  10 …   20
Center1
2  7
Center2
10
 7  9

It should read the entities one by one
when j is in age column take its value and consider it as the column  
number for

new matrix
then go to next entity (j No. columns) and put that entity under the  
columns

number identified in previous step.
In other word
it should get the each element in No. columns (one by one) and place  
them in a
new matrix under the column number which are equal to entity of age  
columns of

first matrix
i have tired ncol, and cbind and things like that but I guess im on  
the wrong
path because it is not working.  I am reading this fine with  
read.csv and

writing back the same way.
do you know how I can make this work?? Is it even possible to do  
something like

this?
Thank you in advance
Natasha



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


[R] How to print matrices in standard format was ... Re: How to define new matrix based on an elementary row oper

2010-09-12 Thread David Winsemius


On Sep 12, 2010, at 11:27 AM, Cuckovic Paik wrote:



I appreciate all you help. This is only for instructional purpose:

A = matrix(c(0,1,1,-2,-3,1,2,-1,0,2,2,4,1,-3,-2,1,-4,-7,-1,-19),  
ncol=5,

byrow=T)
B  
=matrix(sample(c(0,1,1,-2,-3,1,2,-1,0,2,2,4,1,-3,-2,1,-4,-7,-1,-19),),

ncol=5, byrow=T)

Which print func( A, B,  A+B) can print the resulting matrices A and  
B and

A+B  in the following format?

[,1] [,2] [,3] [,4] [,5] [,1] [,2] [,3] [,4] [,5]
[,1]  [,2]  [,3]  [,4] [,5]
[1,]011   -2   -3   [1,]  2   -102  
1[1,]

2 0 1 0-2
[2,]12   -102   +   [2,]  1   -42   -2-2
=  [2,]

2-2 1-2 0
[3,]241   -3   -2   [3,] -31   -71 
-1   [3,]

-1 5-6-2-3
[4,]1   -4   -7   -1  -19  [4,] -304  -19 1   
[4,] -2

-4-3   -20   -18



for( i in 1:nrow(A) ) { cat(sprintf(%4.0f, A[i, ]), paste(   
,if( i==3 ){+}else{ },  , sep=),sprintf(%4.0f,B[i, ]),  
paste(  ,if( i==3 ){=}else{ },  , sep=), sprintf(%4.0f, (A 
+B)[i, ]), \n )}


--

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] scalable delimiters in plotmath

2010-09-12 Thread David Winsemius


On Sep 12, 2010, at 6:15 AM, baptiste auguie wrote:


Thanks everyone. I've also had a look at plotmath.c where bgroup is
defined for [, {, (, . but not . It seems quite trivial to
add it, at first sight, however there is a part that I don't
understand in the RenderDelim routine,

static BBOX RenderDelim(int which, double dist, int draw,  
mathContext *mc,

pGEcontext gc, pGEDevDesc dd)
{

// [... snipped ...]

   case '(':
top = 230; ext = 231; bot = 232; mid = 0;
break;
   case ')':
top = 246; ext = 247; bot = 248; mid = 0;
break;

These integer codes make no sense to me, I have no clue which ones I
should use for  and .


Does this help? (I think they are using Symbol PS fonts with decimal  
indexing.)


 as.octmode(c(230, 231, 232, 246, 247, 248) )
[1] 346 347 350 366 367 370
  plot(1,1, xlab= expression(
symbol(\346)~# upper 1/3 of left paren
symbol(\347)~# to left of center bar
symbol(\350)~# lower 1/3 of left paren

symbol(\366)~# upper 1/3 of right paren
symbol(\367)~# to right of center bar
symbol(\370) ) ) # lower 1/3 of right paren

(caveat: Maybe not standard glyph-names.)

I added octal annotation to the TestChars(font=5) call that the points  
help page offers:


TestChars(font=5)
for(j in 1:14) {
for(i in 0:16){
text(i+0.2, j+.6, labels=as.octmode(i+(j+1)*16), cex=.5)}}

I do not see a trio or pair of glyphs that would form an angle bracket.

--

David.



As far as I understand these codes might
correspond to extended ascii characters whose boundaries and positions
we want to borrow. Then again, maybe it's something else entirely.

Any hints?

Best wishes,

baptiste




On 12 September 2010 03:27, David Winsemius dwinsem...@comcast.net  
wrote:


On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote:


On 2010-09-11 16:14, Dennis Murphy wrote:


Hi Baptiste,

You need to use the symbol(\nnn) concept, where nnn denotes the  
octal
symbol number. For  it's 074 and for  it's 076. This little  
test seemed

to
work:

plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076)))

HTH,
Dennis


It's a matter of taste, but I would use \341 and \361.
However, these are still not scalable, AFAICS.


Not exactly scalable angles, but you can fake it:

plot(1, 1, main = expression(symbol(\341)~scriptstyle( atop(x,y)
)~symbol(\361)), cex.main=3)

scriptstyle shrinks the inner atop() material, and since I tested  
on a Mac

it should work for Baptiste.

--
David.


 -Peter Ehlers



On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie
baptiste.aug...@googlemail.com  wrote:

What do people use to show angle bracketsin R graphics?  
Have I

missed something obvious?

Thanks,

baptiste

On 9 September 2010 17:57, baptiste auguie
baptiste.aug...@googlemail.com  wrote:


Dear list,

I read in ?plotmath that I can use bgroup to draw scalable  
delimiters
such as [ ] and ( ). The same technique fails with 
however, and I

cannot find a workaround,

grid.text(expression(bgroup(,atop(x,y),)))

Error in bgroup(, atop(x, y),) : invalid group delimiter

Regards,

baptiste

sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-apple-darwin9.8.0


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] scalable delimiters in plotmath

2010-09-12 Thread David Winsemius
,

grid.text(expression(bgroup(,atop(x,y),)))

Error in bgroup(, atop(x, y),) : invalid group delimiter

Regards,

baptiste

sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-apple-darwin9.8.0


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.


--
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] reshape matrix entities to columns

2010-09-12 Thread David Winsemius


On Sep 12, 2010, at 3:34 PM, Dennis Murphy wrote:


Hi:

Natasha said:

I changed it so i hope it will look better now
the matrix is like this:
AgeNo.   Age   No.   AgeNo.
Center1 52  8   7
Center210  720 9   4  10
column name = sequence of age-no.

But what I want the data to look like is this
Age
1  2  3   4   5  6   7  8   9 10

  20
Center1
27

Center2
10 7   9
column name= age of ppl
entries = number of ppl with that age in on center
*

It's a continuation of the reshape problem, but we have to
change the NAs in the reshaped data frame to zeros first:

df2[is.na(df2)] - 0

xtabs(n ~ center + age, data = df2)
 age
center  5  6  7  8  9 10 11 12 13 14
1  0 10  0 13  0  9  0  7  0 10
2  0  0 12 14  0  0 16  0  0 13
3  6  0  0  0 10  0 12  0  9  0

How's that?



You've done all the hard work, but the OP wanted the full range of age  
values from 1:max and that pretty easy to do with one further step  
that adds entries fo the missing age levels:


 df3 - rbind(df2, data.frame(center=1,time=1, age=1:max(df2$age),  
n=0))


 xtabs(n ~ center + age, data = df3)
  age
center  1  2  3  4  5  6  7  8  9 10 11 12 13 14
 1  0  0  0  0  0 10  0 13  0  9  0  7  0 10
 2  0  0  0  0  0  0 12 14  0  0 16  0  0 13
 3  0  0  0  0  6  0  0  0 10  0 12  0  9  0

--
David.

Dennis

On Sun, Sep 12, 2010 at 9:46 AM, Dennis Murphy djmu...@gmail.com  
wrote:



Hi:

Here's a made up example using the reshape function:

Input data:
df - structure(list(center = 1:3, age1 = c(6L, 7L, 5L), n1 = c(10L,
12L, 6L), age2 = c(8L, 8L, 8L), n2 = c(13L, 14L, NA), age3 = c(10L,
10L, 9L), n3 = c(9L, NA, 10L), age4 = c(12L, 11L, 11L), n4 = c(7L,
16L, 12L), age5 = c(14L, 14L, 13L), n5 = c(10L, 13L, 9L)), .Names =
c(center,
age1, n1, age2, n2, age3, n3, age4, n4, age5,
n5), class = data.frame, row.names = c(NA, -3L))

df
 center age1 n1 age2 n2 age3 n3 age4 n4 age5 n5
1  16 108 13   10  9   12  7   14 10
2  27 128 14   10 NA   11 16   14 13
3  35  68 NA9 10   11 12   13  9

# To reshape more than one variable at a time, you need
# to put the sets of variables into a list, as follows:

df2 - reshape(df, idvar = 'center', varying =
  list(c(paste('age', 1:5, sep = '')), c(paste('n', 1:5, sep = ''))),
  v.names = c('age', 'n'), times = 1:5, direction = 'long')
df2
   center time age  n
1.1  11   6 10
2.1  21   7 12
3.1  31   5  6
1.2  12   8 13
2.2  22   8 14
3.2  32   8 NA
1.3  13  10  9
2.3  23  10 NA
3.3  33   9 10
1.4  14  12  7
2.4  24  11 16
3.4  34  11 12
1.5  15  14 10
2.5  25  14 13
3.5  35  13  9

HTH,
Dennis

On Sun, Sep 12, 2010 at 7:45 AM, Natasha Asar natasha.asa...@yahoo.com 
wrote:



Greeting R helpers J
I am not familiar with R but I have to use it to analyze data set  
that I

have
(30,000 20,000)
I want to change the structure of the dataset and I am wondering  
how that

might
be possible in R
A main data looks like this:  some entities are empty
AgeNo. AgeNo. AgeNo.
Center15  2  8
7

Center210   7   
20

9  4  10
But what I want the data to look like is
Age1  2  3
4  5  6  7  8
9  10

  20

Center1
2  7
Center2
10
7  9

It should read the entities one by one
when j is in age column take its value and consider it as the column
number for
new matrix
then go to next entity (j No. columns) and put that entity under the
columns
number identified in previous step.
In other word
it should get the each element in No. columns (one by one) and  
place them

in a
new matrix under the column number which are equal to entity of age
columns of
first matrix
i have tired ncol, and cbind and things like that but I guess im  
on the

wrong
path because it is not working.  I am reading this fine with  
read.csv and

writing back the same way.
do you know how I can make this work?? Is it even possible to do  
something

like
this?
Thank you in advance
Natasha



  [[alternative HTML version deleted]]


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






[[alternative HTML version deleted]]

__

Re: [R] How to print matrices in standard format was ... Re: How to define new matrix based on an elementary row oper

2010-09-12 Thread David Winsemius


On Sep 12, 2010, at 12:24 PM, David Winsemius wrote:



On Sep 12, 2010, at 11:27 AM, Cuckovic Paik wrote:



I appreciate all you help. This is only for instructional purpose:

A = matrix(c(0,1,1,-2,-3,1,2,-1,0,2,2,4,1,-3,-2,1,-4,-7,-1,-19),  
ncol=5,

byrow=T)
B  
= 
matrix(sample(c(0,1,1,-2,-3,1,2,-1,0,2,2,4,1,-3,-2,1,-4,-7,-1,-19),),

ncol=5, byrow=T)

Which print func( A, B,  A+B) can print the resulting matrices A  
and B and

A+B  in the following format?

   [,1] [,2] [,3] [,4] [,5] [,1] [,2] [,3] [,4] [, 
5][,1]  [,2]  [,3]  [,4] [,5]
[1,]011   -2   -3   [1,]  2   -102  
1[1,]  2 0 1 0-2
[2,]12   -102   +   [2,]  1   -42   -2-2
=[2,]  2-2 1-2 0
[3,]241   -3   -2   [3,] -31   -71 
-1[3,] -1 5-6-2-3
[4,]1   -4   -7   -1  -19   [4,] -304  -19  
1[4,] -2-4-3   -20   -18




for( i in 1:nrow(A) ) { cat(sprintf(%4.0f, A[i, ]), paste(   
,if( i==3 ){+}else{ },  , sep=),sprintf(%4.0f,B[i, ]),  
paste(  ,if( i==3 ){=}else{ },  , sep=), sprintf(%4.0f,  
(A+B)[i, ]), \n )}



 for( i in 1:nrow(A) ) { cat(sprintf(%4.0f, A[i, ]),
paste(  ,if( i==3 ){+}else{ },  ,  
sep=),

sprintf(%4.0f,B[i, ]),
paste(  ,if( i==3 ){=}else{ },  ,  
sep=),

sprintf(%4.0f, (A+B)[i, ]), \n )}

Even with the prettier printing it stilled seemed like a hack, so here  
is a grid graphics solution that gives prettier _output_:


require(grid)
 grid.newpage()
 pushViewport(plotViewport(c(5,4,2,2)))  # implicit limits are  
c(0,0,1,1) within plot area
 for (i in 1:nrow(A)) { for (j in 1:ncol(A)){grid.text(A[i,j], x=i/ 
20, y=j/20)}}  # plot mtx A
 for (i in 1:nrow(B)) { for (j in 1:ncol(B)){grid.text(B[i,j], x=(i 
+5)/20, y=j/20)}}  # B
 for (i in 1:nrow(B)) { for (j in 1:ncol(B)){grid.text(A[i,j] 
+B[i,j], x=(i+10)/20, y=j/20)}} # A+B

 grid.text(=, x=10/20, y=2.5/20)
 grid.text(+, x=5/20, y=2.5/20)







--

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] How to do a trig regression

2010-09-12 Thread David Winsemius


On Sep 12, 2010, at 10:23 PM, Aaditya Nanduri wrote:


Hello All,

I cant seem to do a trig regression in R.

The equation is as follows : y = a+b*(sin((2*pi*x/360) - c))^2

a, b, c are coefs that I want.
y, x are input vectors.

The equation I put into R: lm(y ~ sin(2*pi*x/360)^2)
This equation is missing the c and I dont get the right answer.


Take a look at section 2.3 of:

http://www.statoek.wiso.uni-goettingen.de/veranstaltungen/zeitreihen/sommer03/ts_r_intro.pdf

Or consider using time series or nonlinear modeling.


Also, I dont know how to plot the lm over the x values instead of the
indices.


Without an example of your data and what you tried it is difficult to  
intuit what problems you may be facing.


--
David.


Any help is sincerely appreciated.
Thank you all very much.

--
Aaditya Nanduri
aaditya.nand...@gmail.com

[[alternative HTML version deleted]]

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


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


Re: [R] Overlay of two graphs of different axes

2010-09-13 Thread David Winsemius


On Sep 13, 2010, at 1:54 AM, Uwe Dippel wrote:

Though I have read quite a bit, and tried quite a bit, I have yet to  
find a nice way to overlay 2 or more curves in the same plot, with  
different ranges.


The different axes could be a problem but if you construct both with  
predefined coordinates systems and scale appropriately it should work  
out. See the twoord.plot function  in plotrix.



Here is simplified sample code to demonstrate the question:

 plot(2*(seq(1,5)), type=l, axes=FALSE)


? lines

 lines(1.5*(seq(2,5)), type=b)



 curve(2*(seq(1,5)), type=b, add=TRUE)
Error in curve(2 * (seq(1, 5)), type = b, add = TRUE) :
 'expr' must be a function or an expression containing 'x'
 axis(2)
 curve(x^2, 1, 5, type=b, add=TRUE)
 axis(4)

Firstly, as an aside, I am not clear why 'curve' has a different  
syntax compared to 'plot'. As a still beginner, I'd for one would be  
happy to add curves to a plot; curves of just different parameters.  
Though, I guess, there must be a good reason?


curve is like abline in that it draws from left x range to right x  
range.


Mostly, however, I wonder how to plot a number of curves into an  
original plot, that re-defines the min/max from the most recent curve.


lines() or segments()



In the example that I constructed, axis(2) does exactly the expected  
thing.
What I want to do next, though, with the least effort, is to add  
another function in a manner that the added function is scaled, not  
according to the first function (plot), but to fit into the plotting  
area. (The example above overshoots the range).
Plus, how can I subsequently add the axis suitable to the most  
recent function? That is, how can I render axis(4) to displaying the  
scale for the second graph, created with 'curve'?


There are many worked examples in the archives, as well as canned  
solutions in widely used packages.






--

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] Create a time-series from cross-sectional data that has each year as a separate column

2010-09-13 Thread David Winsemius


On Sep 13, 2010, at 2:31 AM, Gabriel Bergin wrote:


Hi,

I have a dataset from ILO, originally in csv-format, that I have  
read into
R. It is cross-sectional time-series data, so I have a bunch of  
variables
and dummy variables that I need to extract data from for the entire  
time
period. However, the years are separated by columns instead of rows,  
as is

usually the case in R. This is what it looks like:


str(laborstafinMFBA)

'data.frame': 152 obs. of  39 variables:
$ COUNTRY: Factor w/ 164 levels  
Albania,Algeria,..: 2 4

7 8 9 10 11 11 12 13 ...
$ CODE.COUNTRY   : Factor w/ 163 levels AE,AG,AI,..:  
44 7 8 5

12 11 10 10 13 23 ...
$ SOURCE : Factor w/ 7 levels Administrative  
reports,..:

3 3 3 3 3 3 3 3 3 3 ...
$ CODE.SOURCE: Factor w/ 7 levels A,B,BA,CA,..:  
3 3 3 3

3 3 3 3 3 3 ...
etc..
$ D1990  : num  NA NA NA NA NA ...
$ D1991  : num  NA NA 101 NA NA ...
$ D1992  : num  NA 38.4 111.2 NA NA ...
$ D1993  : num  NA NA 94.4 NA NA ...
$ D1994  : num  NA NA 133.69 NA 1.42 ...
$ D1995  : num  NA NA 121 NA NA ...
$ D1996  : num  NA NA 176 NA NA ...
$ D1997  : num  NA NA 195.31 NA 1.51 ...
$ D1998  : num  NA NA 202 NA NA ...
$ D1999  : num  NA NA 201 NA NA ...
$ D2000  : num  NA NA 207 NA NA ...
$ D2001  : num  68.1 NA 198.3 NA NA ...
$ D2002  : num  NA NA 186 NA NA ...
$ D2003  : num  67.6 NA 148.8 NA NA ...
$ D2004  : num  68.8 NA 143.7 NA NA ...
$ D2005  : num  NA NA 163 NA NA ...
$ D2006  : num  NA NA 189 NA NA ...
$ D2007  : num  NA NA NA 14 1.91 ...

How do I transform this into something that I can make a time-series  
of?


?reshape
package reshape(not the same as the function reshape)
package sqldf

There might also be the possibility of using t() on just the Dyear  
columns but it might not give desired results on the association of  
COUNTRY with SOURCE


It looks as though there are a mixture of data types and that you  
might want to pull out all the types of SOURCE separately before  
transforming or go to a database-oriented solution.





Sincerely,
Gabriel Bergin
gabr...@bergin.se

[[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] Saveing plot to multiple locations

2010-09-13 Thread David Winsemius


On Sep 13, 2010, at 5:32 AM, Joel wrote:



Hi
Im trying to save a plot both to a pdf and as just a picture but  
without

success so if someone can help me I would be happy :)


Are you trying to embed a png file in a graphic or do you just want  
two different files?


If the first (obviously the more difficult) then Paul Murrell has a  
bunch of material he has offered over the years:


cran.r-project.org/web/packages/grImport/vignettes/import.pdf

Vector graphics is the focus but citations to packages handling raster  
or bitmap graphics are included.


If it is the second, then just do one task, complete it with  
dev.off(),  which is needed to close the file, and move on to the other.


--
David



my code:

require(party)
irisct - ctree(Species ~ .,data = iris)
data(iris)
attach(iris)
pdf('/home/joel/Skrivbord/mammamu.pdf')
try(png('/home/joel/Skrivbord/mammamu1.png'))
plot(Sepal.Length, Petal.Length, col=unclass(Species))
legend(4.5, 7, levels(Species), col=plot_colors, cex=0.8, fill=1:3)
try(png('/home/joel/Skrivbord/mammamu2.png'))
plot(irisct)
dev.off()
readBin(pic,'raw',1024*1024)
readBin('/home/joel/Skrivbord/mammamu2.png','raw',1024*1024)

Ive tryed to move around the png and pdf part to see if it worked  
better if

they where in an other order but as I said without success.

//Joel
--
View this message in context: 
http://r.789695.n4.nabble.com/Saveing-plot-to-multiple-locations-tp2537133p2537133.html
Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
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] lattice: Set x-axis in italics only

2010-09-13 Thread David Winsemius


On Sep 13, 2010, at 8:50 AM, Alejo C.S. wrote:


Dear list, I making some box-and-whisker plots in R with vertebrate
data. The x axis are species names that must be in italics. I tried
with the axis function but no luck, and it seems that affects both
axes.
Any tip?


In bwplot just add:

 ..., scales=list(x=list(font=3)),

In this case (and I suppose many others) lattice is much more flexible  
than base. I initially tried what appeared to be valid strategies with  
boxplot and ended up tied in knots. Then I noticed your subject line  
and it was trivial.


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] Axis break with gap.plot()

2010-09-13 Thread David Winsemius


On Sep 13, 2010, at 10:34 AM, Filoche wrote:



Hi again everyone.

Anyone know if there's any limitation with gap.plot concerning the  
fill
color of plotted markers? I would like to fill the circles with a  
color :


library(plotrix);
gap.plot(c(1,2,3,4,10), c(1,2,3,4,10), c(5,9), pch = 21, col = red);

However, it only change the color of the line.  I tried bgcol and  
some

argument but without success.


Change pch to 19. (=solid circle)



With regards,
Phil


--
View this message in context: 
http://r.789695.n4.nabble.com/Axis-break-with-gap-plot-tp2533027p2537540.html
Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
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.


<    3   4   5   6   7   8   9   10   11   12   >