[R] Problems with bilinear interpolation of a grid

2009-06-21 Thread Andrew Aldersley

Dear all,

I'm having trouble interpolating a number of gridded datasets that I have. I'm 
quite new to R so any help/advice that can be offered would be much appreciated!

Firstly I'll describe my dataset. The data is a grid of the planet at 1 degree 
spatial resolution, with each grid cell containing a value describing a 
particular variable (e.g. population density) for coordinate pairs. The 
dimensions of the grid are 360col x 180row. The x-coordinates of the values 
within the grid are longitudes (from -179.5(W) to 179.5(E)) and the 
y-coordinates of the grid values are latitudes (from 89.5(N) to -89.5(S)).

What I want to do is convert this 1 degree dataset to a finer resolution of 0.5 
degrees, thereby quadrupling the number of cells within the frame (i.e. convert 
to 720 x 360 grid). I wish to have longitudinal values ranging from -179.75 to 
179.75 and latitudinal values from 89.75 to -89.75. I selected the 
'interp.surface' function in the 'fields' package to do this as it provides 
bilinear interpolation from one grid to another. I have written the following 
code to try and carry out my interpolation...

 library(fields)

 x.mat - sprintf(%.2f, seq(from = -179.5, to = 179.5, length=360))  # 
 longitude grid values
 y.mat - sprintf(%.2f, seq(from = 89.5, to = -89.5, length=180))  # 
 latitude grid values
 z.mat - read.table(BF_200501.txt, colClasses=numeric)  # dataset
 z.mat - data.matrix(z.mat)
 obj - list(x=x.mat, y=y.mat, z=z.mat)

#Setting up new grid
 a.mat - sprintf(%.2f, seq(from = -179.75, to = 179.75, length = 720))  # 
 longitude grid values
 b.mat - sprintf(%.2f, seq(from = 89.75, to = -89.75, length = 360))  # 
 latitude grid values
 loc - make.surface.grid(list(x=a.mat, y=b.mat))

#Interpolation
 new - interp.surface(obj, loc)

However I get the following error message:
Error in x.new - min(x) : non-numeric argument to binary operator

Can anyone explain what this error message means and why I am getting it? Or 
are there other more effective ways to perform the interpolation on this sort 
of dataset? Like I said I'm new to R so any advice will be gratefully received.

Many thanks,

Andy




_
[[elided Hotmail spam]]

[[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] Warning messages when using rbind

2009-06-21 Thread baptiste auguie

Hi,


You seem to have a glitch in one file,

testread12=read.table(Test100.txt, head = T)
str(testread12) # Column131 is converted to a factor
# $ Column131: Factor w/ 2920 levels --,-0.000122393,..

combining the second data set with this one will convert the new data 
into factor for this column but some (most) levels were not present in 
the first file.


HTH,

baptiste

gug wrote:

Hello,

I have been using a very simple rbind approach (simple enough for me to
understand) to combine data files within R.

It seems to work fine, but then generates warning messages for reasons that
I can't begin to understand.  The text below shows the issue.  


testread12=read.table(C:/Files/Test100.txt, head = T)
testread11=read.table(C:/Files/Test101.txt, head = T)
testbind1=rbind(testread12,testread11)
testbind2=rbind(testread11,testread12)

The testrbind1 line generates the following message:

Warning message:
In `[-.factor`(`*tmp*`, ri, value = c(0.00557998, -0.058016069,  :
  invalid factor level, NAs generated

However the testrbind2 line works fine.  Although the data in the files is
different, the format (columns, etc) should be identical.  The fact that it
works in one order, but not the other, makes it very difficult for me to
understand what the problem is.

Files attached.  Any suggestions gratefully received.  Thanks,

Guy Green
http://www.nabble.com/file/p24130996/Test101.txt Test101.txt 
http://www.nabble.com/file/p24130996/Test100.txt Test100.txt 
  



--
_

Baptiste Auguié

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

Phone: +44 1392 264187

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

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


[R] Help on qpcR package

2009-06-21 Thread Endy BlackEndy
I am using R on a Windows XP professional platform.
  The following code is part of a bigger one
 CODE
  press=function(y,x){
   library(qpcR)
   models.press=numeric(0)
   cat(\n)
   dep=y
  print(dep)
   indep=log(x)
  print(indep)
   yfit=dep-PRESS(lm(dep~indep))[[2]]
  cat(\n yfit\n)
  print(yfit)
   yfit.orig=yfit
   presid=y-yfit.orig
   press=sum(presid^2)
   cat(\n)
   cat(PRESS =,press,\n)
  }
  On the command R window I define

- Ignored:

 x=c(12,24,13,11,23,10,9,17,11,14,18)
 y=c(10,11,9,8,5,12,11,21,12,13,14)

  then I load the press source code, I run it using the x and y values
  defined before
  and I get the following

 press(x,y)
  Loading required package: drc
  Loading required package: alr3
  Loading required package: lattice
  Loading required package: magic
  Loading required package: abind
  Loading required package: MASS
  Loading required package: nlme
  Loading required package: plotrix

  'drc' has been loaded.

  Please cite R and 'drc' if used for a publication,
  for references type 'citation()' and 'citation('drc')'.

  Loading required package: gtools
  Loading required package: gplots
  Loading required package: gdata
  Loading required package: caTools
  Loading required package: bitops
  Loading required package: grid

  Attaching package: 'gplots'


  The following object(s) are masked from package:plotrix :

   plotCI


  The following object(s) are masked from package:stats :

   lowess


  'qpcR' has been loaded.

  Please cite R and the following if used for a publication:

  Spiess AN, Feig C, Ritz
  Highly accurate sigmoidal fitting of real-time PCR data by introducing
  a parameter for asymmetry.
  BMC Bioinformatics 2008, 29:221
  or
  Ritz C, Spiess AN. qpcR: an R package for sigmoidal model selection in
  quantitative real-time polymerase chain reaction analysis.
  Bioinformatics 2008, 24:1549-1551

  Newest version always available at www.dr-spiess.de/qpcR.html.


  Attaching package: 'qpcR'


  The following object(s) are masked from package:gplots :

   residplot


   [1] 12 24 13 11 23 10  9 17 11 14 18
   [1] 2.302585 2.397895 2.197225 2.079442 1.609438 2.484907 2.397895
  3.044522 2.484907 2.564949 2.639057
  Error in get(noquote(a)) : object 'dep' not found

  The error reported, as I understand it, is that the object dep it is
  not defined. Obviously, at least to me, it is defined.

  If I declare the dep and indep objects on the command R window i. e.

   dep=y
   indep=x

  and rerun the programme  then it runs correctly and gives

   press(x,y)

   [1] 12 24 13 11 23 10  9 17 11 14 18
   [1] 2.302585 2.397895 2.197225 2.079442 1.609438 2.484907 2.397895
  3.044522 2.484907 2.564949 2.639057

   yfit
   [1] 13.764062 24.199292 15.804140 15.192045 32.465326  9.547579
  9.845243  6.176015 10.521896 12.325493 14.931854

  PRESS = 248.7043

Can anybody point out what's the problem?
  Thanks in advance
  K. Karakostas

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


Re: [R] Problems with bilinear interpolation of a grid

2009-06-21 Thread David Winsemius
Both from the code and the error message it appears that you are  
creating character matrices and unrealistically expecting a function  
designed for numeric input to accept those as arguments.


?sprintf

It appears you are hoping that sprintf gets you something you desire,  
but to my eyes it looks entirely troublesome in this application. You  
should be able to report which line of code is provoking the error.  
I'm guessing it is:

loc - make.surface.grid(list(x=a.mat, y=b.mat))


What happens when you just use numeric arguments?


--
David.


On Jun 21, 2009, at 1:33 PM, Andrew Aldersley wrote:



Dear all,

I'm having trouble interpolating a number of gridded datasets that I  
have. I'm quite new to R so any help/advice that can be offered  
would be much appreciated!


Firstly I'll describe my dataset. The data is a grid of the planet  
at 1 degree spatial resolution, with each grid cell containing a  
value describing a particular variable (e.g. population density) for  
coordinate pairs. The dimensions of the grid are 360col x 180row.  
The x-coordinates of the values within the grid are longitudes (from  
-179.5(W) to 179.5(E)) and the y-coordinates of the grid values are  
latitudes (from 89.5(N) to -89.5(S)).


What I want to do is convert this 1 degree dataset to a finer  
resolution of 0.5 degrees, thereby quadrupling the number of cells  
within the frame (i.e. convert to 720 x 360 grid). I wish to have  
longitudinal values ranging from -179.75 to 179.75 and latitudinal  
values from 89.75 to -89.75. I selected the 'interp.surface'  
function in the 'fields' package to do this as it provides bilinear  
interpolation from one grid to another. I have written the following  
code to try and carry out my interpolation...



library(fields)


x.mat - sprintf(%.2f, seq(from = -179.5, to = 179.5,  
length=360))  # longitude grid values
y.mat - sprintf(%.2f, seq(from = 89.5, to = -89.5, length=180))   
# latitude grid values

z.mat - read.table(BF_200501.txt, colClasses=numeric)  # dataset
z.mat - data.matrix(z.mat)
obj - list(x=x.mat, y=y.mat, z=z.mat)


#Setting up new grid
a.mat - sprintf(%.2f, seq(from = -179.75, to = 179.75, length =  
720))  # longitude grid values
b.mat - sprintf(%.2f, seq(from = 89.75, to = -89.75, length =  
360))  # latitude grid values

loc - make.surface.grid(list(x=a.mat, y=b.mat))


#Interpolation

new - interp.surface(obj, loc)


However I get the following error message:
Error in x.new - min(x) : non-numeric argument to binary operator

Can anyone explain what this error message means and why I am  
getting it? Or are there other more effective ways to perform the  
interpolation on this sort of dataset? Like I said I'm new to R so  
any advice will be gratefully received.


Many thanks,

Andy



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] help with installation of local gzip-ped packages

2009-06-21 Thread mauede
I was suggested to install two tar-red and gzip-ped packages that are not part 
of CRAN or BioConductors yet.
I read the R manual about Administration and could only find a good description 
of how to install packages 
not canonically included in CRAN repository, on UNIX systems.
I work on Linux/SuSE and  Windows ... so I am stuck with such an installation.
Any suggestion in very welcome.

Thank you.
Maura


tutti i telefonini TIM!


[[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] Roxygen to ignore a block of code?

2009-06-21 Thread Ken-JP

For instance, I am trying to run Roxygen on:

require( zoo )   # needed for time series
setClass( zoo )   # lets S4 know about S3 class so we can use as an
argument
setClass( myClass, representation( .zoo=zoo ), prototype( 0,
as.Date(1970-01-01) ))

When I run this code through Roxygen, it warns:
 No name found for the following expression: require( zoo ) 

and generates zoo.Rd  - I don't want any zoo.Rd to be generated - I am a
user of the library, not an implementer.

1. How can I tell Roxygen NOT to generate zoo.Rd?
2. What do I do to prevent Roxygen from warning about: require( zoo ) ?

Thx.

- Ken
-- 
View this message in context: 
http://www.nabble.com/Roxygen-to-ignore-a-block-of-code--tp24133293p24137672.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] AIC score

2009-06-21 Thread Adel
Dear All,

I've been using step function to find me the best model.this basically works
by using AIC score fucntion that is implemented on step(). The problem I'm
facing with lots of variables on the model for example :


step(lm(x1~x2,x3,x4,..x13)) sometimes gives me a warning message which
is :

AIC=- inf

Coefficients:
   (Intercept) wnt3.values wnt6.values   wnt10b.values
wnt9a.values
2.3462 -0.4689  2.0730  1.2769
-0.2319
  sfrp1.valueswnt5b.values  sfrp1.1.valuessfrp5.values
fzd5.1.values
   -0.2597  0.3150  0.3811  0.5926
-1.5567
   fzd1.values fzd4.values fzd6.values fzd7.values
fzd7.1.values
0.6459 -2.3016  0.3636  NA
NA
   fzd8.values
NA

Warning message:
attempting model selection on an essentially perfect fit is nonsense .

which stops the search.

Does this means that  Residual Sum of Squares (RSS) equals to zero that
makes AIC goes to -inf .And how would I overcome this problem.Can I for
example find those that have strong correlation with x1 first and then use
AIC score to find me the best model among them,.

Regards
Adel,

[[alternative HTML version deleted]]

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


Re: [R] Need help installing xts package

2009-06-21 Thread Detlef Steuer
Hi!

Take a look at this page:
http://fawn.hsu-hh.de/~steuer/rpage.html

The package you want to install ist called
R-base-devel-*.rpm

These packages are provided in opensuse's build service.

Hope that helps
Detlef

On Sat, 20 Jun 2009 21:52:56 -0400
R_help Help rhelp...@gmail.com wrote:

 Hi,
 
 I am trying to install package xts. I am using OPENSUSE 11 64 bit. When I
 invoke:
 
 install.pacakges(xts,dependencies=T)
 
 I received a lot of ERROR: compilation failed for package errors when R
 tries to install xts dependencies. I do not understand this behavior.
 
 I notice one thing. It complains.
 
 ERROR: compilation failed for package 'Hmisc'
 ** Removing '/home/chibi/R/x86_64-unknown-linux-gnu-library/2.8/Hmisc'
 * Installing *source* package 'Design' ...
 ** libs
 WARNING: R include directory is empty -- perhaps need to install R-devel.rpm
 or similar
 
 
 Is it because I need R-devel.rpm? What is it? I search google around and
 cannot find any explanation. Thank you.
 
 adschai
 
   [[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.


-- 
Wisely, and slow. They stumble that run fast. - Shakespeare

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

2009-06-21 Thread Forafo San
Thank-you all for your reply.  It turns out that there were both #
characters and unbalanced quotes in the character fields that were
creating problems for read.table.

Putting in the options quote=  and comment= in the read.table
statment fixes the problem.


On Fri, Jun 19, 2009 at 9:51 PM, jim holtmanjholt...@gmail.com wrote:
 Try  comment.char='', quote=''

 You may have unbalanced quotes or comments (#) in your data.

 On Fri, Jun 19, 2009 at 5:50 PM, Forafo San ppv.g...@gmail.com wrote:

 Hello,

 I'm receiving an error on attempting to use the read.table() function
 to read in data from a tab-delimited file. The file has more than
 60,000 rows with 94 tab-delimited columns. However, the error occurs
 on row 3 of the file:

  wl -read.table(sr003lines.tab, header=T, sep=\t)
 Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
  :
  line 3 did not have 94 elements

 On receiving this error, I wrote a python script to go through the
 file to find rows with fewer than the 94 columns -- python finds that
 the first row with fewer than 94 columns is 1,706 -- much later than
 what R reports.  R keeps running into this problem even with my
 python-massaged input file that I know for sure contains only rows
 with 94 columns.

 I also copied the first 4 rows of the input file into a separate file
 -- R isn't able to get past this problem.  I examined the row (line 3)
 of the input file -- the only thing that's unique about this line is
 that it contains a long string (236 characters) in a column that in
 the previous rows was empty.  Any chance that this sort of thing would
 cause R to run into a road block?

 Thanks,
 Premal P. Vora
 Associate Prof. Finance
 Penn State Harrisburg

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


[R] Incidence Function Model in R help

2009-06-21 Thread steve kimble
All:
Though I am fairly new to R, I am trying to work my way through J Oksanen's
Incidence Function Model in R and can't get past some error with my glm
arguments. I'm getting through

 attach(amphimedon_compressa)

plot(x.crd,y.crd,asp=1,xlab=Easting,ylab=Northing,pch=21,col=p+1,bg=5*p)
 d-dist(cbind(x.crd,y.crd))
 alpha-1
 edis-as.matrix(exp(-alpha*d))
 diag(edis)-0
 edis-sweep(edis,2,A,*)
 S-rowSums(edis[,p0])
 mod-glm(p~offset(2*log(S))+log(A),family=binomial)

before I get the error message

Error: NA/NaN/Inf in foreign function call (arg 4)

which is an argument concerning weights, an optional vector, whose choices
are NULL or a numeric vector. When I define weights=1, I get

Error in model.frame.default(formula = p ~ offset(2 * log(S)) + log(A),  :
  variable lengths differ (found for '(weights)')

and when I define weights=1, I get

Error in weights = 1 :
  comparison (4) is possible only for atomic and list types

Any suggestions?

Thanks!
Steve

[[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] Saving output in an iterated function

2009-06-21 Thread Economics Guy
Unfortunately my actual function is a bit more complicated than
ce=ce+be and does many transformations on the original vectors.
Maybe something like this better conveys what I am trying to do:

functM - function(eh,be,period,endPeriod){
period - period+1
ce - eh+be
de - (eh+be)^2
ee - ifelse(cede,de,ce)
{if (period  endPeriod)
functM(ce,be,period,endPeriod)
else data.frame(eh,be,ce,de,ee,period)}
}

ones - c(1,1,1)
twos - c(2,2,2)
functM(ones,twos,0,4)




On Sun, Jun 21, 2009 at 10:59 AM, Gabor
Grothendieckggrothendi...@gmail.com wrote:
 Try Reduce:

 f - function(d, incr = 1) with(d,
        data.frame(eh = ce, be, ce = ce + be, period = period + incr))
 d - data.frame(ce = ones, be = twos, period = 0)
 Reduce(f, init = d, x = rep(1, 4))
 Reduce(f, init = d, x = rep(1, 4), accumulate = TRUE)


 On Sun, Jun 21, 2009 at 9:06 AM, Economics Guyeconomics@gmail.com wrote:
 # I have a function that takes a few vectors manipulates them and then
 outputs a matrix of results:

 funct1 - function(eh,be){
        ce - eh+be
        data.frame(eh,be,ce)
        }

 ones - c(1,1,1)
 twos - c(2,2,2)
 funct1(ones,twos)


 # I would like to iterate it and save the results from each iteration.
 I could of course write a loop but I would like to do this is the most
 efficient way possible. The best I have come up with is this:


 functM - function(eh,be,period,endPeriod){
        period - period+1
        ce - eh+be
        {if (period  endPeriod)
                functM(ce,be,period,endPeriod)
                else data.frame(eh,be,ce,period)}
        }

 ones - c(1,1,1)
 twos - c(2,2,2)
 functM(ones,twos,0,4)

 # As you can see it only reports the results form the last iteration.
 Here it is the 4th iteration, but if you change the last argument of
 the previous run of functM, you can see that it will always report the
 final matrix. How can I have it save/store/write the results of each
 iteration. I do not care if it stacks it all into the same matrix or
 if I have to write.csv each time. I just want to do it in the most
 efficient way possible (the actual program will run for many many
 iterations of large vectors.

 # 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] Help on qpcR package

2009-06-21 Thread Ben Bolker



Endy BlackEndy wrote:
 
 I am using R on a Windows XP professional platform.
   The following code is part of a bigger one
  CODE
   press=function(y,x){
library(qpcR)
models.press=numeric(0)
cat(\n)
dep=y
   print(dep)
indep=log(x)
   print(indep)
yfit=dep-PRESS(lm(dep~indep))[[2]]
   cat(\n yfit\n)
   print(yfit)
yfit.orig=yfit
presid=y-yfit.orig
press=sum(presid^2)
cat(\n)
cat(PRESS =,press,\n)
   }
   On the command R window I define
 
 - Ignored:
 
  x=c(12,24,13,11,23,10,9,17,11,14,18)
  y=c(10,11,9,8,5,12,11,21,12,13,14)
 
   then I load the press source code, I run it using the x and y values
   defined before
   and I get the following
 
  press(x,y)
   Loading required package: drc
   Loading required package: alr3
   Loading required package: lattice
   Loading required package: magic
   Loading required package: abind
   Loading required package: MASS
   Loading required package: nlme
   Loading required package: plotrix
 
   'drc' has been loaded.
 
   Please cite R and 'drc' if used for a publication,
   for references type 'citation()' and 'citation('drc')'.
 
   Loading required package: gtools
   Loading required package: gplots
   Loading required package: gdata
   Loading required package: caTools
   Loading required package: bitops
   Loading required package: grid
 
   Attaching package: 'gplots'
 
 
   The following object(s) are masked from package:plotrix :
 
plotCI
 
 
   The following object(s) are masked from package:stats :
 
lowess
 
 
   'qpcR' has been loaded.
 
   Please cite R and the following if used for a publication:
 
   Spiess AN, Feig C, Ritz
   Highly accurate sigmoidal fitting of real-time PCR data by introducing
   a parameter for asymmetry.
   BMC Bioinformatics 2008, 29:221
   or
   Ritz C, Spiess AN. qpcR: an R package for sigmoidal model selection in
   quantitative real-time polymerase chain reaction analysis.
   Bioinformatics 2008, 24:1549-1551
 
   Newest version always available at www.dr-spiess.de/qpcR.html.
 
 
   Attaching package: 'qpcR'
 
 
   The following object(s) are masked from package:gplots :
 
residplot
 
 
[1] 12 24 13 11 23 10  9 17 11 14 18
[1] 2.302585 2.397895 2.197225 2.079442 1.609438 2.484907 2.397895
   3.044522 2.484907 2.564949 2.639057
   Error in get(noquote(a)) : object 'dep' not found
 
   The error reported, as I understand it, is that the object dep it is
   not defined. Obviously, at least to me, it is defined.
 
   If I declare the dep and indep objects on the command R window i. e.
 
dep=y
indep=x
 
   and rerun the programme  then it runs correctly and gives
 
press(x,y)
 
[1] 12 24 13 11 23 10  9 17 11 14 18
[1] 2.302585 2.397895 2.197225 2.079442 1.609438 2.484907 2.397895
   3.044522 2.484907 2.564949 2.639057
 
yfit
[1] 13.764062 24.199292 15.804140 15.192045 32.465326  9.547579
   9.845243  6.176015 10.521896 12.325493 14.931854
 
   PRESS = 248.7043
 
 Can anybody point out what's the problem?
   Thanks in advance
   K. Karakostas
 
 

 You really need to contact the package maintainers about this one.
Since your example is (a) not reproducible by us and (b) involves
a niche package (one for a very specific type of analysis), you're
probably not going to get much help here.  My guess is that the
package is trying to do something clever with environments that
makes their function not work when it is called from inside another
function.  You could try running your function code by hand (i.e.
not from within a function) and see if that makes a difference.

  Ben Bolker

-- 
View this message in context: 
http://www.nabble.com/Help-on-qpcR-package-tp24137125p24138743.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] Help on qpcR package

2009-06-21 Thread Ben Bolker



Endy BlackEndy wrote:
 
 I am using R on a Windows XP professional platform.
   The following code is part of a bigger one
  CODE
   press=function(y,x){
library(qpcR)
models.press=numeric(0)
cat(\n)
dep=y
   print(dep)
indep=log(x)
   print(indep)
yfit=dep-PRESS(lm(dep~indep))[[2]]
   cat(\n yfit\n)
   print(yfit)
yfit.orig=yfit
presid=y-yfit.orig
press=sum(presid^2)
cat(\n)
cat(PRESS =,press,\n)
   }
   On the command R window I define
 
 - Ignored:
 
  x=c(12,24,13,11,23,10,9,17,11,14,18)
  y=c(10,11,9,8,5,12,11,21,12,13,14)
 
   then I load the press source code, I run it using the x and y values
   defined before
   and I get the following
 
  press(x,y)
   Loading required package: drc
   Loading required package: alr3
   Loading required package: lattice
   Loading required package: magic
   Loading required package: abind
   Loading required package: MASS
   Loading required package: nlme
   Loading required package: plotrix
 
   'drc' has been loaded.
 
   Please cite R and 'drc' if used for a publication,
   for references type 'citation()' and 'citation('drc')'.
 
   Loading required package: gtools
   Loading required package: gplots
   Loading required package: gdata
   Loading required package: caTools
   Loading required package: bitops
   Loading required package: grid
 
   Attaching package: 'gplots'
 
 
   The following object(s) are masked from package:plotrix :
 
plotCI
 
 
   The following object(s) are masked from package:stats :
 
lowess
 
 
   'qpcR' has been loaded.
 
   Please cite R and the following if used for a publication:
 
   Spiess AN, Feig C, Ritz
   Highly accurate sigmoidal fitting of real-time PCR data by introducing
   a parameter for asymmetry.
   BMC Bioinformatics 2008, 29:221
   or
   Ritz C, Spiess AN. qpcR: an R package for sigmoidal model selection in
   quantitative real-time polymerase chain reaction analysis.
   Bioinformatics 2008, 24:1549-1551
 
   Newest version always available at www.dr-spiess.de/qpcR.html.
 
 
   Attaching package: 'qpcR'
 
 
   The following object(s) are masked from package:gplots :
 
residplot
 
 
[1] 12 24 13 11 23 10  9 17 11 14 18
[1] 2.302585 2.397895 2.197225 2.079442 1.609438 2.484907 2.397895
   3.044522 2.484907 2.564949 2.639057
   Error in get(noquote(a)) : object 'dep' not found
 
   The error reported, as I understand it, is that the object dep it is
   not defined. Obviously, at least to me, it is defined.
 
   If I declare the dep and indep objects on the command R window i. e.
 
dep=y
indep=x
 
   and rerun the programme  then it runs correctly and gives
 
press(x,y)
 
[1] 12 24 13 11 23 10  9 17 11 14 18
[1] 2.302585 2.397895 2.197225 2.079442 1.609438 2.484907 2.397895
   3.044522 2.484907 2.564949 2.639057
 
yfit
[1] 13.764062 24.199292 15.804140 15.192045 32.465326  9.547579
   9.845243  6.176015 10.521896 12.325493 14.931854
 
   PRESS = 248.7043
 
 Can anybody point out what's the problem?
   Thanks in advance
   K. Karakostas
 
 

 You really need to contact the package maintainers about this one.
Since your example is (a) not reproducible by us and (b) involves
a niche package (one for a very specific type of analysis), you're
probably not going to get much help here.  My guess is that the
package is trying to do something clever with environments that
makes their function not work when it is called from inside another
function.  You could try running your function code by hand (i.e.
not from within a function) and see if that makes a difference.

  Ben Bolker

-- 
View this message in context: 
http://www.nabble.com/Help-on-qpcR-package-tp24137125p24138733.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] [Rd] Floating point precision / guard digits? (PR#13771)

2009-06-21 Thread Wacek Kusnierczyk

Stavros Macrakis wrote

[...]


programming languages (including R).  I don't know whether R's sum function
uses this technique or some other (e.g. Kahan summation), but it does manage
to give higher precision than summation with individual arithmetic
operators:

sum(c(2^63,1,-2^63)) = 1
  


not if the arguments are passed as separate elements in ...:

x = c(2^63, 1, -2^63)
sum(x)
# 1
do.call(sum, as.list(x))
# 0

y = 1:3
sum(y)
# 6
do.call(sum, as.list(y))
# 6

vQ

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


Re: [R] Saving output in an iterated function

2009-06-21 Thread Gabor Grothendieck
Extend it like this:

Try this:

f - function(d, endPeriod) with(d, {
period - period + 1
ce - eh + be
de - (eh + be)^2
ee - ifelse(ce  de, de, ce)
eh - ifelse(period  endPeriod, ce, eh)
data.frame(eh, be, ce, de, ee, period)
})
ones - c(1, 1, 1)
twos - c(2, 2, 2)
d - data.frame(eh = ones, be = twos, period = 0)
Reduce(f, init = d, x = rep(4, 4))
Reduce(f, init = d, x = rep(4, 4), accumulate = TRUE)


On Sun, Jun 21, 2009 at 4:49 PM, Economics Guyeconomics@gmail.com wrote:
 Unfortunately my actual function is a bit more complicated than
 ce=ce+be and does many transformations on the original vectors.
 Maybe something like this better conveys what I am trying to do:

 functM - function(eh,be,period,endPeriod){
        period - period+1
        ce - eh+be
        de - (eh+be)^2
        ee - ifelse(cede,de,ce)
        {if (period  endPeriod)
                functM(ce,be,period,endPeriod)
                else data.frame(eh,be,ce,de,ee,period)}
        }

 ones - c(1,1,1)
 twos - c(2,2,2)
 functM(ones,twos,0,4)




 On Sun, Jun 21, 2009 at 10:59 AM, Gabor
 Grothendieckggrothendi...@gmail.com wrote:
 Try Reduce:

 f - function(d, incr = 1) with(d,
        data.frame(eh = ce, be, ce = ce + be, period = period + incr))
 d - data.frame(ce = ones, be = twos, period = 0)
 Reduce(f, init = d, x = rep(1, 4))
 Reduce(f, init = d, x = rep(1, 4), accumulate = TRUE)


 On Sun, Jun 21, 2009 at 9:06 AM, Economics Guyeconomics@gmail.com 
 wrote:
 # I have a function that takes a few vectors manipulates them and then
 outputs a matrix of results:

 funct1 - function(eh,be){
        ce - eh+be
        data.frame(eh,be,ce)
        }

 ones - c(1,1,1)
 twos - c(2,2,2)
 funct1(ones,twos)


 # I would like to iterate it and save the results from each iteration.
 I could of course write a loop but I would like to do this is the most
 efficient way possible. The best I have come up with is this:


 functM - function(eh,be,period,endPeriod){
        period - period+1
        ce - eh+be
        {if (period  endPeriod)
                functM(ce,be,period,endPeriod)
                else data.frame(eh,be,ce,period)}
        }

 ones - c(1,1,1)
 twos - c(2,2,2)
 functM(ones,twos,0,4)

 # As you can see it only reports the results form the last iteration.
 Here it is the 4th iteration, but if you change the last argument of
 the previous run of functM, you can see that it will always report the
 final matrix. How can I have it save/store/write the results of each
 iteration. I do not care if it stacks it all into the same matrix or
 if I have to write.csv each time. I just want to do it in the most
 efficient way possible (the actual program will run for many many
 iterations of large vectors.

 # 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] correlation between categorical data

2009-06-21 Thread Heinz Tuechler

At 07:40 21.06.2009, J Dougherty wrote:

[...]
There are other ways of regarding the FET.  Since it is precisely 
what it says

- an exact test - you can argue that you should avoid carrying over any
conclusions drawn about the small population the test was applied to and
employing them in a broader context.  In so far as the test is concerned, the
sample data and the contingency table it is arrayed in are the entire
universe.  In that sense, the FET can't be conservative or liberal.  It
isn't actually a hypothesis test and should not be thought of as one or used
in the place of one.

JDougherty


Could you give some reference, supporting this, for me, surprising 
view? I don't see a necessary connection between an exact test and 
the idea that it does not test a hypothesis.


Thanks,
Heinz

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


Re: [R] Incidence Function Model in R help

2009-06-21 Thread David Winsemius


On Jun 21, 2009, at 2:47 PM, steve kimble wrote:


All:
Though I am fairly new to R, I am trying to work my way through J  
Oksanen's
Incidence Function Model in R and can't get past some error with  
my glm

arguments. I'm getting through


attach(amphimedon_compressa)

plot(x.crd,y.crd,asp=1,xlab=Easting,ylab=Northing,pch=21,col=p 
+1,bg=5*p)

d-dist(cbind(x.crd,y.crd))
alpha-1
edis-as.matrix(exp(-alpha*d))
diag(edis)-0


That line may be unnecessary. I think as.matrix already did that:
 x - matrix(rnorm(9), nrow=3)
 m - as.matrix(dist(x))
 m
 123
1 0.00 3.287444 2.271032
2 3.287444 0.00 2.459300
3 2.271032 2.459300 0.00


edis-sweep(edis,2,A,*)
S-rowSums(edis[,p0])



mod-glm( p~offset(2*log(S)) + log(A), family=binomial)


before I get the error message

Error: NA/NaN/Inf in foreign function call (arg 4)


Can't you see that asking people to guess what might be the problem  
when the data is left as an unknown is an unreasonable request. This  
part of the Standard Message ...



PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


... means that not just the commands but also data need to be  
provided, either as a toy dataset, or a small sample, or at a location  
where it can be accessed.




which is an argument concerning weights, an optional vector, whose  
choices

are NULL or a numeric vector. When I define weights=1, I get

Error in model.frame.default(formula = p ~ offset(2 * log(S)) +  
log(A),  :

 variable lengths differ (found for '(weights)')


Just a guess, weights needs to be as long as the other vectors being  
given to the model?




and when I define weights=1, I get


That one is easy. You are using a comparison operator =, thinking  
it is the assignment operator -




Error in weights = 1 :
 comparison (4) is possible only for atomic and list types

Any suggestions?

Thanks!
Steve



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] rbind

2009-06-21 Thread Xiaogang Yang
Hi,
I have a array like this
data:
1  5
2  2342
3 33
and another
data1:
1 6
2 5
3 7
 when I do rbind(data,data1)
I get not what I want
 they become
1 5
2 2342
3 33
101 6
102 5
103 7




but I want to make the index as increasing one by one.
like
1 ..
2 ..
3 ..
4 ..
5 ..
6 ..

So what command I should use

thank you.

[[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] deal with array row by row

2009-06-21 Thread Xiaogang Yang
because the index in the result of rebind is not increasing one by one,
how can I deal with row one after another

[[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] rbind

2009-06-21 Thread jim holtman
You need to provide a reproducible example.  At least provide an 'str' of
your data and preferably the output of 'dput'.  I am not sure what you data
looks like.

works fine for me when using matrices:

 data
 [,1]
[1,]5
[2,] 2342
[3,]   33
 data1
 [,1]
[1,]6
[2,]5
[3,]7
 rbind(data,data1)
 [,1]
[1,]5
[2,] 2342
[3,]   33
[4,]6
[5,]5
[6,]7



On Sun, Jun 21, 2009 at 8:31 PM, Xiaogang Yang gavinxy...@gmail.com wrote:

 Hi,
 I have a array like this
 data:
 1  5
 2  2342
 3 33
 and another
 data1:
 1 6
 2 5
 3 7
  when I do rbind(data,data1)
 I get not what I want
  they become
 1 5
 2 2342
 3 33
 101 6
 102 5
 103 7




 but I want to make the index as increasing one by one.
 like
 1 ..
 2 ..
 3 ..
 4 ..
 5 ..
 6 ..

 So what command I should use

 thank you.

[[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.htmlhttp://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?

[[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] deal with array row by row

2009-06-21 Thread jim holtman
You need to indicate what the data is.  You still reference the rows
sequentially regardless of what that first column of your output is saying.

PLEASE do read the posting guide
http://www.R-project.org/posting-guide.htmlhttp://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.


Re: [R] Customize axis labels in xyplot

2009-06-21 Thread Deepayan Sarkar
On Sat, Jun 20, 2009 at 9:13 AM, nmsetnm...@netcourrier.com wrote:

 Hello,

 I'm plotting an xyplot where a continuous var recorded every min is plotted
 on y, and time expressed as HH:MM:SS on x, as follows :

 xaxis=list(tick.number=12,rot=90)
 lst=list(x=xaxis)
 xyplot(upt$LOAD_1 ~ upt$TIME, data=upt, type=c('g','p', 'r'), scales=lst)

 On the x-axis, every time label is drawn and the label quickly become
 unreadable as they overlap on each other.

 I wished to limit the number of label with 'tick.number=12' but it does not
 work as the x values are not treated as a numerical sequence.

 How can I limit the number of ticks and labels for a time series expressed
 as HH:MM:SS ?

 One way might be to convert to mins from an origin, the result would be less
 expressive though.

A reproducible example would help. Have you tried using a date-time class?

-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] Saving output in an iterated function

2009-06-21 Thread Economics Guy
# I have a function that takes a few vectors manipulates them and then
outputs a matrix of results:

funct1 - function(eh,be){
ce - eh+be
data.frame(eh,be,ce)
}

ones - c(1,1,1)
twos - c(2,2,2)
funct1(ones,twos)


# I would like to iterate it and save the results from each iteration.
I could of course write a loop but I would like to do this is the most
efficient way possible. The best I have come up with is this:


functM - function(eh,be,period,endPeriod){
period - period+1
ce - eh+be
{if (period  endPeriod)
functM(ce,be,period,endPeriod)
else data.frame(eh,be,ce,period)}
}

ones - c(1,1,1)
twos - c(2,2,2)
functM(ones,twos,0,4)

# As you can see it only reports the results form the last iteration.
Here it is the 4th iteration, but if you change the last argument of
the previous run of functM, you can see that it will always report the
final matrix. How can I have it save/store/write the results of each
iteration. I do not care if it stacks it all into the same matrix or
if I have to write.csv each time. I just want to do it in the most
efficient way possible (the actual program will run for many many
iterations of large vectors.

# Thanks.

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


Re: [R] correlation between categorical data

2009-06-21 Thread Daniel Malter
 For measures of association between two variables with two values each,
Cramer's V and Yule's Q are useful statistics. Look into this thread, for
example: http://markmail.org/message/sjd53z2dv2pb5nd6

To get a grasp from plotting (sometimes), you may use the jitter function in
the plot...

e=rnorm(n,0,1)
y=x+e
xprob=exp(x)/(1+exp(x))
yprob=exp(y)/(1+exp(y))
xcat=rbinom(n,1,xprob)
ycat=rbinom(n,1,yprob)
plot(ycat~xcat) #totally useless
plot(jitter(ycat)~jitter(xcat)) #can be somewhat useful
table(ycat,xcat) # interesting

#A measure of correlation between nominal variables
yule.Q=function(x,y){(table(x,y)[1,1]*table(x,y)[2,2]-table(x,y)[1,2]*table(
x,y)[2,1])/(table(x,y)[1,1]*table(x,y)[2,2]+table(x,y)[1,2]*table(x,y)[2,1])
}
yule.Q(ycat,xcat)

Best,
Daniel




-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von Marc Schwartz
Gesendet: Saturday, June 20, 2009 7:37 PM
An: Jason Morgan
Cc: r-help
Betreff: Re: [R] correlation between categorical data


On Jun 20, 2009, at 2:05 PM, Jason Morgan wrote:

 On 2009.06.19 14:04:59, Michael wrote:
 Hi all,

 In a data-frame, I have two columns of data that are categorical.

 How do I form some sort of measure of correlation between these two 
 columns?

 For numerical data, I just need to regress one to the other, or do 
 some pairs plot.

 But for categorical data, how do I find and/or visualize correlation 
 between the two columns of data?

 As Dylan mentioned, using crosstabs may be the easiest way. Also, a 
 simple correlation between the two variables may be informative. If 
 each variable is ordinal, you can use Kendall's tau-b (square table) 
 or tau-c (rectangular table). The former you can calculate with ?cor 
 (set method=kendall), the latter you may have to hack something 
 together yourself, there is code on the Internet to do this. If the 
 data are nominal, then a simple chi-squared test (large-n) or Fisher's 
 exact test (small-n) may be more appropriate. There are rules about 
 which to use when one variable is ordinal and one is nominal, but I 
 don't have my notes in front of me. Maybe someone else can provide 
 more assistance (and correct me if I'm wrong :).



I would be cautious in recommending the Fisher Exact Test based upon small
samples sizes, as the FET has been shown to be overly conservative. This
also applies to the use of the continuity correction for the chi-square test
(which replicates the behavior of the FET).

For more information see:
Chi-squared and Fisher-Irwin tests of two-by-two tables with small sample
recommendations Ian Campbell Stat in Med 26:3661-3675; 2007
http://www3.interscience.wiley.com/journal/114125487/abstract
and:
How conservative is Fisher's exact test?
A quantitative evaluation of the two-sample comparative binomial trial
Gerald G. Crans, Jonathan J. Shuster Stat Med. 2008 Aug 15;27(18):3598-611.
http://www3.interscience.wiley.com/journal/117929459/abstract


Frank also has some comments here (bottom of the page):

http://biostat.mc.vanderbilt.edu/wiki/Main/DataAnalysisDisc#Some_Important_P
oints_about_Cont


More generally, Agresti's Categorical Data Analysis is typically the first
reference in this domain to reach for. There is also a document written by
Laura Thompson which provides for a nice R companion to Agresti. It is
available from:

https://home.comcast.net/~lthompson221/Splusdiscrete2.pdf


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.

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

2009-06-21 Thread Ken-JP

Any way to tell Roxygen to ignore a block of code?  It is generating an
unwanted .Rd file.  

I've been searching for hours for an example, scouring documentation, but no
luck...
Thanks.

- Ken
-- 
View this message in context: 
http://www.nabble.com/Roxygen-to-ignore-a-block-of-code--tp24133293p24133293.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] Roxygen vs Sweave for S4 documentation

2009-06-21 Thread Tobias Verbeke

Hi Ken,


I have been using R for a while.  Recently, I have begun converting my
package into S4 classes.  I was previously using Rdoc for documentation. 
Now, I am looking to use the best tool for S4 documentation.  It seems that

the best choices for me are Roxygen and Sweave (I am fine with tex).

Are there any users of Roxygen or Sweave who can comment on the strengths or
weaknesses of one or othe other?  Thanks in advance.


For the moment proper documentation of S4 classes (with a @slot tag 
e.g.) is not implemented yet, but my secret hope is that this will

be implemented before Peter and Manuel (in cc) will present Roxygen
at DSC2009. Maybe they have further comments ?

Kind regards,
Tobias

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


Re: [R] Saving output in an iterated function

2009-06-21 Thread Gabor Grothendieck
Try Reduce:

f - function(d, incr = 1) with(d,
data.frame(eh = ce, be, ce = ce + be, period = period + incr))
d - data.frame(ce = ones, be = twos, period = 0)
Reduce(f, init = d, x = rep(1, 4))
Reduce(f, init = d, x = rep(1, 4), accumulate = TRUE)


On Sun, Jun 21, 2009 at 9:06 AM, Economics Guyeconomics@gmail.com wrote:
 # I have a function that takes a few vectors manipulates them and then
 outputs a matrix of results:

 funct1 - function(eh,be){
        ce - eh+be
        data.frame(eh,be,ce)
        }

 ones - c(1,1,1)
 twos - c(2,2,2)
 funct1(ones,twos)


 # I would like to iterate it and save the results from each iteration.
 I could of course write a loop but I would like to do this is the most
 efficient way possible. The best I have come up with is this:


 functM - function(eh,be,period,endPeriod){
        period - period+1
        ce - eh+be
        {if (period  endPeriod)
                functM(ce,be,period,endPeriod)
                else data.frame(eh,be,ce,period)}
        }

 ones - c(1,1,1)
 twos - c(2,2,2)
 functM(ones,twos,0,4)

 # As you can see it only reports the results form the last iteration.
 Here it is the 4th iteration, but if you change the last argument of
 the previous run of functM, you can see that it will always report the
 final matrix. How can I have it save/store/write the results of each
 iteration. I do not care if it stacks it all into the same matrix or
 if I have to write.csv each time. I just want to do it in the most
 efficient way possible (the actual program will run for many many
 iterations of large vectors.

 # 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] Alternate ways of finding number of occurrence of an element in a vector.

2009-06-21 Thread Allan Engelhardt
Answering my own question: if I explicitly garbage collecte before the 
benchmark then 'index' always wins, which probably also answers the 
original question.

v-rep(1:1000,1:1000); x-5; gc(); benchmark(replications=200, 
columns=c(test,elapsed), order=elapsed, which=length(which(x==v)), 
index=length(v[v==x]), sum=sum(v==x))

Allan


On 19/06/09 16:51, Allan Engelhardt wrote:
 When trying out a couple of different approaches to this problem I get 
 rather different answers between runs.  Anybody know why?

  library(rbenchmark)
  v-rep(1:1000,1:1000); x-5; benchmark(replications=200, 
 columns=c(test,elapsed), order=elapsed, 
 which=length(which(x==v)), index=length(v[v==x]), sum=sum(v==x))
test elapsed
 3   sum   2.513
 2 index   5.512
 1 which   6.712
  v-rep(1:1000,1:1000); x-5; benchmark(replications=200, 
 columns=c(test,elapsed), order=elapsed, 
 which=length(which(x==v)), index=length(v[v==x]), sum=sum(v==x))
test elapsed
 3   sum   2.502
 2 index   3.779
 1 which   6.650
  v-rep(1:1000,1:1000); x-5; benchmark(replications=200, 
 columns=c(test,elapsed), order=elapsed, 
 which=length(which(x==v)), index=length(v[v==x]), sum=sum(v==x))
test elapsed
 2 index   3.796
 3   sum   5.808
 1 which   6.633

 This pattern appears to repeat (so on the next two runs sum will win 
 followed by index followed by sum twice followed by index ...)

 Allan.




 On 19/06/09 14:55, Praveen Surendran wrote:
 Hi,



 I have a vector v and would like to find the number of occurrence of
 element x in the same.

 Is there a way other than,



 sum(as.integer(v==x)) or length(which(x==v))



 to do the this.



 I have a huge file to process and do this.  Both the above described 
 methods
 are pretty slow while dealing with a large vector.

 Please have your comments.



 Praveen Surendran.




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

[[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] Roxygen vs Sweave for S4 documentation

2009-06-21 Thread hadley wickham
 I have been using R for a while.  Recently, I have begun converting my
 package into S4 classes.  I was previously using Rdoc for documentation.
 Now, I am looking to use the best tool for S4 documentation.  It seems that
 the best choices for me are Roxygen and Sweave (I am fine with tex).

 Are there any users of Roxygen or Sweave who can comment on the strengths or
 weaknesses of one or othe other?  Thanks in advance.

Sweave isn't used for writing Rdoc files.

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] Alternate ways of finding number of occurrence of an element in a vector.

2009-06-21 Thread David Winsemius
If one puts the gc() call prior to the expressions themselves, one  
gets consistently ...  different results:


library(rbenchmark)
v-rep(1:500,1:500); x-5; benchmark(
 which= c(gc(),length(which(x==v))),  index= c(gc(),  
length(v[v==x])), sum= c(gc(), sum(v==x)),

 replications=200,  columns=c(test,elapsed), order=elapsed )
   test elapsed
3   sum   3.299
2 index   3.536
1 which   4.172

Since the gc call takes up mor than half the time, the differences may  
be more dramatic


 v-rep(1:500,1:500); x-5; benchmark(
+  which= c(gc()),  index= c(gc()), sum= c(gc()),
+  replications=200,  columns=c(test,elapsed), order=elapsed )
   test elapsed
2 index   2.621
3   sum   2.621
1 which   2.631

 within( benchmark(
+  which= c(gc(),length(which(x==v))),  index= c(gc(),  
length(v[v==x])), sum= c(gc(), sum(v==x)),
+  replications=200,  columns=c(test,elapsed),  
order=elapsed ), {corrected = elapsed-2.62})

   test elapsed corrected
3   sum   3.304 0.684
2 index   3.543 0.923
1 which   4.180 1.560

So the answer may not be so simple.



Allan Engelhardt wrote:


Answering my own question: if I explicitly garbage collecte before the
benchmark then 'index' always wins, which probably also answers the
original question.

v-rep(1:1000,1:1000); x-5; gc(); benchmark(replications=200,
columns=c(test,elapsed), order=elapsed,  
which=length(which(x==v)),

index=length(v[v==x]), sum=sum(v==x))




On 19/06/09 16:51, Allan Engelhardt wrote:
When trying out a couple of different approaches to this problem I  
get

rather different answers between runs.  Anybody know why?


library(rbenchmark)
v-rep(1:1000,1:1000); x-5; benchmark(replications=200,

columns=c(test,elapsed), order=elapsed,
which=length(which(x==v)), index=length(v[v==x]), sum=sum(v==x))
  test elapsed
3   sum   2.513
2 index   5.512
1 which   6.712

v-rep(1:1000,1:1000); x-5; benchmark(replications=200,

columns=c(test,elapsed), order=elapsed,
which=length(which(x==v)), index=length(v[v==x]), sum=sum(v==x))
  test elapsed
3   sum   2.502
2 index   3.779
1 which   6.650

v-rep(1:1000,1:1000); x-5; benchmark(replications=200,

columns=c(test,elapsed), order=elapsed,
which=length(which(x==v)), index=length(v[v==x]), sum=sum(v==x))
  test elapsed
2 index   3.796
3   sum   5.808
1 which   6.633

This pattern appears to repeat (so on the next two runs sum will  
win

followed by index followed by sum twice followed by index ...)





On 19/06/09 14:55, Praveen Surendran wrote:

Hi,

I have a vector v and would like to find the number of  
occurrence of

element x in the same.

Is there a way other than,

sum(as.integer(v==x)) or length(which(x==v))

to do the this.

I have a huge file to process and do this.  Both the above described
methods
are pretty slow while dealing with a large vector.

Please have your comments.

Praveen Surendran.




David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] error ellipse

2009-06-21 Thread Jason Morgan
On 2009.06.20 16:04:21, Alexandru T Codilean wrote:
 
 Dear All,
 
 I have a data set with the following structure:
 
 [A], [a], [B], [b]
 
 where [A] and [B] are measurements and [a] and [b] are the associated  
 uncertainties. I produce [B]/[A] vs. [A] plots in R and would like to  
 show uncertainties  as error ellipses (rather than error bars). Would  
 this be relatively easy to do in R?
 
 I would appreciate any help on this
 Thanks a lot
 
 Tibi

The car package has an Ellipses function that draws elliptical
confidence intervals for estimated model parameters. It's not exactly
what you want, but the code may help you create your own function.

Cheers,
~Jason

-- 
Jason W. Morgan
Graduate Student
Department of Political Science
*The Ohio State University*
154 North Oval Mall
Columbus, Ohio 43210

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

2009-06-21 Thread gug

Hello,

I have been using a very simple rbind approach (simple enough for me to
understand) to combine data files within R.

It seems to work fine, but then generates warning messages for reasons that
I can't begin to understand.  The text below shows the issue.  

testread12=read.table(C:/Files/Test100.txt, head = T)
testread11=read.table(C:/Files/Test101.txt, head = T)
testbind1=rbind(testread12,testread11)
testbind2=rbind(testread11,testread12)

The testrbind1 line generates the following message:

Warning message:
In `[-.factor`(`*tmp*`, ri, value = c(0.00557998, -0.058016069,  :
  invalid factor level, NAs generated

However the testrbind2 line works fine.  Although the data in the files is
different, the format (columns, etc) should be identical.  The fact that it
works in one order, but not the other, makes it very difficult for me to
understand what the problem is.

Files attached.  Any suggestions gratefully received.  Thanks,

Guy Green
http://www.nabble.com/file/p24130996/Test101.txt Test101.txt 
http://www.nabble.com/file/p24130996/Test100.txt Test100.txt 
-- 
View this message in context: 
http://www.nabble.com/Warning-messages-when-using-rbind-tp24130996p24130996.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.