[R] understanding with

2016-09-08 Thread Carl Sutton via R-help
 Hi I have been doing theR-exercises to improve my R programming capabilities.  
Data.frame exercise4 showed me that I have a languageproblem.  Yes, I am 
frustrated, but please don’t take this as acriticism of the R language.  
Theroutines I have managed to write do marvelous things in a short period 
oftime.  I really want to do more, but thisis a steep rocky thick with 
underbrush hill that is not fun to climb.  But there are good resources.  Swirl 
is wonderful.  My thanks to the authors of thatpackage.  Jared Lander’s R for 
Everyoneis a really good beginners book.  DataCamp, Coursera, all informative 
courses.  Yes I’m frustrated.  After a couple of years on and off 
takingclasses, reading books, reading stack overflow and r-help just about 
daily, Iam learning to almost crawl.  At one timeI thought I had advanced to 
walking but days like today show me I’m a toddlerabout to fall on his backside. 
Reading the manuals onCRAN is analogous to reading the tax code. Without a 
specific objective for motivation, reading them is either painfulor a certain 
cure for insomnia. Here's the problem Ireferred to at the beginning and my 
"solution". #  Exercise 4 fromR Exercises#  Create a simpledata frame from 3 
vectors. Order the entire data frame by the#  first column.df2 <- data.frame(a 
=5:1,b = letters[1:5], c = runif(5))order(df2$a) Naturally the orderfunction 
did nothing.   But I did read the help page and thought I followedit.  And 
there is no obvious environmentissue.  It’s a simple data.frame and Iwant to 
order it by one column.  Such asdf2 <- data.table(df2)setkey(df2, a).  Done. No 
fuss, no muss, no needing “with”. Per "help"Description order returns 
apermutation which rearranges its first argument into ascending or 
descendingorder, breaking ties by further arguments. sort.list is the same, 
using onlyone argument.See the examples for howto use these functions to sort 
data frames, etc. Usage order(..., na.last =TRUE, decreasing = FALSE,     
method = c("shell", "radix")) sort.list(x, partial =NULL, na.last = TRUE, 
decreasing = FALSE,         method = c("shell", "quick","radix"))Arguments ... 
a sequence of numeric,complex, character or logical vectors, all of the same 
length, or a classed Robject. Well, doesn't ... meanany legal object?  I gave 
it a legal object and got nada.  And the answerabsolutely has me screaming "Say 
What"df2[with(df2,order(a)),]  What's with "with? In Mr. Lander’s book, page 
126, “Here we used a new function, with.  This allows us to specify the columns 
of adata frame without having to specify the data.frame name each time.”  
Great, I’m a horrible typist and will takeany and all typing shortcuts.  
However, Idon’t use it because I don’t understand what it does.  Obviously it’s 
important, but I’m stuck on why or how I would use it. It is one function I 
donot use because I find it incomprehensible.  To witEvaluate an R expressionin 
an environment constructed from data, possibly modifying (a copy of) 
theoriginal data. First of all, if I'm notmodifying data (or as a subset 
activity creating data), why am I doing whateverit is I'm doing? ("possibly 
modifying (a copy of) the originaldata.") Possibly?? Evaluate. According to the 
thesaurus a) assess(v), b) appraise, c) gage. OK, am I in a safe area? I'll 
evaluate that.  Do I desire future social contact with thisperson?  I'll 
evaluate that. In no way do I ever evaluatean equation.  I may attempt to solve 
it.  I may do a computer programto do the calculations and return a result.  I 
will probably evaluate theresult as to whether or not it helps solve the 
problem.  Think in terms ofan income tax return.  But evaluate an R expression? 
 No clue whatthat might mean.  And that is my problemin a nutshell. The 
remainder of thedefinition is also obtuse.  an R expression in an 
environmentconstructed from data.  Why would one make an environment 
withoutdata?  Obviously I am missing thepoint.  My own created function makes a 
new environment, but I onlycreated it to crunch numbers.  If it doesn't crunch 
numbers it's useless. The point is, I do not understand the definitionof "with" 
and thus have no idea how to use it.  I guesscomputerese is analogous to 
taxlawese.  Familiar words have entirely different meanings. Carl Sutton CPA 

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] element wise pattern recognition and string substitution

2016-09-08 Thread Jun Shen
Hi Ista,

Imagine we have a data set called "all.exposure" with variables
"TX","WTCUT" for a function. The concatenated strings are generated by some
procedure within the function (the dot is used as separator, I can't change
that). Now I want to parse the strings back to the original values as in
"TX" and "WTCUT" (there could be more than two variables). Since the data
set is provided by users, I cannot pre-define the pattern. The patterns
have to be figured out from the values in "TX" and "WTCUT". It's easy if
the values in "TX" or "WTCUT" don't have any "." but much trickier if they
do. However, the number of the patterns are limited by the combination of
the unique values in "TX" and "WTCUT". All possible patterns can be
constructed by the code I posted in this thread. Now I need to figure out a
way to match the patterns to the strings so each string can be parsed
correctly. I have made some progress...

Jun

On Wed, Sep 7, 2016 at 9:34 AM, Ista Zahn  wrote:

> On Tue, Sep 6, 2016 at 11:59 PM, Jun Shen  wrote:
> > Hi Ista,
> >
> > Thanks for the suggestion. I didn't know mapply can be used this way!
> Let me
> > take one more step. Instead of defining a pattern for each string, I
> would
> > like to define a set of patterns from all the possible combination of the
> > unique values of those variables. Then I need each string to find a
> pattern
> > for itself.
>
> Uh, humn, what?!? I have no idea what this means. Example?
>
> --Ista
>
>  I know this is getting a little stretching. Thanks for all the
> > suggestion/comments from everyone.
> >
> > Jun
> >
> > On Tue, Sep 6, 2016 at 9:44 PM, Ista Zahn  wrote:
> >>
> >> If you want to mach each element of 'strings' to a different regex, do
> >> it. Here are three ways, using your original example.
> >>
> >> pattern1 <- "([^.]*)\\.([^.]*\\.[^.]*)\\.(.*)"
> >> pattern2 <- "([^.]*)\\.([^.]*)\\.(.*)"
> >>
> >> patterns <- c(pattern1,pattern2)
> >> strings <- c('TX.WT.CUT.mean','mg.tx.cv')
> >>
> >> for(i in seq(strings)) print(sub(patterns[i], "\\2", strings[i]))
> >>
> >> mapply(sub, pattern = patterns, x = strings, MoreArgs=list(replacement =
> >> "\\2"))
> >>
> >> library(stringi)
> >> stri_replace_all_regex(strings, patterns, "$2")
> >>
> >> Best,
> >> Ista
> >> On Tue, Sep 6, 2016 at 9:20 PM, Jun Shen  wrote:
> >> > Hi Jeff,
> >> >
> >> > Thanks for the reply. I tried your suggestion and it doesn't seem to
> >> > work
> >> > and I tried a simple pattern as follows and it works as expected
> >> >
> >> > sub("(3\\.mg\\.kg)\\.(>50-70\\.kg)\\.(.*)", '\\1',
> >> > "3.mg.kg.>50-70.kg.P05")
> >> > [1] "3.mg.kg"
> >> >
> >> > sub("(3\\.mg\\.kg)\\.(>50-70\\.kg)\\.(.*)", '\\2',
> >> > "3.mg.kg.>50-70.kg.P05")
> >> > [1] ">50-70.kg"
> >> >
> >> > sub("(3\\.mg\\.kg)\\.(>50-70\\.kg)\\.(.*)", '\\3',
> >> > "3.mg.kg.>50-70.kg.P05")
> >> > [1] "P05"
> >> >
> >> > My problem is the pattern has to be dynamically constructed on the
> input
> >> > data of the function I am writing. It's actually not too difficult to
> >> > assemble the final.pattern with some code like the following
> >> >
> >> > sort.var <- c('TX','WTCUT')
> >> > combn.sort.var <- do.call(expand.grid, lapply(sort.var,
> >> >
> >> > function(x)paste('(',gsub('\\.','.',unlist(unique(all.
> exposure[x]))),
> >> > ')', sep='')))
> >> > all.patterns <- do.call(paste, c(combn.sort.var, '(.*)', sep='\\.'))
> >> > final.pattern <- paste0(all.patterns, collapse='|')
> >> >
> >> > You cannot run the code directly since the data object "all.exposure"
> is
> >> > not provided here.
> >> >
> >> > Jun
> >> >
> >> >
> >> >
> >> > On Tue, Sep 6, 2016 at 8:18 PM, Jeff Newmiller
> >> > 
> >> > wrote:
> >> >
> >> >> I am not near my computer today, but each parenthesis gets its own
> >> >> result
> >> >> number, so you should put the parenthesis around the whole pattern of
> >> >> alternatives instead of having many parentheses.
> >> >>
> >> >> I recommend thinking in terms of what common information you expect
> to
> >> >> find in these various strings, and place your parentheses to capture
> >> >> that
> >> >> information. There is no other reason to put parentheses in the
> >> >> pattern...
> >> >> they are not grouping symbols.
> >> >> --
> >> >> Sent from my phone. Please excuse my brevity.
> >> >>
> >> >> On September 6, 2016 5:01:04 PM PDT, Bert Gunter
> >> >> 
> >> >> wrote:
> >> >> >Jun:
> >> >> >
> >> >> >1. Tell us your desired result from your test vector and maybe
> someone
> >> >> >will help.
> >> >> >
> >> >> >2. As we played this game once already (you couldn't do it; I showed
> >> >> >you how), this seems to be a function of your limitations with
> regular
> >> >> >expressions. I'm probably not much better, but in any case, I don't
> >> >> >intend to be your consultant. See if you can find someone locally to
> >> >> >help you if you do not receive a satisfactory reply 

Re: [R] Have help list filters changed recently

2016-09-08 Thread Marc Schwartz
> On Sep 8, 2016, at 7:35 PM, Bert Gunter  wrote:
> 
> To all:
> 
> r-help has been holding up a lot of my recent messages: Have there
> been any changes to help list filters that caused this? Is there
> something I'm doing wrong? -- I have made no changes  that I am aware
> of. Here's what I get:
> 
> Your mail to 'R-help' with the subject
> 
>Re: [R] with and evaluation [for example]
> 
> Is being held until the list moderator can review it for approval.
> 
> The reason it is being held:
> 
>The message headers matched a filter rule
> 
> 
> Best,
> Bert


Bert,

Have there been a lot of cc's in your replies?

That is one thing that will tend to trigger the spam filters. I am not sure 
what the threshold is and I am not sure that Martin knows, but that has bitten 
me in the past on R-Help. As co-moderator with Martin on R-Devel, I have seen 
the other side of it there.

Might also be the e-mail domain of one of the respondents in the thread.

I think that it is the ETHZ SysAdmins that tend to control the formalized spam 
filters and heuristics.

Regards,

Marc

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Have help list filters changed recently

2016-09-08 Thread Bert Gunter
To all:

r-help has been holding up a lot of my recent messages: Have there
been any changes to help list filters that caused this? Is there
something I'm doing wrong? -- I have made no changes  that I am aware
of. Here's what I get:

Your mail to 'R-help' with the subject

Re: [R] with and evaluation [for example]

Is being held until the list moderator can review it for approval.

The reason it is being held:

The message headers matched a filter rule


Best,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] with and evaluation

2016-09-08 Thread Jim Lemon
Hi Carl,
order vs sort
The order function just returns the indices necessary to put the
object into the sorted order, while the sort function returns the
sorted object. If you want to use the order function:

newdf2<-df2[(order(df2[,1]),]

Yes, "with" can be a bit challenging. Think of it as:

with(take_this_thing, and_do_this_with_it)

The usual problem is working out what you want to do and what you want
the function to return. It's probably best to just do things to data
objects in a stepwise manner until you get used to that.

Jim


On Fri, Sep 9, 2016 at 9:07 AM, Duncan Murdoch  wrote:
> On 08/09/2016 6:57 PM, Carl Sutton via R-help wrote:
>>
>> Hi
>> I have doing the R-exercises to improve my R programming capabilities.
>> Data.frame exercise 4 showed me that I have  a language problem.  Here's the
>> problem and my "solution".
>> #  Exercise 4#  Create a simple data frame from 3 vectors. Order the
>> entire data frame by the#  first column.df2 <- data.frame(a = 5:1,b =
>> letters[1:5], c = runif(5))order(df2$a) Naturally the order function did
>> nothing.
>> Per "help"Description
>> order returns a permutation which rearranges its first argument into
>> ascending or descending order, breaking ties by further arguments. sort.list
>> is the same, using only one argument.See the examples for how to use these
>> functions to sort data frames, etc.
>> Usage
>> order(..., na.last = TRUE, decreasing = FALSE,  method = c("shell",
>> "radix"))
>> sort.list(x, partial = NULL, na.last = TRUE, decreasing = FALSE,
>> method = c("shell", "quick", "radix"))Arguments
>> ... a sequence of numeric, complex, character or logical vectors, all of
>> the same length, or a classed R object.
>> Well, doesn't ... mean any legal object?  I gave it a legal object and got
>> nada.And the answer absolutely has me screaming "Say
>> What"df2[with(df2,order(a)),]
>>
>> What's with "with?  It is one function I do not use because I find it
>> incomprehensible.  To witEvaluate an R expression in an environment
>> constructed from data, possibly modifying (a copy of) the original data.
>>
>> First of all, if I'm not modifying data (or as a subset activity creating
>> data), why an I doing whatever it is I'm doing? ("possibly modifying (a copy
>> of) the original data.")
>> Evaluate.  According to the thesarus A) assess(v), b) appraise, c) gage.
>> OK, am I in a safe area?  I'll evaluate that.  Do I desire future social
>> contact with this person?  I'll evaluate that.In no way do I ever evaluate
>> an equation.  I may attempt to solve it.  I may do a computer program to do
>> the calculations and return a result.  I will probably evaluate the result
>> as to whether or not it helps solve the problem.  Think in terms of an
>> income tax return.  But evaluate an R expression?  No clue what that might
>> mean.
>> The remainder of the definition is also obtuse.  an R expression in an
>> environment constructed from data.  Why would one make an environment
>> without data?  Obviously I am missing the point.  My own created function
>> makes a new environment, but I only created it to crunch numbers.  If it
>> doesn't crunch numbers it's useless.
>> The point is, I do not understand the definition of "with" and thus have
>> no idea how to use it.  I guess computerese is analogous to taxlawese.
>> Familiar words have entirely different meanings.
>> Carl Sutton CPA
>>
>> [[alternative HTML version deleted]]
>
>
> This is really hard to read, because you posted in HTML.  If you don't get a
> useful answer, please try again in plain text.
>
> Duncan Murdoch
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] New installation

2016-09-08 Thread jax200
Following up on this thread, I went with ubuntu.  All is good


Many thanks for your responses,

Jack

On Fri, Jun 10, 2016 at 9:54 AM, Leonardo Fontenelle <
leonar...@leonardof.med.br> wrote:

> Em Sex 10 jun. 2016, às 03:58, Rainer M Krug escreveu:
> > Clint Bowman  writes:
> >
> > I am really wondering, why nobody mentioned Ubuntu so far?
> >
> > Ubuntu is a really nice distro, I never had problems with it, many
> > programs are available for Ubuntu, and it is build on Debian
> > (stable). Don't worry about Unity Window manager - there are many other
> > options available (Xubuntu being one of the better known ones - Ubuntu
> > just packed with a different Windows Manager).
> >
> > If you are new to Linux, I would really suggest Ubuntu.
>
> I believe any major Linux distribution will provide decent support for
> R, and I agree there are plenty of reasons for preferring Ubuntu or
> other Linux distributions over Arch Linux. The reason why I suggested
> Arch Linux was how up to date the package is, because that was the
> motivation of the original post.
>
> R 3.3.0 was released by the R Core Team on 2016-05-03, and on 2016-05-04
> it was available in Arch Linux's "testing" repository. On 2016-05-17,
> after at least one week with no (packaging) bug reports, the package was
> moved to the "extra". This is the usual rhythm. Don't be fooled by the
> repository name, it is the repository for popular software like Firefox,
> GNOME and LibreOffice, and it is maintained by official Arch Linux
> developers / package maintainers.
>
> Hope that helps,
>
> Leonardo Ferreira Fontenelle
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] with and evaluation

2016-09-08 Thread Bert Gunter
I echo Duncan's plea.

But I can easily resolve one question:

"What's with "with?  It is one function I do not use because I find it
incomprehensible. "

Consider:

## first, clear the workspace, also known as the Global environment
> rm(list=ls())

## now create a data frame (or list or environment or...) containing
objects named "x" and "w"
> d <- data.frame(x=1:3,w=5:7)
 ## now define a different "x" in the workspace
> x <- 4:6
>
> ## The following will produce an error, because there is no "w" in the 
> workspace
> ##
> w
Error: object 'w' not found
>
> ## But this won't, since with() tells it's expression to first search in d.
>
> with(d,w)
[1] 5 6 7
>
> ## similarly
>
> ##error
> x+w
Error: object 'w' not found
>
> ## But
> with(d, x+w)
[1]  6  8 10
>
> ## In general, the second argument of d can be any expression that you could 
> type at the console.
>
> ## If something can't be found in d, it will be looked for in d's "parent" 
> environment, which is more involved than I want to get here. But:
>
> y <- 5
>
> with(d, x+y) ## used x in d, and y in the workspace.
[1] 6 7 8

HTH

Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Sep 8, 2016 at 3:57 PM, Carl Sutton via R-help
 wrote:
> Hi
> I have doing the R-exercises to improve my R programming capabilities.  
> Data.frame exercise 4 showed me that I have  a language problem.  Here's the 
> problem and my "solution".
> #  Exercise 4#  Create a simple data frame from 3 vectors. Order the entire 
> data frame by the#  first column.df2 <- data.frame(a = 5:1,b = letters[1:5], 
> c = runif(5))order(df2$a) Naturally the order function did nothing.
> Per "help"Description
> order returns a permutation which rearranges its first argument into 
> ascending or descending order, breaking ties by further arguments. sort.list 
> is the same, using only one argument.See the examples for how to use these 
> functions to sort data frames, etc.
> Usage
> order(..., na.last = TRUE, decreasing = FALSE,  method = c("shell", 
> "radix"))
> sort.list(x, partial = NULL, na.last = TRUE, decreasing = FALSE,  
> method = c("shell", "quick", "radix"))Arguments
> ... a sequence of numeric, complex, character or logical vectors, all of the 
> same length, or a classed R object.
> Well, doesn't ... mean any legal object?  I gave it a legal object and got 
> nada.And the answer absolutely has me screaming "Say 
> What"df2[with(df2,order(a)),]
>
> What's with "with?  It is one function I do not use because I find it 
> incomprehensible.  To witEvaluate an R expression in an environment 
> constructed from data, possibly modifying (a copy of) the original data.
>
> First of all, if I'm not modifying data (or as a subset activity creating 
> data), why an I doing whatever it is I'm doing? ("possibly modifying (a copy 
> of) the original data.")
> Evaluate.  According to the thesarus A) assess(v), b) appraise, c) gage.
> OK, am I in a safe area?  I'll evaluate that.  Do I desire future social 
> contact with this person?  I'll evaluate that.In no way do I ever evaluate an 
> equation.  I may attempt to solve it.  I may do a computer program to do the 
> calculations and return a result.  I will probably evaluate the result as to 
> whether or not it helps solve the problem.  Think in terms of an income tax 
> return.  But evaluate an R expression?  No clue what that might mean.
> The remainder of the definition is also obtuse.  an R expression in an 
> environment constructed from data.  Why would one make an environment without 
> data?  Obviously I am missing the point.  My own created function makes a new 
> environment, but I only created it to crunch numbers.  If it doesn't crunch 
> numbers it's useless.
> The point is, I do not understand the definition of "with" and thus have no 
> idea how to use it.  I guess computerese is analogous to taxlawese.  Familiar 
> words have entirely different meanings.
> Carl Sutton CPA
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] with and evaluation

2016-09-08 Thread Jeff Newmiller
You don't say where any of this code you are looking at came from, but I 
suspect [1]. If you feel the author of that site is failing to explain their 
answers sufficiently, please communicate that to them, not us. 

I agree that the documentation file for with() is rather opaque to a beginner 
and could be extended, but the jargon is referring to some valuable concepts 
that you should find a way to learn about (e.g. [2]). 

As Duncan pointed out,  most of your diatribe was destroyed by your use of HTML 
format email, so if you can fix that problem and pose your questions calmly and 
with complete context in the email then someone might be interested in 
discussing them further with you. 

[1] http://r-exercises.com/
[2] http://r-adv.had.co.nz
-- 
Sent from my phone. Please excuse my brevity.

On September 8, 2016 4:07:54 PM PDT, Duncan Murdoch  
wrote:
>On 08/09/2016 6:57 PM, Carl Sutton via R-help wrote:
>> Hi
>> I have doing the R-exercises to improve my R programming
>capabilities.  Data.frame exercise 4 showed me that I have  a language
>problem.  Here's the problem and my "solution".
>> #  Exercise 4#  Create a simple data frame from 3 vectors. Order the
>entire data frame by the#  first column.df2 <- data.frame(a = 5:1,b =
>letters[1:5], c = runif(5))order(df2$a) Naturally the order function
>did nothing.
>> Per "help"Description
>> order returns a permutation which rearranges its first argument into
>ascending or descending order, breaking ties by further arguments.
>sort.list is the same, using only one argument.See the examples for how
>to use these functions to sort data frames, etc.
>> Usage
>> order(..., na.last = TRUE, decreasing = FALSE,  method =
>c("shell", "radix"))
>> sort.list(x, partial = NULL, na.last = TRUE, decreasing = FALSE, 
>method = c("shell", "quick", "radix"))Arguments
>> ... a sequence of numeric, complex, character or logical vectors, all
>of the same length, or a classed R object.
>> Well, doesn't ... mean any legal object?  I gave it a legal object
>and got nada.And the answer absolutely has me screaming "Say
>What"df2[with(df2,order(a)),]
>>
>> What's with "with?  It is one function I do not use because I find it
>incomprehensible.  To witEvaluate an R expression in an environment
>constructed from data, possibly modifying (a copy of) the original
>data.
>>
>> First of all, if I'm not modifying data (or as a subset activity
>creating data), why an I doing whatever it is I'm doing? ("possibly
>modifying (a copy of) the original data.")
>> Evaluate.  According to the thesarus A) assess(v), b) appraise, c)
>gage.
>> OK, am I in a safe area?  I'll evaluate that.  Do I desire future
>social contact with this person?  I'll evaluate that.In no way do I
>ever evaluate an equation.  I may attempt to solve it.  I may do a
>computer program to do the calculations and return a result.  I will
>probably evaluate the result as to whether or not it helps solve the
>problem.  Think in terms of an income tax return.  But evaluate an R
>expression?  No clue what that might mean.
>> The remainder of the definition is also obtuse.  an R expression in
>an environment constructed from data.  Why would one make an
>environment without data?  Obviously I am missing the point.  My own
>created function makes a new environment, but I only created it to
>crunch numbers.  If it doesn't crunch numbers it's useless.
>> The point is, I do not understand the definition of "with" and thus
>have no idea how to use it.  I guess computerese is analogous to
>taxlawese.  Familiar words have entirely different meanings.
>> Carl Sutton CPA
>>
>>  [[alternative HTML version deleted]]
>
>This is really hard to read, because you posted in HTML.  If you don't 
>get a useful answer, please try again in plain text.
>
>Duncan Murdoch
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] with and evaluation

2016-09-08 Thread Duncan Murdoch

On 08/09/2016 6:57 PM, Carl Sutton via R-help wrote:

Hi
I have doing the R-exercises to improve my R programming capabilities.  Data.frame 
exercise 4 showed me that I have  a language problem.  Here's the problem and my 
"solution".
#  Exercise 4#  Create a simple data frame from 3 vectors. Order the entire data 
frame by the#  first column.df2 <- data.frame(a = 5:1,b = letters[1:5], c = 
runif(5))order(df2$a) Naturally the order function did nothing.
Per "help"Description
order returns a permutation which rearranges its first argument into ascending 
or descending order, breaking ties by further arguments. sort.list is the same, 
using only one argument.See the examples for how to use these functions to sort 
data frames, etc.
Usage
order(..., na.last = TRUE, decreasing = FALSE,  method = c("shell", 
"radix"))
sort.list(x, partial = NULL, na.last = TRUE, decreasing = FALSE,  method = c("shell", 
"quick", "radix"))Arguments
... a sequence of numeric, complex, character or logical vectors, all of the 
same length, or a classed R object.
Well, doesn't ... mean any legal object?  I gave it a legal object and got nada.And the 
answer absolutely has me screaming "Say What"df2[with(df2,order(a)),]

What's with "with?  It is one function I do not use because I find it 
incomprehensible.  To witEvaluate an R expression in an environment constructed from 
data, possibly modifying (a copy of) the original data.

First of all, if I'm not modifying data (or as a subset activity creating data), why an I 
doing whatever it is I'm doing? ("possibly modifying (a copy of) the original 
data.")
Evaluate.  According to the thesarus A) assess(v), b) appraise, c) gage.
OK, am I in a safe area?  I'll evaluate that.  Do I desire future social 
contact with this person?  I'll evaluate that.In no way do I ever evaluate an 
equation.  I may attempt to solve it.  I may do a computer program to do the 
calculations and return a result.  I will probably evaluate the result as to 
whether or not it helps solve the problem.  Think in terms of an income tax 
return.  But evaluate an R expression?  No clue what that might mean.
The remainder of the definition is also obtuse.  an R expression in an 
environment constructed from data.  Why would one make an environment without 
data?  Obviously I am missing the point.  My own created function makes a new 
environment, but I only created it to crunch numbers.  If it doesn't crunch 
numbers it's useless.
The point is, I do not understand the definition of "with" and thus have no 
idea how to use it.  I guess computerese is analogous to taxlawese.  Familiar words have 
entirely different meanings.
Carl Sutton CPA

[[alternative HTML version deleted]]


This is really hard to read, because you posted in HTML.  If you don't 
get a useful answer, please try again in plain text.


Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] with and evaluation

2016-09-08 Thread Carl Sutton via R-help
Hi
I have doing the R-exercises to improve my R programming capabilities.  
Data.frame exercise 4 showed me that I have  a language problem.  Here's the 
problem and my "solution".
#  Exercise 4#  Create a simple data frame from 3 vectors. Order the entire 
data frame by the#  first column.df2 <- data.frame(a = 5:1,b = letters[1:5], c 
= runif(5))order(df2$a) Naturally the order function did nothing.  
Per "help"Description
order returns a permutation which rearranges its first argument into ascending 
or descending order, breaking ties by further arguments. sort.list is the same, 
using only one argument.See the examples for how to use these functions to sort 
data frames, etc.
Usage
order(..., na.last = TRUE, decreasing = FALSE,      method = c("shell", 
"radix"))
sort.list(x, partial = NULL, na.last = TRUE, decreasing = FALSE,          
method = c("shell", "quick", "radix"))Arguments
... a sequence of numeric, complex, character or logical vectors, all of the 
same length, or a classed R object.
Well, doesn't ... mean any legal object?  I gave it a legal object and got 
nada.And the answer absolutely has me screaming "Say 
What"df2[with(df2,order(a)),]

What's with "with?  It is one function I do not use because I find it 
incomprehensible.  To witEvaluate an R expression in an environment constructed 
from data, possibly modifying (a copy of) the original data.

First of all, if I'm not modifying data (or as a subset activity creating 
data), why an I doing whatever it is I'm doing? ("possibly modifying (a copy 
of) the original data.")
Evaluate.  According to the thesarus A) assess(v), b) appraise, c) gage.
OK, am I in a safe area?  I'll evaluate that.  Do I desire future social 
contact with this person?  I'll evaluate that.In no way do I ever evaluate an 
equation.  I may attempt to solve it.  I may do a computer program to do the 
calculations and return a result.  I will probably evaluate the result as to 
whether or not it helps solve the problem.  Think in terms of an income tax 
return.  But evaluate an R expression?  No clue what that might mean.
The remainder of the definition is also obtuse.  an R expression in an 
environment constructed from data.  Why would one make an environment without 
data?  Obviously I am missing the point.  My own created function makes a new 
environment, but I only created it to crunch numbers.  If it doesn't crunch 
numbers it's useless.
The point is, I do not understand the definition of "with" and thus have no 
idea how to use it.  I guess computerese is analogous to taxlawese.  Familiar 
words have entirely different meanings.
Carl Sutton CPA

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Revolutions blog: August 2016 roundup

2016-09-08 Thread David Smith via R-help
Since 2008, Microsoft (formerly Revolution Analytics) staff and guests have 
written about R every weekday at the
Revolutions blog: http://blog.revolutionanalytics.com
and every month I post a summary of articles from the previous month of 
particular interest to readers of r-help.

And in case you missed them, here are some articles related to R from the month 
of August:

An amusing short video extols the benefits of reproducible research with R:
http://blog.revolutionanalytics.com/2016/08/a-reproducibility-horror-story.html

A guide to implementing a churn model for mobile phone customers with Microsoft 
R Services:
http://blog.revolutionanalytics.com/2016/08/telco-customer-churn-with-r-in-sql-server-2016.html

Computerworld's Sharon Machlis presents 5 data visualizations each using 5 
lines of R code:
http://blog.revolutionanalytics.com/2016/08/five-great-charts-in-5-lines-of-r-code-each.html

A five-part video series introducing Microsoft R Services:
http://blog.revolutionanalytics.com/2016/08/introduction-to-microsoft-r-server.html

David Robinson analyzes the sentiment of Donald Trump's (and staffers') tweets 
with R
http://blog.revolutionanalytics.com/2016/08/sentiment-analysis-of-trumps-tweets-with-r.html

Microsoft R Open 3.3.1 is now available for Windows, Mac and Linux:
http://blog.revolutionanalytics.com/2016/08/microsoft-r-open-331-now-available-for-windows-mac-and-linux.html

When to use (and when not to use) dual Y axes on time series charts:
http://blog.revolutionanalytics.com/2016/08/dual-axis-time-series.html

You can now use R from PowerBI to import, transform and visualize data:
http://blog.revolutionanalytics.com/2016/08/powerbi-and-r.html

An in-depth look at deep learning frameworks: Part 1
http://blog.revolutionanalytics.com/2016/08/deep-learning-part-1.html and Part 2
http://blog.revolutionanalytics.com/2016/08/deep-learning-part-2.html

The Data Science Summit (Sep 26-27 in Atlanta) features several R-related talks 
and a keynote presentation by Edward
Tufte http://blog.revolutionanalytics.com/2016/08/tufte-keynote.html

The jailbreakr package locates and extracts sub-tables from messy spreadsheets:
http://blog.revolutionanalytics.com/2016/08/jailbreakr.html

Using R to extract information from a PDF table to create a map of dispensary 
locations:
http://blog.revolutionanalytics.com/2016/08/dispensaries.html

Student debt is rising quickly in the US, as shown using the animation package:
http://blog.revolutionanalytics.com/2016/08/student-debt.html

A guide to tuning Apache Spark to optimize computations with Microsoft R Server:
http://blog.revolutionanalytics.com/2016/08/tuning-apache-spark.html

A review of several R packages providing access to online data sources:
http://blog.revolutionanalytics.com/2016/08/r-packages-data-access.html

A cheat-sheet for the dplyrXdf package:
http://blog.revolutionanalytics.com/2016/08/new-cheat-sheet-for-the-dplyrxdf-package.html

A beautiful example of creating publication-ready interactive graphics with R:
http://blog.revolutionanalytics.com/2016/08/interactive-illustrator-quality-graphics-with-r.html

A guide to simulating from the bivariate Normal distribution with R:
http://blog.revolutionanalytics.com/2016/08/simulating-form-the-bivariate-normal-distribution-in-r-1.html

Where to find resources previously available on the now-decommissioned 
inside-r.org:
http://blog.revolutionanalytics.com/2016/08/farewell-inside-rorg.html

An introduction to ROC curves in R: 
http://blog.revolutionanalytics.com/2016/08/roc-curves-in-two-lines-of-code.html

Azure ML Studio now supports Microsoft R Open and Python 2 and 3:
http://blog.revolutionanalytics.com/2016/08/ml-studio-mro-python3.html

General interest stories (not related to R) in the past month included: the 
font of the Stranger Things titles
(http://blog.revolutionanalytics.com/2016/08/because-its-friday-the-font-of-stranger-things.html),
 gravity waves
(http://blog.revolutionanalytics.com/2016/08/because-its-friday-lisa.html), a 
first-squirrel view
(http://blog.revolutionanalytics.com/2016/08/because-its-friday-the-squirrels-pov.html),
 and history set to 70's pop
(http://blog.revolutionanalytics.com/2016/08/because-its-friday-the-knack-to-learning-history.html).

If you're looking for more articles about R, you can find summaries from 
previous months at
http://blog.revolutionanalytics.com/roundups/. You can receive daily blog posts 
via email using services like
blogtrottr.com.

As always, thanks for the comments and please keep sending suggestions to me at 
david...@microsoft.com or via Twitter
(I'm @revodavid).

Cheers,
# David

-- 
David M Smith 
R Community Lead, Microsoft  
Tel: +1 (312) 9205766 (Chicago IL, USA)
Twitter: @revodavid | Blog:  http://blog.revolutionanalytics.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the 

Re: [R-es] ¿Cómo generar tabla apaisada salida PDF con RMarkdown?

2016-09-08 Thread JA Palazón
Hola:

En el documento The |xtable| Gallery 


Puedes encontrar esta referencia:

|print( la.tabla.ancha, floating = TRUE, floating.environment = 
"sidewaystable" )|

Espero que te sea útil

Seguimos



El 08/09/16 a las 17:28, Juan Abasolo escribió:
> Buenas a todos.
>
> No me queda del todo claro si éste es el foro en el que preguntar o 
> debería ser otro, ya que incluye cosas que van más allá de R. Sepan 
> disculpar si me estoy excediendo.
>
> Estoy trabajando con RStudio y quiero generar un documento de salida 
> en PDF; en ese documento tengo bastantes tablas anchas que no entran 
> usando
>
> knitr::kable(la.tabla.ancha)
>
> Sí salen perfectamente en HTML (no son tan anchas). Me resulta 
> evidente que si las pudiera poner a página entera en formato apaisado, 
> no tendría problema y es lo que querría hacer.
>
> Intenté conseguirlo usando 'xtable' con un código que encontré por 
> ahí. Pongo seguido un ejemplo para poner en un documento Rmd
>
> ---
> title: "Tablas que no entran"
> author: "Sandia Urlia"
> date: ""
> output: pdf_document
> ---
>
> ```{r setup, include=FALSE}
> knitr::opts_chunk$set(echo = TRUE)
> ```
>
>
> ```{r}
> la.tabla.ancha <- cars[c(1:10),rep(1,14)]
> knitr::kable(la.tabla.ancha, caption = "La tablaza")
> ```
>
>
> ```{r results='asis'}
> options(xtable.comment = FALSE)
> print(
> xtable::xtable(
> la.tabla.ancha, caption = "La-tablota",
> floating = TRUE,
> floating.environment = "sidewaystable",
> type = "html"
> ))
>
> ```
> Y así se ve que las tablas no entran :__(
>
> Muchas gracias
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es

-- 
___
José Antonio Palazón Ferrando
Profesor Titular. Departamento de Ecología e Hidrología.
Facultad de Biología. Universidad de Murcia.
Campus Universitario de Espinardo
30100 MURCIA-SPAIN
Telf: +34 868 88 49 80
Fax : +34 868 88 39 63
Email: pala...@um.es
http://webs.um.es/palazon


[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Resample with replacement to produce many rarefaction curves with same number of samples

2016-09-08 Thread Stefan Evert

> On 8 Sep 2016, at 16:25, David L Carlson  wrote:
> 
> Sampling without replacement treats the sample as the population for the 
> purposes of estimating the outcomes at smaller sample sizes. Sampling with 
> replacement (the same as bootstrapping) treats the sample as one possible 
> outcome of a larger population at that sample size. 

But the resamples aren't actually independent samples from the underlying 
population, and in contrast to the usual applications of bootstrapping they 
don't give a good approximation of independent samples if you look at type 
("species") counts.

In my understanding – which may be incomplete – bootstrapping works for a test 
statistic computed from the measurements of a single numeric random variable 
(or perhaps several r.v.) in an i.i.d. sample.  The type count cannot be 
expressed as such a test statistic, hence we get the underestimation bias from 
sampling with replacement.

In NLP, we often use parametric power-law models of the population in order to 
extrapolate type counts (e.g. using this implementation 
http://zipfr.r-forge.r-project.org), but this implies strong (and often 
inappropriate) assumptions about the population.

Best,
Stefan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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-es] calculo de datos de temperatura, openair u otra alternativa

2016-09-08 Thread javier valdes

Agradecido por ayudar a encontrar el problema de uqe se quedara pegado R. Hasta el momento no he tenido las dificultades, el cambio de memorias fisicas ayudó.

Estimados les dejo plantedo una inquietud.

necesito calcular lo siguiente;

- TEmperatura media diaria, considerando 3 formas:

 

- Valor de la temperatura a;( (02:00-08:00-14:00-20:00)+(min_diaria)+(max_diaria))/6

 

-(min_diaria)+(max_diaria)/2.(MEDIA)

 

-TODOS LOS VALORES REGISTRADOS EN EL DIA/ Nº DE VALORES.

 

La idea es plotear las 3 formas de medias diarias, y comparar las curvas para anlizar la que mejor se ajusta.

He intentado con openair, pero me da la impresion que esto es un poco mas complejo.

PIdo ayuda para pensar en la mejor alternativa a aplicar.

Agradecido de antemano.

Mis datos estan ordenados de la siguiente forma;

 

fecha             hora       dato


2014-01-01   00:00        1

2014-01-01   00:10        2

Son 86000 datos. Los datos estan tomados cada 10 minutos, es decir, 6 datos diarios.

SAludos a todos

 


Sent: Tuesday, September 06, 2016 at 6:11 AM
From: miguel.angel.rodriguez.mui...@sergas.es
To: javier.val...@mop.gov.cl, c...@qualityexcellence.es
Cc: r-help-es@r-project.org
Subject: Re: [R-es] R SE QUEDA PEGADO e imposibilitado de trabajar.

Hola Javier.

Por lo que comentas (que como bien dice Carlos Ortega, es una
información incompleta) parece que el detonante del error es que la
máquina entre en suspensión/economode.

Varias preguntas

- Es un portátil? un sobremesa?

- Has probado si te pasa eso (en esas condiciones) con otro software que
tenga algún tipo de "trabajo" gráfico?

- Si es un equipo nuevo por qué tiene Windows 7 ¿?¿? Estamos
hablando de trabajo en un entorno corporativo? Tienes algún tipo de
restricción en tu usuario?

Así, sin tener más info, yo te recomendaría revisar qué es lo que hace
tu equipo cuando entra en modo de ahorro de energía (pone sólo la
pantalla en standby? apaga discos? gráfica? ...) .. de hecho, podrías
configurarlo para que estuviera siempre activo y probar un tiempo así
(para intentar determinar las condiciones en las que te pasa).


Un saludo,
Miguel.



El 05/09/2016 a las 22:51, Javier Valdes Cantallopts (DGA) escribió:
> Hola Carlos:
> -Mira, mi máquina es nueva, con 16 giga de memoria Ram, así que no creo que sea problema de recursos
> -En general me pasa esto cuando despliego un Plot. (Después que me paro y vuelvo a mi escritorio, pasado 15 min) el plot se deforma en la pantalla y después al eliminarlo se queda pegado.
> -Me pasa sobre Rstudio.
> -Windows 7 PROF.
>
>
> El 5 de septiembre de 2016, 22:10, Javier Valdes Cantallopts (DGA) > escribió:
> Estimados:
> Tengo problemas con mi programa R. Cada vez que dejo stand-by mi compu por unos minutos, R se queda pegado, e imposibilitado de trabajar, lo que me obliga a cerrarlo y volver a abrirlo cada vez que sucede.
>







Nota: A información contida nesta mensaxe e os seus posibles documentos adxuntos é privada e confidencial e está dirixida únicamente ó seu destinatario/a. Se vostede non é o/a destinatario/a orixinal desta mensaxe, por favor elimínea. A distribución ou copia desta mensaxe non está autorizada.

Nota: La información contenida en este mensaje y sus posibles documentos adjuntos es privada y confidencial y está dirigida únicamente a su destinatario/a. Si usted no es el/la destinatario/a original de este mensaje, por favor elimínelo. La distribución o copia de este mensaje no está autorizada.

See more languages: http://www.sergas.es/aviso-confidencialidad

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es




___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] ¿Cómo generar tabla apaisada salida PDF con RMarkdown?

2016-09-08 Thread Carlos Ortega
Hola,

Creo que esta referencia de StackOverflow te puede ayudar:

http://stackoverflow.com/questions/25849814/rstudio-rmarkdown-both-portrait-and-landscape-layout-in-a-single-pdf

Saludos,
Carlos Ortega
www.qualityexcellence.es

El 8 de septiembre de 2016, 17:28, Juan Abasolo 
escribió:

> Buenas a todos.
>
> No me queda del todo claro si éste es el foro en el que preguntar o
> debería ser otro, ya que incluye cosas que van más allá de R. Sepan
> disculpar si me estoy excediendo.
>
> Estoy trabajando con RStudio y quiero generar un documento de salida en
> PDF; en ese documento tengo bastantes tablas anchas que no entran usando
>
> knitr::kable(la.tabla.ancha)
>
> Sí salen perfectamente en HTML (no son tan anchas). Me resulta evidente
> que si las pudiera poner a página entera en formato apaisado, no tendría
> problema y es lo que querría hacer.
>
> Intenté conseguirlo usando 'xtable' con un código que encontré por ahí.
> Pongo seguido un ejemplo para poner en un documento Rmd
>
> ---
> title: "Tablas que no entran"
> author: "Sandia Urlia"
> date: ""
> output: pdf_document
> ---
>
> ```{r setup, include=FALSE}
> knitr::opts_chunk$set(echo = TRUE)
> ```
>
>
> ```{r}
> la.tabla.ancha <- cars[c(1:10),rep(1,14)]
> knitr::kable(la.tabla.ancha, caption = "La tablaza")
> ```
>
>
> ```{r results='asis'}
> options(xtable.comment = FALSE)
> print(
> xtable::xtable(
> la.tabla.ancha, caption = "La-tablota",
> floating = TRUE,
> floating.environment = "sidewaystable",
> type = "html"
> ))
>
> ```
> Y así se ve que las tablas no entran :__(
>
> Muchas gracias
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[R-es] ¿Cómo generar tabla apaisada salida PDF con RMarkdown?

2016-09-08 Thread Juan Abasolo

Buenas a todos.

No me queda del todo claro si éste es el foro en el que preguntar o 
debería ser otro, ya que incluye cosas que van más allá de R. Sepan 
disculpar si me estoy excediendo.


Estoy trabajando con RStudio y quiero generar un documento de salida en 
PDF; en ese documento tengo bastantes tablas anchas que no entran usando


knitr::kable(la.tabla.ancha)

Sí salen perfectamente en HTML (no son tan anchas). Me resulta evidente 
que si las pudiera poner a página entera en formato apaisado, no tendría 
problema y es lo que querría hacer.


Intenté conseguirlo usando 'xtable' con un código que encontré por ahí. 
Pongo seguido un ejemplo para poner en un documento Rmd


---
title: "Tablas que no entran"
author: "Sandia Urlia"
date: ""
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


```{r}
la.tabla.ancha <- cars[c(1:10),rep(1,14)]
knitr::kable(la.tabla.ancha, caption = "La tablaza")
```


```{r results='asis'}
options(xtable.comment = FALSE)
print(
xtable::xtable(
la.tabla.ancha, caption = "La-tablota",
floating = TRUE,
floating.environment = "sidewaystable",
type = "html"
))

```
Y así se ve que las tablas no entran :__(

Muchas gracias

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[R] [R-pkgs] diffobj released to CRAN

2016-09-08 Thread brodie gaslam via R-packages
diffobj provides tools to compare the visual representation of R objects using 
the Myer's diff algorithm:

## Example:
> mx1 <- matrix(1:9, 3)
> mx2 <- mx1[-2,]
> diffPrint(mx1, mx2, format="raw")
< mx1  > mx2
@@ 1,4 @@  @@ 1,3 @@
.   [,1] [,2] [,3] [,1] [,2] [,3]
. [1,]147[1,]147
< [2,]258  ~
. [3,]369[2,]369

This is similar to `tools::Rdiff`, but is easier to use directly with R 
objects, has colorized output if your terminal supports it, has semantic-aware 
handling of the text output of R objects, and does not require the GNU diff 
utility to be available on the system.

See the vignette for more details 
, and 
the Github page to submit issues .

Many thanks to Uwe Ligges and Kurt Hornik for their patience with my first CRAN 
submission.

Brodie Gaslam.

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 interpret lm's coefficients?

2016-09-08 Thread Bert Gunter
Petr Pikal said:

"The explanation is not for few lines of plain text short mail.

But maybe others will disagree."

Not I -- you should consult your teachers or texts (as Petr said) for
basic statistical questions.

I'll add a nugget to Petr's reply, however: it is very often the case
(for correlated regressors/covariates) that individual coefficients
cannot and should not be interpreted -- the "fit" is merely a
prediction engine.''

Cheers,
Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Sep 8, 2016 at 5:43 AM, Matti Viljamaa  wrote:
> I’m trying to understand how to interpret the return values, specifically 
> “Coefficients:”, of R’s lm function. I’m using it with a dichotomic predictor 
> (mom_hs).
>
> lm(data$kid_score ~ data$mom_hs) returns
>
> Coefficients:
> #   (Intercept)  data$mom_hs
> # 77.5511.77
>
> I read that the (Intercept) value is the “y-intercept” value b, i.e. the y 
> value where the line intercept the y-axis.
>
> The second value is the value of the term m (or “slope”) in the equation of a 
> line y=mx+b.
>
> However,
>
> These two numbers also have the following interpretations:
>
> b or (Intercept) value is the same as:
> The mean of those data$kid_score that have data$mom_hs == 0.
> Why is this a valid interpretation?
>
> m or data$mom_hs value is the same as:
> The difference of means between those data$kid_score that have data$mom_hs == 
> 1
> and those data$kid_score that have data$mom_hs == 0.
> Why is this a valid interpretation?
>
> Can someone explain?
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] The R Journal, Volume 8, Issue 1

2016-09-08 Thread Michael Lawrence
Dear all,

The latest issue of The R Journal is now available at
http://journal.r-project.org/archive/2016-1/

Many thanks to all contributors.

Michael Lawrence

___
r-annou...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-announce

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Resample with replacement to produce many rarefaction curves with same number of samples

2016-09-08 Thread David L Carlson
One way around this would be to use multinomial sampling, but as Stefan 
indicated, the maximum number of species at any size will, of course be 40 (in 
your example):

> set.seed(42)
> # Generate one sample
> census <- round(rlnorm(40))
> sum(census) # Sample size
[1] 76
> sum(as.logical(census)) # No of species present
[1] 31
> 
> # Create probabilities
> census.adj <- census
> # Add .5 to each 0 value
> census.adj[census.adj==0] <- .5
> census.adj <- census.adj/sum(census.adj)
> 
> pcensus <- rmultinom(50, 150, census.adj)
> 
> Species <- apply(pcensus, 2, function(x) sum(as.logical(x)))
> quantile(Species)
  0%  25%  50%  75% 100% 
  29   33   34   36   38

So projecting a sample of 76 to 150 gives an estimated median of 34 species.

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David L Carlson
Sent: Thursday, September 8, 2016 9:25 AM
To: Stefan Evert; Nick Pardikes
Cc: R-help Mailing List
Subject: Re: [R] Resample with replacement to produce many rarefaction curves 
with same number of samples

Sampling without replacement will never find more species than there are in 
your original sample either! 

Sampling without replacement treats the sample as the population for the 
purposes of estimating the outcomes at smaller sample sizes. Sampling with 
replacement (the same as bootstrapping) treats the sample as one possible 
outcome of a larger population at that sample size. 

There is another consideration. A zero value means different things at 
different sample sizes. At sample size 10, it means approximately less than 
10%, but at sample size 100, it means approximately less than 1%, and so on. 

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Stefan Evert
Sent: Thursday, September 8, 2016 7:46 AM
To: Nick Pardikes
Cc: R-help Mailing List
Subject: Re: [R] Resample with replacement to produce many rarefaction curves 
with same number of samples


> On 7 Sep 2016, at 00:07, Nick Pardikes  wrote:
> 
> Is there any way to use rarecurve to resample a community (row) with
> replacement the same number of times for all 50 communities? With
> replacement is important because the communities differ greatly in their
> size (number of species).

Are you sure it makes sense to resample with replacement?  This will 
systematically underestimate the number of species at a given sample size 
(because of the artificial repetition) and will never find more species than 
there are in your original sample.

Best,
Stefan
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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: hello i have a question on music analysis and mathematical synthesis related to r code

2016-09-08 Thread Bert Gunter
Darth:

Please always cc the list if it is not a strictly personal
communication. The information you provide may be relevant and allow
others to help you.

Note also: Jim's suggestion of tuneR was a top hit from the google
search I suggested.

-- Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )



-- Forwarded message --
From: darth brando 
Date: Thu, Sep 8, 2016 at 12:16 AM
Subject: Re: [R] hello i have a question on music analysis and
mathematical synthesis related to r code
To: Bert Gunter 


I've tried google to not much avail I'm afraid. Unless you can point
me in a more specific direction on how to browse the R category stuff
(like i mentioned I'm a very noobs user).

Unfortunately due to google's reliance on page rank; it gives you the
most popular most linked and most viewed pages and not the most
accurate or relevant.

Most of the tutorial/how to/help/ fix articles I've found are on how
to analyze individual tracks and correlate with other analyzed packets
but manually and one by one.

I wish to analyze an entire library to discover patterns and
algorithms within to then create an algorithm which applies those
patterns on permutation to near infinitely execute algorithmic
writing/reinterpretation of the found patterns and data sets.

In short;

I have a library of X amount of tracks,

I wish R code to find all:

1) tempo modulation patterns correlated to the pattern of used scales
and sequences to initiate those tempo modulations

2) the pitch an note pattern motifs for arpeggios used within that
data set and the algorithmic range they create when correlated

3) the min/max range on pitch, note, riffs and ad-lib/ step aka
extraneous added sfx (the range of the outliers and the pattern
algorithm of them within the library)

4) the pattern of min/max range of phrases/bars within the library

I will then essentially use this data and plug the parameters into a
synthesizer emulator application which will infinitely (until turned
off) attempt to emulate the "type" of music the library represents
using algorithms to continuously write sound data uniquely within the
4) pattern parameters above that I mentioned.

so far nothing I have found other than the data on R code logarithms
on chaos theory bifurcation model graphing comes close to the scope I
need help with.

> On Sep 8, 2016, at 02:51, Bert Gunter  wrote:
>
> Search on the Internet!
>
> "Analyze music in R" had hits for several R packages that seemed like
> they might be relevant.
>
> Apologies if you've already done this and found mothing to meet your needs.
>
> Cheers,
> Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>> On Wed, Sep 7, 2016 at 10:57 PM, darth brando  
>> wrote:
>> Apologies for the long title but it is semi specific a topic and yes I am a 
>> noobs user to the system. I have read the guide and will attempt to adhere 
>> to the guide in this process and I do apologize in advance if I fail to do 
>> so, this is my first time here.
>>
>> To the point; firstly version:
>>
>> I have windows 7 64 bit OS, I'm going to be working with most current up to 
>> date version of R code for that OS with optional plug ins as needed, I am 
>> going to be using R code in conjunction with Fruity Loop Studio, 
>> dosbox/visual studio, and both synthesizer plug ins for Fruity Loop Studio 
>> and a physical soundblaster sound card in my alienware 15 2015 version as 
>> well as possibly a few emulator or OS instances for retro hardware to 
>> experiment with. Its a lot of software to take in yea, some I know by heart 
>> others like R Code I am a noob at.
>>
>> Now that the toolbox of software is out of the way; my Question:
>>
>> Music is largely mathematically based, R Code is perfect for analyzing very 
>> large sets of data, naturally I saw some potential and wondered about the 
>> specifics of the type of application which follows.
>>
>> I wish to use R Code to analyze portions of my personal library of music in 
>> order to discover the main sets of underlying patterns within that portion 
>> of my music library. I then wish to utilize patterns discovered to create a 
>> program which using proper algorithms set to those patterns to digitally 
>> synthesize music which conforms to those patterns but that would create said 
>> music automatically and potentially non stop; as in it does not stop writing 
>> the music and playing it until you turn it off. However; I do not wish this 
>> program to create a few tracks and play it on a loop, yes due to the 
>> patterns and the algorithms, certain bars and phrases will inevitably repeat 
>> but that 

Re: [R] How to interpret lm's coefficients?

2016-09-08 Thread PIKAL Petr
Hi

see in line

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Matti
> Viljamaa
> Sent: Thursday, September 8, 2016 2:44 PM
> To: r-help@R-project.org
> Subject: [R] How to interpret lm's coefficients?
>
> I’m trying to understand how to interpret the return values, specifically
> “Coefficients:”, of R’s lm function. I’m using it with a dichotomic predictor
> (mom_hs).
>
> lm(data$kid_score ~ data$mom_hs) returns
>
> Coefficients:
> #   (Intercept)  data$mom_hs
> # 77.5511.77
>
> I read that the (Intercept) value is the “y-intercept” value b, i.e. the y 
> value
> where the line intercept the y-axis.
>
> The second value is the value of the term m (or “slope”) in the equation of a
> line y=mx+b.
>
> However,
>
> These two numbers also have the following interpretations:
>
> b or (Intercept) value is the same as:
> The mean of those data$kid_score that have data$mom_hs == 0.
> Why is this a valid interpretation?

Well, you should rather to look into some statistical textbook. E.g.
Practical Regression and Anova using R,  Julian J. Faraway
or
SimpleR, J. Verzani

The explanation is not for few lines of plain text short mail.

But maybe others will disagree.

Cheers
Petr

PS.
Or you can try to find an interpretation from plots yourself.

plot(data$kid_score ~ data$mom_hs)
abline( lm(data$kid_score ~ data$mom_hs)



>
> m or data$mom_hs value is the same as:
> The difference of means between those data$kid_score that have
> data$mom_hs == 1 and those data$kid_score that have data$mom_hs == 0.
> Why is this a valid interpretation?
>
> Can someone explain?
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
R-help@r-project.org mailing list -- To 

Re: [R] R-specific Software Requirement Specification

2016-09-08 Thread Duncan Murdoch

On 08/09/2016 10:15 AM, Michael Friendly wrote:
devtools::document() is meant to be used within an R **package**, not 
for a standalone file.

Try devtools::create() first.

But at any rate, roxygen format seems to answer your question about 
how to describe the
specifications for a collection of functions written by different 
people.  Translation to .Rd

is not essential for this purpose.


I would say that separate Rd files would be preferable here.  If Harold 
writes the spec and puts it in Roxygen comments in a .R file, then 
Michael writes the function to match the comments, Michael may 
accidentally edit the Roxygen comments at the same time.  It's more work 
for Harold to notice that his spec has been changed than if it is in a 
separate file.


Duncan Murdoch


Create a package, put it on github, and away you go.

On 9/8/2016 9:53 AM, Doran, Harold wrote:

Then from the R workspace I try


>document()

Error: Could not find package root.

And also

>document('path\\to\\file\\test.R')

And gives same error



--
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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Resample with replacement to produce many rarefaction curves with same number of samples

2016-09-08 Thread David L Carlson
Sampling without replacement will never find more species than there are in 
your original sample either! 

Sampling without replacement treats the sample as the population for the 
purposes of estimating the outcomes at smaller sample sizes. Sampling with 
replacement (the same as bootstrapping) treats the sample as one possible 
outcome of a larger population at that sample size. 

There is another consideration. A zero value means different things at 
different sample sizes. At sample size 10, it means approximately less than 
10%, but at sample size 100, it means approximately less than 1%, and so on. 

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Stefan Evert
Sent: Thursday, September 8, 2016 7:46 AM
To: Nick Pardikes
Cc: R-help Mailing List
Subject: Re: [R] Resample with replacement to produce many rarefaction curves 
with same number of samples


> On 7 Sep 2016, at 00:07, Nick Pardikes  wrote:
> 
> Is there any way to use rarecurve to resample a community (row) with
> replacement the same number of times for all 50 communities? With
> replacement is important because the communities differ greatly in their
> size (number of species).

Are you sure it makes sense to resample with replacement?  This will 
systematically underestimate the number of species at a given sample size 
(because of the artificial repetition) and will never find more species than 
there are in your original sample.

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


Re: [R] R-specific Software Requirement Specification

2016-09-08 Thread Michael Friendly
devtools::document() is meant to be used within an R **package**, not 
for a standalone file.
Try devtools::create() first.

But at any rate, roxygen format seems to answer your question about how 
to describe the
specifications for a collection of functions written by different 
people.  Translation to .Rd
is not essential for this purpose.

Create a package, put it on github, and away you go.

On 9/8/2016 9:53 AM, Doran, Harold wrote:
> Then from the R workspace I try
>
>> >document()
> Error: Could not find package root.
>
> And also
>> >document('path\\to\\file\\test.R')
> And gives same error


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


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] CopyDetect Packgace

2016-09-08 Thread Jeff Newmiller
Read the Posting Guide mentioned at the bottom of this message. 

Learn how to pose a question online. [1]

Post using plain text format so your code doesn't get damaged by the HTML 
formatting. 

[1] http://adv-r.had.co.nz/Reproducibility.html
-- 
Sent from my phone. Please excuse my brevity.

On September 8, 2016 5:50:43 AM PDT, Ahmad Nursalim  
wrote:
>Dear All
>x <- CopyDetect2 (data = data.abcd,
>  item.par = slopintrc,
>  pair = c (pairs [i, 1], pairs [i, 2]),
>  options = c ("A", "B", "C", "D", "E"))
>
>What is the mean pair = c (pairs [i, 1], pairs [i, 2]),
>
>Pleas Help Me
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R-specific Software Requirement Specification

2016-09-08 Thread Doran, Harold
I'm trying the example on Hadley's page. I save the following into a file 
called "test.R"

#' Add together two numbers.
#' 
#' @param x A number.
#' @param y A number.
#' @return The sum of \code{x} and \code{y}.
#' @examples
#' add(1, 1)
#' add(10, 1)
add <- function(x, y) {
  x + y
}

Then from the R workspace I try

> document()
Error: Could not find package root.

And also
> document('path\\to\\file\\test.R')

And gives same error


Below is my session information.


> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C  
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

other attached packages:
[1] devtools_1.12.0

loaded via a namespace (and not attached):
[1] magrittr_1.5   tools_3.3.1withr_1.0.2roxygen2_5.0.1 Rcpp_0.12.7   
[6] memoise_1.0.0  stringi_1.1.1  stringr_1.1.0  digest_0.6.10

-Original Message-
From: Michael Friendly [mailto:frien...@yorku.ca] 
Sent: Thursday, September 08, 2016 9:19 AM
To: Doran, Harold ; r-help@r-project.org
Cc: Duncan Murdoch 
Subject: Re: R-specific Software Requirement Specification

You might also or instead look at the roxygen way of doing things, which maps 
to Rd files, but are much easier to write. In R Studio, Code ->  Insert Roxygen 
skeleton does this for you from an existing function.  See: 
http://r-pkgs.had.co.nz/man.html

#' title goes here
#'
#' description goes here
#'
#' @param p1desc of p1
#' @param p2
#' @param ...
#' @return
#' @export
#' @imports
#' @author
#' @seealso
#' @examples
#' example lines

foo <- function (p1, p2, ... ) {

}


On 9/7/2016 12:46 PM, Duncan Murdoch wrote:
> On 07/09/2016 11:35 AM, Doran, Harold wrote:
>> I'm building a large program with many different people contributing 
>> to the coding in R and so it needs a well-articulated design spec. 
>> The program will have many different functions that must interact 
>> with each other, but the individual functions will be written by 
>> different people.
>>
>> I'm curious if anyone has an R-specific SRS document to share that 
>> they have used for a similar purpose listing the objectives for each 
>> function, class definition, generics, what the function inherits 
>> from, and so on, or perhaps even a useful template for such work.
>
> The Rd help pages do some of this.  They aren't so good at describing 
> the class hierarchy but are good at specifying individual functions.
>
> Duncan Murdoch
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] get start and end date of ISO weeks giving a date as input

2016-09-08 Thread Enrico Schumann
Hi Veronica,

please see inline.

On Thu, 08 Sep 2016, Veronica Andreo  writes:

> Hello Luisfo and Enrico,
>
> Thanks for your help! I've been testing both
> solutions... results differ for the same date (I
> changed both functions to use ISO8601). And I added
> contiguous dates, to see how they handle the
> start-end of the week.
>
> So, here the results:
>
> ### one example
> d <- c("2010-08-21","2010-08-22","2010-08-23","2010-08-24")
> iso_start_end <- function(d) {
>   d <- as.Date(d)
>   wday <- as.POSIXlt(d)$wday
>   data.frame(date = d,
>              week = format(d, "%V"),
>              starts = d - wday + 1,
>              ends = d + 7 - wday)
> }
> iso_start_end(d)
>
>         date week     starts       ends
> 1 2010-08-21   33 2010-08-16 2010-08-22
> 2 2010-08-22   33 2010-08-23 2010-08-29
> 3 2010-08-23   34 2010-08-23 2010-08-29
> 4 2010-08-24   34 2010-08-23 2010-08-29

Yes, the second date makes no sense, and it happens
because Sunday is 0 (and not 7). My bad. Here is
a fixed version:

  iso_start_end <- function(d) {
  d <- as.Date(d)
  wday <- as.POSIXlt(d)$wday
  wday[wday == 0] <- 7
  data.frame(date = d,
 week = format(d, "%V"),
 starts = d - wday + 1,
 ends = d + 7 - wday)
  }


> ### the other example:
> dd <- as.Date(strptime('2010-08-21', format="%Y-%m-%d", tz="GMT"))
> ref.date <- as.Date(strptime(paste0(year(dd),"-01-01"), format="%Y-%m-%d"))
> bound.dates <- ref.date + 7 * (isoweek(dd)) + c(0,6)
> bound.dates
> [1] "2010-08-20" "2010-08-26"

You can use the function "weekdays" to see check the
results.

  > weekdays(bound.dates)
  [1] "Friday"   "Thursday"

> So, researching a bit more and inspired by those
> examples, I eventually came up with this solution
> that seems to work fine... I share in case that any
> other has a similar problem:
>
> # get ISOweek for my vector of dates 
> week_iso<-ISOweek(d)
>
> # vector with the format %Y-W%V-1 for start day of the ISO week
> week_iso_day1 <- paste(week_iso,1, sep="-")
>
> #  vector with the format %Y-W%V-7 for end day of the ISO week
> week_iso_day7 <- paste(week_iso, 7, sep="-")
>
> # use ISOweek2date
> data.frame(date= d, week_iso = week_iso, start = ISOweek2date(week_iso_day1), 
> end = ISOweek2date(week_iso_day7)
>
> date week_iso  startend
> 1 2010-08-21 2010-W33 2010-08-16 2010-08-22
> 2 2010-08-22 2010-W33 2010-08-16 2010-08-22
> 3 2010-08-23 2010-W34 2010-08-23 2010-08-29
> 4 2010-08-24 2010-W34 2010-08-23 2010-08-29

The updated 'iso_start_end' gives the same result.
  
  date week starts   ends
  1 2010-08-21   33 2010-08-16 2010-08-22
  2 2010-08-22   33 2010-08-16 2010-08-22
  3 2010-08-23   34 2010-08-23 2010-08-29
  4 2010-08-24   34 2010-08-23 2010-08-29


Kind regards
 Enrico

> Thanks again for your time, ideas and help!
>
> Best,
> Vero
>
> 2016-09-08 8:20 GMT-03:00 Luisfo :
>
> Dear Veronica,
>
> Here there's a way of doing what you requested.
>
> library("lubridate")
> # your date '2010-08-21' as Date object
> dd <- as.Date(strptime("2010-08-21", format="%Y-%m-%d", tz="GMT"))
> # take the first day of the year as Date object, i.e. 2010-01-01 in our 
> example
> ref.date <- as.Date(strptime(paste0(year(dd),"-01-01"), 
> format="%Y-%m-%d", tz="GMT"))
> # the start and end dates
> bound.dates <- ref.date + 7 * (week(dd)-1) + c(0,6)
>
> I hope you find it useful.
>
> Best,
>
> Luisfo Chiroque
> PhD Student | PhD Candidate
> IMDEA Networks Institute
> http://fourier.networks.imdea.org/people/~luis_nunez/
>
> On 09/08/2016 12:13 PM, Veronica Andreo wrote:
>
> Hello list,
> 
> Is there a quick way to get start and end date (%Y-%m-%d) from ISO
> weeks if I only have dates?
> 
> For example, I have this date in which some event happened:
> "2010-08-21". Not only I want the ISO week, which I can obtain either
> with isoweek (lubridate) or ISOweek (ISOweek), but I want the start
> and end date of that ISO week.
> 
> Do I need to print all ISO weeks from the period of interest and
> sample there for start and end date? Or is there a better way to do
> that?
> 
> Thanks a lot in advance!
> 
> Best,
> Veronica
>

-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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

Re: [R] R-specific Software Requirement Specification

2016-09-08 Thread Michael Friendly
You might also or instead look at the roxygen way of doing things, which 
maps to Rd files, but are much easier to write. In R Studio,
Code ->  Insert Roxygen skeleton does this for you from an existing 
function.  See: http://r-pkgs.had.co.nz/man.html


#' title goes here
#'
#' description goes here
#'
#' @param p1desc of p1
#' @param p2
#' @param ...
#' @return
#' @export
#' @imports
#' @author
#' @seealso
#' @examples
#' example lines

foo <- function (p1, p2, ... ) {

}


On 9/7/2016 12:46 PM, Duncan Murdoch wrote:

On 07/09/2016 11:35 AM, Doran, Harold wrote:

I'm building a large program with many different people contributing
to the coding in R and so it needs a well-articulated design spec. The
program will have many different functions that must interact with
each other, but the individual functions will be written by different
people.

I'm curious if anyone has an R-specific SRS document to share that
they have used for a similar purpose listing the objectives for each
function, class definition, generics, what the function inherits from,
and so on, or perhaps even a useful template for such work.


The Rd help pages do some of this.  They aren't so good at describing
the class hierarchy but are good at specifying individual functions.

Duncan Murdoch



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] get start and end date of ISO weeks giving a date as input

2016-09-08 Thread Veronica Andreo
Hello Luisfo and Enrico,

Thanks for your help! I've been testing both solutions... results differ
for the same date (I changed both functions to use ISO8601). And I added
contiguous dates, to see how they handle the start-end of the week.

So, here the results:

### one example
d <- c("2010-08-21","2010-08-22","2010-08-23","2010-08-24")
iso_start_end <- function(d) {
  d <- as.Date(d)
  wday <- as.POSIXlt(d)$wday
  data.frame(date = d,
 week = format(d, "%V"),
 starts = d - wday + 1,
 ends = d + 7 - wday)
}
iso_start_end(d)

date week starts   ends
1 2010-08-21   33 2010-08-16 2010-08-22
*2 2010-08-22   33 2010-08-23 2010-08-29*
3 2010-08-23   34 2010-08-23 2010-08-29
4 2010-08-24   34 2010-08-23 2010-08-29

### the other example:
dd <- as.Date(strptime('2010-08-21', format="%Y-%m-%d", tz="GMT"))
ref.date <- as.Date(strptime(paste0(year(dd),"-01-01"), format="%Y-%m-%d"))
bound.dates <- ref.date + 7 * (isoweek(dd)) + c(0,6)
bound.dates
[1] "2010-08-20" "2010-08-26"

So, researching a bit more and inspired by those examples, I eventually
came up with this solution that seems to work fine... I share in case that
any other has a similar problem:

# get ISOweek for my vector of dates
week_iso<-ISOweek(d)

# vector with the format %Y-W%V-1 for start day of the ISO week
week_iso_day1 <- paste(week_iso,1, sep="-")

#  vector with the format %Y-W%V-7 for end day of the ISO week
week_iso_day7 <- paste(week_iso, 7, sep="-")

# use ISOweek2date
data.frame(date= d, week_iso = week_iso, start =
ISOweek2date(week_iso_day1), end = ISOweek2date(week_iso_day7)

date week_iso  startend
1 2010-08-21 2010-W33 2010-08-16 2010-08-22
2 2010-08-22 2010-W33 2010-08-16 2010-08-22
3 2010-08-23 2010-W34 2010-08-23 2010-08-29
4 2010-08-24 2010-W34 2010-08-23 2010-08-29


Thanks again for your time, ideas and help!

Best,
Vero


2016-09-08 8:20 GMT-03:00 Luisfo :

> Dear Veronica,
>
> Here there's a way of doing what you requested.
>
> library("lubridate")
> # your date '2010-08-21' as Date object
> dd <- as.Date(strptime("2010-08-21", format="%Y-%m-%d", tz="GMT"))
> # take the first day of the year as Date object, i.e. 2010-01-01 in our
> example
> ref.date <- as.Date(strptime(paste0(year(dd),"-01-01"),
> format="%Y-%m-%d", tz="GMT"))
> # the start and end dates
> bound.dates <- ref.date + 7 * (week(dd)-1) + c(0,6)
>
> I hope you find it useful.
>
> Best,
> *Luisfo Chiroque*
>
> *PhD Student | PhD Candidate IMDEA Networks Institute*
> http://fourier.networks.imdea.org/people/~luis_nunez/
>
> On 09/08/2016 12:13 PM, Veronica Andreo wrote:
>
> Hello list,
>
> Is there a quick way to get start and end date (%Y-%m-%d) from ISO
> weeks if I only have dates?
>
> For example, I have this date in which some event happened:
> "2010-08-21". Not only I want the ISO week, which I can obtain either
> with isoweek (lubridate) or ISOweek (ISOweek), but I want the start
> and end date of that ISO week.
>
> Do I need to print all ISO weeks from the period of interest and
> sample there for start and end date? Or is there a better way to do
> that?
>
> Thanks a lot in advance!
>
> Best,
> Veronica
>
> __r-h...@r-project.org mailing 
> list -- To UNSUBSCRIBE and more, 
> seehttps://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] CopyDetect Packgace

2016-09-08 Thread Ahmad Nursalim
Dear All
x <- CopyDetect2 (data = data.abcd,
  item.par = slopintrc,
  pair = c (pairs [i, 1], pairs [i, 2]),
  options = c ("A", "B", "C", "D", "E"))

What is the mean pair = c (pairs [i, 1], pairs [i, 2]),

Pleas Help Me

[[alternative HTML version deleted]]

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


Re: [R] Is there t.test with null hypothesis?

2016-09-08 Thread Michael Dewey

Dear Matti

On 08/09/2016 13:06, Matti Viljamaa wrote:

I’m trying to do a t-test, where the null hypothesis for the two data sets has 
to be:

“the means are the same”/“difference in means is equal to one”



That is two statements not one. Do you mean that your null is that the 
difference is 1? If so just subtract 1 from all the scores in the group 
which is predicted to be higher and run the t-test on the resulting scores.



Using the t.test function in R I’m able to see that it uses the following 
“alternative hypothesis”:

alternative hypothesis: true difference in means is not equal to 0


It means that the null is that the difference is zero.



but does not seem to specify null hypothesis. I believe alternative and null 
hypotheses are different, although
I don’t exactly know how.

So what should I use for my t-test? Or is t.test ok?

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



--
Michael
http://www.dewey.myzen.co.uk/home.html

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

Re: [R] Is there t.test with null hypothesis?

2016-09-08 Thread Matti Viljamaa

> On 08 Sep 2016, at 15:48, Michael Dewey  wrote:
> 
> Dear Matti
> 
> On 08/09/2016 13:06, Matti Viljamaa wrote:
>> I’m trying to do a t-test, where the null hypothesis for the two data sets 
>> has to be:
>> 
>> “the means are the same”/“difference in means is equal to one”
>> 
> 
> That is two statements not one. Do you mean that your null is that the 
> difference is 1? If so just subtract 1 from all the scores in the group which 
> is predicted to be higher and run the t-test on the resulting scores.

Sorry typo, should of course be:

“the means are the same”/“difference in means is equal to zero”

so they are synonymous.

>> Using the t.test function in R I’m able to see that it uses the following 
>> “alternative hypothesis”:
>> 
>> alternative hypothesis: true difference in means is not equal to 0
> 
> It means that the null is that the difference is zero.
> 
>> 
>> but does not seem to specify null hypothesis. I believe alternative and null 
>> hypotheses are different, although
>> I don’t exactly know how.
>> 
>> So what should I use for my t-test? Or is t.test ok?
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> -- 
> Michael
> http://www.dewey.myzen.co.uk/home.html

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Resample with replacement to produce many rarefaction curves with same number of samples

2016-09-08 Thread Stefan Evert

> On 7 Sep 2016, at 00:07, Nick Pardikes  wrote:
> 
> Is there any way to use rarecurve to resample a community (row) with
> replacement the same number of times for all 50 communities? With
> replacement is important because the communities differ greatly in their
> size (number of species).

Are you sure it makes sense to resample with replacement?  This will 
systematically underestimate the number of species at a given sample size 
(because of the artificial repetition) and will never find more species than 
there are in your original sample.

Best,
Stefan
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 interpret lm's coefficients?

2016-09-08 Thread Matti Viljamaa
I’m trying to understand how to interpret the return values, specifically 
“Coefficients:”, of R’s lm function. I’m using it with a dichotomic predictor 
(mom_hs).

lm(data$kid_score ~ data$mom_hs) returns 

Coefficients:
#   (Intercept)  data$mom_hs  
# 77.5511.77

I read that the (Intercept) value is the “y-intercept” value b, i.e. the y 
value where the line intercept the y-axis.

The second value is the value of the term m (or “slope”) in the equation of a 
line y=mx+b.

However,

These two numbers also have the following interpretations:

b or (Intercept) value is the same as:
The mean of those data$kid_score that have data$mom_hs == 0.
Why is this a valid interpretation?

m or data$mom_hs value is the same as:
The difference of means between those data$kid_score that have data$mom_hs == 1
and those data$kid_score that have data$mom_hs == 0.
Why is this a valid interpretation?

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

Re: [R] Is there t.test with null hypothesis?

2016-09-08 Thread Rick Bilonick

You need to include the argument "mu=1" (without parentheses). For example:

> t.test(group1,group2, mu=1)

for a two-sample independent groups t-test. If you type:

> ?t.test

you can see the help information for the t.test function.

RIck

On 09/08/2016 08:06 AM, Matti Viljamaa wrote:

I’m trying to do a t-test, where the null hypothesis for the two data sets has 
to be:

“the means are the same”/“difference in means is equal to one”

Using the t.test function in R I’m able to see that it uses the following 
“alternative hypothesis”:

alternative hypothesis: true difference in means is not equal to 0

but does not seem to specify null hypothesis. I believe alternative and null 
hypotheses are different, although
I don’t exactly know how.

So what should I use for my t-test? Or is t.test ok?

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fstat.ethz.ch%2fmailman%2flistinfo%2fr-help=01%7c01%7crab45%40pitt.edu%7c99a5b7c1533548c5ead708d3d7e0bb76%7c9ef9f489e0a04eeb87cc3a526112fd0d%7c1=Pf9Tku8lIeH9quNmY2dEmR4HNSLgShRP7p7Hx9HUCMY%3d
PLEASE do read the posting guide 
https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fwww.R-project.org%2fposting-guide.html=01%7c01%7crab45%40pitt.edu%7c99a5b7c1533548c5ead708d3d7e0bb76%7c9ef9f489e0a04eeb87cc3a526112fd0d%7c1=eGCmYy70ceyiJ%2bpgDXA8SaHHma%2f4DbxhIbSARUDYwxg%3d
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Fitting Mixture distributions

2016-09-08 Thread Martin Maechler
> Bert Gunter 
> on Wed, 7 Sep 2016 23:47:40 -0700 writes:

> "please suggest what can I do to resolve this
> issue."

> Fitting normal mixtures can be difficult, and sometime the
> optimization algorithm (EM) will get stuck with very slow convergence.
> Presumably there are options in the package to either increase the max
> number of steps before giving up or make the convergence criteria less
> sensitive. The former will increase the run time and the latter will
> reduce the optimality (possibly leaving you farther from the true
> optimum). So you should look into changing these as you think
> appropriate.

I'm jumping in late, without having read everything preceding.

One of the last messages seemed to indicate that you are looking
at mixtures of *one*-dimensional gaussians.

If this is the case, I strongly recommend looking at (my) CRAN
package 'nor1mix' (the "1" is for "*one*-dimensional).

For a while now that small package is providing an alternative
to the EM, namely direct MLE, simply using optim() where the
likelihood uses a somewhat smart parametrization.

Of course, *as the EM*, this also depends on the starting value,
but my (limited) experience has been that
  nor1mix::norMixMLE()
works considerably faster and more reliable than the EM (which I
also provide asnor1mix::norMixEM() .

Apropos 'starting value': The help page shows how to use
kmeans() for "somewhat" reliable starts; alternatively, I'd
recommend using cluster::pam() to get a start there.

I'm glad to hear about experiences using these / comparing
these with other approaches.

Martin


--
Martin Maechler,
ETH Zurich


> On Wed, Sep 7, 2016 at 3:51 PM, Aanchal Sharma
>  wrote:
>> Hi Simon
>> 
>> I am facing same problem as described above. i am trying to fit gaussian
>> mixture model to my data using normalmixEM. I am running a Rscript which
>> has this function running as part of it for about 17000 datasets (in 
loop).
>> The script runs fine for some datasets, but it terminates when it
>> encounters one dataset with the following error:
>> 
>> Error in normalmixEM(expr_glm_residuals, lambda = c(0.75, 0.25), k = 2,  
:
>> Too many tries!
>> 
>> (command used: expr_mix_gau <- normalmixEM(expr_glm_residuals, lambda =
>> c(0.75,0.25), k = 2, epsilon = 1e-08, maxit = 1, maxrestarts=200, 
verb
>> = TRUE))
>> (expr_glm_residuals is my dataset which has residual values for different
>> samples)
>> 
>> It is suggested that one should define the mu and sigma in the command by
>> looking at your dataset. But in my case there are many datasets and it 
will
>> keep on changing every time. please suggest what can I do to resolve this
>> issue.
>> 
>> Regards
>> Anchal
>> 
>> On Tuesday, 16 July 2013 17:53:09 UTC-4, Simon Zehnder wrote:
>>> 
>>> Hi Tjun Kiat Teo,
>>> 
>>> you try to fit a Normal mixture to some data. The Normal mixture is very
>>> delicate when it comes to parameter search: If the variance gets closer 
and
>>> closer to zero, the log Likelihood becomes larger and larger for any 
values
>>> of the remaining parameters. Furthermore for the EM algorithm it is 
known,
>>> that it takes sometimes very long until convergence is reached.
>>> 
>>> Try the following:
>>> 
>>> Use as starting values for the component parameters:
>>> 
>>> start.par <- mean(your.data, na.rm = TRUE) + sd(your.data, na.rm = 
TRUE) *
>>> runif(K)
>>> 
>>> For the weights just use either 1/K or the R cluster function with K
>>> clusters
>>> 
>>> Here K is the number of components. Further enlarge the maximum number 
of
>>> iterations. What you could also try is to randomize start parameters and
>>> run an SEM (Stochastic EM). In my opinion the better method is in this 
case
>>> a Bayesian method: MCMC.
>>> 
>>> 
>>> Best
>>> 
>>> Simon
>>> 
>>> 
>>> On Jul 16, 2013, at 10:59 PM, Tjun Kiat Teo >> > wrote:
>>> 
>>> > I was trying to use the normixEM in mixtools and I got this error
>>> message.
>>> >
>>> > And I got this error message
>>> >
>>> > One of the variances is going to zero;  trying new starting values.
>>> > Error in normalmixEM(as.matrix(temp[[gc]][, -(f + 1)])) : Too many
>>> tries!
>>> >
>>> > Are there any other packages for fitting mixture distributions  ?
>>> >
>>> >
>>> > Tjun Kiat Teo
>>> >
>>> > [[alternative HTML version deleted]]
>>> >
>>> > __
>>> > r-h...@r-project.org  mailing list
>>> > https://stat.ethz.ch/mailman/listinfo/r-help
>>> > PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> > and 

[R] Is there t.test with null hypothesis?

2016-09-08 Thread Matti Viljamaa
I’m trying to do a t-test, where the null hypothesis for the two data sets has 
to be:

“the means are the same”/“difference in means is equal to one”

Using the t.test function in R I’m able to see that it uses the following 
“alternative hypothesis”:

alternative hypothesis: true difference in means is not equal to 0

but does not seem to specify null hypothesis. I believe alternative and null 
hypotheses are different, although
I don’t exactly know how.

So what should I use for my t-test? Or is t.test ok?

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] get start and end date of ISO weeks giving a date as input

2016-09-08 Thread Luisfo via R-help
Dear Veronica,

Here there's a way of doing what you requested.

library("lubridate")
# your date '2010-08-21' as Date object
dd <- as.Date(strptime("2010-08-21", format="%Y-%m-%d", tz="GMT"))
# take the first day of the year as Date object, i.e. 2010-01-01 in our 
example
ref.date <- as.Date(strptime(paste0(year(dd),"-01-01"), 
format="%Y-%m-%d", tz="GMT"))
# the start and end dates
bound.dates <- ref.date + 7 * (week(dd)-1) + c(0,6)

I hope you find it useful.

Best,

*Luisfo Chiroque*
/PhD Student | PhD Candidate
IMDEA Networks Institute/
http://fourier.networks.imdea.org/people/~luis_nunez/ 


On 09/08/2016 12:13 PM, Veronica Andreo wrote:
> Hello list,
>
> Is there a quick way to get start and end date (%Y-%m-%d) from ISO
> weeks if I only have dates?
>
> For example, I have this date in which some event happened:
> "2010-08-21". Not only I want the ISO week, which I can obtain either
> with isoweek (lubridate) or ISOweek (ISOweek), but I want the start
> and end date of that ISO week.
>
> Do I need to print all ISO weeks from the period of interest and
> sample there for start and end date? Or is there a better way to do
> that?
>
> Thanks a lot in advance!
>
> Best,
> Veronica
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Resample with replacement to produce many rarefaction curves with same number of samples

2016-09-08 Thread Luisfo via R-help
Hi Nick,

Yes, you are right. There's one small bug on my code.
The 'if' within the for-loop is wrong. Try it now with the code below.

rrarefy.custom <- function (x, sample, rep.param=F)
{
   if (!identical(all.equal(x, round(x)), TRUE))
 stop("function is meaningful only for integers (counts)")
   x <- as.matrix(x)
   if (ncol(x) == 1)
 x <- t(x)
   if (length(sample) > 1 && length(sample) != nrow(x))
 stop(gettextf("length of 'sample' and number of rows of 'x' do not 
match"))
   sample <- rep(sample, length = nrow(x))
   colnames(x) <- colnames(x, do.NULL = FALSE)
   nm <- colnames(x)
   if (!rep.param && any(rowSums(x) < sample))
 warning("Some row sums < 'sample' and are not rarefied")
   for (i in 1:nrow(x)) {
 if (!rep.param && sum(x[i, ]) <= sample[i])
   next
 row <- sample(rep(nm, times = x[i, ]), sample[i], replace = rep.param)
 row <- table(row)
 ind <- names(row)
 x[i, ] <- 0
 x[i, ind] <- row
   }
   x
}

I have test it now before pasting it.

Best,

*Luisfo Chiroque*
/PhD Student | PhD Candidate
IMDEA Networks Institute/
http://fourier.networks.imdea.org/people/~luis_nunez/ 


On 09/07/2016 10:27 PM, Nick Pardikes wrote:
> Hey Luisfo,
>
> This looks great, however I still get the same plot as before (seen
> below). The output looks the same. Here is the figure that was
> generated from this code:
>
> rrarefy.custom <- function (x, sample, rep.param=F)
> {
>if (!identical(all.equal(x, round(x)), TRUE))
>  stop("function is meaningful only for integers (counts)")
>x <- as.matrix(x)
>if (ncol(x) == 1)
>  x <- t(x)
>if (length(sample) > 1 && length(sample) != nrow(x))
>  stop(gettextf("length of 'sample' and number of rows of 'x' do not 
> match"))
>sample <- rep(sample, length = nrow(x))
>colnames(x) <- colnames(x, do.NULL = FALSE)
>nm <- colnames(x)
>if (!rep.param && any(rowSums(x) < sample))
>  warning("Some row sums < 'sample' and are not rarefied")
>for (i in 1:nrow(x)) {
>  if (rep.param && sum(x[i, ]) <= sample[i])
>next
>  row <- sample(rep(nm, times = x[i, ]), sample[i], replace = rep.param)
>  row <- table(row)
>  ind <- names(row)
>  x[i, ] <- 0
>  x[i, ind] <- row
>}
>x
> }
>
> raredata <- rarecurve(rrarefy.custom(netdata, sample=100,rep.param=T),
> label=F, col=rgb(0, 0, 1, 0.1))
>
> However, I like what you did to the rrarefy function to add the sample
> with replacement option.
>
> On Wed, Sep 7, 2016 at 8:17 AM, Luisfo  wrote:
>> Hi Nick,
>>
>> If you use the following
>>  raredata <- rarecurve(rrarefy(netdata, sample=100), label=F, col=rgb(0,
>> 0, 1, 0.1))
>> should work for any sample size, e.g. sample=100.
>> However, you will have a 'warning' if you don't have samples enough, because
>> it has not replacement.
>>
>> If you type 'rrarefy' on the R console (without brackets), or any other
>> function name, you will see the R code of the function.
>> rrarefy uses the function 'sample()' for sampling, but has no option for
>> replacement.
>> I did the following. I created my custom rrarefy function from the original.
>> rrarefy.custom <- function (x, sample, rep.param=F)
>> {
>>if (!identical(all.equal(x, round(x)), TRUE))
>>  stop("function is meaningful only for integers (counts)")
>>x <- as.matrix(x)
>>if (ncol(x) == 1)
>>  x <- t(x)
>>if (length(sample) > 1 && length(sample) != nrow(x))
>>  stop(gettextf("length of 'sample' and number of rows of 'x' do not
>> match"))
>>sample <- rep(sample, length = nrow(x))
>>colnames(x) <- colnames(x, do.NULL = FALSE)
>>nm <- colnames(x)
>>if (!rep.param && any(rowSums(x) < sample))
>>  warning("Some row sums < 'sample' and are not rarefied")
>>for (i in 1:nrow(x)) {
>>  if (rep.param && sum(x[i, ]) <= sample[i])
>>next
>>  row <- sample(rep(nm, times = x[i, ]), sample[i], replace = rep.param)
>>  row <- table(row)
>>  ind <- names(row)
>>  x[i, ] <- 0
>>  x[i, ind] <- row
>>}
>>x
>> }
>> You can check the differences with the original code if you type 'rrarefy'
>> on the R console.
>>
>> So now, if you type the following
>>  raredata <- rarecurve(rrarefy.custom(netdata, sample=100,rep.param=T),
>> label=F, col=rgb(0, 0, 1, 0.1))
>> you will have the desired behaviour.
>>
>> WARNING: I do not understand about rarefunction curves or communities in
>> your context. So, be careful when resampling. It might not be statistically
>> correct.
>>
>> Regards,
>> Luisfo Chiroque
>> PhD Student | PhD Candidate
>> IMDEA Networks Institute
>> http://fourier.networks.imdea.org/people/~luis_nunez/
>>
>> On 09/07/2016 12:07 AM, Nick Pardikes wrote:
>>
>> I am currently having difficulty producing a graph using rarecurve in the
>> vegan package. I have produced rarefaction curves (seen below) using the
>> following code.
>>
>>
>> library(vegan)

Re: [R] get start and end date of ISO weeks giving a date as input

2016-09-08 Thread Enrico Schumann
On Thu, 08 Sep 2016, Veronica Andreo  writes:

> Hello list,
>
> Is there a quick way to get start and end date (%Y-%m-%d) from ISO
> weeks if I only have dates?
>
> For example, I have this date in which some event happened:
> "2010-08-21". Not only I want the ISO week, which I can obtain either
> with isoweek (lubridate) or ISOweek (ISOweek), but I want the start
> and end date of that ISO week.
>
> Do I need to print all ISO weeks from the period of interest and
> sample there for start and end date? Or is there a better way to do
> that?
>
> Thanks a lot in advance!
>
> Best,
> Veronica


You could use a function like the following one (which
assumes the start of the week is Monday and its end is
Sunday):

  d <- c("2010-08-21",
 "2016-08-01")

  iso_start_end <- function(d) {
  d <- as.Date(d)
  wday <- as.POSIXlt(d)$wday
  data.frame(date = d,
 week = format(d, "%V"),
 starts = d - wday + 1,
 ends = d + 7 - wday)
  }
  
  iso_start_end(d)

The function should produce this output:

date week starts   ends
1 2010-08-21   33 2010-08-16 2010-08-22
2 2016-08-01   31 2016-08-01 2016-08-07



-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] get start and end date of ISO weeks giving a date as input

2016-09-08 Thread Veronica Andreo
Hello list,

Is there a quick way to get start and end date (%Y-%m-%d) from ISO
weeks if I only have dates?

For example, I have this date in which some event happened:
"2010-08-21". Not only I want the ISO week, which I can obtain either
with isoweek (lubridate) or ISOweek (ISOweek), but I want the start
and end date of that ISO week.

Do I need to print all ISO weeks from the period of interest and
sample there for start and end date? Or is there a better way to do
that?

Thanks a lot in advance!

Best,
Veronica

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] building R from source on gnu version >=5.4

2016-09-08 Thread David Winsemius

> On Sep 7, 2016, at 1:17 AM, Chinmay Borwankar  wrote:
> 
> Hi,
>I want to integrate R with ROOTv6.06, which requires that,
>R be built with gcc compiler option "_GLIBCXX_USE_CXX11_ABI=0" .
>I am hoping that if I build R from source then there will be a way to
> do this.
>Is there ?

Like Jeff I believe this belongs on R-devel and any followups should go there. 
Appears you have not yet read the Posting Guide (since you continue to post in 
HTML and it does have a description of suitable topics for R-devel that to my 
reading appears to include this question.) 

https://www.r-project.org/posting-guide.html

The devel version of the Installation and Administration Manual has a section 
regarding CXX flags :

https://cran.r-project.org/doc/manuals/r-devel/R-admin.html#C_002b_002b-Support

-- 
David,

>Regards.
> 
> -- 
> Regards.
> 
>Chinmay Borwankar
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] hello i have a question on music analysis and mathematical synthesis related to r code

2016-09-08 Thread Bert Gunter
Search on the Internet!

"Analyze music in R" had hits for several R packages that seemed like
they might be relevant.

Apologies if you've already done this and found mothing to meet your needs.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Wed, Sep 7, 2016 at 10:57 PM, darth brando  wrote:
> Apologies for the long title but it is semi specific a topic and yes I am a 
> noobs user to the system. I have read the guide and will attempt to adhere to 
> the guide in this process and I do apologize in advance if I fail to do so, 
> this is my first time here.
>
> To the point; firstly version:
>
> I have windows 7 64 bit OS, I'm going to be working with most current up to 
> date version of R code for that OS with optional plug ins as needed, I am 
> going to be using R code in conjunction with Fruity Loop Studio, 
> dosbox/visual studio, and both synthesizer plug ins for Fruity Loop Studio 
> and a physical soundblaster sound card in my alienware 15 2015 version as 
> well as possibly a few emulator or OS instances for retro hardware to 
> experiment with. Its a lot of software to take in yea, some I know by heart 
> others like R Code I am a noob at.
>
> Now that the toolbox of software is out of the way; my Question:
>
> Music is largely mathematically based, R Code is perfect for analyzing very 
> large sets of data, naturally I saw some potential and wondered about the 
> specifics of the type of application which follows.
>
> I wish to use R Code to analyze portions of my personal library of music in 
> order to discover the main sets of underlying patterns within that portion of 
> my music library. I then wish to utilize patterns discovered to create a 
> program which using proper algorithms set to those patterns to digitally 
> synthesize music which conforms to those patterns but that would create said 
> music automatically and potentially non stop; as in it does not stop writing 
> the music and playing it until you turn it off. However; I do not wish this 
> program to create a few tracks and play it on a loop, yes due to the patterns 
> and the algorithms, certain bars and phrases will inevitably repeat but that 
> doesn't mean just loop the same X amount of minutes.
>
> Before I fall off tangent and go into semantics, I am asking help as;
>
> The Music Genome Project
> and Sony's musical mood auto playlist generator
>
> are similar to this underlying theme but have gone down the road of separate 
> applications and to the most important part:
>
> I do not wish to infringe or plagiarize or violate copyright or IP on others 
> said similar themed projects/products.
>
> my idea;
>
> use themes and patterns present in a selection of music to then create a 
> potentially infinite and unique mathematical auto play of algorithmically and 
> digitally created music
>
> what I need help with;
>
> inputting a large data set of audio files into an R Code application for 
> pattern and algorithm analysis with out infringing on open, finished or 
> ongoing projects.
>
> I do not need help with porting the algorithm and pattern generator to an 
> audio synthesis program--> that I  am familiar with how to do.
>
> I do not need help with making the end result potentially infinitely 
> continued computation of algorithms within the found and set pattern 
> parameters---> that I also know how to do.
>
> I apologize for the long message and it's redundancies, it is simply my first 
> time here and I wanted to be thorough.
>
> Thank You for Reading!
>
> Any advice on this will be supremely appreciated!
>
> ---Darth Brando
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Fitting Mixture distributions

2016-09-08 Thread Bert Gunter
"please suggest what can I do to resolve this
issue."

Fitting normal mixtures can be difficult, and sometime the
optimization algorithm (EM) will get stuck with very slow convergence.
Presumably there are options in the package to either increase the max
number of steps before giving up or make the convergence criteria less
sensitive. The former will increase the run time and the latter will
reduce the optimality (possibly leaving you farther from the true
optimum). So you should look into changing these as you think
appropriate.

Cheers,
Bert




Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Wed, Sep 7, 2016 at 3:51 PM, Aanchal Sharma
 wrote:
> Hi Simon
>
> I am facing same problem as described above. i am trying to fit gaussian
> mixture model to my data using normalmixEM. I am running a Rscript which
> has this function running as part of it for about 17000 datasets (in loop).
> The script runs fine for some datasets, but it terminates when it
> encounters one dataset with the following error:
>
> Error in normalmixEM(expr_glm_residuals, lambda = c(0.75, 0.25), k = 2,  :
>   Too many tries!
>
> (command used: expr_mix_gau <- normalmixEM(expr_glm_residuals, lambda =
> c(0.75,0.25), k = 2, epsilon = 1e-08, maxit = 1, maxrestarts=200, verb
> = TRUE))
> (expr_glm_residuals is my dataset which has residual values for different
> samples)
>
> It is suggested that one should define the mu and sigma in the command by
> looking at your dataset. But in my case there are many datasets and it will
> keep on changing every time. please suggest what can I do to resolve this
> issue.
>
> Regards
> Anchal
>
> On Tuesday, 16 July 2013 17:53:09 UTC-4, Simon Zehnder wrote:
>>
>> Hi Tjun Kiat Teo,
>>
>> you try to fit a Normal mixture to some data. The Normal mixture is very
>> delicate when it comes to parameter search: If the variance gets closer and
>> closer to zero, the log Likelihood becomes larger and larger for any values
>> of the remaining parameters. Furthermore for the EM algorithm it is known,
>> that it takes sometimes very long until convergence is reached.
>>
>> Try the following:
>>
>> Use as starting values for the component parameters:
>>
>> start.par <- mean(your.data, na.rm = TRUE) + sd(your.data, na.rm = TRUE) *
>> runif(K)
>>
>> For the weights just use either 1/K or the R cluster function with K
>> clusters
>>
>> Here K is the number of components. Further enlarge the maximum number of
>> iterations. What you could also try is to randomize start parameters and
>> run an SEM (Stochastic EM). In my opinion the better method is in this case
>> a Bayesian method: MCMC.
>>
>>
>> Best
>>
>> Simon
>>
>>
>> On Jul 16, 2013, at 10:59 PM, Tjun Kiat Teo > > wrote:
>>
>> > I was trying to use the normixEM in mixtools and I got this error
>> message.
>> >
>> > And I got this error message
>> >
>> > One of the variances is going to zero;  trying new starting values.
>> > Error in normalmixEM(as.matrix(temp[[gc]][, -(f + 1)])) : Too many
>> tries!
>> >
>> > Are there any other packages for fitting mixture distributions  ?
>> >
>> >
>> > Tjun Kiat Teo
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > r-h...@r-project.org  mailing list
>> > https://stat.ethz.ch/mailman/listinfo/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-h...@r-project.org  mailing list
>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] hello i have a question on music analysis and mathematical synthesis related to r code

2016-09-08 Thread Jim Lemon
Hi Darth,
Have a look at the tuneR package.

Jim


On Thu, Sep 8, 2016 at 3:57 PM, darth brando  wrote:
> Apologies for the long title but it is semi specific a topic and yes I am a 
> noobs user to the system. I have read the guide and will attempt to adhere to 
> the guide in this process and I do apologize in advance if I fail to do so, 
> this is my first time here.
>
> To the point; firstly version:
>
> I have windows 7 64 bit OS, I'm going to be working with most current up to 
> date version of R code for that OS with optional plug ins as needed, I am 
> going to be using R code in conjunction with Fruity Loop Studio, 
> dosbox/visual studio, and both synthesizer plug ins for Fruity Loop Studio 
> and a physical soundblaster sound card in my alienware 15 2015 version as 
> well as possibly a few emulator or OS instances for retro hardware to 
> experiment with. Its a lot of software to take in yea, some I know by heart 
> others like R Code I am a noob at.
>
> Now that the toolbox of software is out of the way; my Question:
>
> Music is largely mathematically based, R Code is perfect for analyzing very 
> large sets of data, naturally I saw some potential and wondered about the 
> specifics of the type of application which follows.
>
> I wish to use R Code to analyze portions of my personal library of music in 
> order to discover the main sets of underlying patterns within that portion of 
> my music library. I then wish to utilize patterns discovered to create a 
> program which using proper algorithms set to those patterns to digitally 
> synthesize music which conforms to those patterns but that would create said 
> music automatically and potentially non stop; as in it does not stop writing 
> the music and playing it until you turn it off. However; I do not wish this 
> program to create a few tracks and play it on a loop, yes due to the patterns 
> and the algorithms, certain bars and phrases will inevitably repeat but that 
> doesn't mean just loop the same X amount of minutes.
>
> Before I fall off tangent and go into semantics, I am asking help as;
>
> The Music Genome Project
> and Sony's musical mood auto playlist generator
>
> are similar to this underlying theme but have gone down the road of separate 
> applications and to the most important part:
>
> I do not wish to infringe or plagiarize or violate copyright or IP on others 
> said similar themed projects/products.
>
> my idea;
>
> use themes and patterns present in a selection of music to then create a 
> potentially infinite and unique mathematical auto play of algorithmically and 
> digitally created music
>
> what I need help with;
>
> inputting a large data set of audio files into an R Code application for 
> pattern and algorithm analysis with out infringing on open, finished or 
> ongoing projects.
>
> I do not need help with porting the algorithm and pattern generator to an 
> audio synthesis program--> that I  am familiar with how to do.
>
> I do not need help with making the end result potentially infinitely 
> continued computation of algorithms within the found and set pattern 
> parameters---> that I also know how to do.
>
> I apologize for the long message and it's redundancies, it is simply my first 
> time here and I wanted to be thorough.
>
> Thank You for Reading!
>
> Any advice on this will be supremely appreciated!
>
> ---Darth Brando
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Cannot convert from unsigned int to double

2016-09-08 Thread Amina Shahzadi Shahzadi
Hi Dear

I am very new to use RcppArmadillo. I am trying to execute the following code. 
But I got the error

cannot convert 'arma::enable_if2, 
arma::eop_exp> >::result {aka const arma::eOp, arma::eop_exp>}' to 'double' in return
  return exp(alpha2+beta2);
 ^
sample.cpp:36:1: warning: control reaches end of non-void function 
[-Wreturn-type]
 }



My code is  as follows: Any help in this regard.
Thank You



#include 
using namespace Rcpp;
using namespace RcppArmadillo;
//[[Rcpp::depends(RcppArmadillo)]]
//[[Rcpp::export]]
arma::duble sample(arma::vec alpha, arma::vec beta)
{
int m = alpha.size();
arma::uvec index(m);
for(int i=0; i

Re: [R] Resample with replacement to produce many rarefaction curves with same number of samples

2016-09-08 Thread Nick Pardikes
Hey Luisfo,

This looks great, however I still get the same plot as before (seen
below). The output looks the same. Here is the figure that was
generated from this code:

rrarefy.custom <- function (x, sample, rep.param=F)
{
  if (!identical(all.equal(x, round(x)), TRUE))
stop("function is meaningful only for integers (counts)")
  x <- as.matrix(x)
  if (ncol(x) == 1)
x <- t(x)
  if (length(sample) > 1 && length(sample) != nrow(x))
stop(gettextf("length of 'sample' and number of rows of 'x' do not match"))
  sample <- rep(sample, length = nrow(x))
  colnames(x) <- colnames(x, do.NULL = FALSE)
  nm <- colnames(x)
  if (!rep.param && any(rowSums(x) < sample))
warning("Some row sums < 'sample' and are not rarefied")
  for (i in 1:nrow(x)) {
if (rep.param && sum(x[i, ]) <= sample[i])
  next
row <- sample(rep(nm, times = x[i, ]), sample[i], replace = rep.param)
row <- table(row)
ind <- names(row)
x[i, ] <- 0
x[i, ind] <- row
  }
  x
}

raredata <- rarecurve(rrarefy.custom(netdata, sample=100,rep.param=T),
label=F, col=rgb(0, 0, 1, 0.1))

However, I like what you did to the rrarefy function to add the sample
with replacement option.

On Wed, Sep 7, 2016 at 8:17 AM, Luisfo  wrote:
> Hi Nick,
>
> If you use the following
> raredata <- rarecurve(rrarefy(netdata, sample=100), label=F, col=rgb(0,
> 0, 1, 0.1))
> should work for any sample size, e.g. sample=100.
> However, you will have a 'warning' if you don't have samples enough, because
> it has not replacement.
>
> If you type 'rrarefy' on the R console (without brackets), or any other
> function name, you will see the R code of the function.
> rrarefy uses the function 'sample()' for sampling, but has no option for
> replacement.
> I did the following. I created my custom rrarefy function from the original.
> rrarefy.custom <- function (x, sample, rep.param=F)
> {
>   if (!identical(all.equal(x, round(x)), TRUE))
> stop("function is meaningful only for integers (counts)")
>   x <- as.matrix(x)
>   if (ncol(x) == 1)
> x <- t(x)
>   if (length(sample) > 1 && length(sample) != nrow(x))
> stop(gettextf("length of 'sample' and number of rows of 'x' do not
> match"))
>   sample <- rep(sample, length = nrow(x))
>   colnames(x) <- colnames(x, do.NULL = FALSE)
>   nm <- colnames(x)
>   if (!rep.param && any(rowSums(x) < sample))
> warning("Some row sums < 'sample' and are not rarefied")
>   for (i in 1:nrow(x)) {
> if (rep.param && sum(x[i, ]) <= sample[i])
>   next
> row <- sample(rep(nm, times = x[i, ]), sample[i], replace = rep.param)
> row <- table(row)
> ind <- names(row)
> x[i, ] <- 0
> x[i, ind] <- row
>   }
>   x
> }
> You can check the differences with the original code if you type 'rrarefy'
> on the R console.
>
> So now, if you type the following
> raredata <- rarecurve(rrarefy.custom(netdata, sample=100,rep.param=T),
> label=F, col=rgb(0, 0, 1, 0.1))
> you will have the desired behaviour.
>
> WARNING: I do not understand about rarefunction curves or communities in
> your context. So, be careful when resampling. It might not be statistically
> correct.
>
> Regards,
> Luisfo Chiroque
> PhD Student | PhD Candidate
> IMDEA Networks Institute
> http://fourier.networks.imdea.org/people/~luis_nunez/
>
> On 09/07/2016 12:07 AM, Nick Pardikes wrote:
>
> I am currently having difficulty producing a graph using rarecurve in the
> vegan package. I have produced rarefaction curves (seen below) using the
> following code.
>
>
> library(vegan)
>
> myMat <- round(matrix(rlnorm(2000), 50)) #creates distribution of
> communities
>
> netdata <- as.data.frame(myMat) #generates a matrix of communities (rows),
> species (columns)
>
> raredata <- rarecurve(netdata, label=F, col=rgb(0, 0, 1, 0.1))  #uses
> rarecurve to plot a rarefaction for each individual community (n=50)
>
>
> However I would like to produce a graph in which all rarefaction curves end
> at the same sample size. For example, in this graph it would be great to
> extend the x-axis (sample size) to 100 and have all curves end at this
> point. Is there any way to use rarecurve to resample a community (row) with
> replacement the same number of times for all 50 communities? With
> replacement is important because the communities differ greatly in their
> size (number of species).
>
>
> I understand that rarefaction is useful to compare communities with
> different sample efforts, but I would still like to generate the figure. My
> actual data has 5000 simulated communities that differ greatly in matrix
> size and number of samples.
>
>
> Thank you in advance for your help and suggestions.
>
>
> Cheers,
>
> Nick
>
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, 

Re: [R] Using apply on a three dimensional matrix and passing multiple arguments to user defined function

2016-09-08 Thread Justin Peter
Dear Liusfo and Jean,

Thank you both for your help and suggestions, which both work.

As Jean mentioned, there is no real speed up using the apply family, which I 
thought there would be, so I will stick with the for loop for clarity.

Liusfo, the reason I used c(1,2) in the apply function (i.e. mask_data <- 
apply(data,c(1,2),mask,y=lsmask)) was because this is what you would do if you 
wanted to sum all the two-dimensional vectors over time (for instance to 
produce an average of a field over a year).

i.e. to get the sum you would do sum_data <- apply(data,c(1,2),sum)

I thought it would extend to using my mask function.

Anyway, thanks again for both of your help.

Cheers,
Justin
--
Justin Peter
Research Fellow
International Centre for Applied Climate Sciences,
University of Southern Queensland
West St, Toowoomba, QLD, 4350
Australia

Email: justin.pe...@usq.edu.au
Ph: +61 (0) 7 4631 1181
Fax: +61 (0) 7 4631 5581
Mob: +61 (0)474 774 107


-Original Message-
From: Luisfo >
To: "Adams, Jean" 
>, Justin 
Peter 
>
CC: r-help@r-project.org 
>
Subject: Re: [R] Using apply on a three dimensional matrix and passing multiple 
arguments to user defined function
Date: Wed, 7 Sep 2016 16:05:48 +0200

Hi,

Jean's example with lapply works fine.

However, if you still want to use apply, I think this works.
One observation first. You were passing c(1,2) as second argument to apply, in 
your code. And that is what makes you have lots of NAs as a result, since your 
function is being applied twice, by rows and columns (first and second 
dimensions) respectively.
Use:
masked_data <- apply(data,3,mask,y=lsmask)
# but now masked_data has dim(nlon*nlat,ntime), so change it
dim(masked_data) <- dim(data)

The apply goes over the third dimension (second parameter '3'), so it takes 
every nlot*nlat matrix as first argument for function mask.
I think it should work.

Regards,

Luisfo Chiroque
PhD Student | PhD Candidate
IMDEA Networks Institute
http://fourier.networks.imdea.org/people/~luis_nunez/


On 09/07/2016 03:17 PM, Adams, Jean wrote:



Justin,

I don't think you can get the apply() function to return an array.  You
could use lapply() instead, and then use simplify2array() to convert the
list of matrices to an array.  Also, in your mask() function you don't need
the which() and you should return the x.  See my example with toy data
below.

# toy data
nlon <- 2
nlat <- 4
ntime <- 3
data <- array(1:(nlon*nlat*ntime), dim=c(nlon, nlat, ntime))
lsmask <- array(sample(0:1, size=nlon*nlat, replace=TRUE), dim=c(nlon,
nlat))

# newly defined function
mask <- function(x, y) {
  x[y==0] <- NA
  x
}

# doit
data2 <- simplify2array(lapply(1:ntime, function(i) mask(data[, , i],
lsmask)))


You may prefer to stick with the for() loop approach (for clarity or
simplicity or ...)  When I ramped up the toy data to much larger
dimensions, the lapply() approach was only slightly faster than the for()
loop approach on my PC.

data3 <- data
data3[ , , i] <- mask(data3[ , , i], lsmask)

Jean




On Tue, Sep 6, 2016 at 11:33 PM, Justin Peter 

wrote:




Dear R-user,

I have a three-dimensional matrix of atmospheric data. The first two
dimensions are spatial (lon and lat) and the third is time, such that

dim(data) <- c(nlon,nlat,ntime)

I wish to apply a land sea mask data which is a matrix of "0" and "1" if
dim(nlon,nlat)

dim(lsmask) <- c(nlon,nlat)

I wish to set all of the elements in the two-dimensional array of
data[,,ntime] for every 1:length(ntime).

I could do this in a loop:

for (i in 1:ntime){
data[,,i][which(lsmask == 0)] <- NA
}

I would like to do this using apply, but I need to pass two variables to
the function in apply (data and lsmask), where data is a two-dimensional
array.

I tried:

mask <- function(x,y) {x[which(y==0)] <- NA}

masked_data <- apply(data,c(1,2),mask,y=lsmask)

but I get back a vector of dim(nlon,nlat) populated with NA.

Any clues as to what I am missing?

Thanks in advance for you help.

Kind regards,
Justin



--
Justin Peter
Research Fellow
International Centre for Applied Climate Sciences,
University of Southern Queensland
West St, Toowoomba, QLD, 4350
Australia

Email: 
justin.pe...@usq.edu.au
Ph: +61 (0) 7 4631 1181
Fax: +61 (0) 7 4631 5581
Mob: +61 (0)474 774 107




_
This email (including any attached files) is confidential and is for the
intended recipient(s) only. If you received this 

Re: [R] Fitting Mixture distributions

2016-09-08 Thread Aanchal Sharma
Hi Simon

I am facing same problem as described above. i am trying to fit gaussian 
mixture model to my data using normalmixEM. I am running a Rscript which 
has this function running as part of it for about 17000 datasets (in loop). 
The script runs fine for some datasets, but it terminates when it 
encounters one dataset with the following error:

Error in normalmixEM(expr_glm_residuals, lambda = c(0.75, 0.25), k = 2,  : 
  Too many tries!

(command used: expr_mix_gau <- normalmixEM(expr_glm_residuals, lambda = 
c(0.75,0.25), k = 2, epsilon = 1e-08, maxit = 1, maxrestarts=200, verb 
= TRUE))
(expr_glm_residuals is my dataset which has residual values for different 
samples)

It is suggested that one should define the mu and sigma in the command by 
looking at your dataset. But in my case there are many datasets and it will 
keep on changing every time. please suggest what can I do to resolve this 
issue.

Regards
Anchal

On Tuesday, 16 July 2013 17:53:09 UTC-4, Simon Zehnder wrote:
>
> Hi Tjun Kiat Teo, 
>
> you try to fit a Normal mixture to some data. The Normal mixture is very 
> delicate when it comes to parameter search: If the variance gets closer and 
> closer to zero, the log Likelihood becomes larger and larger for any values 
> of the remaining parameters. Furthermore for the EM algorithm it is known, 
> that it takes sometimes very long until convergence is reached. 
>
> Try the following: 
>
> Use as starting values for the component parameters: 
>
> start.par <- mean(your.data, na.rm = TRUE) + sd(your.data, na.rm = TRUE) * 
> runif(K) 
>
> For the weights just use either 1/K or the R cluster function with K 
> clusters 
>
> Here K is the number of components. Further enlarge the maximum number of 
> iterations. What you could also try is to randomize start parameters and 
> run an SEM (Stochastic EM). In my opinion the better method is in this case 
> a Bayesian method: MCMC. 
>
>
> Best 
>
> Simon 
>
>
> On Jul 16, 2013, at 10:59 PM, Tjun Kiat Teo  > wrote: 
>
> > I was trying to use the normixEM in mixtools and I got this error 
> message. 
> > 
> > And I got this error message 
> > 
> > One of the variances is going to zero;  trying new starting values. 
> > Error in normalmixEM(as.matrix(temp[[gc]][, -(f + 1)])) : Too many 
> tries! 
> > 
> > Are there any other packages for fitting mixture distributions  ? 
> > 
> > 
> > Tjun Kiat Teo 
> > 
> > [[alternative HTML version deleted]] 
> > 
> > __ 
> > r-h...@r-project.org  mailing list 
> > https://stat.ethz.ch/mailman/listinfo/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-h...@r-project.org  mailing list 
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] hello i have a question on music analysis and mathematical synthesis related to r code

2016-09-08 Thread darth brando
Apologies for the long title but it is semi specific a topic and yes I am a 
noobs user to the system. I have read the guide and will attempt to adhere to 
the guide in this process and I do apologize in advance if I fail to do so, 
this is my first time here.

To the point; firstly version:

I have windows 7 64 bit OS, I'm going to be working with most current up to 
date version of R code for that OS with optional plug ins as needed, I am going 
to be using R code in conjunction with Fruity Loop Studio, dosbox/visual 
studio, and both synthesizer plug ins for Fruity Loop Studio and a physical 
soundblaster sound card in my alienware 15 2015 version as well as possibly a 
few emulator or OS instances for retro hardware to experiment with. Its a lot 
of software to take in yea, some I know by heart others like R Code I am a noob 
at. 

Now that the toolbox of software is out of the way; my Question:

Music is largely mathematically based, R Code is perfect for analyzing very 
large sets of data, naturally I saw some potential and wondered about the 
specifics of the type of application which follows.

I wish to use R Code to analyze portions of my personal library of music in 
order to discover the main sets of underlying patterns within that portion of 
my music library. I then wish to utilize patterns discovered to create a 
program which using proper algorithms set to those patterns to digitally 
synthesize music which conforms to those patterns but that would create said 
music automatically and potentially non stop; as in it does not stop writing 
the music and playing it until you turn it off. However; I do not wish this 
program to create a few tracks and play it on a loop, yes due to the patterns 
and the algorithms, certain bars and phrases will inevitably repeat but that 
doesn't mean just loop the same X amount of minutes.

Before I fall off tangent and go into semantics, I am asking help as;

The Music Genome Project
and Sony's musical mood auto playlist generator

are similar to this underlying theme but have gone down the road of separate 
applications and to the most important part:

I do not wish to infringe or plagiarize or violate copyright or IP on others 
said similar themed projects/products. 

my idea;

use themes and patterns present in a selection of music to then create a 
potentially infinite and unique mathematical auto play of algorithmically and 
digitally created music  

what I need help with;

inputting a large data set of audio files into an R Code application for 
pattern and algorithm analysis with out infringing on open, finished or ongoing 
projects.

I do not need help with porting the algorithm and pattern generator to an audio 
synthesis program--> that I  am familiar with how to do. 

I do not need help with making the end result potentially infinitely continued 
computation of algorithms within the found and set pattern parameters---> that 
I also know how to do.

I apologize for the long message and it's redundancies, it is simply my first 
time here and I wanted to be thorough.

Thank You for Reading!

Any advice on this will be supremely appreciated! 

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