[R] Clash between alr3 and AlgDesign. (Was: Re: Second subsequent calls to function fails. Please help debug.)

2008-03-30 Thread Michael Kubovy
Thanks, Duncan,

I started a new session under the suspicion that packages were clashing.
#
# RUN 1
#
require(faraway)
# Loading required package: faraway
data(oatvar)
ov.lm - lm(yield ~ variety + block, oatvar)
require(alr3)
# Loading required package: alr3
out - tukey.nonadd.test(ov.lm)
#
# RUN 1 OK
# RUN 2
#
require(HH)
#Loading required package: HH
#Loading required package: lattice
#
#Attaching package: 'lattice'
#
#
#   The following object(s) are masked from package:faraway :
#
#melanoma
#
#Loading required package: grid
#Loading required package: multcomp
#Loading required package: mvtnorm
#
#Attaching package: 'HH'
#
#
#   The following object(s) are masked from package:alr3 :
#
#residual.plots
#
#
#   The following object(s) are masked from package:faraway :
#
#vif,
#vif.default,
#vif.lm
#
out - tukey.nonadd.test(ov.lm)
#
# RUN 2 OK
# RUN 3
#
require(crossdes)
#Loading required package: crossdes
#Loading required package: AlgDesign
#Loading required package: gtools
#
#Attaching package: 'gtools'
#
#
#   The following object(s) are masked from package:faraway :
#
#logit
#
#Loading required package: MASS
#Loading required package: grDevices
out - tukey.nonadd.test(ov.lm)
#Error in parse(text = x) :
#  unexpected symbol in yield ~ variety + block + preds(yield+variety 
+block+preds.sq)sq
#
# RUN 3 FAILS
#

#
# CHECKING FOR INTERACTION AMONG PACKAGES
#
require(MASS)
#Loading required package: MASS
#Loading required package: grDevices
out - tukey.nonadd.test(ov.lm)
require(gtools)
#Loading required package: gtools
#
#Attaching package: 'gtools'
#
#
#   The following object(s) are masked from package:faraway :
#
#logit
#
#
out - tukey.nonadd.test(ov.lm)
#
# alr3 pays well with MASS, grDevices, gtools
#
require(AlgDesign)
#Loading required package: AlgDesign
out - tukey.nonadd.test(ov.lm)
#Error in parse(text = x) :
#  unexpected symbol in yield ~ variety + block + preds(yield+variety 
+block+preds.sq)sq
require(crossdes)
#Loading required package: crossdes
out - tukey.nonadd.test(ov.lm)
#Error in parse(text = x) :
#  unexpected symbol in yield ~ variety + block + preds(yield+variety 
+block+preds.sq)sq
#
# BAD INTERACTION BETWEEN alr3 and AlgDesign
#

What now?

_
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS: P.O.Box 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
 McCormick RoadCharlottesville, VA 22903
Office:B011+1-434-982-4729
Lab:B019+1-434-982-4751
Fax:+1-434-982-4766
WWW:http://www.people.virginia.edu/~mk9y/

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

2008-03-30 Thread Christophe Genolini
Hi the list

I made up a new statistical procedure. I will publish it in a medical 
journal, but there will be only the way of using it, no calculation or 
algorithme detail.
So is there a journal (I mean scientific journal) with selection commity 
to submit an article describing the detail of a package?

Christophe

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


Re: [R] Defining reference category for a cph model summary inside of a for loop

2008-03-30 Thread Frank E Harrell Jr
Wells, Brian wrote:
 Dr. Harrell, 
 Thanks for you help. 
 
 I tried:
 
 print(summary(f,parse(text=paste(i,'=1st Quartile', sep=''
 
 Same result. No error, the reference category simply doesn't change. 

That's good, because the default in summary is to compare the outer 
quartiles for a continuous variable.  And as I said before the string 
'1st Quartile' has no special meaning for R or Design.

Get what you are trying to do to work without parse (and you'll need 
eval() with parse) first.  When you want total control over a setting, 
say getting a hazard ratio for the .2 to the .8 quantile, do something like

summary(f, age=quantile(age,c(.2,.8),na.rm=TRUE))

Frank

 
 Brian 
 
 -Original Message-
 From: Frank E Harrell Jr [mailto:[EMAIL PROTECTED] 
 Sent: Friday, March 28, 2008 8:34 PM
 To: Wells, Brian
 Cc: r-help@r-project.org
 Subject: Re: [R] Defining reference category for a cph model summary
 inside of a for loop
 
 Wells, Brian wrote:
 I have the following code. 

  

  

 f - cph(formula = Surv(TimeToDeath, Dead == Yes)
 ~1,data=single.dat, x=T, y=T, surv=T)

 for(i in c('A', 'B', 'C', 'D', 'E', 'F')){
 f -update(f,as.formula(paste('Surv(TimeToDeath, Dead ==
 Yes)~',i,sep='')))

 print(summary(f, paste(i,=1st Quartile, sep='')))
  

  

 There is no error message generated in R, but R ignores the reference
 category defined with paste in the summary function for the cph model.
 
  

 The output uses the 1st Quartile as the reference category to
 calculate hazards for some of the variables defined by i, but not all
 of
 them. 
 
 
 Your code is confusing.  What is to the right of ~ in a formula is a 
 predictor variable name, not a value.  If your variables are named A, B,
 
 C, ... you are OK.
 
 '1st Quartile' has no special meaning to R or Design, and you can't pass
 
 a character string as a second argument to summary and expect it to
 work.
 
 You will need parse(text=paste(...)) to create an appropriate
 expression.
 
 But Design gives you inter-quartile range hazard ratios by default
 anyway.
 
 Beware of getting hazard ratios that are not adjusted for other 
 variables needed in the model.
 
 Frank Harrell
 
  

  

 Any help would be greatly appreciated. 

  

 thanks

  

 Brian J. Wells, MD, MS

 Research Associate

 Quantitative Health Sciences

 Cleveland Clinic

 


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


Re: [R] Journal for R

2008-03-30 Thread Gavin Simpson
On Sun, 2008-03-30 at 15:01 +0200, Christophe Genolini wrote:
 Hi the list
 
 I made up a new statistical procedure. I will publish it in a medical 
 journal, but there will be only the way of using it, no calculation or 
 algorithme detail.
 So is there a journal (I mean scientific journal) with selection commity 
 to submit an article describing the detail of a package?

There may be others, perhaps dedicated to a particular area of study
(e.g. Computers and Geosciences, and Ecological Modelling might be
appropriate places for the broad area of environmetrics), but the
Journal of Statistical Software is an obvious choice for what you
describe.

www.jstatsoft.org

HTH

G

 
 Christophe
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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


Re: [R] Clash between alr3 and AlgDesign. (Was: Re: Second subsequent calls to function fails. Please help debug.)

2008-03-30 Thread Duncan Murdoch
On 30/03/2008 8:43 AM, Michael Kubovy wrote:
 Thanks, Duncan,
 
 I started a new session under the suspicion that packages were clashing.

  ...

 #
 # BAD INTERACTION BETWEEN alr3 and AlgDesign
 #
 
 What now?

There's not much you can do; this is up to the package authors to fix. 
Some advice for them:

alr3, crossdes, faraway, and HH don't use a namespace.  This makes them 
very vulnerable to this sort of interaction, because they don't get to 
choose where the functions they use come from.  They should add one.

In my opinion, all packages should have namespaces, and I'd like to 
create a default one if the author doesn't.  (The default would be: 
import what is listed in the Depends clause, export everything.)  I 
don't think this will happen for 2.7.0, though package.skeleton might 
start creating one.

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] Journal for R

2008-03-30 Thread Peter Dalgaard
Gavin Simpson wrote:
 On Sun, 2008-03-30 at 15:01 +0200, Christophe Genolini wrote:
   
 Hi the list

 I made up a new statistical procedure. I will publish it in a medical 
 journal, but there will be only the way of using it, no calculation or 
 algorithme detail.
 So is there a journal (I mean scientific journal) with selection commity 
 to submit an article describing the detail of a package?
 

 There may be others, perhaps dedicated to a particular area of study
 (e.g. Computers and Geosciences, and Ecological Modelling might be
 appropriate places for the broad area of environmetrics), but the
 Journal of Statistical Software is an obvious choice for what you
 describe.

 www.jstatsoft.org

 HTH

 G
   
Also, let me remind you and others that R News is also peer reviewed 
(although not yet indexed).
It specifically includes solicits short to medium length articles of the 
following kinds

* Changes in R: new features of the latest release
* Changes on CRAN: new add-on packages, manuals, binary
  distributions, mirrors,...
* Add-on packages: short introductions to or reviews of R extension
  packages
* Programmer's Niche: nifty hints for programming in R (or S)
* Hints for newcomers: Explaining sides of R that might not be so
  obvious from reading the manuals and FAQs.
* Applications: Examples of analyzing data with R

Lengthier papers are probably better placed in the JSS, JCGS 
(J.Computational and Graphical Statistics), or CSDA (Computational 
Statistics and Data Analysis), depending on contents. For in-depth 
descriptions of packages, JSS has become quite popular in recent years

-pd
(Current associate editor for R News, past AE for JSS)

-- 
   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] tests Rin Rout

2008-03-30 Thread Christophe Genolini
Hi the list,

Some rumour (!) say that is it possible to prepare some tests for 
checking our code using .Rin and .Rout. It seems to be a very good 
practice, but I did not manage to find information on it.
So does someone know how it works ? What are we suppose to write in Rin ?

More precisely :
 - I have a package myPack.r in directories ~/myR/myPack/R/
 - I create the directory ~/myR/myPack/tests

myPack.r is :

`f1` - function(x){cat(\nXXX F1 = ,x,XXX\n)}
`f2` - function(x){cat(\nXXX F2 = ,f1(x^2),XXX\n)}

What am I suppose to do to test it? Create myPack.Rin, but what in it?

Thanks for your help.

Christophe

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


[R] convert weekly time series data to monthly

2008-03-30 Thread Richard Saba

I have weekly time series data with year, month, day, and price variables.
The input data set for the weekly series takes the following form: 

 Year   month   day price
19908   20  119.1   
19908   27  124.5
19909   3   124.2
19909   10  125.2
19909   17  126.6
19909   24  127.2
199010  1   132.1
199010  8   133.3
199010  15  133.9
199010  22  134.5
199010  29  133.9
..  ... ... ...
... ... 
20083   3   313.7
20083   10  320
20083   17  325.7
20083   24  322.4 


I would like to collapse the data into monthly averages to merge with a
monthly series. The input data set for the monthly series takes the
following form: 

M-Y YearMonth   Change
Aug-199019908   -226.871
Sep-199019909   -896.333
Oct-1990199010  111.419
Nov-1990199011  -364.2
Dec-1990199012  -527.645
Jan-199119911   -70.935
Feb-199119912   231.214
Mar-199119913   -239 

... ... .   ..  


The merged data set should be of class(ts).
I can perform the conversions outside of R  and then import but I would
rather perform all conversions within R. I have looked through the zoo and
Rmetrics packages but without success. 

Any help will be appreciated.
Thanks,

Richard Saba
Department of Economics
Auburn University
Email:  [EMAIL PROTECTED]
Phone:  334 844-2922

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


Re: [R] Clash between alr3 and AlgDesign. (Was: Re: Second subsequent calls to function fails. Please help debug.)

2008-03-30 Thread Gabor Grothendieck
On Sun, Mar 30, 2008 at 9:43 AM, Duncan Murdoch [EMAIL PROTECTED] wrote:
 In my opinion, all packages should have namespaces, and I'd like to
 create a default one if the author doesn't.  (The default would be:
 import what is listed in the Depends clause, export everything.)  I
 don't think this will happen for 2.7.0, though package.skeleton might
 start creating one.

Namespaces are such a pain when you don't really need them though.
Its nice just to be able to source a new version of a function and have
it immediately work with the package.  Particularly for packages that
are changing or for which there is substantial code changes in the
devel version this is very convenient and namespaces interefere with that.

Although its possible to have namespace problems as discussed in this
thread I have found that it rarely actually happens and certainly not enough
to impose it.

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


Re: [R] convert weekly time series data to monthly

2008-03-30 Thread Henrique Dallazuanna
If I understand:

x.new - cbind('M.Y'=paste(month.abb[x$month], x$Year, sep=-), x[-3])
aggregate(list(Change=x.new$price),
  list(M.Y=x.new[,M.Y], Year=x.new$Year,
Month=x.new$month),   FUN=mean)

On 30/03/2008, Richard Saba [EMAIL PROTECTED] wrote:

 I have weekly time series data with year, month, day, and price variables.
 The input data set for the weekly series takes the following form:

  Year month   day price
 1990  8   20  119.1   
 1990  8   27  124.5
 1990  9   3   124.2
 1990  9   10  125.2
 1990  9   17  126.6
 1990  9   24  127.2
 1990  10  1   132.1
 1990  10  8   133.3
 1990  10  15  133.9
 1990  10  22  134.5
 1990  10  29  133.9
 ..... ... ...
 ...   ... 
 2008  3   3   313.7
 2008  3   10  320
 2008  3   17  325.7
 2008  3   24  322.4


 I would like to collapse the data into monthly averages to merge with a
 monthly series. The input data set for the monthly series takes the
 following form:

 M-Y   YearMonth   Change
 Aug-1990  19908   -226.871
 Sep-1990  19909   -896.333
 Oct-1990  199010  111.419
 Nov-1990  199011  -364.2
 Dec-1990  199012  -527.645
 Jan-1991  19911   -70.935
 Feb-1991  19912   231.214
 Mar-1991  19913   -239

 ...   ... .   ..  


 The merged data set should be of class(ts).
 I can perform the conversions outside of R  and then import but I would
 rather perform all conversions within R. I have looked through the zoo and
 Rmetrics packages but without success.

 Any help will be appreciated.
 Thanks,

 Richard Saba
 Department of Economics
 Auburn University
 Email:  [EMAIL PROTECTED]
 Phone:  334 844-2922

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

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


Re: [R] convert weekly time series data to monthly

2008-03-30 Thread Gabor Grothendieck
Do you mean merge them into a two column series of price
for one column and change for another column?  That is what
I will assume since the result was not illustrated.

Suggest you read the help files and the three
vignettes in the zoo package.

Also R News 4/1 has info on dates.

If you were looking for OHLC representations then see
the xts package which in turn uses zoo and read its
documentation in addition to the above.


library(zoo) # ensure you are using zoo 1.5.0 or later
price.Lines - Year   month   day price
19908   20  119.1
19908   27  124.5
19909   3   124.2
19909   10  125.2
19909   17  126.6
19909   24  127.2
199010  1   132.1
199010  8   133.3
199010  15  133.9
199010  22  134.5
199010  29  133.9
20083   3   313.7
20083   10  320
20083   17  325.7
20083   24  322.4

price.DF - read.table(textConnection(price.Lines), header = TRUE)
price - with(price.DF,
zoo(price, as.Date(paste(Year, month, day, sep = -

change.Lines - M-Y YearMonth   Change
Aug-199019908   -226.871
Sep-199019909   -896.333
Oct-1990199010  111.419
Nov-1990199011  -364.2
Dec-1990199012  -527.645
Jan-199119911   -70.935
Feb-199119912   231.214
Mar-199119913   -239

change - read.zoo(textConnection(change.Lines), header = TRUE,
FUN = as.yearmon, format = %b-%Y,
colClasses = c(character, NULL, NULL, numeric))

# convert change series to Date using last of month as the date
time(change) - as.Date(time(change), frac = 1)

merge(price, change)


On Sun, Mar 30, 2008 at 11:24 AM, Richard Saba [EMAIL PROTECTED] wrote:

 I have weekly time series data with year, month, day, and price variables.
 The input data set for the weekly series takes the following form:

  Year   month   day price
 19908   20  119.1
 19908   27  124.5
 19909   3   124.2
 19909   10  125.2
 19909   17  126.6
 19909   24  127.2
 199010  1   132.1
 199010  8   133.3
 199010  15  133.9
 199010  22  134.5
 199010  29  133.9
 ..  ... ... ...
 ... ... 
 20083   3   313.7
 20083   10  320
 20083   17  325.7
 20083   24  322.4


 I would like to collapse the data into monthly averages to merge with a
 monthly series. The input data set for the monthly series takes the
 following form:

 M-Y YearMonth   Change
 Aug-199019908   -226.871
 Sep-199019909   -896.333
 Oct-1990199010  111.419
 Nov-1990199011  -364.2
 Dec-1990199012  -527.645
 Jan-199119911   -70.935
 Feb-199119912   231.214
 Mar-199119913   -239

 ... ... .   ..  


 The merged data set should be of class(ts).
 I can perform the conversions outside of R  and then import but I would
 rather perform all conversions within R. I have looked through the zoo and
 Rmetrics packages but without success.

 Any help will be appreciated.
 Thanks,

 Richard Saba
 Department of Economics
 Auburn University
 Email:  [EMAIL PROTECTED]
 Phone:  334 844-2922

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Quick question: Does this graph have a name?

2008-03-30 Thread mika03

Thanks a lot for all your replies so far!

I now share your feeling that this might not be the best way to show the
data.

Here's what the data is about: We have search engine queries (12,000 of
them), which are grouped into semantic categories. (Some ask for a Person,
some are about celebrity Gossip etc., you can see this on the x-axis.)

Then we asked three subjects for each query, how they think the query should
best be answered, we were mainly interested in the preferred length of the
response (y-axis: With a phrase, a sentence, a text paragraph etc.)

We want to show in this graph,
1) that users indeed think that queries from different semantic categories
should be answered with responses of different lengths. (That a Yes/No
answer basically.)
2) how the different length categories are distributed in the individual
semantic categories.

I hope this was somewhat clear..?

Thanks!

-- 
View this message in context: 
http://www.nabble.com/Quick-question%3A-Does-this-graph-have-a-name--tp16349649p16384250.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] Problem: using cor.test with by( )

2008-03-30 Thread Che-hsu (Joe) Chang
Hello everyone, 

 

I'm a new R user switching from SAS and JMP. In the first few days, I have
been trying to do a fairly simple task but yet found no success. I've
checked the help archive as well as few R textbooks but didn't seem to find
the answer. So, please help me if you can.

 

Basically, I want to calculate the correlation between variable A and B for
every subject in my study. (yep, that simple)

What I did is this:

 

by(data, id, function (x) cor.test(A,B, data=x))

 

The results gave me numbers of correlation for each subject. But, the
problem is that, all these correlations are the same numbers and the sample
size was always the entire database (including all subjects). I've also
tried the lm function instead of the cor.test, and the by() function works
fine. Can any of you tell me what I did wrong? Or could you tell me what is
the best way to apply a function by subjects? Thank you!

 

 

Best,

Che-hsu (Joe) Chang, Sc.D., P.T.

 


[[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] Journal for R

2008-03-30 Thread Mark Kimpel
As a medical researcher, I keep tabs on the journals Bioinformatics andd BMC
Bioinformatics. If your package is for 'omics, those are good journals to
look at.
Mark

On Sun, Mar 30, 2008 at 10:02 AM, Peter Dalgaard [EMAIL PROTECTED]
wrote:

 Gavin Simpson wrote:
  On Sun, 2008-03-30 at 15:01 +0200, Christophe Genolini wrote:
 
  Hi the list
 
  I made up a new statistical procedure. I will publish it in a medical
  journal, but there will be only the way of using it, no calculation or
  algorithme detail.
  So is there a journal (I mean scientific journal) with selection
 commity
  to submit an article describing the detail of a package?
 
 
  There may be others, perhaps dedicated to a particular area of study
  (e.g. Computers and Geosciences, and Ecological Modelling might be
  appropriate places for the broad area of environmetrics), but the
  Journal of Statistical Software is an obvious choice for what you
  describe.
 
  www.jstatsoft.org
 
  HTH
 
  G
 
 Also, let me remind you and others that R News is also peer reviewed
 (although not yet indexed).
 It specifically includes solicits short to medium length articles of the
 following kinds

* Changes in R: new features of the latest release
* Changes on CRAN: new add-on packages, manuals, binary
  distributions, mirrors,...
* Add-on packages: short introductions to or reviews of R extension
  packages
* Programmer's Niche: nifty hints for programming in R (or S)
* Hints for newcomers: Explaining sides of R that might not be so
  obvious from reading the manuals and FAQs.
* Applications: Examples of analyzing data with R

 Lengthier papers are probably better placed in the JSS, JCGS
 (J.Computational and Graphical Statistics), or CSDA (Computational
 Statistics and Data Analysis), depending on contents. For in-depth
 descriptions of packages, JSS has become quite popular in recent years

-pd
(Current associate editor for R News, past AE for JSS)

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




-- 
Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry
Indiana University School of Medicine

15032 Hunter Court, Westfield, IN 46074

(317) 490-5129 Work,  Mobile  VoiceMail
(317) 663-0513 Home (no voice mail please)

**

[[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] Clash between alr3 and AlgDesign. (Was: Re: Second subsequent calls to function fails. Please help debug.)

2008-03-30 Thread Michael Kubovy
Hi Duncan,

Yes, I came to realize that ifelse was not the way to go. Here is how  
I dealt with it:

if(sum('AlgDesign' == (.packages()))  0) detach('package:AlgDesign')

It requires me (and my students) to learn only the (.packages())  
construct (and avoid knowing anything about search(), match() or pos).  
As a former student of mine (who has long since gone into business)  
once said: I avoid learning experiences like the plague.

Thanks again,
Michael

On Mar 30, 2008, at 1:36 PM, Duncan Murdoch wrote:

 On 30/03/2008 10:06 AM, Michael Kubovy wrote:
 I've been trying to dynamically detach and attach things in my  
 Sweave,  in order to circumvent the problem.
 Here is my first attempt:
 pkg - 'package:AlgDesign'
 p - is.na(match(pkg, search()))
 ifelse(p  == FALSE, detach(pkg), NA)

 You can't use detach this way.  It is fine to say  
 detach(package:AlgDesign) or detach(AlgDesign), but the way detach  
 is written, you're attempting to detach something named pkg.

 This rewrite of your code is untested, but I think it should work:

 pkg - 'package:AlgDesign'
 p - match(pkg, search())
 if (!is.na(p)) detach(pos=p)
 require(alr3)

 I've also changed your ifelse() to if (), and not just because I  
 don't need an else clause:  ifelse() is designed to do computations  
 on vectors, if() is designed for flow control.  I think we want flow  
 control here.

 Duncan Murdoch

_
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS: P.O.Box 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
 McCormick RoadCharlottesville, VA 22903
Office:B011+1-434-982-4729
Lab:B019+1-434-982-4751
Fax:+1-434-982-4766
WWW:http://www.people.virginia.edu/~mk9y/

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


Re: [R] Clash between alr3 and AlgDesign. (Was: Re: Second subsequent calls to function fails. Please help debug.)

2008-03-30 Thread Duncan Murdoch
On 30/03/2008 11:31 AM, Gabor Grothendieck wrote:
 On Sun, Mar 30, 2008 at 9:43 AM, Duncan Murdoch [EMAIL PROTECTED] wrote:
 In my opinion, all packages should have namespaces, and I'd like to
 create a default one if the author doesn't.  (The default would be:
 import what is listed in the Depends clause, export everything.)  I
 don't think this will happen for 2.7.0, though package.skeleton might
 start creating one.
 
 Namespaces are such a pain when you don't really need them though.

I would say there is no such case.  Packages all import functions. 
Having the imports change because of unrelated code means that there is 
no way to write reliable code.

 Its nice just to be able to source a new version of a function and have
 it immediately work with the package.  Particularly for packages that
 are changing or for which there is substantial code changes in the
 devel version this is very convenient and namespaces interefere with that.

That sounds like a problem with the way we handle package code, making 
it too hard to reload a package that has had small changes made.  We 
should make it easy to make a small change to a package and reload the 
modified version.

 Although its possible to have namespace problems as discussed in this
 thread I have found that it rarely actually happens and certainly not enough
 to impose it.

I suspect it happens more than people realize, and that in some cases 
they just get the wrong answers, without any helpful error message to 
let them know about it.

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] Clash between alr3 and AlgDesign. (Was: Re: Second subsequent calls to function fails. Please help debug.)

2008-03-30 Thread Duncan Murdoch
On 30/03/2008 10:06 AM, Michael Kubovy wrote:
 I've been trying to dynamically detach and attach things in my Sweave,  
 in order to circumvent the problem.
 
 Here is my first attempt:
 pkg - 'package:AlgDesign'
 p - is.na(match(pkg, search()))
 ifelse(p  == FALSE, detach(pkg), NA)

You can't use detach this way.  It is fine to say 
detach(package:AlgDesign) or detach(AlgDesign), but the way detach is 
written, you're attempting to detach something named pkg.

This rewrite of your code is untested, but I think it should work:

pkg - 'package:AlgDesign'
p - match(pkg, search())
if (!is.na(p)) detach(pos=p)
require(alr3)

I've also changed your ifelse() to if (), and not just because I don't 
need an else clause:  ifelse() is designed to do computations on 
vectors, if() is designed for flow control.  I think we want flow 
control here.

Duncan Murdoch

 require(alr3)
 
 My first two runs show that I've done something wrong:
 
   Sweave('20080331.Rnw')
 Writing to file 20080331.tex
 Processing code chunks ...
   1 : term hide (label=setup)
   2 : echo term verbatim (label=oatvar)
   3 : echo term verbatim (label=oatvar1)
   4 : echo term verbatim (label=oat2wt)
   5 : echo term verbatim (label=oat2wt)
   6 : echo term verbatim (label=lm)
   7 : echo term verbatim (label=diag)
   8 : echo term verbatim (label=tukey)
   9 : echo term verbatim (label=nonad)
 10 : echo term verbatim (label=efficiency)
 11 : echo term verbatim (label=wear)
 12 : echo term verbatim (label=wearX)
 13 : echo term verbatim (label=gyd)
 Loading required package: crossdes
 Loading required package: AlgDesign
 14 : echo term verbatim (label=2wt)
 15 : echo term verbatim (label=ablm)
 16 : echo term verbatim (label=abaov)
 17 : echo term verbatim (label=abTukey)
 18 : echo term verbatim (label=effAb)
 19 : echo term verbatim (label=rabbit)
 20 : echo term verbatim (label=rabbit2)
 21 : echo term verbatim (label=rabbit2wt)
 
 You can now run LaTeX on '20080331.tex'
 There were 42 warnings (use warnings() to see them)
   Sweave('20080331.Rnw')
 Writing to file 20080331.tex
 Processing code chunks ...
   1 : term hide (label=setup)
   2 : echo term verbatim (label=oatvar)
   3 : echo term verbatim (label=oatvar1)
   4 : echo term verbatim (label=oat2wt)
   5 : echo term verbatim (label=oat2wt)
   6 : echo term verbatim (label=lm)
   7 : echo term verbatim (label=diag)
   8 : echo term verbatim (label=tukey)
 
 Error:  chunk 8 (label=tukey)
 Error in detach(pkg) : invalid name
   pkg
 [1] package:AlgDesign
 
 (1) I should learn how to fix the above code.
 
 (2) In general, in preparing scripts, perhaps one should just ditch  
 all the loaded packages at the beginning of each run, so as to insure  
 that users won't get bitten by packages I had loaded but didn't do so  
 explicitly in the Sweave script, *and* it would solve the current  
 problem as well. Is there a straightforward way to do that?
 


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


Re: [R] Problem: using cor.test with by( )

2008-03-30 Thread Peter Dalgaard
Che-hsu (Joe) Chang wrote:
 Hello everyone, 

  

 I'm a new R user switching from SAS and JMP. In the first few days, I have
 been trying to do a fairly simple task but yet found no success. I've
 checked the help archive as well as few R textbooks but didn't seem to find
 the answer. So, please help me if you can.

  

 Basically, I want to calculate the correlation between variable A and B for
 every subject in my study. (yep, that simple)

 What I did is this:

  

 by(data, id, function (x) cor.test(A,B, data=x))

  

 The results gave me numbers of correlation for each subject. But, the
 problem is that, all these correlations are the same numbers and the sample
 size was always the entire database (including all subjects). I've also
 tried the lm function instead of the cor.test, and the by() function works
 fine. Can any of you tell me what I did wrong? Or could you tell me what is
 the best way to apply a function by subjects? Thank you!

  

   
Only the model formula interface to cor.test uses the data argument, so 
you need either

cor.test(x$A,x$B)

or

cor.test(~A+B, data=x)

  

 Best,

 Che-hsu (Joe) Chang, Sc.D., P.T.

  


   


-- 
   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] tests Rin Rout

2008-03-30 Thread Duncan Murdoch
On 30/03/2008 10:44 AM, Christophe Genolini wrote:
 Hi the list,
 
 Some rumour (!) say that is it possible to prepare some tests for 
 checking our code using .Rin and .Rout. It seems to be a very good 
 practice, but I did not manage to find information on it.
 So does someone know how it works ? What are we suppose to write in Rin ?

See the paragraph in Writing R Extensions which explains this, near the 
end of the section on Package Subdirectories (section 1.1.3 in the 
version I'm looking at).

Rin would be fairly rarely needed:  it is supposed to write a script to 
perform the tests.  Normally you write your script directly, in a .R file.

 
 More precisely :
  - I have a package myPack.r in directories ~/myR/myPack/R/
  - I create the directory ~/myR/myPack/tests
 
 myPack.r is :
 
 `f1` - function(x){cat(\nXXX F1 = ,x,XXX\n)}
 `f2` - function(x){cat(\nXXX F2 = ,f1(x^2),XXX\n)}
 
 What am I suppose to do to test it? Create myPack.Rin, but what in it?

Create tests/myPack.R with those lines in it plus lines to actually run 
the code.  If the code generates errors, your test will fail.  If you 
want to see reports of changes to the output, also include 
tests/myPack.Rout.save with the known correct versions of the output.

Duncan Murdoch

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

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


Re: [R] Generating maps in R

2008-03-30 Thread Roger Bivand
Aleksandr Andreev aleksandr.andreev at duke.edu writes:

 
 Greetings!
 
 I am trying plot some data on a map in R. Here's the scenario.
 
 I have a variable called probworkinghealthy which contains a predicted
 probability of employment for every individual in my sample (about
 100,000 observations).
 I have another variable, called a001ter, which contains the subject of
 residency in the Russian Federation (akin to a US state) for every
 individual in the sample.
 I have a shape file with the boundaries of all the subjects, called 
 russia.shp.
 
 I can plot boxplots of the probability by Federal Subject using
 plot(probworkinghealthy ~ a001ter). I can also plot the map using
 plot(russia.shp)

So what you need to do is to aggregate the input data frame for 
individuals, and assign the summary value, here mean, to the correct 
shapefile geometries. Probably most of what you need is in the maptools 
package. There is a question about the IDs used to identify the Federal 
Subject geometries in the shapefile. Assuming that they are named as in
the individual data frame, something like:

FS - readShapePoly(russia.shp, IDvar=a001ter)

will associate the geometries in the SpatialPolygonsDataFrame with the 
correct ID - change the IDvar argument value to suit the shapefile. If 
you do not have IDs in the shapefile to match the unique values of
a001ter, you will need to create them.

From there, create a new data frame with row names matching the unique IDs:

agg1 - tapply(probworkinghealthy, a001ter, mean)
agg2 - data.frame(mean_probworkinghealthy=agg1, row.names=names(agg1))

and check row.names(agg2) and 
sapply(slot(FS, polygons), function(x) slot(x, ID))

for obvious blunders. Merge using:

FS1 - spCbind(FS, agg2)

(usually takes a number of tries to get the matching correct). The 
reason for the complications with IDs is that it is easy to merge data
with geometries in the wrong order, and having to provide positive 
matching should help prevent this.


 
 Now, I would like to plot the mean probability of employment (i.e.
 mean(probworkinghealthy)) on a map of Russia using color coding all
 the Federal Subjects. Does anyone know how to do something like that?

Then 

spplot(FS1, mean_probworkinghealthy)

gives a map with default class intervals and colour palette.

I suggest that you also consider assigning a coordinate reference 
system to the geometries as Russia has a large extent, and the 
correct interpretation of the geometry coordinates may matter. 

Roger

PS. You could consider following up on the R-sig-geo list, or exploring 
information in the Spatial Task View, or in the list archives.

 
 Much appreciated,
 
 Aleks Andreev
 Duke 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] Definition of wrapper?

2008-03-30 Thread Bryan Hanson
I think I more or less understand what a ³wrapper² is, but I¹d like to hear
how more experienced R users define it, and especially I'd like to know if
there is a formal definition.  In my reading, it seems like there are a
fairly wide range of meanings, but they are all conceptually similar.

I've looked in a couple of the classic R texts, the extensions and
developers' manuals, and R help archives, and didn't find a definition.  Of
course, I may have missed it.

Thanks in advance.  Bryan

**
Bryan Hanson
Professor of Chemistry  Biochemistry
DePauw University
602 S. College Avenue
Greencastle, IN 46135
PHONE 765-658-4602
FAX 765-658-6084
[EMAIL PROTECTED]
http://academic.depauw.edu/~hanson/deadpezsociety.html
http://www.depauw.edu/acad/chemistry/
http://academic.depauw.edu/~hanson/UMP/index.html

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


Re: [R] tests Rin Rout

2008-03-30 Thread Christophe Genolini


 See the paragraph in Writing R Extensions which explains this
Well, I saw it again and again (before asking on the r-help) but I do 
not understand. Same for the Kurt Hornik slides on the web.


 Create tests/myPack.R with those lines in it plus lines to actually 
 run the code.
Does it mean that each time I change the code, I will have to change it 
twice, once in R/ and once in tests/
   If the code generates errors, your test will fail.  If you want to 
 see reports of changes to the output, also include 
 tests/myPack.Rout.save with the known correct versions of the output.

What should the Rout.save looks like ? I mean, what is the syntax of 
this file ?

Christophe

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


Re: [R] Definition of wrapper?

2008-03-30 Thread Charilaos Skiadas
On Mar 30, 2008, at 2:51 PM, Bryan Hanson wrote:

 I think I more or less understand what a “wrapper” is, but I’d like  
 to hear
 how more experienced R users define it, and especially I'd like to  
 know if
 there is a formal definition.  In my reading, it seems like there  
 are a
 fairly wide range of meanings, but they are all conceptually similar.

 I've looked in a couple of the classic R texts, the extensions and
 developers' manuals, and R help archives, and didn't find a  
 definition.  Of
 course, I may have missed it.

 Thanks in advance.  Bryan

This is a general programming question, likely. This might offer a  
starting point:
http://en.wikipedia.org/wiki/Wrapper_pattern

Greetings from Hanover, IN

 **
 Bryan Hanson
 Professor of Chemistry  Biochemistry
 DePauw University

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

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

2008-03-30 Thread SS-R

hello,
I have two 2-d normal multivariate distributions mapped out on a scatter
plot. I now need a line that equates the two discriminant functions, ie.
g1(x) = g2(x). This should be a quadratic. 
How can I solve this in R?
Thanks
-- 
View this message in context: 
http://www.nabble.com/Describing-discriminant-function-tp16385838p16385838.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] Definition of wrapper?

2008-03-30 Thread Gabor Grothendieck
The wrapper wraps, i.e. calls, another function that does the real
work but provides a different or more convenient (or more convenient
for a specific purpose) interface to it or specific syntax.  Often the wrapper
has the same arguments but different defaults and sometimes that
is referred to as a convenience wrapper.  Sometimes its used in
the sense of providing an R interface to a C function with essentially
similar arguments.

by is a wrapper to tapply which preprocesses the data in a way
that makes it acceptable to tapply, read.csv and Map are wrappers
to read.table and mapply which are the same but have different argument
defaults, sprintf is a wrapper to the C function of the same name,
%o% is a wrapper to outer.

I don't think there is a formalized definition within R -- the above is
based on current usage.

On Sun, Mar 30, 2008 at 2:51 PM, Bryan Hanson [EMAIL PROTECTED] wrote:
 I think I more or less understand what a ³wrapper² is, but I¹d like to hear
 how more experienced R users define it, and especially I'd like to know if
 there is a formal definition.  In my reading, it seems like there are a
 fairly wide range of meanings, but they are all conceptually similar.

 I've looked in a couple of the classic R texts, the extensions and
 developers' manuals, and R help archives, and didn't find a definition.  Of
 course, I may have missed it.

 Thanks in advance.  Bryan

 **
 Bryan Hanson
 Professor of Chemistry  Biochemistry
 DePauw University
 602 S. College Avenue
 Greencastle, IN 46135
 PHONE 765-658-4602
 FAX 765-658-6084
 [EMAIL PROTECTED]
 http://academic.depauw.edu/~hanson/deadpezsociety.html
 http://www.depauw.edu/acad/chemistry/
 http://academic.depauw.edu/~hanson/UMP/index.html

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

2008-03-30 Thread Duncan Murdoch
For questions like this about package development, you should ask on 
R-devel, but I'll continue the thread here for one more message.

On 30/03/2008 2:54 PM, Christophe Genolini wrote:
 See the paragraph in Writing R Extensions which explains this
 Well, I saw it again and again (before asking on the r-help) but I do 
 not understand. Same for the Kurt Hornik slides on the web.

Generally I find it's good to look at examples that work.  For examples 
of packages using tests, look at source packages on CRAN.  Run the tests 
on them (using R CMD check), and see what gets produced.

 Create tests/myPack.R with those lines in it plus lines to actually 
 run the code.
 Does it mean that each time I change the code, I will have to change it 
 twice, once in R/ and once in tests/

There shouldn't be any duplication.  Just put tests in the tests 
directory.  That code will be run with your package loaded when you run 
R CMD check.  If it fails, your package will fail the check.

   If the code generates errors, your test will fail.  If you want to 
 see reports of changes to the output, also include 
 tests/myPack.Rout.save with the known correct versions of the output.

 What should the Rout.save looks like ? I mean, what is the syntax of 
 this file ?

It should just be a copy of the Rout file produced from a previous 
trusted run.  R CMD check will ignore certain differences (like changes 
to the date or R version at the top of the file), but will report on others.

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] Plot for jump point

2008-03-30 Thread kate
Hi,

 My code is as the following,
ratio-seq(0,1,by=0.01)
payoff-NULL
for (i in 1:length(ratio) )
{
payoff1-100*(ratio[i]=0.7)+max(100*(1+(ratio[i]-1)*2),0)*(ratio[i]0.7)
payoff-c(payoff,payoff1)
}
plot(ratio,payoff, xlab='ST/S0', ylab='Payoff',type='l')

I have the discontinuous point at ratio=0.7. I do not want to have the line at 
0.7, and would like a solid dot at payoff=100 and a hollow dot at payoff=40 at 
the jump point 0.7. How would I do this?

Thanks,   

Kate 
[[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] Problem: using cor.test with by( )

2008-03-30 Thread Liviu Andronic
On Sun, Mar 30, 2008 at 7:11 PM, Che-hsu (Joe) Chang [EMAIL PROTECTED] wrote:
  Basically, I want to calculate the correlation between variable A and B for
  every subject in my study. (yep, that simple)

  What I did is this:
  by(data, id, function (x) cor.test(A,B, data=x))

This recent thread [1] might prove of interest.
Liviu

[1] http://www.nabble.com/p-value-in-Spearman-rank-order-tt15738907.html

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

2008-03-30 Thread mohammed alawa
Dear , Madam/Sir
   
  I'm student doing master in statistics, I'd like to know how i can set data 
in R and apply meta-analysis. i have tries many ways but I'm really stuck.
  i really appreciate if you can help me in this matter.
   
  Mohammed Owlowa



   
-

[[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] maximum of identical elements in a vector

2008-03-30 Thread Daniel Malter
Hi,

the problem I have is seemingly very simple, but not simple enough for me to
figure out. I just want to find the most (or least) frequent element in the
vector.

a=c(Alice,Alice,Alice,Alice,Bob,Bob)
unique(a)
length(which(a==Alice))


unique(a) shows me that the elements in my vector are Alice and Bob. The
latter expression gives 4 as the frequency of Alice in vector a.  
To find the maximum frequency of the unique elements, however, it assumes
that I know that Alice is the most (or least) frequent element. Therefore,
how can find that Alice is the most frequent element in this vector? I
assume there is an easier way than computationally intensive loops (for long
vectors).

Cheers,
Daniel

-
cuncta stricte discussurus

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


Re: [R] Plot for jump point

2008-03-30 Thread jim holtman
Try this:

ratio-seq(0,1,by=0.01)
payoff-NULL
for (i in 1:length(ratio) )
{
payoff1-100*(ratio[i]=0.7)+max(100*(1+(ratio[i]-1)*2),0)*(ratio[i]0.7)
payoff-c(payoff,payoff1)
}
payoff[70] - NA  # force no line
plot(ratio,payoff, xlab='ST/S0', ylab='Payoff',type='l')
points(c(ratio[69], ratio[71]), c(payoff[69], payoff[71]), pch=c(1,16))




On Sun, Mar 30, 2008 at 4:17 PM, kate [EMAIL PROTECTED] wrote:
 Hi,

  My code is as the following,
 ratio-seq(0,1,by=0.01)
 payoff-NULL
 for (i in 1:length(ratio) )
 {
 payoff1-100*(ratio[i]=0.7)+max(100*(1+(ratio[i]-1)*2),0)*(ratio[i]0.7)
 payoff-c(payoff,payoff1)
 }
 plot(ratio,payoff, xlab='ST/S0', ylab='Payoff',type='l')

 I have the discontinuous point at ratio=0.7. I do not want to have the line 
 at 0.7, and would like a solid dot at payoff=100 and a hollow dot at 
 payoff=40 at the jump point 0.7. How would I do this?

 Thanks,

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




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

What is the problem 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] maximum of identical elements in a vector

2008-03-30 Thread Chuck Cleland
On 3/30/2008 5:35 PM, Daniel Malter wrote:
 Hi,
 
 the problem I have is seemingly very simple, but not simple enough for me to
 figure out. I just want to find the most (or least) frequent element in the
 vector.
 
 a=c(Alice,Alice,Alice,Alice,Bob,Bob)
 unique(a)
 length(which(a==Alice))
 
 
 unique(a) shows me that the elements in my vector are Alice and Bob. The
 latter expression gives 4 as the frequency of Alice in vector a.  
 To find the maximum frequency of the unique elements, however, it assumes
 that I know that Alice is the most (or least) frequent element. Therefore,
 how can find that Alice is the most frequent element in this vector? I
 assume there is an easier way than computationally intensive loops (for long
 vectors).

  names(which.max(table(a)))
[1] Alice

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

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

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


Re: [R] maximum of identical elements in a vector

2008-03-30 Thread Gavin Simpson
On Sun, 2008-03-30 at 17:35 -0400, Daniel Malter wrote:
 Hi,
 
 the problem I have is seemingly very simple, but not simple enough for me to
 figure out. I just want to find the most (or least) frequent element in the
 vector.
 
 a=c(Alice,Alice,Alice,Alice,Bob,Bob)
 unique(a)
 length(which(a==Alice))

 a - c(Alice,Alice,Alice,Alice,Bob,Bob)
 tab - table(a)
 tab
a
Alice   Bob 
4 2 
 which.max(tab)
Alice 
1 
 tab[which.max(tab)]
Alice 
4 

HTH

G

 
 
 unique(a) shows me that the elements in my vector are Alice and Bob. The
 latter expression gives 4 as the frequency of Alice in vector a.  
 To find the maximum frequency of the unique elements, however, it assumes
 that I know that Alice is the most (or least) frequent element. Therefore,
 how can find that Alice is the most frequent element in this vector? I
 assume there is an easier way than computationally intensive loops (for long
 vectors).
 
 Cheers,
 Daniel
 
 -
 cuncta stricte discussurus
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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


Re: [R] problem with white space

2008-03-30 Thread jim holtman
Here is one way of doing it.  I would suggest that you read in the
data with readLines and then combine into one single string so that
you can use substring on it.  Since you did not provide  provide
commented, minimal, self-contained, reproducible code, I will take a
guess at that your data looks like:

# create some test data -- might be read in the readLines
sdata - sapply(1:10, function(x){  # 10 lines of strings with 50 characters
paste(sample(LETTERS, 50, TRUE), collapse='')
})
# put into one large string so you can do substring on it
sdata - paste(sdata, collapse='')
# now create 10 sample of size 20 and write in files (file1, file2, ... file10)
for (i in 1:10){
x - sample(nchar(sdata), 20)
writeLines(paste(substring(sdata, x, x), collapse=''),
con=paste(file, i, sep=''))
}





On Sun, Mar 30, 2008 at 3:41 PM, Suraaga Kulkarni
[EMAIL PROTECTED] wrote:
 Hi,

 I need to resample characters from a dataset that consists of an extremely
 long string that is written over hundreds of thousands of lines, each of
 length 50 characters.  I am currently doing this by first inserting a space
 after each character in the dataset and then using the following commands:

 y - as.matrix(read.table(data.txt), stringsAsFactors=FALSE)
 bstrap - sample(length(y), 10, TRUE)
 write(y[bstrap], file=Rep1.txt, ncolumns=50, append=FALSE)
 bstrap - sample(length(y), 10, TRUE)
 write(y[bstrap], file=Rep2.txt, ncolumns=50, append=FALSE)
 bstrap - sample(length(y), 10, TRUE)
 .
 .
 .
 and so on for 500 reps.


 I think there should be a better way of doing this.  My specific questions:

 1. Is there a way to avoid inserting spaces between the characters before
 calling the sample command (because I don't want spaces between the
 resampled characters in the output either; see number 2 below)?

 2. If I have no choice but to insert the spaces in my data before
 resampling, is there a way to output the resampled data without spaces, but
 simply as 50-character long strings one below the other)?  I tried inserting
 the following command: strip.white=TRUE in the write command line, but it
 gave me an error as it did not understand the command.

 3. Finally, since I have to get 500 such resampled reps from each dataset
 (and there are over 20 such huge datasets) is there a way around having to
 write a separate write command for each rep?

 Any suggestions will be greatly appreciated.

 Thanks,

 S.

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




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

What is the problem 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] problem with white space

2008-03-30 Thread jim holtman
How long is it taking?  Can you send me the code that you are using.

Another technique is to recode you characters into numbers and store
them as integers.  You can then sample the values and reconstruct the
output.  Here is a faster way:

# create some test data -- might be read in the readLines
# use 'raw' class for the data.
sdata - sapply(1:10, function(x){
charToRaw(paste(sample(LETTERS, 50, TRUE), collapse=))#
encode the character as a number
})
# now create 10 sample of size 20 and write in files
for (i in 1:10){
x - sample(sdata, 10, TRUE)
# convert back to characters
writeLines(rawToChar(x), con=paste(file, i, sep=''))
}






On Sun, Mar 30, 2008 at 6:06 PM, Suraaga Kulkarni
[EMAIL PROTECTED] wrote:
 Jim,

 Thanks very much.  I am very new to R and am trying to understand your code.
 It works perfectly on your sample data of course.  I tried your code on my
 data.  While it works, it takes too much time to generate each replicate.
 At present I'm outputting the replicates with only 2000 resampled
 characters.  I actually need to resample something like 1-5 million
 characters.  I work with the human genome, and need to generate 500
 bootstrap replicates of a scaled down version (about 2%) of each chromosome
 by means of resampling with replacement.

 Sorry about the cryptic code but I thought my initial description of the
 problem explained it.  In any case, your guess was correct.

 Let me see if I can rework your code to suit my purposes.  In the meanwhile,
 if you have any other suggestions, I'll be happy to hear them.

 Thanks again for the prompt response.

 S.



 On Sun, Mar 30, 2008 at 6:15 PM, jim holtman [EMAIL PROTECTED] wrote:
  Here is one way of doing it.  I would suggest that you read in the
  data with readLines and then combine into one single string so that
  you can use substring on it.  Since you did not provide  provide
  commented, minimal, self-contained, reproducible code, I will take a
  guess at that your data looks like:
 
  # create some test data -- might be read in the readLines
  sdata - sapply(1:10, function(x){  # 10 lines of strings with 50
 characters
 paste(sample(LETTERS, 50, TRUE), collapse='')
  })
  # put into one large string so you can do substring on it
  sdata - paste(sdata, collapse='')
  # now create 10 sample of size 20 and write in files (file1, file2, ...
 file10)
  for (i in 1:10){
 x - sample(nchar(sdata), 20)
 writeLines(paste(substring(sdata, x, x), collapse=''),
  con=paste(file, i, sep=''))
 
 
 
  }
 
 
 
 
 
  On Sun, Mar 30, 2008 at 3:41 PM, Suraaga Kulkarni
  [EMAIL PROTECTED] wrote:
   Hi,
  
   I need to resample characters from a dataset that consists of an
 extremely
   long string that is written over hundreds of thousands of lines, each of
   length 50 characters.  I am currently doing this by first inserting a
 space
   after each character in the dataset and then using the following
 commands:
  
   y - as.matrix(read.table(data.txt), stringsAsFactors=FALSE)
   bstrap - sample(length(y), 10, TRUE)
   write(y[bstrap], file=Rep1.txt, ncolumns=50, append=FALSE)
   bstrap - sample(length(y), 10, TRUE)
   write(y[bstrap], file=Rep2.txt, ncolumns=50, append=FALSE)
   bstrap - sample(length(y), 10, TRUE)
   .
   .
   .
   and so on for 500 reps.
  
  
   I think there should be a better way of doing this.  My specific
 questions:
  
   1. Is there a way to avoid inserting spaces between the characters
 before
   calling the sample command (because I don't want spaces between the
   resampled characters in the output either; see number 2 below)?
  
   2. If I have no choice but to insert the spaces in my data before
   resampling, is there a way to output the resampled data without spaces,
 but
   simply as 50-character long strings one below the other)?  I tried
 inserting
   the following command: strip.white=TRUE in the write command line, but
 it
   gave me an error as it did not understand the command.
  
   3. Finally, since I have to get 500 such resampled reps from each
 dataset
   (and there are over 20 such huge datasets) is there a way around having
 to
   write a separate write command for each rep?
  
   Any suggestions will be greatly appreciated.
  
   Thanks,
  
   S.
  
  [[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.
  
 
 
 
  --
  Jim Holtman
  Cincinnati, OH
  +1 513 646 9390
 
  What is the problem you are trying to solve?
 





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

What is the problem 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 

Re: [R] Generating maps in R

2008-03-30 Thread Aleksandr Andreev
Roger Bivand Roger.Bivand at nhh.no writes:

 Merge using:
 FS1 - spCbind(FS, agg2)

This call fails, because:
Error in spCbind(FS, agg2) : different numbers of rows

The reason is because I have data in a001ter for 79 Federal Subjects,
but russia.shp contains 193 labeled objects (93 Federal Subjects plus
100 Arctic Ocean Islands and other things). Is there a way I can merge
without an equal number of rows, labeling the data for the Arctic
islands as missing?

Thanks,

Aleks Andreev
Duke University

2008/3/29, Aleksandr Andreev [EMAIL PROTECTED]:
 Greetings!

  I am trying plot some data on a map in R. Here's the scenario.

  I have a variable called probworkinghealthy which contains a predicted
  probability of employment for every individual in my sample (about
  100,000 observations).
  I have another variable, called a001ter, which contains the subject of
  residency in the Russian Federation (akin to a US state) for every
  individual in the sample.
  I have a shape file with the boundaries of all the subjects, called 
 russia.shp.

  I can plot boxplots of the probability by Federal Subject using
  plot(probworkinghealthy ~ a001ter). I can also plot the map using
  plot(russia.shp)

  Now, I would like to plot the mean probability of employment (i.e.
  mean(probworkinghealthy)) on a map of Russia using color coding all
  the Federal Subjects. Does anyone know how to do something like that?

  Much appreciated,

  Aleks Andreev
  Duke 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.


Re: [R] maximum of identical elements in a vector

2008-03-30 Thread Daniel Malter
 
Thanks to all who responded so quickly.

-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: Chuck Cleland [mailto:[EMAIL PROTECTED] 
Gesendet: Sunday, March 30, 2008 5:45 PM
An: Daniel Malter
Cc: [EMAIL PROTECTED]
Betreff: Re: [R] maximum of identical elements in a vector

On 3/30/2008 5:35 PM, Daniel Malter wrote:
 Hi,
 
 the problem I have is seemingly very simple, but not simple enough for 
 me to figure out. I just want to find the most (or least) frequent 
 element in the vector.
 
 a=c(Alice,Alice,Alice,Alice,Bob,Bob)
 unique(a)
 length(which(a==Alice))
 
 
 unique(a) shows me that the elements in my vector are Alice and 
 Bob. The latter expression gives 4 as the frequency of Alice in vector
a.
 To find the maximum frequency of the unique elements, however, it 
 assumes that I know that Alice is the most (or least) frequent 
 element. Therefore, how can find that Alice is the most frequent 
 element in this vector? I assume there is an easier way than 
 computationally intensive loops (for long vectors).

  names(which.max(table(a)))
[1] Alice

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

--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Finding a mean value of a variable holding a dummy variable fixed

2008-03-30 Thread Alexander Ovodenko
I have time-series data on approval ratings of British Prime Ministers.  The
prime ministers dating from MacMillan onward till today are coded as dummy
variables and the approval ratings are entered for each month.  I want to
know the mean value of the approval rating of each Prime Minister in the
dataset and the approval rating during his/her first month and last month as
PM.  What R code should I enter for these data?  In other words, I want hold
the dummy corresponding to each Prime Minister fixed at value one and know
the first rating that PM has, the last rating s/he has, and the mean rating
s/he has.  Thanks.

[[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] Finding a mean value of a variable holding a dummy variablefixed

2008-03-30 Thread Daniel Malter
The mean problem can be solved with

president=c(Johnson,Johnson,Johnson,Johnson,Johnson,Johnson,Nix
on,Nixon,Nixon,Nixon,Nixon,Nixon)
approval=seq(1:12)
tapply(approval,president,mean)

For the other, I will try to come back. But I am sure somebody will be
faster than I.

Cheers,
Daniel 


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
Auftrag von Alexander Ovodenko
Gesendet: Sunday, March 30, 2008 9:47 PM
An: r-help@r-project.org
Betreff: [R] Finding a mean value of a variable holding a dummy
variablefixed

I have time-series data on approval ratings of British Prime Ministers.  The
prime ministers dating from MacMillan onward till today are coded as dummy
variables and the approval ratings are entered for each month.  I want to
know the mean value of the approval rating of each Prime Minister in the
dataset and the approval rating during his/her first month and last month as
PM.  What R code should I enter for these data?  In other words, I want hold
the dummy corresponding to each Prime Minister fixed at value one and know
the first rating that PM has, the last rating s/he has, and the mean rating
s/he has.  Thanks.

[[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] Finding a mean value of a variable holding a dummy variablefixed

2008-03-30 Thread Daniel Malter
I found a solution. It's probably not the easiest one, but it works.  It
assumes that your data frame is ordered from earliest to latest record for
each president, but it can be easily adjusted if you want to make it
dependent on a third column. The final vector index gives you the line
indices for the first record for each president. If you replace min by
max you get the last instead of the first record. You can then find the
values by


##Sample data

president=c(Johnson,Johnson,Johnson,Johnson,Johnson,Johnson,Nix
on,Nixon,Nixon,Nixon,Nixon,Nixon)
approval=c(3,4,5,6,7,8,6,5,4,3,2,1)
tapply(approval,president,mean)

##Find index for first row of each president; assumes ascending order of
observations; change min to max to find last record

index=NULL
for(i in 1:length(unique(president)))
  index[i]=min(which((president==unique(president)[i])==TRUE))

index

##Generate table with first approvals

first.approval=data.frame(cbind(index,president[index],approval[index]))
names(first.approval)=c(Index,President,Approval)
first.approval

Cheers,
Daniel




-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
Auftrag von Alexander Ovodenko
Gesendet: Sunday, March 30, 2008 9:47 PM
An: r-help@r-project.org
Betreff: [R] Finding a mean value of a variable holding a dummy
variablefixed

I have time-series data on approval ratings of British Prime Ministers.  The
prime ministers dating from MacMillan onward till today are coded as dummy
variables and the approval ratings are entered for each month.  I want to
know the mean value of the approval rating of each Prime Minister in the
dataset and the approval rating during his/her first month and last month as
PM.  What R code should I enter for these data?  In other words, I want hold
the dummy corresponding to each Prime Minister fixed at value one and know
the first rating that PM has, the last rating s/he has, and the mean rating
s/he has.  Thanks.

[[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] Finding a mean value of a variable holding a dummyvariablefixed

2008-03-30 Thread Bill.Venables
Here is another way, starting with similar dummy data:



PMData - 
data.frame(PM = c(Thatcher, Thatcher, Thatcher, Thatcher,
   Thatcher, Thatcher,Major, Major, Major,
   Major, Major, Major),
approval = c(3, 4, 5, 6, 7, 8, 6, 5, 4, 3, 2, 1))
 
PMData - transform(PMData, Month = 1:nrow(PMData))  ## add the time variable

PM_average - with(PMData, tapply(approval, PM, mean))

PM_span - with(PMData, sapply(tapply(Month, PM, range),
  function(x) structure(approval[Month[x]],
names = c(First, Last


 rbind(mean = PM_average, PM_span)
  Major Thatcher
mean3.5  5.5
First   6.0  3.0
Last1.0  8.0 


(I don't recall any Prime Minister called Johnson or Nixon, by the way...)

Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile: +61 4 8819 4402
Home Phone: +61 7 3286 7700
mailto:[EMAIL PROTECTED]
http://www.cmis.csiro.au/bill.venables/ 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Daniel Malter
Sent: Monday, 31 March 2008 1:22 PM
To: 'Alexander Ovodenko'; r-help@r-project.org
Subject: Re: [R] Finding a mean value of a variable holding a dummyvariablefixed

I found a solution. It's probably not the easiest one, but it works.  It
assumes that your data frame is ordered from earliest to latest record for
each president, but it can be easily adjusted if you want to make it
dependent on a third column. The final vector index gives you the line
indices for the first record for each president. If you replace min by
max you get the last instead of the first record. You can then find the
values by


##Sample data

president=c(Johnson,Johnson,Johnson,Johnson,Johnson,Johnson,Nix
on,Nixon,Nixon,Nixon,Nixon,Nixon)
approval=c(3,4,5,6,7,8,6,5,4,3,2,1)
tapply(approval,president,mean)

##Find index for first row of each president; assumes ascending order of
observations; change min to max to find last record

index=NULL
for(i in 1:length(unique(president)))
  index[i]=min(which((president==unique(president)[i])==TRUE))

index

##Generate table with first approvals

first.approval=data.frame(cbind(index,president[index],approval[index]))
names(first.approval)=c(Index,President,Approval)
first.approval

Cheers,
Daniel




-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
Auftrag von Alexander Ovodenko
Gesendet: Sunday, March 30, 2008 9:47 PM
An: r-help@r-project.org
Betreff: [R] Finding a mean value of a variable holding a dummy
variablefixed

I have time-series data on approval ratings of British Prime Ministers.  The
prime ministers dating from MacMillan onward till today are coded as dummy
variables and the approval ratings are entered for each month.  I want to
know the mean value of the approval rating of each Prime Minister in the
dataset and the approval rating during his/her first month and last month as
PM.  What R code should I enter for these data?  In other words, I want hold
the dummy corresponding to each Prime Minister fixed at value one and know
the first rating that PM has, the last rating s/he has, and the mean rating
s/he has.  Thanks.

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


[R] Find the index for min of a matrix

2008-03-30 Thread kate
Hi,

My example is as the following, 

W-matrix(c(2,4,2,8,1,3),ncol=3)
which(W==min(W))

I would like to find the index for min of the matrix W, i.e. (1, 3) instead of 
5 as the output. What command could I use?

Thanks,

Kate 
[[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] APPLY as alternate to FOR loop?

2008-03-30 Thread zack holden

Dear list, 
Below I've written a clunky for loop that counts NA's in a row, replacing all 
with NA if there are
more than 3 missing values, or keeping the values if 4 or more are present. 
This is sample code from a very large 
dataframe I'm trying to clean up. 
 
I know there are many simpler more elegant solutions to this little problem. 
 
Would someone be willing to show me how to create a function that I can APPLY 
to 
each row rather than looping? I've tried and can't get it.
 
Thank you,
Zack
 
# Count NA's in each row. IF  
3 NA's in a row, make all 
NA### 
##  test dataframe ###x1 - c(1,NA,NA,NA,NA,1,2,2)x2 - 
c(1,NA,NA,NA,NA,1,2,1)x3 - c(1,NA,1,1,1,1,1,5)x4 - c(1,NA,NA,NA,NA,NA,NA,5)x 
- rbind(x1,x2,x3,x4)test - rowSums(is.na(x))   ## count numer of NA's 
in rowx - cbind(x, test) ## add row NA count to datax - 
data.frame(x)  ## make dataframe
 
 
# FOR LOOP to apply across all rows of dataframe -- for(i in 1:nrow(x)) 
{if(x[i,9]  4) {x[i,1:7] - NA} else { x[i,1:7] - x[i,1:7]i = i+1}}
#
[[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] multivariate histogram

2008-03-30 Thread johyhan
Dear Everyone,



1.  I have an n-dimension data.

2.  I could get the shape of pdf of each one from each of their histograms.

3.?Now I would like to get the joint pdf of the all the dimensions of X. 



How do we do #3 above?  



Regards,



Joh

[[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] APPLY as alternate to FOR loop?

2008-03-30 Thread Bill.Venables
As far as I know there is no function called 'APPLY'

There is one called 'apply', but why are you determined to use it here?
It is essentially concealed looping.

Here is an alternative way of solving your problem:
___

x - rbind(x1 = c(1, NA, NA, NA, NA,  1,  2, 2),
   x2 = c(1, NA, NA, NA, NA,  1,  2, 1),
   x3 = c(1, NA,  1,  1,  1,  1,  1, 5),
   x4 = c(1, NA, NA, NA, NA, NA, NA, 5))

badRows - which(rowSums(is.na(x))  3)
is.na(x[as.matrix(expand.grid(badRows, 1:ncol(x)))]) - TRUE
___

 x
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
x1   NA   NA   NA   NA   NA   NA   NA   NA
x2   NA   NA   NA   NA   NA   NA   NA   NA
x31   NA111115
x4   NA   NA   NA   NA   NA   NA   NA   NA



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of zack holden
Sent: Monday, 31 March 2008 2:32 PM
To: r-help@r-project.org
Subject: [R] APPLY as alternate to FOR loop?


Dear list, 
Below I've written a clunky for loop that counts NA's in a row,
replacing all with NA if there are
more than 3 missing values, or keeping the values if 4 or more are
present. This is sample code from a very large 
dataframe I'm trying to clean up. 
 
I know there are many simpler more elegant solutions to this little
problem. 
 
Would someone be willing to show me how to create a function that I can
APPLY to 
each row rather than looping? I've tried and can't get it.
 
Thank you,
Zack
 
# Count NA's in each
row. IF  3 NA's in a row, make all
NA### 
##  test dataframe ###x1 - c(1,NA,NA,NA,NA,1,2,2)x2 -
c(1,NA,NA,NA,NA,1,2,1)x3 - c(1,NA,1,1,1,1,1,5)x4 -
c(1,NA,NA,NA,NA,NA,NA,5)x - rbind(x1,x2,x3,x4)test - rowSums(is.na(x))
## count numer of NA's in rowx - cbind(x, test) ## add
row NA count to datax - data.frame(x)  ## make
dataframe
 
 
# FOR LOOP to apply across all rows of dataframe -- for(i in 1:nrow(x))
{if(x[i,9]  4) {x[i,1:7] - NA} else { x[i,1:7] - x[i,1:7]i = i+1}}
#
[[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] WinXP exhibits sluggish graphics window movement mouse tracking (repainting?) over windows graphics devices

2008-03-30 Thread Richard Yeh
I just noticed when using 2.6.1, 2.6.2 (2008-02-08), 2.6.2pat
(2008-02-21 r44582), and 2.6.2pat (2008-03-24 r44975) on my poor old
Celeron D330 (2.6 GHz; 3.5 years old) running Windows XP, that the
mouse cursor appears to be redrawn more sluggishly when the pointer is
over R windows graphics devices than over the R console window or
other applications' windows. The slowdown seems to start only after I
plotting something in the window (running windows() to open the
device does not cause any slowdown), but the behavior starts after a
plot(rnorm(100)). The slowdown seems to depend on the area of the R
graphics window that is visible. The slowdown also occurs when moving
the plot window.  For example, if the graphics window is frontmost,
and I want to move it until it is mostly offscreen, then the movement
is jerky.  However, once the window is mostly offscreen, dragging it
back onto the screen is smooth and fast.  (When I drag windows, I only
see the frame, not the contents.) This seems to affect SDI and MDI
modes.  The Windows task manager confirms that when the plot window is
frontmost, Rgui.exe takes most of the CPU time.

My graphics card is based on an ATI Radeon 7000, with 32 MB of RAM.

I am surprised that I never noticed this before. Nobody else seems to
have reported it to the r-help list. Is this problem restricted to my
system? (My work machine is much newer, and I do not notice the
problem there.)

-- 
607-351-4838 / [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.