[R] add to vector without duplicatation

2008-08-28 Thread Yuan Jian
Hi,
 
I try to add items to a vector, but when the it has existed, the item should be 
skipped.
does anyone know how to do it a simple way?
 
 
Yu


  
[[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] add to vector without duplicatation

2008-08-28 Thread Nicky Chorley
2008/8/28 Yuan Jian [EMAIL PROTECTED]:
 Hi,

 I try to add items to a vector, but when the it has existed, the item should 
 be skipped.
 does anyone know how to do it a simple way?

You might be able to use unique().

Regards,

Nicky Chorley

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

2008-08-28 Thread Chris Oldmeadow

Hi all,

I have some rough code to sample consecutive integers with length 
according to a vector of lengths


#sample space (representing positions)
pos-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)

#sample lengths
lengths-c(2,3,2)

From these two vectors I need a vector of sampled positions.


the sampling is without replacement, making things tough as the sampled 
integers need to be consecutive. Im hoping somebody knows a faster way 
of doing it than I have. ATM its way to slow on large vectors.



samplePos-function(l){
   start.pos-sample(pos,1)
   end.pos-start.pos+l-1
   posies-start.pos:end.pos
   posies
}

s.start-c()


newPos-function(a){
   rp-samplePos(a)
   #test sampled range is consecutive, if not resample
   if (length(rp) != rp[a]+1 -rp[1]){rp-samplePos(a)}
   pos-setdiff(pos,rp)
   rp[1]
}

newps-c()
newps-unlist(lapply(lengths,newPos))

I think the bottleneck may be on the setdiff() function - the sample 
space is quite large so I dont think there would be too many rejections.




Many thanks,
Chris

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

2008-08-28 Thread Williams, Robin
Hi,
  Is there any quick and easy way to rename a number of objects, without
having to rename each one individually and then remove the old one? And
if so, is there anything I can do to adjust the associated comments
accordingly? 
Thanks for any help,

Robin Williams
Met Office summer intern - Health Forecasting
[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.


Re: [R] Upgrading R means I lose my packages

2008-08-28 Thread ONKELINX, Thierry

On a windows machine you get the same problem. Useless one uses tha same
trick as Rolf suggested: don't install the packages in the default
directory and set R_LIBS to that directory. Then all you need to do
after an upgrade is to set R_LIBS in the new version and run
update.package(checkBuilt = TRUE). Given Rolf's suggestion I suppose
this trick will work on a Mac too.

HTH,

Thierry




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
[EMAIL PROTECTED]
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey



I'm not sure --- I find Mac OS very confusing.  But I have the 
***impression*** that
(on my system) by default packages get installed into

~/Library/R/2.7/library

i.e. into a library inside the directory tree rooted in my login

directory.

I don't use this --- I've created my own library ~/Rlib and have
set up an environment variable to point to it.

(This works properly only if you start R from the command line;
for
reasons I don't understand if you start R by clicking on the
icon
then R doesn't know about the R_LIBS environment variable.  But
since
all civilized people start R from the command line .)

I have no idea why youse guys' systems would eschew using
~/Library/
whatever.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in  this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document

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


Re: [R] Updating a list.

2008-08-28 Thread ONKELINX, Thierry

Kevin,

Notice the subtle difference between Hadley's and your code:

Hadley
m2008$DayOfYear - factor(m2008$DayOfYear, levels = 1:365)

Kevin
m2007$DayOfYear - factor(m2008$DayOfYear, levels = 1:365)

Your are using the m2007 object instead of the suggested m2008 object!

HTH,

Thierry





ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
[EMAIL PROTECTED]
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Namens [EMAIL PROTECTED]
Verzonden: donderdag 28 augustus 2008 3:14
Aan: r-help@r-project.org
Onderwerp: Re: [R] Updating a list.

Since this didn't work:

 m2007$DayOfYear - factor(m2008$DayOfYear, levels = 1:365)
Error in `$-.data.frame`(`*tmp*`, DayOfYear, value = c(1L, 1L, 1L,  :

  replacement has 432267 rows, data has 1592009

Perhaps I need to clarify how the m2007 object was generated.

t2007 - read.csv(Total2007.dat, header = TRUE)
m2007 - melt(t2007,
id.var=c(DayOfYear,Category,SubCategory,Sku),
measure.var=c(Quantity))

Kevin


 hadley wickham [EMAIL PROTECTED] wrote:

 Try this:

 m2008$DayOfYear - factor(m2008$DayOfYear, levels = 1:365)
 r2007 - cast(m2008, DayOfYear ~ variable | Sku, sum, fill = 0)

 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.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in  this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document

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


Re: [R] ggplot2: problem with large fonts and overlapping labels

2008-08-28 Thread ONKELINX, Thierry

Dear Paul,

How are you generating (saving) your plots? I tend to play with the
pointsize argument of the graphical device, something in conjunction
with the size argument in ggplot2 (size of points and lines). Working
like that I get plots with nicely propotioned labels without overlaps.

HTH,

Thierry




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
[EMAIL PROTECTED]
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Namens Paul Emberson
Verzonden: woensdag 27 augustus 2008 17:58
Aan: r-help@r-project.org
Onderwerp: [R] ggplot2: problem with large fonts and overlapping labels

Hi,

I am using ggplot2 to generate graphs for a paper I am writing in two
column format.  When I shrink the graphs to fit in a single column, the
graph is clear but the axis and tick labels are way too small.

I have increased the font sizes by manipulating the grid.  However, when

I do this the tick labels and axis labels get very close or even
overlap, especially on the y-axis.  Is there a way to increase the
margin between tick labels and axis labels with ggplot or by
manipulating the grid?

Regards,

Paul

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

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in  this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document

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


[R] Odp: I need to change from character to numeric?

2008-08-28 Thread Petr PIKAL
Hi

[EMAIL PROTECTED] napsal dne 28.08.2008 02:55:34:

 
 Hi,
 
 I am reading numeric data as below but the problem is the object ndata1 
and
 nd1 have characters instead of numeric values. I want to keep it as 
numeric.
 Why the type has changed from numeric to character and how to avoid this
 problem?
 
 
 
 rdata1- read.table(file=data1.txt, header=F,stringsAsFactors=F)

Read your data properly. They obviously have header so why you use header 
= F.

rdata1- read.table(file=data1.txt, header=T, stringsAsFactors=F)

shall read it as numeric if you do not have some non numeric values 
somwhere.

Regards
Petr

 rdata1
   V1
 1 d1
 2 11
 3 20
 4 13
 rdata2
   V1
 1 d2
 2  1
 3  7
 4  5
 5  6
 ndata1-rdata1[2:nrow(rdata1),]
  ndata1
 [1] 11 20 13
 nd1-cbind(ndata1,v2=0)
  nd1
  ndata1 v2 
 [1,] 11   0
 [2,] 20   0
 [3,] 13   0
 
 -- 
 View this message in context: 
http://www.nabble.com/I-need-to-change-from-
 character-to-numeric--tp19192541p19192541.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] coding rules

2008-08-28 Thread Gavin Simpson
On Wed, 2008-08-27 at 09:48 -0300, Henrique Dallazuanna wrote:
 See
 
 http://www1.maths.lth.se/help/R/RCC/

The R Internals manual that is shipped with R also has a section on
coding standards:

http://cran.r-project.org/doc/manuals/R-ints.html#R-coding-standards

though this is quite short and does not go into detail of naming
conventions etc. This document also points to the GNU Coding Standards
which R aims to follow.

The R Developer Page has some useful information, such as guidelines for
writing *.Rd files: http://developer.r-project.org/ and the Writing R
Extensions manual has a lot of information on writing packages, cross
platform portability etc:

http://cran.r-project.org/doc/manuals/R-exts.html

G

 
 On Wed, Aug 27, 2008 at 9:36 AM, Thomas LOUBRIEU
 [EMAIL PROTECTED] wrote:
  Dear all,
 
  I am organizing a set of specific R code as package (to ease the
  documentation and deployment of it to users).
  Before doing so, I would like to know if there are written coding rules for
  R (with functions, objects naming convention for example).
 
  Thanks a lot,
 
  Thomas
 
  --
 
 
  -
  Thomas LOUBRIEU
  IFREMER IDM/ISI
  BP70
  29280 Plouzane
  FRANCE
   email: [EMAIL PROTECTED]
  WWW  : http://www.coriolis.eu.org/cdc
  Tel.:  (+33) (0)2 98 22 48 53
  Fax:   (+33) (0)2 98 22 46 44
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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.


[R] drop unused levels in sqldf

2008-08-28 Thread glaporta

Hi,
sqldf is a fantastic package, but when the SELECT procedure runs unused
levels remain in the output. I tried with the drop function, but without
success. Do you have any suggestions?
Thanx, Gianandrea

data(iris)
require(sqldf)
base-sqldf(select * from iris where Species  'setosa')
str(base) # Species with 3 levels!

-- 
View this message in context: 
http://www.nabble.com/drop-unused-levels-in-sqldf-tp19196464p19196464.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to learn R language?

2008-08-28 Thread Tomas Lanczos

Bert Gunter wrote:
 


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Robert Baer
Sent: Wednesday, August 27, 2008 3:42 PM
To: r-help@r-project.org
Subject: Re: [R] How to learn R language?

but I doubt you'll ever be done 
learning because the project is so comprehensive ;-)



-- which is a good thing for us old geezers who need to keep our neurons
firing as much as possible...

Cheers,
Bert
  

How true!!!
:-)

Tomas

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 princomp output to equation for plane?

2008-08-28 Thread Mark Difford

Hi Bill,

 Since x, y,and z all have measurement errors attached, the proper way 
 to do the fit is with principal components analysis, and to use the 
 first component (called loadings in princomp output).

The easiest way for you to do this is to use the pcr [principal component
regression] function in the pls package. Be aware that unless you fit all
components you will be carrying out a form of penalized regression. A small
example follows (assumes that you have installed the pls package):

##
lm.mod - lm(Ozone ~ Solar.R + Wind + Month, data=airquality)
pc.mod - pcr(Ozone ~ Solar.R + Wind + Month, data=airquality)

lm.mod
coef(pc.mod, intercept = TRUE)
coef(pc.mod, ncomp=1, intercept = TRUE)
coef(pc.mod, ncomp=3, intercept = TRUE)

Regards, Mark.


William Simpson-2 wrote:
 
 I want to fit something like:
 z = b0 + b1*x + b2*y
 
 Since x, y,and z all have measurement errors attached, the proper way
 to do the fit is with principal components analysis, and to use the
 first component (called loadings in princomp output).
 
 My dumb question is: how do I convert the princomp output to equation
 coefficients in the format above?
 
 I guess another dumb question would be: how about getting the standard
 deviations of b0, b1, b2?
 
 Thanks very much for any help.
 
 Bill
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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/convert-princomp-output-to-equation-for-plane--tp19182643p19197360.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] Fw: How to learn R language?

2008-08-28 Thread Graham Smith
While agreeing with how good the texts that have been suggested are,
the questions to me (language + systematic) suggests

Braun and Murdoch  A first course in statistical programming  or/and
Chambers  Software for data analysis: programming with R

These would seem to take you through developing an understanding of
language fundamentals, in a more structured manner than the other
books mentioned.

Graham

2008/8/27 saggak [EMAIL PROTECTED]:


 --- On Wed, 27/8/08, saggak [EMAIL PROTECTED] wrote:

 From: saggak [EMAIL PROTECTED]
 Subject: How to learn R language?
 To: r-help@r-project.org
 Date: Wednesday, 27 August, 2008, 3:37 PM






 Hi!

 I am a post graduate in Statistics. I want to learn R language, but am very 
 confused as to how to begin systematically. I need to learn R language from 
 Statistics point of view e.g. I need to fit distributions to data or run 
 regression analysis etc. No doubt there are so many articles available on 
 internet. But can someone guide me as to how do I begin and go on improving 
 myself SYSTEMATICALLY?

 Hence, please guide me as to how should I start learning R language? What 
 should I read first etc.

 Thanks in advance,

 Sagga K



 Unlimited freedom, unlimited storage. Get it now


  Unlimited freedom, unlimited storage. Get it now, on 
 http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
[[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] drop unused levels in sqldf

2008-08-28 Thread David Hajage
If you want to suppress the unused level of Species, you can use factor() :

table(base$Species)
table(factor(base$Species))

2008/8/28 glaporta [EMAIL PROTECTED]


 Hi,
 sqldf is a fantastic package, but when the SELECT procedure runs unused
 levels remain in the output. I tried with the drop function, but without
 success. Do you have any suggestions?
 Thanx, Gianandrea

 data(iris)
 require(sqldf)
 base-sqldf(select * from iris where Species  'setosa')
 str(base) # Species with 3 levels!

 --
 View this message in context:
 http://www.nabble.com/drop-unused-levels-in-sqldf-tp19196464p19196464.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


[R] error in packet 1

2008-08-28 Thread Giovanni Tarquinio
Hello, 
I'm Giovanni from ROMA..

I can't find a solution for the error:

error using packet 1
the y field is not specified and it has not a default value
(this is my traslation from italian language)

The code is:

pc-qqmath(~valori,
distribution=function(p) qweibull(p,beta,alpha),
prepanel = prepanel.qqmathline,
panel = function(x, y) {
 panel.grid()
 panel.qqmathline(y, distribution = function(p)
qweibull(p,beta,alpha))
 panel.qqmath(x, y)
   },
layout = c( 1,1), aspect = 0.8,
xlab = Unit Weibull Quantile, ylab = D
)


Thanks for your regard,
Giovanni

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Linear model with one known coordinate

2008-08-28 Thread abaresic

Dear All,
I have a question which seems trivial, but I reached a dead end.
I have a set of points (measurements) and I used lm() to obtain their linear
regression model. From the biological background this line must pass through
a point (100,0). Our dataset is not optimal and it shows a slight deviation
from that coordinate. How can I add the restraint to the model, to go
through that point?

Any help would be appreciated.

Anya Baresic, PhD Student
Research Department of Structural and Molecular Biology
University College London
[EMAIL PROTECTED]
-- 
View this message in context: 
http://www.nabble.com/Linear-model-with-one-known-coordinate-tp19196978p19196978.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] A simple analysis of Bayesian Robustness with R

2008-08-28 Thread Davide Crapis

I have to make a simulation testing the Bayesian Robustness of a normal
linear model and comparing the regression results obtained using two
different g-priors. I tried with the function  blinreg() in the LearnBayes
package from J.Albert but it doesn't help me because it uses a standard flat
nonninformative prior, while I need to make changes to the structure of the
prior (in particular to the prior variance) to perform my simulation.

Does anybody has any suggestion or knows any R-function that would help?
-- 
View this message in context: 
http://www.nabble.com/A-simple-analysis-of-Bayesian-Robustness-with-R-tp19197602p19197602.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] ggplot2: problem with large fonts and overlapping labels

2008-08-28 Thread Paul Emberson

Hi Thierry,

Thanks for your reply.  I use the pdf graphics device.  I did not know 
about the pointsize option so I will take a look.  Here is an example of 
what I might do.


pdf(onefile=FALSE, width=10, height=7)
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() + theme_bw
grid.gedit(gPath(labels, label), gp=gpar(col=rgb(0,0,0), cex=1.25))
grid.gedit(gPath(xlabel), gp=gpar(cex=1.25))
grid.gedit(gPath(ylabel), gp=gpar(cex=1.25))
dev.off()

On this example it actually looks ok, but on my real data I have longer 
axis labels which overlap with the tick labels.


Regards,

Paul

ONKELINX, Thierry wrote:

Dear Paul,

How are you generating (saving) your plots? I tend to play with the
pointsize argument of the graphical device, something in conjunction
with the size argument in ggplot2 (size of points and lines). Working
like that I get plots with nicely propotioned labels without overlaps.

HTH,

Thierry




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
[EMAIL PROTECTED]
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Namens Paul Emberson
Verzonden: woensdag 27 augustus 2008 17:58
Aan: r-help@r-project.org
Onderwerp: [R] ggplot2: problem with large fonts and overlapping labels

Hi,

I am using ggplot2 to generate graphs for a paper I am writing in two
column format.  When I shrink the graphs to fit in a single column, the
graph is clear but the axis and tick labels are way too small.

I have increased the font sizes by manipulating the grid.  However, when

I do this the tick labels and axis labels get very close or even
overlap, especially on the y-axis.  Is there a way to increase the
margin between tick labels and axis labels with ggplot or by
manipulating the grid?

Regards,

Paul

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

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in  this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document


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


Re: [R] ggplot2: problem with large fonts and overlapping labels

2008-08-28 Thread Paul Emberson

Dear Thierry,

The pointsize option works perfectly for me.

Thanks,

Paul

ONKELINX, Thierry wrote:

Dear Paul,

How are you generating (saving) your plots? I tend to play with the
pointsize argument of the graphical device, something in conjunction
with the size argument in ggplot2 (size of points and lines). Working
like that I get plots with nicely propotioned labels without overlaps.

HTH,

Thierry




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
[EMAIL PROTECTED]
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Namens Paul Emberson
Verzonden: woensdag 27 augustus 2008 17:58
Aan: r-help@r-project.org
Onderwerp: [R] ggplot2: problem with large fonts and overlapping labels

Hi,

I am using ggplot2 to generate graphs for a paper I am writing in two
column format.  When I shrink the graphs to fit in a single column, the
graph is clear but the axis and tick labels are way too small.

I have increased the font sizes by manipulating the grid.  However, when

I do this the tick labels and axis labels get very close or even
overlap, especially on the y-axis.  Is there a way to increase the
margin between tick labels and axis labels with ggplot or by
manipulating the grid?

Regards,

Paul

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

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in  this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document


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


[R] Singularity?

2008-08-28 Thread Williams, Robin
Hi all, 
  When using lm to model a response with 8 explanatory variables, one of
the variables is not defined due to singularities. I have checked the
csv file from which the data come, there are no na's in the dataset,
etc. What should I be looking for in this variable to correct the
problem? 
Thanks for any help. 
 

Robin Williams
Met Office summer intern - Health Forecasting
[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] R graph with values incorporated

2008-08-28 Thread Prasanth
Dear All:

 

Greetings!

By the way, is it possible to have a graph (say line graph) that shows
values as well (say y-axis values within the graph)? One could do it in
excel. I am just wondering whether it is possible with R!

 

 

Thanks in advance,

Prasanth VP,

Global Manager - Biometrics,

Delta Technology  Management Services Pvt Ltd,

Plot No: 13/2, Sector - I,

Third Floor, HUDA Techno Enclave,

Madhapur, Hyderabad - 500 033.

Office:+91-40-2355-3992 
Mobile: +91-9848290025.

www.deltaintech.com

 


**

'The information contained in this email is confidential and may contain
proprietary information. It is meant solely for the intended recipient.
Access to this email by anyone else is unauthorized. If you are not the
intended recipient, any disclosure, copying, distribution or any action
taken or omitted in reliance on this, is prohibited and may be unlawful. No
liability or responsibility is accepted if information or data is, for
whatever reason corrupted or does not reach its intended recipient. No
warranty is given that this email is free of viruses. The views expressed in
this email are, unless otherwise stated, those of the author and not those
of DELTA Technology and Management Services pvt ltd or its management. DELTA
Technology and Management Services pvt ltd reserves the right to monitor
intercept and block emails addressed to its users or take any other action
in accordance with its email use policy' 

Thank you in advance for your cooperation.


**

P Please don't print this e-mail unless you really need to.

 


[[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] Quantitative risk analysis with R

2008-08-28 Thread Tobias Verbeke

Dear Graham,


Recently a course with this title, from Vose consulting, was announced
on the list. Does anyone know of  any books/websites/downloadable
tutorials etc that cover the same ground.


There is an R package QRMlib on CRAN

http://cran.r-project.org/web/packages/QRMlib/index.html

that accompanies the book Quantitative Risk Management: Concepts, 
Techniques and Tools by Alexander J. McNeil, Rüdiger Frey and Paul Embrechts


http://www.ma.hw.ac.uk/~mcneil/book/index.html

HTH,
Tobias


ie not just quantitative risk analysis, but specifically on using R
for risk analysis and as an alternative to @Risk/Crystal Ball.

Many thanks,

Graham

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

2008-08-28 Thread Fränzi Korner
Hi

does somebody know how to plot single letters in a text in different
colours?

example 1: 
I would like to add the word ABC to a figure. Thereby each letter should
have a different colour.

text(x,y,ABC, col=c(1,2,3))  # this does not work



example 2:
I would like to add the name of a parameter p with an index i to a figure.
The index i should be in red, whereas the rest of the text should be in
black.

text(x,y, expression(p[i]))


Looking forward to your answers!

Fränzi

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


Re: [R] Renaming objects

2008-08-28 Thread stephen sefick
names, colnames, rownames - list of names
I think it depends on what you are renaming?

Stephen

On Thu, Aug 28, 2008 at 4:03 AM, Williams, Robin
[EMAIL PROTECTED] wrote:
 Hi,
  Is there any quick and easy way to rename a number of objects, without
 having to rename each one individually and then remove the old one? And
 if so, is there anything I can do to adjust the associated comments
 accordingly?
 Thanks for any help,

 Robin Williams
 Met Office summer intern - Health Forecasting
 [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.




-- 
Stephen Sefick
Research Scientist
Southeastern Natural Sciences Academy

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

-K. Mullis

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


Re: [R] Singularity?

2008-08-28 Thread Ted Harding
On 28-Aug-08 11:04:47, Wi lliams, Robin wrote:
 Hi all, 
   When using lm to model a response with 8 explanatory variables,
 one of the variables is not defined due to singularities.
 I have checked the csv file from which the data come, there are
 no na's in the dataset, etc. What should I be looking for in this
 variable to correct the problem? 
 Thanks for any help. 
 
 Robin Williams
 Met Office summer intern - Health Forecasting
 [EMAIL PROTECTED]

You should be looking at whether the variable is expressible,
throughout, as a linear combination of the other explanatory
variables.

Try svd(X) where X is the transpose of the matrix of explanatory
variables from the CSV file (i.e. X has variables as rows, cases
as columns) -- if you get a very small value in svd(X)$d then that
points to your problem. Example:

  X-rbind(rnorm(10),rnorm(10),rnorm(10))
  X - rbind(X,X[1,]+ 0.5*X[2,]-0.25*X[3,])
 svd(X)
# $d
# [1] 4.355094e+00 3.717386e+00 2.101743e+00 1.842137e-16
# $u
# [,1]   [,2][,3]  [,4]
# [1,] -0.71645227 -0.1715990 -0.15753569 -0.657596
# [2,]  0.47501937 -0.8106696  0.09520123 -0.328798
# [3,]  0.09347153 -0.1262667 -0.97380325  0.164399
# [4,] -0.50231047 -0.5453671  0.13351574  0.657596
# (plus the right-hand eigenvectors)

Note the very small value of $d[4] -- this is the machine approximation
to zero. The corresponding left eigenvector $u[,4] annihilates X:

V - svd(X)$u[,4]
t(V)%*%X
#   [,1]  [,2]  [,3]  [,4] 
# [1,]  4.228388e-17 -3.894996e-17 -8.020386e-17 -9.790346e-17
#   [,5]  [,6]  [,7]  [,8]
# [1,] -2.710505e-17 -2.683400e-18 -3.876700e-17  8.250779e-17
#   [,9] [,10]
# [1,]  1.439278e-16  1.015762e-17

all of which are machine approximations to zero!

Hoping this helps,
Ted.


E-Mail: (Ted Harding) [EMAIL PROTECTED]
Fax-to-email: +44 (0)870 094 0861
Date: 28-Aug-08   Time: 12:42:31
-- 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] A Tip: lm, glm, and retained cases

2008-08-28 Thread Prof Brian Ripley

In R-devel


na.action(GLM)


will work as the extractor.  The problem with attr(GLM$model, na.action)
is that the 'model' component is optional, and with 
model.frame(ModelObject) that if the 'model' component has been omitted it 
will try to recreate the model frame from the currently visible objects of 
the name originally used.  (Because that is error-prone, we switched to 
model=TRUE as the default.)


In earlier versions of R, GLM$na.action is the copy you want.

However, I think if you care about omitted rows, you should use 
na.action=na.exclude, for then most auxiliary functions will give you 
results for all the rows.



On Tue, 26 Aug 2008, Marc Schwartz wrote:


on 08/26/2008 07:31 PM (Ted Harding) wrote:

On 26-Aug-08 23:49:37, hadley wickham wrote:

On Tue, Aug 26, 2008 at 6:45 PM, Ted Harding
[EMAIL PROTECTED] wrote:

Hi Folks,
This tip is probably lurking somewhere already, but I've just
discovered it the hard way, so it is probably worth passing
on for the benefit of those who might otherwise hack their
way along the same path.

Say (for example) you want to do a logistic regression of a
binary response Y on variables X1, X2, X3, X4:

 GLM - glm(Y ~ X1 + X2 + X3 + X4)

Say there are 1000 cases in the data. Because of missing values
(NAs) in the variables, the number of complete cases retained
for the regression is, say, 600. glm() does this automatically.

QUESTION: Which cases are they?

You can of course find out by hand on the lines of

 ix - which( (!is.na(Y))(!is.na(X1))...(!is.na(X4)) )

but one feels that GLM already knows -- so how to get it to talk?

ANSWER: (e.g.)

 ix - as.integer(names(GLM$fit))


This is a partial match to 'fitted', and will only work if default row 
names were used.



Alternatively, you can use:

attr(GLM$model, na.action)

Hadley


Thanks! I can see that it works -- though understanding how
requires a deeper knowledge of R internals. However, since
you've approached it from that direction, simply

  GLM$model

is a dataframe of the retained cases (with corresponding
row-names), all variables at once, and that is possibly an
even simpler approach!


Or just use:

  model.frame(ModelObject)

as the extractor function...  :-)

Another 'a priori' approach would be to use na.omit() or one of its
brethren on the data frame before creating the model. Which function is
used depends upon how 'na.action' is set.

The returned value, or more specifically the 'na.action' attribute as
appropriate, would yield information similar to Hadley's approach
relative to which records were excluded.

For example, using the simple data frame in ?na.omit:

DF - data.frame(x = c(1, 2, 3), y = c(0, 10, NA))


DF

 x  y
1 1  0
2 2 10
3 3 NA

DF.na - na.omit(DF)


DF.na

 x  y
1 1  0
2 2 10


attr(DF.na, na.action)

3
3
attr(,class)
[1] omit


So you can see that record 3 was removed from the original data frame
due to the NA for 'y'.

HTH,

Marc Schwartz

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



--
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] Quantitative risk analysis with R

2008-08-28 Thread Graham Smith
Tobias,

Thanks I will give this a look, it seems the focus is on credit risk
(where I am more interested in environmental risks) but it should
still be useful.

Graham

2008/8/28 Tobias Verbeke [EMAIL PROTECTED]:
 Dear Graham,

 Recently a course with this title, from Vose consulting, was announced
 on the list. Does anyone know of  any books/websites/downloadable
 tutorials etc that cover the same ground.

 There is an R package QRMlib on CRAN

 http://cran.r-project.org/web/packages/QRMlib/index.html

 that accompanies the book Quantitative Risk Management: Concepts, Techniques
 and Tools by Alexander J. McNeil, Rüdiger Frey and Paul Embrechts

 http://www.ma.hw.ac.uk/~mcneil/book/index.html

 HTH,
 Tobias

 ie not just quantitative risk analysis, but specifically on using R
 for risk analysis and as an alternative to @Risk/Crystal Ball.

 Many thanks,

 Graham

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

2008-08-28 Thread Barry Rowlingson
2008/8/28 Fränzi Korner [EMAIL PROTECTED]:

 example 1:
 I would like to add the word ABC to a figure. Thereby each letter should
 have a different colour.

 text(x,y,ABC, col=c(1,2,3))  # this does not work


kludge alert!

 How about:
text(x,y,ABC,col=3)
text(x,y,AB,col=2)
text(x,y,A,col=1)

 Basically this overlays three coloured texts to give the impression
of individual coloured letters. This may or may not be practical for
your real application. It's also possible that if you print this your
printer will end up printing A with a mix of colours 1, 2 and 3.

 If your font is monospaced you could do it with text(x,y,
C,col=3), but in a pretty font the letters AB wont have the same
width as two spaces.

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.


[R] [R-pkgs] New package: ``denstrip'' for compactly illustrating distributions

2008-08-28 Thread Chris Jackson

Dear R users,

I'd like to announce a new package on CRAN called ``denstrip''.  It
implements ``density strips'' and other graphical methods for
illustrating and comparing distributions in a compact fashion.

Posterior distributions of parameters are often summarised using point
and line drawings of means and credible intervals.  This is common,
for example, in multiple regression or meta-analysis.  Density
strips generalise these to illustrate whole distributions.  Instead of a
point and line, a shaded strip indicates the density as proportional to
the darkness of the shading.  They taper to white at the end of the
strip, instead of terminating at a clear limit - this may discourage
casually categorising effects as ``significant'' if the line excludes
the null.

The shading idea generalises to ``density regions'' to show
uncertainty about continuously-varying quantities, such as predictions
from time series.  The package includes other functions for
illustrating distributions in ``one dimension'', such as varying-width
strips (similar to violin plots) and sectioned density plots.

If you're interested in reading more about these methods, I discuss
them in a forthcoming article in The American Statistician, ``Displaying
uncertainty with shading'', also available from

http://www.mrc-bsu.cam.ac.uk/personal/chris/papers/denstrip.pdf

Comments and suggestions for improvement of the package are welcome.

--
Christopher Jackson [EMAIL PROTECTED]
Research Statistician, MRC Biostatistics Unit, Institute of Public
Health, Robinson Way, Cambridge, UK, CB2 0SR. +44 (1223) 330381

___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages

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


Re: [R] averaging pairs of columns in a dataframe

2008-08-28 Thread Gasper Cankar
 somehow robust method for dataframe df would be

newdf - (df[,seq(1,66,2)]+df[,seq(2,66,2)])/2


Gasper


-Original Message-
From: JonD [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 27, 2008 3:47 PM
To: r-help@r-project.org
Subject: [R] averaging pairs of columns in a dataframe


Dear all,

I have a dataframe with 132 columns and 100 rows.  Every 2nd column is a
repeat measurement so that the columns could be titled, a a b b c c d d etc.

I would like to average the repeats such that I am left with a data frame of
66 columns (of means) and 100 rows.  

I have been trying to use rowMeans but have not been able to average the
pairs of columns, only the whole dataframe.

Any help would be appreciated, I am new to R.

Thanks in advance,

Jon.
--
View this message in context:
http://www.nabble.com/averaging-pairs-of-columns-in-a-dataframe-tp19181319p1
9181319.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] Plots spanning columns

2008-08-28 Thread Jose Luis Aznarte M.
   Hi! I want to plot three graphs (residuals, ACF and PACF of a 
model). Ideally I would use a c(2,2) disposition where the residuals 
plot would start at position 1,1 and span to position 1,2. Then I would 
plot the ACF in position 2,1 and the PACF in position 2,2. Maybe is 
clearer like this:


--
||
|   residuals|
||
--
 -
|  | |   |
|ACF   | |   PACF|
|  | |   |
 -

Does anyone know if that is possible at all? Cheers!

--
--  --
Jose Luis Aznarte M.   http://decsai.ugr.es/~jlaznarte
Department of Computer Science and Artificial Intelligence
Universidad de Granada   Tel. +34 - 958 - 24 04 67
GRANADA (Spain)  Fax: +34 - 958 - 24 00 79

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


Re: [R] coloured letters in a text

2008-08-28 Thread Gabor Grothendieck
See ?strwidth, e.g.

plot(1)
text(1.1, 1.1, A)
text(1.1 + strwidth(A), 1.1, B, col = 2)
text(1.1 + strwidth(AB), 1.1, C, col = 3)


On Thu, Aug 28, 2008 at 7:33 AM, Fränzi Korner
[EMAIL PROTECTED] wrote:
 Hi

 does somebody know how to plot single letters in a text in different
 colours?

 example 1:
 I would like to add the word ABC to a figure. Thereby each letter should
 have a different colour.

 text(x,y,ABC, col=c(1,2,3))  # this does not work



 example 2:
 I would like to add the name of a parameter p with an index i to a figure.
 The index i should be in red, whereas the rest of the text should be in
 black.

 text(x,y, expression(p[i]))


 Looking forward to your answers!

 Fränzi

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

2008-08-28 Thread Henrique Dallazuanna
Try this:

l - layout(matrix(c(1, 2, 1, 3), 2))
layout.show(l)

On Thu, Aug 28, 2008 at 9:40 AM, Jose Luis Aznarte M. 
[EMAIL PROTECTED] wrote:

   Hi! I want to plot three graphs (residuals, ACF and PACF of a model).
 Ideally I would use a c(2,2) disposition where the residuals plot would
 start at position 1,1 and span to position 1,2. Then I would plot the ACF in
 position 2,1 and the PACF in position 2,2. Maybe is clearer like this:

 --
 ||
 |   residuals|
 ||
 --
  -
 |  | |   |
 |ACF   | |   PACF|
 |  | |   |
  -

 Does anyone know if that is possible at all? Cheers!

 --
 --  --
 Jose Luis Aznarte M.   
 http://decsai.ugr.es/~jlaznartehttp://decsai.ugr.es/%7Ejlaznarte
 Department of Computer Science and Artificial Intelligence
 Universidad de Granada   Tel. +34 - 958 - 24 04 67
 GRANADA (Spain)  Fax: +34 - 958 - 24 00 79

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

2008-08-28 Thread rkevinburton
That would be one source of error. Thank you.

Kevin

 ONKELINX wrote: 
 
 Kevin,
 
 Notice the subtle difference between Hadley's and your code:
 
 Hadley
 m2008$DayOfYear - factor(m2008$DayOfYear, levels = 1:365)
 
 Kevin
 m2007$DayOfYear - factor(m2008$DayOfYear, levels = 1:365)
 
 Your are using the m2007 object instead of the suggested m2008 object!
 
 HTH,
 
 Thierry
 
 
 
 
 
 ir. Thierry Onkelinx
 Instituut voor natuur- en bosonderzoek / Research Institute for Nature
 and Forest
 Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
 methodology and quality assurance
 Gaverstraat 4
 9500 Geraardsbergen
 Belgium
 
 tel. + 32 54/436 185
 [EMAIL PROTECTED]
 
 www.inbo.be
 
 
 To call in the statistician after the experiment is done may be no more
 than asking him to perform a post-mortem examination: he may be able to
 say what the experiment died of.
 ~ Sir Ronald Aylmer Fisher
 
 The plural of anecdote is not data.
 ~ Roger Brinner
 
 The combination of some data and an aching desire for an answer does not
 ensure that a reasonable answer can be extracted from a given body of
 data.
 ~ John Tukey
 
 -Oorspronkelijk bericht-
 Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Namens [EMAIL PROTECTED]
 Verzonden: donderdag 28 augustus 2008 3:14
 Aan: r-help@r-project.org
 Onderwerp: Re: [R] Updating a list.
 
 Since this didn't work:
 
  m2007$DayOfYear - factor(m2008$DayOfYear, levels = 1:365)
 Error in `$-.data.frame`(`*tmp*`, DayOfYear, value = c(1L, 1L, 1L,  :
 
   replacement has 432267 rows, data has 1592009
 
 Perhaps I need to clarify how the m2007 object was generated.
 
 t2007 - read.csv(Total2007.dat, header = TRUE)
 m2007 - melt(t2007,
 id.var=c(DayOfYear,Category,SubCategory,Sku),
 measure.var=c(Quantity))
 
 Kevin
 
 
  hadley wickham [EMAIL PROTECTED] wrote:
 
 
 
  Try this:
 
 
  m2008$DayOfYear - factor(m2008$DayOfYear, levels = 1:365)
  r2007 - cast(m2008, DayOfYear ~ variable | Sku, sum, fill = 0)
 
 
  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.
 
 Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
 en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd 
 is door een geldig ondertekend document.
 The views expressed in  this message and any annex are purely those of the 
 writer and may not be regarded as stating an official position of INBO, as 
 long as the message is not confirmed by a duly signed document

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


Re: [R] Potential Error/Bug?: addition of NULL during arithmetic

2008-08-28 Thread Prof Brian Ripley

On Tue, 26 Aug 2008, Eric DeWitt wrote:


I encountered an error that does not make sense to me given my reading
of the documentation and does not appear to be referenced in the list
archives or online. The error occurred when a function received a NULL
value rather than a numeric value as a parameter and then attempted to
use the NULL value in the calculateion. The error: Error during wrapup:
nothing to replace with can be easily recreated with the following code:


1 + NULL  # note that the opperation succeeds and returns a numeric vector with 
dim(NULL)

numeric(0)


As documented, of course.


bar - 1
bar

[1] 1

foo - 1 + NULL
foo

numeric(0)


bar - bar + foo # note that here the assignment operation succeeds and 1 + (1 + 
NULL) - numeric(0)
bar

numeric(0)


bar - c(1, 1) # however if the assignment is into a vector
bar[1] - bar[1] + foo # note that the mathematical operation is identical, but 
the assignment fails

Error during wrapup: nothing to replace with


That's the trouble, this is not the same operation at all.  This is 
replacing one element of a vector, not naming the result 'bar'.



If this is the intended behavior, a more informative error message (e.g.
'attempt to assign NULL to vector element') would be useful. If it is
not the intended behavior, should I log this as a bug?


It is the intended and documented behaviour. You tried to set element 1 of 
bar to bar[1] + foo, which is numeric(0) (by the documented recycling 
rules).  The error message: 'nothing to replace with' seems very 
informative to me.  If you put some effort into understanding your own 
errors by doing things step by step, as in



bar - c(1, 1)
foo - bar[1] + foo
bar[1] - foo

Error in bar[1] - foo : nothing to replace with

foo

numeric(0)

you might learn more.

I don't know how you got an 'Error during wrapup': that is not 
reproducible (it might be a function of using a console, if you did).




-eric


sessionInfo()

R version 2.7.1 (2008-06-23)
powerpc-apple-darwin8.10.1

locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   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] R graph with values incorporated

2008-08-28 Thread Rubén Roa-Ureta

Prasanth wrote:

Dear All:

 


Greetings!

By the way, is it possible to have a graph (say line graph) that shows
values as well (say y-axis values within the graph)? One could do it in
excel. I am just wondering whether it is possible with R!
  

x - rnorm(100,2,3)
y - rnorm(100,2,3)
plot(x,y,pch=19)
text(x=x,y=y+.5,format(x,digits=1),cex=.5)


[[alternative HTML version deleted]]  -- Read the posting guide.



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


Re: [R] Upgrading R means I lose my packages

2008-08-28 Thread Michael Friendly

James Milks wrote:
The title says it all.  Does anyone know of a way to save your packages 
when you upgrade to a new version of R?  This may seem petty, but I'm 
accumulating enough packages that having to download and install each of 
them anew every time I install a new version of R is rather of a pain.  
Ideally, I would like the new version of R to recognize the packages 
I've installed on the previous version without needing to reinstall the 
packages.  Is that possible?


My system: Mac OS 10.5.4.
Current R version: 2.7.1

Thanks for any suggestions.  My apologies if this has been answered 
before and my search missed it.


Jim Milks

Degree Candidate

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

and provide commented, minimal, self-contained, reproducible code.


What I find simplest (on Windows at least) is

# To reinstall packages from one R version to the next:
#Currently you can do

tmp - installed.packages()
installedpkgs - as.vector(tmp[is.na(tmp[,Priority]), 1])
save(installedpkgs, file=c:/R/installed.rda)

#in the old version to get a list of packages you installed.  Then in the
#new version,

load(c:/R/installed.rda)
install.packages(installedpkgs)



--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA

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


Re: [R] coloured letters in a text

2008-08-28 Thread Prof Brian Ripley

On Thu, 28 Aug 2008, Barry Rowlingson wrote:


2008/8/28 Fränzi Korner [EMAIL PROTECTED]:


example 1:
I would like to add the word ABC to a figure. Thereby each letter should
have a different colour.

text(x,y,ABC, col=c(1,2,3))  # this does not work



kludge alert!

How about:
text(x,y,ABC,col=3)
text(x,y,AB,col=2)
text(x,y,A,col=1)


You need adj=0 for left justification.


Basically this overlays three coloured texts to give the impression
of individual coloured letters. This may or may not be practical for
your real application. It's also possible that if you print this your
printer will end up printing A with a mix of colours 1, 2 and 3.

If your font is monospaced you could do it with text(x,y,
C,col=3), but in a pretty font the letters AB wont have the same
width as two spaces.


What's wrong with using strwidth?


x - 3
text(x, 5, A, adj=0, col=1)
x - x + strwidth(A)
text(x, 5, B, adj=0, col=2)
x - x + strwidth(B)
text(x, 5, C, adj=0, col=3)


This will not use kerning, but only a few devices do.

--
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] Plots spanning columns

2008-08-28 Thread Richard M. Heiberger
library(HH)
example(tsacfplots)
?tsacfplots

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


Re: [R] Plots spanning columns

2008-08-28 Thread David Scott

On Thu, 28 Aug 2008, Jose Luis Aznarte M. wrote:

  Hi! I want to plot three graphs (residuals, ACF and PACF of a model). 
Ideally I would use a c(2,2) disposition where the residuals plot would start 
at position 1,1 and span to position 1,2. Then I would plot the ACF in 
position 2,1 and the PACF in position 2,2. Maybe is clearer like this:


--
||
|   residuals|
||
--
 -
|  | |   |
|ACF   | |   PACF|
|  | |   |
 -

Does anyone know if that is possible at all? Cheers!




I happened to do virtually that plot just recently. Just had data rather 
than residuals:


### Function to display plot, ACF and PACF
displayTimeSeries - function(x, heading = NULL,
  heights = NULL, ...){
defaultPars - par(no.readonly = TRUE)
if (is.null(heading)) {
heading - paste(Series: , deparse(substitute(x)))
}
if (is.null(heights)) heights - c(1,1)
layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE), heights = heights)
plot(x, main = heading)
par(mar = c(5,4,1,2) + 0.1)
acfVal -  acf(x, main = )$acf
pacfVal - acf(x, type = partial, main = )$acf
par(defaultPars)
invisible(list(acf = acfVal, pacf = pacfVal))
}

If you add a line which calculates the residuals and plots them instead of 
the data, then you should have what you want.


David Scott


_
David Scott Department of Statistics, Tamaki Campus
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000
Email:  [EMAIL PROTECTED]

Graduate Officer, Department of Statistics
Director of Consulting, Department of Statistics

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


Re: [R] Upgrading R means I lose my packages

2008-08-28 Thread Prof Brian Ripley

On Thu, 28 Aug 2008, Michael Friendly wrote:


James Milks wrote:
The title says it all.  Does anyone know of a way to save your packages 
when you upgrade to a new version of R?  This may seem petty, but I'm 
accumulating enough packages that having to download and install each of 
them anew every time I install a new version of R is rather of a pain. 
Ideally, I would like the new version of R to recognize the packages I've 
installed on the previous version without needing to reinstall the 
packages.  Is that possible?


My system: Mac OS 10.5.4.
Current R version: 2.7.1

Thanks for any suggestions.  My apologies if this has been answered before 
and my search missed it.


Jim Milks

Degree Candidate

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

and provide commented, minimal, self-contained, reproducible code.


What I find simplest (on Windows at least) is

# To reinstall packages from one R version to the next:
#Currently you can do

tmp - installed.packages()
installedpkgs - as.vector(tmp[is.na(tmp[,Priority]), 1])
save(installedpkgs, file=c:/R/installed.rda)

#in the old version to get a list of packages you installed.  Then in the
#new version,

load(c:/R/installed.rda)
install.packages(installedpkgs)


But this is an FAQ, with a cleaner answer in the rw-FAQ.  It really is 
much easier to make use of a separate library for the additional packages 
you install (and there is no need to reinstall packages when going from 
2.7.1 to 2.7.2, which helps if you have hundreds or even thousands 
installed -- a complete reinstall on our 32-bit Linux server took about 
5 hours when we did it for 2.7.0).


--
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] Integrate a 1-variable function with 1 parameter (Jose L.Romero)

2008-08-28 Thread Ravi Varadhan
Hi,

The answer can be obtained in closed form using the pgamma function,
which is closely related to the incomplete gamma function, as follows:


integrand - function (t, x) {
exp(-2*t)*(2*t)^x/(10*factorial(x))
}

upper - 10

x - 0:44

ans1 - sapply(x, function(x) integrate(integrand, lower=0, upper=upper,
x=x)) 

ans2 - gamma(x+1) * pgamma(q=2*upper, shape=x+1, rate = 1, scale = 1,
lower.tail = TRUE) / (20*factorial(x))# using the pgamma function 

cbind(x=x, ans1=unlist(ans1[1,]), ans2=ans2)  # both answers are identical


Ravi.



---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: [EMAIL PROTECTED]

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 





-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Moshe Olshansky
Sent: Wednesday, August 27, 2008 9:58 PM
To: r-help@r-project.org; [EMAIL PROTECTED]
Subject: Re: [R] Integrate a 1-variable function with 1 parameter (Jose
L.Romero)

This can be done analytically: after changing a variable (2*t - t) and some
scaling we need to compute
f(x) = integral from 0 to 20 of (t^x*exp(-t))dt/factorial(x)

f(0) = int from 0 to 20 of exp(-t)dt = 1 - exp(-20) and integration by parts
yields (for x=1,2,3,...) 

f(x) = -exp(-20)*20^x/factorial(x) + f(x-1) so that

f(x) = 1 - exp(-20)*sum(20^k/factorial(k)) where the sum is for k=0,1,...,x

If I did not a mistake, your original quantity should be f(x)/20.


--- On Thu, 28/8/08, jose romero [EMAIL PROTECTED] wrote:

 From: jose romero [EMAIL PROTECTED]
 Subject: [R] Integrate a 1-variable function with 1 parameter (Jose L. 
 Romero)
 To: r-help@r-project.org
 Received: Thursday, 28 August, 2008, 12:23 AM Hey fellas:
 
 I would like to integrate the following function:
 
 integrand - function (x,t) {
   exp(-2*t)*(2*t)^x/(10*factorial(x))
 }
 
 with respect to the t variable, from 0 to 10.
 The variable x here works as a parameter: I would like to integrate 
 the said function for each value of x in 0,1,..,44.
 
 I have tried Vectorize to no avail.
 
 Thanks in advance,
 jose romero
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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

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


Re: [R] Renaming objects

2008-08-28 Thread Gavin Simpson
On Thu, 2008-08-28 at 07:39 -0400, stephen sefick wrote:
 names, colnames, rownames - list of names
 I think it depends on what you are renaming?

Those alter the dimnames of objects that have them, not the names of the
objects themselves.

I think a short answer to the question is no. There is a nice thread on
a similar topic from April this year. In R, do:

RSiteSearch(rename objects)

And the first few hits cover the discussion. Rolf Turner presents his
mv() function in that thread, equivalent to the mv shell command in
Unix.

You could modify Rolf's mv() to accept a vector of objects to rename and
the new names they take. you could probably just pop the body of Rolf's
function in a loop over the number of rename operations, though I
haven't done this myself to check it works so simply...

G

 
 Stephen
 
 On Thu, Aug 28, 2008 at 4:03 AM, Williams, Robin
 [EMAIL PROTECTED] wrote:
  Hi,
   Is there any quick and easy way to rename a number of objects, without
  having to rename each one individually and then remove the old one? And
  if so, is there anything I can do to adjust the associated comments
  accordingly?
  Thanks for any help,
 
  Robin Williams
  Met Office summer intern - Health Forecasting
  [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.
 
 
 
 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 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.


[R] Help with shading a polygon below a segment of a curve (normal distribution)

2008-08-28 Thread Bertolt Meyer

Dear R users,

I still feel new to R so please apologize if I am doing something stupid 
here. My use of the polygon() function produces a result that I cannot 
comprehend: In a plot, I would like to shade the area below a normal 
distribution. However, I do not want the entire area to be shaded, but 
just the area on the right side of a vertical line that I draw through 
the distribution (in order to illustrate the function of a t-test). Here 
is what I do:


scale - 0.1
x - seq(-4, 6, scale)
y - dnorm(x)
plot(x, y, type = l, main=t-Test, t = 2.2)

linepos - 2.2
abline(v = linepos)

# I try to fill a polygon right of the vertical line:
# max(x) - linepos (in this case, 2.2) / scale (0.1)
# results in the last 38 elements of x and y.
# so I take the last 38 elements of x and y and try to
# draw a polygon underneath:

cutpoint - (max(x) - linepos) / scale

xt - x[(length(x)-cutpoint):length(x)]
yt - y[(length(y)-cutpoint):length(y)]

# draw the polygon

polygon(xt, yt, density = 10 )

As you can see in the result, this is not what I want; some area above 
the line gets shaded, but not below. Can someone tell me what I am missing?


Thank you very much,
Bertolt

--
Bertolt Meyer
Oberassistent
Sozialpsychologie, Psychologisches Institut der Universität Zürich
Binzmühlestr. 14, Box 15
CH-8050 Zürich

[EMAIL PROTECTED]
tel:   +41446357282
fax:   +41446357279
mob:   +41788966111

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


Re: [R] GeoR model.control - defining covariates at prediction locations

2008-08-28 Thread imicola

Thanks,

I've managed to make some progress, but seem to be getting some strange
results from my kriging, which I think much have something to do with a
problem with my prediction points.

I have my geodata object (called nicola), my prediction points (predpoints,
imported from a csv containing only the x and y coordinated of the
prediction locations) and my covariate data at each of the prediction points
(covars, imported from a csv containing the x and y coordinates of the
prediction locations, plus the values of the two covariates I want to use at
each of the prediction locations).

predpoints-read.csv(file=C:\\Documents and Settings\\s9901315\\My 
+ Documents\\Uni\\Data\\Work\\Case control study\\Full study area\\R\\Files
for analysis\\Prediction 
+ points\\predpoints.csv, header=FALSE, sep=,)

covars-read.csv(file=C:\\Documents and Settings\\s9901315\\My 
+ Documents\\Uni\\Data\\Work\\Case control study\\Full study area\\R\\Files
for analysis\\Covariate 
+ data\\covars.csv, header=TRUE, sep=,)

The final model is defined using OTUBOIDIST and LSTPHAN as external
covariates:

mlx2-likfit(nicola, cov.model=mat, kap=0.5, ini=c(0.6, 20), nug=0.3,
trend=~OTUBOIDIST + 
+ LSTPHAN)

and then I carry out the kriging using the model mlx2, prediction points
predpoints, and covariate data covars :

kcontrol-krige.control(obj.m=mlx2, type.krige=ok, trend.d=~OTUBOIDIST +
LSTPHAN, 
+ trend.l=~covars$otuboidist + covars$lstphan) 

krige-krige.conv(nicola, loc=predpoints, krige=kcontrol)

Then I view it using the image function:

image(krige, col=gray(seq(1, 0.2, l=100)))

The resulting image is clearly wrong with a regular stepped line appearing
diagonally across the image, and the predicted values do not coincide with
the actual observed data at all.  I've included the predicted data image, as
well as the predicted image overlaid with the data points.

http://www.nabble.com/file/p19201449/no%2Bpoints.jpg 
http://www.nabble.com/file/p19201449/withpoints.jpg 

Can anyone give me any pointers of why this may be going wrong?  I've tried
the same thing many times having changed everything I can think of that
might be causing the problem.

Thanks,
Nicola



[EMAIL PROTECTED]



Paulo Justiniano Ribeiro Jr-2 wrote:
 
 Trends in ge are handled by the trendargument.
 In particular, for the so called external trend we use varioables which
 can be at the geodata object or another object.
 
 For instance a model fitting call could be somethoing like:
 ML - likfit..., trend= ~covar1+ covar2, ...)
 
 where covar1 and covar2 have the same dimension as the data and can be
 vector or columuns withing the covariate elelent of a geodata obvject.
 
 For kriging you need the values of such covariates at prediction locations
 lts say the vectors predcovar1 and predcovar2
 
 Then you use model.control(..., trend.l= ~ predcovar1+predcovar2)
 
 Three are osme more examples at geoR page, Tutorials section, and please
 send the commands such that we can be more specific
 
 best
 P.J.
 
 
 
 Date: Mon, 18 Aug 2008 02:59:50 -0700 (PDT)
 From: imicola [EMAIL PROTECTED]
 Subject: [R] GeoR model.control - defining covariates at prediction
 locations
 To: r-help@r-project.org
 Message-ID: [EMAIL PROTECTED]
 Content-Type: text/plain; charset=us-ascii
 
 
 Hi,
 
 Im using geoR and I'm trying to do some predictions, based on an external
 trend.
 
 I'm having some problems specifying my model.control, specifically how do
 I
 define my model, and also the source of the covariate data at the
 prediction
 locations?
 
 I am assuming that the covariate data at the prediction locations should
 be
 imported to a geodata object along with the prediction location
 coordinates
 - this is what I have done, but I can't get the prediction to work.
 
 So my question is:  How should the prediction location and covariate data
 at
 prediction locations be stored?  And also how do I specify model.control
 so
 that it recognises where my covariate data is?
 
 Below is the error message that I am getting:
 
 krige.bayes: model with mean defined by covariates provided by the user
 Warning messages:
 1: locations provided as a list with more than 2 components. Only the 2
 first will be used as coordinates in: .check.locations(locations)
 2: data length [507] is not a sub-multiple or multiple of the number of
 rows
 [254] in matrix
 Error in trend.spatial(trend = model$trend.l, geodata = list(coords =
 locations)) :
 
 trend elements not found
 
 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.
 
 

-- 
View this message in context: 
http://www.nabble.com/GeoR-model.control---defining-covariates-at-prediction-locations-tp19028273p19201449.html
Sent from the R help mailing list archive at Nabble.com.


Re: [R] Help with shading a polygon below a segment of a curve (normal distribution)

2008-08-28 Thread Peter Dalgaard
Bertolt Meyer wrote:
 Dear R users,

 I still feel new to R so please apologize if I am doing something
 stupid here. My use of the polygon() function produces a result that I
 cannot comprehend: In a plot, I would like to shade the area below a
 normal distribution. However, I do not want the entire area to be
 shaded, but just the area on the right side of a vertical line that I
 draw through the distribution (in order to illustrate the function of
 a t-test). Here is what I do:

 scale - 0.1
 x - seq(-4, 6, scale)
 y - dnorm(x)
 plot(x, y, type = l, main=t-Test, t = 2.2)

 linepos - 2.2
 abline(v = linepos)

 # I try to fill a polygon right of the vertical line:
 # max(x) - linepos (in this case, 2.2) / scale (0.1)
 # results in the last 38 elements of x and y.
 # so I take the last 38 elements of x and y and try to
 # draw a polygon underneath:

 cutpoint - (max(x) - linepos) / scale

 xt - x[(length(x)-cutpoint):length(x)]
 yt - y[(length(y)-cutpoint):length(y)]

 # draw the polygon

 polygon(xt, yt, density = 10 )

 As you can see in the result, this is not what I want; some area above
 the line gets shaded, but not below. Can someone tell me what I am
 missing?

 Thank you very much,
 Bertolt

Your polygon contains no points on the x axis (yt==0).

Try adding this:

n - length(xt)
xt - c(xt[1], xt, xt[n])
yt - c(0,yt,0)
polygon(xt, yt, col=red )




-- 
   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] juxtaposed and stacked bars in one barplot?

2008-08-28 Thread Stefan Uhmann

hadley wickham schrieb:

Hi Stefan,

Could you be a bit more explicit?  Do you have an example dataset that
you are trying to visualise?



Right, thanks for pointing out the obvious.

So here's my code:


library(gplots)

quarter - as.factor(sample(c(Q1, Q2, Q3, Q4),
100, replace = TRUE))
year - as.factor(sample(c(seq(from=2000, to=2008)), 100, replace = TRUE))
category - as.factor(sample(c(seq(from=1, to=4)), 100, replace = TRUE))
test - data.frame(quarter, year, category)
table(test$category, test$quarter, test$year)
barplot2(table(test$quarter, test$year),
beside=T, ylim=c(0,10), main=how to include dim3?)
# inclusion of 3rd dimension does not work:
barplot2(table(test$quarter, test$year, test$category),
beside=T, ylim=c(0,10), main=how to include dim3?)


I want the barplot to be exactly the same but with the bars stacked (by 
'category'). I got the message from Gaspar, but have not yet tried to 
fit his example to my data.


/Stefan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 shading a polygon below a segment of a curve (normaldistribution)

2008-08-28 Thread Richard M. Heiberger
library(HH)
normal.and.t.dist()

There are many related examples in
example(normal.and.t.dist)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 shading a polygon below a segment of a curve (normaldistribution)

2008-08-28 Thread Derek Ogle
Bertolt,

The points you send to polygon() do not fully enclose the area you desire.  Try 
adding one more point as such

xt - c(x[(length(x)-cutpoint):length(x)],linepos)
yt - c(y[(length(y)-cutpoint):length(y)],0)
polygon(xt, yt, density = 10 )


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bertolt Meyer
Sent: Thursday, August 28, 2008 9:03 AM
To: r-help@r-project.org
Subject: [R] Help with shading a polygon below a segment of a curve 
(normaldistribution)

Dear R users,

I still feel new to R so please apologize if I am doing something stupid 
here. My use of the polygon() function produces a result that I cannot 
comprehend: In a plot, I would like to shade the area below a normal 
distribution. However, I do not want the entire area to be shaded, but 
just the area on the right side of a vertical line that I draw through 
the distribution (in order to illustrate the function of a t-test). Here 
is what I do:

scale - 0.1
x - seq(-4, 6, scale)
y - dnorm(x)
plot(x, y, type = l, main=t-Test, t = 2.2)

linepos - 2.2
abline(v = linepos)

# I try to fill a polygon right of the vertical line:
# max(x) - linepos (in this case, 2.2) / scale (0.1)
# results in the last 38 elements of x and y.
# so I take the last 38 elements of x and y and try to
# draw a polygon underneath:

cutpoint - (max(x) - linepos) / scale

xt - x[(length(x)-cutpoint):length(x)]
yt - y[(length(y)-cutpoint):length(y)]

# draw the polygon

polygon(xt, yt, density = 10 )

As you can see in the result, this is not what I want; some area above 
the line gets shaded, but not below. Can someone tell me what I am missing?

Thank you very much,
Bertolt

-- 
Bertolt Meyer
Oberassistent
Sozialpsychologie, Psychologisches Institut der Universität Zürich
Binzmühlestr. 14, Box 15
CH-8050 Zürich

[EMAIL PROTECTED]
tel:   +41446357282
fax:   +41446357279
mob:   +41788966111

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

2008-08-28 Thread Don MacQueen
Speaking for myself, I think it's easier to just create a script and 
put it somewhere easy to remember.


For example

  my.pkgs - c('pkg1', 'pkg2')  ## and so on for my preferred packages
  install.packages(my.pkgs, dependencies=TRUE)

Then after each upgrade just source the script.
You will need to create a second list if you use any packages for 
which binaries are not available.


Creating the list the first time might be inconvenient  but 
thereafter it's easy.


Additional benefits include
   you can use the script when you get a new machine
   you can use the script when a friend or colleague decides to try 
R, and you want them to have the same packages

   you can use the script if you maintain R on more than one platform, as I do

A downside would be if you have a huge number of packages and it 
takes a long time to update them all. But even then, since most 
packages are available as binaries, it should be reasonable. 
Installing a huge number from source will take a long time.


This method is also a little tricky if you have locally written packages.

-Don

At 10:02 PM -0400 8/27/08, James Milks wrote:
The title says it all.  Does anyone know of a way to save your 
packages when you upgrade to a new version of R?  This may seem 
petty, but I'm accumulating enough packages that having to download 
and install each of them anew every time I install a new version of 
R is rather of a pain.  Ideally, I would like the new version of R 
to recognize the packages I've installed on the previous version 
without needing to reinstall the packages.  Is that possible?


My system: Mac OS 10.5.4.
Current R version: 2.7.1

Thanks for any suggestions.  My apologies if this has been answered 
before and my search missed it.


Jim Milks

Degree Candidate

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



--
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 shading a polygon below a segment of a curve (normal distribution)

2008-08-28 Thread Greg Snow
The power.examp function in the TeachingDemos package (among others) may 
already do what you want.  Even if it does not, it does shade the area under a 
curve, you can look at the source for the function as an example of where to 
start.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111



 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Bertolt Meyer
 Sent: Thursday, August 28, 2008 8:03 AM
 To: r-help@r-project.org
 Subject: [R] Help with shading a polygon below a segment of a
 curve (normal distribution)

 Dear R users,

 I still feel new to R so please apologize if I am doing
 something stupid here. My use of the polygon() function
 produces a result that I cannot
 comprehend: In a plot, I would like to shade the area below a
 normal distribution. However, I do not want the entire area
 to be shaded, but just the area on the right side of a
 vertical line that I draw through the distribution (in order
 to illustrate the function of a t-test). Here is what I do:

 scale - 0.1
 x - seq(-4, 6, scale)
 y - dnorm(x)
 plot(x, y, type = l, main=t-Test, t = 2.2)

 linepos - 2.2
 abline(v = linepos)

 # I try to fill a polygon right of the vertical line:
 # max(x) - linepos (in this case, 2.2) / scale (0.1) #
 results in the last 38 elements of x and y.
 # so I take the last 38 elements of x and y and try to # draw
 a polygon underneath:

 cutpoint - (max(x) - linepos) / scale

 xt - x[(length(x)-cutpoint):length(x)]
 yt - y[(length(y)-cutpoint):length(y)]

 # draw the polygon

 polygon(xt, yt, density = 10 )

 As you can see in the result, this is not what I want; some
 area above the line gets shaded, but not below. Can someone
 tell me what I am missing?

 Thank you very much,
 Bertolt

 --
 Bertolt Meyer
 Oberassistent
 Sozialpsychologie, Psychologisches Institut der Universität
 Zürich Binzmühlestr. 14, Box 15 CH-8050 Zürich

 [EMAIL PROTECTED]
 tel:   +41446357282
 fax:   +41446357279
 mob:   +41788966111

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

2008-08-28 Thread Robert A LaBudde

At 04:12 AM 8/28/2008, ONKELINX, Thierry wrote:


On a windows machine you get the same problem. Useless one uses tha same
trick as Rolf suggested: don't install the packages in the default
directory and set R_LIBS to that directory. Then all you need to do
after an upgrade is to set R_LIBS in the new version and run
update.package(checkBuilt = TRUE). Given Rolf's suggestion I suppose
this trick will work on a Mac too.


What I do in installing a new version of R on a Windows system is as follows:

1. In the c:\Program Files\R folder, the installation is in a 
subfolder labeled by the version, such as R-2.7.1.


2. I leave the old (say, 2.7.1) version installed, and install the 
new version (say, 2.7.2). This leaves the old subfolder R-2.7.1 
intact, and creates a new one R-2.7.2.


3. I use a file-compare utility (in my case, Beyond Compare, which I 
recommend), to compare the subfolders C:\Program 
Files\R\R-2.7.1\library and C:\Program Files\R\R-2.7.2\library. I 
set the comparison to find files present or newer in the 2.7.1 folder 
vs. the 2.7.2. Then I copy all such files over.


4. At this point, the 2.7.2 has the same or new packages than 2.7.1, 
most or all of which will work.


5. I use the Packages|Update Package ... to update packages to 2.7.2.

6. Then I delete the 2.7.1 subfolder.

You need Administrator rights to do this.





Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: [EMAIL PROTECTED]
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947

Vere scire est per causas scire

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


Re: [R] RCurl: authentication when posting forms

2008-08-28 Thread Duncan Temple Lang



Hi Valerie

Valerie Obenchain wrote:

Hi,

Has anyone successfully used RCurl for posting data to a 
password-protected site? 


Yes. I just set up a sample form to test with and the following
all work


# Perl script (and HTML form for testing in the browser) taken from
#   http://www.elated.com/articles/form-validation-with-perl-and-cgi/


# Provide the login  password directly
postForm(http://www.omegahat.org/RCurl/testPassword/form_validation.cgi;,
   your_name = Duncan,
   your_age = 35-55,
   your_sex = m,
   submit = submit,
   .opts = list(userpwd = bob:welcome))

# Get the login  password in ~/.netrc
postForm(http://www.omegahat.org/RCurl/testPassword/form_validation.cgi;,
   your_name = Duncan,
   your_age = 35-55,
   your_sex = m,
   submit = submit,
  .opts = list(netrc = TRUE))

# Get the login  password from a different netrc file

postForm(http://www.omegahat.org/RCurl/testPassword/form_validation.cgi;,
   your_name = Duncan,
   your_age = 35-55,
   your_sex = m,
   submit = submit,
   .opts = list(netrc = TRUE,
netrc.file = 
/Users/duncan/Projects/org/omegahat/R/RCurl/inst/examples/omg.netrc))



So let me know what problems you are having and more details
about the OS, version of libcurl, and a sample URL to which
to post, etc.

  D.

I
have tired using option netrc=1 with both postForm and curlPerform (with 
postfields option) but can't authenticate.
I would happily provide more details if some one has had some experience 
with this.


Thanks very much.
Valerie

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

2008-08-28 Thread Dani Valverde

Hello,
I have a text file with this structure:

# File created = Thursday, August 28, 2008 3:33:02 PM GMT
# Data set = 373  2  1  C:\Bruker\TOPSPIN  GABRMN
# Spectral Region:
# LEFT = 4.5 ppm. RIGHT = 0.5 ppm.
#
# SIZE = 13111 ( = number of points)
#
# In the following ordering is from the 'left' to the 'right' limits!
# Lines beginning with '#' must be considered as comment lines.
#
1628.40625
1628.40625
1964.40625
2242.0625
2533.5
2937.90625
3448.0
3923.96875

Is it possible to read it with R, something like scan() but keeping the 
structure?

Best,

Dani

--
Daniel Valverde Saubí

Grup de Biologia Molecular de Llevats
Facultat de Veterinària de la Universitat Autònoma de Barcelona
Edifici V, Campus UAB
08193 Cerdanyola del Vallès- SPAIN

Centro de Investigación Biomédica en Red
en Bioingeniería, Biomateriales y
Nanomedicina (CIBER-BBN)

Grup d'Aplicacions Biomèdiques de la RMN
Facultat de Biociències
Universitat Autònoma de Barcelona
Edifici Cs, Campus UAB
08193 Cerdanyola del Vallès- SPAIN
+34 93 5814126

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Tidying up code - Warning message: deparse may be incomplete

2008-08-28 Thread Marie Pierre Sylvestre
Dear R users,

I am currently writing a R package and to do so I am following the
guidelines in manual 'Writing R extensions'.

In Section 3.1, it is suggested to tidy up the code using a file
containing the following:
options(keep.source = FALSE)
source(myfuns..R)
dump(ls(all = TRUE), file = new.myfuns.R)

I have done this for my own packages and although it runs, I get several
warnings of the type:

Warning message:
In dump(ls(all = TRUE), file = PermAlgo.R) : deparse may be incomplete

I am clueless as to what this means.

Even if I try to tidy only one function from my code, I get the warning.


E.g. the file lala.R contains only this:
partialHazards - function(t, v, covArray, betas){   exp( covArray[v,t,]
%*% betas ) }

the file tidylala.R contains:

options(keep.source = FALSE)
source(lala.R)
dump(ls(all = TRUE), file = newlala.R)

On Linux I run:

R --vanilla  tidylala.R  

Then I obtain:

Warning message:
In dump(ls(all = TRUE), file = newlala.R) : deparse may be incomplete

The file newlala.R looks like this:

`partialHazards` -
function (t, v, covArray, betas)
{
exp(covArray[v, t, ] %*% betas)
}

What does the warning mean? Can I simply ignore it?

thanks,

MP

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


Re: [R] juxtaposed and stacked bars in one barplot?

2008-08-28 Thread hadley wickham
On Thu, Aug 28, 2008 at 9:31 AM, Stefan Uhmann
[EMAIL PROTECTED] wrote:
 hadley wickham schrieb:

 Hi Stefan,

 Could you be a bit more explicit?  Do you have an example dataset that
 you are trying to visualise?


 Right, thanks for pointing out the obvious.

 So here's my code:


 library(gplots)

 quarter - as.factor(sample(c(Q1, Q2, Q3, Q4),
100, replace = TRUE))
 year - as.factor(sample(c(seq(from=2000, to=2008)), 100, replace = TRUE))
 category - as.factor(sample(c(seq(from=1, to=4)), 100, replace = TRUE))
 test - data.frame(quarter, year, category)
 table(test$category, test$quarter, test$year)
 barplot2(table(test$quarter, test$year),
beside=T, ylim=c(0,10), main=how to include dim3?)
 # inclusion of 3rd dimension does not work:
 barplot2(table(test$quarter, test$year, test$category),
beside=T, ylim=c(0,10), main=how to include dim3?)
 

 I want the barplot to be exactly the same but with the bars stacked (by
 'category'). I got the message from Gaspar, but have not yet tried to fit
 his example to my data.

Hi Stefan,

For your data, I'd suggest you consider using lines instead of bars.
http://peltiertech.com/WordPress/2008/08/27/stacked-vs-clustered/ has
some good reasons why. - but basically stacking makes it difficult to
see how each group changes over time.  It's pretty easy to play around
different variations with ggplot2, so I've included a few you might
want to look at.  (Including your original request right at the
bottom)

test - data.frame(quarter, year, category)
tabdf - as.data.frame(with(test, table(category, quarter, year)))

install.packages(ggplot2)
qplot(year, Freq, data=tabdf, geom=line, colour = category, facets =
 quarter ~ . , group = interaction(category, quarter))
# OR
qplot(year, Freq, data=tabdf, geom=line, colour = quarter, facets =
category ~ . , group = interaction(category, quarter))

# If you _really_ want stacking:

qplot(year, Freq, data=tabdf, geom=area, fill = quarter, facets =
category ~ . , group = interaction(category, quarter))

# OR

qplot(year, Freq, data=tabdf, geom=bar, stat=identity, fill =
quarter, facets =  category ~ .)

# OR finally, like what you originally asked for

qplot(quarter, Freq, data=tabdf, geom=bar, stat=identity, fill =
category, facets = . ~ year)


Regards,

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.


Re: [R] Tidying up code - Warning message: deparse may be incomplete

2008-08-28 Thread Duncan Murdoch

On 28/08/2008 10:46 AM, Marie Pierre Sylvestre wrote:

Dear R users,

I am currently writing a R package and to do so I am following the
guidelines in manual 'Writing R extensions'.

In Section 3.1, it is suggested to tidy up the code using a file
containing the following:
options(keep.source = FALSE)
source(myfuns..R)
dump(ls(all = TRUE), file = new.myfuns.R)

I have done this for my own packages and although it runs, I get several
warnings of the type:

Warning message:
In dump(ls(all = TRUE), file = PermAlgo.R) : deparse may be incomplete

I am clueless as to what this means.

Even if I try to tidy only one function from my code, I get the warning.


E.g. the file lala.R contains only this:
partialHazards - function(t, v, covArray, betas){   exp( covArray[v,t,]
%*% betas ) }

the file tidylala.R contains:

options(keep.source = FALSE)
source(lala.R)
dump(ls(all = TRUE), file = newlala.R)

On Linux I run:

R --vanilla  tidylala.R  


Then I obtain:

Warning message:
In dump(ls(all = TRUE), file = newlala.R) : deparse may be incomplete

The file newlala.R looks like this:

`partialHazards` -
function (t, v, covArray, betas)
{
exp(covArray[v, t, ] %*% betas)
}

What does the warning mean? Can I simply ignore it?


The warning means that you may have lost some information, i.e. sourcing 
newlala.R won't produce the same thing as sourcing lala.R.  I think in 
your case, there's no loss, so it's a bug, but I don't have time to 
track down why you're getting 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] Read a file

2008-08-28 Thread jim holtman
Is this what you want to do:

 x - scan('clipboard', what=, sep=\n)
Read 18 items
 x
 [1] # File created = Thursday, August 28, 2008 3:33:02 PM GMT
 [2] # Data set = 373  2  1  C:\\Bruker\\TOPSPIN  GABRMN
 [3] # Spectral Region:
 [4] # LEFT = 4.5 ppm. RIGHT = 0.5 ppm.
 [5] #
 [6] # SIZE = 13111 ( = number of points)
 [7] #
 [8] # In the following ordering is from the 'left' to the 'right' limits!
 [9] # Lines beginning with '#' must be considered as comment lines.
[10] #
[11] 1628.40625
[12] 1628.40625
[13] 1964.40625
[14] 2242.0625
[15] 2533.5
[16] 2937.90625
[17] 3448.0
[18] 3923.96875



On Thu, Aug 28, 2008 at 11:41 AM, Dani Valverde [EMAIL PROTECTED] wrote:
 Hello,
 I have a text file with this structure:

 # File created = Thursday, August 28, 2008 3:33:02 PM GMT
 # Data set = 373  2  1  C:\Bruker\TOPSPIN  GABRMN
 # Spectral Region:
 # LEFT = 4.5 ppm. RIGHT = 0.5 ppm.
 #
 # SIZE = 13111 ( = number of points)
 #
 # In the following ordering is from the 'left' to the 'right' limits!
 # Lines beginning with '#' must be considered as comment lines.
 #
 1628.40625
 1628.40625
 1964.40625
 2242.0625
 2533.5
 2937.90625
 3448.0
 3923.96875

 Is it possible to read it with R, something like scan() but keeping the
 structure?
 Best,

 Dani

 --
 Daniel Valverde Saubí

 Grup de Biologia Molecular de Llevats
 Facultat de Veterinària de la Universitat Autònoma de Barcelona
 Edifici V, Campus UAB
 08193 Cerdanyola del Vallès- SPAIN

 Centro de Investigación Biomédica en Red
 en Bioingeniería, Biomateriales y
 Nanomedicina (CIBER-BBN)

 Grup d'Aplicacions Biomèdiques de la RMN
 Facultat de Biociències
 Universitat Autònoma de Barcelona
 Edifici Cs, Campus UAB
 08193 Cerdanyola del Vallès- SPAIN
 +34 93 5814126

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

2008-08-28 Thread Henrique Dallazuanna
Try this:

x - readLines('clipboard')
newx - as.numeric(x[setdiff(seq(length(x)), grep(^#, x))])
comment(newx) - grep(^#, x, value = TRUE)
newx
comment(newx)

On Thu, Aug 28, 2008 at 12:41 PM, Dani Valverde [EMAIL PROTECTED]wrote:

 Hello,
 I have a text file with this structure:

 # File created = Thursday, August 28, 2008 3:33:02 PM GMT
 # Data set = 373  2  1  C:\Bruker\TOPSPIN  GABRMN
 # Spectral Region:
 # LEFT = 4.5 ppm. RIGHT = 0.5 ppm.
 #
 # SIZE = 13111 ( = number of points)
 #
 # In the following ordering is from the 'left' to the 'right' limits!
 # Lines beginning with '#' must be considered as comment lines.
 #
 1628.40625
 1628.40625
 1964.40625
 2242.0625
 2533.5
 2937.90625
 3448.0
 3923.96875

 Is it possible to read it with R, something like scan() but keeping the
 structure?
 Best,

 Dani

 --
 Daniel Valverde Saubí

 Grup de Biologia Molecular de Llevats
 Facultat de Veterinària de la Universitat Autònoma de Barcelona
 Edifici V, Campus UAB
 08193 Cerdanyola del Vallès- SPAIN

 Centro de Investigación Biomédica en Red
 en Bioingeniería, Biomateriales y
 Nanomedicina (CIBER-BBN)

 Grup d'Aplicacions Biomèdiques de la RMN
 Facultat de Biociències
 Universitat Autònoma de Barcelona
 Edifici Cs, Campus UAB
 08193 Cerdanyola del Vallès- SPAIN
 +34 93 5814126

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Maintaining repeated ID numbers when transposing with reshape

2008-08-28 Thread Adaikalavan Ramasamy
Not the prettiest code but it returns what you want. Might be slow for 
large dataframes.


df - data.frame( ID=c(1,1,1,1,2,2),
  TEST=c(A,A,B,C,B,B),
  RESULT=c(17,12,15,12,8,9) )


big.out - list(NULL)

for( uID in unique(df$ID) ){
 m - df[ df$ID == uID, , drop=FALSE ]
 run.order - unlist(sapply( table(m$TEST), function(x) if(x  0) 1:x) )
 m - cbind( m, run.order=run.order )

 nr - max(run.order)
 out - matrix( nr=nr, nc=nlevels(m$TEST),
dimnames=list( rep(uID, nr), levels(m$TEST) ))

 for(i in 1:nrow(m)) out[ m$run.order[i], m$TEST[i] ] - m$RESULT[i]
 big.out[[uID]] - out
}

do.call( rbind, big.out )

   A  B  C
1 17 15 12
1 12 NA NA
2 NA  8 NA
2 NA  9 NA


Regards, Adai


jcarmichael wrote:

Thank you for your suggestion, I will play around with it. I guess my concern
is that I need each test result to occupy its own cell rather than have
one or more in the same row.


Adaikalavan Ramasamy-2 wrote:
There might be a more elegant way of doing this but here is a way of 
doing it without reshape().


df - data.frame( ID=c(1,1,1,1,2,2),
  TEST=c(A,A,B,C,B,B),
  RESULT=c(17,12,15,12,8,9) )

df.s - split( df, df$ID )

out  - sapply( df.s, function(m)
tapply( m$RESULT, m$TEST, paste, collapse=, ) )

t(out)

  A   B C
1 17,12 15  12
2 NA  8,9 NA

Not the same output as you wanted. This makes more sense unless you have 
a reason to priotize 17 instead of 12 in the first row.


Regards, Adai


jcarmichael wrote:

I have a dataset in long format that looks something like this:

ID   TESTRESULT
1   A  17
1   A  12
1   B  15
1   C  12
2   B   8
2   B   9

Now what I would like to do is transpose it like so:

IDTEST ATEST BTEST C
1 17   15  12
1 12..
2  . 8.
2  . 9.

When I try:

reshape(mydata, v.names=result, idvar=id,timevar=test,
direction=wide)

It gives me only the first occurrence of each test for each subject.  How
can I transpose my dataset in this way without losing information about
repeated tests?

Any help or guidance would be appreciated!  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.






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


Re: [R] Cluster

2008-08-28 Thread Adaikalavan Ramasamy
Try reading help(hclust) and help(matplot) and run the examples given in 
the documentation. If that doesn't work, try posting again with a simple 
reproducible example.


Regards, Adai



Marco Chiapello wrote:

Hi all,
I'm trying to do a cluster analysis,but I don't know if it's possible in
the way that I want.
I have a data set like the follow:
115/114 
 116/114 
 117/114 
0.45

0.72
0.41
1.16
0.63
0.91
0.42
0.94
0.61
My real data set is, just a bit bigger, 610 entries.
I want plot each row on the same graph, like a line (see the attach
file). Then if it's possible I want perform a cluster analysis. The
final perfect result would be a graph with many lines, with the cluster
line in the same color.
Any advice?
Marco




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

2008-08-28 Thread markleeds
this is for the person who asked me about prediction confidence 
intervals in a GLM because I lost your email. Below follows a simple 
example in CAR and the variance covariance of the beta coefficients is 
in the summary. So, I think, given that output,  it should be pretty 
straightforward to do what you want. I also bet that code for what you 
want to do is in some function in John's effects package but I haven't 
looked at the code. If it's not possible to find it in John's code, ( I 
think prediction intervals have an extra term in the formula for the CI 
because of the error term variance )  that formula should be in any 
decent regression text book.  Good luck.



#

attach(Mroz)
model.mroz-glm(lfp ~ k5 + k618 + age + wc + hc + lwg + inc, 
family=binomial)


print(model.mroz)

modsumm-summary(model.mroz)
print(modsumm)

print(str(modsumm))

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


Re: [R] Linear model with one known coordinate

2008-08-28 Thread Philipp Pagel
 I have a set of points (measurements) and I used lm() to obtain their linear
 regression model. From the biological background this line must pass through
 a point (100,0). Our dataset is not optimal and it shows a slight deviation
 from that coordinate. How can I add the restraint to the model, to go
 through that point?

You can do that with offset(). There is an example in the manual page
for glm.

cu
Philipp

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

2008-08-28 Thread stephen sefick
WHAT is this in reguard too?

On Thu, Aug 28, 2008 at 12:56 PM, Ajay ohri [EMAIL PROTECTED] wrote:
 For the record,

 I*  *
 **
 *am not and have never been an employee of World Programming Ltd and that
 the postings and views expressed in these communities and forums have been
 motivated by my own personal thoughts and sentiments*
 **
 In addition ,

 I am not and never have been an employee of SAS Institute and R -Project.

 Grow up fellows.

 Ajay

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




-- 
Stephen Sefick
Research Scientist
Southeastern Natural Sciences Academy

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

-K. Mullis

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


Re: [R] svymeans question

2008-08-28 Thread Thomas Lumley


Other people have explained that the issue is missing data.  I just wanted 
to note that the reason for using only the complete cases on all variables 
is that svymeans() computes the covariance matrix of all the means, and 
this can't really be done sensibly when the means are based on different 
subsets.


-thomas


On Tue, 26 Aug 2008, Doran, Harold wrote:


I have the following code which produces the output below it

clus1 - svydesign(ids = ~schid, data = lower_dat)
items -  as.formula(paste( ~ , paste(lset, collapse= +)))
rr1 - svymean(items, clus1, deff='replace', na.rm=TRUE)


rr1

   mean   SE   DEff
W525209 0.719748 0.015606 2.4932
W525223 0.508228 0.027570 6.2802
W525035 0.827202 0.014060 2.8561
W525131 0.805421 0.015425 3.1350
W525033 0.242982 0.020074 4.5239
W525163 0.904647 0.013905 4.6289
W525165 0.439981 0.020029 3.3620
W525167 0.148112 0.013047 2.7860
W525177 0.865924 0.014977 3.9898
W525179 0.409003 0.020956 3.7515
W525181 0.634076 0.022076 4.3372
W525183 0.242498 0.019073 4.0894
W525401 0.262343 0.021830 3.4354
W525059 0.854792 0.016551 4.5576
W525251 0.691191 0.025010 6.0512
W525083 0.433204 0.017310 2.5200
W525289 0.634560 0.012762 1.4504
W524763 0.791868 0.014478 2.6265
W524765 0.223621 0.019627 4.5818
W524951 0.242982 0.016796 3.1669
W524769 0.820910 0.016786 3.9579
W524771 0.872701 0.015853 4.6712
W524839 0.518877 0.026433 5.7794
W525374 1.209584 0.043065 5.1572
W524885 0.585673 0.027780 6.5674
W525377 1.100678 0.050093 5.8851
W524787 0.839303 0.012994 2.5852
W524789 0.339787 0.019230 3.4041
W524791 0.847047 0.012885 2.6461
W524825 0.500968 0.021988 3.9935
W524795 0.868345 0.014951 4.0377
W524895 0.864472 0.013872 3.3917
W524897 0.804937 0.020070 5.2977
W524967 0.475799 0.032137 8.5511
W525009 0.681994 0.018670 3.3188

However, when I do the following:

svymean(~W524787, clus1, deff='replace', na.rm=TRUE)
   mean   SE   DEff
W524787 0.855547 0.011365 4.1158

Compare this to the value in the row 9 up from the bottom to see it is
different.

Computing the mean of the item by itself with svymeans agrees with the
sample mean


mean(lower_dat$W524787, na.rm=T)

[1] 0.8555471

Now, I know that there is a covariance between the variables, but I was
under the impression that the sample mean was still of pragmatic
utility, but to account for sample design only the standard error is
affected.

In the work I am doing, it is important for the means of the items from
svymeans to be the same as the sample mean when it is computed by
itself. It's a bit of a story as to why, and I can provide that info if
relevant.

I don't see an argument in svydesign or in svymean that would allow for
me to treat the variables as being independent. But, maybe I am missing
something else and would welcome any reactions.

Harold

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



Thomas Lumley   Assoc. Professor, Biostatistics
[EMAIL PROTECTED]   University of Washington, Seattle

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


Re: [R] sample consecutive integers efficiently

2008-08-28 Thread Charles C. Berry

On Thu, 28 Aug 2008, Chris Oldmeadow wrote:


Hi all,

I have some rough code to sample consecutive integers with length according 
to a vector of lengths


#sample space (representing positions)
pos-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)

#sample lengths
lengths-c(2,3,2)

From these two vectors I need a vector of sampled positions.


the sampling is without replacement, making things tough as the sampled 
integers need to be consecutive. Im hoping somebody knows a faster way of 
doing it than I have. ATM its way to slow on large vectors.



samplePos-function(l){
   start.pos-sample(pos,1)
   end.pos-start.pos+l-1
   posies-start.pos:end.pos
   posies
}

s.start-c()


newPos-function(a){
   rp-samplePos(a)
   #test sampled range is consecutive, if not resample
   if (length(rp) != rp[a]+1 -rp[1]){rp-samplePos(a)}
   pos-setdiff(pos,rp)
   rp[1]
}

newps-c()
newps-unlist(lapply(lengths,newPos))

I think the bottleneck may be on the setdiff() function - the sample space is 
quite large so I dont think there would be too many rejections.



The bottleneck is in the formulation of the sampling scheme.

This is a simple combinatorics problem. There are 3360 possible values ( 
prod(16:14) ) for the start positions of the three elements, and you can 
form a bijection between 1:3360 and the individual samples. If the number 
of possible sample is small enough, it would be most efficient to sample 
from the corresponding integer vector and then translate it to the 
corresponding sample. For larger values where the number of possible 
samples become a challenge for 32-bit integer arithmetic, I expect this 
approach would be preferred:


Permute length ( pos ) - sum ( lengths ) + length( lengths ) distinct 
(consecutively labelled) elements:


elz - sample( length ( pos ) - sum ( lengths ) + length( lengths ) )


Take the lengths of the original objects to be

z.lens - rep( 1, length( elz ) )
z.lens[ seq(along = lengths ) ] - lengths

(i.e. objects longer than 1 appear first)

Determine the start positions of the objects as if they were laid down 
consecutively according to the permutation:


start - head( cumsum( c(0, z.lens[ elz ]) ) + 1 , -1 )

Find the start positions of just those with lengths greater than 1

gt.1 - match( seq(along=lengths) , elz )

Report the start positions

start[ gt.1 ]

---

If length( pos ) is large, you can rewrite the above to simply sample 
the positions (in the ordering) of the objects with lengths greater than 
1. You will have to revise the calculation of start and gt.1 in that case.


HTH,

Chuck


 



Many thanks,
Chris

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



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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

2008-08-28 Thread rkevinburton
Why does:

(shape/scale) * (1:365/scale)^(shape - 1)

return a vector of numbers but calling a function

hasard(1:365,shape,scale)

defined like:

hazard - function(x,shape,scale)
{
   return (shape/scale) * (x/scale)^(shape - 1)
}

Only return a single value? It is like x becomes a single value passed as an 
argument.

Thank you.

Kevin

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


Re: [R] Survey Design / Rake questions

2008-08-28 Thread Thomas Lumley

On Mon, 25 Aug 2008, Farley, Robert wrote:


I see a number of things that bother me.
 1) str(ByEBNum$StnTraveld) says int [1:12] 1 2 3 4 5 6 7 8 9 10 ...
Even though StnTraveld  - c(as.factor(1:12))


You don't want the c()

a-as.factor(1:12)
str(a)

 Factor w/ 12 levels 1,2,3,4,..: 1 2 3 4 5 6 7 8 9 10 ...

str(c(a))

 int [1:12] 1 2 3 4 5 6 7 8 9 10 ...

As the help for c() says  all attributes except names are removed., 
which includes the factor levels.



 2) ByEBOn$StnName[1:5] seems to imply I have extra spaces in the data.  Where 
would they have come from?


No, that's just R printing things in columns

a-factor(1:12, labels=c(1:11,antidisestablishmentarianism))
a

 [1] 12
 [3] 34
 [5] 56
 [7] 78
 [9] 910
[11] 11   antidisestablishmentarianism
Levels: 1 2 3 4 5 6 7 8 9 10 11 antidisestablishmentarianism


 3) I'd like to verify that the order (value) of EBSurvey$lineon 
matches my definition in StnName


all(levels(EBSurvey$lineon)==StnName)

-thomas



Thanks for helping...


***
***

library(survey)
SurveyData - read.spss(C:/Data/R/orange_delivery.sav, use.value.labels=TRUE, 
max.value.labels=Inf, to.data.frame=TRUE)
#===
temp - sub(' +$', '', SurveyData$direction_)
SurveyData$direction_ - temp
#===
SurveyData$NumStn=abs(as.numeric(SurveyData$lineon)-as.numeric(SurveyData$lineoff))
mean(SurveyData$NumStn)

[1] 6.785276

### Kludge
SurveyData$NumStn - pmax(1,SurveyData$NumStn)
mean(SurveyData$NumStn)

[1] 6.789877

SurveyData$NumStn - as.factor(SurveyData$NumStn)
###
EBSurvey - subset(SurveyData, direction_ == EASTBOUND )
XTTable - xtabs(~direction_ , EBSurvey)
XTTable

direction_
EASTBOUND
 345

WBSurvey - subset(SurveyData, direction_ == WESTBOUND )
XTTable - xtabs(~direction_ , WBSurvey)
XTTable

direction_
WESTBOUND
 307

#
EBDesign - svydesign(id=~sampn, weights=~expwgt, data=EBSurvey)
#   svytable(~lineon+lineoff, EBDesign)
StnName - c( Warner Center, De Soto, Pierce College, Tampa, Reseda, Balboa, Woodley, Sepulveda, Van 
Nuys, Woodman, Valley College, Laurel Canyon, North Hollywood)
EBOnNewTots - c(1000,   600, 1200, 500, 
1000,  500,   200, 250,   1000,   300,  100,   
   123.65,0 )
StnTraveld  - c(as.factor(1:12))
EBNumStn- c(673.65, 800, 1000, 1000,  800,  700,  600, 500, 400, 200,  
50, 50 )
ByEBOn  - data.frame(StnName,   Freq=EBOnNewTots)
ByEBNum - data.frame(StnTraveld, Freq=EBNumStn)
RakedEBSurvey - rake(EBDesign, list(~lineon, ~NumStn), list(ByEBOn, ByEBNum) )

Error in postStratify.survey.design(design, strata[[i]], 
population.margins[[i]],  :
 Stratifying variables don't match


str(EBSurvey$lineon)

Factor w/ 13 levels Warner Center,..: 3 1 1 1 2 13 1 5 1 5 ...

EBSurvey$lineon[1:5]

[1] Pierce College Warner Center  Warner Center  Warner Center  De Soto
13 Levels: Warner Center De Soto Pierce College Tampa Reseda Balboa ... North 
Hollywood

str(ByEBOn$StnName)

Factor w/ 13 levels Balboa,De Soto,..: 11 2 5 8 6 1 12 7 10 13 ...

ByEBOn$StnName[1:5]

[1] Warner Center  De SotoPierce College Tampa  Reseda
13 Levels: Balboa De Soto Laurel Canyon North Hollywood ... Woodman


str(EBSurvey$NumStn)

Factor w/ 12 levels 1,2,3,4,..: 10 12 4 12 8 1 8 8 12 4 ...

EBSurvey$NumStn[1:5]

[1] 10 12 4  12 8
Levels: 1 2 3 4 5 6 7 8 9 10 11 12

str(ByEBNum$StnTraveld)

int [1:12] 1 2 3 4 5 6 7 8 9 10 ...

ByEBNum$StnTraveld[1:5]

[1] 1 2 3 4 5





Robert Farley
Metro
www.Metro.net


-Original Message-
From: Thomas Lumley [mailto:[EMAIL PROTECTED]
Sent: Saturday, August 23, 2008 09:38
To: Farley, Robert
Cc: r-help@r-project.org
Subject: Re: [R] Survey Design / Rake questions

On Fri, 22 Aug 2008, Farley, Robert wrote:


I *think* I'm making progress, but I'm still failing at the same step.  My rake 
call fails with:
Error in postStratify.survey.design(design, strata[[i]], 
population.margins[[i]],  :
 Stratifying variables don't match

To my naïve eyes, it seems that my factors are in the wrong order.  If so,
how do I assert an ordering in my survey dataframe, or copy an image from
the survey dataframe to my marginals dataframes?  I'd prefer to pull the
original marginals dataframe(s) from the survey dataframe so that I can
automate that in production.


It looks like a problem with the NumStn factor. One copy has been converted to 

Re: [R] Function not returning a vector?

2008-08-28 Thread Jeff Laake

Try

hazard - function(x,shape,scale)
{
  return ((shape/scale) * (x/scale)^(shape - 1))
}
hazard(1:365,1,1)

--jeff

[EMAIL PROTECTED] wrote:

Why does:

(shape/scale) * (1:365/scale)^(shape - 1)

return a vector of numbers but calling a function

hasard(1:365,shape,scale)

defined like:

hazard - function(x,shape,scale)
{
   return (shape/scale) * (x/scale)^(shape - 1)
}

Only return a single value? It is like x becomes a single value passed as an 
argument.

Thank you.

Kevin

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

2008-08-28 Thread Barry Rowlingson
2008/8/28  [EMAIL PROTECTED]:

 hazard - function(x,shape,scale)
 {
   return (shape/scale) * (x/scale)^(shape - 1)
 }

 Only return a single value? It is like x becomes a single value passed as an 
 argument.


 It's evaluating return(shape/scale) and returning that! Add some
extra parentheses:

 return( (shape/scale) * (x/scale)^(shape-1) )

 seems to work. Are you a python programmer, perhaps?

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] Function not returning a vector?

2008-08-28 Thread Peter Dalgaard

[EMAIL PROTECTED] wrote:

Why does:

(shape/scale) * (1:365/scale)^(shape - 1)

return a vector of numbers but calling a function

hasard(1:365,shape,scale)

defined like:

hazard - function(x,shape,scale)
{
   return (shape/scale) * (x/scale)^(shape - 1)
}

Only return a single value? It is like x becomes a single value passed as an 
argument.

  
No, but return is syntactically like a function name. Watch your 
parentheses


--
  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] Function not returning a vector?

2008-08-28 Thread Mark Lyman
 rkevinburton at charter.net writes:

 
 Why does:
 
 (shape/scale) * (1:365/scale)^(shape - 1)
 
 return a vector of numbers but calling a function
 
 hasard(1:365,shape,scale)
 
 defined like:
 
 hazard - function(x,shape,scale)
 {
return (shape/scale) * (x/scale)^(shape - 1)
 }
 
 Only return a single value? It is like x becomes a single value passed as an 
argument.
 

I believe you have a couple of typos. Your function is returning shape/scale 
only. Try:

hazard - function(x,shape,scale)
{
 return ((shape/scale) * (x/scale)^(shape - 1))
}

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


Re: [R] Function not returning a vector?

2008-08-28 Thread Achim Zeileis



On Thu, 28 Aug 2008, [EMAIL PROTECTED] wrote:


Why does:

(shape/scale) * (1:365/scale)^(shape - 1)

return a vector of numbers but calling a function

hasard(1:365,shape,scale)

defined like:

hazard - function(x,shape,scale)
{
  return (shape/scale) * (x/scale)^(shape - 1)



return() is a function, its argument is returned, everything afterwards is 
ignored. And shape/scalar is probably a scalar in your case...


So either change to

return((shape/scale) * (x/scale)^(shape - 1))

or simply

   (shape/scale) * (x/scale)^(shape - 1)

without explicitely calling return().


}

Only return a single value? It is like x becomes a single value passed as an 
argument.

Thank you.

Kevin

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

2008-08-28 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of 
 [EMAIL PROTECTED]
 Sent: Thursday, August 28, 2008 11:36 AM
 To: r-help@r-project.org
 Subject: [R] Function not returning a vector?
 
 Why does:
 
 (shape/scale) * (1:365/scale)^(shape - 1)
 
 return a vector of numbers but calling a function
 
 hasard(1:365,shape,scale)
 
 defined like:
 
 hazard - function(x,shape,scale)
 {
return (shape/scale) * (x/scale)^(shape - 1)
 }
 
 Only return a single value? It is like x becomes a single 
 value passed as an argument.
 
 Thank you.
 
 Kevin
 

Change your function definition to one of the following (I don't know which is 
better).

hazard - function(x,shape,scale)
{  
   return( (shape/scale) * (x/scale)^(shape - 1) )
}

hazard - function(x,shape,scale)
{
   (shape/scale) * (x/scale)^(shape - 1)
}

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204
 
 

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

2008-08-28 Thread Van Patten, Isaac T
Is there an R function to generate a radar or spider graph from a table
- e.g.radar(table(x)) or some such?

 

==

Isaac T. Van Patten, Ph.D.

Professor 

Department of Criminal Justice

Box 6934, Radford University

Radford, VA 24142

540-831-6148

[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] 

http://ivanpatt.asp.radford.edu http://ivanpatt.asp.radford.edu  

 

 

The hottest places in hell are reserved for those who, in time of great
moral crisis, maintain their neutrality. -Dante Alighieri

 


[[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] Spider Graph

2008-08-28 Thread Sarah Goslee
help.search(radar)
and
help.search(spider)
would both get you right to
stars()

Sarah

On Thu, Aug 28, 2008 at 3:00 PM, Van Patten, Isaac T
[EMAIL PROTECTED] wrote:
 Is there an R function to generate a radar or spider graph from a table
 - e.g.radar(table(x)) or some such?



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

2008-08-28 Thread Henrik Bengtsson
On Thu, Aug 28, 2008 at 10:42 AM, stephen sefick [EMAIL PROTECTED] wrote:
 WHAT is this in reguard too?

It seems to be a message from another universe (SAS something) -
maybe a wormhole?  Are we not alone?

/H


 On Thu, Aug 28, 2008 at 12:56 PM, Ajay ohri [EMAIL PROTECTED] wrote:
 For the record,

 I*  *
 **
 *am not and have never been an employee of World Programming Ltd and that
 the postings and views expressed in these communities and forums have been
 motivated by my own personal thoughts and sentiments*
 **
 In addition ,

 I am not and never have been an employee of SAS Institute and R -Project.

 Grow up fellows.

 Ajay

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




 --
 Stephen Sefick
 Research Scientist
 Southeastern Natural Sciences Academy

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

-K. Mullis

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] hex2RGB back to hex not the same?

2008-08-28 Thread Aaron Mackey
Witness this oddity (to me):

 rainbow_hcl(10)[1]
[1] #E18E9E
 d - attributes(hex2RGB(rainbow_hcl(10)))$coords[1,]
 rgb(d[1], d[2], d[3])
[1] #C54D5F

What happened?  FYI, this came up as I'm trying to reuse the RGB values I
get from rainbow_hcl in a call to rgb() where I can also set alpha
transparency levels ...

-Aaron

[[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] error in packet 1

2008-08-28 Thread Deepayan Sarkar
On Thu, Aug 28, 2008 at 3:07 AM, Giovanni Tarquinio
[EMAIL PROTECTED] wrote:
 Hello,
 I'm Giovanni from ROMA..

 I can't find a solution for the error:

 error using packet 1
 the y field is not specified and it has not a default value
 (this is my traslation from italian language)

 The code is:

 pc-qqmath(~valori,
distribution=function(p) qweibull(p,beta,alpha),
prepanel = prepanel.qqmathline,
panel = function(x, y) {
 panel.grid()
 panel.qqmathline(y, distribution = function(p)
 qweibull(p,beta,alpha))
 panel.qqmath(x, y)
   },
layout = c( 1,1), aspect = 0.8,
xlab = Unit Weibull Quantile, ylab = D
)

Here's a hint:

 args(panel.qqmath)
function (x, f.value = NULL, distribution = qnorm, qtype = 7,
groups = NULL, ...)

panel.qqmath() does not have a 'y' argument, which should tell you
that qqmath() does not pass a 'y' argument to its panel function.

-Deepayan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] drop.unused.levels for two factors {lattice}

2008-08-28 Thread Dylan Beaudette
Hi,

Is there any way to suppress plotting of panels that don't actually contain 
any information? I have tried using 'drop.unused.levels=TRUE', but there 
doesn't seem to be any effect. Here is an example:

library(lattice)

# some fake data:
d - data.frame(x=runif(20), x.class=rep(letters[1:5], each=4),  
f1=rep(letters[1:2], each=10), f2=rep(letters[10:19], each=2) )

# plot it:
dotplot(x.class ~ x | f1 + f2, data=d, scales=list(relation='free'))

Thanks,

Dylan

-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Interaction between aggregate() and length()

2008-08-28 Thread Seeliger . Curt
Folks,

I've been running into an odd situation that occurs when I use length() 
function with aggregate(), but not with either one separately.  Together, 
the results looks correct but is given an unexpected name. 'if 
(stringsAsFactors) factor(x) else x' instead of just 'x'.

# Numbers work ok
tt - data.frame(idx=c(1,1,1,1,1,1,2,2,2,2,2,2)
,n=c(1,3,5,7,5,5,2,4,8,16,4,4)
,t=c(1,3,5,7,5,5,2,4,8,16,4,4)
,stringsAsFactors=FALSE)

aggregate(tt$t, list('idx'=tt$idx), length)
aggregate(as.factor(tt$t), list('idx'=tt$idx), length)

# Character data doesn't work right unless I convert the data to factors.
tt - data.frame(idx=c(1,1,1,1,1,1,2,2,2,2,2,2)
,n=c('1','3','5','7','5','5','2','4','8','16','4','4')
,t=c('1','3','5','7','5','5','2','4','8','16','4','4')
,stringsAsFactors=FALSE)

aggregate(tt$t, list('idx'=tt$idx), length)
aggregate(as.factor(tt$t), list('idx'=tt$idx), length)


Any idea what is going on here?  For the record, this also happens with 
the modalvalue() function defined at 
http://wiki.r-project.org/rwiki/doku.php?id=tips:stats-basic:modalvalue 
(which also relies on length() ).

As a side note, this began as an attempt to determine sample size, for 
which I've defined a function count - function(x) { length(na.omit(x)) }. 
 No doubt there's a built in function to do just that, but as a newbie 
I've yet to find it.

Thank you for your help,
cur
-- 
Curt Seeliger, Data Ranger
Raytheon Information Services - Contractor to ORD
[EMAIL PROTECTED]
541/754-4638

[[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] hex2RGB back to hex not the same?

2008-08-28 Thread Deepayan Sarkar
On Thu, Aug 28, 2008 at 1:07 PM, Aaron Mackey [EMAIL PROTECTED] wrote:
 Witness this oddity (to me):

 rainbow_hcl(10)[1]
 [1] #E18E9E
 d - attributes(hex2RGB(rainbow_hcl(10)))$coords[1,]
 rgb(d[1], d[2], d[3])
 [1] #C54D5F

 What happened?  FYI, this came up as I'm trying to reuse the RGB values I
 get from rainbow_hcl in a call to rgb() where I can also set alpha
 transparency levels ...

 d - coords(hex2RGB(#E18E9E, gamma=NA))
 rgb(d[,1], d[,2], d[,3])
[1] #E18E9E

Another alternative is

 d - col2rgb(#E18E9E) / 255
 rgb(d[1,], d[2,], d[3,])
[1] #E18E9E

-Deepayan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] USING TOBIT OR WHAT ALTERNATIVE WHEN DATA ARE PANEL AND HETEROSKEDASTIC AND PROBABLY AUTOCORRELATED?

2008-08-28 Thread Adrienne Kandel

Please, I seek expertise and advice, possibly leads to R packages or
stats literature.
My data: measurements of economic variables for each county of
California over 37 years. 
My dependent variable is square feet of office floor space permitted to
be added in a county.  
Independent variables include for example change in number of office
jobs in same county same year (and lagged years).  
Smaller (less populous) counties have many years in which there were no
permits taken out; the largest counties had at least some permitted
square footage each year.  Among the set of years and places where
permits were taken out,  smaller counties tend to more permitted square
footage per capita.  I imagine the relationships are as follows:
y* = desired change in floor space = X b + e , where X are independent
variables and b their coefficients, and e is heteroskedastic (by state)
and possibly autocorrelated noise.  e is the sort of noise you’d expect
on a time series of cross sections, no sampling (one observation for
every county for every year studied).  I must include fixed county
effects (county dummies) in X because I will need them for
county-specific forecasts later.
y = permits taken out
y = y* when y*  0
y = 0 when y* = 0
y never has been observed  = 0 when population  pop*
How do folks recommend that I estimate this regression?  I could first
estimate the probability of having any permits given level of population
and change in office jobs.  That could include a deterministic
component: if population  pop* then y = y*.  I could try a tobit-2
model  or its ML estimator, which I see have just been developed in an R
package called “sampleSelection.”  But in that case, I have I would
guess in my ignorance that I’m way biased because it assumes specific
error distributions and that they are homoskedastic.  (I could transform
the data in advance to get homoskedasticity if necessary).  I could make
an instrument for probability(y*0) and multiply that by each
observation of permits, avoiding distributional assumptions in e (but
not in prob(y*0)), but would that give me really high variance?  (And
is there an easier way to find variance than algebraically figuring out
Newey West estimator for 2-stage method of moments procedures and how it
applies here?)  I know nothing of the non- and semi-parametric options
here but does someone had an article or book chapter telling that’s the
right thing to do and how?   It would be most convenient for me to use R
but I also have access to STATA and SAS.
Now another question for the statistically-minded:  After running this
regression I will forecast for each region how many square feet of
office space will have permits taken out for it each year, given
expected trends on office jobs and such.  This does not allow each
individual county to have a different type of response to office jobs,
assuming the office job coefficient is pooled.  Please be encouraged to
comment on these options I am considering to allow more variation:
County-specific coefficients don’t work well; I tried separate
(admittedly OLS) regressions for each county and found that with only 35
or so observations per county, my variances were too large and
coefficients were insignificant and often of unintuitive signs.
Random coefficients won’t give me county specific info, which I’ll need
for the forecasts.
So is this idea good?  After I have coefficients from the pooled
regression above, I take each coefficient b and its standard error.  I
use that as a stochastic restriction or Bayesian prior, for individual
county regressions.  That is, each county regression estimates its own b
value, but subject to the stochastic restriction or Bayesian prior that
b is in fact the pooled b, with the distribution of said prior being
that b’s variance is the variance we estimated in the pooled regression.
 (I’m thinking of what has been called Bayesian/Mixed Estimation here,
but if I’m out of the loop on newer better techniques, do tell.)  I’d
think this county-specific estimation would be a simple non-tobit
regression for  large counties that never lack additions in any year. 
For small counties, I might need to do a tobit-style or instrumental
variable regression again (or whatever you folks recommend).  It might
be harder to estimate probability of nonzero permits on the smaller
sample size so I might have to keep the old estimate.

All thoughts are welcome and appreciated.  Thanks very very much.
 

[[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] drop.unused.levels for two factors {lattice}

2008-08-28 Thread Deepayan Sarkar
On Thu, Aug 28, 2008 at 1:21 PM, Dylan Beaudette
[EMAIL PROTECTED] wrote:
 Hi,

 Is there any way to suppress plotting of panels that don't actually contain
 any information? I have tried using 'drop.unused.levels=TRUE', but there
 doesn't seem to be any effect. Here is an example:

 library(lattice)

 # some fake data:
 d - data.frame(x=runif(20), x.class=rep(letters[1:5], each=4),
 f1=rep(letters[1:2], each=10), f2=rep(letters[10:19], each=2) )

 # plot it:
 dotplot(x.class ~ x | f1 + f2, data=d, scales=list(relation='free'))

No, you can only drop factor levels that are unused (anywhere). Try

 dotplot(x.class ~ x | f1:f2, data=d, scales=list(relation='free'))

You can use 'layout' and 'skip' to get to a layout similar to your
original call, if you need to.

-Deepayan

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


Re: [R] Interaction between aggregate() and length()

2008-08-28 Thread Henrique Dallazuanna
One option is use this:

aggregate(list(t=tt$t), list(idx=tt$idx), length)

On Thu, Aug 28, 2008 at 4:36 PM, [EMAIL PROTECTED] wrote:

 Folks,

 I've been running into an odd situation that occurs when I use length()
 function with aggregate(), but not with either one separately.  Together,
 the results looks correct but is given an unexpected name. 'if
 (stringsAsFactors) factor(x) else x' instead of just 'x'.

 # Numbers work ok
 tt - data.frame(idx=c(1,1,1,1,1,1,2,2,2,2,2,2)
,n=c(1,3,5,7,5,5,2,4,8,16,4,4)
,t=c(1,3,5,7,5,5,2,4,8,16,4,4)
,stringsAsFactors=FALSE)

 aggregate(tt$t, list('idx'=tt$idx), length)
 aggregate(as.factor(tt$t), list('idx'=tt$idx), length)

 # Character data doesn't work right unless I convert the data to factors.
 tt - data.frame(idx=c(1,1,1,1,1,1,2,2,2,2,2,2)
,n=c('1','3','5','7','5','5','2','4','8','16','4','4')
,t=c('1','3','5','7','5','5','2','4','8','16','4','4')
,stringsAsFactors=FALSE)

 aggregate(tt$t, list('idx'=tt$idx), length)
 aggregate(as.factor(tt$t), list('idx'=tt$idx), length)


 Any idea what is going on here?  For the record, this also happens with
 the modalvalue() function defined at
 http://wiki.r-project.org/rwiki/doku.php?id=tips:stats-basic:modalvalue
 (which also relies on length() ).

 As a side note, this began as an attempt to determine sample size, for
 which I've defined a function count - function(x) { length(na.omit(x)) }.
  No doubt there's a built in function to do just that, but as a newbie
 I've yet to find it.

 Thank you for your help,
 cur
 --
 Curt Seeliger, Data Ranger
 Raytheon Information Services - Contractor to ORD
 [EMAIL PROTECTED]
 541/754-4638

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




-- 
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] drop.unused.levels for two factors {lattice}

2008-08-28 Thread Dylan Beaudette
On Thursday 28 August 2008, Deepayan Sarkar wrote:
 On Thu, Aug 28, 2008 at 1:21 PM, Dylan Beaudette

 [EMAIL PROTECTED] wrote:
  Hi,
 
  Is there any way to suppress plotting of panels that don't actually
  contain any information? I have tried using 'drop.unused.levels=TRUE',
  but there doesn't seem to be any effect. Here is an example:
 
  library(lattice)
 
  # some fake data:
  d - data.frame(x=runif(20), x.class=rep(letters[1:5], each=4),
  f1=rep(letters[1:2], each=10), f2=rep(letters[10:19], each=2) )
 
  # plot it:
  dotplot(x.class ~ x | f1 + f2, data=d, scales=list(relation='free'))

 No, you can only drop factor levels that are unused (anywhere). Try

  dotplot(x.class ~ x | f1:f2, data=d, scales=list(relation='free'))

 You can use 'layout' and 'skip' to get to a layout similar to your
 original call, if you need to.

 -Deepayan

Thanks! that did the trick.

Dylan

-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341

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


Re: [R] Interaction between aggregate() and length()

2008-08-28 Thread Seeliger . Curt
That's a great work around, as I can eliminate renaming the results column 
from 'x' to whatever.  Thanks for the quick tip, Henrique.

On the other hand, I'm still stumped as to why aggregate() would name an 
output column as 'if (stringsAsFactors) factor(x) else x'.  That sort of 
behaviour seems to contrdict the principle of least astonishment.

Enjoy your days,
cur

Henrique Dallazuanna [EMAIL PROTECTED] wrote on 08/28/2008 01:52:03 PM:

 One option is use this:
 
 aggregate(list(t=tt$t), list(idx=tt$idx), length)

 On Thu, Aug 28, 2008 at 4:36 PM, [EMAIL PROTECTED] wrote:
 Folks,
 
 I've been running into an odd situation that occurs when I use length()
 function with aggregate(), but not with either one separately. Together,
 the results looks correct but is given an unexpected name. 'if
 (stringsAsFactors) factor(x) else x' instead of just 'x'.
 
 # Numbers work ok
 tt - data.frame(idx=c(1,1,1,1,1,1,2,2,2,2,2,2)
,n=c(1,3,5,7,5,5,2,4,8,16,4,4)
,t=c(1,3,5,7,5,5,2,4,8,16,4,4)
,stringsAsFactors=FALSE)
 
 aggregate(tt$t, list('idx'=tt$idx), length)
 aggregate(as.factor(tt$t), list('idx'=tt$idx), length)
 
 # Character data doesn't work right unless I convert the data to 
factors.
 tt - data.frame(idx=c(1,1,1,1,1,1,2,2,2,2,2,2)
,n=c('1','3','5','7','5','5','2','4','8','16','4','4')
,t=c('1','3','5','7','5','5','2','4','8','16','4','4')
,stringsAsFactors=FALSE)
 
 aggregate(tt$t, list('idx'=tt$idx), length)
 aggregate(as.factor(tt$t), list('idx'=tt$idx), length)
 
 
 Any idea what is going on here?  For the record, this also happens with
 the modalvalue() function defined at
 http://wiki.r-project.org/rwiki/doku.php?id=tips:stats-basic:modalvalue
 (which also relies on length() ).
 
 As a side note, this began as an attempt to determine sample size, for
 which I've defined a function count - function(x) { length(na.omit(x)) 
}.
  No doubt there's a built in function to do just that, but as a newbie
 I've yet to find it.
 
 Thank you for your help,
 cur


-- 
Curt Seeliger, Data Ranger
Raytheon Information Services - Contractor to ORD
[EMAIL PROTECTED]
541/754-4638
[[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] RCurl: authentication when posting forms

2008-08-28 Thread Valerie Obenchain

Duncan,

Thank you for the examples.  I had tried all of these different options 
for authentication but had no luck. I was getting a 100 continue and 
then a 401 unauthorized response.  This morning the owners of the 
server I was trying to access discovered a bug with their api when using 
basic authorization. Evidently the code on their side was explicitly 
checking that the request method was GET, hence why all of my POST 
attempts were failing. They are in the process of fixing that code and 
my guess is that when I am able to try again the RCurl post functions 
will work just fine.


I did have one other RCurl question I'd like to ask you about the 
parseHTTPHeader function.


The parser appears to parse on spaces, so when the error message is more 
than one word (eg, not found), the message returned is not. I have 
modified the parseHTTPHeader function so that it works for me. I may not 
have done this in the most efficient way but at least you can see what I 
was trying to do.


Below I have pasted my modification for the parseHTTPHeader function 
which I am calling parseHeader. Please let me know if you think this is 
a bug or if I am just using the function incorrectly.


Thank you for the help.
Valerie

#---
#Sample code:
reader - basicTextGatherer()
header - basicTextGatherer()
handle - getCurlHandle()
myopts - curlOptions(  netrc=1, httpheader=c(Authorization=mypwd, 
Accept=test/xml,
  Accept=multipart/*, 
'Content-Type'=text/xml; charset=utf-8),
  postfields=body, 
writefunction=reader$update, headerfunction=header$update,
  ssl.verifyhost=FALSE, 
ssl.verifypeer=FALSE, followlocation=TRUE)} else


curlPerform(url=myUrl, .opts=myopts, curl=handle)
h - parseHeader(header$value())
status - h$status
message - h$statusMessage
#

#Modified parse function:
parseHeader - function (lines)
{
  if (length(lines)  1)
  return(NULL)
  if (length(lines) == 1)
  lines = strsplit(lines, \r\n)[[1]]
  status = lines[1]
  lines = lines[-c(1, length(lines))]
  lines = gsub(\r\n, , lines)
  if (FALSE) {
  header = lines[-1]
  header - read.dcf(textConnection(header))
  }
  else {
  els - sapply(lines, function(x) strsplit(x, :[ ]*))
  header - lapply(els, function(x) x[2])
  names(header) - sapply(els, function(x) x[1])
  }
  els - strsplit(status,  )[[1]]
  header[[status]] - as.integer(els[2])
# new code below
  hstring - NULL
  for(i in 3:length(els)) hstring - paste(hstring, ,els[i],sep=)
  hstring - substr(hstring,2,nchar(hstring))
  header[[statusMessage]] - hstring
  header
}












Duncan Temple Lang wrote:



Hi Valerie

Valerie Obenchain wrote:

Hi,

Has anyone successfully used RCurl for posting data to a 
password-protected site? 


Yes. I just set up a sample form to test with and the following
all work


# Perl script (and HTML form for testing in the browser) taken from
#   http://www.elated.com/articles/form-validation-with-perl-and-cgi/


# Provide the login  password directly
postForm(http://www.omegahat.org/RCurl/testPassword/form_validation.cgi;, 


   your_name = Duncan,
   your_age = 35-55,
   your_sex = m,
   submit = submit,
   .opts = list(userpwd = bob:welcome))

# Get the login  password in ~/.netrc
postForm(http://www.omegahat.org/RCurl/testPassword/form_validation.cgi;, 


   your_name = Duncan,
   your_age = 35-55,
   your_sex = m,
   submit = submit,
  .opts = list(netrc = TRUE))

# Get the login  password from a different netrc file

postForm(http://www.omegahat.org/RCurl/testPassword/form_validation.cgi;, 


   your_name = Duncan,
   your_age = 35-55,
   your_sex = m,
   submit = submit,
   .opts = list(netrc = TRUE,
netrc.file = 
/Users/duncan/Projects/org/omegahat/R/RCurl/inst/examples/omg.netrc))



So let me know what problems you are having and more details
about the OS, version of libcurl, and a sample URL to which
to post, etc.

  D.

I
have tired using option netrc=1 with both postForm and curlPerform 
(with postfields option) but can't authenticate.
I would happily provide more details if some one has had some 
experience with this.


Thanks very much.
Valerie

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

[R] Adjusting for initial status (intercept) in lme growth models

2008-08-28 Thread D Chaws
Hi everyone, I have a quick and probably easy question about lme for this
list.

Say, for instance you want to model growth in pituitary distance  as a
function of age in the Orthodont dataset.

fm1 = lme(distance ~ I(age-8), random = ~ 1 + I(age-8) | Subject, data =
Orthodont)

You notice that there is substantial variability in the intercepts (initial
distance) for people at 8 years, and that
this variability in initial distance is related to growth over time:

R# summary(fm1)
...
Random effects:
 Formula: ~1 + I(age - 8) | Subject
 Structure: General positive-definite, Log-Cholesky parametrization
StdDev Corr
(Intercept) 1.8866 (Intr)
I(age - 8)  0.2264 0.209
Residual1.3100

Now 2 questions:

1.  With lme, how can you get a fit of the growth model accounting for the
relationship between initial status (intercept) and growth?
Some texts call this latent variable regression or something or other, which
seems to basically boil down to adding the random effects
intercept as a predictor in the growth model.  Is this done in lme by simply
adding the intercept results from ranef(fm1) to the model?
This two-step process seems wrong to me for some reason, perhaps because it
seems too simple.  Anyone know the proper way to do
in lme?

2.  In addition, suppose you see that there are significant differences in
initial status by Sex:

fm2 = lme(distance ~ I(age-8) + Sex, random = ~ 1 + I(age-8) | Subject, data
= Orthodont)

R# summary(fm2)
Fixed effects: distance ~ I(age - 8) + Sex
 Value Std.Error DF t-value p-value
(Intercept) 22.9170.5134 80   44.64   0.000
I(age - 8)   0.6600.0713 809.27   0.000
SexFemale   -2.1450.7575 25   -2.83   0.009

Along the lines of question #1, how would you get a growth model adjusting
for these Sex differences in initial status?  I am looking for something
similar to adjusting for baseline differences between Sexes in ANCOVA.  I
know Lord would not approve, but this is just by way of example...  Thanks
so much for your help, and this wonderful program Dr. Bates.

- DC

[[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] abline of an lm fit not correct

2008-08-28 Thread stephen sefick
mac osx 10.5.4
R 2.7.1

I have fit a model
d-lm(y~x)

with an R^2 of 0.963
but when I issue the command
abline(d)
the line is below where it ought to be.  Looks like the right slope,
but not the right intercept.
thanks

-- 
Stephen Sefick
Research Scientist
Southeastern Natural Sciences Academy

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

-K. Mullis

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


Re: [R] abline of an lm fit not correct

2008-08-28 Thread stephen sefick
sorry idiotic question- you have to make sure you are using the right
things before you start ploting

On Thu, Aug 28, 2008 at 7:54 PM, stephen sefick [EMAIL PROTECTED] wrote:
 mac osx 10.5.4
 R 2.7.1

 I have fit a model
 d-lm(y~x)

 with an R^2 of 0.963
 but when I issue the command
 abline(d)
 the line is below where it ought to be.  Looks like the right slope,
 but not the right intercept.
 thanks

 --
 Stephen Sefick
 Research Scientist
 Southeastern Natural Sciences Academy

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

-K. Mullis




-- 
Stephen Sefick
Research Scientist
Southeastern Natural Sciences Academy

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

-K. Mullis

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


Re: [R] sample consecutive integers efficiently

2008-08-28 Thread Chris Oldmeadow



Charles C. Berry wrote:

On Thu, 28 Aug 2008, Chris Oldmeadow wrote:


Hi all,

I have some rough code to sample consecutive integers with length 
according to a vector of lengths


#sample space (representing positions)
pos-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)

#sample lengths
lengths-c(2,3,2)

From these two vectors I need a vector of sampled positions.


the sampling is without replacement, making things tough as the 
sampled integers need to be consecutive. Im hoping somebody knows a 
faster way of doing it than I have. ATM its way to slow on large 
vectors.



samplePos-function(l){
   start.pos-sample(pos,1)
   end.pos-start.pos+l-1
   posies-start.pos:end.pos
   posies
}

s.start-c()


newPos-function(a){
   rp-samplePos(a)
   #test sampled range is consecutive, if not resample
   if (length(rp) != rp[a]+1 -rp[1]){rp-samplePos(a)}
   pos-setdiff(pos,rp)
   rp[1]
}

newps-c()
newps-unlist(lapply(lengths,newPos))

I think the bottleneck may be on the setdiff() function - the sample 
space is quite large so I dont think there would be too many rejections.



The bottleneck is in the formulation of the sampling scheme.

This is a simple combinatorics problem. There are 3360 possible values 
( prod(16:14) ) for the start positions of the three elements, and you 
can form a bijection between 1:3360 and the individual samples. If the 
number of possible sample is small enough, it would be most efficient 
to sample from the corresponding integer vector and then translate it 
to the corresponding sample. For larger values where the number of 
possible samples become a challenge for 32-bit integer arithmetic, I 
expect this approach would be preferred:


Permute length ( pos ) - sum ( lengths ) + length( lengths ) distinct 
(consecutively labelled) elements:


elz - sample( length ( pos ) - sum ( lengths ) + length( lengths ) )


Take the lengths of the original objects to be

z.lens - rep( 1, length( elz ) )
z.lens[ seq(along = lengths ) ] - lengths

(i.e. objects longer than 1 appear first)

Determine the start positions of the objects as if they were laid down 
consecutively according to the permutation:


start - head( cumsum( c(0, z.lens[ elz ]) ) + 1 , -1 )

Find the start positions of just those with lengths greater than 1

gt.1 - match( seq(along=lengths) , elz )

Report the start positions

start[ gt.1 ]

---

If length( pos ) is large, you can rewrite the above to simply sample 
the positions (in the ordering) of the objects with lengths greater 
than 1. You will have to revise the calculation of start and gt.1 in 
that case.


HTH,

Chuck


 



Many thanks,
Chris

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

and provide commented, minimal, self-contained, reproducible code.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive 
Medicine

E mailto:[EMAIL PROTECTED]UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 
92093-0901






Thanks! that worked perfectly.

Chris

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


Re: [R] RCurl: authentication when posting forms

2008-08-28 Thread Duncan Temple Lang
Valerie Obenchain wrote:
 Duncan,
 
 Thank you for the examples.  I had tried all of these different options 
 for authentication but had no luck. I was getting a 100 continue and 
 then a 401 unauthorized response.  This morning the owners of the 
 server I was trying to access discovered a bug with their api when using 
 basic authorization. Evidently the code on their side was explicitly 
 checking that the request method was GET, hence why all of my POST 
 attempts were failing. They are in the process of fixing that code and 
 my guess is that when I am able to try again the RCurl post functions 
 will work just fine.

Thanks for the update.  Good to know that there isn't a problem
with the libcurl/RCurl code.

 
 I did have one other RCurl question I'd like to ask you about the 
 parseHTTPHeader function.
 
 The parser appears to parse on spaces, so when the error message is more 
 than one word (eg, not found), the message returned is not. I have 
 modified the parseHTTPHeader function so that it works for me. I may not 
 have done this in the most efficient way but at least you can see what I 
 was trying to do.


Yes, this is a problem. Thanks for bringing it to my attention.
I did get your mail directly to me from about 2 weeks ago 
and I replied. Perhaps my reply got eaten by your filters.
In it, I said that it was a bug, and that it would be
very useful if you could send me an RCurl command
that illustrated the error so that I could add it to the RCurl
tests.
 

The only modification that can make your patch slightly
better is that the words in the statusMessage are essentially
all the words in the status variable, less the first two
(the status number and the protocol name). So

 header[[statusMessage]] - paste(els[-c(1,2)], collapse =  )

is more convenient than

  hstring - NULL
  for(i in 3:length(els)) hstring - paste(hstring, ,els[i],sep=)
  hstring - substr(hstring,2,nchar(hstring))
  header[[statusMessage]] - hstring


If you do have a URL that I can use to test the error handling code, I'd 
appreciate
if you could send it to me.  


 D.

 
 Below I have pasted my modification for the parseHTTPHeader function 
 which I am calling parseHeader. Please let me know if you think this is 
 a bug or if I am just using the function incorrectly.
 
 Thank you for the help.
 Valerie
 
 #---
 #Sample code:
 reader - basicTextGatherer()
 header - basicTextGatherer()
 handle - getCurlHandle()
 myopts - curlOptions(  netrc=1, httpheader=c(Authorization=mypwd, 
 Accept=test/xml,
   Accept=multipart/*, 
 'Content-Type'=text/xml; charset=utf-8),
   postfields=body, 
 writefunction=reader$update, headerfunction=header$update,
   ssl.verifyhost=FALSE, 
 ssl.verifypeer=FALSE, followlocation=TRUE)} else
 
 curlPerform(url=myUrl, .opts=myopts, curl=handle)
 h - parseHeader(header$value())
 status - h$status
 message - h$statusMessage
 #
 
 #Modified parse function:
 parseHeader - function (lines)
 {
   if (length(lines)  1)
   return(NULL)
   if (length(lines) == 1)
   lines = strsplit(lines, \r\n)[[1]]
   status = lines[1]
   lines = lines[-c(1, length(lines))]
   lines = gsub(\r\n, , lines)
   if (FALSE) {
   header = lines[-1]
   header - read.dcf(textConnection(header))
   }
   else {
   els - sapply(lines, function(x) strsplit(x, :[ ]*))
   header - lapply(els, function(x) x[2])
   names(header) - sapply(els, function(x) x[1])
   }
   els - strsplit(status,  )[[1]]
   header[[status]] - as.integer(els[2])
 # new code below
   hstring - NULL
   for(i in 3:length(els)) hstring - paste(hstring, ,els[i],sep=)
   hstring - substr(hstring,2,nchar(hstring))
   header[[statusMessage]] - hstring
   header
 }
 
 
 
 
 
 
 
 
 
 
 
 
 Duncan Temple Lang wrote:
 
 
 Hi Valerie
 
 Valerie Obenchain wrote:
 Hi,
 
 Has anyone successfully used RCurl for posting data to a 
 password-protected site? 
 
 Yes. I just set up a sample form to test with and the following
 all work
 
 
 # Perl script (and HTML form for testing in the browser) taken from
 #   http://www.elated.com/articles/form-validation-with-perl-and-cgi/
 
 
 # Provide the login  password directly
 postForm(http://www.omegahat.org/RCurl/testPassword/form_validation.cgi;, 
 
your_name = Duncan,
your_age = 35-55,
your_sex = m,
submit = submit,
.opts = list(userpwd = bob:welcome))
 
 # Get the login  password in ~/.netrc
 postForm(http://www.omegahat.org/RCurl/testPassword/form_validation.cgi;, 
 
your_name = Duncan,
your_age = 35-55,
your_sex = m,
submit = submit,
   .opts = list(netrc = TRUE))
 
 # Get the login  password from a different netrc file
 
 

[R] Newbie: Examples on functions callling a library etc.

2008-08-28 Thread Eduardo M. A. M.Mendes
Hello

 

R is pretty new to me. I need to write a function that returns three
matrices of different dimensions.  In addition, I need to call a function
from a contributed package with the function.   I have browsed several
manuals and docs but the examples on them are either very simple or
extremely hard to follow.

 

Many thanks

 

Ed

 

 

 


[[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] Survey Design / Rake questions

2008-08-28 Thread Farley, Robert
I'm feeling like I just don't get it.  My attempt at rake now fails
with:
Error in postStratify.survey.design(design, strata[[i]],
population.margins[[i]],  : 
  Stratifying variables don't match

The factors in the data frame looks fine.  Should I have the same
structure in the design?
 str(EBDesign$lineon)
 NULL
 str(EBSurvey$lineon)
 Factor w/ 13 levels Warner Center,..: 3 1 1 1 2 13 1 5 1 5 ...
 str(ByEBOn$StnName)
 Factor w/ 13 levels Balboa,De Soto,..: 11 2 5 8 6 1 12 7 10 13 ...
 all(levels(EBSurvey$lineon)==StnName)
[1] TRUE
 #
 str(EBDesign$NumStn)
 NULL
 str(EBSurvey$NumStn)
 Factor w/ 12 levels 1,2,3,4,..: 10 12 4 12 8 1 8 8 12 4 ...
 str(ByEBNum$StnTraveld)
 Factor w/ 12 levels 1,2,3,4,..: 1 2 3 4 5 6 7 8 9 10 ...
 all(levels(EBSurvey$NumStn)==StnTraveld)
[1] TRUE

A complete listing is below:
**
**
**
 sessionInfo()# List loaded packages
R version 2.7.2 (2008-08-25) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

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


other attached packages:
[1] survey_3.8-1   fortunes_1.3-5 moonsun_0.1prettyR_1.3-2
foreign_0.8-29
 SurveyData - read.spss(C:/Data/R/orange_delivery.sav,
use.value.labels=TRUE, max.value.labels=Inf, to.data.frame=TRUE)

#===

 temp - sub(' +$', '', SurveyData$direction_) 
 SurveyData$direction_ - temp

#===

 # Calc. # stations traversed from StnOn/StnOff

SurveyData$NumStn=abs(as.numeric(SurveyData$lineon)-as.numeric(SurveyDat
a$lineoff))
  Kludge
 mean(SurveyData$NumStn)
[1] 6.785276
 SurveyData$NumStn - pmax(1,SurveyData$NumStn)
 mean(SurveyData$NumStn)
[1] 6.789877
 
 SurveyData$NumStn - as.factor(SurveyData$NumStn)

#===

 # Adjust one direction at a time.  Start W/ EB {learn subsetting
later}
 EBSurvey - subset(SurveyData, direction_ == EASTBOUND )
 EBDesign - svydesign(id=~sampn, weights=~expwgt, data=EBSurvey)

#===

 # New Marignals {start w/ 2 dimensions: StnOn X Distance}   
 StnName - as.factor(c( Warner Center, De Soto, Pierce College,
Tampa, Reseda, Balboa, Woodley, Sepulveda, Van Nuys,
Woodman, Valley College, Laurel Canyon, North Hollywood))
 EBOnNewTots   - c(1000,   600, 1200,
500, 1000,  500,   200, 250,   1000,   300,
100,  123.65,0 )
 ByEBOn  - data.frame(StnName, Freq=EBOnNewTots)
 #
 StnTraveld - as.factor(1:12)
 EBNumStn   - c(673.65, 800, 1000, 1000,  800,  700,  600, 500,
400, 200,  50, 50 )
 ByEBNum- data.frame(StnTraveld, Freq=EBNumStn)
 #
 RakedEBSurvey - rake(EBDesign, list(~lineon, ~NumStn), list(ByEBOn,
ByEBNum) )
Error in postStratify.survey.design(design, strata[[i]],
population.margins[[i]],  : 
  Stratifying variables don't match
 #
 str(EBDesign$lineon)
 NULL
 str(EBSurvey$lineon)
 Factor w/ 13 levels Warner Center,..: 3 1 1 1 2 13 1 5 1 5 ...
 str(ByEBOn$StnName)
 Factor w/ 13 levels Balboa,De Soto,..: 11 2 5 8 6 1 12 7 10 13 ...
 all(levels(EBSurvey$lineon)==StnName)
[1] TRUE
 #
 str(EBDesign$NumStn)
 NULL
 str(EBSurvey$NumStn)
 Factor w/ 12 levels 1,2,3,4,..: 10 12 4 12 8 1 8 8 12 4 ...
 str(ByEBNum$StnTraveld)
 Factor w/ 12 levels 1,2,3,4,..: 1 2 3 4 5 6 7 8 9 10 ...
 all(levels(EBSurvey$NumStn)==StnTraveld)
[1] TRUE
 #
**
**
**

Robert Farley
Metro
www.Metro.net 


-Original Message-
From: Thomas Lumley [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 28, 2008 11:43
To: Farley, Robert
Cc: r-help@r-project.org
Subject: Re: [R] Survey Design / Rake questions

On Mon, 25 Aug 2008, Farley, Robert wrote:

 I see a number of things that bother me.
  1) str(ByEBNum$StnTraveld) says int [1:12] 1 2 3 4 5 6 7 8 9 10 ...
 Even though StnTraveld  - c(as.factor(1:12))

You don't want the c()
 a-as.factor(1:12)
 str(a)
  Factor w/ 12 levels 1,2,3,4,..: 1 2 3 4 5 6 7 8 9 10 ...
 str(c(a))
  int [1:12] 1 2 3 4 5 6 7 8 9 10 ...

As the help for c() says  all attributes except names are removed., 
which includes the factor levels.

  2) ByEBOn$StnName[1:5] seems to imply I have extra spaces in the
data.  Where would they have come from?

No, that's just R printing things in columns
 a-factor(1:12, 

[R] lost attrubute:names

2008-08-28 Thread Yuan Jian
Hi,
when I pick out one element from a matrix, the attribute name is kept, but when
more than one elements are extracted, the attribute name lost;
 
a-matrix(c(1,2,3,11,12,13,45,56,76),ncol=3,dimnames=list(c(),c(c1,c2,c3)))
 k-a[a[,c3]50,c3]
 kk-a[a[,c3]60,c3]
 attributes(k)
NULL
 attributes(kk)
$names
[1] c3
 
 
YU


  
[[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] lost attrubute:names

2008-08-28 Thread Charles C. Berry

On Thu, 28 Aug 2008, Yuan Jian wrote:


Hi,
when I pick out one element from a matrix, the attribute name is kept, but when
more than one elements are extracted, the attribute name lost;


To what attribute 'name' do you refer?

I only see 'dim' and 'dimnames' attributes:


attributes(a)

$dim
[1] 3 3

$dimnames
$dimnames[[1]]
NULL

$dimnames[[2]]
[1] c1 c2 c3





?

a-matrix(c(1,2,3,11,12,13,45,56,76),ncol=3,dimnames=list(c(),c(c1,c2,c3)))
k-a[a[,c3]50,c3]
kk-a[a[,c3]60,c3]
attributes(k)

NULL

attributes(kk)

$names
[1] c3
?


Try attributes(a[a[,c3]50,c3, drop = FALSE ] ).

Try adding rownames to 'a', and see what happens to the attributes of each 
of the above forms.


[ merely tries to do something reasonable.

Why do you think k should have any attributes, and what names do you think 
k should have???


HTH,

Chuck


?
YU



[[alternative HTML version deleted]]




Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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: Examples on functions callling a library etc.

2008-08-28 Thread Ben Bolker
Eduardo M. A. M.Mendes emammendes at gmail.com writes:

 R is pretty new to me. I need to write a function that returns three
 matrices of different dimensions.  In addition, I need to call a function
 from a contributed package with the function.   I have browsed several
 manuals and docs but the examples on them are either very simple or
 extremely hard to follow.
 
 Many thanks
 
 Ed
 

  I think you need to try to specify your needs a little bit
more carefully.  Here is a function that technically meets
your needs:

library(example_pkg)  ## to load the contributed package
myfunction - function() {  ## function with no arguments
   foo()## assuming the function foo is in the package
   list(matrix(nrow=2,ncol=2),matrix(nrow=3,ncol=3),matrix(nrow=4,ncol=4)
}

  But I suspect that doesn't really do what you need ...

  Ben Bolker

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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: Examples on functions callling a library etc.

2008-08-28 Thread Steven McKinney

Hi Ed, 

Here's a simple example showing your needs:


myfun - function(n1, n2, n3) {
  mat1 - matrix(rep(1), nrow = n1, ncol = 3)
  mat2 - matrix(rep(2), nrow = n2, ncol = 4)
  mat3 - matrix(rep(3), nrow = n3, ncol = 5)

  require(survival) ## make sure the package you need is loaded
  mypkgfun - survival::is.Surv ## Use the '::' and ':::' extractors to get 
visible and hidden functions respectively from the package

  list(mat1 = mat1, mat2 = mat2, mat3 = mat3, mypkgfun = mypkgfun) ## Return 
the items in a list
}

## Now invoke the function
foo - myfun(n1 = 1, n2 = 1, n3 = 5)

## and look at the returned results
foo

 myfun - function(n1, n2, n3) {
+   mat1 - matrix(rep(1), nrow = n1, ncol = 3)
+   mat2 - matrix(rep(2), nrow = n2, ncol = 4)
+   mat3 - matrix(rep(3), nrow = n3, ncol = 5)
+ 
+   require(survival)
+   mypkgfun - survival::is.Surv
+ 
+   list(mat1 = mat1, mat2 = mat2, mat3 = mat3, mypkgfun = mypkgfun)
+ }
 
 foo - myfun(n1 = 1, n2 = 1, n3 = 5)
 
 foo
$mat1
 [,1] [,2] [,3]
[1,]111

$mat2
 [,1] [,2] [,3] [,4]
[1,]2222

$mat3
 [,1] [,2] [,3] [,4] [,5]
[1,]33333
[2,]33333
[3,]33333
[4,]33333
[5,]33333

$mypkgfun
function (x) 
inherits(x, Surv)
environment: namespace:survival

 

HTH

Steve McKinney


-Original Message-
From: [EMAIL PROTECTED] on behalf of Eduardo M. A. M.Mendes
Sent: Thu 8/28/2008 5:43 PM
To: r-help@r-project.org
Subject: [R] Newbie:  Examples on functions callling a library etc.
 
Hello

 

R is pretty new to me. I need to write a function that returns three
matrices of different dimensions.  In addition, I need to call a function
from a contributed package with the function.   I have browsed several
manuals and docs but the examples on them are either very simple or
extremely hard to follow.

 

Many thanks

 

Ed

 

 

 


[[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] extract variance components

2008-08-28 Thread huang min
HI,

I would like to extract the variance components estimation in lme function
like

a.fit-lme(distance~age, data=aaa, random=~day/subject)

There should be three variances \sigma_day, \sigma_{day %in% subject } and
\sigma_e.

I can extract the \sigma_e using something like a.fit$var. However, I cannot
manage to extract the first two variance components. I can only see the
results in summary(a.fit).

I have some problem in the lme4 package and hence use the nlme package. The
example data also has some problem so I just list the function here using
some imaginary data set. Thank you.

Huang

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


  1   2   >