Re: [R] How to re-combine values based on an index?

2012-12-02 Thread signal
Thank you I believe that is just what I was looking for.

Brian

On Dec 2, 2012, at 12:37 AM, Berend Hasselman [via R] 
ml-node+s789695n4651599...@n4.nabble.com wrote:

 
 On 02-12-2012, at 06:06, Brian Feeny wrote: 
 
  Thank you for your response,  here is a better example of what I am trying 
  to do: 
  
  data(iris) 
  index_setosa - which(iris$Species == setosa) 
  iris_setosa - data.frame() 
  iris_setosa[index_setosa,] -iris[index_setosa,] 
  iris_others - data.frame() 
  iris_others[-index_setosa,] - iris[-index_setosa,] 
  
 
 Change you example to make it actually do something 
 
 data(iris) 
 index_setosa - which(iris$Species == setosa) 
 iris_setosa -iris[index_setosa,] 
 head(iris_setosa) 
 
 # iris_others - data.frame() 
 # iris_others[-index_setosa,] - iris[-index_setosa,] 
 iris_others - iris[-index_setosa,] 
 head(iris_others) 
 tail(iris_others) 
 
 The head() and tail() calls are for checking. 
 Combine the two like this 
 
 z - rbind(iris_setosa,iris_others) 
 head(z) 
 tail(z) 
 
 Berend 
 
  So the idea would be that iris_setosa is a dataframe of size 150, with 50 
  observations of setosa, 
  using their original same indices, and 100 observations of NA.  Likewise 
  iris_others would be 
  100 observations of species besides setosa, using their original indices, 
  and there would be 50 NA's. 
  
  The above doesn't work.  When I execute it, I am left with iris_setosa 
  having 0 columns, I wish it to have all 
  the original columns of iris. 
  
  That said, once I get past the above (being able to split them out and keep 
  original indices), I wish to be able to combine 
  iris_setosa and iris_others so that iris_combined is a data frame with no 
  NA's and all the original data. 
  
  Does this make sense?  So I am basically taking a dataframe, splitting it 
  based on some criteria, and working on the two 
  split dataframes separately, and then I wish to recombine. 
  
  Brian 
  
  
  So at this point, I have iris_setosa a dataframe of size 
  On Dec 1, 2012, at 11:34 PM, William Dunlap wrote: 
  
  newdataset[testindex] = testset[testindex] 
  object 'dataset' not found 
  
  Is that really what R printed?  I get 
  newdataset[testindex] = testset[testindex] 
  Error in newdataset[testindex] = testset[testindex] : 
object 'newdataset' not found 
  but perhaps you have a different problem.  Copy and paste 
  (and read) the error message you got. 
  
  Bill Dunlap 
  Spotfire, TIBCO Software 
  wdunlap tibco.com 
  
  
  -Original Message- 
  From: [hidden email] [mailto:[hidden email]] On Behalf 
  Of Brian Feeny 
  Sent: Saturday, December 01, 2012 8:04 PM 
  To: [hidden email] 
  Subject: [R] How to re-combine values based on an index? 
  
  I am able to split my df into two like so: 
  
  dataset - trainset 
  index - 1:nrow(dataset) 
  testindex - sample(index, trunc(length(index)*30/100)) 
  trainset - dataset[-testindex,] 
  testset - dataset[testindex,-1] 
  
  So I have the index information, how could I re-combine the data using 
  that back into a 
  single df? 
  
  I tried what I thought might work, but failed with: 
  
  newdataset[testindex] = testset[testindex] 
  object 'dataset' not found 
  newdataset[-testindex] = trainset[-testindex] 
  object 'dataset' not found 
  
  Brian 
  
  __ 
  [hidden email] mailing list 
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code. 
  
  __ 
  [hidden email] mailing list 
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __ 
 [hidden email] mailing list 
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code. 
 
 
 If you reply to this email, your message will be added to the discussion 
 below:
 http://r.789695.n4.nabble.com/How-to-re-combine-values-based-on-an-index-tp4651594p4651599.html
 To unsubscribe from How to re-combine values based on an index?, click here.
 NAML





--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-re-combine-values-based-on-an-index-tp4651594p4651600.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

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


Re: [R] Line numbers with errors and warnings?

2012-12-02 Thread Worik R
What I mean is how do I get the R compilation or execution process to spit
out a line number with errors and warnings?

I should not have mentioned ESS, that is a distraction.

option(error=browser) is a help.  But it still does not say what piece of
code caused the error.

This is costing me a lot of time chasing down errors in mine and others
code...

Worik


On Sat, Dec 1, 2012 at 1:47 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 12-11-30 7:15 PM, Worik R wrote:

 How?

 This is a script I am running under ess on Emacs


 I've never used ESS.  You'll need to ask someone on the ESS list.

 Duncan Murdoch

  (Useful information optuion(error=recover)

 cheers
 Worik


 On Sat, Dec 1, 2012 at 12:34 PM, Duncan Murdoch
 murdoch.dun...@gmail.com 
 mailto:murdoch.duncan@gmail.**commurdoch.dun...@gmail.com
 wrote:

 On 12-11-30 4:22 PM, Worik R wrote:

 Is it possible to get a line number with an error report?


 Yes, if the error occurs in code that has line number information.
 You get line number info by default if you use source().  If the
 error is deeply buried in code that doesn't have the info (as it may
 be in your case), then the suggestions to use options(error=recover)
 will offer you a stack trace that shows you which high level code
 called the function reporting the problem.

 Duncan Murdoch


 I have a long script and an error:

 Error in `[.xts`(x, xsubset) : subscript out of bounds


 It would be very helpful, and save a lot of time, if there was
 some
 indication in the error message which line the error was.

 I can find it using binary search but that is a painful process.

 cheers
 Worik

  [[alternative HTML version deleted]]

 __**__
 R-help@r-project.org mailto:R-help@r-project.org mailing list
 
 https://stat.ethz.ch/mailman/_**_listinfo/r-helphttps://stat.ethz.ch/mailman/__listinfo/r-help

 
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://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

 
 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.


[R] How can i change the number of iterations in lme function

2012-12-02 Thread Haris Rhrlp
lme2-lme(y~ age + time + timeDay,data= DF, random=~time |id/timeDay)
Error in lme.formula(y ~ age + time + timeDay, data = DF, random = ~time |  : 
  nlminb problem, convergence error code = 1
  message = iteration limit reached without convergence (10)

[[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] Nightingale’s Rose chart-any suggestion?

2012-12-02 Thread Jim Lemon

On 11/30/2012 11:24 PM, Henry Smith wrote:

Hello, Everyone.

Does anyone know how to create a Nightingale’s Rose chart by using R?
Hopefully, the graph could be displayed like this:
http://mbostock.github.com/protovis/ex/crimea-rose.html


Hi Henry,
I cited Florence in a paper with Anupam Tyagi as a predecessor of a 
novel type of chart, but the recently added radial.pie (plotrix) 
function might give you a close enough approximation.


Jim

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


Re: [R] x axis labels

2012-12-02 Thread Jim Lemon

On 12/02/2012 09:49 AM, apprentice wrote:

Hi,

I have a problem with plotting my data as a histogram using barplot2. I am
plotting the x axis using axis(). I want to label only every fifth bar and
not all of them as they get too busy but I don't know how to do it. I was
trying to set the labels for the axis using at=seq(min value, max value,
by=5) but that leads to labels not being under the right bars but just sort
of spread around.
Does anyone know how to do it properly?


Hi Barbara,
Two ways I can think of. Get the bar positions from the call to barplot2:

barpos-barplot2(...)

Try barp in the plotrix package. By default the bars or groups are 
spaced at integer values and you get the bar positions returned as well.


Jim

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


Re: [R] instrumental variables regression using ivreg (AER) or tsls (sem)

2012-12-02 Thread Achim Zeileis

On Thu, 29 Nov 2012, Ranjan Maitra wrote:


Dear friends,

I am trying to understand and implement instrumental variables
regression using R.

I found a small (simple) example here which purportedly illustrates the
mechanics (using 2-stage least-squares):

http://www.r-bloggers.com/a-simple-instrumental-variables-problem/


The 1st stage regression is not quite correct in this example. My 
understanding is that he wants to use distance as an instrument for 
education and all other variables as instruments for themselves. However, 
the rest of the instruments have been erroneously left out of the 1st 
stage in his example.



Basically, here are the R commands (reproducible example) from that
site:

# -- begin R 


library(AER)

library(lmtest)

data(CollegeDistance)

cd.d-CollegeDistance

simple.ed.1s- lm(education ~ distance,data=cd.d)


This should be:

simple.ed.1s- lm(education ~ urban + gender + ethnicity + unemp + distance,
  data=cd.d)


cd.d$ed.pred- predict(simple.ed.1s)

simple.ed.2s- lm(wage ~ urban + gender + ethnicity + unemp + ed.pred ,
data=cd.d)


And then the same estimates could be obtained in ivreg() as:

m - ivreg(wage ~ urban + gender + ethnicity + unemp + education |
  urban + gender + ethnicity + unemp + distance, data = CollegeDistance)

Or in tsls() as:

m2 - tsls(wage ~ urban + gender + ethnicity + unemp + education,
  ~ urban + gender + ethnicity + unemp + distance, data = CollegeDistance)

Best,
Z


# -- end R


This yields the following summary:

summary(simple.ed.2s)

Call:
lm(formula = wage ~ urban + gender + ethnicity + unemp + ed.pred,
   data = cd.d)

Residuals:
   Min  1Q  Median  3Q Max 
-3.1692 -0.8294  0.1502  0.8482  3.9537 


Coefficients:
  Estimate Std. Error t value Pr(|t|) 
(Intercept)   -2.053604   1.675314  -1.226   0.2203 
urbanyes  -0.013588   0.046403  -0.293   0.7697 
genderfemale  -0.086700   0.036909  -2.349   0.0189 * 
ethnicityafam -0.566524   0.051686 -10.961   2e-16 ***

ethnicityhispanic -0.529088   0.048429 -10.925   2e-16 ***
unemp  0.145806   0.006969  20.922   2e-16 ***
ed.pred0.774340   0.120372   6.433 1.38e-10 ***
---
Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 


Residual standard error: 1.263 on 4732 degrees of freedom
Multiple R-squared: 0.1175,	Adjusted R-squared: 0.1163 
F-statistic:   105 on 6 and 4732 DF,  p-value:  2.2e-16 




Question: Assuming that the above illustration is correct, I was
wondering how I could mimic these calculations using the ivreg () in
AER or tsls () in sem?

Any suggestions? 


Many thanks in advance, and best wishes,
Ranjan

--
Important Notice: This mailbox is ignored: e-mails are set to be
deleted on receipt. For those needing to send personal or professional
e-mail, please use appropriate addresses.


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [mgcv][gam] Manually defining my own knots?

2012-12-02 Thread Simon Wood

Hi Andrew,

mgcv matches the knots to the smooth arguments by name. If an element of 
'knots' has
no name it will be ignored. The following will do what you want...

dumb.example = gam(y~s(x,k=3),knots=list(x=dumb.knots))

best,
Simon

On 29/11/12 23:44, Andrew Crane-Droesch wrote:

Dear List,

I'm using GAMs in a multiple imputation project, and I want to be able
to combine the parameter estimates and covariance matrices from each
completed dataset's fitted model in the end.  In order to do this, I
need the knots to be uniform for each model with partially-imputed
data.  I want to specify these knots based on the quantiles of the
unique values of the non-missing original data, ignoring the NA's.  When
I fit the GAM with the imputed data included, I don't want mgcv to use
the data that it is supplied to figure out the knots, because this will
lead to un-comparable results when the many fitted models are combined.

Here is a caricatured example of what I want to do:

#Random data
x = runif(1000,0,1)
y = (log(x^2)+x^3)/sin(x)
example = gam(y~s(x))
plot(example)

#But I want to define my own knots
dumb.knots = c(.7,.8,.9)
dumb.example = gam(y~s(x,k=3),knots=list(dumb.knots))
plot(dumb.example)
dumb.example2 = gam(y~s(x,k=3))
plot(dumb.example2)

Dumb example 1 is the same as dumb example 2, but it shouldn't be.

Once I figure out how to do this, I'll take the fitted coefficients from
each model and average them, then take the vcv's from each model and
average them, and add a correction to account for within and between
imputation variability, then plug them into a gamObject$coeffient and
gamObject$Vp matrix, plot/summarize, and have my result.  Comments
welcome on whether or not this would be somehow incorrect would be
welcome as well.  Still have a lot to learn!

Thanks,
Andrew

[[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] How can i change the number of iterations in lme function

2012-12-02 Thread Berend Hasselman

On 02-12-2012, at 10:15, Haris Rhrlp wrote:

 lme2-lme(y~ age + time + timeDay,data= DF, random=~time |id/timeDay)
 Error in lme.formula(y ~ age + time + timeDay, data = DF, random = ~time |  : 
   nlminb problem, convergence error code = 1
   message = iteration limit reached without convergence (10)


Assuming you are using package nlme.

Have you tried  ?lmeControl
and seen the msMaxIter and/or msMaxEval arguments.
You can set these with the control argument of lme.

Reading and browsing the help of a package really can be quite helpful.

Berend

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


Re: [R] cubic spline

2012-12-02 Thread Hans W Borchers
 but definitely *no* need to use a function from an extra CRAN
 package .. as someone else ``erronously'' suggested.

Except that Matlab's interp1() 'cubic' method does not use cubic spline 
interpolation, but Moler's 'pchip' approach, a piecewise cubic Hermite 
interpolation. Thus the results are different:

% Matlab:
interp1(X, Y, 11, 'cubic')  %= 5.8000
interp1(X, Y, 15, 'cubic')  %= 5.

# R:
spfun - splinefun( X, Y, natural)
spfun(11)#= 5.785714
spfun(15)#= 4.928571

spfun - splinefun( X, Y, monoH.FC)
spfun(11)#= 5.8
spfun(15)#= 5.0

Unfortunately, if the points are not monotonic, the 'monoH.FC' method does
not exactly agree with the 'pchip' approach, i.e. does not in general return
the same results.

By the way, pchip() in package 'pracma' implements Moler's approach and does
return the same (interpolation and extrapolation) results as interp1() with
the 'cubic' option in Matlab.

Hans Werner


Martin Maechler maechler at stat.math.ethz.ch writes:
 
  David Winsemius dwinsemius at comcast.net
  on Sat, 1 Dec 2012 09:25:42 -0700 writes:
 
  On Dec 1, 2012, at 5:09 AM, Steve Stephenson wrote:
 
  Hallo, I'm facing a problem and I would really appreciate
  your support.  I have to translate some Matalb code in R
  that I don't know very well but I would like to.  I have
  to interpolate 5 point with a cubic spline function and
  then I expect my function returns the Y value as output a
  specific X value inside the evaluation range.  Let's
  suppose that: 1- *X = [-10, -5, 0, 5, 10]* 2 - *Y = [12,
  10, 8, 7, 6]* 3 - *I have to interpolate with a cubic
  spline assuming x=11*
  
  In Matlab I used this function:
  
  *y = interp1(X, Y, x, cubic); *
  
  How can I do the same in R?  Many thanks in advance for
  your reply and support!
 
  splinefun( x = c(-10, -5, 0, 5, 10), y = c(12, 10, 8, 7, 6), 
 method=natural)(11) [1] 5.785714
 
 Yes, indeed, or simple  spline()
 
 but definitely *no* need to use a function from an extra CRAN
 package .. as someone else ``erronously'' suggested.
 
 Note that
   spline() and splinefun()
 together with
   approx() and approxfun()
 are among the several hundred functions that were already
 part of pre-alpha R, i.e., before R had a version number
 or *any* packages ... 
 and yes, the README then started with the two lines
 
 | R Source Code (Tue Jun 20 14:33:47 NZST 1995)
 | Copyright 1993, 1994, 1995 by Robert Gentleman and Ross Ihaka
 
 and it would be *really* *really* great
 if people did not add stuff to their packages that has
 been part of R for longer than they have even heard of R.
 
 Martin Maechler, ETH Zurich


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


Re: [R] Line numbers with errors and warnings?

2012-12-02 Thread Steve Lianoglou
Hi,

On Sun, Dec 2, 2012 at 12:31 AM, Worik R wor...@gmail.com wrote:
 What I mean is how do I get the R compilation or execution process to spit
 out a line number with errors and warnings?

As Duncan mentioned already, you can't *always* get a line number. You
can, however, usually get enough context around the failing call for
you to be able to smoke the problem out.

 option(error=browser) is a help.  But it still does not say what piece of
 code caused the error.

I typically run with a slightly different setting:

R options(error=utils:::dump.frames)

Whenever my script throws an error, after I'm done cursing at it I
then wonder where this error happened, so I call:

R traceback()

And you'll see the details of the stack that just blew up, starting
(or ending, can't remember) with the call itself, then the parent
call, and its parent, etc. all the way up to the top most call (likely
the line in your script itself).

If that's not enough information for me to figure out how to fix the
code in my script, I'll then call:

R debugger()

and this will then give me (more or less) the same information that
`traceback` showed (but in reverse order (which is why I never
remember the order of traceback)) and you are asked at what point
you'd like to enter the exploded wreckage to explore (via picking a
number) ... this way you can poke at the local variables until you see
what went wrong.

Your error:

Error in `[.xts`(x, xsubset) : subscript out of bounds

Is suggesting that you are trying to index an `xts` object with an
illegal value -- can you find the part in your code that's trying to
do this in your own script? You can put a call to `browser()` before
that part and explore the value of the subscript vs. the length of
your xts object to see what the problem is.

If you can't find this point, then take the traceback/debugger route.

 This is costing me a lot of time chasing down errors in mine and others
 code...

... which is typical when your wading in uncharted territory. As you
get a better feel of how to resolve these issues, your time-to-fix
these things will get better, so ... stay strong.

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


Re: [R] Line numbers with errors and warnings?

2012-12-02 Thread Milan Bouchet-Valat
Le dimanche 02 décembre 2012 à 06:02 -0500, Steve Lianoglou a écrit :
 Hi,
 
 On Sun, Dec 2, 2012 at 12:31 AM, Worik R wor...@gmail.com wrote:
  What I mean is how do I get the R compilation or execution process to spit
  out a line number with errors and warnings?
Indeed, I often suffer from the same problem when debugging R code too.
This is a real issue for me.

 As Duncan mentioned already, you can't *always* get a line number. You
 can, however, usually get enough context around the failing call for
 you to be able to smoke the problem out.
What are the cases where you cannot get line numbers? Duncan said
source()ed code comes with line numbers, but what's the more general
rule?

  option(error=browser) is a help.  But it still does not say what piece of
  code caused the error.
 
 I typically run with a slightly different setting:
 
 R options(error=utils:::dump.frames)
 
 Whenever my script throws an error, after I'm done cursing at it I
 then wonder where this error happened, so I call:
 
 R traceback()
 
 And you'll see the details of the stack that just blew up, starting
 (or ending, can't remember) with the call itself, then the parent
 call, and its parent, etc. all the way up to the top most call (likely
 the line in your script itself).
 
 If that's not enough information for me to figure out how to fix the
 code in my script, I'll then call:
 
 R debugger()
 
 and this will then give me (more or less) the same information that
 `traceback` showed (but in reverse order (which is why I never
 remember the order of traceback)) and you are asked at what point
 you'd like to enter the exploded wreckage to explore (via picking a
 number) ... this way you can poke at the local variables until you see
 what went wrong.
This is very useful of course to find the problematic function, but
quite often I end up wondering what exact command triggered an error.
For example, subscript out of bounds is hard to match to a precise `['
use in a whole function.

Even when using browser(), sometimes you cannot know where you are in
the function. So the line number, or the contents of the last line,
would be relevant information.

 Your error:
 
 Error in `[.xts`(x, xsubset) : subscript out of bounds
 
 Is suggesting that you are trying to index an `xts` object with an
 illegal value -- can you find the part in your code that's trying to
 do this in your own script? You can put a call to `browser()` before
 that part and explore the value of the subscript vs. the length of
 your xts object to see what the problem is.
 
 If you can't find this point, then take the traceback/debugger route.
 
  This is costing me a lot of time chasing down errors in mine and others
  code...
 
 ... which is typical when your wading in uncharted territory. As you
 get a better feel of how to resolve these issues, your time-to-fix
 these things will get better, so ... stay strong.
Of course experience helps, but without the most relevant information
(line number) you productivity is always affected... ;-)


Regards

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


Re: [R] Line numbers with errors and warnings?

2012-12-02 Thread Duncan Murdoch

On 12-12-02 12:31 AM, Worik R wrote:

What I mean is how do I get the R compilation or execution process to
spit out a line number with errors and warnings?

I should not have mentioned ESS, that is a distraction.


I think ESS is not a distraction here, it is the cause of the problem. 
If you source() your code, R will (by default) record line numbers.  ESS 
apparently doesn't send code to R using source().  (Or perhaps it does, 
and you aren't looking in the right place for it?)


For example, in Windows, if I put this code into the clipboard:

f - function() {
  stop(this is the error)
}

g - function() {
  f()
}

g()

then run source(clipboard) followed by traceback(), this is what I see:

 source(clipboard)
Error in f() (from clipboard#2) : this is the error
 traceback()
7: stop(this is the error) at clipboard#2
6: f() at clipboard#6
5: g() at clipboard#9
4: eval(expr, envir, enclos)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source(clipboard)

You can ignore entries 1 to 4; they are part of source().  Entries 5, 6, 
and 7 each tell the line of the script where they were parsed.


Duncan Murdoch



option(error=browser) is a help.  But it still does not say what piece
of code caused the error.

This is costing me a lot of time chasing down errors in mine and others
code...

Worik


On Sat, Dec 1, 2012 at 1:47 PM, Duncan Murdoch murdoch.dun...@gmail.com
mailto:murdoch.dun...@gmail.com wrote:

On 12-11-30 7:15 PM, Worik R wrote:

How?

This is a script I am running under ess on Emacs


I've never used ESS.  You'll need to ask someone on the ESS list.

Duncan Murdoch

(Useful information optuion(error=recover)

cheers
Worik


On Sat, Dec 1, 2012 at 12:34 PM, Duncan Murdoch
murdoch.dun...@gmail.com mailto:murdoch.dun...@gmail.com
mailto:murdoch.duncan@gmail.__com
mailto:murdoch.dun...@gmail.com wrote:

 On 12-11-30 4:22 PM, Worik R wrote:

 Is it possible to get a line number with an error report?


 Yes, if the error occurs in code that has line number
information.
 You get line number info by default if you use source().
  If the
 error is deeply buried in code that doesn't have the info
(as it may
 be in your case), then the suggestions to use
options(error=recover)
 will offer you a stack trace that shows you which high
level code
 called the function reporting the problem.

 Duncan Murdoch


 I have a long script and an error:

 Error in `[.xts`(x, xsubset) : subscript out of bounds


 It would be very helpful, and save a lot of time, if
there was some
 indication in the error message which line the error was.

 I can find it using binary search but that is a painful
process.

 cheers
 Worik

  [[alternative HTML version deleted]]

 __
R-help@r-project.org mailto:R-help@r-project.org
mailto:R-help@r-project.org mailto:R-help@r-project.org
mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
https://stat.ethz.ch/mailman/__listinfo/r-help

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

 http://www.R-project.org/__posting-guide.html
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] Line numbers with errors and warnings?

2012-12-02 Thread Duncan Murdoch

On 12-12-02 8:33 AM, Milan Bouchet-Valat wrote:

Le dimanche 02 décembre 2012 à 06:02 -0500, Steve Lianoglou a écrit :

Hi,

On Sun, Dec 2, 2012 at 12:31 AM, Worik R wor...@gmail.com wrote:

What I mean is how do I get the R compilation or execution process to spit
out a line number with errors and warnings?

Indeed, I often suffer from the same problem when debugging R code too.
This is a real issue for me.


As Duncan mentioned already, you can't *always* get a line number. You
can, however, usually get enough context around the failing call for
you to be able to smoke the problem out.

What are the cases where you cannot get line numbers? Duncan said
source()ed code comes with line numbers, but what's the more general
rule?


The general rule is that parse() needs to be called with the srcfile 
argument set to a srcfile object.  source() does that by default.


Duncan Murdoch




option(error=browser) is a help.  But it still does not say what piece of
code caused the error.


I typically run with a slightly different setting:

R options(error=utils:::dump.frames)

Whenever my script throws an error, after I'm done cursing at it I
then wonder where this error happened, so I call:

R traceback()

And you'll see the details of the stack that just blew up, starting
(or ending, can't remember) with the call itself, then the parent
call, and its parent, etc. all the way up to the top most call (likely
the line in your script itself).

If that's not enough information for me to figure out how to fix the
code in my script, I'll then call:

R debugger()

and this will then give me (more or less) the same information that
`traceback` showed (but in reverse order (which is why I never
remember the order of traceback)) and you are asked at what point
you'd like to enter the exploded wreckage to explore (via picking a
number) ... this way you can poke at the local variables until you see
what went wrong.

This is very useful of course to find the problematic function, but
quite often I end up wondering what exact command triggered an error.
For example, subscript out of bounds is hard to match to a precise `['
use in a whole function.

Even when using browser(), sometimes you cannot know where you are in
the function. So the line number, or the contents of the last line,
would be relevant information.


Your error:

Error in `[.xts`(x, xsubset) : subscript out of bounds

Is suggesting that you are trying to index an `xts` object with an
illegal value -- can you find the part in your code that's trying to
do this in your own script? You can put a call to `browser()` before
that part and explore the value of the subscript vs. the length of
your xts object to see what the problem is.

If you can't find this point, then take the traceback/debugger route.


This is costing me a lot of time chasing down errors in mine and others
code...


... which is typical when your wading in uncharted territory. As you
get a better feel of how to resolve these issues, your time-to-fix
these things will get better, so ... stay strong.

Of course experience helps, but without the most relevant information
(line number) you productivity is always affected... ;-)


Regards

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

2012-12-02 Thread Christofer Bogaso
Thanks Ted (and other) for your suggestion. Here I have implemented 
following:


Tab - matrix(c(8, 10, 12, 6), nr = 2)

Simu_Number - 5
Tab_Simulate - vector(list, length = Simu_Number)
for (i in 1:Simu_Number) {
Tab_Simulate[[i]] - matrix(rmultinom(1, sum(Tab), rep(0.25, 
4)), nrow = 2)   ## All Cells have equal probability

}
Sample_ChiSq - sapply(Tab_Simulate, function(x) {
Statistic -
sum((chisq.test(as.table(x))$observed - 
chisq.test(as.table(x))$expected)^2/chisq.test(as.table(x))$expected)

return(Statistic)
})

length(Sample_ChiSq[Sample_ChiSq  qchisq(0.95, 1)])/Simu_Number

hist(Sample_ChiSq, freq = FALSE)
lines(dchisq(seq(min(Sample_ChiSq), max(Sample_ChiSq), by = 0.5), 1))


However I think I am making some serious mistake as histogram did not 
match the density curve.


Can somebody help me where I am making mistake?

Thanks and regards,


On 01-12-2012 21:45, (Ted Harding) wrote:

You will need to be clear about whether you are conditioning on
the marginal totals as well as on the overall total. As stated,
you are only asking for the overall total (36) to be fixed.

In that case, one possible (and by no means unique) approach
would be to:

[A]: Choose any four random integers a,b,c,d that add up to 36
(even there, you still have to make a choice about what distribution
to adopt for the random integers).
[B]: Place the results into the 2x2 matrix; then evaluate chi-squared.
[C]: Repeat until you have enough cases.

Example (using equiprobable multinomial to generate 4 random integers)

   Tab - matrix(rmultinom(1,36,c(1,1,1,1)/4), nrow=2)

A more specific choice would be to fix the row and column probablilties
(but not the sample row and column totals), e.g.:

   P.row1 - 0.25 ; P.row2 - 1 - P.row1
   P.col1 - 0.50 ; P.col2 - 1 - P.col1

Then, adopting the hypothesis of independence between rows and columns:

   P11 - P.row1*P.col1
   P21 - P.row2*P.col1
   P12 - P.row1*P.col2
   P22 - P.row2*P.col2

   Tab - matrix(rmultinom(1,36,c(P11,P21,P12,P22)), nrow=2)

On the other hand, if you want to also fix the sample row margins
and column margins, then your sampled table needs to be generated
using a hypergeometric distribution, (which is the basis of the
fisher.test mentioned by Bert Gunter). Since explaining how to
do this is a bit mjore complicated than the above, please first
confirm what constraints (e.g. only total count; row-margins
only; col-margins only; both row-  col-margins) you wich to impose.

Hoping this helps,
Ted.

On 01-Dec-2012 14:28:24 Christofer Bogaso wrote:

Thanks Bert for your reply.

I am trying to understand/visualize the Sample Chi-Squared Statistic's
Null distribution. Therefore I need all possible Contingency tables
under Independence case.

What could be better way to visualize that?

Thanks and regards,

On 01 December 2012 20:03:00, Bert Gunter wrote:

Christopher:

Don't do this!

  If I understand you correctly, you want FIsher's exact test. This is
already available in R, using far smarter algorithms then you would. See:

?fisher.test

-- Bert

On Sat, Dec 1, 2012 at 5:48 AM, Christofer Bogaso
bogaso.christo...@gmail.com  mailto:bogaso.christo...@gmail.com wrote:

 Thanks John for your reply. However still not clear how I should
 proceed.

 My goal is to generate all possible contingency tables. Basically
 I want to see the distribution of Chi-squared Statistic under
 independence (NULL).

 So I was thinking if I can generate all possible permutation of
 integer numbers having sum equal to (8 + 10 + 12 + 6) = 36. Is
 there any R function to do that?

 Thanks and regards,


 On 01-12-2012 18:39, John Kane wrote:

 Are you basically asking for all possible permutations of the
 table?  If so see ?permn in the combinat package.

 John Kane
 Kingston ON Canada


 -Original Message-
 From:bogaso.christo...@gmail.com
 mailto:bogaso.christo...@gmail.com
 Sent: Sat, 01 Dec 2012 18:10:15 +0545
 To:r-help@r-project.org  mailto:r-help@r-project.org
 Subject: [R] Getting all possible contingency tables

 Hello all,

 Let say I have 2-way contingency table:

 Tab - matrix(c(8, 10, 12, 6), nr = 2)

 and the Chi-squared test could not reject the independence:

chisq.test(Tab)

   Pearson's Chi-squared test with Yates'
 continuity correction

 data:  Tab
 X-squared = 1.0125, df = 1, p-value = 0.3143


 However I want to get all possible contingency tables
 under this
 independence scenario (one of them would obviously be the
 given table
 as, we could not reject the independence), and for each
 such table I
 want to 

Re: [R] reading json tables

2012-12-02 Thread Michael Friendly

On 12/1/2012 4:08 PM, Duncan Temple Lang wrote:

Hi Michael

   The problem is that the content of the .js file is not JSON,
but actual JavaScript code.

You could use something like the following

tt = readLines(http://mbostock.github.com/protovis/ex/wheat.js;)

txt = c([, gsub(;, ,, gsub(var [a-zA-Z]+ = , , tt)), ])
tmp = paste(txt, collapse = \n)
tmp = gsub(([a-zA-Z]+):, '\\1:', tmp)
o = fromJSON(tmp)
data = structure(o[1:2], names = c(wheat, monarch))

Basically, this
 removes the 'var variable name =' part
 replaces the ; with a , to separate elements
 quotes the names of the fields, e.g. year, wheat, wages
 puts the two global data objects into a top-level array ([]) container

This isn't ideal (as the regular expressions are not sufficiently specific
and could modify the actual values incorrectly). However, it does the job
for this particular file.


Thanks for this, Duncan

I hadn't understood that the data had to be pure JSON.

The actual result I want is two data frames, wheat and monarch, whereas 
fromJSON returns a list of lists.  I'll try to figure that part out.


-Michael

--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.  Chair, Quantitative Methods
York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
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] reading json tables

2012-12-02 Thread Duncan Temple Lang

Hi Michael

 The actual result I want is two data frames, wheat and monarch, whereas 
 fromJSON returns a list of lists.  I'll try to
 figure that part out.

 do.call(rbind, data[[1]])

will do the job, but there are elements in each of data[[1]] and data[[2]]
that are incomplete and which need to be filled in with NAs before rbinding.

Best,
  D.

On 12/2/12 6:26 AM, Michael Friendly wrote:
 On 12/1/2012 4:08 PM, Duncan Temple Lang wrote:
 Hi Michael

The problem is that the content of the .js file is not JSON,
 but actual JavaScript code.

 You could use something like the following

 tt = readLines(http://mbostock.github.com/protovis/ex/wheat.js;)

 txt = c([, gsub(;, ,, gsub(var [a-zA-Z]+ = , , tt)), ])
 tmp = paste(txt, collapse = \n)
 tmp = gsub(([a-zA-Z]+):, '\\1:', tmp)
 o = fromJSON(tmp)
 data = structure(o[1:2], names = c(wheat, monarch))

 Basically, this
  removes the 'var variable name =' part
  replaces the ; with a , to separate elements
  quotes the names of the fields, e.g. year, wheat, wages
  puts the two global data objects into a top-level array ([]) container

 This isn't ideal (as the regular expressions are not sufficiently specific
 and could modify the actual values incorrectly). However, it does the job
 for this particular file.
 
 Thanks for this, Duncan
 
 I hadn't understood that the data had to be pure JSON.
 
 The actual result I want is two data frames, wheat and monarch, whereas 
 fromJSON returns a list of lists.  I'll try to
 figure that part out.
 
 -Michael


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


Re: [R] Line numbers with errors and warnings?

2012-12-02 Thread Milan Bouchet-Valat
Le dimanche 02 décembre 2012 à 09:02 -0500, Duncan Murdoch a écrit :
 On 12-12-02 8:33 AM, Milan Bouchet-Valat wrote:
  Le dimanche 02 décembre 2012 à 06:02 -0500, Steve Lianoglou a écrit :
  Hi,
 
  On Sun, Dec 2, 2012 at 12:31 AM, Worik R wor...@gmail.com wrote:
  What I mean is how do I get the R compilation or execution process to spit
  out a line number with errors and warnings?
  Indeed, I often suffer from the same problem when debugging R code too.
  This is a real issue for me.
 
  As Duncan mentioned already, you can't *always* get a line number. You
  can, however, usually get enough context around the failing call for
  you to be able to smoke the problem out.
  What are the cases where you cannot get line numbers? Duncan said
  source()ed code comes with line numbers, but what's the more general
  rule?
 
 The general rule is that parse() needs to be called with the srcfile 
 argument set to a srcfile object.  source() does that by default.
OK. But isn't it technically possible to compute a line number even when
no source file is present? If you call fix() on any function, you will
get something like a source file even if srcfile was not set. So it
could make sense to have a line number referring to what you would see
in fix(). Or at least, the last executed line when calling browser() or
when using options(error=recover), like gdb does.

This could be especially useful for packages that were not installed
with keep.source=TRUE. It could even help getting more useful error
messages on R-help...

Regards

 Duncan Murdoch
 
 
  option(error=browser) is a help.  But it still does not say what piece of
  code caused the error.
 
  I typically run with a slightly different setting:
 
  R options(error=utils:::dump.frames)
 
  Whenever my script throws an error, after I'm done cursing at it I
  then wonder where this error happened, so I call:
 
  R traceback()
 
  And you'll see the details of the stack that just blew up, starting
  (or ending, can't remember) with the call itself, then the parent
  call, and its parent, etc. all the way up to the top most call (likely
  the line in your script itself).
 
  If that's not enough information for me to figure out how to fix the
  code in my script, I'll then call:
 
  R debugger()
 
  and this will then give me (more or less) the same information that
  `traceback` showed (but in reverse order (which is why I never
  remember the order of traceback)) and you are asked at what point
  you'd like to enter the exploded wreckage to explore (via picking a
  number) ... this way you can poke at the local variables until you see
  what went wrong.
  This is very useful of course to find the problematic function, but
  quite often I end up wondering what exact command triggered an error.
  For example, subscript out of bounds is hard to match to a precise `['
  use in a whole function.
 
  Even when using browser(), sometimes you cannot know where you are in
  the function. So the line number, or the contents of the last line,
  would be relevant information.
 
  Your error:
 
  Error in `[.xts`(x, xsubset) : subscript out of bounds
 
  Is suggesting that you are trying to index an `xts` object with an
  illegal value -- can you find the part in your code that's trying to
  do this in your own script? You can put a call to `browser()` before
  that part and explore the value of the subscript vs. the length of
  your xts object to see what the problem is.
 
  If you can't find this point, then take the traceback/debugger route.
 
  This is costing me a lot of time chasing down errors in mine and others
  code...
 
  ... which is typical when your wading in uncharted territory. As you
  get a better feel of how to resolve these issues, your time-to-fix
  these things will get better, so ... stay strong.
  Of course experience helps, but without the most relevant information
  (line number) you productivity is always affected... ;-)
 
 
  Regards
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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] Getting all possible contingency tables

2012-12-02 Thread Ted Harding
On 02-Dec-2012 14:17:20 Christofer Bogaso wrote:
 Thanks Ted (and other) for your suggestion. Here I have implemented 
 following:
 
 Tab - matrix(c(8, 10, 12, 6), nr = 2)
 
 Simu_Number - 5
 Tab_Simulate - vector(list, length = Simu_Number)
 for (i in 1:Simu_Number) {
  Tab_Simulate[[i]] - matrix(rmultinom(1, sum(Tab), rep(0.25, 
 4)), nrow = 2)   ## All Cells have equal probability
  }
 Sample_ChiSq - sapply(Tab_Simulate, function(x) {
  Statistic -
 sum((chisq.test(as.table(x))$observed - 
 chisq.test(as.table(x))$expected)^2/chisq.test(as.table(x))$expected)
  return(Statistic)
  })
 
 length(Sample_ChiSq[Sample_ChiSq  qchisq(0.95, 1)])/Simu_Number
 
 hist(Sample_ChiSq, freq = FALSE)
 lines(dchisq(seq(min(Sample_ChiSq), max(Sample_ChiSq), by = 0.5), 1))
 
 
 However I think I am making some serious mistake as histogram did not 
 match the density curve.
 
 Can somebody help me where I am making mistake?
 
 Thanks and regards,
 [the remainder (copies of previous posts) snipped]

The reasons for the mis-match are:

A: that you have put the curve in the wrong place, by not
supplying x-coordinates to lines(), so that it plots its
points at x = 1,2,3,4,...

B: that you need to multiply the plotted density by the width
of the histogram cells, so as to match the density curve to the
discrete density of the histogram. It will also then look better
when the chis-squared curve is plotted at the mid-points of the cells.

Hence, try something like:

hist(Sample_ChiSq, freq = FALSE, breaks=0.5*(0:40))
x0 - 0.25+0.5*(0:20)
lines(x0,dchisq(x0,1))

Hoping this helps,
Ted.

-
E-Mail: (Ted Harding) ted.hard...@wlandres.net
Date: 02-Dec-2012  Time: 15:02:45
This message was sent by 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] How to use doSMP(revoIPC) with R 2.15.x version

2012-12-02 Thread Uwe Ligges



On 29.11.2012 17:56, 박상규 wrote:

Hello,


I'd like to use package 'doSMP'. But I can only found source codes in the CRAN.
I tried to build source code using 'r CMD build doSMP' in the source directory,
the following error is shown:



ERROR: dependencies 'foreach', 'iterators', 'revoIPC' are not available for pack
age 'doSMP'


So, i tried to install dependency packages. But I failed to install revoIPC 
with following error:



install.packages('revoIPC')
Installing package(s) into ‘C:/Program Files/R/R-2.15.2/library’
(as ‘lib’ is unspecified)
Warning in install.packages :
   package ‘revoIPC’ is not available (for R version 2.15.2)




Could you let me know how to use it in R ver2.15.x ?




See
https://stat.ethz.ch/pipermail/r-help/2012-January/301664.html

Uwe Ligges



Thanks in advance,





[[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] overlapping graphs in logarithmic y-axis

2012-12-02 Thread eliza botto

dear useRs,
i want to overlap graphs of two matrices in such a way that the y-axis of graph 
should be logarithmic against normal x-axis.
i am, unsuccessfully, trying the followings
matplot(mata, log=mata,type = l, col=red)lines(mata, log=matb,type = 
l, col=yellow)
could you please help me out on it??
thanks in advanceregards
eliza 
[[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] Getting all possible contingency tables

2012-12-02 Thread Christofer Bogaso
Thanks Ted for your correction. I was depressed thinking that I did not 
understand the theory. However now it comes as just a plotting mistake!


Thanks,

On 02 December 2012 20:47:48, (Ted Harding) wrote:

On 02-Dec-2012 14:17:20 Christofer Bogaso wrote:

Thanks Ted (and other) for your suggestion. Here I have implemented
following:

Tab - matrix(c(8, 10, 12, 6), nr = 2)

Simu_Number - 5
Tab_Simulate - vector(list, length = Simu_Number)
for (i in 1:Simu_Number) {
  Tab_Simulate[[i]] - matrix(rmultinom(1, sum(Tab), rep(0.25,
4)), nrow = 2)   ## All Cells have equal probability
  }
Sample_ChiSq - sapply(Tab_Simulate, function(x) {
  Statistic -
sum((chisq.test(as.table(x))$observed -
chisq.test(as.table(x))$expected)^2/chisq.test(as.table(x))$expected)
  return(Statistic)
  })

length(Sample_ChiSq[Sample_ChiSq  qchisq(0.95, 1)])/Simu_Number

hist(Sample_ChiSq, freq = FALSE)
lines(dchisq(seq(min(Sample_ChiSq), max(Sample_ChiSq), by = 0.5), 1))


However I think I am making some serious mistake as histogram did not
match the density curve.

Can somebody help me where I am making mistake?

Thanks and regards,
[the remainder (copies of previous posts) snipped]


The reasons for the mis-match are:

A: that you have put the curve in the wrong place, by not
supplying x-coordinates to lines(), so that it plots its
points at x = 1,2,3,4,...

B: that you need to multiply the plotted density by the width
of the histogram cells, so as to match the density curve to the
discrete density of the histogram. It will also then look better
when the chis-squared curve is plotted at the mid-points of the cells.

Hence, try something like:

hist(Sample_ChiSq, freq = FALSE, breaks=0.5*(0:40))
x0 - 0.25+0.5*(0:20)
lines(x0,dchisq(x0,1))

Hoping this helps,
Ted.

-
E-Mail: (Ted Harding) ted.hard...@wlandres.net
Date: 02-Dec-2012  Time: 15:02:45
This message was sent by 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] overlapping graphs in logarithmic y-axis

2012-12-02 Thread Uwe Ligges



On 02.12.2012 16:19, eliza botto wrote:


dear useRs,
i want to overlap graphs of two matrices in such a way that the y-axis of graph should be 
logarithmic against normal x-axis.
i am, unsuccessfully, trying the followings

matplot(mata, log=mata,type = l, col=red)lines(mata, log=matb,type = l, 
col=yellow)


This cannot wok for several reasons, inclusing typos, and is not 
reproducible for us given we do not know about mata.


Anyway, fixing your typos and the specification of the argument log, 
we get:


matplot(mata, log=y, type = l, col = red)

and overlay the red with yellow lines, although it makes no sense:

matplot(mata, type = l, col = yellow, add = TRUE)

Uwe Ligges




could you please help me out on it??
thanks in advanceregards
eliza   
[[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] Stripchart colors don't vary after I sort a data frame

2012-12-02 Thread Uwe Ligges



On 28.11.2012 18:27, Thomas Levine wrote:

# Hi,

# This plot has two colors.

overflow - read.csv('http://chainsaw.thomaslevine.com/overflow.csv',
stringsAsFactors = F)
png('original.png')
stripchart(overflow$precipi ~ overflow$after.9.am, method='stack', pch =
22, bg = overflow$overflow + 1, vertical = T, col = 0)
dev.off()

# I wanted continuous bands of color, so I sorted the data frame.
# But after sorting, it only had one color.

overflow.sorted - overflow[order(overflow$overflow),]
png('sorted.png')
stripchart(overflow.sorted$precipi ~ overflow.sorted$after.9.am,
method='stack', pch = 22, bg = overflow.sorted$overflow + 1, vertical =
T, col = 0)
dev.off()

# What's wrong?



All red are hidden by the black strips, perhaps you want to order it the 
other way round, i.e.:

 overflow.sorted - overflow[order(rev(overflow$overflow)),]
do not understand the data and you aim well enough after 5 seconds, 
hence it may not be what you aim at...


Uwe Ligges


# Here are all of the files.
# http://chainsaw.thomaslevine.com/overflow.csv
# http://chainsaw.thomaslevine.com/original.png
# http://chainsaw.thomaslevine.com/sorted.png

# Thanks
# Tom

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


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


Re: [R] overlapping graphs in logarithmic y-axis

2012-12-02 Thread eliza botto

Dear ligges,thankyou very much. Actually majority of the questions i asked on 
this forum were without sense, as quoted by majority of experts. i actually 
wanted to over lap mata and matb. by replacing your code with matb, it 
worked!!!
thankseliza

 Date: Sun, 2 Dec 2012 16:53:24 +0100
 From: lig...@statistik.tu-dortmund.de
 To: eliza_bo...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] overlapping graphs in logarithmic y-axis
 
 
 
 On 02.12.2012 16:19, eliza botto wrote:
 
  dear useRs,
  i want to overlap graphs of two matrices in such a way that the y-axis of 
  graph should be logarithmic against normal x-axis.
  i am, unsuccessfully, trying the followings
  matplot(mata, log=mata,type = l, col=red)lines(mata, log=matb,type 
  = l, col=yellow)
 
 This cannot wok for several reasons, inclusing typos, and is not 
 reproducible for us given we do not know about mata.
 
 Anyway, fixing your typos and the specification of the argument log, 
 we get:
 
 matplot(mata, log=y, type = l, col = red)
 
 and overlay the red with yellow lines, although it makes no sense:
 
 matplot(mata, type = l, col = yellow, add = TRUE)
 
 Uwe Ligges
 
 
 
  could you please help me out on it??
  thanks in advanceregards
  eliza   
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
  
[[alternative HTML version deleted]]

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


Re: [R] overlapping graphs in logarithmic y-axis

2012-12-02 Thread Uwe Ligges



On 02.12.2012 17:03, eliza botto wrote:


Dear ligges,thankyou very much. Actually majority of the questions i asked on 
this forum were without sense



IOnm this case the reason is that you do not ask the question precisely. 
Your exampole had


matplot(mata, .)
lines(mata, )

Please just be more specific, try to avoid errors that are not subject 
of your question, then people can help much better and understand what 
you are actually going to do. Also,m provide toy matrices.


Uwe Ligges




, as quoted by majority of experts. i actually wanted to over lap mata 
and matb. by replacing your code with matb, it worked!!!

thankseliza


Date: Sun, 2 Dec 2012 16:53:24 +0100
From: lig...@statistik.tu-dortmund.de
To: eliza_bo...@hotmail.com
CC: r-help@r-project.org
Subject: Re: [R] overlapping graphs in logarithmic y-axis



On 02.12.2012 16:19, eliza botto wrote:


dear useRs,
i want to overlap graphs of two matrices in such a way that the y-axis of graph should be 
logarithmic against normal x-axis.
i am, unsuccessfully, trying the followings

matplot(mata, log=mata,type = l, col=red)lines(mata, log=matb,type = l, 
col=yellow)


This cannot wok for several reasons, inclusing typos, and is not
reproducible for us given we do not know about mata.

Anyway, fixing your typos and the specification of the argument log,
we get:

matplot(mata, log=y, type = l, col = red)

and overlay the red with yellow lines, although it makes no sense:

matplot(mata, type = l, col = yellow, add = TRUE)

Uwe Ligges




could you please help me out on it??
thanks in advanceregards
eliza   
[[alternative HTML version deleted]]

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



[[alternative HTML version deleted]]

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



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


Re: [R] Plot from a jpeg

2012-12-02 Thread Uwe Ligges



On 27.11.2012 22:38, bgnumis wrote:

Hi all,

I know that I can for instance draw to plots in one using

nf-layout(matrix(c(1,2),1,2,byrow=FALSE))

Imagine I have 3 files:

plot1.jpeg
plot2.jpeg
plot3.jpeg

Anyone knows if I can read them and put on one colum and three rows reading
directly from the jpeg file?



Yes, there are many packages around,

One idea:

download.file(http://www.user2007.org/photos/r-cake.jpg;, jpfile - 
tempfile(), mode=wb)

library(ReadImages)
jp - read.jpeg(jpfile)
par(mfrow=c(3,1))
plot(jp)
plot(jp)
plot(jp)


Best,
Uwe Ligges





Many Thanks

[[alternative HTML version deleted]]

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



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


[R] simple subset question

2012-12-02 Thread Felipe Carrillo
 Hi,
Consider the small dataset below, I want to subset by two variables in
one line but it wont work...it works though if I subset separately. I have
to be missing something obvious that I did not realize before while using 
subset..

fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L, 
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 
47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L, 
1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L, 
91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L, 
19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 
13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L, 
44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L, 
13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L, 
8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L, 
111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L, 
30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L, 
1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L, 
0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L, 
23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L, 
905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L, 
31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L, 
1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L, 
94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L, 
33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 
13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L, 
53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L, 
22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 
2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 
2011L)), .Names = c(IDWeek, Total, Fry, Smolt, FryEq, 
Year), row.names = c(NA, 52L), class = data.frame)
fish
#  Subset to get the max Total for 2012
  x - subset(winter,Year==2012  Total==max(Total));b  # How come one line 
doesn't work?
  
  # It works if I subset the year first and then get the Total max from it
  xx - subset(winter,Year==2012)  
xxx - subset(xx,Total==max(Total));xxx   
xxx

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx

[[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] simple subset question

2012-12-02 Thread Anthony Damico
shouldn't you just change b to x and winter to fish?  :)


On Sun, Dec 2, 2012 at 12:21 PM, Felipe Carrillo
mazatlanmex...@yahoo.comwrote:

  Hi,
 Consider the small dataset below, I want to subset by two variables in
 one line but it wont work...it works though if I subset separately. I have
 to be missing something obvious that I did not realize before while using
 subset..

 fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
 30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
 1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
 0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
 23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
 905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
 31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
 94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
 33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
 53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
 22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L)), .Names = c(IDWeek, Total, Fry, Smolt, FryEq,
 Year), row.names = c(NA, 52L), class = data.frame)
 fish
 #  Subset to get the max Total for 2012
   x - subset(winter,Year==2012  Total==max(Total));b  # How come one
 line doesn't work?

   # It works if I subset the year first and then get the Total max from it
   xx - subset(winter,Year==2012)
 xxx - subset(xx,Total==max(Total));xxx
 xxx

 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx

 [[alternative HTML version deleted]]


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



[[alternative HTML version deleted]]

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


Re: [R] simple subset question

2012-12-02 Thread David Winsemius


On Dec 2, 2012, at 9:21 AM, Felipe Carrillo wrote:


 Hi,
Consider the small dataset below, I want to subset by two variables in
one line but it wont work...it works though if I subset separately.  
I have
to be missing something obvious that I did not realize before while  
using subset..


fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L)), .Names = c(IDWeek, Total, Fry, Smolt, FryEq,
Year), row.names = c(NA, 52L), class = data.frame)
fish
#  Subset to get the max Total for 2012
  x - subset(winter,Year==2012  Total==max(Total));b  # How come  
one line doesn't work?


  # It works if I subset the year first and then get the Total max  
from it

  xx - subset(winter,Year==2012)
xxx - subset(xx,Total==max(Total));xxx
xxx


Try instead either of these one step operations:
 xxx - max( subset(fish, Year==2012 )$Total) ;xxx
[1] 303259
 xxx - max( subset(fish, Year==2012 , Total) ) ;xxx
[1] 303259

--
David Winsemius, MD
Alameda, CA, USA

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


Re: [R] simple subset question

2012-12-02 Thread R. Michael Weylandt
On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
mazatlanmex...@yahoo.com wrote:
  Hi,
 Consider the small dataset below, I want to subset by two variables in
 one line but it wont work...it works though if I subset separately. I have
 to be missing something obvious that I did not realize before while using 
 subset..

 fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
 30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
 1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
 0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
 23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
 905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
 31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
 94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
 33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
 53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
 22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L)), .Names = c(IDWeek, Total, Fry, Smolt, FryEq,
 Year), row.names = c(NA, 52L), class = data.frame)
 fish
 #  Subset to get the max Total for 2012
   x - subset(winter,Year==2012  Total==max(Total));b  # How come one line 
 doesn't work?

Works fine for me if I change winter to fish here.

subset(fish,Year==2012  Total==max(Total))
   IDWeek  Total   Fry  Smolt  FryEq Year
21 47 303259 34008 269248 491733 2012


   # It works if I subset the year first and then get the Total max from it
   xx - subset(winter,Year==2012)
 xxx - subset(xx,Total==max(Total));xxx
 xxx

 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx

 [[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] simple subset question

2012-12-02 Thread Gerrit Eichner

Hi, Felipe,

two typos? See below!

On Sun, 2 Dec 2012, Felipe Carrillo wrote:


 Hi,
Consider the small dataset below, I want to subset by two variables in
one line but it wont work...it works though if I subset separately. I have
to be missing something obvious that I did not realize before while using 
subset..

fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,



... [snip]



2011L)), .Names = c(IDWeek, Total, Fry, Smolt, FryEq,
Year), row.names = c(NA, 52L), class = data.frame)
fish
#  Subset to get the max Total for 2012
  x - subset(winter,Year==2012  Total==max(Total));b  # How come one line 
doesn't work?


Don't you want *fish* instead of *winter* and *x* instead of *b*, as in

x - subset(  fish,Year==2012  Total==max(Total));x

?

 Hth  --  Gerrit


 
  # It works if I subset the year first and then get the Total max from it
  xx - subset(winter,Year==2012) 
xxx - subset(xx,Total==max(Total));xxx  
xxx
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to calculate mean of every nth time series data with zoo or xts ?

2012-12-02 Thread 박상규
Hello,


I have 1-minute time series stock data and I'd like to calculate mean of every 
n-th candle data of m-days.


result = c(mean of 1th data, mean of 2nd data, ...)


mean of 1th data = (1th data of 2012-1-1 + 1th data of 2012-1-2 + 1th data of 
2012-1-3) / 3

mean of 2nd data = (2nd data of 2012-1-1 + 2nd data of 2012-1-2 + 2nd data of 
2012-1-3) / 3
...

Could you let me know the fastest method ?


 Thanks in advance,



[[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] missed values

2012-12-02 Thread Joshua Ulrich
It's simpler, easier, and more correct to use zoo::na.approx.

R library(zoo)
R dat1-read.table(text=
+date value
+ 80  2006-10 0.1577647
+ 81  2006-11   NaN
+ 82  2006-12   NaN
+ 83  2007-01   NaN
+ 84  2007-02   NaN
+ 85  2007-03 0.2956429,
+ header=TRUE,stringsAsFactors=FALSE)
R dat1$valnew - na.approx(dat1$value, as.yearmon(dat1$date))
R dat1
  date valuevalnew
80 2006-10 0.1577647 0.1577647
81 2006-11   NaN 0.1853403
82 2006-12   NaN 0.2129160
83 2007-01   NaN 0.2404916
84 2007-02   NaN 0.2680673
85 2007-03 0.2956429 0.2956429

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com


On Fri, Nov 30, 2012 at 11:28 AM, arun smartpink...@yahoo.com wrote:
 Hi,
 May be this helps:
 dat1-read.table(text=
 ---data---
 ,header=TRUE,stringsAsFactors=FALSE)

 library(zoo)
  dat1$date-as.yearmon(dat1$date,format=%Y-%m)
 lm1-lm(value~date,dat1)
 dat2-data.frame(date=dat1[,1])
  dat1$fit-predict(lm1,newdata=dat2)
  dat1-within(dat1,{newvalue-ifelse(is.na(value)==T,fit,value)})
 dat1new-dat1[,c(1:2,4)]
 dat1new[80:86,]
 #   date value  newvalue
 #80 Oct 2006 0.1577647 0.1577647
 #81 Nov 2006   NaN 0.2782320
 #82 Dec 2006   NaN 0.2773986
 #83 Jan 2007   NaN 0.2765651
 #84 Feb 2007   NaN 0.2757317
 #85 Mar 2007 0.2956429 0.2956429
 #86 Apr 2007 0.3767500 0.3767500
 A.K.




 - Original Message -
 From: Vasilchenko Aleksander vasilchenko@gmail.com
 To: arun smartpink...@yahoo.com
 Cc:
 Sent: Friday, November 30, 2012 8:22 AM
 Subject: Re: [R] missed values

date value
snip
 80  2006-10 0.1577647
 81  2006-11   NaN
 82  2006-12   NaN
 83  2007-01   NaN
 84  2007-02   NaN
 85  2007-03 0.2956429
snip

 I want to obtain these values by linear interpolation between 80
 2006-10 0.1577647 and  85  2007-03 0.2956429
 81  2006-11   NaN
 82  2006-12   NaN
 83  2007-01   NaN
 84  2007-02   NaN

 This time series has only one such block, but there can be several
 such blocks in general

 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] simple subset question

2012-12-02 Thread Felipe Carrillo
Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
forgot to change the variable names
when I asked the question. David W suggestion works but the strange part is 
that I am still getting an error message
with :
  x - subset(fish,Year==2012  Total==max(Total));x
I get:
[1] IDWeek Total  Fry    Smolt  FryEq  Year  
0 rows (or 0-length row.names)
 
I will start a fresh session to see if that helps...Thank you all

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: R. Michael Weylandt michael.weyla...@gmail.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Cc: r-help@r-project.org r-help@r-project.org 
Sent: Sunday, December 2, 2012 9:42 AM
Subject: Re: [R] simple subset question

On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
mazatlanmex...@yahoo.com wrote:
  Hi,
 Consider the small dataset below, I want to subset by two variables in
 one line but it wont work...it works though if I subset separately. I have
 to be missing something obvious that I did not realize before while using 
 subset..

 fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
 30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
 1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
 0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
 23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
 905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
 31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
 94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
 33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
 53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
 22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L)), .Names = c(IDWeek, Total, Fry, Smolt, FryEq,
 Year), row.names = c(NA, 52L), class = data.frame)
 fish
 #  Subset to get the max Total for 2012
  x - subset(winter,Year==2012  Total==max(Total));b  # How come one line 
doesn't work?

Works fine for me if I change winter to fish here.

subset(fish,Year==2012  Total==max(Total))
  IDWeek  Total  Fry  Smolt  FryEq Year
21    47 303259 34008 269248 491733 2012


  # It works if I subset the year first and then get the Total max from it
  xx - subset(winter,Year==2012)
 xxx - subset(xx,Total==max(Total));xxx
 xxx

 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx

        [[alternative HTML version deleted]]


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




[[alternative HTML version deleted]]

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


Re: [R] How to calculate mean of every nth time series data with zoo or xts ?

2012-12-02 Thread Rui Barradas

Hello,

You should include a data example, using ?dput.
Anyway, making up some data,


t1 - as.POSIXct(2012-1-1 0:0:0)
t2 - as.POSIXct(2012-1-4 0:0:0)
d - seq(t1, t2, by = 1 min)
x - rnorm(length(d))

z - zoo(x, d)

aggregate(z, list(format(index(z), %H:%M)), FUN = mean)


Hope this helps,

Rui Barradas
Em 02-12-2012 18:09, 박상규 escreveu:

Hello,


I have 1-minute time series stock data and I'd like to calculate mean of every 
n-th candle data of m-days.


result = c(mean of 1th data, mean of 2nd data, ...)


mean of 1th data = (1th data of 2012-1-1 + 1th data of 2012-1-2 + 1th data of 
2012-1-3) / 3

mean of 2nd data = (2nd data of 2012-1-1 + 2nd data of 2012-1-2 + 2nd data of 
2012-1-3) / 3
...

Could you let me know the fastest method ?


  Thanks in advance,



[[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] simple subset question

2012-12-02 Thread Felipe Carrillo
Works with the small dataset (2 years) but I get the error message with the 
whole dataset (12 years of data). I am going to have
to check what's wrong with it...Thanks

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: arun smartpink...@yahoo.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Cc: R help r-help@r-project.org; R. Michael Weylandt 
michael.weyla...@gmail.com 
Sent: Sunday, December 2, 2012 10:29 AM
Subject: Re: [R] simple subset question

Hi,
I am getting this:
x-subset(fish,Year==2012  Total==max(Total))
 x
#   IDWeek  Total   Fry  Smolt  FryEq Year
#21 47 303259 34008 269248 491733 2012
A.K.




- Original Message -
From: Felipe Carrillo mazatlanmex...@yahoo.com
To: R. Michael Weylandt michael.weyla...@gmail.com
Cc: r-help@r-project.org r-help@r-project.org
Sent: Sunday, December 2, 2012 1:25 PM
Subject: Re: [R] simple subset question

Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
forgot to change the variable names
when I asked the question. David W suggestion works but the strange part is 
that I am still getting an error message
with :
  x - subset(fish,Year==2012  Total==max(Total));x
I get:
[1] IDWeek Total  Fry    Smolt  FryEq  Year  
0 rows (or 0-length row.names)
 
I will start a fresh session to see if that helps...Thank you all

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: R. Michael Weylandt michael.weyla...@gmail.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Cc: r-help@r-project.org r-help@r-project.org 
Sent: Sunday, December 2, 2012 9:42 AM
Subject: Re: [R] simple subset question

On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
mazatlanmex...@yahoo.com wrote:
  Hi,
 Consider the small dataset below, I want to subset by two variables in
 one line but it wont work...it works though if I subset separately. I have
 to be missing something obvious that I did not realize before while using 
 subset..

 fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
 30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
 1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
 0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
 23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
 905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
 31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
 94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
 33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
 53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
 22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L)), .Names = c(IDWeek, Total, Fry, Smolt, FryEq,
 Year), row.names = c(NA, 52L), class = data.frame)
 fish
 #  Subset to get the max Total for 2012
  x - subset(winter,Year==2012  Total==max(Total));b  # How come one line 
doesn't work?

Works fine for me if I change winter to fish here.

subset(fish,Year==2012  Total==max(Total))
  IDWeek  Total  Fry  Smolt  FryEq Year
21    47 303259 34008 269248 491733 2012


  # It works if I subset the year first and then get the Total max from it
  xx - subset(winter,Year==2012)
 xxx - subset(xx,Total==max(Total));xxx
 xxx

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

Re: [R] simple subset question

2012-12-02 Thread R. Michael Weylandt
On Sun, Dec 2, 2012 at 6:46 PM, Felipe Carrillo
mazatlanmex...@yahoo.com wrote:
 Works with the small dataset (2 years) but I get the error message with the
 whole dataset (12 years of data). I am going to have
 to check what's wrong with it...Thanks

Off the cuff guess: there's a NA in Total so max(Total) is NA which
throws a wrench in `==`.

MW

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


Re: [R] simple subset question

2012-12-02 Thread William Dunlap
 I am
 still getting an error message
 with :
   x - subset(fish,Year==2012  Total==max(Total));x
 I get:
 [1] IDWeek Total  FrySmolt  FryEq  Year
 0 rows (or 0-length row.names)

The above is not an error message.  It says that there
are no rows satisfying your criteria.  Note that Total==max(Total)
returns a TRUE for each row in which the Total value
equals the maximum Total value over all the years in
the data.  Are you looking for the maximum value of Total
in each year?

 tmp - transform(fish, YearlyMaxTotal = ave(Total, Year, FUN=max))
 subset(tmp, Total==YearlyMaxTotal)
   IDWeek  TotalFry  Smolt  FryEq Year YearlyMaxTotal
21 47 303259  34008 269248 491733 2012 303259
39 39 157260 156909351 157506 2011 157260
 subset(tmp, Total==YearlyMaxTotal  Year==2012)
   IDWeek  Total   Fry  Smolt  FryEq Year YearlyMaxTotal
21 47 303259 34008 269248 491733 2012 303259

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Felipe Carrillo
 Sent: Sunday, December 02, 2012 10:47 AM
 To: arun
 Cc: R help
 Subject: Re: [R] simple subset question
 
 Works with the small dataset (2 years) but I get the error message with the 
 whole
 dataset (12 years of data). I am going to have
 to check what's wrong with it...Thanks
 
 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx
 
 
 From: arun smartpink...@yahoo.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Cc: R help r-help@r-project.org; R. Michael Weylandt
 michael.weyla...@gmail.com
 Sent: Sunday, December 2, 2012 10:29 AM
 Subject: Re: [R] simple subset question
 
 Hi,
 I am getting this:
 x-subset(fish,Year==2012  Total==max(Total))
  x
 #   IDWeek  Total   Fry  Smolt  FryEq Year
 #21 47 303259 34008 269248 491733 2012
 A.K.
 
 
 
 
 - Original Message -
 From: Felipe Carrillo mazatlanmex...@yahoo.com
 To: R. Michael Weylandt michael.weyla...@gmail.com
 Cc: r-help@r-project.org r-help@r-project.org
 Sent: Sunday, December 2, 2012 1:25 PM
 Subject: Re: [R] simple subset question
 
 Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
 forgot to
 change the variable names
 when I asked the question. David W suggestion works but the strange part is 
 that I am
 still getting an error message
 with :
   x - subset(fish,Year==2012  Total==max(Total));x
 I get:
 [1] IDWeek Total  Fry    Smolt  FryEq  Year
 0 rows (or 0-length row.names)
 
 I will start a fresh session to see if that helps...Thank you all
 
 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx
 
 
 From: R. Michael Weylandt michael.weyla...@gmail.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Cc: r-help@r-project.org r-help@r-project.org
 Sent: Sunday, December 2, 2012 9:42 AM
 Subject: Re: [R] simple subset question
 
 On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
 mazatlanmex...@yahoo.com wrote:
   Hi,
  Consider the small dataset below, I want to subset by two variables in
  one line but it wont work...it works though if I subset separately. I have
  to be missing something obvious that I did not realize before while using 
  subset..
 
  fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
  34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
  47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
  34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
  47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
  1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
  91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
  19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
  13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
  44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
  13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
  8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
  111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
  0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
  30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
  1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
  0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
  23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
  0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
  905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
  31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
  1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
  94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
  33327L, 0L, 

Re: [R] Line numbers with errors and warnings?

2012-12-02 Thread Duncan Murdoch

On 12-12-02 9:52 AM, Milan Bouchet-Valat wrote:

Le dimanche 02 décembre 2012 à 09:02 -0500, Duncan Murdoch a écrit :

On 12-12-02 8:33 AM, Milan Bouchet-Valat wrote:

Le dimanche 02 décembre 2012 à 06:02 -0500, Steve Lianoglou a écrit :

Hi,

On Sun, Dec 2, 2012 at 12:31 AM, Worik R wor...@gmail.com wrote:

What I mean is how do I get the R compilation or execution process to spit
out a line number with errors and warnings?

Indeed, I often suffer from the same problem when debugging R code too.
This is a real issue for me.


As Duncan mentioned already, you can't *always* get a line number. You
can, however, usually get enough context around the failing call for
you to be able to smoke the problem out.

What are the cases where you cannot get line numbers? Duncan said
source()ed code comes with line numbers, but what's the more general
rule?


The general rule is that parse() needs to be called with the srcfile
argument set to a srcfile object.  source() does that by default.

OK. But isn't it technically possible to compute a line number even when
no source file is present?


Yes, you don't really need to have a file present, you just need a 
srcfile object.  For example, on Windows when you use 
source(clipboard), there's no file, just the system clipboard.


 If you call fix() on any function, you will

get something like a source file even if srcfile was not set.


Yes, and then you can call source on that object, and you'll get line 
number information attached, relative to whatever you sourced.



So it

could make sense to have a line number referring to what you would see
in fix(). Or at least, the last executed line when calling browser() or
when using options(error=recover), like gdb does.


The thing is that if you didn't attach the line number information to 
the code, then it's not there.  R can't figure out after the fact where 
the code came from.  It needs to have the debug info in place when it 
runs it.  How could R figure out where some expression came from that it 
happens to be executing?  Using eval() on a constructed expression in a 
function is not all that uncommon, but to the evaluator, it looks just 
like any other evaluation.





This could be especially useful for packages that were not installed
with keep.source=TRUE. It could even help getting more useful error
messages on R-help...


If you're debugging a package, then why not install it with 
keep.source=TRUE?


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] simple subset question

2012-12-02 Thread Felipe Carrillo
 
Using my whole dataset I get:
library(plyr)
ddply(winter,Year,summarise,maxTotal=max(Total))
 
 fish - structure(list(Year = 2002:2012, maxTotal = c(1464311L, 1071051L, 
714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L, 
157260L, 303259L)), .Names = c(Year, maxTotal), row.names = c(NA, 
-11L), class = data.frame)
 
I only want to extract the max Total for 2012 and want the whole row like this:
 IDWeek  Total   Fry  Smolt  FryEq Year
21 47 303259 34008 269248 491733 2012
 
My whole dataset is too big to post it so thanks for your help and will try
to figure out why subset returns an empty row

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: William Dunlap wdun...@tibco.com
To: Felipe Carrillo mazatlanmex...@yahoo.com; arun smartpink...@yahoo.com 
Cc: R help r-help@r-project.org 
Sent: Sunday, December 2, 2012 11:00 AM
Subject: RE: [R] simple subset question

 I am
 still getting an error message
 with :
   x - subset(fish,Year==2012  Total==max(Total));x
 I get:
 [1] IDWeek Total  Fry    Smolt  FryEq  Year
 0 rows (or 0-length row.names)

The above is not an error message.  It says that there
are no rows satisfying your criteria.  Note that Total==max(Total)
returns a TRUE for each row in which the Total value
equals the maximum Total value over all the years in
the data.  Are you looking for the maximum value of Total
in each year?

 tmp - transform(fish, YearlyMaxTotal = ave(Total, Year, FUN=max))
 subset(tmp, Total==YearlyMaxTotal)
  IDWeek  Total    Fry  Smolt  FryEq Year YearlyMaxTotal
21    47 303259  34008 269248 491733 2012        303259
39    39 157260 156909    351 157506 2011        157260
 subset(tmp, Total==YearlyMaxTotal  Year==2012)
  IDWeek  Total  Fry  Smolt  FryEq Year YearlyMaxTotal
21    47 303259 34008 269248 491733 2012        303259

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Felipe Carrillo
 Sent: Sunday, December 02, 2012 10:47 AM
 To: arun
 Cc: R help
 Subject: Re: [R] simple subset question
 
 Works with the small dataset (2 years) but I get the error message with the 
 whole
 dataset (12 years of data). I am going to have
 to check what's wrong with it...Thanks
 
 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx
 
 
 From: arun smartpink...@yahoo.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Cc: R help r-help@r-project.org; R. Michael Weylandt
 michael.weyla...@gmail.com
 Sent: Sunday, December 2, 2012 10:29 AM
 Subject: Re: [R] simple subset question
 
 Hi,
 I am getting this:
 x-subset(fish,Year==2012  Total==max(Total))
  x
 #   IDWeek  Total   Fry  Smolt  FryEq Year
 #21 47 303259 34008 269248 491733 2012
 A.K.
 
 
 
 
 - Original Message -
 From: Felipe Carrillo mazatlanmex...@yahoo.com
 To: R. Michael Weylandt michael.weyla...@gmail.com
 Cc: r-help@r-project.org r-help@r-project.org
 Sent: Sunday, December 2, 2012 1:25 PM
 Subject: Re: [R] simple subset question
 
 Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
 forgot to
 change the variable names
 when I asked the question. David W suggestion works but the strange part is 
 that I am
 still getting an error message
 with :
   x - subset(fish,Year==2012  Total==max(Total));x
 I get:
 [1] IDWeek Total  Fry    Smolt  FryEq  Year
 0 rows (or 0-length row.names)
 
 I will start a fresh session to see if that helps...Thank you all
 
 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx
 
 
 From: R. Michael Weylandt michael.weyla...@gmail.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Cc: r-help@r-project.org r-help@r-project.org
 Sent: Sunday, December 2, 2012 9:42 AM
 Subject: Re: [R] simple subset question
 
 On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
 mazatlanmex...@yahoo.com wrote:
   Hi,
  Consider the small dataset below, I want to subset by two variables in
  one line but it wont work...it works though if I subset separately. I 
  have
  to be missing something obvious that I did not realize before while 
  using subset..
 
  fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
  34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
  47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
  34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
  47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
  1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
  91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
  19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
  13202L, 

Re: [R] e1071 SVM: Cross-validation error confusion matrix

2012-12-02 Thread Frank Harrell
What do you mean by accuracy?  Proportion classified correctly is not a good
index of accuracy if that's the problem.
Frank

rahul143 wrote
 Hi, 
 
 I ran two svm models in R e1071 package: the first without
 cross-validation and the second with 10-fold cross-validation. 
 
 I used the following syntax: 
 
 #Model 1: Without cross-validation: 
 svm.model - svm(Response ~ ., data=data.df, type=C-classification,
 kernel=linear, cost=1) 
 predict - fitted(svm.model) 
 cm - table(predict, data.df$Response) 
 cm 
 
 #Model2: With 10-fold cross-validation: 
 svm.model2 - svm(Response ~ ., data=data.df, type=C-classification,
 kernel=linear, cost=1, cross=10) 
 predict2 - fitted(svm.model2) 
 cm2 - table(predict2, data.df$Response) 
 cm2 
 
 However, when I compare cm and cm2, I notice that the confusion matrices
 are identical although the accuracy of each model is diffent. What am I
 doing wrong? 
   
 Thanks for you help,





-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/e1071-SVM-Cross-validation-error-confusion-matrix-tp4651652p4651692.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] simple subset question

2012-12-02 Thread David Winsemius
The reason I suggested the alternative that I did was because your  
code could fail when the max(Total) value was not in the subset where  
Year==2012.


--
David
On Dec 2, 2012, at 11:34 AM, Felipe Carrillo wrote:



Using my whole dataset I get:
library(plyr)
ddply(winter,Year,summarise,maxTotal=max(Total))

 fish - structure(list(Year = 2002:2012, maxTotal = c(1464311L,  
1071051L,

714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L,
157260L, 303259L)), .Names = c(Year, maxTotal), row.names = c(NA,
-11L), class = data.frame)

I only want to extract the max Total for 2012 and want the whole row  
like this:

 IDWeek  Total   Fry  Smolt  FryEq Year
21 47 303259 34008 269248 491733 2012

My whole dataset is too big to post it so thanks for your help and  
will try

to figure out why subset returns an empty row

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: William Dunlap wdun...@tibco.com
To: Felipe Carrillo mazatlanmex...@yahoo.com; arun smartpink...@yahoo.com 


Cc: R help r-help@r-project.org
Sent: Sunday, December 2, 2012 11:00 AM
Subject: RE: [R] simple subset question


I am
still getting an error message

with :
  x - subset(fish,Year==2012  Total==max(Total));x
I get:
[1] IDWeek Total  FrySmolt  FryEq  Year
0 rows (or 0-length row.names)


The above is not an error message.  It says that there
are no rows satisfying your criteria.  Note that Total==max(Total)
returns a TRUE for each row in which the Total value
equals the maximum Total value over all the years in
the data.  Are you looking for the maximum value of Total
in each year?


tmp - transform(fish, YearlyMaxTotal = ave(Total, Year, FUN=max))
subset(tmp, Total==YearlyMaxTotal)

  IDWeek  TotalFry  Smolt  FryEq Year YearlyMaxTotal
2147 303259  34008 269248 491733 2012303259
3939 157260 156909351 157506 2011157260

subset(tmp, Total==YearlyMaxTotal  Year==2012)

  IDWeek  Total  Fry  Smolt  FryEq Year YearlyMaxTotal
2147 303259 34008 269248 491733 2012303259

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
] On Behalf

Of Felipe Carrillo
Sent: Sunday, December 02, 2012 10:47 AM
To: arun
Cc: R help
Subject: Re: [R] simple subset question

Works with the small dataset (2 years) but I get the error message  
with the whole

dataset (12 years of data). I am going to have
to check what's wrong with it...Thanks

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: arun smartpink...@yahoo.com

To: Felipe Carrillo mazatlanmex...@yahoo.com
Cc: R help r-help@r-project.org; R. Michael Weylandt

michael.weyla...@gmail.com

Sent: Sunday, December 2, 2012 10:29 AM
Subject: Re: [R] simple subset question

Hi,
I am getting this:
x-subset(fish,Year==2012  Total==max(Total))
 x
#   IDWeek  Total   Fry  Smolt  FryEq Year
#21 47 303259 34008 269248 491733 2012
A.K.




- Original Message -
From: Felipe Carrillo mazatlanmex...@yahoo.com
To: R. Michael Weylandt michael.weyla...@gmail.com
Cc: r-help@r-project.org r-help@r-project.org
Sent: Sunday, December 2, 2012 1:25 PM
Subject: Re: [R] simple subset question

Sorry, I was trying it to subset from a bigger dataset called  
'winter' and forgot to

change the variable names
when I asked the question. David W suggestion works but the  
strange part is that I am

still getting an error message

with :
  x - subset(fish,Year==2012  Total==max(Total));x
I get:
[1] IDWeek Total  FrySmolt  FryEq  Year
0 rows (or 0-length row.names)

I will start a fresh session to see if that helps...Thank you all

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: R. Michael Weylandt michael.weyla...@gmail.com

To: Felipe Carrillo mazatlanmex...@yahoo.com
Cc: r-help@r-project.org r-help@r-project.org
Sent: Sunday, December 2, 2012 9:42 AM
Subject: Re: [R] simple subset question

On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
mazatlanmex...@yahoo.com wrote:

  Hi,
Consider the small dataset below, I want to subset by two  
variables in
one line but it wont work...it works though if I subset  
separately. I have
to be missing something obvious that I did not realize before  
while using subset..


fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L,  
33L,

34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L,  
53015L,
91689L, 

Re: [R] simple subset question

2012-12-02 Thread Felipe Carrillo
I also thought that I could use it but ggplot didn't like it by itself,,,it 
wants to whole rowI guess it is hard
to understand because I didn't post all the ggplot code of what I am trying to 
accomplish. The strangest thing is that
ddply can extract all my Totals by year but when I try to subset only one year 
out of my whole dataset, it returns
empty rows it regardless of what year I am subsetting. I am doing  a few tests 
to see what's going on

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: David Winsemius dwinsem...@comcast.net
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Cc: William Dunlap wdun...@tibco.com; arun smartpink...@yahoo.com; R help 
r-help@r-project.org 
Sent: Sunday, December 2, 2012 11:54 AM
Subject: Re: [R] simple subset question

The reason I suggested the alternative that I did was because your code could 
fail when the max(Total) value was not in the subset where Year==2012.

--David
On Dec 2, 2012, at 11:34 AM, Felipe Carrillo wrote:

 
 Using my whole dataset I get:
 library(plyr)
 ddply(winter,Year,summarise,maxTotal=max(Total))
 
  fish - structure(list(Year = 2002:2012, maxTotal = c(1464311L, 1071051L,
 714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L,
 157260L, 303259L)), .Names = c(Year, maxTotal), row.names = c(NA,
 -11L), class = data.frame)
 
 I only want to extract the max Total for 2012 and want the whole row like 
 this:
  IDWeek  Total  Fry  Smolt  FryEq Year
 21    47 303259 34008 269248 491733 2012
 
 My whole dataset is too big to post it so thanks for your help and will try
 to figure out why subset returns an empty row
 
 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx
 
 
 From: William Dunlap wdun...@tibco.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com; arun 
 smartpink...@yahoo.com
 Cc: R help r-help@r-project.org
 Sent: Sunday, December 2, 2012 11:00 AM
 Subject: RE: [R] simple subset question
 
 I am
 still getting an error message
 with :
  x - subset(fish,Year==2012  Total==max(Total));x
 I get:
 [1] IDWeek Total  Fry    Smolt  FryEq  Year
 0 rows (or 0-length row.names)
 
 The above is not an error message.  It says that there
 are no rows satisfying your criteria.  Note that Total==max(Total)
 returns a TRUE for each row in which the Total value
 equals the maximum Total value over all the years in
 the data.  Are you looking for the maximum value of Total
 in each year?
 
 tmp - transform(fish, YearlyMaxTotal = ave(Total, Year, FUN=max))
 subset(tmp, Total==YearlyMaxTotal)
  IDWeek  Total    Fry  Smolt  FryEq Year YearlyMaxTotal
 21    47 303259  34008 269248 491733 2012        303259
 39    39 157260 156909    351 157506 2011        157260
 subset(tmp, Total==YearlyMaxTotal  Year==2012)
  IDWeek  Total  Fry  Smolt  FryEq Year YearlyMaxTotal
 21    47 303259 34008 269248 491733 2012        303259
 
 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com
 
 
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
 On Behalf
 Of Felipe Carrillo
 Sent: Sunday, December 02, 2012 10:47 AM
 To: arun
 Cc: R help
 Subject: Re: [R] simple subset question
 
 Works with the small dataset (2 years) but I get the error message with 
 the whole
 dataset (12 years of data). I am going to have
 to check what's wrong with it...Thanks
 
 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx
 
 
 From: arun smartpink...@yahoo.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Cc: R help r-help@r-project.org; R. Michael Weylandt
 michael.weyla...@gmail.com
 Sent: Sunday, December 2, 2012 10:29 AM
 Subject: Re: [R] simple subset question
 
 Hi,
 I am getting this:
 x-subset(fish,Year==2012  Total==max(Total))
  x
 #  IDWeek  Total  Fry  Smolt  FryEq Year
 #21    47 303259 34008 269248 491733 2012
 A.K.
 
 
 
 
 - Original Message -
 From: Felipe Carrillo mazatlanmex...@yahoo.com
 To: R. Michael Weylandt michael.weyla...@gmail.com
 Cc: r-help@r-project.org r-help@r-project.org
 Sent: Sunday, December 2, 2012 1:25 PM
 Subject: Re: [R] simple subset question
 
 Sorry, I was trying it to subset from a bigger dataset called 'winter' 
 and forgot to
 change the variable names
 when I asked the question. David W suggestion works but the strange part 
 is that I am
 still getting an error message
 with :
  x - subset(fish,Year==2012  Total==max(Total));x
 I get:
 [1] IDWeek Total  Fry    Smolt  FryEq  Year
 0 rows (or 0-length row.names)
 
 I will start a fresh session to see if that helps...Thank you all
 
 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 

Re: [R] Line numbers with errors and warnings?

2012-12-02 Thread Milan Bouchet-Valat
Le dimanche 02 décembre 2012 à 14:21 -0500, Duncan Murdoch a écrit :
 On 12-12-02 9:52 AM, Milan Bouchet-Valat wrote:
  Le dimanche 02 décembre 2012 à 09:02 -0500, Duncan Murdoch a écrit :
  On 12-12-02 8:33 AM, Milan Bouchet-Valat wrote:
  Le dimanche 02 décembre 2012 à 06:02 -0500, Steve Lianoglou a écrit :
  Hi,
 
  On Sun, Dec 2, 2012 at 12:31 AM, Worik R wor...@gmail.com wrote:
  What I mean is how do I get the R compilation or execution process to 
  spit
  out a line number with errors and warnings?
  Indeed, I often suffer from the same problem when debugging R code too.
  This is a real issue for me.
 
  As Duncan mentioned already, you can't *always* get a line number. You
  can, however, usually get enough context around the failing call for
  you to be able to smoke the problem out.
  What are the cases where you cannot get line numbers? Duncan said
  source()ed code comes with line numbers, but what's the more general
  rule?
 
  The general rule is that parse() needs to be called with the srcfile
  argument set to a srcfile object.  source() does that by default.
  OK. But isn't it technically possible to compute a line number even when
  no source file is present?
 
 Yes, you don't really need to have a file present, you just need a 
 srcfile object.  For example, on Windows when you use 
 source(clipboard), there's no file, just the system clipboard.
 
   If you call fix() on any function, you will
  get something like a source file even if srcfile was not set.
 
 Yes, and then you can call source on that object, and you'll get line 
 number information attached, relative to whatever you sourced.
 
 
 So it
  could make sense to have a line number referring to what you would see
  in fix(). Or at least, the last executed line when calling browser() or
  when using options(error=recover), like gdb does.
 
 The thing is that if you didn't attach the line number information to 
 the code, then it's not there.  R can't figure out after the fact where 
 the code came from.  It needs to have the debug info in place when it 
 runs it.  How could R figure out where some expression came from that it 
 happens to be executing?  Using eval() on a constructed expression in a 
 function is not all that uncommon, but to the evaluator, it looks just 
 like any other evaluation.
OK.

  This could be especially useful for packages that were not installed
  with keep.source=TRUE. It could even help getting more useful error
  messages on R-help...
 
 If you're debugging a package, then why not install it with 
 keep.source=TRUE?
Of course. I just wondered whether this step could possibly be avoided.
It can be useful to have debugging details when casual users report a
bug, without reinstalling the package. Not a big deal, though.


Regards

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


Re: [R] cubic spline

2012-12-02 Thread Steve Stephenson
Dear all,
many thanks for your answer and support!!
Steve




--
View this message in context: 
http://r.789695.n4.nabble.com/cubic-spline-tp4651537p4651698.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] What is ts command for?

2012-12-02 Thread Hard Core
Hello, i'm here to have  an explenation about time series
I have to analize a time series of a stock prices and i don't understand the
meaning of ts .. 

i load, for instance 

mps - get.hist.quote(instrument = bmps.mi , quote=Close,
start=2006-01-01, end=2012-09-30, compression=d)

and i get a value mps(zoo) ...

if i run mps i get this :
http://r.789695.n4.nabble.com/file/n4651620/Immagine.png 

isn't that a time series already? why do i have to transform it with ts or
read.ts?
I don't get the point
Thank you for your availability
Have a good day




--
View this message in context: 
http://r.789695.n4.nabble.com/What-is-ts-command-for-tp4651620.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] function stays in loop

2012-12-02 Thread Mkkl
function - function(p){
i - 2
r - 0
while(i  p) {
q - (p/i)
while(q=1) {
q=(q-1)
}
if (q==0) {
r=1
}   else 
i=i+1
}
return(r)
}

This function stays in some kind of loop when I enter 4 as a function value.
It immediately returns 0 when I inter 3 though.
I don't seem te get why it does not give me just a result. Can someone tell
me why it stays in a loop?

Kind regards,

Michiel



--
View this message in context: 
http://r.789695.n4.nabble.com/function-stays-in-loop-tp4651619.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] Fwd: How to calculate different groups of varialbes importance level?

2012-12-02 Thread Solmaz Filiz KARABAĞ
Dear R user!
I have a small question!
I have calculated the relative importance of the variables.

However I would like to compare the relative importance of two different
groups of variables (i.e Strategy and industry)

For example let me say that strategy has 2 sub varialbes and industry has
four different variables!

Can I simply add the importance of those four industry variables importance
over each other  and say that the importance level of industry is the total
of those four varibales' importance?
Can I also do the same thing and add the importance of two strategic
variables and have a strategic level importance?

After these simple calculation, can I compare the importance of those
groups?

Thanks for the kind help
Best regards

--
 Solmaz Filiz KARABAG




--
 Solmaz Filiz KARABAG

[[alternative HTML version deleted]]





-- 
 Solmaz Filiz KARABAG

[[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] Daily Time Series, patterns.

2012-12-02 Thread arun
HI,
I guess you can check library(forecast).

You could also use ?stl(), though not sure whether this will help you in this 
case.
For e.g.
set.seed(5)
quantity-sample(c(120:220,NA),699,replace=TRUE)
Date=seq(as.Date(2011-01-01),len=699,by=1 day)
dat3-data.frame(Date=Date,quantity=quantity)
library(zoo)
 z - zooreg(dat3[,2], frequency = 7)
 plot(stl(na.approx(z),per))

A.K.





- Original Message -
From: mekbatub mekba...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Saturday, December 1, 2012 8:00 PM
Subject: Re: [R] Daily Time Series, patterns.

Hi Arun, thx for Your reply.

thats interesting, but its not what I mean.

I know that there is some patterns in data, example:

the highest value of the sale is on Monday, and the smallest on Wednesday
and so on, there might be trend also

I am trying to build forecasting model that will include patterns like that,
for example forecast to next 5 days. So i think I can say that is weekly
sesonality, i believe the metod to make correct model is to decompose time
series like there.

http://otexts.com/fppfigs/elecequip_stl.png
http://otexts.com/fppfigs/elecequip_stl.png  

Do You think I am right? In any case, I have big problem to do this in R. 



--
View this message in context: 
http://r.789695.n4.nabble.com/Daily-Time-Series-patterns-tp4651569p4651591.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] help setting up crossed data

2012-12-02 Thread derrick
Hello, and thanks for your time reading this.   I'm trying to test
interactions of my dataset, in which the all of the factors are within the
same column.  
TypeVol
1   CMass   -4.598
2   BBack   -4.605
3   BMass   -4.602
4   CMass   -4.601
5   CBack   -4.605
6   CMass   -4.604
7   CMass   -4.602
8   CMass   -4.604
9   CBack   -4.605
10  BBack   -4.503
11  CMass   -4.605

Im attempting to determine the interaction effects of B or C on Mass and
Back
Looking for a set up as such Volume ~ CorB + MassorBack + CorB:MassorBack
is there an easy way to arrange the data so I can have the factors in column
1 broken down as I'd like?  

Here if my current setup of the situation, In which I don't consider the
interactions.  please forgive the armature coding.

if (T) {
  #Arrange all data in a 2 column matrix as such: [Tissue Type, Measure]
  measure = matrix(NA,4812,2)
  measure=data.frame(measure)
  for (i in a:b) {
#loads threshold factor
measure[,1] = data[,1]
#loads ith threshold
measure[,2] = data[,i]
measure$X1=factor(measure$X1, levels =
c('CMass','BMass','CBack','BBack'))
measure.aov= aov(X2 ~ X1,data = measure)
#prints results
print(TukeyHSD(measure.aov, order= TRUE, conf.level = .995))
  }
}







--
View this message in context: 
http://r.789695.n4.nabble.com/help-setting-up-crossed-data-tp4651674.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] CreateThread failure since R 2.15.2 (32-bit)

2012-12-02 Thread Martin Studer
I tried with Java 1.6.0_20 and 1.7.0_09. It actually doesn't matter what
command I'm running with system. Any command will fail with the same error
message. But for the example I posted, yes, I was using ls from Rtools.

I found that I can only reproduce this with R 2.15.2+  32-bit on Windows
32-bit. There are no issues with R 2.15.2+ 32-bit on Windows 64-bit.

Best regards,
Martin






--
View this message in context: 
http://r.789695.n4.nabble.com/CreateThread-failure-since-R-2-15-2-32-bit-tp4651411p4651651.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] simple subset question

2012-12-02 Thread arun
Hi,
I am getting this:
x-subset(fish,Year==2012  Total==max(Total))
 x
#   IDWeek  Total   Fry  Smolt  FryEq Year
#21 47 303259 34008 269248 491733 2012
A.K.




- Original Message -
From: Felipe Carrillo mazatlanmex...@yahoo.com
To: R. Michael Weylandt michael.weyla...@gmail.com
Cc: r-help@r-project.org r-help@r-project.org
Sent: Sunday, December 2, 2012 1:25 PM
Subject: Re: [R] simple subset question

Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
forgot to change the variable names
when I asked the question. David W suggestion works but the strange part is 
that I am still getting an error message
with :
  x - subset(fish,Year==2012  Total==max(Total));x
I get:
[1] IDWeek Total  Fry    Smolt  FryEq  Year  
0 rows (or 0-length row.names)
 
I will start a fresh session to see if that helps...Thank you all

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: R. Michael Weylandt michael.weyla...@gmail.com
To: Felipe Carrillo mazatlanmex...@yahoo.com 
Cc: r-help@r-project.org r-help@r-project.org 
Sent: Sunday, December 2, 2012 9:42 AM
Subject: Re: [R] simple subset question

On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
mazatlanmex...@yahoo.com wrote:
  Hi,
 Consider the small dataset below, I want to subset by two variables in
 one line but it wont work...it works though if I subset separately. I have
 to be missing something obvious that I did not realize before while using 
 subset..

 fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
 13221L, 4894L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
 30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
 1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L), Smolt = c(0L, 0L, 0L,
 0L, 0L, 0L, 0L, 62L, 0L, 0L, 38L, 195L, 433L, 3518L, 7067L, 11290L,
 23058L, 10327L, 68712L, 64328L, 269248L, 19479L, 0L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 147L, 238L, 0L, 131L, 351L,
 905L, 1592L, 4324L, 13391L, 16414L, 20774L, 19444L, 14491L, 35330L,
 31142L, 7736L, 13221L, 4894L), FryEq = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8864L, 6060L, 19326L, 63185L, 100854L, 53318L,
 94151L, 157576L, 130610L, 77432L, 22805L, 134639L, 120393L, 491733L,
 33327L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13306L, 19894L, 30518L, 85042L, 157506L, 146328L, 86914L, 65073L,
 53812L, 34763L, 36931L, 33769L, 24998L, 60110L, 52938L, 13149L,
 22476L, 8319L), Year = c(2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
 2012L, 2012L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
 2011L)), .Names = c(IDWeek, Total, Fry, Smolt, FryEq,
 Year), row.names = c(NA, 52L), class = data.frame)
 fish
 #  Subset to get the max Total for 2012
  x - subset(winter,Year==2012  Total==max(Total));b  # How come one line 
doesn't work?

Works fine for me if I change winter to fish here.

subset(fish,Year==2012  Total==max(Total))
  IDWeek  Total  Fry  Smolt  FryEq Year
21    47 303259 34008 269248 491733 2012


  # It works if I subset the year first and then get the Total max from it
  xx - subset(winter,Year==2012)
 xxx - subset(xx,Total==max(Total));xxx
 xxx

 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx

        [[alternative HTML version deleted]]


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




    [[alternative HTML version deleted]]


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

Re: [R] How to calculate mean of every nth time series data with zoo or xts ?

2012-12-02 Thread arun
Hi,
You could use:
set.seed(5)
dat1-data.frame(Date=seq(from=as.POSIXct(2012-11-01 
00:00:00),to=as.POSIXct(2012-11-03 23:59:00),  by=1 
min),col2=rnorm(4320,0,1))
library(xts)
dat2-xts(dat1[,-1],order.by=dat1[,1])
res-ave(dat2[,1],format(index(dat2),%H:%M),FUN=mean)
#or
res-tapply(dat2[,1],format(index(dat2),%H:%M),FUN=mean)
head(res)
# 00:00   00:01   00:02   00:03   00:04   00:05 
#-0.50875473  0.07165023 -0.35019421  0.44377065  0.61380169  0.21490898 
A.K.





- Original Message -
From: 박상규 birdfir...@naver.com
To: r-help@r-project.org
Cc: 
Sent: Sunday, December 2, 2012 1:09 PM
Subject: [R] How to calculate mean of every nth time series data with zoo or 
xts ?

Hello,


I have 1-minute time series stock data and I'd like to calculate mean of every 
n-th candle data of m-days.


result = c(mean of 1th data, mean of 2nd data, ...)


mean of 1th data = (1th data of 2012-1-1 + 1th data of 2012-1-2 + 1th data of 
2012-1-3) / 3

mean of 2nd data = (2nd data of 2012-1-1 + 2nd data of 2012-1-2 + 2nd data of 
2012-1-3) / 3
...

Could you let me know the fastest method ?


Thanks in advance,



    [[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] Warning message: In scan(file, what, nmax...)

2012-12-02 Thread F86
Dear R-users,

When i try  -
Data1-read.table(/Users/kama/Analysis/GDP10.csv,header=TRUE,sep=;)  i
am getting this error: Warning message: In scan(file, what, nmax, sep, dec,
quote, skip, nlines, na.strings,  :
  number of items read is not a multiple of the number of columns

I wonder what Iam doing wrong. i guess it is something simple, however, i do
not understand the help-function in R. 


Thank you,


Regards, 
Faradj
Stockholm university
Department of Political Science 




--
View this message in context: 
http://r.789695.n4.nabble.com/Warning-message-In-scan-file-what-nmax-tp4651689.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] Repeated-measures anova with a within-subject covariate (or varying slopes random-effects?)

2012-12-02 Thread Giuseppe Pagnoni
Dear all,

I am having quite a hard time in trying to figure out how to correctly
spell out a model in R (a repeated-measures anova with a
within-subject covariate, I guess).  Even though I have read in the
posting guide that statistical advice may or may not get an answer on
this list, I decided to try it anyway, hoping not to incur in
somebody's ire for misusing the tool.

For the sake of clarity, I will explain the problem.

We conducted an experiment measuring average response times in a
cognitive task. The task has two types of stimuli (stim1, stim2) and
was performed in a 6-run session, where subjects performed the task
under condition A on odd-numbered runs and under condition B on
even-numbered runs.  Thus, the temporal sequence of the runs was the
following:

- run 1: cond A
- run 2: cond B
- run 3: cond A
- run 4: cond B
- run 5: cond A
- run 6: cond B

where for each run and for each subject, an average RT was collected
for stim1 and for stim2.

After collecting and plotting the data, an approximately linear
decrease in RT from run1 to run6 was apparent in most subjects
(practice effect: subjects become better and faster with time).

Now, I am struggling with how to properly specify a model to perform
the group analysis by taking into account this confounding practice
effect, so that the real effects of interest (the main effect of
condition, and the interaction of condition and stimulus type) can be
better assessed.

 I used a dataframe in long format, with `subj', `rt' (response time),
`stim' (stim1, stim2), `cond' (A, B), and `run' (1 to 6) as columns,
where `run' is coded as an integer so that it can be used for modeling
a linear trend. The R command I tried is:

  rt.aov - aov(rt ~ run + stim * cond + Error(subj /(run + stim *
cond)), data=rt.df)

but I am not at all sure that the error term is correctly specified.

Furthermore, we have also collected data on an additional batch of
subjects that performed the task in the 6-run session but with the
order of conditions A and B reversed (A on even-numbered runs and B on
odd-numbered runs); now, if we wanted to analyze the data from the two
groups of subjects together, by including a between-subjects group
factor (groupAB, groupBA), would the model specification become
something like the following?

rt.aov - aov(rt ~ run + group * stim * cond + Error(subj /(run +
stim * cond)), data=rt.df)

Perhaps should lme() be used instead (and with which formula?)?

Many thanks in advance to anybody who'd be so kind to offer their
advice or tip on this.  I have scoured the web and some textbooks for
a few days now, but to little avail.

very best

giuseppe


-- 
Giuseppe Pagnoni
Dip. Scienze Biomediche, Metaboliche e Neuroscienze
Sezione Fisiologia e Neuroscienze
Univ. di Modena e Reggio Emilia
Via Campi 287
I-41125 Modena, Italy
Tel: +39-059-205-5742
Fax: +39-059-205-5363

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Change case of factor in data frame

2012-12-02 Thread Audrey
I am trying to write a function to change the case of all of the text in a
data frame to lower case.  I do not have foreknowledge of the data frame
names or the data types of each column. 

It seems that if one references the data frame by index, then it returns
class data.frame but if it is referenced by name, it returns class
factor or whatever the column actually is:
dat[1] returns class data.frame but 
dat$name returns class factor

The problem is that, when one applies the tolower() and toupper() functions,
dat$name will return a column of lower/uppercase returns (now class
character) but dat[1] will return an array of factor level indexes.
Specifying dat[1] as.character during the function call does not work (e.g.
tolower(as.character(dat[1]))). 

So, I would loop over the column names, but I can not figure out how to
generically call them:
tst=names(dat);
dat$(tst[1]) returns an error
dat[tst[1]] returns class data.frame again

Thank you in advance!

change_case-function(dat,wcase){
  # change case
  res=sapply(dat,class); # get classes
  ind-res=='character';
  dat[ind]-switch(wcase,
   'lower'=tolower(dat[ind]),
   'upper'=toupper(dat[ind])
  )
  rm(ind);
  ind-res=='factor';
  dat[ind]-switch(wcase,
   'lower'=factor(tolower(as.character(dat[ind]))),
   'upper'=factor(toupper(as.character(dat[ind])))
  )
  return(dat);
}



--
View this message in context: 
http://r.789695.n4.nabble.com/Change-case-of-factor-in-data-frame-tp4651696.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] marginal structural modeling

2012-12-02 Thread John Sorkin

Does anyone know an R package that implements marginal structural modeling as 
described by Jamie Robins? A similar question was asked of the list 
approximately two-years ago and it does not appear that anyone responded. 
Thanks,
John Sorkin 
 John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
Confidentiality Statement:
This email message, including any attachments, is for the sole use of the 
intended recipient(s) and may contain confidential and privileged information.  
Any unauthorized use, disclosure or distribution is prohibited.  If you are not 
the intended recipient, please contact the sender by reply email and destroy 
all copies of the original message. 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] simple subset question

2012-12-02 Thread arun
Hi,
From the ddply() output, you could get the whole row by:

 fish1 - structure(list(Year = 2002:2012, maxTotal = c(1464311L, 1071051L, 
714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L, 
157260L, 303259L)), .Names = c(Year, maxTotal), row.names = c(NA, 
-11L), class = data.frame)


 fish[fish[,2]%in%fish1[,2][fish1[,1]==2012],]  #fish (or winter) is your 
original dataset
#   IDWeek  Total   Fry  Smolt  FryEq Year
#21 47 303259 34008 269248 491733 2012
A.K.






From: Felipe Carrillo mazatlanmex...@yahoo.com
To: William Dunlap wdun...@tibco.com; arun smartpink...@yahoo.com 
Cc: R help r-help@r-project.org 
Sent: Sunday, December 2, 2012 2:34 PM
Subject: Re: [R] simple subset question



Using my whole dataset I get:
library(plyr)
ddply(winter,Year,summarise,maxTotal=max(Total))

 fish - structure(list(Year = 2002:2012, maxTotal = c(1464311L, 1071051L, 
714837L, 2115018L, 850491L, 207537L, 321195L, 935599L, 194429L, 
157260L, 303259L)), .Names = c(Year, maxTotal), row.names = c(NA, 
-11L), class = data.frame)

I only want to extract the max Total for 2012 and want the whole row like this:
 IDWeek  Total   Fry  Smolt  FryEq Year
21 47 303259 34008 269248 491733 2012

My whole dataset is too big to post it so thanks for your help and will try
to figure out why subset returns an empty row

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx



From: William Dunlap wdun...@tibco.com
To: Felipe Carrillo mazatlanmex...@yahoo.com; arun smartpink...@yahoo.com 
Cc: R help r-help@r-project.org 
Sent: Sunday, December 2, 2012 11:00 AM
Subject: RE: [R] simple subset question

 I am
 still getting an error message
 with :
   x - subset(fish,Year==2012
 Total==max(Total));x
 I get:
 [1] IDWeek Total  Fry    Smolt  FryEq  Year
 0 rows (or 0-length row.names)

The above is not an error message.  It says that there
are no rows satisfying your criteria.  Note that Total==max(Total)
returns a TRUE for each row in which the Total value
equals the maximum Total value over all the years in
the data.  Are you looking for the maximum value of Total
in each year?

 tmp - transform(fish, YearlyMaxTotal = ave(Total, Year, FUN=max))
 subset(tmp, Total==YearlyMaxTotal)
  IDWeek  Total    Fry  Smolt  FryEq Year YearlyMaxTotal
21    47 303259  34008 269248 491733 2012        303259
39    39 157260 156909    351 157506 2011        157260
 subset(tmp, Total==YearlyMaxTotal
 Year==2012)
  IDWeek  Total  Fry  Smolt  FryEq Year YearlyMaxTotal
21    47 303259 34008 269248 491733 2012        303259

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Felipe Carrillo
 Sent: Sunday, December 02, 2012 10:47 AM
 To: arun
 Cc: R help
 Subject: Re: [R] simple subset question
 
 Works with the small dataset (2 years) but I get the error message with the 
 whole
 dataset (12 years of data). I am going to have
 to check what's
wrong with it...Thanks
 
 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx
 
 
 From: arun smartpink...@yahoo.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Cc: R help r-help@r-project.org; R. Michael Weylandt
 michael.weyla...@gmail.com
 Sent: Sunday, December 2, 2012 10:29 AM
 Subject: Re: [R] simple subset question
 

Hi,
 I am getting this:
 x-subset(fish,Year==2012  Total==max(Total))
  x
 #   IDWeek  Total   Fry  Smolt  FryEq Year
 #21 47 303259 34008 269248 491733 2012
 A.K.
 
 
 
 
 - Original Message -
 From: Felipe Carrillo mazatlanmex...@yahoo.com
 To: R. Michael Weylandt michael.weyla...@gmail.com
 Cc: r-help@r-project.org r-help@r-project.org
 Sent:
Sunday, December 2, 2012 1:25 PM
 Subject: Re: [R] simple subset question
 
 Sorry, I was trying it to subset from a bigger dataset called 'winter' and 
 forgot to
 change the variable names
 when I asked the question. David W suggestion works but the strange part is 
 that I am
 still getting an error message
 with :
   x - subset(fish,Year==2012  Total==max(Total));x
 I get:
 [1] IDWeek Total  Fry    Smolt  FryEq  Year
 0 rows (or 0-length row.names)
 
 I will start a fresh session to see if that helps...Thank you all
 
 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx
 
 
 From: R. Michael Weylandt michael.weyla...@gmail.com
 To: Felipe Carrillo mazatlanmex...@yahoo.com
 Cc: r-help@r-project.org r-help@r-project.org
 Sent: Sunday, December 2, 2012 9:42 AM
 Subject: Re: [R] simple subset question
 
 On Sun, Dec 2, 2012 at 5:21 PM, Felipe Carrillo
 mazatlanmex...@yahoo.com wrote:
   Hi,
  Consider the small dataset below, I want to subset by 

Re: [R] Line numbers with errors and warnings?

2012-12-02 Thread John Sorkin
Gentleman,
This thread has been of great interest. Perhaps I missed part of it,
but do far I have not seen an example of code that has line numbers that
demonstrates how one can (in some instances) recover the line number of
an error. Can I impose upon the people who contributed to this thread to
post example code? The question if very important, and the discussion
about solutions has been somewhat abstract to this point.
Thank you,
John

 
John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
Milan Bouchet-Valat nalimi...@club.fr 12/2/2012 4:00 PM 
Le dimanche 02 décembre 2012 à 14:21 -0500, Duncan Murdoch a écrit :
 On 12-12-02 9:52 AM, Milan Bouchet-Valat wrote:
  Le dimanche 02 décembre 2012 à 09:02 -0500, Duncan Murdoch a écrit
:
  On 12-12-02 8:33 AM, Milan Bouchet-Valat wrote:
  Le dimanche 02 décembre 2012 à 06:02 -0500, Steve Lianoglou a
écrit :
  Hi,
 
  On Sun, Dec 2, 2012 at 12:31 AM, Worik R wor...@gmail.com
wrote:
  What I mean is how do I get the R compilation or execution
process to spit
  out a line number with errors and warnings?
  Indeed, I often suffer from the same problem when debugging R
code too.
  This is a real issue for me.
 
  As Duncan mentioned already, you can't *always* get a line
number. You
  can, however, usually get enough context around the failing call
for
  you to be able to smoke the problem out.
  What are the cases where you cannot get line numbers? Duncan
said
  source()ed code comes with line numbers, but what's the more
general
  rule?
 
  The general rule is that parse() needs to be called with the
srcfile
  argument set to a srcfile object.  source() does that by default.
  OK. But isn't it technically possible to compute a line number even
when
  no source file is present?
 
 Yes, you don't really need to have a file present, you just need a 
 srcfile object.  For example, on Windows when you use 
 source(clipboard), there's no file, just the system clipboard.
 
   If you call fix() on any function, you will
  get something like a source file even if srcfile was not set.
 
 Yes, and then you can call source on that object, and you'll get line

 number information attached, relative to whatever you sourced.
 
 
 So it
  could make sense to have a line number referring to what you would
see
  in fix(). Or at least, the last executed line when calling
browser() or
  when using options(error=recover), like gdb does.
 
 The thing is that if you didn't attach the line number information to

 the code, then it's not there.  R can't figure out after the fact
where 
 the code came from.  It needs to have the debug info in place when it

 runs it.  How could R figure out where some expression came from that
it 
 happens to be executing?  Using eval() on a constructed expression in
a 
 function is not all that uncommon, but to the evaluator, it looks
just 
 like any other evaluation.
OK.

  This could be especially useful for packages that were not
installed
  with keep.source=TRUE. It could even help getting more useful
error
  messages on R-help...
 
 If you're debugging a package, then why not install it with 
 keep.source=TRUE?
Of course. I just wondered whether this step could possibly be
avoided.
It can be useful to have debugging details when casual users report a
bug, without reinstalling the package. Not a big deal, though.


Regards

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

Confidentiality Statement:
This email message, including any attachments, is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information.  Any unauthorized use, disclosure or distribution is
prohibited.  If you are not the intended recipient, please contact the
sender by reply email and destroy all copies of the original message. 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Line numbers with errors and warnings?

2012-12-02 Thread Duncan Murdoch

On 12-12-02 5:02 PM, John Sorkin wrote:

Gentleman,
This thread has been of great interest. Perhaps I missed part of it, but
do far I have not seen an example of code that has line numbers that
demonstrates how one can (in some instances) recover the line number of
an error. Can I impose upon the people who contributed to this thread to
post example code? The question if very important, and the discussion
about solutions has been somewhat abstract to this point.


From my post this morning:


For example, in Windows, if I put this code into the clipboard:

f - function() {
   stop(this is the error)
}

g - function() {
   f()
}

g()

then run source(clipboard) followed by traceback(), this is what I see:

  source(clipboard)
Error in f() (from clipboard#2) : this is the error
  traceback()
7: stop(this is the error) at clipboard#2
6: f() at clipboard#6
5: g() at clipboard#9
4: eval(expr, envir, enclos)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source(clipboard)

You can ignore entries 1 to 4; they are part of source().  Entries 5, 6,
and 7 each tell the line of the script where they were parsed.

Duncan Murdoch




Thank you,
John

John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
Milan Bouchet-Valat nalimi...@club.fr 12/2/2012 4:00 PM 
Le dimanche 02 décembre 2012 à 14:21 -0500, Duncan Murdoch a écrit :
  On 12-12-02 9:52 AM, Milan Bouchet-Valat wrote:
   Le dimanche 02 décembre 2012 à 09:02 -0500, Duncan Murdoch a écrit :
   On 12-12-02 8:33 AM, Milan Bouchet-Valat wrote:
   Le dimanche 02 décembre 2012 à 06:02 -0500, Steve Lianoglou a écrit :
   Hi,
  
   On Sun, Dec 2, 2012 at 12:31 AM, Worik R wor...@gmail.com wrote:
   What I mean is how do I get the R compilation or execution
process to spit
   out a line number with errors and warnings?
   Indeed, I often suffer from the same problem when debugging R
code too.
   This is a real issue for me.
  
   As Duncan mentioned already, you can't *always* get a line
number. You
   can, however, usually get enough context around the failing call for
   you to be able to smoke the problem out.
   What are the cases where you cannot get line numbers? Duncan said
   source()ed code comes with line numbers, but what's the more general
   rule?
  
   The general rule is that parse() needs to be called with the srcfile
   argument set to a srcfile object.  source() does that by default.
   OK. But isn't it technically possible to compute a line number even
when
   no source file is present?
 
  Yes, you don't really need to have a file present, you just need a
  srcfile object.  For example, on Windows when you use
  source(clipboard), there's no file, just the system clipboard.
 
If you call fix() on any function, you will
   get something like a source file even if srcfile was not set.
 
  Yes, and then you can call source on that object, and you'll get line
  number information attached, relative to whatever you sourced.
 
 
  So it
   could make sense to have a line number referring to what you would see
   in fix(). Or at least, the last executed line when calling browser() or
   when using options(error=recover), like gdb does.
 
  The thing is that if you didn't attach the line number information to
  the code, then it's not there.  R can't figure out after the fact where
  the code came from.  It needs to have the debug info in place when it
  runs it.  How could R figure out where some expression came from that it
  happens to be executing?  Using eval() on a constructed expression in a
  function is not all that uncommon, but to the evaluator, it looks just
  like any other evaluation.
OK.

   This could be especially useful for packages that were not installed
   with keep.source=TRUE. It could even help getting more useful error
   messages on R-help...
 
  If you're debugging a package, then why not install it with
  keep.source=TRUE?
Of course. I just wondered whether this step could possibly be avoided.
It can be useful to have debugging details when casual users report a
bug, without reinstalling the package. Not a big deal, though.


Regards

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

*_Confidentiality Statement:_*

This email message, including any attachments, is for ...{{dropped:7}}


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

Re: [R] simple subset question

2012-12-02 Thread Felipe Carrillo
Actually, I dput(winter) and is not that big.so here is the whole thing I
am trying to accomplish. 
 winter - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
13221L, 4894L, 0L, 460L, 1129L, 1757L, 11105L, 27730L, 55769L,
12298L, 32964L, 80110L, 160507L, 74134L, 101736L, 138355L, 107873L,
53806L, 194429L, 7596L, 55497L, 30336L, 18392L, 22291L, 16850L,
16567L, 14799L, 7909L, 93L, 329L, 363L, 2762L, 5573L, 33466L,
96762L, 340947L, 612835L, 347972L, 526506L, 656981L, 344181L,
145465L, 150543L, 935599L, 32789L, 15092L, 7288L, 9889L, 6945L,
5138L, 6299L, 3095L, 108227L, 1191L, 0L, 0L, 132L, 227L, 2157L,
7558L, 16459L, 87220L, 321195L, 209299L, 110807L, 112024L, 128058L,
74373L, 41531L, 15111L, 21890L, 15060L, 22538L, 12443L, 11052L,
3907L, 2640L, 2745L, 3936L, 17593L, 0L, 0L, 10775L, 4166L, 4958L,
16221L, 29401L, 34951L, 33188L, 146044L, 105007L, 185297L, 159682L,
207537L, 140694L, 128275L, 44274L, 27079L, 18928L, 10437L, 29984L,
18395L, 25846L, 4573L, 31995L, 3679L, 707L, 2390L, 8860L, 24430L,
40885L, 72792L, 205521L, 344493L, 662973L, 526409L, 631953L,
850491L, 842678L, 445987L, 558152L, 332032L, 174326L, 80601L,
48696L, 98571L, 103563L, 149469L, 78081L, 182478L, 2158L, 16566L,
0L, 868L, 2044L, 4064L, 6049L, 9399L, 13304L, 45172L, 242155L,
476864L, 712534L, 1058409L, 2115018L, 1510342L, 1138213L, 333192L,
158820L, 94379L, 348882L, 39290L, 29701L, 47258L, 69837L, 7884L,
49338L, 22168L, 0L, 147L, 1231L, 3216L, 5021L, 18462L, 37441L,
64669L, 136590L, 338523L, 559448L, 714837L, 358037L, 180910L,
291943L, 222708L, 163801L, 39109L, 23247L, 15726L, 38701L, 5795L,
12509L, 18721L, 822L, 6674L, 765L, 1753L, 6226L, 9727L, 22033L,
50472L, 67863L, 100909L, 276699L, 239609L, 416465L, 845073L,
1071051L, 571656L, 409021L, 451331L, 167006L, 68069L, 250439L,
104641L, 76062L, 35261L, 55883L, 16064L, 11058L, 8872L, 9346L,
24760L, 41699L, 40032L, 80576L, 152208L, 171888L, 292862L, 522669L,
441518L, 858538L, 906010L, 1464311L, 1334433L, 542204L, 211514L,
64507L, 94830L, 100663L, 116931L, 83139L, 46268L, 14455L, 22811L,
47446L, 54224L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L, 13055L, 19488L,
30518L, 84818L, 156909L, 144786L, 84207L, 57720L, 31049L, 6858L,
1616L, 719L, 364L, 49L, 0L, 0L, 0L, 0L, 0L, 460L, 1129L, 1757L,
11105L, 27730L, 55769L, 12109L, 32638L, 79547L, 158892L, 72867L,
96249L, 130695L, 88837L, 32531L, 65746L, 1885L, 4188L, 680L,
100L, 109L, 0L, 0L, 0L, 0L, 93L, 329L, 363L, 2762L, 5573L, 33466L,
96694L, 339394L, 611967L, 345807L, 522991L, 645886L, 327353L,
118537L, 109158L, 419571L, 6691L, 456L, 133L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 132L, 227L, 2157L, 7558L, 16459L, 87220L,
320684L, 207921L, 110221L, 110021L, 123153L, 63829L, 23982L,
5090L, 4183L, 374L, 439L, 78L, 67L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
10775L, 4166L, 4958L, 16221L, 29401L, 34851L, 32933L, 145103L,
105007L, 182715L, 153781L, 201622L, 129968L, 87997L, 17235L,
3401L, 1343L, 397L, 316L, 37L, 0L, 0L, 0L, 0L, 707L, 2390L, 8860L,
24430L, 40885L, 72792L, 205521L, 343593L, 658875L, 523360L, 627333L,
847147L, 837189L, 429016L, 523436L, 

[R] Problem with figures

2012-12-02 Thread Shige Song
I am having problem making ggplot2, tikzDevice, and knitr working together.
I used a very simple example:
---example.Rnw-
\documentclass[preview]{standalone}

\begin{document}

\begin{figure}
fig1,eval=TRUE,echo=FALSE,dev='tikz'=
library(ggplot2)
qplot(displ, hwy, data = mpg, colour = factor(cyl))
@
\end{figure}

\end{document}
-
I got ... !  == Fatal error occurred, no output PDF file produced!
label: fig1 (with options)
List of 3
 $ eval: logi TRUE
 $ echo: logi FALSE
 $ dev : chr tikz

Error in process_file(text, output) :
  Quitting from lines 6-8: (test_Rnw.Rnw) Error in
getMetricsFromLatex(TeXMetrics) :
TeX was unable to calculate metrics for the following string
or character:

hwy

Common reasons for failure include:
  * The string contains a character which is special to LaTeX unless
escaped properly, such as % or $.
  * The string makes use of LaTeX commands provided by a package and
the tikzDevice was not told to load the package.

The contents of the LaTeX log of the aborted run have been printed above,
it may contain additional details as to why the metric calculation failed.

Calls: knit - process_file

Execution halted

Best,
Shige

[[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] Line numbers with errors and warnings?

2012-12-02 Thread Steve Lianoglou
Similar to Duncan's example, if you have a script test.R which looks like so:

 start script =
a1 - 1:10
a2 - 101:122
plot(a1, a1)
plot(a1, a2)
 end script ==

You can source it one way:

R source('test.R', keep.source=TRUE)
Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
R traceback()
8: stop('x' and 'y' lengths differ)
7: xy.coords(x, y, xlabel, ylabel, log)
6: plot.default(a1, a2)
5: plot(a1, a2) at test.R#4  ### - Error is on line 4
4: eval(expr, envir, enclos)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source(test.R, keep.source = TRUE)

If you `source(test.R, keep.source=FALSE)`, you will see that the
line number is not reported.

Also:

R library(devtools)
R options(keep.source=TRUE)
R install_github(BadPackage, lianos)
R plot.me(1:10)
Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
R traceback()
5: stop('x' and 'y' lengths differ)
4: xy.coords(x, y, xlabel, ylabel, log)
3: plot.default(x, c(x, 0), pch = 16)
2: plot(x, c(x, 0), pch = 16) at test.R#4   - BAM
1: plot.me(1:10)

HTH,
-steve

On Sun, Dec 2, 2012 at 5:08 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote:
 On 12-12-02 5:02 PM, John Sorkin wrote:

 Gentleman,
 This thread has been of great interest. Perhaps I missed part of it, but
 do far I have not seen an example of code that has line numbers that
 demonstrates how one can (in some instances) recover the line number of
 an error. Can I impose upon the people who contributed to this thread to
 post example code? The question if very important, and the discussion
 about solutions has been somewhat abstract to this point.


 From my post this morning:


 For example, in Windows, if I put this code into the clipboard:

 f - function() {
stop(this is the error)
 }

 g - function() {
f()
 }

 g()

 then run source(clipboard) followed by traceback(), this is what I see:

   source(clipboard)
 Error in f() (from clipboard#2) : this is the error
   traceback()
 7: stop(this is the error) at clipboard#2
 6: f() at clipboard#6
 5: g() at clipboard#9
 4: eval(expr, envir, enclos)
 3: eval(ei, envir)
 2: withVisible(eval(ei, envir))
 1: source(clipboard)

 You can ignore entries 1 to 4; they are part of source().  Entries 5, 6,
 and 7 each tell the line of the script where they were parsed.

 Duncan Murdoch



 Thank you,
 John

 John David Sorkin M.D., Ph.D.
 Chief, Biostatistics and Informatics
 University of Maryland School of Medicine Division of Gerontology
 Baltimore VA Medical Center
 10 North Greene Street
 GRECC (BT/18/GR)
 Baltimore, MD 21201-1524
 (Phone) 410-605-7119
 (Fax) 410-605-7913 (Please call phone number above prior to faxing)
 Milan Bouchet-Valat nalimi...@club.fr 12/2/2012 4:00 PM 
 Le dimanche 02 décembre 2012 à 14:21 -0500, Duncan Murdoch a écrit :
   On 12-12-02 9:52 AM, Milan Bouchet-Valat wrote:
Le dimanche 02 décembre 2012 à 09:02 -0500, Duncan Murdoch a écrit :
On 12-12-02 8:33 AM, Milan Bouchet-Valat wrote:
Le dimanche 02 décembre 2012 à 06:02 -0500, Steve Lianoglou a écrit
 :
Hi,
   
On Sun, Dec 2, 2012 at 12:31 AM, Worik R wor...@gmail.com wrote:
What I mean is how do I get the R compilation or execution
 process to spit
out a line number with errors and warnings?
Indeed, I often suffer from the same problem when debugging R
 code too.
This is a real issue for me.
   
As Duncan mentioned already, you can't *always* get a line
 number. You
can, however, usually get enough context around the failing call
 for
you to be able to smoke the problem out.
What are the cases where you cannot get line numbers? Duncan said
source()ed code comes with line numbers, but what's the more
 general
rule?
   
The general rule is that parse() needs to be called with the
 srcfile
argument set to a srcfile object.  source() does that by default.
OK. But isn't it technically possible to compute a line number even
 when
no source file is present?
  
   Yes, you don't really need to have a file present, you just need a
   srcfile object.  For example, on Windows when you use
   source(clipboard), there's no file, just the system clipboard.
  
 If you call fix() on any function, you will
get something like a source file even if srcfile was not set.
  
   Yes, and then you can call source on that object, and you'll get line
   number information attached, relative to whatever you sourced.
  
  
   So it
could make sense to have a line number referring to what you would
 see
in fix(). Or at least, the last executed line when calling browser()
 or
when using options(error=recover), like gdb does.
  
   The thing is that if you didn't attach the line number information to
   the code, then it's not there.  R can't figure out after the fact where
   the code came from.  It needs to have the debug info in place when it
   runs it.  How could R figure out where some expression came from that
 it
   happens to 

Re: [R] simple subset question

2012-12-02 Thread David L Carlson
As David W. guessed. The maximum is in year 2005 not 2012 so no row from
2012 matches the maximum.

 subset(winter,Year==2012  Total==max(Total))
[1] IDWeek Total  FrySmolt  FryEq  Year  
0 rows (or 0-length row.names)
 winter[which(winter$Total==max(winter$Total)),]
IDWeek   Total Fry Smolt   FryEq Year
195 39 2115018 2083214 31805 2137281 2005

Change to

 subset(winter, Year==2012  Total==max(Total[Year==2012]))
   IDWeek  Total   Fry  Smolt  FryEq Year
21 47 303259 34008 269248 491733 2012

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Felipe Carrillo
 Sent: Sunday, December 02, 2012 4:40 PM
 To: arun
 Cc: R help
 Subject: Re: [R] simple subset question
 
 Actually, I dput(winter) and is not that big.so here is the whole
 thing I
 am trying to accomplish.
  winter - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
 13221L, 4894L, 0L, 460L, 1129L, 1757L, 11105L, 27730L, 55769L,
 12298L, 32964L, 80110L, 160507L, 74134L, 101736L, 138355L, 107873L,
 53806L, 194429L, 7596L, 55497L, 30336L, 18392L, 22291L, 16850L,
 16567L, 14799L, 7909L, 93L, 329L, 363L, 2762L, 5573L, 33466L,
 96762L, 340947L, 612835L, 347972L, 526506L, 656981L, 344181L,
 145465L, 150543L, 935599L, 32789L, 15092L, 7288L, 9889L, 6945L,
 5138L, 6299L, 3095L, 108227L, 1191L, 0L, 0L, 132L, 227L, 2157L,
 7558L, 16459L, 87220L, 321195L, 209299L, 110807L, 112024L, 128058L,
 74373L, 41531L, 15111L, 21890L, 15060L, 22538L, 12443L, 11052L,
 3907L, 2640L, 2745L, 3936L, 17593L, 0L, 0L, 10775L, 4166L, 4958L,
 16221L, 29401L, 34951L, 33188L, 146044L, 105007L, 185297L, 159682L,
 207537L, 140694L, 128275L, 44274L, 27079L, 18928L, 10437L, 29984L,
 18395L, 25846L, 4573L, 31995L, 3679L, 707L, 2390L, 8860L, 24430L,
 40885L, 72792L, 205521L, 344493L, 662973L, 526409L, 631953L,
 850491L, 842678L, 445987L, 558152L, 332032L, 174326L, 80601L,
 48696L, 98571L, 103563L, 149469L, 78081L, 182478L, 2158L, 16566L,
 0L, 868L, 2044L, 4064L, 6049L, 9399L, 13304L, 45172L, 242155L,
 476864L, 712534L, 1058409L, 2115018L, 1510342L, 1138213L, 333192L,
 158820L, 94379L, 348882L, 39290L, 29701L, 47258L, 69837L, 7884L,
 49338L, 22168L, 0L, 147L, 1231L, 3216L, 5021L, 18462L, 37441L,
 64669L, 136590L, 338523L, 559448L, 714837L, 358037L, 180910L,
 291943L, 222708L, 163801L, 39109L, 23247L, 15726L, 38701L, 5795L,
 12509L, 18721L, 822L, 6674L, 765L, 1753L, 6226L, 9727L, 22033L,
 50472L, 67863L, 100909L, 276699L, 239609L, 416465L, 845073L,
 1071051L, 571656L, 409021L, 451331L, 167006L, 68069L, 250439L,
 104641L, 76062L, 35261L, 55883L, 16064L, 11058L, 8872L, 9346L,
 24760L, 41699L, 40032L, 80576L, 152208L, 171888L, 292862L, 522669L,
 441518L, 858538L, 906010L, 1464311L, 1334433L, 542204L, 211514L,
 64507L, 94830L, 100663L, 116931L, 83139L, 46268L, 14455L, 22811L,
 47446L, 54224L), Fry = c(0L, 0L, 326L, 1735L, 1807L, 2208L, 3883L,
 8759L, 6060L, 19326L, 63119L, 100524L, 52582L, 88170L, 145564L,
 111416L, 38233L, 5248L, 17826L, 11038L, 34008L, 215L, 0L, 0L,
 0L, 0L, 0L, 0L, 0L, 0L, 

[R] Object Browser

2012-12-02 Thread rahul143
Dear all, 

I have tried all the popular R IDE or editors like Eclipse, Komodo, JGR,
Revolution... 
They all have fancy fucntions like auto completion, syntax highlight 
BUT, I JUST WANT A OBJECT BROWSER! 

The easiest way to view objects in R console is fix(), but you have no
global view of all the objects in the workspace. 
Revolution has the best object browser so far, but this thing is way too
big... 
Eclipse all has automatically object browser, but you can't only see the
basic summary info. and it's really tricky to configure StatET. 
Jgr is very handy, when you double click the object name, you can view the
object in a spreadsheet like using fix(), but you have to press the
Refresh button each time you want to see the updated objects... 

So, is there any thing like the combination of eclipse and Jgr? 
If not, I am interested to develope something to fulfill this simple but
very important function. But right now I have no idea where to start. Any
suggestions? 


Peter 




-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/Object-Browser-tp4651647.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] Can you turn a string into a (working) symbol?

2012-12-02 Thread rahul143
Dear folks-- 

Suppose I have an expression that evaluates to a string, and that that
string, were it not a character vector, would be a symbol.  I would like a
function, call it doppel(), that will take that expression as an argument
and produce something that functions exactly like the symbol would have if I
typed it in the place of the function of the expression.  It should go as
far along the path to evaluation as the symbol would have, and then stop,
and be available for subsequent manipulation.  For example, if 

aa - 3.1416 
bb  - function(x) {x^2} 
r - 2 
xx - c(aa, bb) 

out - doppel(xx[1])*doppel(xx[2])(r) 

Then out should be 13.3664 

Or similarly, after 
doppel(paste(a,  a,  sep=''))  -  3 
aa 

typing aa should return 3. 

Is there such a function? Can there be? 

I thought as.symbol would do this, but it does not. 
 as.symbol (xx[1])*as.symbol (xx[2])(r) 
Error: attempt to apply non-function 




-





--
View this message in context: 
http://r.789695.n4.nabble.com/Can-you-turn-a-string-into-a-working-symbol-tp4651634.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] Conjoint Analysis in R??

2012-12-02 Thread rahul143
Pls advise how I can use R in conjoint analysis?? 

regds 
Faisal Afzal Siddiqui 
Karachi, Pakistan 


 

 
Looking for last minute shopping deals? 




-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/Conjoint-Analysis-in-R-tp4651650.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] postForm() in RCurl and library RHTMLForms

2012-12-02 Thread rahul143
Hi RUsers, 

Suppose I want to see the data on the website 
url - http://www.nseindia.com/content/indices/ind_histvalues.htm; 

for the index SP CNX NIFTY for 
dates FromDate=01-11-2010,ToDate=02-11-2010 

then read the html table from the page using readHTMLtable() 

I am using this code 
webpage - postForm(url,.params=list( 
   FromDate=01-11-2010, 
   ToDate=02-11-2010, 
   IndexType=SP CNX NIFTY, 
   Indicesdata=Get Details), 
 .opts=list(useragent = getOption(HTTPUserAgent))) 

But it doesn't give me desired result 

Also I was trying to use the function getHTMLFormDescription from the 
package RHTMLForms but there we can't use the argument 
.opts=list(useragent = getOption(HTTPUserAgent)) which is needed for this 
particular website 




-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/postForm-in-RCurl-and-library-RHTMLForms-tp4651655.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] Stepwise analysis with fixed variables

2012-12-02 Thread rahul143
Hello,
How can I run a backward stepwise regression with part of the variables
fixed, while the others participate in the backward stepwise analysis?
Thank you



-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/Stepwise-analysis-with-fixed-variables-tp4651636.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] Reading PDF files

2012-12-02 Thread rahul143
I need to do text mining on PDF files. I understand there is a readPDF 
command in tm that can be used. Have read the 2008 posts on converting 
PDF files to text by Tony Breyal and others. 

  

Wondering if the procedure has been standardized in any tutorial or 
otherwise? Being new to R, I was able to follow only part of the 
discussion. 

  

Any way to get a set of step by step instructions appropriate for my 
level? I am an ageing academic who has worked mostly with SAS and 
MATLAB. 

  



-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/Reading-PDF-files-tp4651657.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] Problems with nls

2012-12-02 Thread rahul143
I'm trying to fit the Bass Diffusion Model using the nls function in R but 
I'm running into a strange problem. The model has either two or three 
parameters, depending on how it's parameterized, p (coefficient of 
innovation), q (coefficient of immitation), and sometimes m (maximum market 
share). Regardless of how I parameterize the model I get an error saying 
that the step factor has decreased below it's minimum. I have tried 
re-setting the minimum in nls.controls but that doesn't seem to fix the 
problem. Likewise, I have run through a variety of start values in the past 
few days, all to no avail. Looking at the trace output it appears that R 
believes I always have one more parameter than I actually have (i.e. when 
the model is parameterized with p and q R seems to be seeing three 
parameters, when m is also included R seems to be seeing four). My 
experience with nls is limited, can someone explain to me why it's doing 
this? I've included the data set I'm working with (published in Michalakelis 
et al. 2008) and some example code. 

## Assign relevant variables 
adoption - 
c(167000,273000,531000,938000,2056452,3894103,5932090,7963742,9314687,10469060,11393302,11976340)
 
time - seq(from = 1,to = 12, by = 1) 
## Models 
Bass.Model - adoption ~ ((p + q)^2/p) * (exp(-(p + q) * time)/((q / p) * 
exp(-(p + q) * time) + 1)^2) 
## Starting Parameters 
Bass.Params - list(p = 0.1, q = 0.1) 
## Model fitting 



-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/Problems-with-nls-tp4651641.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] postForm() in RCurl and library RHTMLForms

2012-12-02 Thread rahul143
Hi RUsers, 

Suppose I want to see the data on the website 
url - http://www.nseindia.com/content/indices/ind_histvalues.htm; 

for the index SP CNX NIFTY for 
dates FromDate=01-11-2010,ToDate=02-11-2010 

then read the html table from the page using readHTMLtable() 

I am using this code 
webpage - postForm(url,.params=list( 
   FromDate=01-11-2010, 
   ToDate=02-11-2010, 
   IndexType=SP CNX NIFTY, 
   Indicesdata=Get Details), 
 .opts=list(useragent = getOption(HTTPUserAgent))) 

But it doesn't give me desired result 

Also I was trying to use the function getHTMLFormDescription from the 
package RHTMLForms but there we can't use the argument 
.opts=list(useragent = getOption(HTTPUserAgent)) which is needed for this 
particular website 


Thanks and Regard



-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/postForm-in-RCurl-and-library-RHTMLForms-tp4651644.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] Sullivan, Timmerman and White 1999: TA rules, and R

2012-12-02 Thread rahul143
Friends 

I am trying to save myself some tedious work. 

I am processing a paper from  The Journal Of Finance * Vol. LIV, No. 5   
October 1999 by Sullivan,  Timmerman and  White.  Data-Snooping, 
Technical Trading Rule Performance, and the Bootstrap 

I am aiming to reproduce their results using the same  TA rules as they 
used. 

They describe the rules they use in English and I am in the process of 
trying to programme them into R.  But if some one has already done this 
it would save me a pile of work. 

It would be nice to just grab some rules from the TTR package, but 
because of the way STW describe the rules it is quite a lot of work to 
calculate what parameters to use. 

So I am clutching at a straw here:  If anybody could point me in a 
better direction than slogging through the English text and trying to 
match that with the TTR docs I would be grateful 

cheers 



-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/Sullivan-Timmerman-and-White-1999-TA-rules-and-R-tp4651658.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] e1071 SVM: Cross-validation error confusion matrix

2012-12-02 Thread rahul143
Hi, 

I ran two svm models in R e1071 package: the first without cross-validation
and the second with 10-fold cross-validation. 

I used the following syntax: 

#Model 1: Without cross-validation: 
 svm.model - svm(Response ~ ., data=data.df, type=C-classification,
 kernel=linear, cost=1) 
 predict - fitted(svm.model) 
 cm - table(predict, data.df$Response) 
 cm 

#Model2: With 10-fold cross-validation: 
 svm.model2 - svm(Response ~ ., data=data.df, type=C-classification,
 kernel=linear, cost=1, cross=10) 
 predict2 - fitted(svm.model2) 
 cm2 - table(predict2, data.df$Response) 
 cm2 

However, when I compare cm and cm2, I notice that the confusion matrices are
identical although the accuracy of each model is diffent. What am I doing
wrong? 
  
Thanks for you help, 




-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/e1071-SVM-Cross-validation-error-confusion-matrix-tp4651652.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] Problems of metafile plots when converting word to pdf file

2012-12-02 Thread rahul143
Hi all, 

I copy metafile boxplot from R to Word. Then save as Pdf file. But I found
there are some unexpected black lines in some plots within this PDF file. 

Please give me some advice how to get rid of these black lines in PDF files. 

Thanks a lot, 

Jim 



-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/Problems-of-metafile-plots-when-converting-word-to-pdf-file-tp4651659.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] RMySQL install on windows

2012-12-02 Thread rahul143
I have been trying to install RMySQL on Windows 7 following the 
procedure at: 
http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL

I think I have properly installed RTools and created a proper 
Renviron.site file saying: 
MYSQL_HOME=C:/Program Files/MySQL/MySQL Server 5.5 

When I try to install the packages from source, I get warnings that 
suggest I'm still not quite with the program yet. There are comments 
about POSIX paths that I don't quite grasp. Can anyone give me 
additional hints? 

There seems to be a libmysql.dll in the /lib subdirectory although the 
install seems to be looking in the /bin directory for a file of similar 
name. Is this something that has changed with recent versions of MySQL 
that should be fixed in the RMySQL package or is it something I can work 
around by hand or by properly setting some environmental variable? 

Thanks, 




-




--
View this message in context: 
http://r.789695.n4.nabble.com/RMySQL-install-on-windows-tp4651660.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] Object Browser

2012-12-02 Thread rahul143
What's the best object browser? 

Dear all, 

I have tried all the popular R IDE or editors like Eclipse, Komodo, JGR,
Revolution... 
They all have fancy fucntions like auto completion, syntax highlight 
BUT, I JUST WANT A OBJECT BROWSER! 

The easiest way to view objects in R console is fix(), but you have no
global view of all the objects in the workspace. 
Revolution has the best object browser so far, but this thing is way too
big... 
Eclipse all has automatically object browser, but you can't only see the
basic summary info. and it's really tricky to configure StatET. 
Jgr is very handy, when you double click the object name, you can view the
object in a spreadsheet like using fix(), but you have to press the
Refresh button each time you want to see the updated objects... 

So, is there any thing like the combination of eclipse and Jgr? 
If not, I am interested to develope something to fulfill this simple but
very important function. But right now I have no idea where to start. Any
suggestions? 




-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/Object-Browser-tp4651654.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] Linking C/C++ GUI to R.dll

2012-12-02 Thread rahul143
Hi, 

I am in the process of linking a C/C++ application to the R.dll 
directly.  I have obtained the R source code and compiled it 
successfully.  I have also successfully linked the R.dll directly into 
our application and have made calls successfully into the R.dll that are 
included in the sample rtest.c and in the Writing R Extensions - The R 
API.   

The R functionality that we are interested in embedding into our 
application is the data analysis and graphics.  However, I did not see 
any references to this in the R API section of the documentation.  Is 
this functionality available from our C/C++ application via the R.dll? 
If so, how do we access this functionality? 

Thank you, 



-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/Linking-C-C-GUI-to-R-dll-tp4651661.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] Sullivan, Timmerman and White 1999: TA rules, and R

2012-12-02 Thread rahul143
Friends 

I am trying to save myself some tedious work. 

I am processing a paper from  The Journal Of Finance * Vol. LIV, No. 5   
October 1999 by Sullivan,  Timmerman and  White.  Data-Snooping, 
Technical Trading Rule Performance, and the Bootstrap 

I am aiming to reproduce their results using the same  TA rules as they 
used. 

They describe the rules they use in English and I am in the process of 
trying to programme them into R.  But if some one has already done this 
it would save me a pile of work. 

It would be nice to just grab some rules from the TTR package, but 
because of the way STW describe the rules it is quite a lot of work to 
calculate what parameters to use. 

So I am clutching at a straw here:  If anybody could point me in a 
better direction than slogging through the English text and trying to 
match that with the TTR docs I would be grateful 




-
TO GET MORE DETAILS CLICK HERE  
--
View this message in context: 
http://r.789695.n4.nabble.com/Sullivan-Timmerman-and-White-1999-TA-rules-and-R-tp4651656.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] residual and null deviance of an lme object with correlation structure

2012-12-02 Thread rahul143
Hello, 

I am attempting to calculate the residual and null deviance of an lme 
object that includes a corAR1 correlation structure. I tried 
deviance(lme.object) and it only returned NULL. Can anyone help? Thank 
you. 



-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/residual-and-null-deviance-of-an-lme-object-with-correlation-structure-tp4651662.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] finding index of maximum value in vector

2012-12-02 Thread rahul143
I found: 
  max.col(matrix(c(1,3,2),nrow=1)) 
Is there a more concise/elegant way? 
Thanks, 




-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/finding-index-of-maximum-value-in-vector-tp4651663.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] Fitting binomial lmer-model, high deviance and low logLik

2012-12-02 Thread rahul143
Hello 

I have a problem when fitting a mixed generalised linear model with the 
lmer-function in the Matrix package, version 0.98-7. I have a respons 
variable (sfox) that is 1 or 0, whether a roe deer fawn is killed or not 
by red fox. This is expected to be related to e.g. the density of red 
fox (roefoxratio) or other variables. In addition, we account for family 
effects by adding the mother (fam) of the fawns as random factor. I want 
to use AIC to select the best model (if no other model selection 
criterias are suggested). 

the syntax looks like this: 
  mod - lmer(sfox ~ roefoxratio + (1|fam), data=manu2, family=binomial) 

The output looks ok, except that the deviance is extremely high 
(1.798e+308). 

  mod 
Generalized linear mixed model fit using PQL 
Formula: sfox ~ roefoxratio + (1 | fam) 
Data: manu2 
  Family: binomial(logit link) 
AIC   BIC logLik  deviance 
  1.797693e+308 1.797693e+308 -8.988466e+307 1.797693e+308 
Random effects: 
  GroupsNameVarianceStd.Dev. 
 fam (Intercept)  17.149  4.1412 
# of obs: 128, groups: fam, 58 

Estimated scale (compare to 1)  0.5940245 




-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/Fitting-binomial-lmer-model-high-deviance-and-low-logLik-tp4651668.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] Hmisc latex cell background color

2012-12-02 Thread rahul143
Dear latex/R-Sweavers, 

Using the codel below, I can color text in individual cells for latex 
output. 
Is there a similar way to get a background shading? My attempts failed 
because I did not get the closing brace at the right place with Hmisc/latex. 

library(Hmisc) 

x - as.data.frame(diag(rnorm(3),nrow=3)) 
cellTex - matrix(rep(, NROW(x) * NCOL(x)), nrow=NROW(x)) 
cellTex[2,2] - \color{red} 
ct - latex(x, cellTexCmds = cellTex,numeric.dollar=FALSE) 
ct$style - color 
dvi(ct) 




-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/Hmisc-latex-cell-background-color-tp4651664.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] Kalman Filter Forecast using 'SSPIR'

2012-12-02 Thread rahul143
Dear R Users, 

  

  I am new to state-space modeling. I am using SSPIR 
package for Kalman Filter. I have a data set containing one dependent 
variable and 7 independent variables with 250 data points. I want to use 
Kalman Filter for forecast the future values of the dependent variable 
using a multiple regression framework. I have used ssm function to 
produce the state space (SS) object, but I am bit confused that how can 
I predict the future values. 

  

Thanks a lot in advance. 

  



-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/Kalman-Filter-Forecast-using-SSPIR-tp4651666.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] Fitting binomial lmer-model, high deviance and low logLik

2012-12-02 Thread rahul143
Hello 

I have a problem when fitting a mixed generalised linear model with the 
lmer-function in the Matrix package, version 0.98-7. I have a respons 
variable (sfox) that is 1 or 0, whether a roe deer fawn is killed or not 
by red fox. This is expected to be related to e.g. the density of red 
fox (roefoxratio) or other variables. In addition, we account for family 
effects by adding the mother (fam) of the fawns as random factor. I want 
to use AIC to select the best model (if no other model selection 
criterias are suggested). 

the syntax looks like this: 
  mod - lmer(sfox ~ roefoxratio + (1|fam), data=manu2, family=binomial) 

The output looks ok, except that the deviance is extremely high 
(1.798e+308). 

  mod 
Generalized linear mixed model fit using PQL 
Formula: sfox ~ roefoxratio + (1 | fam) 
Data: manu2 
  Family: binomial(logit link) 
AIC   BIC logLik  deviance 
  1.797693e+308 1.797693e+308 -8.988466e+307 1.797693e+308 
Random effects: 
  GroupsNameVarianceStd.Dev. 
 fam (Intercept)  17.149  4.1412 
# of obs: 128, groups: fam, 58 

Estimated scale (compare to 1)  0.5940245 




-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/Fitting-binomial-lmer-model-high-deviance-and-low-logLik-tp4651669.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] How to simulate correlated data

2012-12-02 Thread rahul143
Hello there, 

I would like to simulate X --Normal (20, 5) 
 Y-- Normal (40, 10) 

and the correlation between X and Y is 0.6. How do I do it in R? 

Thank you very much 



-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-simulate-correlated-data-tp4651667.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] concatenating expressions and standard text

2012-12-02 Thread rahul143
Hi all, 

is it possible to concatenate expressions and basic text when for 
instance labeling axis of a plot? I would like to see something like the 
concatenation of expression(C[0]) and for case 1 on my x axis. 
Obviously a plot(x, y, xlab=paste(expression(C[0]), in case1)) will 
not work. 

Thank you in advance, 




-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/concatenating-expressions-and-standard-text-tp4651670.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] superimpose density line over hist

2012-12-02 Thread rahul143
 Romain == Romain Francois [hidden email] 
 on Tue, 13 Dec 2005 15:40:59 +0100 writes: 

   

Romain A few comments : 
Romain - your code should be reproductible, otherwise it is useless.
(that 
Romain recommandation is on the posting guide) 

Romain - that question is a top ten question on that list, go to the
archive 
Romain and you will find answers. (also posting guide) 
Romain BTW, it should be a FAQ and what about an example of overlaying
in hist 
Romain help page ? 

What about the following one --- do also note the comments though! 

set.seed(14) 
x - rchisq(100, df = 4) 

## Comparing data with a model distribution should be done with qqplot()! 
qqplot(x, qchisq(ppoints(x), df = 4)); abline(0,1, col = 2, lty = 2) 

## if you really insist on using hist() ... : 
hist(x, prob = TRUE, ylim = c(0, 0.2)) 
curve(dchisq(x, df = 4), col = 2, lty = 2, lwd = 2, add = TRUE) 




-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/Re-superimpose-density-line-over-hist-tp4651671.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] Labeling a range of bars in barplot?

2012-12-02 Thread rahul143
Marc Schwartz (via MN) wrote:

 On Tue, 2005-12-13 at 10:53 +, Dan Bolser wrote: 
 
Hi, I am plotting a distribution of (ordered) values as a barplot. I 
would like to label groups of bars together to highlight aspects of the 
distribution. The label for the group should be the range of values in 
those bars. 
 
As this is hard to describe, here is an example; 
 



-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/Re-Labeling-a-range-of-bars-in-barplot-tp4651672.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] model selection with spg and AIC (or, convert list to fitted model object)

2012-12-02 Thread Adam Zeilinger
Dear Ravi,

Thank you so much for the help.  I switched to using the optimx function 
but I continue to use the spg method (for the most part) because I found 
that only spg consistently converges give different datasets.  I also 
decided to use AIC rather that a likelihood ratio test.

I have a new question.  I would like to construct 95% confidence 
intervals for the parameter estimates from the best model.  From a 
previous R Help thread, you said that it was a bad idea to use the 
Hessian matrix computed from optim/optimx or hessian() [numDeriv 
package] when the optimization is constrained and parameter estimates 
are on the boundary because the MLE is likely at a local minimum:

http://tolstoy.newcastle.edu.au/R/e15/help/11/09/6673.html

In the same thread, you suggest using the Hessian matrix from augmented 
Lagrangian optimization with auglag() [alabama package] (with some 
caveats).  I would like to construct 95% CI with auglag, but I don't 
understand how to write the inequality constraints (hin) function.  
Could you please help me write the hin function?

Below is R code for my MLE problem, using data that results in parameter 
estimates on the boundary, and my unsuccessful attempt at auglag() 
optimization.  Note: I have gradient functions for NLL1 and NLL2 but 
they're very large and don't seem to improve optimization, so they are 
not included here.  I can supply them if needed for the auglag() 
function.  Also, I am running R 2.15.2 on a Windows 7 64-bit machine.

##

library(optimx)
library(alabama)

# define multinomial distribution
dmnom2 - function(x,prob,log=FALSE) {
   r - lgamma(sum(x) + 1) + sum(x * log(prob) - lgamma(x + 1))
   if (log) r else exp(r)
}

# data frame y

y - structure(list(t = c(0.167, 0.5, 1, 12, 18, 24, 36), n1 = c(1L,
1L, 1L, 8L, 9L, 10L, 12L), n2 = c(0L, 1L, 2L, 6L, 5L, 3L, 2L),
 n3 = c(13L, 12L, 11L, 0L, 0L, 1L, 0L)), .Names = c(t, n1,
n2, n3), class = data.frame, row.names = 36:42)


# Negative log-likelihood functions
NLL1 - function(par, y) {
   p1 - par[1]
   p2 - p1
   mu1 - par[2]
   mu2 - mu1
   t - y$t
   n1 - y$n1
   n2 - y$n2
   n3 - y$n3
   P1 - (p1*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2)))*t))*((-mu2)*(mu2 - p1 + p2) +
 mu1*(mu2 + 2*p2)) - mu2*sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2))) -
 exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t)*
 mu2*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) +
 2*exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2*t)*mu2*
 sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)/
 exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2*t)/(2*(mu2*p1 + mu1*(mu2 + p2))*
 sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2
   P2 - (p2*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2)))*t))*(-mu1^2 + 2*mu2*p1 +
 mu1*(mu2 - p1 + p2)) - mu1*sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2))) -
 exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t)*
 mu1*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) +
 2*exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2*t)*mu1*
 sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)/
 exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2*t)/(2*(mu2*p1 + mu1*(mu2 + p2))*
 sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2
   P3 - 1 - P1 - P2
   p.all - c(P1, P2, P3)
   if(all(p.all  0  p.all  1)) -sum(dmnom2(c(n1, n2, n3), prob = 
p.all, log = TRUE)) else 1e07
}

NLL2 - function(par, y) {
   p1 - par[1]
   p2 - par[2]
   mu1 - par[3]
   mu2 - par[4]
   t - y$t
   n1 - y$n1
   n2 - y$n2
   n3 - y$n3
   P1 - (p1*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2)))*t))*((-mu2)*(mu2 - p1 + p2) +
 mu1*(mu2 + 2*p2)) - mu2*sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2))) -
 exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t)*
 mu2*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) +
 2*exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2*t)*mu2*
 sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)/
 exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2*t)/(2*(mu2*p1 + mu1*(mu2 + p2))*
 sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2
   P2 - (p2*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 -
 4*(mu2*p1 + mu1*(mu2 + p2)))*t))*(-mu1^2 + 2*mu2*p1 +
 mu1*(mu2 - p1 + p2)) - 

[R] R beginner

2012-12-02 Thread Akrem Zoghlami
Dear R-help group,

I'm a R beginner and I find difficulty in manipulating R. Could you send to
me a support that helps me to be familiar with R. Thank you in advance

 

Sincerely,


[[alternative HTML version deleted]]

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


Re: [R] problem with convergence in mle2/optim function

2012-12-02 Thread Adam Zeilinger

Dear Berend,

Thank you so much for your help!  I was able to write the gradient 
function for my NLL function.  For you're and others' possible interest, 
here is my final gradient function:


Following from my description of the problem below, gr.p1, gr.p2, 
gr.mu1, and gr.mu2 are the (very large) gradient equations of NLL2, 
below, with respect to the parameters p1, p2, mu1, and mu2, 
respectively.  The gradient function is:


# Gradient function of NLL1
grr - function(par, y){
 p1 - par[1]
 p2 - par[2]
 mu1 - par[3]
 mu2 - par[4]
 t - y[,1]
 n1 - y[,2]
 n2 - y[,3]
 n3 - y[,4]
 gr.p1 - 
 gr.p2 - 
 gr.mu1 - 
 gr.mu2 - 
 gr.mat - matrix(c(gr.p1, gr.p2, gr.mu1, gr.mu2), ncol = 4)
 -colSums(gr.mat)
}

I verified this gradient function with numerical approximation with the 
grad() function [numDeriv package].


Thanks again.
Adam Zeilinger


On 10/10/2012 3:57 AM, Berend Hasselman wrote:

On 10-10-2012, at 00:21, Adam Zeilinger wrote:


Dear R help,

Thanks again for the responses.  I increased the lower constraint to:

lower = list(p1 = 0.0001, p2 = 0.0001, mu1 = 0.0001, mu2 = 0.0001).

I also included an upper box constraint of:

upper = list(p1 = Inf, p2 = Inf, mu1 = p1t, mu2 = p2t).

Making these changes improved the rate of convergence among stochastic 
simulation runs, but I still had convergence problems.

I found success in switching from mle2/optim to spg (BB package).  So far, spg 
has produced similarly precise estimates as L-BFGS-B and consistently provides 
parameter estimates.

If anyone is interested, here is the new objective function and spg call, 
instead of my previous objective function and mle2 call.  All other parts of my 
reproducible code are the same as I've previously supplied:

##
library(BB)

# Objective function for spg()
NLL2 - function(par, y){
  p1 - par[1]
  p2 - par[2]
  mu1 - par[3]
  mu2 - par[4]
  t - y$tv
  n1 - y$n1
  n2 - y$n2
  n3 - y$n3
  P1 - (p1*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 -
4*(mu2*p1 + mu1*(mu2 + p2)))*t))*((-mu2)*(mu2 - p1 + p2) +
mu1*(mu2 + 2*p2)) - mu2*sqrt((mu1 + mu2 + p1 + p2)^2 -
4*(mu2*p1 + mu1*(mu2 + p2))) -
exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t)*
mu2*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) +
2*exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
4*(mu2*p1 + mu1*(mu2 + p2*t)*mu2*
sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)/
exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
4*(mu2*p1 + mu1*(mu2 + p2*t)/(2*(mu2*p1 + mu1*(mu2 + p2))*
sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2
  P2 - (p2*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 -
4*(mu2*p1 + mu1*(mu2 + p2)))*t))*(-mu1^2 + 2*mu2*p1 +
mu1*(mu2 - p1 + p2)) - mu1*sqrt((mu1 + mu2 + p1 + p2)^2 -
4*(mu2*p1 + mu1*(mu2 + p2))) -
exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t)*
mu1*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) +
2*exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
4*(mu2*p1 + mu1*(mu2 + p2*t)*mu1*
sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)/
exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
4*(mu2*p1 + mu1*(mu2 + p2*t)/(2*(mu2*p1 + mu1*(mu2 + p2))*
sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2
  P3 - 1 - P1 - P2
  p.all - c(P1, P2, P3)
  #cat(NLL.free p.all {P1,P2,P3}\n)
  #print(matrix(p.all, ncol=3))
  -sum(dmnom2(c(n1, n2, n3), prob = p.all, log = TRUE))
}

par - c(p1t, p2t, mu1t, mu2t)

spg.fit - spg(par = par, fn = NLL2, y = yt,
lower = c(0.001, 0.001, 0.001, 0.001),
control = list(maxit = 5000))



My next problem is that spg takes about twice as long as L-BFGS-B to converge.  
The spg help file strongly suggests the use of an exact gradient function to 
improve speed.  But I am having trouble writing a gradient function.  Here is 
what I have so far:

I derived the gradient function by taking the derivative of my NLL equation 
with respect to each parameter.  My NLL equation is the probability mass 
function of the trinomial distribution.  Here is some reproducible code:

#
library(Ryacas)

p1 - Sym(p1); p2 - Sym(p2); mu1 - Sym(mu1); mu2 - Sym(mu2)
t - Sym(t); n1 - Sym(n1); n2 - Sym(n2); n3 - Sym(n3)

P1.symb - ((p1*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 -
  4*(mu2*p1 + mu1*(mu2 + p2)))*t))*((-mu2)*(mu2 - p1 + p2) +
  mu1*(mu2 + 2*p2)) - mu2*sqrt((mu1 + mu2 + p1 + p2)^2 -
  4*(mu2*p1 + mu1*(mu2 + p2))) -
  exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t)*
  mu2*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) +
  2*exp((1/2)*(mu1 + mu2 + p1 + p2 + sqrt((mu1 + mu2 + p1 + p2)^2 -
  4*(mu2*p1 + mu1*(mu2 + 

Re: [R] Warning message: In scan(file, what, nmax...)

2012-12-02 Thread F86
In addition, 

I tried  Data1-read.table(/Users/kama/Analysis/GDP10.csv, sep=\t,
fill=TRUE)

the result:   *** caught segfault ***
address 0xd020, cause 'memory not mapped'

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace




--
View this message in context: 
http://r.789695.n4.nabble.com/Warning-message-In-scan-file-what-nmax-tp4651689p4651712.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] Warning message: In scan(file, what, nmax...)

2012-12-02 Thread F86
Also tries this: 

x-count.fields(/Users/kama/Analysis/GDP10.csv, sep=\t)
 x
   [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
  [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
  [75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [112] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [149] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [186] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [223] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [260] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [297] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [334] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [371] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [408] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [445] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [482] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [519] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [556] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [593] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [630] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [667] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [704] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [741] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [778] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [815] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [852] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [889] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [926] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [963] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
[1000] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
[1037] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
[1074] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
[] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
[1148] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
[1185] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
[1222] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


However, it is not clear for me what is wrong with my data. ..



--
View this message in context: 
http://r.789695.n4.nabble.com/Warning-message-In-scan-file-what-nmax-tp4651689p4651715.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] simple subset question

2012-12-02 Thread Felipe Carrillo
I finally see what you and David W mean...I was under the assumption that by 
subsetting
Year==2012 it would also extract the max for that year.I guess I have to 
review 'subset' again :)
Thank you much 

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx




From: David L Carlson dcarl...@tamu.edu
To: 'Felipe Carrillo' mazatlanmex...@yahoo.com; 'arun' 
smartpink...@yahoo.com 
Cc: 'R help' r-help@r-project.org 
Sent: Sunday, December 2, 2012 2:54 PM
Subject: RE: [R] simple subset question

As David W. guessed. The maximum is in year 2005 not 2012 so no row from
2012 matches the maximum.

 subset(winter,Year==2012  Total==max(Total))
[1] IDWeek Total  Fry    Smolt  FryEq  Year  
0 rows (or 0-length row.names)
 winter[which(winter$Total==max(winter$Total)),]
    IDWeek  Total    Fry Smolt  FryEq Year
195    39 2115018 2083214 31805 2137281 2005

Change to

 subset(winter, Year==2012  Total==max(Total[Year==2012]))
  IDWeek  Total  Fry  Smolt  FryEq Year
21    47 303259 34008 269248 491733 2012

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Felipe Carrillo
 Sent: Sunday, December 02, 2012 4:40 PM
 To: arun
 Cc: R help
 Subject: Re: [R] simple subset question
 
 Actually, I dput(winter) and is not that big.so here is the whole
 thing I
 am trying to accomplish.
  winter - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
 47L, 48L, 49L, 50L, 51L, 52L), Total = c(0L, 0L, 326L, 1735L,
 1807L, 2208L, 3883L, 8820L, 6060L, 19326L, 63158L, 100718L, 53015L,
 91689L, 152629L, 122708L, 61293L, 15574L, 86538L, 75365L, 303259L,
 19691L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 161L, 321L, 1000L, 4425L,
 13202L, 19726L, 30518L, 84949L, 157260L, 145691L, 85801L, 62044L,
 44439L, 23272L, 22391L, 20159L, 14854L, 35379L, 31142L, 7736L,
 13221L, 4894L, 0L, 460L, 1129L, 1757L, 11105L, 27730L, 55769L,
 12298L, 32964L, 80110L, 160507L, 74134L, 101736L, 138355L, 107873L,
 53806L, 194429L, 7596L, 55497L, 30336L, 18392L, 22291L, 16850L,
 16567L, 14799L, 7909L, 93L, 329L, 363L, 2762L, 5573L, 33466L,
 96762L, 340947L, 612835L, 347972L, 526506L, 656981L, 344181L,
 145465L, 150543L, 935599L, 32789L, 15092L, 7288L, 9889L, 6945L,
 5138L, 6299L, 3095L, 108227L, 1191L, 0L, 0L, 132L, 227L, 2157L,
 7558L, 16459L, 87220L, 321195L, 209299L, 110807L, 112024L, 128058L,
 74373L, 41531L, 15111L, 21890L, 15060L, 22538L, 12443L, 11052L,
 3907L, 2640L, 2745L, 3936L, 17593L, 0L, 0L, 10775L, 4166L, 4958L,
 16221L, 29401L, 34951L, 33188L, 146044L, 105007L, 185297L, 159682L,
 207537L, 140694L, 128275L, 44274L, 27079L, 18928L, 10437L, 29984L,
 18395L, 25846L, 4573L, 31995L, 3679L, 707L, 2390L, 8860L, 24430L,
 40885L, 72792L, 205521L, 344493L, 662973L, 526409L, 631953L,
 850491L, 842678L, 445987L, 558152L, 332032L, 174326L, 80601L,
 48696L, 98571L, 103563L, 149469L, 78081L, 182478L, 2158L, 16566L,
 0L, 868L, 2044L, 4064L, 6049L, 9399L, 13304L, 45172L, 242155L,
 476864L, 712534L, 1058409L, 2115018L, 1510342L, 1138213L, 333192L,
 158820L, 94379L, 348882L, 39290L, 29701L, 47258L, 69837L, 7884L,
 49338L, 22168L, 0L, 147L, 1231L, 3216L, 5021L, 18462L, 37441L,
 64669L, 136590L, 338523L, 559448L, 714837L, 358037L, 180910L,
 291943L, 222708L, 163801L, 39109L, 23247L, 15726L, 38701L, 5795L,
 12509L, 18721L, 822L, 6674L, 765L, 1753L, 

Re: [R] Problem with figures

2012-12-02 Thread Duncan Murdoch

On 12-12-02 5:42 PM, Shige Song wrote:

I am having problem making ggplot2, tikzDevice, and knitr working together.
I used a very simple example:


I don't use knitr so I can't really help, but you didn't tell us how you 
passed this file to knitr, so maybe nobody can.  However, if you were 
using Sweave, you would need to mention that the code chunk produces a 
figure (using fig=TRUE in the = header).


Duncan Murdoch


---example.Rnw-
\documentclass[preview]{standalone}

\begin{document}

\begin{figure}
fig1,eval=TRUE,echo=FALSE,dev='tikz'=
library(ggplot2)
qplot(displ, hwy, data = mpg, colour = factor(cyl))
@
\end{figure}

\end{document}
-
I got ... !  == Fatal error occurred, no output PDF file produced!
label: fig1 (with options)
List of 3
  $ eval: logi TRUE
  $ echo: logi FALSE
  $ dev : chr tikz

Error in process_file(text, output) :
   Quitting from lines 6-8: (test_Rnw.Rnw) Error in
getMetricsFromLatex(TeXMetrics) :
TeX was unable to calculate metrics for the following string
or character:

 hwy

Common reasons for failure include:
   * The string contains a character which is special to LaTeX unless
 escaped properly, such as % or $.
   * The string makes use of LaTeX commands provided by a package and
 the tikzDevice was not told to load the package.

The contents of the LaTeX log of the aborted run have been printed above,
it may contain additional details as to why the metric calculation failed.

Calls: knit - process_file

Execution halted

Best,
Shige

[[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] Can you turn a string into a (working) symbol?

2012-12-02 Thread R. Michael Weylandt
I believe I answered this a few weeks ago at this link:
https://stat.ethz.ch/pipermail/r-help/2012-November/328053.html and
following.

Michael

On Sun, Dec 2, 2012 at 2:43 PM, rahul143 rk204...@gmail.com wrote:
 Dear folks--

 Suppose I have an expression that evaluates to a string, and that that
 string, were it not a character vector, would be a symbol.  I would like a
 function, call it doppel(), that will take that expression as an argument
 and produce something that functions exactly like the symbol would have if I
 typed it in the place of the function of the expression.  It should go as
 far along the path to evaluation as the symbol would have, and then stop,
 and be available for subsequent manipulation.  For example, if

 aa - 3.1416
 bb  - function(x) {x^2}
 r - 2
 xx - c(aa, bb)

 out - doppel(xx[1])*doppel(xx[2])(r)

 Then out should be 13.3664

 Or similarly, after
 doppel(paste(a,  a,  sep=''))  -  3
 aa

 typing aa should return 3.

 Is there such a function? Can there be?

 I thought as.symbol would do this, but it does not.
 as.symbol (xx[1])*as.symbol (xx[2])(r)
 Error: attempt to apply non-function




 -





 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Can-you-turn-a-string-into-a-working-symbol-tp4651634.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] RMySQL install on windows

2012-12-02 Thread Gabor Grothendieck
On Sun, Dec 2, 2012 at 11:35 AM, rahul143 rk204...@gmail.com wrote:
 I have been trying to install RMySQL on Windows 7 following the
 procedure at:
 http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL

 I think I have properly installed RTools and created a proper
 Renviron.site file saying:
 MYSQL_HOME=C:/Program Files/MySQL/MySQL Server 5.5

 When I try to install the packages from source, I get warnings that
 suggest I'm still not quite with the program yet. There are comments
 about POSIX paths that I don't quite grasp. Can anyone give me
 additional hints?

 There seems to be a libmysql.dll in the /lib subdirectory although the
 install seems to be looking in the /bin directory for a file of similar
 name. Is this something that has changed with recent versions of MySQL
 that should be fixed in the RMySQL package or is it something I can work
 around by hand or by properly setting some environmental variable?


There likely has been some change in the location of the dll's in
various versions of MySQL.  See:

http://www.mail-archive.com/r-help@r-project.org/msg185838.html


--
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] Problem with figures

2012-12-02 Thread Shige Song
Easiest way: copy and paste the code into Rstudio and hit compile pdf.
From the command line, I believe you can do knit2pdf example.Rnw.

Shige


On Sun, Dec 2, 2012 at 6:12 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 12-12-02 5:42 PM, Shige Song wrote:

 I am having problem making ggplot2, tikzDevice, and knitr working
 together.
 I used a very simple example:


 I don't use knitr so I can't really help, but you didn't tell us how you
 passed this file to knitr, so maybe nobody can.  However, if you were using
 Sweave, you would need to mention that the code chunk produces a figure
 (using fig=TRUE in the = header).

 Duncan Murdoch

  ---**example.Rnw---**--
 \documentclass[preview]{**standalone}

 \begin{document}

 \begin{figure}
 fig1,eval=TRUE,echo=FALSE,**dev='tikz'=
 library(ggplot2)
 qplot(displ, hwy, data = mpg, colour = factor(cyl))
 @
 \end{figure}

 \end{document}
 --**--**
 -
 I got ... !  == Fatal error occurred, no output PDF file produced!
 label: fig1 (with options)
 List of 3
   $ eval: logi TRUE
   $ echo: logi FALSE
   $ dev : chr tikz

 Error in process_file(text, output) :
Quitting from lines 6-8: (test_Rnw.Rnw) Error in
 getMetricsFromLatex(**TeXMetrics) :
 TeX was unable to calculate metrics for the following string
 or character:

  hwy

 Common reasons for failure include:
* The string contains a character which is special to LaTeX unless
  escaped properly, such as % or $.
* The string makes use of LaTeX commands provided by a package and
  the tikzDevice was not told to load the package.

 The contents of the LaTeX log of the aborted run have been printed above,
 it may contain additional details as to why the metric calculation failed.

 Calls: knit - process_file

 Execution halted

 Best,
 Shige

 [[alternative HTML version deleted]]

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html 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] finding index of maximum value in vector

2012-12-02 Thread Jorge I Velez
?which.max



On Mon, Dec 3, 2012 at 3:44 AM, rahul143 rk204...@gmail.com wrote:

 I found:
   max.col(matrix(c(1,3,2),nrow=1))
 Is there a more concise/elegant way?
 Thanks,




 -
TO GET MORE DETAILS CLICK HERE





 --
 View this message in context:
 http://r.789695.n4.nabble.com/finding-index-of-maximum-value-in-vector-tp4651663.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.


  1   2   >