Re: [R] Encoding() and strsplit()

2008-11-07 Thread Prof Brian Ripley

See the 'R Internals' manual.

ASCII characters are not marked as Latin-1 nor UTF-8.

On Fri, 7 Nov 2008, Heinz Tuechler wrote:


Dear All,

Encoding() goes beyond my understanding. See the example. I would expect from 
reading the help for Encoding() that strsplit preserves the encoding for each 
resulting element, but for simple letters it gets lost.
Also it seems that an Encoding() cannot be declared for simple letters. They 
remain in any case unknown. In paste() latin1 seems to dominate 
unknown.
What kind of characteristic of an object is the encoding? It does not show up 
as attribute and also str() does not give me any hint.

Where can I find some explanation regarding encoding?

Thanks

Heinz

###   Encoding() and strsplit
u - 'abcäöü'
Encoding(u)
[1] latin1
Encoding(u) - 'latin1' # to be sure about encoding
us - strsplit(u, '')[[1]] # split in single strings
Encoding(us)
[1] unknown unknown unknown latin1  latin1  latin1
Encoding(us) - rep('latin1', length(us))
Encoding(us)
[1] unknown unknown unknown latin1  latin1  latin1
pus - paste(us[1], us[5], sep='')
Encoding(pus)
[1] latin1

Version:
platform = i386-pc-mingw32
arch = i386
os = mingw32
system = i386, mingw32
status = Patched
major = 2
minor = 8.0
year = 2008
month = 11
day = 04
svn rev = 46830
language = R
version.string = R version 2.8.0 Patched (2008-11-04 r46830)

Windows XP (build 2600) Service Pack 2

Locale:
LC_COLLATE=German_Austria.1252;LC_CTYPE=German_Austria.1252;LC_MONETARY=German_Austria.1252;LC_NUMERIC=C;LC_TIME=German_Austria.1252

Search Path:
.GlobalEnv, package:stats, package:graphics, package:grDevices, 
package:utils, package:datasets, package:methods, Autoloads, package:base


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



--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] FW: [rkward-devel] questions on RKWard

2008-11-07 Thread Donatas G.
To get output going into the Output tab, your either have to work
through the rkward menus, or you have to wrap up your commands in
rkward-specific code; you can get examples of the code by running any
statistical operation through the menus and checking the code produced
by rkward (it is shown beneath each interactive dialog).

Regarding the 3-rd problem, can you just check the option Do not
display this message again? Rkward, despite the warning, should display
the help output in html in a new tab.

Regarding the 1-st problem, just go into menu Settings  Configure
Rkward  General and choose your startup action...

Regarding the 2-nd problem - yes, it is strange that this kde
application does not have the standard kde dialog in Settings menu
Configure shortcuts. But in my case there are some shortcuts
predefined, like, ctrl+shift+O opens a new workspace...

Hope this helps

Donatas G.

Horace Tso rašė:
 Thought I should copy the list with Matthieu's response.

 H

 -Original Message-
 From: Matthieu Stigler [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, November 05, 2008 8:29 PM
 To: Horace Tso; [EMAIL PROTECTED]
 Subject: Re: [rkward-devel] questions on RKWard


 some answer only for the third question: do you have the package
 r-doc-html installed? (on ubuntu check with dpkg -l r-*) this is maybe
 the solution

 Horace Tso a écrit :
   
 Folks,

 I'm making progress moving from Windows to Linux and have RKward up
 and running. I read somewhere that Rkward's supposed to be the Tinn-R
 for linux and Tinn-R has worked out great for me. So naturally I'd
 like to do the following, if possible,

 1. How to ask Rkward not to load the last saved image. Right now
 whenever it starts, it loads an image from some obscure corner of my
 directory. I can't quite figure out where it gets that image from. On
 the command line, I can do --no-restore. But there seems to be no
 place to sneak in these command line options under Rkward.  A startup
 config file hidden somewhere?

 2. Customize CTRL-keys. Just out of the box, many menu options do not
 have a control key associated with them. Any way to pick my favorite key?

 3. I'm used to typing ?command on the R-console and get a HTML help
 page pops up. But when I do that, a shockingly large window comes up
 and complains in many words about some error which I can't quite
 figure out what it's saying (sorry don't have linux in front of me
 right now).

 4. I see there is an 'Output' tab by default. But command results are
 sent to R-console, and nothing seems to happen in 'Output'.

 I have R 2.7.1 running under KDE on openSUSE 10.3.

 TIA.

 Horace
 

 -
 This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
 Build the coolest Linux based applications with Moblin SDK  win great prizes
 Grand prize is a trip for two to an Open Source event anywhere in the world
 http://moblin-contest.org/redirect.php?banner_id=100url=/
 

 ___
 RKWard-devel mailing list
 [EMAIL PROTECTED]
 https://lists.sourceforge.net/lists/listinfo/rkward-devel

 

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

2008-11-07 Thread Philipp Pagel

Thank you Phil and Bert!

I was sure there must be an efficient way using some kind of
indexing trick but totally did not see the as.matrix solution.

Thanks again
Philipp


On Wed, Nov 05, 2008 at 02:59:20PM -0800, Phil Spector wrote:
 Philipp -

res = matrix(NA,5,3)
res[as.matrix(foo[,c(1,2)])] = foo$val



-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 manipulate the time data without the date?

2008-11-07 Thread Barry Rowlingson
2008/11/7 tedzzx [EMAIL PROTECTED]:

 The problem is that: There is some rounding problems, for example
 Library(chron)
 any(times(4:00:01)==times(4:00:00)+times(00:00:01)))
 False

 But,it should be true

 FAQ 7.31 in disguise!

 chron stores date-times as fractions, so you're comparing two
floating point numbers here. FAQ 7.31 applies.

 Use 'all.equal', which has a method for chron that uses a 1 second
tolerance to match times:

 all.equal(times(4:00:01),times(4:00:00)+times(00:00:01))
[1] TRUE

Barry

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


Re: [R] Encoding() and strsplit()

2008-11-07 Thread Heinz Tuechler

At 09:15 07.11.2008, Prof Brian Ripley wrote:

See the 'R Internals' manual.


Thank you, now I understand a little more.
My real problem, however is a data frame produced 
by spss.get(). Is there a simple possibility to 
mark all characters in that data.frame (except 
ASCII characters), including levels of factors to latin1?


Heinz Tüchler



ASCII characters are not marked as Latin-1 nor UTF-8.

On Fri, 7 Nov 2008, Heinz Tuechler wrote:


Dear All,

Encoding() goes beyond my understanding. See 
the example. I would expect from reading the 
help for Encoding() that strsplit preserves the 
encoding for each resulting element, but for simple letters it gets lost.
Also it seems that an Encoding() cannot be 
declared for simple letters. They remain in any 
case unknown. In paste() latin1 seems to dominate unknown.
What kind of characteristic of an object is the 
encoding? It does not show up as attribute and 
also str() does not give me any hint.

Where can I find some explanation regarding encoding?

Thanks

Heinz

###   Encoding() and strsplit
u - 'abcäöü'
Encoding(u)
[1] latin1
Encoding(u) - 'latin1' # to be sure about encoding
us - strsplit(u, '')[[1]] # split in single strings
Encoding(us)
[1] unknown unknown unknown latin1  latin1  latin1
Encoding(us) - rep('latin1', length(us))
Encoding(us)
[1] unknown unknown unknown latin1  latin1  latin1
pus - paste(us[1], us[5], sep='')
Encoding(pus)
[1] latin1

Version:
platform = i386-pc-mingw32
arch = i386
os = mingw32
system = i386, mingw32
status = Patched
major = 2
minor = 8.0
year = 2008
month = 11
day = 04
svn rev = 46830
language = R
version.string = R version 2.8.0 Patched (2008-11-04 r46830)

Windows XP (build 2600) Service Pack 2

Locale:
LC_COLLATE=German_Austria.1252;LC_CTYPE=German_Austria.1252;LC_MONETARY=German_Austria.1252;LC_NUMERIC=C;LC_TIME=German_Austria.1252

Search Path:
.GlobalEnv, package:stats, package:graphics, 
package:grDevices, package:utils, 
package:datasets, package:methods, Autoloads, package:base


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


--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] is there any way to run R method as a background process from R interface

2008-11-07 Thread Kurapati, Ravichandra (Ravichandra)
Hi ,

 

can some body tell to me how to run a R method /function as a
background process from R interface

 

Thanks

K.Ravichandra

 

 


[[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] method to return rgb values from pixels of an image

2008-11-07 Thread Hans-Joachim Klemmt

hello,

i am looking for a method to return rgb-values of predifined pixels of 
jpg images.


can anybody help me?

thank you very much

best regards

hans-joachim klemmt

--
--

Dr. Hans-Joachim Klemmt

Forstoberrat
Organisationsprogrammierer IHK


Bayerische Landesanstalt für Wald und Forstwirtschaft

zugewiesen an

Lehrstuhl für Waldwachstumskunde
Technische Universität München
Am Hochanger 13

85354 Freising

Tel.: 08161/ 7147-14
Fax : 08161/ 7147-21

eMail: [EMAIL PROTECTED]

Skype: hajo_klemmt

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

2008-11-07 Thread Petr PIKAL
Are you looking for expand.grid?

expand.grid(1:2, letters[1:2])

Petr Pikal
[EMAIL PROTECTED]
724008364, 581252140, 581252257


[EMAIL PROTECTED] napsal dne 07.11.2008 01:53:56:

 Dear R Gurus:
 
 How do you put together a 2^2 (or even 2^k) factorial problem, please?
 
 Since you have 2 levels for A and B, do you put in A+ and A- as
 factors, please?
 
 Thanks,
 Edna Bell
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Umlaut read from csv-file

2008-11-07 Thread Peter Dalgaard
Heinz Tuechler wrote:
 Dear Prof.Ripley!
 
 Thank you very much for your attention. In the given example Encoding(),
 or the encoding parameter of read.csv solve the problem. I hope your
 patch will solve also the problem, when I read a spss file by
 spss.get(), since this function has no encoding parameter and my real
 problem originated there.

read.spss() (package foreign) does have a reencode argument, though; and
 this is called by spss.get(), so it looks like an easy hack to add it
there.



-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

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


Re: [R] Agent-based social simulation and R

2008-11-07 Thread Tom Backer Johnsen

Simone Gabbriellini wrote:

Tom,

I don't know if there are better ways, but this is the way I do:

I use Python for building the AB model, and RPy as an interface to R for 
statistical analysis.
One of the best package for SNA in R is igraph, which has a nice Python 
version.
But if you prefere statnet (which is great too), you can simply handle 
it via RPy.


I've learned this strategy from Pietro Terna - 
http://web.econ.unito.it/terna/


Thank you for useful information and suggestions.  I will certainly look 
into what you mention.  I am at the moment looking at the igraph 
package, which seems to have what I need, and includes visualization as 
well.  As for Python, that is nice, but if I can do most of what I want 
in R, I would prefer that.


Tom

++
| Tom Backer Johnsen, Psychometrics Unit,  Faculty of Psychology |
| University of Bergen, Christies gt. 12, N-5015 Bergen,  NORWAY |
| Tel : +47-5558-9185Fax : +47-5558-9879 |
| Email : [EMAIL PROTECTED]URL : http://www.galton.uib.no/ |
++

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

2008-11-07 Thread Christoph Scherber

Dear all,

I am trying to bootstrap predictions from gnls models using the following code:

# a is the dataframe with which I am working; it contains the variables
# response.variable,LD,L,G,P and F

###

model=gnls(response.variable ~ a * LD/(b + LD),
params = list(a + b ~ L), start = c(1,1,1,1), data=a)

df=cbind(a,fit=predict(model,list(LD=1,L=0.5,G=0.5,P=0.46,F=2.2)))
model.bootfunc=function(rs,i){
df$response.variable=df$fit+rs[i]
as.numeric(predict(gnls(response.variable ~ a * LD/(b + LD),
params = list(a + b ~ L), start = coef(model), data=df)))
}

rs=scale(resid(model),scale=F)
(model.boot=boot(rs,model.bootfunc,R=1))
booted=boot.ci(model.boot,index=1,type=c(norm,basic,perc,bca))

###

The problem is that this code yields NA for the s.e. of the bootstrap 
statistics:

Bootstrap Statistics :
  original   biasstd. error
t1*  0.1651658 -0.020663364  NA
t2*  0.1669592 -0.021759335  NA
t3*  0.1676765 -0.001858686  NA
t4*  0.1726982 -0.025321349  NA
t5*  0.1658092  0.024721214  NA


And hence the boot.ci function and others don?t work.

Does anyone have an idea on that?

Many thanks and best wishes
Christoph



--
Dr. rer.nat. Christoph Scherber
University of Goettingen
DNPW, Agroecology
Waldweg 26
D-37073 Goettingen
Germany

phone +49 (0)551 39 8807
fax   +49 (0)551 39 8806

Homepage http://www.gwdg.de/~cscherb1

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Unexpected behavior of clocktime related to daylight savings time

2008-11-07 Thread Dennis Fisher
Colleagues,

I submitted this several days ago and no one responded, so I am trying  
again, trying a different subject line:

I just encountered some unexpected behavior of difftime in  
relationship to the change from daylight savings to standard time.

My understanding is that DST and ST take effect at 2AM.  However, the  
results below suggests that R (version 2.8.0 in OS X) implements the  
change at 2:16AM:

Expected:
  difftime(2008-11-02 02:01:00, 2008-11-02 00:59:00)
 Time difference of 2.03 hours
  difftime(2008-11-02 01:16:00, 2008-11-02 01:15:00)
 Time difference of 1 mins
  difftime(2008-11-02 01:18:00, 2008-11-02 01:17:00)
 Time difference of 1 mins

Not expected:
  difftime(2008-11-02 01:17:00, 2008-11-02 01:16:00)
 Time difference of 1.016667 hours

Can anyone explain this?

Dennis


Dennis Fisher MD
P  (The P Less Than Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-415-564-2220
www.PLessThan.com


[[alternative HTML version deleted]]

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


Re: [R] Election Maps

2008-11-07 Thread Duncan Murdoch

On 11/7/2008 8:31 AM, roger koenker wrote:

Those of you with an interest in the US election and/or
statistical graphics may find the maps at:

http://www-personal.umich.edu/~mejn/election/2008/

interesting.



Nice stuff.  Do you know if anyone has ported the cartogram code to R? 
I see a question on the list a couple of years ago


https://stat.ethz.ch/pipermail/r-help/2006-May/106501.html

but I don't see a positive answer...

Duncan Murdoch

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


Re: [R] Applying a function to a list of arguments ...

2008-11-07 Thread Gabor Grothendieck
Try this:

func - function(f, ...) f(...)

# e.g.
func(sin, 0) # same as sin(0)
func(max, 1, 2) # same as max(1, 2)

On Fri, Nov 7, 2008 at 5:21 AM,  [EMAIL PROTECTED] wrote:
 How can I apply function f, that I get as an argument as in

 func - function(f, ...) {
 .
 .
 .
 }

 to a list of arguments list(a, b, c) (eg the ... argument of func above)
 in order to obtain

 f(a, b, c)

 Thanks a lot,

 Roberto

[[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] Agent-based social simulation and R

2008-11-07 Thread Simone Gabbriellini

Tom,

I don't know if there are better ways, but this is the way I do:

I use Python for building the AB model, and RPy as an interface to R  
for statistical analysis.
One of the best package for SNA in R is igraph, which has a nice  
Python version.
But if you prefere statnet (which is great too), you can simply handle  
it via RPy.


I've learned this strategy from Pietro Terna - http://web.econ.unito.it/terna/

hope it helps,
Simone Gabbriellini



Il giorno 07/nov/08, alle ore 13:06, Tom Backer Johnsen ha scritto:

Do anyone know anything about the use of R for agent-based social  
simulation?  It should be possible, and would be convenient for the  
simple reason that there are several nice packages containing useful  
stuff for SNA (Social Network Analysis).  Information about  
packages, web sites, experienced persons in the field, etc. would be  
very welcome.


Tom
++
| Tom Backer Johnsen, Psychometrics Unit,  Faculty of Psychology |
| University of Bergen, Christies gt. 12, N-5015 Bergen,  NORWAY |
| Tel : +47-5558-9185Fax : +47-5558-9879 |
| Email : [EMAIL PROTECTED]URL : http://www.galton.uib.no/ |
++

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




dott. Simone Gabbriellini - PhD Student
Department of Social Sciences
University of Pisa
[EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] two kind of Hosmer and Lemeshow’s test

2008-11-07 Thread leo_wa

I know that there are two method to apply the Hosmer and Lemeshow’s.  One of
them is calculated based on the fixed and pre-determined cut-off points of
the estimated probability of success.  One of them is calculated based on
the percentiles of estimated probabilities.  
In the previous post,i find that the Hosmer and Lemeshow’s test how to use
in R.
hosmerlem -
function (y, yhat, g = 10) 
{
cutyhat - cut(x, breaks = quantile(yhat, probs = seq(0, 
1, 1/g)), include.lowest = T)
obs - xtabs(cbind(1 - y, y) ~ cutyhat)
expect - xtabs(cbind(1 - yhat, yhat) ~ cutyhat)
chisq - sum((obs - expect)^2/expect)
P - 1 - pchisq(chisq, g - 2)
c(X^2 = chisq, Df = g - 2, P(Chi) = P)
}
I want to know how can i use the another method which is not use the
probability of success. i want to know how can i revise above program to
achieve an objective.
-- 
View this message in context: 
http://www.nabble.com/two-kind-of-Hosmer-and-Lemeshow%E2%80%99s-test-tp20380578p20380578.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Umlaut read from csv-file

2008-11-07 Thread Heinz Tuechler

At 13:34 07.11.2008, Peter Dalgaard wrote:

Heinz Tuechler wrote:
 Dear Prof.Ripley!

 Thank you very much for your attention. In the given example Encoding(),
 or the encoding parameter of read.csv solve the problem. I hope your
 patch will solve also the problem, when I read a spss file by
 spss.get(), since this function has no encoding parameter and my real
 problem originated there.

read.spss() (package foreign) does have a reencode argument, though; and
 this is called by spss.get(), so it looks like an easy hack to add it
there.


Thank you, that means, I have to change spss.get 
to make it accept the reencode argument and pass 
it to read.spss. At the moment I prefer to step 
back to R 2.7.2 and to wait for a more general 
solution, because to me, there seem to be still strange effects of encoding.


In the following example the encoding gets lost 
by dumping and rereading, even if I use the 
encoding parameter of source(). But may be, I 
don't understand what this parameter should do.


Heinz Tüchler


us - c(a, b, c, ä, ö, ü)
Encoding(us)
[1] unknown unknown unknown latin1  latin1  latin1
dump('us', 'us_dump.txt')
rm(us)
source('us_dump.txt', encoding='latin1')
us
[1] a b c ä ö ü
Encoding(us)
[1] unknown unknown unknown unknown unknown unknown
unlink('us_dump.txt')






--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907


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


Re: [R] Election Maps

2008-11-07 Thread hadley wickham
On Fri, Nov 7, 2008 at 7:53 AM, Duncan Murdoch [EMAIL PROTECTED] wrote:
 On 11/7/2008 8:31 AM, roger koenker wrote:

 Those of you with an interest in the US election and/or
 statistical graphics may find the maps at:

http://www-personal.umich.edu/~mejn/election/2008/

 interesting.


 Nice stuff.  Do you know if anyone has ported the cartogram code to R? I see
 a question on the list a couple of years ago

 https://stat.ethz.ch/pipermail/r-help/2006-May/106501.html

 but I don't see a positive answer...

The source code (in C) for this type of cartogram (Diffusion-based
method for producing density equalizing maps) is available from here:
http://www-personal.umich.edu/~mejn/cart/download/

Hadley


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


[R] x axe values

2008-11-07 Thread Laura Poggio
Dear list,
I have to draw a simple plot. On y axe some numerical values that correspond
to various categories on axe x.
The table I am reading looks like:

cat Obj1 Obj2 Obj3
max 23 27 34
ave 21 25 32
min 19 23 30

In order to avoid that the first column is reordered alphabetically I used:
(found here http://tolstoy.newcastle.edu.au/R/help/06/09/33808.html)

a - as.character(table$cat)
table$cat = factor(a, levels=a)

However if I use plot() I get thick lines instead of points because of the
reason explained in the link above. If I use plot.default() I get number on
the x axe instead of the name of the categories.

1) first question: any solution?

An alternative could be to use plot.default() and then to change the value
on the axe.

2) second question: how to chnage the value of the axes? not the label, but
the values themself?

Thank you very much in advance

Laura

[[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] [newbie] scatterplot with marginal histograms (done) and axes labels

2008-11-07 Thread KarstenW

Hello,

I am stuck when I want to add axes labels to my scatterplot with histograms.
I guess it must be something  with par(mar=) or so, but could someone give
me a hint?

Here is what I got so far:

# adapted from
http://www.stat.ucl.ac.be/ISdidactique/comment/fichiers/r/scatterhist.rs and
from ?layout
#
# see also: 
# - http://biom1.univ-lyon1.fr/ADE-4/ade4-html/s.hist.html (a function
called s.hist in package ade4)
# - http://www.statmethods.net/graphs/scatterplot.html (shows how to do
some nice scatterplots, 
#   e.g. with the function scatterplot in package car)

scatterhist=function(x,y, xlab=, ylab=){
 #oldpar = par(no.readonly = TRUE) # save default, for resetting...
 zones=matrix(c(2,0,1,3),ncol=2,byrow=TRUE)
 layout(zones,widths=c(4/5,1/5),heights=c(1/5,4/5))
 xhist - hist(x, plot=FALSE)
 yhist - hist(y, plot=FALSE)
 top - max(c(xhist$counts, yhist$counts))
 par(mar=c(3,3,1,1))
 plot(x,y, xlab=xlab, ylab=ylab)
 par(mar=c(0,3,1,1))
 barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0)
 par(mar=c(3,0,1,1))
 barplot(yhist$counts, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE)
 #par(oldpar) # reset to default
}

Now if I do
 x=rnorm(50)
 y=rnorm(50)
 scatterhist(x,y,xlab=x, ylab=y)

there are no axes labels.
I also wonder why R complains if I uncomment the first and last line in the
function (invalid value
for parameter fig specified).

Any hint appreciated,
Karsten.
-- 
View this message in context: 
http://www.nabble.com/-newbie--scatterplot-with-marginal-histograms-%28done%29-and-axes-labels-tp20381450p20381450.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Umlaut read from csv-file

2008-11-07 Thread Prof Brian Ripley

On Fri, 7 Nov 2008, Peter Dalgaard wrote:


Heinz Tuechler wrote:

Dear Prof.Ripley!

Thank you very much for your attention. In the given example Encoding(),
or the encoding parameter of read.csv solve the problem. I hope your
patch will solve also the problem, when I read a spss file by
spss.get(), since this function has no encoding parameter and my real
problem originated there.


read.spss() (package foreign) does have a reencode argument, though; and
this is called by spss.get(), so it looks like an easy hack to add it
there.


Yes, older software like spss.get needs to get updated for the 
internationalization age.  Modifying it to have a ... argument passed to 
read.spss would be a good idea (and future-proofing).


In cases like this it is likely that the SPSS file does contain its 
encoding (although sometimes it does not and occasionally it is wrong), so 
it is helpful to make use of the info if it is there.  However, the 
default is read.spss(reencode=NA) because of the problems of assuming that 
the info is correct when it is not are worse.


--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] clogit and small sample sizes: what to do?

2008-11-07 Thread Johannes Elias
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Conditional logistic regression and small sample sizes: what to do?

Dear R-Gurus,

[I run R 2.8.0 on WinXP. I have no formal training in statistics.]

Please feel free to skip the 'Blah blah part' for questions below.

- ---Blah blah part
Why I use clogit (package 'survival')?: I am looking for risk factors
for cases during a recent small flare-up of disease in a hospital. To
this end I matched 11 cases (no more of them, sorry!) with 33 controls
based on sex. The next step was to perform conditional logistic
regression to evaluate risk 'exposures' for cases.

Now clogit() (Package 'survival') produces some conflicting results:

Briefly, 10 of 11 cases have a certain exposure, compared to 9 of 33
controls. The odds ratio is significant (p-value = 0.000311) while the
output of clogit() is inconclusive (.95 confidence intervals for risk
factor range from 0 to infinity, conflicting 'likelihood ratio test' and
'Wald test') plus produces following warning message, Warning message:
In fitter(X, Y, strats, offset, init, control, weights = weights,: Ran
out of iterations and did not converge. Tampering with the data (i.e.
reducing the number of cases with the exposure to 7 of 11) renders the
odds ratio unsignificant (p-value = 0.06681), yet makes clogit() assign
a significant p-value to the exposure in question (0.043). Furthermore,
the warning message is gone after the tampering.

Interestingly reducing (instead of increasing) cases with the risk
factor yields a significant result with clogit().

I believe now, that this behaviour might be due to small sample size.
Now I am looking for an R package to maybe circumvent this limitation of
clogit(). (Alternatively, I could just chuck the project and order a
Margerita. Maybe the risk factor is plainly not significant after all.
But I digress...)

Six years ago, the following message was posted to this list:

   -old post 2002
Dear R folks,
We completed a matched case-control study that was analyzed using
conditional logistic regression. Because of the small sample size we
need to calculate exact confidence intervals. The quick solution is to
purchase LogExact by Cytel. However, we'd like to do this in R. Anyone
have experience with this?

Many thanks,
Tomas

Tomas Aragon, MD, DrPH
   -old post 2002 end

At that time, the answers were not too encouraging. Anyway, I might have
the very same query 2008.

Ok, I tried to do some homework and started to look for packages maybe
implementing different methods. I did run across 'elrm' (Zamar, D.,
McNeney, B.  Graham, J., 2007), but I am unsure whether this package is
appropriate for my original 1:3 matched design.

- ---Blah blah part end


- ---Questions, finally!---
So my questions to you are:

1) Is the problem I describe above likely related to small sample sizes?
2) Do you have experience with 'elrm' or packages finding a solution for
the above problem? Is 1:n matching as in clogit() possible?

- ---Questions, finally! end---

Thank you for your time and effort,

Johannes







-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkUZLsACgkQeixPRMMDSjthxwCgpe0ACd6qrMVCz60yzVfzML2K
EpMAnRnrfbWDrZ29TLFKMCe+bH/YrNZI
=hb1P
-END PGP SIGNATURE-

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


Re: [R] Unexpected behavior of clocktime related to daylight savings time

2008-11-07 Thread Prof Brian Ripley

On Fri, 7 Nov 2008, Dennis Fisher wrote:


Colleagues,

I submitted this several days ago and no one responded, so I am trying
again, trying a different subject line:


Well, you posted something that indicated you had not studied the relevant 
help pages, without the information requested in the R posting guide, and 
with an HTML posting.



I just encountered some unexpected behavior of difftime in
relationship to the change from daylight savings to standard time.

My understanding is that DST and ST take effect at 2AM.  However, the
results below suggests that R (version 2.8.0 in OS X) implements the
change at 2:16AM:


The transition time depends on the country (and in some cases, the year).
In the EU it is at 2am (and always has been, not that the EU is very old).


Expected:

difftime(2008-11-02 02:01:00, 2008-11-02 00:59:00)

Time difference of 2.03 hours

difftime(2008-11-02 01:16:00, 2008-11-02 01:15:00)

Time difference of 1 mins

difftime(2008-11-02 01:18:00, 2008-11-02 01:17:00)

Time difference of 1 mins


Not expected:

difftime(2008-11-02 01:17:00, 2008-11-02 01:16:00)

Time difference of 1.016667 hours


Can anyone explain this?


Yes, and you should have been able to do so from the information in the 
help pages.  As ?strptime says


 Remember that in most timezones some times do not occur and some
 occur twice because of transitions to/from summer time.  What
 happens in those cases is OS-specific.

See also the note on ?Sys.timezone.  No OS I tried did this, not even Mac 
OS X set to EST5EDT.  But in EST5EDT 2008-11-02 01:17:00 occurred twice:



as.POSIXct(2008-11-02 01:17:00)

[1] 2008-11-02 01:17:00 EDT

as.POSIXct(2008-11-02 01:17:00) + 3600

[1] 2008-11-02 01:17:00 EST

so 1.016667 hours would be one of two correct answers in that timezone.

However, you didn't tell us what timezone you are in and hence we cannot 
know when DST transitions occur in that timezone.




Dennis


Dennis Fisher MD
P  (The P Less Than Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-415-564-2220
www.PLessThan.com


--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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

2008-11-07 Thread Prof Brian Ripley

On Fri, 7 Nov 2008, Christoph Scherber wrote:


Dear all,

I am trying to bootstrap predictions from gnls models using the following 
code:


# a is the dataframe with which I am working; it contains the variables
# response.variable,LD,L,G,P and F


And without it your code is not reproducible.



###

model=gnls(response.variable ~ a * LD/(b + LD),
   params = list(a + b ~ L), start = c(1,1,1,1), data=a)

df=cbind(a,fit=predict(model,list(LD=1,L=0.5,G=0.5,P=0.46,F=2.2)))
model.bootfunc=function(rs,i){
df$response.variable=df$fit+rs[i]
as.numeric(predict(gnls(response.variable ~ a * LD/(b + LD),
   params = list(a + b ~ L), start = coef(model), data=df)))
}

rs=scale(resid(model),scale=F)
(model.boot=boot(rs,model.bootfunc,R=1))
booted=boot.ci(model.boot,index=1,type=c(norm,basic,perc,bca))


Do please try to make your code readable, using spaces and - for 
assignments.  I would have spotted the problem much sooner with legible, 
reproducible code.



###

The problem is that this code yields NA for the s.e. of the bootstrap 
statistics:


Bootstrap Statistics :
 original   biasstd. error
t1*  0.1651658 -0.020663364  NA
t2*  0.1669592 -0.021759335  NA
t3*  0.1676765 -0.001858686  NA
t4*  0.1726982 -0.025321349  NA
t5*  0.1658092  0.024721214  NA


And hence the boot.ci function and others don?t work.

Does anyone have an idea on that?


Yes: how can you estimate standard errors from a single sample (you set 
R=1)?



Many thanks and best wishes
Christoph



--
Dr. rer.nat. Christoph Scherber
University of Goettingen
DNPW, Agroecology
Waldweg 26
D-37073 Goettingen
Germany

phone +49 (0)551 39 8807
fax   +49 (0)551 39 8806

Homepage http://www.gwdg.de/~cscherb1

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



--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [R] Applying a function to a list of arguments ...

2008-11-07 Thread Duncan Murdoch

On 11/7/2008 5:40 AM, baptiste auguie wrote:

perhaps something like,


func - function(f, ...) {
do.call(f, ...)
}

func(rnorm, list(n=3, mean=2, sd=3))


Alternatively, if the caller doesn't want to put the args in a list, 
your func can do it:


func2 - function(f, ...) {
  do.call(f, list(...))
}

func2(rnorm, n=3, mean=2, sd=3)





baptiste


On 7 Nov 2008, at 10:21, [EMAIL PROTECTED] wrote:


How can I apply function f, that I get as an argument as in

func - function(f, ...) {
.
.
.
}

to a list of arguments list(a, b, c) (eg the ... argument of func  
above)

in order to obtain

f(a, b, c)

Thanks a lot,

Roberto

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


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] is there any way to run R method as a background process from R interface

2008-11-07 Thread Philippe Grosjean

Hello,

Two approaches depending when you want to trigger this background 
calculation:


1) It is enough to trigger the background computation after each 
top-level instruction entered at the command line: use ?addTaskCallback


2) You want to trigger the background calculation at a given time, or 
redo it every xxx ms. This is a little bit more complicate. I have 
success using the tcltk package and the 'after' Tcl function.


Best,

Philippe Grosjean

..°}))
 ) ) ) ) )
( ( ( ( (Prof. Philippe Grosjean
 ) ) ) ) )
( ( ( ( (Numerical Ecology of Aquatic Systems
 ) ) ) ) )   Mons-Hainaut University, Belgium
( ( ( ( (
..

Kurapati, Ravichandra (Ravichandra) wrote:

Hi ,

 


can some body tell to me how to run a R method /function as a
background process from R interface

 


Thanks

K.Ravichandra

 

 



[[alternative HTML version deleted]]

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



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


[R] Updating Packages with Personal Library

2008-11-07 Thread Alan Lue
I'm having trouble running `updates.packages()' and installing into a
personal library.

Setup:
1. .Renviron file contains: R_LIBS_USER=~/lib/R/%p-library/%v
2. Hence personal library is: ~/lib/R/i486-pc-linux-gnu-library/2.6/
3. Library path upon starting R:

 .libPaths()
[1] /home/johnny/lib/R/i486-pc-linux-gnu-library/2.6
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library

That's the setup.  The problem is that `update.packages()' does not consider
packages in my personal library when determining what to update.  To
elaborate:

Here's some output when I update packages:

 update.packages(instlib=.libPaths()[1])
KernSmooth :
 Version 2.22-21 installed in /usr/lib/R/library
 Version 2.22-22 available at http://cran.cnr.Berkeley.edu
Update (y/N/c)?
...

I answer yes to everything, and the update succeeds; updated packages are
installed into my personal library,
`~/lib/R/i486-pc-linux-gnu-library/2.6/'.  But if I run the package update
command again, immediately after having just run it, I get the exact same
output:

 update.packages(instlib=.libPaths()[1])
KernSmooth :
 Version 2.22-21 installed in /usr/lib/R/library
 Version 2.22-22 available at http://cran.cnr.Berkeley.edu
Update (y/N/c)?

R looked in `/usr/lib/R/library', saw that there was a package that needed
updating, and neglected the fact that the updated package was already in my
personal library.

How can I get R to check packages in my personal library while determining
what to update?

Alan

[[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] [solved] sapply and median, possible or not ?

2008-11-07 Thread Ptit_Bleu

Thanks a lot Keith : your function does the job (but I don't understand the
trick) !
Have a nice week-end (Thanks to you, I can have a good one :-)),
Ptit Bleu.


-
median.data.frame - function(x, ...)
sapply(x, median, ...)


I haven't tried it, but it might work

hth

Keith J
-- 
View this message in context: 
http://www.nabble.com/sapply-and-median%2C-possible-or-not---tp20378222p20379667.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Bootstrapping gnls models

2008-11-07 Thread Christoph Scherber

Dear all,

Here comes a reproducible example, with the original data added.

The error message when running boot() is:
Error in gnls(response.variable ~ a * LD/(b + LD), params - list(a +  :
  Step halving factor reduced below minimum in NLS step

boot() in this case only seems to work for very small values of R (say, within [1..5]), which is of 
course not desirable. Maybe this is due to problems with model convergence.


I would very much appreciate any help.

###
LD=c(4.087462841,2.321928095,4.087462841,1,1,4.087462841,2.321928095,1,1,2.321928095,4.087462841,2.321928095,5.930737338,2.321928095,5.930737338,1,1,2.321928095,2.321928095,4.087462841,1,1,2.321928095,4.087462841,4.087462841,1,2.321928095,1,4.087462841,2.321928095,1,2.321928095,5.930737338,4.087462841,1,4.087462841,2.321928095,4.087462841,5.930737338,4.087462841,1,2.321928095,2.321928095,1,2.321928095,1,1,4.087462841,4.087462841,2.321928095)
L=c(1,1,0,1,0,0,1,0,0,0,1,0,1,1,1,0,0,1,0,0,0,1,1,1,1,0,1,0,0,0,1,0,1,1,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,0)

response.variable=c(0.335737179487179,0.391025641025641,0.391826923076923,0.487980769230769,0.294070512820513,0.507211538461538,0.3958333,0.0825320512820513,0.443108974358974,0.290064102564103,0.59775641025641,0.514423076923077,0.65625,0.193910256410256,0.4479167,0,0.2604167,0.407852564102564,0.44150641025641,0.596153846153846,0.0600961538461538,0.21875,0.256410256410256,0.3645833,0.435096153846154,0.0793269230769231,0.249198717948718,0.0304487179487179,0.230769230769231,0.485576923076923,0.684294871794872,0.0737179487179487,0.490384615384615,0.599358974358974,0.215544871794872,0.219551282051282,0.602564102564103,0.907852564102564,0.391025641025641,0.43349358974359,0.0384615384615385,0.337339743589744,0.502403846153846,0.405448717948718,1,0.362980769230769,0.116185897435897,0.459134615384615,0.661057692307692,0.0769230769230769)

a=data.frame(LD,L,response.variable)

model=gnls(model = response.variable ~ a * LD/(b + LD), data = a,
params = list(a + b ~ L), start = c(1, 1, 1, 1))

df-cbind(a,fit-as.numeric(predict(model,list(LD=1,L=0.5
rs-scale(resid(model),scale=F)

model.bootfunc-function(rs,i){
df$response.variable-df$fit+rs[i]
as.numeric(predict(gnls(response.variable ~ a * LD/(b + LD),
  params - list(a + b ~ L), start = coef(model), data=df)))
}

(model.boot-boot(rs,model.bootfunc,R=100))
booted-boot.ci(model.boot,index=1,type=c(norm))
booted$t0
booted$normal

###

Best wishes,
Christoph.


Prof Brian Ripley schrieb:

On Fri, 7 Nov 2008, Christoph Scherber wrote:


Dear all,

I am trying to bootstrap predictions from gnls models using the 
following code:


# a is the dataframe with which I am working; it contains the variables
# response.variable,LD,L,G,P and F


And without it your code is not reproducible.



###

model=gnls(response.variable ~ a * LD/(b + LD),
   params = list(a + b ~ L), start = c(1,1,1,1), data=a)

df=cbind(a,fit=predict(model,list(LD=1,L=0.5,G=0.5,P=0.46,F=2.2)))
model.bootfunc=function(rs,i){
df$response.variable=df$fit+rs[i]
as.numeric(predict(gnls(response.variable ~ a * LD/(b + LD),
   params = list(a + b ~ L), start = coef(model), data=df)))
}

rs=scale(resid(model),scale=F)
(model.boot=boot(rs,model.bootfunc,R=1))
booted=boot.ci(model.boot,index=1,type=c(norm,basic,perc,bca))


Do please try to make your code readable, using spaces and - for 
assignments.  I would have spotted the problem much sooner with legible, 
reproducible code.



###

The problem is that this code yields NA for the s.e. of the 
bootstrap statistics:


Bootstrap Statistics :
 original   biasstd. error
t1*  0.1651658 -0.020663364  NA
t2*  0.1669592 -0.021759335  NA
t3*  0.1676765 -0.001858686  NA
t4*  0.1726982 -0.025321349  NA
t5*  0.1658092  0.024721214  NA


And hence the boot.ci function and others don?t work.

Does anyone have an idea on that?


Yes: how can you estimate standard errors from a single sample (you set 
R=1)?



Many thanks and best wishes
Christoph



--
Dr. rer.nat. Christoph Scherber
University of Goettingen
DNPW, Agroecology
Waldweg 26
D-37073 Goettingen
Germany

phone +49 (0)551 39 8807
fax   +49 (0)551 39 8806

Homepage http://www.gwdg.de/~cscherb1

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] sapply and median, possible or not ?

2008-11-07 Thread Ptit_Bleu

Unfortunately, I have the same error message.
lapply(rowsplit, function(x)mean(x[,sapply(x, is.numeric)])) works but not
with median.
Strange, isn't it?

Any other idea?

Thanks in advance,
Ptit Bleu.


Henrique Dallazuanna wrote:
 
 Try this:
 
 lapply(l, function(x)median(x[,sapply(x, is.numeric)]))
 
 
 -- 
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O
 
   [[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.
 
 

-- 
View this message in context: 
http://www.nabble.com/sapply-and-median%2C-possible-or-not---tp20378222p20378663.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] [newbie] scatterplot with marginal histograms (done) and axes labels

2008-11-07 Thread KarstenW

Hello,
sometimes it helps if I formulate my problem. I tried the following after I
posted my previous post.

scatterhist=function(x,y, xlab=, ylab=){
 #oldpar = par(no.readonly = TRUE) # save default, for resetting...
 zones=matrix(c(2,0,1,3),ncol=2,byrow=TRUE)
 layout(zones,widths=c(4/5,1/5),heights=c(1/5,4/5))
 xhist - hist(x, plot=FALSE)
 yhist - hist(y, plot=FALSE)
 top - max(c(xhist$counts, yhist$counts))
 par(mar=c(3,3,1,1))
 plot(x,y)
 par(mar=c(0,3,1,1))
 barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0)
 par(mar=c(3,0,1,1))
 barplot(yhist$counts, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE)
 par(oma=c(3,3,0,0))
 mtext(xlab, side=1, line=1, outer=TRUE, adj=0)
 mtext(ylab, side=2, line=1, outer=TRUE, adj=0)
 #par(oldpar) # reset to default
}

This works quite nice in the R Gui (the labels appear, but it is not easy
for me to center them). However, when I use the function in a Sweave
context, i.e.

\begin{Scode}{fig=true, echo=false, results=hide}
print(scatterhist(x,y, x, y))
\end{Scode}

the labels still do not appear...

Kind regards,
Karsten.


KarstenW wrote:
 
 Hello,
 
 I am stuck when I want to add axes labels to my scatterplot with
 histograms. I guess it must be something  with par(mar=) or so, but could
 someone give me a hint?
 
 Here is what I got so far:
 
 # adapted from
 http://www.stat.ucl.ac.be/ISdidactique/comment/fichiers/r/scatterhist.rs
 and from ?layout
 #
 # see also: 
 # - http://biom1.univ-lyon1.fr/ADE-4/ade4-html/s.hist.html (a function
 called s.hist in package ade4)
 # - http://www.statmethods.net/graphs/scatterplot.html (shows how to
 do some nice scatterplots, 
 #   e.g. with the function scatterplot in package car)
 
 scatterhist=function(x,y, xlab=, ylab=){
  #oldpar = par(no.readonly = TRUE) # save default, for resetting...
  zones=matrix(c(2,0,1,3),ncol=2,byrow=TRUE)
  layout(zones,widths=c(4/5,1/5),heights=c(1/5,4/5))
  xhist - hist(x, plot=FALSE)
  yhist - hist(y, plot=FALSE)
  top - max(c(xhist$counts, yhist$counts))
  par(mar=c(3,3,1,1))
  plot(x,y, xlab=xlab, ylab=ylab)
  par(mar=c(0,3,1,1))
  barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0)
  par(mar=c(3,0,1,1))
  barplot(yhist$counts, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE)
  #par(oldpar) # reset to default
 }
 
 Now if I do
 x=rnorm(50)
 y=rnorm(50)
 scatterhist(x,y,xlab=x, ylab=y)
 
 there are no axes labels.
 I also wonder why R complains if I uncomment the first and last line in
 the function (invalid value
 for parameter fig specified).
 
 Any hint appreciated,
 Karsten.
 

-- 
View this message in context: 
http://www.nabble.com/-newbie--scatterplot-with-marginal-histograms-%28done%29-and-axes-labels-tp20381450p20382242.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Vectorizing sample()

2008-11-07 Thread Stephen Collins
I am simulating sickness among a group of families.  Part of the task is 
to randomly draw who in the family will be sick, randomly drawing from 
family ID's where Dad =1, Mom = 2, Kid1 = 3, Kid2 = 4., etc.  My census of 
Dads is of the form shown below. 

Dad_ID  Spouse (Y=1;N=0)#Kids #People_Becoming_Sick
1   1   0   1
2   0   2   2
3   1   0   2
4   1   3   3
...

The end output needed is if 3 people in a family are to be sick, was it 
the dad and two kids, with random family ID's =  {1,3,4}, or the mom, dad, 
and one kid,  with random family ID's =  {2,1,4}, etc..  The complication 
is that length of the family ID's to choose from and the associated 
sampling probabilities -- changes with each family.   I could loop through 
the Dads, from i in 1:nrow(census), but is there a way I could vectorize 
sample() to get at the same objective? 

My attempts to use the apply-based functions have dead ended.  Other ideas 
to vectorize this problem are warmly welcomed.



Regards,
 
Stephen Collins, MPP | Analyst
Health  Benefits | Aon Consulting
200 East Randolph, Suite 900, Chicago, IL
Tel: 312-381-2578 | Fax: 312-381-0136
Email: [EMAIL PROTECTED]
 
Aon Consulting selected by the readers of Business Insurance as the “Best 
Employee Benefit Consulting Firm” in 2006, 2007, and 2008
 
NOTE: The information contained in this transmission, including any 
attachment(s) is only for the use of the intended individual(s) or entity, 
and may contain information that is privileged and confidential. If the 
reader of this message is not an intended recipient, you are hereby 
notified that any dissemination, distribution, disclosure, or copying of 
this information is unauthorized and strictly prohibited. If you have 
received this communication in error, please contact the sender 
immediately by reply email and destroy all copies of the original message.
 

[[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] Mismatch in logical result?

2008-11-07 Thread Heinz Tuechler

Maybe this?
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

At 11:23 07.11.2008, Shubha Vishwanath Karanth wrote:

Content-Type: text/plain
Content-Disposition: inline
Content-length: 569



Hi R,



I have certain checkings, which gives FALSE, but 
actually it is true. Why does this happen? Note 
that the equations that I am checking below are 
not even the case of recurring decimals...




 1.4^2 == 1.96

[1] FALSE



 1.2^3==1.728

[1] FALSE





Thanks in advance, Shubha

Shubha Karanth | Amba Research

Ph +91 80 3980 8031 | Mob +91 94 4886 4510

Bangalore * Colombo * London * New York * San 
José * Singapore * www.ambaresearch.com




This e-mail may contain confidential and/or privileged i...{{dropped:13}}


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

2008-11-07 Thread ARNAUD_MOSNIER
Dear R Users,

May be this message should be directy send to Douglas Bates ...
I just want to know if I can use the AIC value given in the output of an lmer 
model to classify my logistic models.
I heard that the AIC value given in GLIMMIX output (SAS) is false because it 
come from a calculation based on pseudo-likelyhood.
Is it the same for lmer ???

thanks,

Arnaud



Arnaud MOSNIER
Biologiste Ph.D.

Département de Biologie
Université du Québec à Rimouski
300 Allée des Ursulines Rimouski, Québec, G5L 3A1
Tél. : 723-1986 poste 1653
E-mail : [EMAIL PROTECTED]


[[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] ordinal logistic model with pre-defined coefficients

2008-11-07 Thread kazys . o . simutis
Hi,

I'm trying to fit a proportional ordinal logistic model using function 
polr() (package MASS).

Is there a way to fix certain betas in the regression (e.g. function 
arima() allows this by defining fixed )
Maybe there is another function than polr() which allows that?



Thanks
Kazys
[[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] Updating Packages with Personal Library

2008-11-07 Thread Alan Lue
Test.

On Fri, Nov 7, 2008 at 2:40 AM, Alan Lue [EMAIL PROTECTED] wrote:

 I'm having trouble running `updates.packages()' and installing into a
 personal library.

 Setup:
 1. .Renviron file contains: R_LIBS_USER=~/lib/R/%p-library/%v
 2. Hence personal library is: ~/lib/R/i486-pc-linux-gnu-library/2.6/
 3. Library path upon starting R:

  .libPaths()
 [1] /home/johnny/lib/R/i486-pc-linux-gnu-library/2.6
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

 That's the setup.  The problem is that `update.packages()' does not
 consider packages in my personal library when determining what to update.
 To elaborate:

 Here's some output when I update packages:

  update.packages(instlib=.libPaths()[1])
 KernSmooth :
  Version 2.22-21 installed in /usr/lib/R/library
  Version 2.22-22 available at http://cran.cnr.Berkeley.edu
 Update (y/N/c)?
 ...

 I answer yes to everything, and the update succeeds; updated packages are
 installed into my personal library,
 `~/lib/R/i486-pc-linux-gnu-library/2.6/'.  But if I run the package update
 command again, immediately after having just run it, I get the exact same
 output:

  update.packages(instlib=.libPaths()[1])
 KernSmooth :
  Version 2.22-21 installed in /usr/lib/R/library
  Version 2.22-22 available at http://cran.cnr.Berkeley.edu
 Update (y/N/c)?

 R looked in `/usr/lib/R/library', saw that there was a package that needed
 updating, and neglected the fact that the updated package was already in my
 personal library.

 How can I get R to check packages in my personal library while determining
 what to update?

 Alan


[[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] need help in plotting barchart

2008-11-07 Thread Petr PIKAL
Kurapati, Ravichandra \(Ravichandra\) 
[EMAIL PROTECTED] napsal dne 07.11.2008 11:06:28:

 Hi
I want NA counts also.


Well

barley[5:15, 1] - NA
barchart(yield ~ variety | site, data = barley,
  groups = year, layout = c(1,6),
  ylab = Barley Yield (bushels/acre),
  scales = list(x = list(abbreviate = TRUE,
minlength = 5)))

works and bars with NA values are missing but all labels are preserved.

So obviously everything works. Without reproducible example what you did 
and what and how something is not as you expect it is rather difficult to 
provide suitable advice.

Regards
Petr 


 
 K.Ravi 
 
 -Original Message-
 From: Petr PIKAL [mailto:[EMAIL PROTECTED] 
 Sent: Friday, November 07, 2008 3:31 PM
 To: Kurapati, Ravichandra (Ravichandra)
 Cc: r-help@r-project.org
 Subject: Odp: [R] need help in plotting barchart
 
 Hi
 
 I did not see any response and will not give you any answer too, just a 
 hint. Your code can not be reproduced and it is also difficult to say
 what 
 you really want.
 
 Eg. this is rather confusing.
 
  On a generated plot  I observed that what ever records have counts as
  NA, those are not suppressed. but I don't want them to be
 suppressed.
 
 Do you want NA to be suppressed or not?
 
 I would
 
 ensure my data frame has variables with correct class and then I would 
 select those with non zero and non NA counts by e.g.
 
 Df.OK - Df[which(Df$counts),]
 
 if you want to drop unused levels of factor you can use e.g. drop=T in 
 subseting this factor
 
 Regards
 Petr
 
 
 [EMAIL PROTECTED] napsal dne 06.11.2008 12:30:13:
 
  Df contains 
  
   Session_Setup   DCT RevDataVols_bincounts
  comp
  
  1Session_Setup   RLL   1NA
  Session_Setup+RLL+1
  
  2Session_Setup   RLL   2NA
  Session_Setup+RLL+2
  
  3Session_Setup   RLL   3NA
  Session_Setup+RLL+3
  
  4Session_Setup   RLL   4NA
  Session_Setup+RLL+4
  
  5Session_Setup   RLL   5NA
  Session_Setup+RLL+5
  
  6Session_Setup   RLL   6NA
  Session_Setup+RLL+6
  
  7Session_Setup   RLL   7NA
  Session_Setup+RLL+7
  
  8Session_Setup   RLL   8NA
  Session_Setup+RLL+8
  
  9Session_Setup   RLL   9NA
  Session_Setup+RLL+9
  
  10   Session_Setup   RLL  10NA
  Session_Setup+RLL+10
  
  11   Session_Setup   RLL  11NA
  Session_Setup+RLL+11
  
  12   Session_Setup   RLL  12NA
  Session_Setup+RLL+12
  
  13   Session_Setup   RLL  13NA
  Session_Setup+RLL+13
  
  14   Session_Setup   RLL  14NA
  Session_Setup+RLL+14
  
  15   Session_Setup   RLL  15NA
  Session_Setup+RLL+15
  
  16   Session_Setup   RLL  16NA
  Session_Setup+RLL+16
  
  17   Session_Setup   RLL  17NA
  Session_Setup+RLL+17
  
  18   Session_Setup   RLL  18NA
  Session_Setup+RLL+18
  
  19   Session_Setup   RLL  19NA
  Session_Setup+RLL+19
  
  20   Session_Setup   RLL  20NA
  Session_Setup+RLL+20
  
  21   Session_Setup   RLL  21NA
  Session_Setup+RLL+21
  
  22   Session_Setup   RLL  22NA
  Session_Setup+RLL+22
  
  23   Session_Setup   RLL  23NA
  Session_Setup+RLL+23
  
  24   Session_Setup   RLL  24NA
  Session_Setup+RLL+24
  
  25   Session_Setup   RLL  25NA
  Session_Setup+RLL+25
  
  26   Session_Setup   RLL  26NA
  Session_Setup+RLL+26
  
  27   Session_Setup   RLL  27NA
  Session_Setup+RLL+27
  
  28   Session_Setup   RLL  28NA
  Session_Setup+RLL+28
  
  29   Session_Setup   RLL  29NA
  Session_Setup+RLL+29
  
  30   Session_Setup   RLL  30NA
  Session_Setup+RLL+30
  
  31  User_Initiated   RLL   1  8.487840
  User_Initiated+RLL+1
  
  32  User_Initiated   RLL   2  6.066089
  User_Initiated+RLL+2
  
  33  User_Initiated   RLL   3NA
  User_Initiated+RLL+3
  
  34  User_Initiated   RLL   4NA
  User_Initiated+RLL+4
  
  35  User_Initiated   RLL   5  5.906891
  User_Initiated+RLL+5
  
  36  User_Initiated   RLL   6NA
  User_Initiated+RLL+6
  
  37  User_Initiated   RLL   7NA
  User_Initiated+RLL+7
  
  38  User_Initiated   RLL   8NA
  User_Initiated+RLL+8
  
  39  User_Initiated   RLL   9NA
  User_Initiated+RLL+9
  
  40  User_Initiated   RLL  10NA
  User_Initiated+RLL+10
  
  41  User_Initiated   RLL  11NA
  User_Initiated+RLL+11
  
  42  User_Initiated   RLL  12

[R] grouped and stacked plot

2008-11-07 Thread Ferry
Dear R users,

Beside lattice and vcd packages, what is my option if I want to create a
grouped and stacked categorical plots?

With lattice, what I usually do is breaking my data from a wide form to a
long form (using subset and rbind), such as:

TypeID - Var 1 - Var 2 - Var 3 - Val

to

TypeID+Var1 - Val
TypeID+Var2 - Val
...

therefore, if I use auto.key = TRUE, I will have permutation as Type* Number
of Vars.

I think I have to use similar process with vcd as well, using doubledecker
or mosaic plot.

Or, is there a different way/setting to create grouped and stacked using
lattice or vcd that I am not accustomed (which is very like, since I am such
as newbie with R, much less with R-graphics).

Any idea is appreciated,

Thanks,

Ferry

[[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] 2^2 factorial design question

2008-11-07 Thread Ted Harding
On 07-Nov-08 00:53:56, Edna Bell wrote:
 Dear R Gurus:
 
 How do you put together a 2^2 (or even 2^k) factorial problem, please?

I'm not clear about what you mean here, especially about put together!
Can you describe what you want to end up with in more detail?

 Since you have 2 levels for A and B, do you put in A+ and A- as
 factors, please?

In any case, I would not use the names A+ and A-, since this
provides too many opportunities for expressions involving these
to be interpreted as arithmetic operations. Better, and safer,
to use names A1 and A0, say.

Best wishes,
Ted.

 Thanks,
 Edna Bell


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 07-Nov-08   Time: 09:51:39
-- XFMail --

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


Re: [R] nls: Fitting two models at once?

2008-11-07 Thread Heather Turner
Dear Martin,

You can use the same idea of concatenating the data in R. The following
reproduces your example:

spec - c(asfe, dias)
n1 - length(asfe)
n2 - length(dias)
CYT - c(28 * CYTF, 24.6 * 2 * CYTB6)
B559HP - c(B559HP, numeric(n2))
B559LP - c(numeric(n1), B559LP)
C550 - c(numeric(n1), C550)

spec.fit -
nls(
spec ~ cyt.v*CYT + hp.v*B559HP + lp.v*B559LP + c550.v*C550,
start = list(cyt.v = 0.5, hp.v = 0.03, lp.v = 1,
 c550.v = 1) # arbitrary
);

or more efficiently, using lm

spec.fit - lm(spec ~ 0 + CYT + B559HP + B559LP + C550)

# draw stuff
plot(
1, 2,
type=n,
xlim = c(540, 575),
ylim=c(-0.002, 0.008),
);

# first spectrum and fit
lines(wl, asfe, type=b, pch=19); # solid circles
lines(wl, fitted(spec.fit)[1:n1], col = red);

# second spectrum and fit
lines(wl, dias, type=b);
lines(wl, fitted(spec.fit)[(n1 + 1):(n1 + n2)], col = blue);

Best wishes,

Heather

Dr H Turner
Senior Research Fellow
Dept. of Statistics
The University of Warwick
Coventry
CV4 7AL

Tel: 024 76575870
Fax: 024 76524532
Url: www.warwick.ac.uk/go/heatherturner


Martin Ballaschk wrote:
 Hello,
 
 I'm still a newbie user and struggling to automate some analyses from
 SigmaPlot using R. R is a great help for me so far!
 
 But the following problem makes me go nuts.
 
 I have two spectra, both have to be fitted to reference data. Problem: the
 both spectra are connected in some way: the stoichiometry of coefficients
 cytf.v/cytb.v is 1/2.
 {{In the SigmaPlot workflow one has to copy the two spectra into one column
 beneath each other and the  two spectra are somehow treated as one curve -
 like in http://home.arcor.de/ballaschk/cytbf-help/sigmaplot%20formula.png}}
 
 Can anybody help? :(
 
 I tried to condense everything to the minimum R script below to give an
 impression of what I'm talking about.
 
   Martin
 
 
 
 
 # Minimal R script reading remote data for convenience
 
 ### READ IN DATA
 # first spectrum
 asfe - read.table(http://home.arcor.de/ballaschk/cytbf-help/asfe.csv;)[, 1];
 # second spectrum
 dias - read.table(http://home.arcor.de/ballaschk/cytbf-help/dias.csv;)[, 1];
 
 # reference data for fit, wavelength = wl
 ref - read.table(http://home.arcor.de/ballaschk/cytbf-help/reference.csv;,
 sep=\t, dec=., header=T);
 attach(ref);
 
 ### FITTING, problem: 2*cytf.v == cytb.v
 
 # fit first spectrum to two reference spectra
 asfe.fit -
 nls(
   asfe ~ (cytf.v * 28) * CYTF + hp.v * B559HP,
   start = list(cytf.v = 0.5, hp.v = 0.03) # arbitrary
 );
 
 # fit second spectrum to three reference spectra
 dias.fit -
 nls(
   dias ~ (cytb.v * 24.6 * 2) * CYTB6 + lp.v * B559LP + c550.v * C550,
   start = list(cytb.v = 1, lp.v = 1, c550.v = 1) # arbitrary
 );
 
 
 # draw stuff
 plot(
   1, 2,
   type=n,
   xlim = c(540, 575),
   ylim=c(-0.002, 0.008),
 );
 
 # first spectrum and fit
 lines(wl, asfe, type=b, pch=19); # solid circles
 lines(wl, fitted(asfe.fit), col = red);
 
 # second spectrum and fit
 lines(wl, dias, type=b);
 lines(wl, fitted(dias.fit), col = blue);
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Odp: need help in plotting barchart

2008-11-07 Thread Petr PIKAL
Hi

I did not see any response and will not give you any answer too, just a 
hint. Your code can not be reproduced and it is also difficult to say what 
you really want.

Eg. this is rather confusing.

 On a generated plot  I observed that what ever records have counts as
 NA, those are not suppressed. but I don't want them to be suppressed.

Do you want NA to be suppressed or not?

I would

ensure my data frame has variables with correct class and then I would 
select those with non zero and non NA counts by e.g.

Df.OK - Df[which(Df$counts),]

if you want to drop unused levels of factor you can use e.g. drop=T in 
subseting this factor

Regards
Petr


[EMAIL PROTECTED] napsal dne 06.11.2008 12:30:13:

 Df contains 
 
  Session_Setup   DCT RevDataVols_bincounts
 comp
 
 1Session_Setup   RLL   1NA
 Session_Setup+RLL+1
 
 2Session_Setup   RLL   2NA
 Session_Setup+RLL+2
 
 3Session_Setup   RLL   3NA
 Session_Setup+RLL+3
 
 4Session_Setup   RLL   4NA
 Session_Setup+RLL+4
 
 5Session_Setup   RLL   5NA
 Session_Setup+RLL+5
 
 6Session_Setup   RLL   6NA
 Session_Setup+RLL+6
 
 7Session_Setup   RLL   7NA
 Session_Setup+RLL+7
 
 8Session_Setup   RLL   8NA
 Session_Setup+RLL+8
 
 9Session_Setup   RLL   9NA
 Session_Setup+RLL+9
 
 10   Session_Setup   RLL  10NA
 Session_Setup+RLL+10
 
 11   Session_Setup   RLL  11NA
 Session_Setup+RLL+11
 
 12   Session_Setup   RLL  12NA
 Session_Setup+RLL+12
 
 13   Session_Setup   RLL  13NA
 Session_Setup+RLL+13
 
 14   Session_Setup   RLL  14NA
 Session_Setup+RLL+14
 
 15   Session_Setup   RLL  15NA
 Session_Setup+RLL+15
 
 16   Session_Setup   RLL  16NA
 Session_Setup+RLL+16
 
 17   Session_Setup   RLL  17NA
 Session_Setup+RLL+17
 
 18   Session_Setup   RLL  18NA
 Session_Setup+RLL+18
 
 19   Session_Setup   RLL  19NA
 Session_Setup+RLL+19
 
 20   Session_Setup   RLL  20NA
 Session_Setup+RLL+20
 
 21   Session_Setup   RLL  21NA
 Session_Setup+RLL+21
 
 22   Session_Setup   RLL  22NA
 Session_Setup+RLL+22
 
 23   Session_Setup   RLL  23NA
 Session_Setup+RLL+23
 
 24   Session_Setup   RLL  24NA
 Session_Setup+RLL+24
 
 25   Session_Setup   RLL  25NA
 Session_Setup+RLL+25
 
 26   Session_Setup   RLL  26NA
 Session_Setup+RLL+26
 
 27   Session_Setup   RLL  27NA
 Session_Setup+RLL+27
 
 28   Session_Setup   RLL  28NA
 Session_Setup+RLL+28
 
 29   Session_Setup   RLL  29NA
 Session_Setup+RLL+29
 
 30   Session_Setup   RLL  30NA
 Session_Setup+RLL+30
 
 31  User_Initiated   RLL   1  8.487840
 User_Initiated+RLL+1
 
 32  User_Initiated   RLL   2  6.066089
 User_Initiated+RLL+2
 
 33  User_Initiated   RLL   3NA
 User_Initiated+RLL+3
 
 34  User_Initiated   RLL   4NA
 User_Initiated+RLL+4
 
 35  User_Initiated   RLL   5  5.906891
 User_Initiated+RLL+5
 
 36  User_Initiated   RLL   6NA
 User_Initiated+RLL+6
 
 37  User_Initiated   RLL   7NA
 User_Initiated+RLL+7
 
 38  User_Initiated   RLL   8NA
 User_Initiated+RLL+8
 
 39  User_Initiated   RLL   9NA
 User_Initiated+RLL+9
 
 40  User_Initiated   RLL  10NA
 User_Initiated+RLL+10
 
 41  User_Initiated   RLL  11NA
 User_Initiated+RLL+11
 
 42  User_Initiated   RLL  12NA
 User_Initiated+RLL+12
 
 43  User_Initiated   RLL  13NA
 User_Initiated+RLL+13
 
 44  User_Initiated   RLL  14NA
 User_Initiated+RLL+14
 
 45  User_Initiated   RLL  15NA
 User_Initiated+RLL+15
 
 46  User_Initiated   RLL  16NA
 User_Initiated+RLL+16
 
 47  User_Initiated   RLL  17NA
 User_Initiated+RLL+17
 
 48  User_Initiated   RLL  18NA
 User_Initiated+RLL+18
 
 49  User_Initiated   RLL  19NA
 User_Initiated+RLL+19
 
 50  User_Initiated   RLL  20NA
 User_Initiated+RLL+20
 
 51  User_Initiated   RLL  21NA
 User_Initiated+RLL+21
 
 52  User_Initiated   RLL  22NA
 User_Initiated+RLL+22
 
 53  User_Initiated   RLL  23NA
 User_Initiated+RLL+23
 
 54  User_Initiated   RLL  24NA
 User_Initiated+RLL+24
 
 55  User_Initiated   RLL  25NA
 User_Initiated+RLL+25
 
 56  User_Initiated   

[R] help with maps : center on the dateline

2008-11-07 Thread Melanie . Abecassis
Hi,
I'm trying to plot a map of the pacific ocean, centered on the dateline, using 
the maps package.


library(maps) # Basic library to draw maps
library(mapdata)# Library with specialized maps
library(mapproj)

map(database = world, fill = TRUE, col = 1, plot = TRUE,add=F,  
xlim = c(120,300), ylim = c(-20,40))


I tried several different combinations of coordinates, but whatever I try, it 
doesn't plot anything past the dateline.
Is there a way to plot a map like the one attached, with this package ?

thanks !

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


Re: [R] Applying a function to a list of arguments ...

2008-11-07 Thread baptiste auguie

perhaps something like,


func - function(f, ...) {
do.call(f, ...)
}

func(rnorm, list(n=3, mean=2, sd=3))


baptiste


On 7 Nov 2008, at 10:21, [EMAIL PROTECTED] wrote:


How can I apply function f, that I get as an argument as in

func - function(f, ...) {
.
.
.
}

to a list of arguments list(a, b, c) (eg the ... argument of func  
above)

in order to obtain

f(a, b, c)

Thanks a lot,

Roberto

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


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

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


Re: [R] Vectorizing sample()

2008-11-07 Thread Duncan Murdoch

On 11/7/2008 12:00 PM, Stephen Collins wrote:
I am simulating sickness among a group of families.  Part of the task is 
to randomly draw who in the family will be sick, randomly drawing from 
family ID's where Dad =1, Mom = 2, Kid1 = 3, Kid2 = 4., etc.  My census of 
Dads is of the form shown below. 


Dad_ID  Spouse (Y=1;N=0)#Kids #People_Becoming_Sick
1   1   0   1
2   0   2   2
3   1   0   2
4   1   3   3
...

The end output needed is if 3 people in a family are to be sick, was it 
the dad and two kids, with random family ID's =  {1,3,4}, or the mom, dad, 
and one kid,  with random family ID's =  {2,1,4}, etc..  The complication 
is that length of the family ID's to choose from and the associated 
sampling probabilities -- changes with each family.   I could loop through 
the Dads, from i in 1:nrow(census), but is there a way I could vectorize 
sample() to get at the same objective? 

My attempts to use the apply-based functions have dead ended.  Other ideas 
to vectorize this problem are warmly welcomed.


You might want to transform runif instead of using sample().  For 
example, if you want to generate M integers from 1:n_i, where n_i varies 
from sample to sample, you could use


gen - ceiling(runif(M, 0, n))

(where n is a vector of length M giving the upper limits).

Duncan Murdoch






Regards,
 
Stephen Collins, MPP | Analyst

Health  Benefits | Aon Consulting
200 East Randolph, Suite 900, Chicago, IL
Tel: 312-381-2578 | Fax: 312-381-0136
Email: [EMAIL PROTECTED]
 
Aon Consulting selected by the readers of Business Insurance as the “Best 
Employee Benefit Consulting Firm� in 2006, 2007, and 2008
 
NOTE: The information contained in this transmission, including any 
attachment(s) is only for the use of the intended individual(s) or entity, 
and may contain information that is privileged and confidential. If the 
reader of this message is not an intended recipient, you are hereby 
notified that any dissemination, distribution, disclosure, or copying of 
this information is unauthorized and strictly prohibited. If you have 
received this communication in error, please contact the sender 
immediately by reply email and destroy all copies of the original message.
 


[[alternative HTML version deleted]]





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


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


Re: [R] help with maps : center on the dateline

2008-11-07 Thread Duncan Murdoch

On 11/7/2008 12:08 PM, [EMAIL PROTECTED] wrote:

Hi,
I'm trying to plot a map of the pacific ocean, centered on the dateline, using 
the maps package.


library(maps) # Basic library to draw maps
library(mapdata)# Library with specialized maps
library(mapproj)

map(database = world, fill = TRUE, col = 1, plot = TRUE,add=F,  
xlim = c(120,300), ylim = c(-20,40))



I tried several different combinations of coordinates, but whatever I try, it 
doesn't plot anything past the dateline.
Is there a way to plot a map like the one attached, with this package ?


Use the world2 (or world2Hires, from mapdata) database.

Duncan Murdoch

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


Re: [R] How to manipulate the time data without the date?

2008-11-07 Thread Gabor Grothendieck
On Fri, Nov 7, 2008 at 3:32 AM, Barry Rowlingson
[EMAIL PROTECTED] wrote:
 2008/11/7 tedzzx [EMAIL PROTECTED]:

 The problem is that: There is some rounding problems, for example
 Library(chron)
 any(times(4:00:01)==times(4:00:00)+times(00:00:01)))
 False

 But,it should be true

  FAQ 7.31 in disguise!

  chron stores date-times as fractions, so you're comparing two
 floating point numbers here. FAQ 7.31 applies.

  Use 'all.equal', which has a method for chron that uses a 1 second
 tolerance to match times:


That solution works but just to be precise, note that a times
class object need not be a dates or chron class object and
while there is a chron:::all.equal.dates there is no chron:::all.equal.times.

The reason all.equal works here is that all.equal.default works here and
it works here by ultimately calling all.equal.numeric to do the real work.

 y - times(4:00:00)+times(00:00:01)
 class(y) # no dates or chron in class vector
[1] times

Also all.equal.dates uses a tenth of a second as the tolerance:

 chron:::all.equal.dates
function (..., tolerance = 1/(10 * 24 * 60 * 60))
NextMethod(all.equal, ..., tolerance = tolerance)
environment: namespace:chron


 all.equal(times(4:00:01),times(4:00:00)+times(00:00:01))
 [1] TRUE


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


[R] Applying a function to a list of arguments ...

2008-11-07 Thread roby . brunelli
How can I apply function f, that I get as an argument as in

func - function(f, ...) {
.
.
.
}

to a list of arguments list(a, b, c) (eg the ... argument of func above)
in order to obtain

f(a, b, c)

Thanks a lot,

Roberto

[[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] sapply and median, possible or not ?

2008-11-07 Thread Henrique Dallazuanna
You can provide a example of your data?

On Fri, Nov 7, 2008 at 9:14 AM, Ptit_Bleu [EMAIL PROTECTED] wrote:


 Unfortunately, I have the same error message.
 lapply(rowsplit, function(x)mean(x[,sapply(x, is.numeric)])) works but not
 with median.
 Strange, isn't it?

 Any other idea?

 Thanks in advance,
 Ptit Bleu.


 Henrique Dallazuanna wrote:
 
  Try this:
 
  lapply(l, function(x)median(x[,sapply(x, is.numeric)]))
 
 
  --
  Henrique Dallazuanna
  Curitiba-Paraná-Brasil
  25° 25' 40 S 49° 16' 22 O
 
[[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.
 
 

 --
 View this message in context:
 http://www.nabble.com/sapply-and-median%2C-possible-or-not---tp20378222p20378663.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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[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] sapply and median, possible or not ?

2008-11-07 Thread Keith Jewell
I haven't looked at the detail, but I guess the answer is that mean works on 
a data frame while median doesn't.

?mean
snip
For a data frame, a named vector with the appropriate method being applied 
column by column.
-

I guess to use median you'll need nested '[l/s]apply's, the outer working 
through the list of dataframes and the inner working through the columns of 
each dataframe.

Or perhaps, by analogy with mean.data.frame you could just define
-
median.data.frame - function(x, ...)
sapply(x, median, ...)


I haven't tried it, but it might work

hth

Keith J
-
Ptit_Bleu [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 Unfortunately, I have the same error message.
 lapply(rowsplit, function(x)mean(x[,sapply(x, is.numeric)])) works but not
 with median.
 Strange, isn't it?

 Any other idea?

 Thanks in advance,
 Ptit Bleu.


 Henrique Dallazuanna wrote:

 Try this:

 lapply(l, function(x)median(x[,sapply(x, is.numeric)]))


 -- 
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O

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



 -- 
 View this message in context: 
 http://www.nabble.com/sapply-and-median%2C-possible-or-not---tp20378222p20378663.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] Vectorizing sample()

2008-11-07 Thread Kenn Konstabel
Hi,

I'm not quite sure I understood everything but is this something close?

d - read.table(textConnection(Dad_ID  SpouseYN  NKids  NSick
1  10  1
2  02  2
3  10  2
4  13  3), header=TRUE)

mapply(sample, d$NKids+d$SpouseYN+1, d$NSick)

# d$NKids+d$SpouseYN+1 is supposed to be family size

Best regards,
Kenn

On Fri, Nov 7, 2008 at 7:00 PM, Stephen Collins [EMAIL PROTECTED]wrote:

 I am simulating sickness among a group of families.  Part of the task is
 to randomly draw who in the family will be sick, randomly drawing from
 family ID's where Dad =1, Mom = 2, Kid1 = 3, Kid2 = 4., etc.  My census of
 Dads is of the form shown below.

 Dad_ID  Spouse (Y=1;N=0)#Kids #People_Becoming_Sick
 1   1   0   1
 2   0   2   2
 3   1   0   2
 4   1   3   3
 ...

 The end output needed is if 3 people in a family are to be sick, was it
 the dad and two kids, with random family ID's =  {1,3,4}, or the mom, dad,
 and one kid,  with random family ID's =  {2,1,4}, etc..  The complication
 is that length of the family ID's to choose from and the associated
 sampling probabilities -- changes with each family.   I could loop through
 the Dads, from i in 1:nrow(census), but is there a way I could vectorize
 sample() to get at the same objective?

 My attempts to use the apply-based functions have dead ended.  Other ideas
 to vectorize this problem are warmly welcomed.



 Regards,

 Stephen Collins, MPP | Analyst
 Health  Benefits | Aon Consulting
 200 East Randolph, Suite 900, Chicago, IL
 Tel: 312-381-2578 | Fax: 312-381-0136
 Email: [EMAIL PROTECTED]

 Aon Consulting selected by the readers of Business Insurance as the “Best
 Employee Benefit Consulting Firm† in 2006, 2007, and 2008

 NOTE: The information contained in this transmission, including any
 attachment(s) is only for the use of the intended individual(s) or entity,
 and may contain information that is privileged and confidential. If the
 reader of this message is not an intended recipient, you are hereby
 notified that any dissemination, distribution, disclosure, or copying of
 this information is unauthorized and strictly prohibited. If you have
 received this communication in error, please contact the sender
 immediately by reply email and destroy all copies of the original message.


[[alternative HTML version deleted]]


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



[[alternative HTML version deleted]]

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


[R] Re gular Expression help

2008-11-07 Thread Rajasekaramya

hi there

I have a vector with a set of data.I just wanna seperate them based on the
first p and q values metioned within the data.

[1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
[2] chr1q22-q24 
[3] chr1q22-q24 
[4] chr1pter-q24
[5] chr1pter-q24
[6] chr1pter-q24  

i used a regular expression [+q*] to match up the values but it matches q
found anywhere i know i have written like that but i jus want it to match
the first p or q values.

my result should be for q and 
[2] chr1q22-q24  
[3] chr1q22-q24  

for p
[1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
[4] chr1pter-q24
[5] chr1pter-q24
[6] chr1pter-q24 



-- 
View this message in context: 
http://www.nabble.com/Regular-Expression-help-tp20385971p20385971.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Rmpi task-pull

2008-11-07 Thread Daniel Ferrara
Hi, I'm testing the efficiency of the Rmpi package regarding parallelization
using a cluster.
I've found and tried the task pull programming method, but even if it is
described as the best method, it seems to cause deadlock, anyone could help
me in using this method?
here is the code I've found and tried:


# Initialize MPI
library(Rmpi)

# Notice we just say give us all the slaves you've got.
mpi.spawn.Rslaves()

if (mpi.comm.size()  2) {
print(More slave processes are required.)
mpi.quit()
}

.Last - function(){
if (is.loaded(mpi_initialize)){
if (mpi.comm.size(1)  0){
print(Please use mpi.close.Rslaves() to close slaves.)
mpi.close.Rslaves()
}
print(Please use mpi.quit() to quit R)
.Call(mpi_finalize)
}
}

# Function the slaves will call to perform a validation on the
# fold equal to their slave number.
# Assumes: thedata,fold,foldNumber,p
foldslave - function() {
# Note the use of the tag for sent messages:
# 1=ready_for_task, 2=done_task, 3=exiting
# Note the use of the tag for received messages:
# 1=task, 2=done_tasks
junk - 0

done - 0
while (done != 1) {
# Signal being ready to receive a new task
mpi.send.Robj(junk,0,1)

# Receive a task
task - mpi.recv.Robj(mpi.any.source(),mpi.any.tag())
task_info - mpi.get.sourcetag()
tag - task_info[2]

if (tag == 1) {
foldNumber - task$foldNumber

rss - double(p)
for (i in 1:p) {
# produce a linear model on the first i variables on
# training data
templm - lm(y~.,data=thedata[fold!=foldNumber,1:(i+1)])

# produce predicted data from test data
yhat -
predict(templm,newdata=thedata[fold==foldNumber,1:(i+1)])

# get rss of yhat-y
localrssresult - sum((yhat-thedata[fold==foldNumber,1])^2)
rss[i] - localrssresult
}

# Send a results message back to the master
results - list(result=rss,foldNumber=foldNumber)
mpi.send.Robj(results,0,2)
}
else if (tag == 2) {
done - 1
}
# We'll just ignore any unknown messages
}

mpi.send.Robj(junk,0,3)
}

# We're in the parent.
# first make some data
n - 1000# number of obs
p - 30# number of variables

# Create data as a set of n samples of p independent variables,
# make a random beta with higher weights in the front.
# Generate y's as y = beta*x + random
x - matrix(rnorm(n*p),n,p)
beta - c(rnorm(p/2,0,5),rnorm(p/2,0,.25))
y - x %*% beta + rnorm(n,0,20)
thedata - data.frame(y=y,x=x)

fold - rep(1:10,length=n)
fold - sample(fold)

summary(lm(y~x))

# Now, send the data to the slaves
mpi.bcast.Robj2slave(thedata)
mpi.bcast.Robj2slave(fold)
mpi.bcast.Robj2slave(p)

# Send the function to the slaves
mpi.bcast.Robj2slave(foldslave)

# Call the function in all the slaves to get them ready to
# undertake tasks
mpi.bcast.cmd(foldslave())


# Create task list
tasks - vector('list')
for (i in 1:10) {
tasks[[i]] - list(foldNumber=i)
}

# Create data structure to store the results
rssresult = matrix(0,p,10)

junk - 0
closed_slaves - 0
n_slaves - mpi.comm.size()-1

while (closed_slaves  n_slaves) {
# Receive a message from a slave
message - mpi.recv.Robj(mpi.any.source(),mpi.any.tag())
message_info - mpi.get.sourcetag()
slave_id - message_info[1]
tag - message_info[2]

if (tag == 1) {
# slave is ready for a task. Give it the next task, or tell it tasks

# are done if there are none.
if (length(tasks)  0) {
# Send a task, and then remove it from the task list
mpi.send.Robj(tasks[[1]], slave_id, 1);
tasks[[1]] - NULL
}
else {
mpi.send.Robj(junk, slave_id, 2)
}
}
else if (tag == 2) {
# The message contains results. Do something with the results.
# Store them in the data structure
foldNumber - message$foldNumber
rssresult[,foldNumber] - message$result
}
else if (tag == 3) {
# A slave has closed down.
closed_slaves - closed_slaves + 1
}
}


# plot the results
plot(apply(rssresult,1,mean))

mpi.close.Rslaves()
mpi.quit(save=no)


Thanks for your help!!!

[[alternative HTML version deleted]]

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


Re: [R] Re gular Expression help

2008-11-07 Thread Peter Dalgaard
Rajasekaramya wrote:
 hi there
 
 I have a vector with a set of data.I just wanna seperate them based on the
 first p and q values metioned within the data.
 
 [1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
 [2] chr1q22-q24 
 [3] chr1q22-q24 
 [4] chr1pter-q24
 [5] chr1pter-q24
 [6] chr1pter-q24  
 
 i used a regular expression [+q*] to match up the values but it matches q
 found anywhere i know i have written like that but i jus want it to match
 the first p or q values.
 
 my result should be for q and 
 [2] chr1q22-q24  
 [3] chr1q22-q24  
 
 for p
 [1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
 [4] chr1pter-q24
 [5] chr1pter-q24
 [6] chr1pter-q24 
 

Something like

sub([^pq]*([pq]).*,\\1,x)

should get you the first p or q


-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Sweave: How to load available colors from pkg 'color'

2008-11-07 Thread Felipe Carrillo
Hi: Is there a shorter way to color the abstract,sections subsections and page 
headings of a document. I am using the code below in my preamble to accomplish 
some of it:

[EMAIL PROTECTED],dvips]{color}
\else\usepackage[usenames,dvipsnames]{color}
% and fix pdf colour problems
\IfFileExists{pdfcolmk.sty}{\usepackage{pdfcolmk}}{}
\fi
%\renewcommand{\MakeUppercase}[1]{\color{OliveGreen}\textsf{#1}}
%\renewcommand{\abstractname}{\color{blue}Abstract}

 Also,'\usepackage[usenames]{color}' is suppossed to load all the available 
colors in the package 'color' but for some reason it doesn't  load them when 
running it trhough Sweave. It loads all the colors if I run it outside R though.
Here's a dummy document:

\documentclass[12pt]{article}
\usepackage{floatflt,graphicx,times,babel}
\usepackage[usenames]{color}
\usepackage{verbatim}
\usepackage[ps2pdf,
bookmarks=true,
bookmarksnumbered=false, 
bookmarksopen=false, 
colorlinks=true,
linkcolor=blue]{hyperref}

\pdfbookmark[1]{Contents}{table}
\title{BROOD-YEAR 2008 PINK SALMON RUN}
\author{Felipe D. Carrillo}
\pagestyle{headings}
\begin{document}
\setkeys{Gin}{width=0.9\textwidth}
\maketitle
\begin{abstract}
 This is my abstract
\end{abstract}
\tableofcontents
\section{list of figures}
\section{introduction}
here's my introduction
\section{study area}
This is my study area
\section{methods}
subsection{sampling gear}
I used this sampling gear
\subsection{data collection}
\end{document}


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

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


[R] sapply and median, possible or not ?

2008-11-07 Thread Ptit_Bleu

Hello,

I have a list of data.frame
rowsplit : List of 15
 $ (0,0.025]   :'data.frame':   169 obs. of  7 variables:
 $ (0.025,0.05]:'data.frame':   174 obs. of  7 variables:
 $ (0.05,0.075]:'data.frame':   92 obs. of  7 variables:
 $ (0.075,0.1] :'data.frame':   76 obs. of  7 variables:
 $ (0.1,0.125] :'data.frame':   37 obs. of  7 variables:
 $ (0.125,0.15]:'data.frame':   32 obs. of  7 variables:
 $ (0.15,0.175]:'data.frame':   45 obs. of  7 variables:
 $ (0.175,0.2] :'data.frame':   56 obs. of  7 variables:
 $ (0.2,0.225] :'data.frame':   36 obs. of  7 variables:
 $ (0.225,0.25]:'data.frame':   47 obs. of  7 variables:
 $ (0.25,0.275]:'data.frame':   34 obs. of  7 variables:
 $ (0.275,0.3] :'data.frame':   43 obs. of  7 variables:
 $ (0.3,0.325] :'data.frame':   29 obs. of  7 variables:
 $ (0.325,0.35]:'data.frame':   29 obs. of  7 variables:
 $ (0.35,0.375]:'data.frame':   17 obs. of  7 variables:

And I would like to get a data.frame gathering the median value of each
variable for each intervall.
as.data.frame(t(sapply(rowsplit, mean)) works well but I would prefer to use
median but with sapply(rowsplit, median), I get the following message Error
in median.default(X[[1L]], ...) : need numeric data.

Any idea ?

Thanks in advance for your help,
Have a nice week-end,
Ptit Bleu.

PS :I'm under XP and use R2.7.2.  
-- 
View this message in context: 
http://www.nabble.com/sapply-and-median%2C-possible-or-not---tp20378222p20378222.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Re move specific rows from a matrix

2008-11-07 Thread mentor_

Hi,

imagine the following two matrix:
Matrix A:
a b c
1 2 3
4 5 6
7 8 9

Matrix B:
a
4
7

I would like to remove those rows from matrix A which are present in both
matrices.
So after removing the corresponding rows the matrix A should look like this:
Matrix A:
a b c
1 2 3

Thanks in advance!
-- 
View this message in context: 
http://www.nabble.com/Remove-specific-rows-from-a-matrix-tp20379566p20379566.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] standard errors for predict.nls?

2008-11-07 Thread Christoph Scherber

Dear all,

I would like to get standard errors (or confidence intervals) for *predicted* 
values from an nls fit.

I have tried to implement code from p.225 in MASS (bootstrapping a nls fit), but this gives only the 
confidence intervals of the parameter estimates, but not an overall confidence interval for the 
predicted value(s):


puro1-nls(rate~a*conc/(b+conc), data=Puromycin[1:12,], start=list(a=200, b=1)) 
 #set up nls model

# assume only one predicted value is obtained using 
predict(puro1,list(conc=0.02)):

st=cbind(Puromycin[1:12,],fit=predict(puro1,list(conc=0.02)))

puro.bf=function(rs,i){
st$rate=st$fit+rs[i]
coef(nls(rate~a*conc/(b+conc), st, start=coef(puro1)))
}

rs=scale(resid(puro1),scale=F)
(puro.boot=boot(rs,puro.bf,R=100))

boot.ci(puro.boot,index=1,type=c(norm))
boot.ci$t0
boot.ci$norm
###

How do I have to change the code to get the c.i. for the predicted value?


Many thanks and best wishes,
Christoph





Prof Brian Ripley schrieb:

On Mon, 3 Nov 2008, Ben Bolker wrote:


Prof Brian Ripley wrote:

Christoph Scherber Christoph.Scherber at agr.uni-goettingen.de
writes:



Dear all,

Is there a way to retrieve standard errors from nls models?
The help page tells me that arguments
such as se.fit are ignored...

Many thanks and best wishes
Christoph



In general using the delta method (which is I guess what you mean, local
linearization via derivatives) is nowhere near accurate enough to be
useful.  That's why it has not been done on several occasions in the 
past.

If you think it might be, see ?delta.method in package alr3.

I would suggest using simulation/bootsrapping to explore the 
uncertainty.

There is an example in MASS of doing so (and that illustrates some of
the pitfalls).


 Hmmm.  By an example, do you mean an example of using bootstrapping to
explore uncertainty in general, or of using bootstrapping to get
standard errors of predictions from nonlinear regressions?  I looked
through my copy of MASS (4th ed.) and found only section 5.7
(bootstrapping in general) and chapter 8 (nonlinear and smooth
regression, esp. p. 225 bootstrapping for getting bootstrap c.i.'s on
parameter estimates).  I didn't find anything *specifically* covering
s.e./c.i. for nls predictions, but maybe that's not what you meant.


I meant the example on p.225 on bootstrapping a nls fit (and that you 
needed to bootstrap residuals in some cases).  You can use almost 
identical code to set s.e./c.i. for nls predictions.



 And yes, I meant delta method rather than delta function in my
original post.  Oops.

 I might add something quick/dirty/naive to the wiki giving
some examples of delta method/bootstrap approaches ...

 If there is no intention to add confidence interval calculation
to predict.se in the foreseeable future might I suggest that the details
under Value as to what se.fit will do when it is implemented be
removed? (And perhaps even a statement to the effect [as you say
above] that delta method is considered unreliable?)  As written it's a
bit of a tease ...


I didn't write that ... and its author might have other opinions.


 cheers
   Ben Bolker





--
Dr. rer.nat. Christoph Scherber
University of Goettingen
DNPW, Agroecology
Waldweg 26
D-37073 Goettingen
Germany

phone +49 (0)551 39 8807
fax   +49 (0)551 39 8806

Homepage http://www.gwdg.de/~cscherb1

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


Re: [R] chi square table

2008-11-07 Thread Peter Dalgaard
Berwin A Turlach wrote:


 rant on
 That's the problem with introductory textbook whose author think they
 do the students a favour by using notation as z_alpha, z_0.01,
 z_(alpha/2) instead of z_(1-alpha), z_0.99, z_(1-alpha/2),
 respectively.  In my opinion this produces in the long run only
 more confusion and does not help students at all.  It just panders to
 intellectual laziness of (some) students and shows a great deal of
 confusion on the side of the authors.
 I would search another textbook
 rand off

Exposure to certain groups of students might change your opinions
there Some of us have been teaching to people who have trouble
calculating 21% of the number of boys so you really don't want to
throw them further off their feet by relying on mathematical nitty-gritty.

(Actually, I don't think you see z_alpha that much. It's more like tail
area, P value, Two sided P value.)

-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

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

2008-11-07 Thread Tom Backer Johnsen
Do anyone know anything about the use of R for agent-based social 
simulation?  It should be possible, and would be convenient for the 
simple reason that there are several nice packages containing useful 
stuff for SNA (Social Network Analysis).  Information about packages, 
web sites, experienced persons in the field, etc. would be very welcome.


Tom
++
| Tom Backer Johnsen, Psychometrics Unit,  Faculty of Psychology |
| University of Bergen, Christies gt. 12, N-5015 Bergen,  NORWAY |
| Tel : +47-5558-9185Fax : +47-5558-9879 |
| Email : [EMAIL PROTECTED]URL : http://www.galton.uib.no/ |
++

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


Re: [R] ordinal logistic model with pre-defined coefficients

2008-11-07 Thread Prof Brian Ripley

On Fri, 7 Nov 2008, [EMAIL PROTECTED] wrote:


Hi,

I'm trying to fit a proportional ordinal logistic model using function
polr() (package MASS).

Is there a way to fix certain betas in the regression (e.g. function
arima() allows this by defining fixed )
Maybe there is another function than polr() which allows that?


See ?offset, the standard tool in regression-like fitting in R (and 
described in the book MASS supports).



Thanks
Kazys


--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [R] Agent-based social simulation and R

2008-11-07 Thread Tom Backer Johnsen

Martin Elff wrote:

Hi Tom,

my package 'memisc' contains a sort of an infrastructure for doing 
simulations. As a fun exercise I also used it to create a 'toy' agent based 
simulation of Schelling's neighbourhood model. Although it is not a serious 
application, at least it shows that agent based simulation is possible in R.


Just run 'demo(schelling)' after loading 'memisc'.


Interesting.  I'll have to look trough the code.  How far away do the 
agents see?  Anything beyond their immidiate neighbors?


Tom

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

2008-11-07 Thread Shubha Vishwanath Karanth
 

Hi R,

 

I have certain checkings, which gives FALSE, but actually it is true. Why does 
this happen? Note that the equations that I am checking below are not even the 
case of recurring decimals...

 

 1.4^2 == 1.96

[1] FALSE

 

 1.2^3==1.728

[1] FALSE

 

 

Thanks in advance, Shubha

Shubha Karanth | Amba Research

Ph +91 80 3980 8031 | Mob +91 94 4886 4510 

Bangalore * Colombo * London * New York * San José * Singapore * 
www.ambaresearch.com

 

This e-mail may contain confidential and/or privileged i...{{dropped:13}}

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

2008-11-07 Thread roger koenker

Those of you with an interest in the US election and/or
statistical graphics may find the maps at:

http://www-personal.umich.edu/~mejn/election/2008/

interesting.


url:www.econ.uiuc.edu/~rogerRoger Koenker
email[EMAIL PROTECTED]Department of Economics
vox: 217-333-4558University of Illinois
fax:   217-244-6678Champaign, IL 61820

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


Re: [R] method to return rgb values from pixels of an image

2008-11-07 Thread Duncan Murdoch

On 11/7/2008 3:24 AM, Hans-Joachim Klemmt wrote:

hello,

i am looking for a method to return rgb-values of predifined pixels of 
jpg images.


can anybody help me?



See the rimage package, with function read.jpeg.  It will read the whole 
file into a large array, with separate red, green, blue entries.


Duncan Murdoch

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


[R] rmpi/snow/sge/openmpi help

2008-11-07 Thread jk jk
I'm trying to snow working with openmpi and sge.  Everything appears
to work, except, the program only runs on 2 node.  If i tell snow to
run on 9 nodes, it spawns 9 processes on a single node.  I'm at a loss
of ideas.  Any help would be appreciated.

Setup:  Rocks Cluster, OpenMPI, R 2.8.0, Snow, Rmpi.


Please ask for specifics.  Thanks in advance.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] esoteric inconsistency -- intended or not?

2008-11-07 Thread Bert Gunter

Is the following intended or not?

 func- function(y) match.call()

 z - func(y =2)

 z
func(y = 2)

 z[[a]] - 5

 z
func(y = 2, 5) ## Note that the second argument **is not** named

## BUT...

 z - func(y =2)

 z$a - 5

 z
func(y = 2, a = 5) ## The second argument **is** named

### End of example code ###

The reason I ask is that the man page for [[ specifically says:
**
Both [[ and $ select a single element of the list. The main difference is
that $ does not allow computed indices, whereas [[ does. x$name is
equivalent to x[[name, exact = FALSE]]. Also, the partial matching
behavior of [[ can be controlled using the exact argument. 

[ and [[ are sometimes applied to other recursive objects such as calls and
expressions. Pairlists are coerced to lists for extraction by [, but all
three operators can be used for replacement.
 

 I (mis?)read this as saying the behavior in the code snippets above should
produce identical results.

I note that the above inconsistency can be trivially avoided by first
coercing the call object to a list, modifying it either way, and then
coercing it back to a call object.

I doubt if it makes a difference, but:

 version
   _  
platform   i386-pc-mingw32
arch   i386   
os mingw32
system i386, mingw32  
status Patched
major  2  
minor  8.0
year   2008   
month  10 
day23 
svn rev46779  
language   R  
version.string R version 2.8.0 Patched (2008-10-23 r46779)

Cheers,
Bert Gunter

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


Re: [R] Election Maps

2008-11-07 Thread Liviu Andronic
On Fri, Nov 7, 2008 at 4:02 PM, hadley wickham [EMAIL PROTECTED] wrote:
 The source code (in C) for this type of cartogram (Diffusion-based
 method for producing density equalizing maps) is available from here:
 http://www-personal.umich.edu/~mejn/cart/download/

From the documentation [1]:
If you wish to make more sophisticated use of this software, such as
incorporating it into one of your own programs, then you should read
this page [2], which describes the workings in detail.

[1] http://www-personal.umich.edu/~mejn/cart/doc/
[2] http://www-personal.umich.edu/~mejn/cart/doc/description.html

Liviu








-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

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


Re: [R] rmpi/snow/sge/openmpi help

2008-11-07 Thread jk jk
Forgive the spam.  Let me try that e-mail again.


I'm trying to get snow working with openmpi and sge.  Everything
appears to work, except the program only runs on 1 node.  If i tell
snow to run on 5 nodes, it spawns 5 processes on a single node, 6
nodes = 6 procs on 1 node and so on.  I'm at a loss for ideas.  Any
help would be appreciated.

Setup:  Rocks Cluster, OpenMPI, R 2.8.0, Snow, Rmpi.


Please ask for specifics.  Thanks in advance.

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

2008-11-07 Thread Sundar Dorai-Raj

Hi,

I'm dealing with a lattice plot inserted into a tk widget and would like 
to know when a user has clicked on the plot area of a plot (i.e. inside 
the axes). For example,


library(tkrplot)
library(lattice)
tt - tktoplevel()
makePlot - function() print(xyplot(1 ~ 1))
printCoords - function(x, y) print(c(x, y))
img - tkrplot(tt, makePlot)
tkbind(img, 1, printCoords)
tkpack(img)

I would like to know when a user clicks inside the axes, but don't know 
how to determine where the plot region is. Essentially, this comes down 
to answering the following question: Assuming the entire plot is on a 
unit square, what are the coordinates of the plotting area?


This question is may seem unrelated to tkrplot, but outside of this 
context I may not get answers that work. I have been playing with both 
lattice::trellis.focus and grid::grid.locator to no avail.


Thanks,

--sundar

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] For Loop - loading 10 sets of data and calculating

2008-11-07 Thread PDXRugger

I am trying to simplify my code by adding a for loop that will load and
compute a sequence of code 10 time.  They way i run it now is that the same
8 lines of code are basically reproduced 10 times.  I would like to replace
the numeric value in the code (e.g. Bin1, Bin2Bin10) each time the loop
goes around.  Below i tried doing this with a simple for loop and adding the
string character before each numeric value.  I need to first load the data
then calculate, im sure this is possible as i have seen it done but cant
seem to reproduce it in my own code.  Hope my question is clear and i hope
someone can offer some guidance.

Cheers, 
JR

for (i in 1:10) {

#--- 

#Loads bin data frame from csv files with acres and TAZ data
Bin$i_main -
read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin$i_lookup.csv,head=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin$i_Acres=Bin$i_main[[1]]*43560

#Separates TAZ data from main data 
Bin$i_TAZ=Bin$i_main[[2]]

#Separates TAZ data from main data and converts acres to square feet
Bin$i_TAZvacant=Bin$i_main[[3]]*43560

#Sums each parcel acreage data of the bin
Bin$iAcres_sum=sum(Bin$i_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin$i_cumper=cumsum(Bin$i_Acres/Bin$iAcres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin$i_parprob=abs(1-Bin$i_cumper)

#Combines parcel acreage data and cumlative percentage data
Bin$iMain.data = cbind(Bin%i_Acres,Bin$i_parprob,Bin$i_TAZ,Bin$i_TAZvacant)
}

-- 
View this message in context: 
http://www.nabble.com/For-Loop---loading-10-sets-of-data-and-calculating-tp20386673p20386673.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] help with syntax of random formula

2008-11-07 Thread Thomas Wutzler
Dear R-users

Thanks to Jose Pinheiro, Douglas Bates and coworkes for providing R with the 
nlme package.

Could someone help me, please, to specify a correct random formula for a
mixed model, that specifies no random effect on a higher level?

I have the following dataset of timeseries of respiration measurements
(column resp) of biomass including a parameter initial biomass x0. Respiration
measurements have been recorded in several experiments, each consisting
of several replicates.

str(rd)
'data.frame':   3229 obs. of  5 variables:
 $ suite : Factor w/ 3 levels Face,Fal,Pushchino: 1 1 1 1 1 1
1 1 1 1 ...
 $ experiment: Factor w/ 44 levels 1,2,3,4,..: 1 1 1 1 1 1 1 1 1
1 ...
 $ replicate : Factor w/ 3 levels 1,2,3: 1 1 1 1 1 1 1 1 1 1 ...
 $ time  : num  1.84 2.84 3.84 4.84 5.84 ...
 $ resp  : num  4.09 3.94 3.70 3.88 4.03 ...

rd - 
groupedData( resp ~ time | experiment/replicate, data=rd)

Time is the first level at the same level as the dependent variable
resp, replicate is the second level, experiment the third. (In future
suite will be used as another level. For simplicity here, I first try
with data of only one suite)

I want to fit a mixed model to the data which includes random effects on
the replicate level but no random effects on the experiment level. The
random effects should have a distribution around 0 within each experiment.

I succeded to include random effects on both levels.
random=list( experiment=x0~1, replicate=x0~1 )

I succeded also to fit a model to only replicate level:
# replicate 1 in experiment i has nothing to do with replicate 1 in
other experiment
rd$exprep - paste( rd$experiment, rd$replicate, sep=_)
random=list( exprep=x0~1 )

However, this gives a single distribution across all replicates of all
experiments.
Instead, I want to have a distribution of random effects across only
replicates of an experiment with mean zero for each experiment

I tried amongst others the following syntax without success:
random=list( experiment=~1, exprep=x0~1 )
random=list( experiment=1~1, exprep=x0~1 )
random=list( experiment=NULL, exprep=x0~1 )

I am using nlme version 3.1-86 on R 2.6.1 on Windows XP.

Is it possible to fit such a model with nlme?
What is the correct syntax?
Do I need the exprep- variable or is it clear with the grouping that
replicate=1 in experiment=1 is different from replicate=1 in other
experiments!=1?

Best regards
Thomas Wutzler

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

2008-11-07 Thread penny77114

So, I have training data, and testing data

however, when I try to predict values for the testing data, it gives me
values for the training data. what gives? 

the following is my code:

train = read.table(train.txt, header = TRUE, sep =  )
test = read.table(test.txt, header = TRUE, sep =  )
model = glm(formula = train[,10]~ train[2] + train[3] + ... + train[9],
family = binomial(logit))
pred = predict(model, newdata = test.txt, type = response)

and then I get an warning: 
Warning messages:
1: 'newdata' had 45014 rows but variable(s) found have 45001 rows 
2: In predict.lm(object, newdata, se.fit, scale = 1, type = ifelse(type == 
:
  prediction from a rank-deficient fit may be misleading


and it seems it's not reading the newdata at all, as the pred is exactly the
same whether I put 
pred = predict(model, newdata = test.txt, type = response)
or 
pred = predict(model, type = response)


thanks in advance for any help
-- 
View this message in context: 
http://www.nabble.com/help-with-prediction-of-GLM-tp20383039p20383039.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Help With Graphs

2008-11-07 Thread Alex99

Hi guys,

I am truing to draw a circle and choose 10 points on the circle and put a
number from 1 to 10 above each point. I don't have a problem with drawing a
circle and choosing 10 points. my problem is with numbering . is it even
possible to put a number above each chosen point? if so any idea how to do
it?

ps: the circle has red dots and the selected points are in black.

here is my code:

D=cos(2*pi*(0:9)/10)
C=sin(2*pi*(0:9)/10)

x1=(sin((0:100)*2*pi/100))
y1=(cos((0:100)*2*pi/100))
plot(x1,y1,col=red)

points(C,D)

Thanks,
-- 
View this message in context: 
http://www.nabble.com/Help-With-Graphs-tp20385465p20385465.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] rmpi/snow/sge/openmpi help

2008-11-07 Thread Markus Schmidberger
Hi,

there is a new mailing list for R and HPC: [EMAIL PROTECTED]
This is probably a better list for your question. Do not forgett, first
of all you have to register: https://stat.ethz.ch/mailman/listinfo/r-sig-hpc

Did you tried to run openmpi and R without SGE?
Like this: orterun -n 1 R --no-save

I think openmpi / orterun do not get the correct hostfile. Therefore it
starts with a default hostfile and this is only for the local machine!
So all nodes are at the same machine.
It normally works like this that SGE creates a hostfile and puts the
path of the hostfile to a special (environment) variable. Now you have
to  make sure that the correct hostfile will be used. So SGE should call
something like this:
ortrun -n 1 --hostfile $PATH_TO_HOSTFILE R --so-save

Best
Markus




jk jk wrote:
 Forgive the spam.  Let me try that e-mail again.
 
 
 I'm trying to get snow working with openmpi and sge.  Everything
 appears to work, except the program only runs on 1 node.  If i tell
 snow to run on 5 nodes, it spawns 5 processes on a single node, 6
 nodes = 6 procs on 1 node and so on.  I'm at a loss for ideas.  Any
 help would be appreciated.
 
 Setup:  Rocks Cluster, OpenMPI, R 2.8.0, Snow, Rmpi.
 
 
 Please ask for specifics.  Thanks in advance.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Dipl.-Tech. Math. Markus Schmidberger

Ludwig-Maximilians-Universität München
IBE - Institut für medizinische Informationsverarbeitung,
Biometrie und Epidemiologie
Marchioninistr. 15, D-81377 Muenchen
URL: http://www.ibe.med.uni-muenchen.de
Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de
Tel: +49 (089) 7095 - 4599

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

2008-11-07 Thread Sarah Goslee
?text

On Fri, Nov 7, 2008 at 12:42 PM, Alex99 [EMAIL PROTECTED] wrote:

 Hi guys,

 I am truing to draw a circle and choose 10 points on the circle and put a
 number from 1 to 10 above each point. I don't have a problem with drawing a
 circle and choosing 10 points. my problem is with numbering . is it even
 possible to put a number above each chosen point? if so any idea how to do
 it?

 ps: the circle has red dots and the selected points are in black.

 here is my code:

 D=cos(2*pi*(0:9)/10)
 C=sin(2*pi*(0:9)/10)

 x1=(sin((0:100)*2*pi/100))
 y1=(cos((0:100)*2*pi/100))
 plot(x1,y1,col=red)

 points(C,D)

 Thanks,
 --
 View this message in context: 
 http://www.nabble.com/Help-With-Graphs-tp20385465p20385465.html
 Sent from the R help mailing list archive at Nabble.com.


-- 
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] Rmpi task-pull

2008-11-07 Thread Markus Schmidberger
Hi,

there is a new mailing list for R and HPC: [EMAIL PROTECTED]
This is probably a better list for your question. Do not forget, first
of all you have to register: https://stat.ethz.ch/mailman/listinfo/r-sig-hpc

I tried your code and it is working!

Please send us your sessionInfo() output. Probably you use some old
package versions?

Is this your first Rmpi code? Is other code working?

You can try something like this to get output from all nodes.
library(Rmpi)
mpi.spawn.Rslaves(nslaves=3)
mpi.remote.exec(paste(I am
node,mpi.comm.rank(),of,mpi.comm.size(),on,Sys.info()[nodename]))
mpi.remote.exec(sessionInfo())
mpi.close.Rslaves()
mpi.quit()

For some more debugging you can start your cluster with log output:
mpi.spawn.Rslaves(nslaves=3, needlog=TRUE)
Then there should be logfiles for every node in your working directory.

Best
Markus


Daniel Ferrara wrote:
 Hi, I'm testing the efficiency of the Rmpi package regarding parallelization
 using a cluster.
 I've found and tried the task pull programming method, but even if it is
 described as the best method, it seems to cause deadlock, anyone could help
 me in using this method?
 here is the code I've found and tried:
 
 
 # Initialize MPI
 library(Rmpi)
 
 # Notice we just say give us all the slaves you've got.
 mpi.spawn.Rslaves()
 
 if (mpi.comm.size()  2) {
 print(More slave processes are required.)
 mpi.quit()
 }
 
 .Last - function(){
 if (is.loaded(mpi_initialize)){
 if (mpi.comm.size(1)  0){
 print(Please use mpi.close.Rslaves() to close slaves.)
 mpi.close.Rslaves()
 }
 print(Please use mpi.quit() to quit R)
 .Call(mpi_finalize)
 }
 }
 
 # Function the slaves will call to perform a validation on the
 # fold equal to their slave number.
 # Assumes: thedata,fold,foldNumber,p
 foldslave - function() {
 # Note the use of the tag for sent messages:
 # 1=ready_for_task, 2=done_task, 3=exiting
 # Note the use of the tag for received messages:
 # 1=task, 2=done_tasks
 junk - 0
 
 done - 0
 while (done != 1) {
 # Signal being ready to receive a new task
 mpi.send.Robj(junk,0,1)
 
 # Receive a task
 task - mpi.recv.Robj(mpi.any.source(),mpi.any.tag())
 task_info - mpi.get.sourcetag()
 tag - task_info[2]
 
 if (tag == 1) {
 foldNumber - task$foldNumber
 
 rss - double(p)
 for (i in 1:p) {
 # produce a linear model on the first i variables on
 # training data
 templm - lm(y~.,data=thedata[fold!=foldNumber,1:(i+1)])
 
 # produce predicted data from test data
 yhat -
 predict(templm,newdata=thedata[fold==foldNumber,1:(i+1)])
 
 # get rss of yhat-y
 localrssresult - sum((yhat-thedata[fold==foldNumber,1])^2)
 rss[i] - localrssresult
 }
 
 # Send a results message back to the master
 results - list(result=rss,foldNumber=foldNumber)
 mpi.send.Robj(results,0,2)
 }
 else if (tag == 2) {
 done - 1
 }
 # We'll just ignore any unknown messages
 }
 
 mpi.send.Robj(junk,0,3)
 }
 
 # We're in the parent.
 # first make some data
 n - 1000# number of obs
 p - 30# number of variables
 
 # Create data as a set of n samples of p independent variables,
 # make a random beta with higher weights in the front.
 # Generate y's as y = beta*x + random
 x - matrix(rnorm(n*p),n,p)
 beta - c(rnorm(p/2,0,5),rnorm(p/2,0,.25))
 y - x %*% beta + rnorm(n,0,20)
 thedata - data.frame(y=y,x=x)
 
 fold - rep(1:10,length=n)
 fold - sample(fold)
 
 summary(lm(y~x))
 
 # Now, send the data to the slaves
 mpi.bcast.Robj2slave(thedata)
 mpi.bcast.Robj2slave(fold)
 mpi.bcast.Robj2slave(p)
 
 # Send the function to the slaves
 mpi.bcast.Robj2slave(foldslave)
 
 # Call the function in all the slaves to get them ready to
 # undertake tasks
 mpi.bcast.cmd(foldslave())
 
 
 # Create task list
 tasks - vector('list')
 for (i in 1:10) {
 tasks[[i]] - list(foldNumber=i)
 }
 
 # Create data structure to store the results
 rssresult = matrix(0,p,10)
 
 junk - 0
 closed_slaves - 0
 n_slaves - mpi.comm.size()-1
 
 while (closed_slaves  n_slaves) {
 # Receive a message from a slave
 message - mpi.recv.Robj(mpi.any.source(),mpi.any.tag())
 message_info - mpi.get.sourcetag()
 slave_id - message_info[1]
 tag - message_info[2]
 
 if (tag == 1) {
 # slave is ready for a task. Give it the next task, or tell it tasks
 
 # are done if there are none.
 if (length(tasks)  0) {
 # Send a task, and then remove it from the task list
 mpi.send.Robj(tasks[[1]], slave_id, 1);
 tasks[[1]] - NULL
 }
 else {
 mpi.send.Robj(junk, slave_id, 2)
 

Re: [R] For Loop - loading 10 sets of data and calculating

2008-11-07 Thread jim holtman
# I would put this in a list in the following manner

Bin - lapply(1:10, function(.file){

#---

#Loads bin data frame from csv files with acres and TAZ data
fileName -
paste(I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin,
.file, _lookup.csv, sep=)
Bin_main - read.csv(file=fileName,head=FALSE);

#Separates Acres data from main data and converts acres to square feet
Bin_Acres=Bin_main[[1]]*43560

#Separates TAZ data from main data
Bin_TAZ=Bin_main[[2]]

#Separates TAZ data from main data and converts acres to square feet
Bin_TAZvacant=Bin_main[[3]]*43560

#Sums each parcel acreage data of the bin
BinAcres_sum=sum(Bin_Acres)

#Creates data frame of cumlative percentages of each parcel of bin
Bin_cumper=cumsum(Bin_Acres/BinAcres_sum)

#Calculates the probability of choosing particular parcel from bin
Bin_parprob=abs(1-Bin_cumper)

#Combines parcel acreage data and cumlative percentage data
cbind(Bin_Acres,Bin_parprob,Bin_TAZ,Bin_TAZvacant)
})

On Fri, Nov 7, 2008 at 1:48 PM, PDXRugger [EMAIL PROTECTED] wrote:

 I am trying to simplify my code by adding a for loop that will load and
 compute a sequence of code 10 time.  They way i run it now is that the same
 8 lines of code are basically reproduced 10 times.  I would like to replace
 the numeric value in the code (e.g. Bin1, Bin2Bin10) each time the loop
 goes around.  Below i tried doing this with a simple for loop and adding the
 string character before each numeric value.  I need to first load the data
 then calculate, im sure this is possible as i have seen it done but cant
 seem to reproduce it in my own code.  Hope my question is clear and i hope
 someone can offer some guidance.

 Cheers,
 JR

 for (i in 1:10) {

 #---

 #Loads bin data frame from csv files with acres and TAZ data
 Bin$i_main -
 read.csv(file=I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin$i_lookup.csv,head=FALSE);

 #Separates Acres data from main data and converts acres to square feet
 Bin$i_Acres=Bin$i_main[[1]]*43560

 #Separates TAZ data from main data
 Bin$i_TAZ=Bin$i_main[[2]]

 #Separates TAZ data from main data and converts acres to square feet
 Bin$i_TAZvacant=Bin$i_main[[3]]*43560

 #Sums each parcel acreage data of the bin
 Bin$iAcres_sum=sum(Bin$i_Acres)

 #Creates data frame of cumlative percentages of each parcel of bin
 Bin$i_cumper=cumsum(Bin$i_Acres/Bin$iAcres_sum)

 #Calculates the probability of choosing particular parcel from bin
 Bin$i_parprob=abs(1-Bin$i_cumper)

 #Combines parcel acreage data and cumlative percentage data
 Bin$iMain.data = cbind(Bin%i_Acres,Bin$i_parprob,Bin$i_TAZ,Bin$i_TAZvacant)
 }

 --
 View this message in context: 
 http://www.nabble.com/For-Loop---loading-10-sets-of-data-and-calculating-tp20386673p20386673.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

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


Re: [R] Agent-based social simulation and R

2008-11-07 Thread Martin Elff
On Friday 07 November 2008 (19:45:04), you wrote:
 Martin Elff wrote:
  Hi Tom,
 
  my package 'memisc' contains a sort of an infrastructure for doing
  simulations. As a fun exercise I also used it to create a 'toy' agent
  based simulation of Schelling's neighbourhood model. Although it is not a
  serious application, at least it shows that agent based simulation is
  possible in R.
 
  Just run 'demo(schelling)' after loading 'memisc'.

 Interesting.  I'll have to look trough the code.  How far away do the
 agents see?  Anything beyond their immidiate neighbors?

In the demo, dissatisfied agents jump at random to free places. This puts the 
neighborhood model to the 'hardest' test. Yet the demo code also contains 
some other possibilities.

Best,
Martin

-- 
-
Dr. Martin Elff
Department of Social Sciences
University of Mannheim
A5, Room 328
68131 Mannheim
Germany

Phone: ++49-621-181-2093
Fax: ++49-621-181-2099
E-Mail: [EMAIL PROTECTED]
Homepage: 
http://webrum.uni-mannheim.de/sowi/elff
http://www.sowi.uni-mannheim.de/lspwivs/

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

2008-11-07 Thread Joseph Magagnoli
I estimated a negative binomial model using zelig.
z.out- zelig(NEWBHC~ PW80 + CHNGBLK + XBLK,data=data, model=negbin)

How do I calculate predicted probabilities for this model?  Is it the same
process as a poisson regression?
Thanks in advance
Joe

[[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] easy way to cap a data frame to a max value

2008-11-07 Thread Grey Moran
Hello,

I have some rather large matrices.  Is there a way (without having to
loop) to cap all the values of a data frame to a given ceiling?
E.g.
junk - cbind(c(1,2,3,4,5),c(2,4,6,8,10))
 junk
 [,1] [,2]
[1,]12
[2,]24
[3,]36
[4,]48
[5,]5   10

 replace anything over the value of 5 with 5...

Thank you all,

Grey

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


Re: [R] easy way to cap a data frame to a max value

2008-11-07 Thread Gabor Grothendieck
Assuming the data frame is all numeric:

DF[] - pmax(10, unlist(DF))


On Fri, Nov 7, 2008 at 4:16 PM, Grey Moran [EMAIL PROTECTED] wrote:
 Hello,

 I have some rather large matrices.  Is there a way (without having to
 loop) to cap all the values of a data frame to a given ceiling?
 E.g.
 junk - cbind(c(1,2,3,4,5),c(2,4,6,8,10))
 junk
 [,1] [,2]
 [1,]12
 [2,]24
 [3,]36
 [4,]48
 [5,]5   10

 replace anything over the value of 5 with 5...

 Thank you all,

 Grey

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] easy way to cap a data frame to a max value

2008-11-07 Thread Erik Iverson
Are they objects of class matrix or data.frame? You seem to make 
reference to both, but know there is a difference.


Try:

junk[junk  5] - 5



Grey Moran wrote:

Hello,

I have some rather large matrices.  Is there a way (without having to
loop) to cap all the values of a data frame to a given ceiling?
E.g.
junk - cbind(c(1,2,3,4,5),c(2,4,6,8,10))

junk

 [,1] [,2]
[1,]12
[2,]24
[3,]36
[4,]48
[5,]5   10


 replace anything over the value of 5 with 5...


Thank you all,

Grey

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] nls: Fitting two models at once?

2008-11-07 Thread Martin Ballaschk
Dear Heather!

Thank you very, very much for your solution which also reproduces exactly
the results I get from the SigmaPlot analysises. :)

Martin

Heather Turner schrieb:
 Dear Martin,
 
 You can use the same idea of concatenating the data in R. The following
 reproduces your example:
 
 spec - c(asfe, dias)
 n1 - length(asfe)
 n2 - length(dias)
 CYT - c(28 * CYTF, 24.6 * 2 * CYTB6)
 B559HP - c(B559HP, numeric(n2))
 B559LP - c(numeric(n1), B559LP)
 C550 - c(numeric(n1), C550)
 
 spec.fit -
 nls(
   spec ~ cyt.v*CYT + hp.v*B559HP + lp.v*B559LP + c550.v*C550,
   start = list(cyt.v = 0.5, hp.v = 0.03, lp.v = 1,
c550.v = 1) # arbitrary
 );
 
 or more efficiently, using lm
 
 spec.fit - lm(spec ~ 0 + CYT + B559HP + B559LP + C550)
 
 # draw stuff
 plot(
   1, 2,
   type=n,
   xlim = c(540, 575),
   ylim=c(-0.002, 0.008),
 );
 
 # first spectrum and fit
 lines(wl, asfe, type=b, pch=19); # solid circles
 lines(wl, fitted(spec.fit)[1:n1], col = red);
 
 # second spectrum and fit
 lines(wl, dias, type=b);
 lines(wl, fitted(spec.fit)[(n1 + 1):(n1 + n2)], col = blue);
 
 Best wishes,
 
 Heather
 
 Dr H Turner
 Senior Research Fellow
 Dept. of Statistics
 The University of Warwick
 Coventry
 CV4 7AL
 
 Tel: 024 76575870
 Fax: 024 76524532
 Url: www.warwick.ac.uk/go/heatherturner
 
 
 Martin Ballaschk wrote:
 Hello,
 
 I'm still a newbie user and struggling to automate some analyses from
 SigmaPlot using R. R is a great help for me so far!
 
 But the following problem makes me go nuts.
 
 I have two spectra, both have to be fitted to reference data. Problem: the
 both spectra are connected in some way: the stoichiometry of coefficients
 cytf.v/cytb.v is 1/2.
 {{In the SigmaPlot workflow one has to copy the two spectra into one column
 beneath each other and the  two spectra are somehow treated as one curve -
 like in http://home.arcor.de/ballaschk/cytbf-help/sigmaplot%20formula.png}}
 
 Can anybody help? :(
 
 I tried to condense everything to the minimum R script below to give an
 impression of what I'm talking about.
 
  Martin
 
 
 
 
 # Minimal R script reading remote data for convenience
 
 ### READ IN DATA
 # first spectrum
 asfe - read.table(http://home.arcor.de/ballaschk/cytbf-help/asfe.csv;)[, 
 1];
 # second spectrum
 dias - read.table(http://home.arcor.de/ballaschk/cytbf-help/dias.csv;)[, 
 1];
 
 # reference data for fit, wavelength = wl
 ref - read.table(http://home.arcor.de/ballaschk/cytbf-help/reference.csv;,
 sep=\t, dec=., header=T);
 attach(ref);
 
 ### FITTING, problem: 2*cytf.v == cytb.v
 
 # fit first spectrum to two reference spectra
 asfe.fit -
 nls(
  asfe ~ (cytf.v * 28) * CYTF + hp.v * B559HP,
  start = list(cytf.v = 0.5, hp.v = 0.03) # arbitrary
 );
 
 # fit second spectrum to three reference spectra
 dias.fit -
 nls(
  dias ~ (cytb.v * 24.6 * 2) * CYTB6 + lp.v * B559LP + c550.v * C550,
  start = list(cytb.v = 1, lp.v = 1, c550.v = 1) # arbitrary
 );
 
 
 # draw stuff
 plot(
  1, 2,
  type=n,
  xlim = c(540, 575),
  ylim=c(-0.002, 0.008),
 );
 
 # first spectrum and fit
 lines(wl, asfe, type=b, pch=19); # solid circles
 lines(wl, fitted(asfe.fit), col = red);
 
 # second spectrum and fit
 lines(wl, dias, type=b);
 lines(wl, fitted(dias.fit), col = blue);
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] easy way to cap a data frame to a max value

2008-11-07 Thread Gabor Grothendieck
That should be pmin:

On Fri, Nov 7, 2008 at 4:25 PM, Gabor Grothendieck
[EMAIL PROTECTED] wrote:
 Assuming the data frame is all numeric:

 DF[] - pmax(10, unlist(DF))


 On Fri, Nov 7, 2008 at 4:16 PM, Grey Moran [EMAIL PROTECTED] wrote:
 Hello,

 I have some rather large matrices.  Is there a way (without having to
 loop) to cap all the values of a data frame to a given ceiling?
 E.g.
 junk - cbind(c(1,2,3,4,5),c(2,4,6,8,10))
 junk
 [,1] [,2]
 [1,]12
 [2,]24
 [3,]36
 [4,]48
 [5,]5   10

 replace anything over the value of 5 with 5...

 Thank you all,

 Grey

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] easy way to cap a data frame to a max value

2008-11-07 Thread Grey Moran
Thanks to all who replied - lots of good ideas.
The one I prefered at the end was:
junk[junk  5] - 5

Grey

On Fri, Nov 7, 2008 at 4:38 PM, Gabor Grothendieck
[EMAIL PROTECTED] wrote:
 That should be pmin:

 On Fri, Nov 7, 2008 at 4:25 PM, Gabor Grothendieck
 [EMAIL PROTECTED] wrote:
 Assuming the data frame is all numeric:

 DF[] - pmax(10, unlist(DF))


 On Fri, Nov 7, 2008 at 4:16 PM, Grey Moran [EMAIL PROTECTED] wrote:
 Hello,

 I have some rather large matrices.  Is there a way (without having to
 loop) to cap all the values of a data frame to a given ceiling?
 E.g.
 junk - cbind(c(1,2,3,4,5),c(2,4,6,8,10))
 junk
 [,1] [,2]
 [1,]12
 [2,]24
 [3,]36
 [4,]48
 [5,]5   10

 replace anything over the value of 5 with 5...

 Thank you all,

 Grey

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] easy way to cap a data frame to a max value

2008-11-07 Thread Grey Moran
On Fri, Nov 7, 2008 at 4:46 PM, Grey Moran [EMAIL PROTECTED] wrote:
 Thanks to all who replied - lots of good ideas.
 The one I prefered at the end was:
 junk[junk  5] - 5

 Grey

 On Fri, Nov 7, 2008 at 4:38 PM, Gabor Grothendieck
 [EMAIL PROTECTED] wrote:
 That should be pmin:

 On Fri, Nov 7, 2008 at 4:25 PM, Gabor Grothendieck
 [EMAIL PROTECTED] wrote:
 Assuming the data frame is all numeric:

 DF[] - pmax(10, unlist(DF))


 On Fri, Nov 7, 2008 at 4:16 PM, Grey Moran [EMAIL PROTECTED] wrote:
 Hello,

 I have some rather large matrices.  Is there a way (without having to
 loop) to cap all the values of a data frame to a given ceiling?
 E.g.
 junk - cbind(c(1,2,3,4,5),c(2,4,6,8,10))
 junk
 [,1] [,2]
 [1,]12
 [2,]24
 [3,]36
 [4,]48
 [5,]5   10

 replace anything over the value of 5 with 5...

 Thank you all,

 Grey

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] easy way to cap a data frame to a max value

2008-11-07 Thread Gabor Grothendieck
A few more.  These each have the advantage of not
destroying the original data frame:

# based on Erik's
DF2 - replace(DF, DF  10, 10)

# based on my previous one
DF2 - replace(DF, TRUE, pmin(10, unlist(DF)))

DF2 - (DF + 10)/2 - abs(DF - 10)/2

On Fri, Nov 7, 2008 at 4:38 PM, Gabor Grothendieck
[EMAIL PROTECTED] wrote:
 That should be pmin:

 On Fri, Nov 7, 2008 at 4:25 PM, Gabor Grothendieck
 [EMAIL PROTECTED] wrote:
 Assuming the data frame is all numeric:

 DF[] - pmax(10, unlist(DF))


 On Fri, Nov 7, 2008 at 4:16 PM, Grey Moran [EMAIL PROTECTED] wrote:
 Hello,

 I have some rather large matrices.  Is there a way (without having to
 loop) to cap all the values of a data frame to a given ceiling?
 E.g.
 junk - cbind(c(1,2,3,4,5),c(2,4,6,8,10))
 junk
 [,1] [,2]
 [1,]12
 [2,]24
 [3,]36
 [4,]48
 [5,]5   10

 replace anything over the value of 5 with 5...

 Thank you all,

 Grey

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

2008-11-07 Thread stenka1

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 kind of Hosmer and Lemeshow’s test

2008-11-07 Thread Frank E Harrell Jr

leo_wa wrote:

I know that there are two method to apply the Hosmer and Lemeshow’s.  One of
them is calculated based on the fixed and pre-determined cut-off points of
the estimated probability of success.  One of them is calculated based on
the percentiles of estimated probabilities.  


Both of these methods have been made obsolete by methods that do not 
require any arbitrary groupings of predicted probabilities.  See the 
residuals.lrm function in the Design package and the reference in its 
help file, to the Hosmer paper.


Frank


In the previous post,i find that the Hosmer and Lemeshow’s test how to use
in R.
hosmerlem -
function (y, yhat, g = 10) 
{
cutyhat - cut(x, breaks = quantile(yhat, probs = seq(0, 
1, 1/g)), include.lowest = T)

obs - xtabs(cbind(1 - y, y) ~ cutyhat)
expect - xtabs(cbind(1 - yhat, yhat) ~ cutyhat)
chisq - sum((obs - expect)^2/expect)
P - 1 - pchisq(chisq, g - 2)
c(X^2 = chisq, Df = g - 2, P(Chi) = P)
}
I want to know how can i use the another method which is not use the
probability of success. i want to know how can i revise above program to
achieve an objective.



--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University

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

2008-11-07 Thread Denise Duarte
Hi,

I am trying to get R 2.8.0 for Mac OS from CRAN, but I thing I am
doing something wrong because when R starts I have annoying error
messages:

During startup - Warning messages:
1: Setting LC_CTYPE failed, using C
2: Setting LC_COLLATE failed, using C
3: Setting LC_TIME failed, using C
4: Setting LC_MESSAGES failed, using C
WARNING: You're using a non-UTF8 locale, therefore only ASCII
characters will work.
Please read R for Mac OS X FAQ (see Help) section 9 and adjust your
system preferences accordingly.

I have tried all suggestions in such section 9 but still get the same
error message. If you can give me some another suggestion It would be
very nice.

Sincerely,

Denise Duarte
UFMG- MG- Brazil

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


Re: [R] Re gular Expression help

2008-11-07 Thread Wacek Kusnierczyk
Peter Dalgaard wrote:
 Rajasekaramya wrote:
   
 hi there

 I have a vector with a set of data.I just wanna seperate them based on the
 first p and q values metioned within the data.

 [1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
 [2] chr1q22-q24 
 [3] chr1q22-q24 
 [4] chr1pter-q24
 [5] chr1pter-q24
 [6] chr1pter-q24  

 i used a regular expression [+q*] to match up the values but it matches q
 found anywhere i know i have written like that but i jus want it to match
 the first p or q values.

 my result should be for q and 
 [2] chr1q22-q24  
 [3] chr1q22-q24  

 for p
 [1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
 [4] chr1pter-q24
 [5] chr1pter-q24
 [6] chr1pter-q24 

 

 Something like

 sub([^pq]*([pq]).*,\\1,x)

 should get you the first p or q

   

and the following will do the whole job (assuming x is your vector):

result = lapply(
   list(p='p', q='q'),
   function(letter)
  grep(paste(^[^pq]*[, ], sep=letter), x, value=TRUE))

result$p
# those with p first

result$q
# those with q first

vQ

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

2008-11-07 Thread Swanton0822

Hi.
i have a data, and there is 3 columns, Month, Year and Total. and there is
over 1000 rows for them because there is 87 years data for every month, so
there is month from Jan-Dec, and year from 1900-1987,
so i was wondering if i would want to make 12 groups (Jan,Feb...,Dec),
and put each year's total into the corresponding month (so every month group
will have 88 values of total)
how can i do that?
many thanks.
-- 
View this message in context: 
http://www.nabble.com/grouping-data-together-tp20389726p20389726.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Faster way to combine data sets with different date ranges

2008-11-07 Thread t c
I am trying to combine two data sets, one with daily values and one with weekly 
values.  SurveyData conatins environmental data collected on a daily basis.  
sat.data contains satellite sea surface temperature that is an average of 
satellite measurements over a six day period.  I would like to combine the two 
files so that my output file has the daily dates from SurveyData and the weekly 
average from sat.data that corresponds to that day.  I have written a loop that 
does exactly what I want, but it takes a very long time.  Is there a faster way 
to do this?  What I have so far is below.
Thanks,
Tim

#Compare dates
 for(i in 1:length(SurveyData$Date))
 {
 print(i)
 for(j in 1:length(sat.data$Date.Start))
  {
  if(
  sat.data$Date.Start[j]=SurveyData$Date[i] 
  sat.data$Date.End[j]=SurveyData$Date[i])
  survey.data[i]- sat.data$data[j]
  }
 } 
 
#Create data frame with final data
 final.data-data.frame(SurveyData$Record,SurveyData$Date,survey.data)
 
#Write data to file
 write.csv(final.data,file=Combined.csv)



  
[[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] Re gular Expression help

2008-11-07 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote:
 Peter Dalgaard wrote:
   
 Rajasekaramya wrote:
   
 
 hi there

 I have a vector with a set of data.I just wanna seperate them based on the
 first p and q values metioned within the data.

 [1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
 [2] chr1q22-q24 
 [3] chr1q22-q24 
 [4] chr1pter-q24
 [5] chr1pter-q24
 [6] chr1pter-q24  

 i used a regular expression [+q*] to match up the values but it matches q
 found anywhere i know i have written like that but i jus want it to match
 the first p or q values.

 my result should be for q and 
 [2] chr1q22-q24  
 [3] chr1q22-q24  

 for p
 [1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
 [4] chr1pter-q24
 [5] chr1pter-q24
 [6] chr1pter-q24 

 
   
 Something like

 sub([^pq]*([pq]).*,\\1,x)

 should get you the first p or q

   
 

 and the following will do the whole job (assuming x is your vector):

 result = lapply(
list(p='p', q='q'),
function(letter)
   grep(paste(^[^pq]*[, ], sep=letter), x, value=TRUE))

   

and this one might be slightly faster, depending on your data:

result = local({
   p = grep(^[^pq]*p, d)
   list(p=d[p], q=d[-p])
})

vQ

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


Re: [R] Re gular Expression help

2008-11-07 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote:

   
 
 Rajasekaramya wrote:
   
 
   
 hi there

 I have a vector with a set of data.I just wanna seperate them based on the
 first p and q values metioned within the data.

 [1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
 [2] chr1q22-q24 
 [3] chr1q22-q24 
 [4] chr1pter-q24
 [5] chr1pter-q24
 [6] chr1pter-q24  

 i used a regular expression [+q*] to match up the values but it matches q
 found anywhere i know i have written like that but i jus want it to match
 the first p or q values.

 my result should be for q and 
 [2] chr1q22-q24  
 [3] chr1q22-q24  

 for p
 [1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
 [4] chr1pter-q24
 [5] chr1pter-q24
 [6] chr1pter-q24 


 
 the following will do the whole job (assuming x is your vector):


 
 result = local({
p = grep(^[^pq]*p, d)
list(p=d[p], q=d[-p])
 })
   

oops, replace 'd' with 'x'

vQ

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


Re: [R] Re gular Expression help

2008-11-07 Thread Gabor Grothendieck
Here are a few more solutions.  x is the input vector
of character strings.

The first is a slightly shorter version of one of Wacek's.
The next three all create an anonymous grouping variable
(using sub, substr/gsub and strapply respectively)
whose components are p and q and then tapply
is used to separate out the corresponding components
of x according to the grouping:

sapply(c(p = ^[^pq]*p, q = ^[^pq]*q), grep, x = x, value = TRUE)

tapply(x, sub(^[^pq]*(.).*, \\1, x), c)

tapply(x, substr(gsub([^pq], , x), 1, 1), c)

library(gsubfn)
tapply(x, strapply(x, ^[^pq]*(.), simplify = c), c)

On Fri, Nov 7, 2008 at 1:09 PM, Rajasekaramya [EMAIL PROTECTED] wrote:

 hi there

 I have a vector with a set of data.I just wanna seperate them based on the
 first p and q values metioned within the data.

 [1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
 [2] chr1q22-q24
 [3] chr1q22-q24
 [4] chr1pter-q24
 [5] chr1pter-q24
 [6] chr1pter-q24

 i used a regular expression [+q*] to match up the values but it matches q
 found anywhere i know i have written like that but i jus want it to match
 the first p or q values.

 my result should be for q and
 [2] chr1q22-q24
 [3] chr1q22-q24

 for p
 [1] chr10p15.3 /// chr3q29 /// chr4q35 /// chr9q34.3
 [4] chr1pter-q24
 [5] chr1pter-q24
 [6] chr1pter-q24



 --
 View this message in context: 
 http://www.nabble.com/Regular-Expression-help-tp20385971p20385971.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


[R] missing value where TRUE/FALSE needed

2008-11-07 Thread David Croll

Hello dear R people,


for my MSc thesis I need to program some functions, and some of them 
simply do not work. In the following example, I made sure both vectors 
have the same length (10), but R gives me the following error:


Error in if (vector1[i] == vector2[j]) { :
 missing value where TRUE/FALSE needed

I googled for possible solutions, but I did not find a good explanation 
for this...



The code:

test - function() {
  
   vector1 - sample(1:100,10)

   vector2 - sample(1:100,10)
  
   for (i in vector1) {
  
   for (j in vector2) {
  
   if (vector1[i] == vector2[j]) {
  
   show(list(i,j))
  
   }
  
   }
  
   }
  
   }   



Regards, 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] esoteric inconsistency -- intended or not?

2008-11-07 Thread Felix Andrews
2008/11/8 Bert Gunter [EMAIL PROTECTED]:
 Is the following intended or not?

 func- function(y) match.call()

 z - func(y =2)

 z
 func(y = 2)

 z[[a]] - 5

 z
 func(y = 2, 5) ## Note that the second argument **is not** named

 ## BUT...

 z - func(y =2)

 z$a - 5

 z
 func(y = 2, a = 5) ## The second argument **is** named

 ### End of example code ###

 The reason I ask is that the man page for [[ specifically says:
 **
 Both [[ and $ select a single element of the list. The main difference is
 that $ does not allow computed indices, whereas [[ does. x$name is
 equivalent to x[[name, exact = FALSE]]. Also, the partial matching
 behavior of [[ can be controlled using the exact argument.

 [ and [[ are sometimes applied to other recursive objects such as calls and
 expressions. Pairlists are coerced to lists for extraction by [, but all
 three operators can be used for replacement.

 
  I (mis?)read this as saying the behavior in the code snippets above should
 produce identical results.

 I note that the above inconsistency can be trivially avoided by first
 coercing the call object to a list, modifying it either way, and then
 coercing it back to a call object.

I too have been caught by this apparent inconsistency a few times.

By the way, another way to get around it is
z - quote(func(y = 2))
z[a] - list(5)

Another inconsistency between the indexing of lists and calls is
recursive indexing, e.g.

## recursive indexing of lists works
 foo - list(a = list(1, 2, 3), b = list(4, 5, 6))
 foo[[c(2,2)]]
[1] 5

## recursive indexing of calls fails
 foocall - quote(func(a = list(1, 2, 3), b = list(4, 5, 6)))
 foocall[[c(3, 2)]]
Error in foocall[[c(3, 2)]] : attempt to select more than one element

OK, this is pretty obscure, and it is easy enough to write a function
to do it (as I have done), but it would be nice to have in the long
run, so that indexing is more standardised.


-- 
Felix Andrews / 安福立
http://www.neurofractal.org/felix/
3358 543D AAC6 22C2 D336  80D9 360B 72DD 3E4C F5D8

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


Re: [R] missing value where TRUE/FALSE needed

2008-11-07 Thread cruz
is this what you want?

 vector1
 [1]  65   1  34 100  42  20  79  43  89  10
 vector2
 [1] 34 65 47 91 48 32 23 74 92 86

 for (i in 1:10) {
+   for (j in 1:10) {
+ if (vector1[i] == vector2[j])
+ show(c(i,j))
+ }
+  }
[1] 1 2
[1] 3 1



On Sat, Nov 8, 2008 at 8:22 AM, David Croll [EMAIL PROTECTED] wrote:
 Hello dear R people,


 for my MSc thesis I need to program some functions, and some of them simply
 do not work. In the following example, I made sure both vectors have the
 same length (10), but R gives me the following error:

 Error in if (vector1[i] == vector2[j]) { :
  missing value where TRUE/FALSE needed

 I googled for possible solutions, but I did not find a good explanation for
 this...


 The code:

 test - function() {
 vector1 - sample(1:100,10)
   vector2 - sample(1:100,10)
 for (i in vector1) {
 for (j in vector2) {
 if (vector1[i] == vector2[j]) {
 show(list(i,j))
 }
 }
 }
 }

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


Re: [R] grouping data together

2008-11-07 Thread cruz
hi friend,

this is from your previous posts on Kruskal-Wallis test:)
i came up with this one:

A5 - read.table('kew.dat' ,header=TRUE)
plot(factor(A5$Month, levels=month.abb), A5$Rain)

is that what you want?


On Sat, Nov 8, 2008 at 7:03 AM, Swanton0822 [EMAIL PROTECTED] wrote:

 Hi.
 i have a data, and there is 3 columns, Month, Year and Total. and there is
 over 1000 rows for them because there is 87 years data for every month, so
 there is month from Jan-Dec, and year from 1900-1987,
 so i was wondering if i would want to make 12 groups (Jan,Feb...,Dec),
 and put each year's total into the corresponding month (so every month group
 will have 88 values of total)
 how can i do that?
 many thanks.

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


  1   2   >