[R] monte carlo simulations in permanova in vegan package

2015-10-27 Thread Sean Porter
Dear colleagues,

 

I am trying to run a PERMANOVA in the vegan package with an appropriate
number of permutations (see example below), ideally . Obviously that
number of permutations does not exists so I would like to use Monte Carlo
permutation tests to derive the probability value, as is done in the
commercial package PERMANOVA+ for PRIMER. How can I adapt my code so that
adonis will do so ? Many thanks, Sean

 

> permanova <- adonis(species ~ time, data = time, permutations=99,
method="bray")

> permanova

 

Call:

adonis(formula = species ~ time, data = time, permutations = 99,  method
= "bray") 

 

Permutation: free

Number of permutations: 99

 

Terms added sequentially (first to last)

 

  Df SumsOfSqs  MeanSqs F.Model  R2 Pr(>F)   

time   1  0.070504 0.070504  123.65 0.96866   0.01 **

Residuals  4  0.002281 0.000570 0.03134  

Total  5  0.072785  1.0  

---

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

 

 

> permanova <- adonis(species ~ time, data = time, permutations=999,
method="bray")

'nperm' > set of all permutations; Resetting 'nperm'.

 

 

 

 


[[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] monte carlo simulations in permanova in vegan package

2015-10-27 Thread stephen sefick
The example code works, and reports  permutations. Can you provide more
information?

data(dune)
data(dune.env)
adonis(dune ~ Management*A1, data=dune.env, permutations=)



On Tue, Oct 27, 2015 at 3:56 AM, Sean Porter  wrote:

> Dear colleagues,
>
>
>
> I am trying to run a PERMANOVA in the vegan package with an appropriate
> number of permutations (see example below), ideally . Obviously that
> number of permutations does not exists so I would like to use Monte Carlo
> permutation tests to derive the probability value, as is done in the
> commercial package PERMANOVA+ for PRIMER. How can I adapt my code so that
> adonis will do so ? Many thanks, Sean
>
>
>
> > permanova <- adonis(species ~ time, data = time, permutations=99,
> method="bray")
>
> > permanova
>
>
>
> Call:
>
> adonis(formula = species ~ time, data = time, permutations = 99,
> method
> = "bray")
>
>
>
> Permutation: free
>
> Number of permutations: 99
>
>
>
> Terms added sequentially (first to last)
>
>
>
>   Df SumsOfSqs  MeanSqs F.Model  R2 Pr(>F)
>
> time   1  0.070504 0.070504  123.65 0.96866   0.01 **
>
> Residuals  4  0.002281 0.000570 0.03134
>
> Total  5  0.072785  1.0
>
> ---
>
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
>
>
>
>
> > permanova <- adonis(species ~ time, data = time, permutations=999,
> method="bray")
>
> 'nperm' > set of all permutations; Resetting 'nperm'.
>
>
>
>
>
>
>
>
>
>
> [[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.
>



-- 
Stephen Sefick
**
Auburn University
Biological Sciences
331 Funchess Hall
Auburn, Alabama
36849
**
sas0...@auburn.edu
http://www.auburn.edu/~sas0025
**

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

-K. Mullis

"A big computer, a complex algorithm and a long time does not equal
science."

  -Robert Gentleman

[[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] Failed to read UTF-16LE file on Windows

2015-10-27 Thread Wush Wu
Dear all,

I tried to run the following code on 3 different OS:

```
download.file("
https://raw.githubusercontent.com/wush978/DataScienceAndR/course/RBasic-07-Loading-Dataset/orglist-100.CSV;,
destfile = "orglist-100.CSV")
con <- file("orglist-100.CSV", encoding = "UTF-16LE")
src <- readLines(con)
length(src) # should be 100
```

On ubuntu and OS X, R correctly read 100 lines from the file. However, the
windows will only read the first line with the following warning message:

```
Warning message:
In readLines(file("orglist-100.CSV", encoding = "UTF-16LE")) :
  incomplete final line found on 'orglist-100.CSV'
```

Is there any recommended way to read a local UTF-16LE file on windows?

Thanks,
Wush

[[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] An R data set with both numerical and categorical variables and a two-class response (at least 15 variables)

2015-10-27 Thread Farideh Bagherzadeh via R-help
Hi 

I need a data set containing both numerical and categorical variables and a 
two-class outcome to be used in examples of my R package (for variable 
selection). Do you know any well-known one? I prefer it to be related to 
healthcare and to have at least about 15 variables.
 
Regards
Farideh Bagherzadeh Khiabani

__
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] HPbayes

2015-10-27 Thread Marwah Sabry Siam
Dear R-team,

I am using HPbayes package, specificaly hp.bm.imis function in it.
When I run the function it sometimes gives this error
Error in eigen(m, only.values = TRUE, symmetric = TRUE) :
  infinite or missing values in 'x'
even though in my data there isn't any missing values or infinte values.

The weird thing though is that when I run the function again sometimes
it changes the error to be
Error in like.resamp(K = K, log.like.0 = log.like.0, opt.cov.d = opt.cov.d,  :
  argument "K" is missing, with no default
even though I defined the K in advance.

I don't know what is the problem and why it gives different error at
each run. Also, when I expanded the function it gave another error in
MVN!!!

Thank you for your time and patience.


Regards,
Marwah Sabry Siam,
Teaching Assistant at Faculty of Economics and Political Science,
Statistics Department,
01225875205

__
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] Having trouble updating and installing R 3.2.1 and 3.2.2

2015-10-27 Thread Jeff Newmiller
You might also want to try a different mirror.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On October 26, 2015 6:49:42 AM PDT, Jeff Newmiller  
wrote:
>I have not used W10, but for quite awhile the *administrator" account
>(not the hidden one named "Administrator") has merely had the right to
>"Run As Administrator"... but doing so explicitly is not recommended
>unless you definitely know what you are doing (in which case you should
>not be asking for help here). As long as you let the UAC (User Account
>Control) prompt you at the necessary moments you should not have
>permissions trouble. If you have followed this advice already then
>there might be a bug in the installer, but I would have thought I would
>have seen more complaints by now if it was a bug.
>---
>Jeff NewmillerThe .   .  Go
>Live...
>DCN:Basics: ##.#.   ##.#.  Live
>Go...
> Live:   OO#.. Dead: OO#..  Playing
>Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
>/Software/Embedded Controllers)   .OO#.   .OO#. 
>rocks...1k
>---
>
>Sent from my phone. Please excuse my brevity.
>
>On October 26, 2015 6:16:47 AM PDT, Keith S Weintraub
> wrote:
>>I uninstalled all versions of R on my computer and killed all R
>>directories (I think).
>>
>>I am wondering that since I “upgraded” to Windows 10 is it possible
>>that I should create a user separate from the administrator account?
>My
>>previous version of Windows was 7 Home I think. 
>>
>>Here is a longer version of the error messages that I get.
>>
>>> install.packages("sm")
>>Installing package into ‘C:/Users/Administrator/My
>>Documents/R/win-library/3.2’
>>(as ‘lib’ is unspecified)
>>--- Please select a CRAN mirror for use in this session ---
>>Warning: unable to access index for repository
>>https://cran.cnr.Berkeley.edu/src/contrib
>>Warning: unable to access index for repository
>>https://cran.cnr.Berkeley.edu/bin/windows/contrib/3.2
>>Warning messages:
>>1: In normalizePath(path.expand(path), winslash, mustWork) :
>>path[1]="C:/Users/Administrator/My Documents/R/win-library/3.2":
>Access
>>is denied
>>2: package ‘sm’ is not available (for R version 3.2.2) 
>>
>>
>>Thanks for your help,
>>KW
>>
>>
>>> On Oct 25, 2015, at 7:15 PM, Jeff Newmiller
>> wrote:
>>> 
>>> I would guess that you ran R as administrator at some point and now
>>you have a permissions problem on your user library. I can't say I
>know
>>how to fix it, though using administrator mode to fix the permissions
>>is probably hard while using administrator mode to delete the R
>>directory and reinstalling your packages might be easier.
>>>
>>---
>>> Jeff NewmillerThe .   .  Go
>>Live...
>>> DCN:Basics: ##.#.   ##.#. 
>Live
>>Go...
>>>  Live:   OO#.. Dead: OO#.. 
>>Playing
>>> Research Engineer (Solar/BatteriesO.O#.   #.O#. 
>with
>>> /Software/Embedded Controllers)   .OO#.   .OO#. 
>>rocks...1k
>>>
>>---
>>
>>> Sent from my phone. Please excuse my brevity.
>>> 
>>> On October 25, 2015 7:50:07 AM PDT, Keith S Weintraub
>> wrote:
 I get the following error:
 
 Warning message:
 In normalizePath(path.expand(path), winslash, mustWork) :
 path[1]="C:\Users\Administrator\My Documents/R/win-library/3.2":
>>Access
 is denied
 
 This may be the first time that I have tried to upgrade R since I
 upgraded my Windows installation (on Parallels on my Mac no less)
>to
 Windows 10.
 
 Needless to say when I try to install packages outside of core CRAN
>>I
 have issues.
 
 Any help is greatly appreciated.
 
 Thanks much,
 KW
 
 __
 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 

Re: [R] Having trouble updating and installing R 3.2.1 and 3.2.2

2015-10-27 Thread Keith S Weintraub
Jeff et. al (although there are no others so far on this thread).

I finally gave up and decided to use 4.2 below from the "R for Windows FAQ”

_
4.2 I don’t have permission to write to the R-3.2.2\library directory.

You can install packages anywhere and use the environment variable R_LIBS (see 
How do I set environment variables?) to point to the library location(s). 

Suppose your packages are installed in p:\myRlib. Then you can EITHER 

set the environment variable R_LIBS to p:/myRlib before starting R


OR use a package by, e.g. 

library(mypkg, lib.loc="p:/myRlib")


You can also have a personal library, which defaults to the directory 
R\win-library\x.y of your home directory for versions x.y.z of R. This location 
can be changed by setting the environment variable R_LIBS_USER, and can be 
found from inside R by running Sys.getenv("R_LIBS_USER"). This will only be 
used if it exists so you may need to create it: you can use 

dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)


to do so. If you use install.packages and do not have permission to write to 
the main or site library, it should offer to create a personal library for you 
and install the packages there. This will also happen if update.packages offers 
to update packages for you in a library where you do not have write permission. 

There can be additional security issues under Windows Vista and later: See Does 
R run under Windows Vista?. In particular, the detection that a standard user 
has suitable permissions appears to be unreliable under Vista, so we recommend 
that you do create a personal directory yourself. 

_



---
KW



> On Oct 26, 2015, at 9:49 AM, Jeff Newmiller  wrote:
> 
> I have not used W10, but for quite awhile the *administrator" account (not 
> the hidden one named "Administrator") has merely had the right to "Run As 
> Administrator"... but doing so explicitly is not recommended unless you 
> definitely know what you are doing (in which case you should not be asking 
> for help here). As long as you let the UAC (User Account Control) prompt you 
> at the necessary moments you should not have permissions trouble. If you have 
> followed this advice already then there might be a bug in the installer, but 
> I would have thought I would have seen more complaints by now if it was a bug.
> ---
> Jeff NewmillerThe .   .  Go Live...
> DCN:Basics: ##.#.   ##.#.  Live Go...
>  Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
> /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
> --- 
> Sent from my phone. Please excuse my brevity.
> 
> On October 26, 2015 6:16:47 AM PDT, Keith S Weintraub  
> wrote:
>> I uninstalled all versions of R on my computer and killed all R
>> directories (I think).
>> 
>> I am wondering that since I “upgraded” to Windows 10 is it possible
>> that I should create a user separate from the administrator account? My
>> previous version of Windows was 7 Home I think. 
>> 
>> Here is a longer version of the error messages that I get.
>> 
>>> install.packages("sm")
>> Installing package into ‘C:/Users/Administrator/My
>> Documents/R/win-library/3.2’
>> (as ‘lib’ is unspecified)
>> --- Please select a CRAN mirror for use in this session ---
>> Warning: unable to access index for repository
>> https://cran.cnr.Berkeley.edu/src/contrib
>> Warning: unable to access index for repository
>> https://cran.cnr.Berkeley.edu/bin/windows/contrib/3.2
>> Warning messages:
>> 1: In normalizePath(path.expand(path), winslash, mustWork) :
>> path[1]="C:/Users/Administrator/My Documents/R/win-library/3.2": Access
>> is denied
>> 2: package ‘sm’ is not available (for R version 3.2.2) 
>> 
>> 
>> Thanks for your help,
>> KW
>> 
>> 
>>> On Oct 25, 2015, at 7:15 PM, Jeff Newmiller
>>  wrote:
>>> 
>>> I would guess that you ran R as administrator at some point and now
>> you have a permissions problem on your user library. I can't say I know
>> how to fix it, though using administrator mode to fix the permissions
>> is probably hard while using administrator mode to delete the R
>> directory and reinstalling your packages might be easier.
>>> 
>> ---
>>> Jeff NewmillerThe .   .  Go
>> Live...
>>> DCN:Basics: ##.#.   ##.#.  Live
>> Go...
>>> Live:   OO#.. Dead: OO#.. 
>> Playing
>>> Research Engineer 

Re: [R] Memory problems with mice

2015-10-27 Thread Michael Dewey

Dear Jennifer

See inline below

On 27/10/2015 12:20, Lorenz, Jennifer wrote:

Hi everyone,

I am trying to perform a multiple imputation with mice on a dataset of about 13000 observations and 
178 variables. I can start an "empty" imputation ("imp_start <- mice(data, 
maxit=0)"), but after a few minutes R stops with the following error message:
Error: cannot allocate vector of size 2.0 Gb
In addition: Warning messages:
1: In col(value) :
   Reached total allocation of 8078Mb: see help(memory.size)
2: In col(value) :
   Reached total allocation of 8078Mb: see help(memory.size)
3: In unique.default(x) :
   Reached total allocation of 8078Mb: see help(memory.size)
4: In unique.default(x) :
   Reached total allocation of 8078Mb: see help(memory.size)
5: In unique.default(x) :
   Reached total allocation of 8078Mb: see help(memory.size)
6: In unique.default(x) :
   Reached total allocation of 8078Mb: see help(memory.size)

I am using R (with R Studio) on Windows 7, my computer has a total of 8 GB RAM.
Following advice I found on the internet, I installed the newest R-version 
(64-bit) and tried the following commands:


Well the internet is wonderful, but ...


memory.size(max = F)
memory.limit(size=NA)



... R documentation is even more wonderful.
?memory.limit
says that (size = NA) reports the limit but does not set it.


But I still get the same error. Now I am wondering, if my dataset is really to 
large for mice or R? Or is there any other setting I could use to increase 
memory size for R? I would really appreciate if anyone who is familiar with 
this problem would share their insights...

Thanks,
Jen


---
Jennifer Lorenz, M.A.
Georg-August-Universit�t G�ttingen
Sozialwissenschaftliche Fakult�t
Institut f�r Erziehungswissenschaft
Lehrstuhl Schulp�dagogik / Empirische Schulforschung

e-mail: jlor...@uni-goettingen.de
phone: 0551-39-21411
adress: Waldweg 26, 37073 G�ttingen
room: 8.106


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



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

[R] How to use curve() with two parameters in the function

2015-10-27 Thread C W
Dear R list,

I am trying to plot the curve of a function.

Here's the R code:

library(mvtnorm)

p <- function(x, mu){
   mu <- c(mu, 0)
   dmvnorm(c(x, 1), mu, diag(2))
}

> curve(p(x, 2), from = 0, to =1)
Error in dmvnorm(c(x, 1), mu, diag(2)) :
  mean and sigma have non-conforming size

I think my matrix probably have different size inside curve(), maybe I need
to use apply()?  I am not sure.

Thanks so much!

[[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] monte carlo simulations in permanova in vegan package

2015-10-27 Thread Cade, Brian
Sean:  There are only 20 possible combinations, 6!/(3! x 3!), so you just
need to enumerate them completely (no Monte Carlo approximation required).
I don't know if permanova() can do this but you can do it with the mrpp()
functions and argument (,exact=TRUE) in Blossom package for R.

Brian

Brian S. Cade, PhD

U. S. Geological Survey
Fort Collins Science Center
2150 Centre Ave., Bldg. C
Fort Collins, CO  80526-8818

email:  ca...@usgs.gov 
tel:  970 226-9326


On Tue, Oct 27, 2015 at 7:42 AM, Sean Porter  wrote:

> Hi Stephen and others,
>
>
>
> I am trying to run a one-way permanova where I have only 2 levels in the
> factor “time”, and each level contains only 3 replicates. So because I have
> such few observations (6 in total) and levels (2) there are not enough
> possible permutations to get a reasonable test (i.e. (2*3)!/ [2!(3!)^2].
>  That is why for example if I run the analysis with only 99 permutations it
> completes the task. However, if I set the number of permutations to
> anything larger it returns the message “'nperm' > set of all permutations;
> Resetting 'nperm'.” as the number of possible permutations exceeds the
> number set by the argument “permutations=”. In PERMANOVA + for PRIMER there
> is a way of dealing with this issue – by using Monte Carlo simulations to
> generate the p value with a reasonable number of permutations. Hopefully
> this clarifies my situation and aim?
>
>
>
> I was therefore hoping there was a way of coding for the Monte-Carlo
> permutation procedure into adonis?
>
>
>
> Thanks for your help!
>
>
>
> From: stephen sefick [mailto:ssef...@gmail.com]
> Sent: 27 October 2015 03:11 PM
> To: Sean Porter
> Cc: r-help@r-project.org
> Subject: Re: [R] monte carlo simulations in permanova in vegan package
>
>
>
> The example code works, and reports  permutations. Can you provide
> more information?
>
>
>
> data(dune)
> data(dune.env)
> adonis(dune ~ Management*A1, data=dune.env, permutations=)
>
>
>
>
>
> On Tue, Oct 27, 2015 at 3:56 AM, Sean Porter  wrote:
>
> Dear colleagues,
>
>
>
> I am trying to run a PERMANOVA in the vegan package with an appropriate
> number of permutations (see example below), ideally . Obviously that
> number of permutations does not exists so I would like to use Monte Carlo
> permutation tests to derive the probability value, as is done in the
> commercial package PERMANOVA+ for PRIMER. How can I adapt my code so that
> adonis will do so ? Many thanks, Sean
>
>
>
> > permanova <- adonis(species ~ time, data = time, permutations=99,
> method="bray")
>
> > permanova
>
>
>
> Call:
>
> adonis(formula = species ~ time, data = time, permutations = 99,
> method
> = "bray")
>
>
>
> Permutation: free
>
> Number of permutations: 99
>
>
>
> Terms added sequentially (first to last)
>
>
>
>   Df SumsOfSqs  MeanSqs F.Model  R2 Pr(>F)
>
> time   1  0.070504 0.070504  123.65 0.96866   0.01 **
>
> Residuals  4  0.002281 0.000570 0.03134
>
> Total  5  0.072785  1.0
>
> ---
>
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
>
>
>
>
> > permanova <- adonis(species ~ time, data = time, permutations=999,
> method="bray")
>
> 'nperm' > set of all permutations; Resetting 'nperm'.
>
>
>
>
>
>
>
>
>
>
> [[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.
>
>
>
>
>
>
>
> --
>
> Stephen Sefick
> **
> Auburn University
> Biological Sciences
> 331 Funchess Hall
> Auburn, Alabama
> 36849
> **
> sas0...@auburn.edu
> http://www.auburn.edu/~sas0025
> **
>
> Let's not spend our time and resources thinking about things that are so
> little or so large that all they really do for us is puff us up and make us
> feel like gods.  We are mammals, and have not exhausted the annoying little
> problems of being mammals.
>
> -K. Mullis
>
> "A big computer, a complex algorithm and a long time does not equal
> science."
>
>   -Robert Gentleman
>
>
> [[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.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and 

Re: [R] monte carlo simulations in permanova in vegan package

2015-10-27 Thread stephen sefick
Look at the permute package. I believe this functionality is there.

Please excuse my brevity; this message was sent from my telephone.
On Oct 27, 2015 10:55 AM, "Cade, Brian"  wrote:

> Sean:  There are only 20 possible combinations, 6!/(3! x 3!), so you just
> need to enumerate them completely (no Monte Carlo approximation required).
> I don't know if permanova() can do this but you can do it with the mrpp()
> functions and argument (,exact=TRUE) in Blossom package for R.
>
> Brian
>
> Brian S. Cade, PhD
>
> U. S. Geological Survey
> Fort Collins Science Center
> 2150 Centre Ave., Bldg. C
> Fort Collins, CO  80526-8818
>
> email:  ca...@usgs.gov 
> tel:  970 226-9326
>
>
> On Tue, Oct 27, 2015 at 7:42 AM, Sean Porter  wrote:
>
> > Hi Stephen and others,
> >
> >
> >
> > I am trying to run a one-way permanova where I have only 2 levels in the
> > factor “time”, and each level contains only 3 replicates. So because I
> have
> > such few observations (6 in total) and levels (2) there are not enough
> > possible permutations to get a reasonable test (i.e. (2*3)!/ [2!(3!)^2].
> >  That is why for example if I run the analysis with only 99 permutations
> it
> > completes the task. However, if I set the number of permutations to
> > anything larger it returns the message “'nperm' > set of all
> permutations;
> > Resetting 'nperm'.” as the number of possible permutations exceeds the
> > number set by the argument “permutations=”. In PERMANOVA + for PRIMER
> there
> > is a way of dealing with this issue – by using Monte Carlo simulations to
> > generate the p value with a reasonable number of permutations. Hopefully
> > this clarifies my situation and aim?
> >
> >
> >
> > I was therefore hoping there was a way of coding for the Monte-Carlo
> > permutation procedure into adonis?
> >
> >
> >
> > Thanks for your help!
> >
> >
> >
> > From: stephen sefick [mailto:ssef...@gmail.com]
> > Sent: 27 October 2015 03:11 PM
> > To: Sean Porter
> > Cc: r-help@r-project.org
> > Subject: Re: [R] monte carlo simulations in permanova in vegan package
> >
> >
> >
> > The example code works, and reports  permutations. Can you provide
> > more information?
> >
> >
> >
> > data(dune)
> > data(dune.env)
> > adonis(dune ~ Management*A1, data=dune.env, permutations=)
> >
> >
> >
> >
> >
> > On Tue, Oct 27, 2015 at 3:56 AM, Sean Porter  wrote:
> >
> > Dear colleagues,
> >
> >
> >
> > I am trying to run a PERMANOVA in the vegan package with an appropriate
> > number of permutations (see example below), ideally . Obviously that
> > number of permutations does not exists so I would like to use Monte Carlo
> > permutation tests to derive the probability value, as is done in the
> > commercial package PERMANOVA+ for PRIMER. How can I adapt my code so that
> > adonis will do so ? Many thanks, Sean
> >
> >
> >
> > > permanova <- adonis(species ~ time, data = time, permutations=99,
> > method="bray")
> >
> > > permanova
> >
> >
> >
> > Call:
> >
> > adonis(formula = species ~ time, data = time, permutations = 99,
> > method
> > = "bray")
> >
> >
> >
> > Permutation: free
> >
> > Number of permutations: 99
> >
> >
> >
> > Terms added sequentially (first to last)
> >
> >
> >
> >   Df SumsOfSqs  MeanSqs F.Model  R2 Pr(>F)
> >
> > time   1  0.070504 0.070504  123.65 0.96866   0.01 **
> >
> > Residuals  4  0.002281 0.000570 0.03134
> >
> > Total  5  0.072785  1.0
> >
> > ---
> >
> > Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> >
> >
> >
> >
> >
> > > permanova <- adonis(species ~ time, data = time, permutations=999,
> > method="bray")
> >
> > 'nperm' > set of all permutations; Resetting 'nperm'.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > [[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.
> >
> >
> >
> >
> >
> >
> >
> > --
> >
> > Stephen Sefick
> > **
> > Auburn University
> > Biological Sciences
> > 331 Funchess Hall
> > Auburn, Alabama
> > 36849
> > **
> > sas0...@auburn.edu
> > http://www.auburn.edu/~sas0025
> > **
> >
> > Let's not spend our time and resources thinking about things that are so
> > little or so large that all they really do for us is puff us up and make
> us
> > feel like gods.  We are mammals, and have not exhausted the annoying
> little
> > problems of being mammals.
> >
> > -K. Mullis
> >
> > "A big computer, a complex algorithm and a long time does not equal
> > science."
> >
> >   

[R] How to get variable name while doing series of regressions in an automated manner?

2015-10-27 Thread Ravi Varadhan
Hi,

I am running through a series of regression in a loop as follows:

results <- vector("list", length(mydata$varnames))

for (i in 1:length(mydata$varnames)) {
results[[i]] <- summary(lm(log(eval(parse(text=varnames[i]))) ~ age + sex + 
CMV.status, data=mydata))
}

Now, when I look at the results[i]] objects, I won't be able to see the 
original variable names.  Obviously, I will only see the following:

Call:
lm(formula = log(eval(parse(text = varnames[i]))) ~ age + sex + CMV.status,
data = mydata)


Is there a way to display the original variable names on the LHS?  In addition, 
is there a better paradigm for doing these type of series of regressions in an 
automatic fashion?

Thank you very much,
Ravi

Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg)
Associate Professor,  Department of Oncology
Division of Biostatistics & Bionformatics
Sidney Kimmel Comprehensive Cancer Center
Johns Hopkins University
550 N. Broadway, Suite -E
Baltimore, MD 21205
410-502-2619


[[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] How to get variable name while doing series of regressions in an automated manner?

2015-10-27 Thread Bert Gunter
Marc,Ravi:

I may misunderstand, but I think Marc's solution labels the list
components but not necessarily the summary() outputs. This might be
sufficient, as in:

> z <- list(y1=rnorm(10,5),y2 = rnorm(10,8),x=1:10)
>
> ##1
> results1<-lapply(z[-3],function(y)lm(log(y)~x,data=z))
> lapply(results1,summary)
$y1

Call:
lm(formula = log(y) ~ x, data = z)

Residuals:
Min  1Q  Median  3Q Max
-0.2185 -0.1259 -0.0643  0.1340  0.3988

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  1.693190.14375  11.779 2.47e-06 ***
x   -0.014950.02317  -0.6450.537
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.2104 on 8 degrees of freedom
Multiple R-squared:  0.04945,Adjusted R-squared:  -0.06937
F-statistic: 0.4161 on 1 and 8 DF,  p-value: 0.5369


$y2

Call:
lm(formula = log(y) ~ x, data = z)

Residuals:
  Min1QMedian3Q   Max
-0.229072 -0.094579 -0.006498  0.134303  0.188158

Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept)  2.084846   0.104108  20.026 4.03e-08 ***
x   -0.006226   0.016778  -0.371 0.72
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1524 on 8 degrees of freedom
Multiple R-squared:  0.01692,Adjusted R-squared:  -0.106
F-statistic: 0.1377 on 1 and 8 DF,  p-value: 0.7202


## 2

Alternatively, if you want output with the correct variable names,
bquote() can be used, as in:

> results2 <-lapply(names(z)[1:2],
+function(nm){
+  fo <-formula(paste0("log(",nm,")~x"))
+   eval(bquote(lm(.(u),data=z),list(u=fo)))
+})
> lapply(results2,summary)
[[1]]

Call:
lm(formula = log(y1) ~ x, data = z)

Residuals:
Min  1Q  Median  3Q Max
-0.2185 -0.1259 -0.0643  0.1340  0.3988

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  1.693190.14375  11.779 2.47e-06 ***
x   -0.014950.02317  -0.6450.537
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.2104 on 8 degrees of freedom
Multiple R-squared:  0.04945,Adjusted R-squared:  -0.06937
F-statistic: 0.4161 on 1 and 8 DF,  p-value: 0.5369


[[2]]

Call:
lm(formula = log(y2) ~ x, data = z)

Residuals:
  Min1QMedian3Q   Max
-0.229072 -0.094579 -0.006498  0.134303  0.188158

Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept)  2.084846   0.104108  20.026 4.03e-08 ***
x   -0.006226   0.016778  -0.371 0.72
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1524 on 8 degrees of freedom
Multiple R-squared:  0.01692,Adjusted R-squared:  -0.106
F-statistic: 0.1377 on 1 and 8 DF,  p-value: 0.7202


HTH or apologies if I've missed the point and broadcasted noise.

Cheers,
Bert
Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll


On Tue, Oct 27, 2015 at 8:19 AM, Ravi Varadhan  wrote:
> Hi,
>
> I am running through a series of regression in a loop as follows:
>
> results <- vector("list", length(mydata$varnames))
>
> for (i in 1:length(mydata$varnames)) {
> results[[i]] <- summary(lm(log(eval(parse(text=varnames[i]))) ~ age + sex + 
> CMV.status, data=mydata))
> }
>
> Now, when I look at the results[i]] objects, I won't be able to see the 
> original variable names.  Obviously, I will only see the following:
>
> Call:
> lm(formula = log(eval(parse(text = varnames[i]))) ~ age + sex + CMV.status,
> data = mydata)
>
>
> Is there a way to display the original variable names on the LHS?  In 
> addition, is there a better paradigm for doing these type of series of 
> regressions in an automatic fashion?
>
> Thank you very much,
> Ravi
>
> Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg)
> Associate Professor,  Department of Oncology
> Division of Biostatistics & Bionformatics
> Sidney Kimmel Comprehensive Cancer Center
> Johns Hopkins University
> 550 N. Broadway, Suite -E
> Baltimore, MD 21205
> 410-502-2619
>
>
> [[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] rgl plot rotation with device other than mouse

2015-10-27 Thread santiago gil
Well, I haven't built the device yet, I'm trying to figure out what my
options will be. In the case of plugging in a simple USB trackball, I
suppose it can work with the HID Manager in Mac to customize the signal
from it.

In general, would it be possible to manipulate the plot, say for example,
with a standard joystick? Is there something "deeper" in the code that I
could look towards to make this possible? Or any other library that might
support something like this?

2015-10-27 14:17 GMT-04:00 Duncan Murdoch :

> On 27/10/2015 1:38 PM, santiago gil wrote:
>
>> Hello R,
>>
>> I'm trying to figure out if it would be possible use a device (maybe
>> simply
>> a trackball) separate from the mouse that would have the ability to rotate
>> a 3D plot made with rgl without any buttons. This is to build an
>> interactive "demo"-like piece for which a mouse or trackpad is an
>> unsatisfactory manipulation tool. The worse solution would be to make the
>> trackpad button "sticky" so that it works as a rotation on/off toggle.
>> Anything that is less intrusive with the computer's operability is even
>> better. I couldn't find the right way in par3d or anything of the sort.
>> Any
>> tips anybody? Or any other libraries to would use to do something like
>> this?
>>
>
> Do you know how to get input from that device?  If so, you can explicitly
> set par3d("userMatrix") to a rotation
> matrix based on the input.
>
> rgl itself has no support for getting input from anything other than the
> mouse and keyboard.
>
> Duncan Murdoch
>



-- 
---
http://barabasilab.neu.edu/people/gil/

[[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] rgl plot rotation with device other than mouse

2015-10-27 Thread Duncan Murdoch

On 27/10/2015 1:38 PM, santiago gil wrote:

Hello R,

I'm trying to figure out if it would be possible use a device (maybe simply
a trackball) separate from the mouse that would have the ability to rotate
a 3D plot made with rgl without any buttons. This is to build an
interactive "demo"-like piece for which a mouse or trackpad is an
unsatisfactory manipulation tool. The worse solution would be to make the
trackpad button "sticky" so that it works as a rotation on/off toggle.
Anything that is less intrusive with the computer's operability is even
better. I couldn't find the right way in par3d or anything of the sort. Any
tips anybody? Or any other libraries to would use to do something like this?


Do you know how to get input from that device?  If so, you can 
explicitly set par3d("userMatrix") to a rotation

matrix based on the input.

rgl itself has no support for getting input from anything other than the 
mouse and keyboard.


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] Extract entries from matrix

2015-10-27 Thread Jorge I Velez
Dear R-help,

I am working with a matrix "m" from which I would like to extract some
elements.  An toy example is as follows:

## input matrix
m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L,
0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L), .Dim = c(22L, 5L))

R> m
# [,1]  [,2] [,3] [,4] [,5]
#  [1,]00000
#  [2,]00000
#  [3,]00000
#  [4,]12300
#  [5,]12300
#  [6,]12300
#  [7,]12300
#  [8,]12300
#  [9,]12340
# [10,]   12340
# [11,]   12345
# [12,]   12345

>From "m", I would like to extract the entries

4, 1
5, 2
6, 3
7, 1
8, 2
9, 3
10, 1
11, 2
12, 3

so at the end of applying a function "f" to "m" I get

1, 2, 3, 1, 2, 3, 4, 1, 2, 3


Basically the idea is to extract the diagonal elements until a zero is
found.

In the real problem the dimensions of "m" are much bigger, but this smaller
version of "m" illustrate what needs to be done.

I would greatly appreciate any ideas on how to do this.

Thanks in advance,
Jorge Velez.-

[[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] How to get variable name while doing series of regressions in an automated manner?

2015-10-27 Thread Marc Schwartz

> On Oct 27, 2015, at 10:19 AM, Ravi Varadhan  wrote:
> 
> Hi,
> 
> I am running through a series of regression in a loop as follows:
> 
> results <- vector("list", length(mydata$varnames))
> 
> for (i in 1:length(mydata$varnames)) {
> results[[i]] <- summary(lm(log(eval(parse(text=varnames[i]))) ~ age + sex + 
> CMV.status, data=mydata))
> }
> 
> Now, when I look at the results[i]] objects, I won't be able to see the 
> original variable names.  Obviously, I will only see the following:
> 
> Call:
> lm(formula = log(eval(parse(text = varnames[i]))) ~ age + sex + CMV.status,
>data = mydata)
> 
> 
> Is there a way to display the original variable names on the LHS?  In 
> addition, is there a better paradigm for doing these type of series of 
> regressions in an automatic fashion?
> 
> Thank you very much,
> Ravi


Ravi,

Something like this, using the 'iris' dataset might be helpful as an example:

# Define the response variables
VarNames <- c("Sepal.Length", "Sepal.Width", "Petal.Length")

# Create the formulae
> paste0("log(", VarNames, ") ~ Petal.Width + Species")
[1] "log(Sepal.Length) ~ Petal.Width + Species"
[2] "log(Sepal.Width) ~ Petal.Width + Species" 
[3] "log(Petal.Length) ~ Petal.Width + Species"


# Create a list of model summary objects
# The result of paste0() will be coerced to a formula by lm()
# if a valid formula, so no need to call as.formula()
MODS <- lapply(paste0("log(", VarNames, ") ~ Petal.Width + Species"), 
   function(x) summary(lm(x, data = iris)))


You can either use the original 'VarNames' vector for the source response 
variables, or consider:

> as.character(formula(MODS[[1]]))
[1] "~" "log(Sepal.Length)"
[3] "Petal.Width + Species"


> sapply(MODS, function(x) formula(x)[[2]])
[[1]]
log(Sepal.Length)

[[2]]
log(Sepal.Width)

[[3]]
log(Petal.Length)


Regards,

Marc Schwartz

__
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 use curve() with two parameters in the function

2015-10-27 Thread C W
Never mind, I figured it out.

You need to use sapply(), for instance, curve(sapply(x, p), from = 0, to
=10)

Thanks all!

On Tue, Oct 27, 2015 at 11:14 AM, C W  wrote:

> Dear R list,
>
> I am trying to plot the curve of a function.
>
> Here's the R code:
>
> library(mvtnorm)
>
> p <- function(x, mu){
>mu <- c(mu, 0)
>dmvnorm(c(x, 1), mu, diag(2))
> }
>
> > curve(p(x, 2), from = 0, to =1)
> Error in dmvnorm(c(x, 1), mu, diag(2)) :
>   mean and sigma have non-conforming size
>
> I think my matrix probably have different size inside curve(), maybe I
> need to use apply()?  I am not sure.
>
> Thanks so much!
>

[[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] rgl plot rotation with device other than mouse

2015-10-27 Thread santiago gil
Hello R,

I'm trying to figure out if it would be possible use a device (maybe simply
a trackball) separate from the mouse that would have the ability to rotate
a 3D plot made with rgl without any buttons. This is to build an
interactive "demo"-like piece for which a mouse or trackpad is an
unsatisfactory manipulation tool. The worse solution would be to make the
trackpad button "sticky" so that it works as a rotation on/off toggle.
Anything that is less intrusive with the computer's operability is even
better. I couldn't find the right way in par3d or anything of the sort. Any
tips anybody? Or any other libraries to would use to do something like this?

Thanks!

Santiago
-- 
---
http://barabasilab.neu.edu/people/gil/

[[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] Neuralnet package in R gives wrong output

2015-10-27 Thread Marijan Sapina
I'm trying to generate prediction of the column "dubina" using this
algorithm made in R's "neuralnet" package. But I keep getting non-reliable
neural-net output. I have tried changing the number of hidden layers,
normalizing and denormalizing data. Is there a mistake in the algorithm,
maybe because of the activation function being logistic, not sigmoid?

The algorithm and the dataset are added as attachments but are added as
attachments.

I'd be very grateful if you'd help me.
__
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-es] pregunta

2015-10-27 Thread jbetancourt

Estimados

Cuando existia epicalc,  hab�a una  manera muy f�cil de determinar la media de 
una variable (en esta caso Gain)  por grupos, en este caso (Diet). ?Como se 
puede hacer ahora?

  Diet Gain
1d1  270
2d1  300
3d1  280
4d1  280
5d1  270
6d2  290
7d2  250
8d2  280
9d2  290
10   d2  280
11   d3  290
12   d3  340
13   d3  330
14   d3  300
15   d3  300

Saludos
Jos�

[[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] warning on generic function when building R package

2015-10-27 Thread David Stevens
Sorry to be a late comer to this problem but I'm having a similar 
issue.  My function is called by ode from deSolve


ADM1_C <- function(t,state,parameters,...){

with(as.list(c(state,parameters)), {
  # do some stuff here and return a list containing a vector of 
derivatives to ode

...
})
}
in which 't' is a time and 'state' and 'parameters' are numeric vectors 
with each element named. When I invoke the solver,


times <- d.df$time
out <- as.data.frame(ode(y = state,times = times,func = ADM1_C,parms = 
parameters))


I get ~three Note:s for each value in 'state'  (sometimes more). The 
calculation is successful but the issue is a little puzzling.

Here's 'state'
state
 Ssu  Saa  Sfa  Sva  Sbu Spro Sac  Sh2 
Sch4  Sic
0.30 0.001000 0.30 0.30 0.30 0.30 0.30 0.01 
0.10 0.04
 Sin   Si   Xc  Xch  Xpr  Xli Xsu  Xaa  
Xfa  Xc4
0.01 0.02 0.30 0.026000 0.30 0.03 0.40 1.10 
0.20 0.41
Xpro  Xac  Xh2   Xi  Scation   Sanion Sva_mSbu_m   
Spro_mSac_m
0.137000 0.70 0.01 5.00 0.04 0.02 0.09 0.09 
0.074000 0.169000

 Shco3_m Snh3  Sgas_h2 Sgas_ch4 Sgas_co2
0.009700 0.016000 0.02 0.02 0.037600

The messages are something like this ...
Note: no visible binding for global variable 'Sin'
Note: no visible binding for global variable 'Snh3'
Note: no visible binding for global variable 'Scation'
Note: no visible binding for global variable 'Shco3_m'
 (~130 rows of these messages)

Neither Duncan's nor Jim's solution solved the problem.  I can't change 
(at least I don't think so) how ode(...) calls the function except via 
the documentation. Any ideas? Does it matter? Could it be ode strips out 
the names, but only sometimes?


signed Grasping at Straws (David)

David K Stevens, P.E., Ph.D.
Professor and Head, Environmental Engineering
Civil and Environmental Engineering
Utah Water Research Laboratory
8200 Old Main Hill
Logan, UT  84322-8200
435 797 3229 - voice
435 797 1363 - fax
david.stev...@usu.edu


On 10/19/2015 2:32 PM, carol white via R-help wrote:

In effect, this works
but whether I use x or x.init, y or y.init in plot.func, I get
  
no visible binding for global variable ‘x.init’no visible binding for global variable ‘y.init’

Regards,

  On Monday, October 19, 2015 9:59 PM, Duncan Murdoch 
 wrote:



  On 19/10/2015 3:50 PM, carol white wrote:

Thanks Murdoch.

defining
plot.func<- function(x=x.init, y=y.init, arg3, arg4, "title", col, arg5)

and if plot doesn't take the exact parameters of plot.func but modified
of these parameters
plot(x=x.pt,y=y.pt,xlim = c(0, 10), ylim = c(0,1), xlab= "xlab",
ylab="ylab", main = "title", col = col,type = "l")

then, how to define and invoke to be consisent?

I don't really understand your question, but this is all about the
function header for plot.func, not the call you make to plot().  You
need to name the first argument as "x", you need to include "..." as an
open argument, and you need a legal header.  So this would be okay:


plot.func<- function(x=x.init, y=y.init, arg3, arg4,
 main = "title", # can't skip the arg name
 col, arg5,
 ...)  {  # can't skip the dots

Duncan Murdoch


Regards,

On Monday, October 19, 2015 7:45 PM, Duncan Murdoch
 wrote:


On 19/10/2015 1:29 PM, carol white via R-help wrote:


Hi,I have invoked plot in a function (plot.func) as follows but when I

check the built package, I get a warning:

plot(x.pt,y.pt,xlim = c(0, 10), ylim = c(0,1), xlab= "xlab",

ylab="ylab", main = "title", col = col,type = "l")

R CMD check my.package
checking S3 generic/method consistency ... WARNING
plot:
   function(x, ...)
plot.func:
   function(x.pt, y.pt, arg3, arg4, "title", col, arg5)

See section ‘Generic functions and methods’ in the ‘Writing R
Extensions’ manual.
Which plot argument is illegitimate or missing and how to eliminate

the warning?


The first argument to plot.func needs to be called "x" if you want to
use it as a method.  Method signatures need to be consistent with the
generic signature.

Duncan Murdoch







   
	[[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] Time it takes to run a code

2015-10-27 Thread Maram SAlem
Thanks for helping Boris.

 Regards,
 Maram Salem

On 25 October 2015 at 23:30, Boris Steipe  wrote:

> It may be useful for you to estimate the time complexity of your function:
> try it with smaller input that takes short and noticeable time, see whether
> the time increases linearly, quadratically, or exponentially with the
> number of elements you process, then  extrapolate to your full data set.
>
>
> To see what your function is doing, you could
> - add a print statement that tells you the progress every 1000 or 10,000
> items or so...
> - add a progress bar
>
> https://stat.ethz.ch/R-manual/R-patched/library/utils/html/txtProgressBar.html
> - install and use the pbapply package
> https://cran.r-project.org/web/packages/pbapply/pbapply.pdf
>
>
> You are right to make sure you are getting some feedback, it is easy to
> make a mistake in function logic that will cause a function to fail to
> terminate.
>
>
> B.
>
>
>
> On Oct 25, 2015, at 5:05 PM, Maram SAlem 
> wrote:
>
> > Hi All,
> >
> > I'm using a function, say func, and I want to apply it to all the rows
> of a
> > certain matrix. The problem is that my code kept on running for more than
> > two days without giving any output. I've made some modifications.But is
> > there a way to know the time needed to execute my code and reach an ouput
> > but before running the code and not after it is run? I've tried
> Sys.time()
> > and system.time(), but still the console freezed for so long and I didn't
> > reach anything.
> >
> > Any suggestions are much appreciated.
> > Thanks in advance.
> >
> > Maram Salem
> >
> >   [[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.
>
>

[[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] warning on generic function when building R package

2015-10-27 Thread Duncan Murdoch
On 27/10/2015 3:52 PM, David Stevens wrote:
> Sorry to be a late comer to this problem but I'm having a similar 
> issue.  My function is called by ode from deSolve
> 
> ADM1_C <- function(t,state,parameters,...){
> 
> with(as.list(c(state,parameters)), {
># do some stuff here and return a list containing a vector of 
> derivatives to ode
> ...
> })
> }
> in which 't' is a time and 'state' and 'parameters' are numeric vectors 
> with each element named. When I invoke the solver,
> 
> times <- d.df$time
> out <- as.data.frame(ode(y = state,times = times,func = ADM1_C,parms = 
> parameters))
> 
> I get ~three Note:s for each value in 'state'  (sometimes more). The 
> calculation is successful but the issue is a little puzzling.
> Here's 'state'
> state
>   Ssu  Saa  Sfa  Sva  Sbu Spro Sac  Sh2 
> Sch4  Sic
> 0.30 0.001000 0.30 0.30 0.30 0.30 0.30 0.01 
> 0.10 0.04
>   Sin   Si   Xc  Xch  Xpr  Xli Xsu  Xaa  
> Xfa  Xc4
> 0.01 0.02 0.30 0.026000 0.30 0.03 0.40 1.10 
> 0.20 0.41
>  Xpro  Xac  Xh2   Xi  Scation   Sanion Sva_mSbu_m   
> Spro_mSac_m
> 0.137000 0.70 0.01 5.00 0.04 0.02 0.09 0.09 
> 0.074000 0.169000
>   Shco3_m Snh3  Sgas_h2 Sgas_ch4 Sgas_co2
> 0.009700 0.016000 0.02 0.02 0.037600
> 
> The messages are something like this ...
> Note: no visible binding for global variable 'Sin'
> Note: no visible binding for global variable 'Snh3'
> Note: no visible binding for global variable 'Scation'
> Note: no visible binding for global variable 'Shco3_m'
>  (~130 rows of these messages)

I don't see how this has anything to do with the previous problem.
> 
> Neither Duncan's nor Jim's solution solved the problem.  I can't change 
> (at least I don't think so) how ode(...) calls the function except via 
> the documentation. Any ideas? Does it matter? Could it be ode strips out 
> the names, but only sometimes?

You will need to post something that we can reproduce if you want help
with it.  (Please do this on a new thread, since you really have nothing
to do with generic functions as far as I can see.)

Or you can add cat() and print() statements to your function (or set
breakpoints in a debugger) and you'll be able to see what it's getting.

Duncan Murdoch

> 
> signed Grasping at Straws (David)
> 
> David K Stevens, P.E., Ph.D.
> Professor and Head, Environmental Engineering
> Civil and Environmental Engineering
> Utah Water Research Laboratory
> 8200 Old Main Hill
> Logan, UT  84322-8200
> 435 797 3229 - voice
> 435 797 1363 - fax
> david.stev...@usu.edu
> 
> 
> On 10/19/2015 2:32 PM, carol white via R-help wrote:
>> In effect, this works
>> but whether I use x or x.init, y or y.init in plot.func, I get
>>   
>> no visible binding for global variable ‘x.init’no visible binding for global 
>> variable ‘y.init’
>> Regards,
>>
>>   On Monday, October 19, 2015 9:59 PM, Duncan Murdoch 
>>  wrote:
>> 
>>
>>   On 19/10/2015 3:50 PM, carol white wrote:
>>> Thanks Murdoch.
>>>
>>> defining
>>> plot.func<- function(x=x.init, y=y.init, arg3, arg4, "title", col, arg5)
>>>
>>> and if plot doesn't take the exact parameters of plot.func but modified
>>> of these parameters
>>> plot(x=x.pt,y=y.pt,xlim = c(0, 10), ylim = c(0,1), xlab= "xlab",
>>> ylab="ylab", main = "title", col = col,type = "l")
>>>
>>> then, how to define and invoke to be consisent?
>> I don't really understand your question, but this is all about the
>> function header for plot.func, not the call you make to plot().  You
>> need to name the first argument as "x", you need to include "..." as an
>> open argument, and you need a legal header.  So this would be okay:
>>
>>
>> plot.func<- function(x=x.init, y=y.init, arg3, arg4,
>>  main = "title", # can't skip the arg name
>>  col, arg5,
>>  ...)  {  # can't skip the dots
>>
>> Duncan Murdoch
>>
>>> Regards,
>>>
>>> On Monday, October 19, 2015 7:45 PM, Duncan Murdoch
>>>  wrote:
>>>
>>>
>>> On 19/10/2015 1:29 PM, carol white via R-help wrote:
>>>
 Hi,I have invoked plot in a function (plot.func) as follows but when I
>>> check the built package, I get a warning:
 plot(x.pt,y.pt,xlim = c(0, 10), ylim = c(0,1), xlab= "xlab",
>>> ylab="ylab", main = "title", col = col,type = "l")
 R CMD check my.package
 checking S3 generic/method consistency ... WARNING
 plot:
function(x, ...)
 plot.func:
function(x.pt, y.pt, arg3, arg4, "title", col, arg5)

 See section ‘Generic functions and methods’ in the ‘Writing R
 Extensions’ manual.
 Which plot argument is illegitimate or missing and how to eliminate
>>> the warning?
>>>
>>>
>>> The first argument to plot.func needs to be called "x" if you want to
>>> use it as a method.  

Re: [R] rgl plot rotation with device other than mouse

2015-10-27 Thread Duncan Murdoch
On 27/10/2015 2:35 PM, santiago gil wrote:
> Well, I haven't built the device yet, I'm trying to figure out what my
> options will be. In the case of plugging in a simple USB trackball, I
> suppose it can work with the HID Manager in Mac to customize the signal
> from it.
> 
> In general, would it be possible to manipulate the plot, say for
> example, with a standard joystick? Is there something "deeper" in the
> code that I could look towards to make this possible? Or any other
> library that might support something like this?

I've already answered this below.

Duncan Murdoch

> 
> 2015-10-27 14:17 GMT-04:00 Duncan Murdoch  >:
> 
> On 27/10/2015 1:38 PM, santiago gil wrote:
> 
> Hello R,
> 
> I'm trying to figure out if it would be possible use a device
> (maybe simply
> a trackball) separate from the mouse that would have the ability
> to rotate
> a 3D plot made with rgl without any buttons. This is to build an
> interactive "demo"-like piece for which a mouse or trackpad is an
> unsatisfactory manipulation tool. The worse solution would be to
> make the
> trackpad button "sticky" so that it works as a rotation on/off
> toggle.
> Anything that is less intrusive with the computer's operability
> is even
> better. I couldn't find the right way in par3d or anything of
> the sort. Any
> tips anybody? Or any other libraries to would use to do
> something like this?
> 
> 
> Do you know how to get input from that device?  If so, you can
> explicitly set par3d("userMatrix") to a rotation
> matrix based on the input.
> 
> rgl itself has no support for getting input from anything other than
> the mouse and keyboard.
> 
> Duncan Murdoch
> 
> 
> 
> 
> -- 
> ---
> http://barabasilab.neu.edu/people/gil/

__
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 get variable name while doing series of regressions in an automated manner?

2015-10-27 Thread Ravi Varadhan
Thank you very much, Marc & Bert.

Bert - I think you're correct.  With Marc's solution, I am not able to get the 
response variable name in the call to lm().  But, your solution works well.

Best regards,
Ravi

-Original Message-
From: Bert Gunter [mailto:bgunter.4...@gmail.com] 
Sent: Tuesday, October 27, 2015 1:50 PM
To: Ravi Varadhan 
Cc: r-help@r-project.org
Subject: Re: [R] How to get variable name while doing series of regressions in 
an automated manner?

Marc,Ravi:

I may misunderstand, but I think Marc's solution labels the list components but 
not necessarily the summary() outputs. This might be sufficient, as in:

> z <- list(y1=rnorm(10,5),y2 = rnorm(10,8),x=1:10)
>
> ##1
> results1<-lapply(z[-3],function(y)lm(log(y)~x,data=z))
> lapply(results1,summary)
$y1

Call:
lm(formula = log(y) ~ x, data = z)

Residuals:
Min  1Q  Median  3Q Max
-0.2185 -0.1259 -0.0643  0.1340  0.3988

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  1.693190.14375  11.779 2.47e-06 ***
x   -0.014950.02317  -0.6450.537
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.2104 on 8 degrees of freedom
Multiple R-squared:  0.04945,Adjusted R-squared:  -0.06937
F-statistic: 0.4161 on 1 and 8 DF,  p-value: 0.5369


$y2

Call:
lm(formula = log(y) ~ x, data = z)

Residuals:
  Min1QMedian3Q   Max
-0.229072 -0.094579 -0.006498  0.134303  0.188158

Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept)  2.084846   0.104108  20.026 4.03e-08 ***
x   -0.006226   0.016778  -0.371 0.72
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1524 on 8 degrees of freedom
Multiple R-squared:  0.01692,Adjusted R-squared:  -0.106
F-statistic: 0.1377 on 1 and 8 DF,  p-value: 0.7202


## 2

Alternatively, if you want output with the correct variable names,
bquote() can be used, as in:

> results2 <-lapply(names(z)[1:2],
+function(nm){
+  fo <-formula(paste0("log(",nm,")~x"))
+   eval(bquote(lm(.(u),data=z),list(u=fo)))
+})
> lapply(results2,summary)
[[1]]

Call:
lm(formula = log(y1) ~ x, data = z)

Residuals:
Min  1Q  Median  3Q Max
-0.2185 -0.1259 -0.0643  0.1340  0.3988

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  1.693190.14375  11.779 2.47e-06 ***
x   -0.014950.02317  -0.6450.537
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.2104 on 8 degrees of freedom
Multiple R-squared:  0.04945,Adjusted R-squared:  -0.06937
F-statistic: 0.4161 on 1 and 8 DF,  p-value: 0.5369


[[2]]

Call:
lm(formula = log(y2) ~ x, data = z)

Residuals:
  Min1QMedian3Q   Max
-0.229072 -0.094579 -0.006498  0.134303  0.188158

Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept)  2.084846   0.104108  20.026 4.03e-08 ***
x   -0.006226   0.016778  -0.371 0.72
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1524 on 8 degrees of freedom
Multiple R-squared:  0.01692,Adjusted R-squared:  -0.106
F-statistic: 0.1377 on 1 and 8 DF,  p-value: 0.7202


HTH or apologies if I've missed the point and broadcasted noise.

Cheers,
Bert
Bert Gunter

"Data is not information. Information is not knowledge. And knowledge is 
certainly not wisdom."
   -- Clifford Stoll


On Tue, Oct 27, 2015 at 8:19 AM, Ravi Varadhan  wrote:
> Hi,
>
> I am running through a series of regression in a loop as follows:
>
> results <- vector("list", length(mydata$varnames))
>
> for (i in 1:length(mydata$varnames)) { results[[i]] <- 
> summary(lm(log(eval(parse(text=varnames[i]))) ~ age + sex + 
> CMV.status, data=mydata)) }
>
> Now, when I look at the results[i]] objects, I won't be able to see the 
> original variable names.  Obviously, I will only see the following:
>
> Call:
> lm(formula = log(eval(parse(text = varnames[i]))) ~ age + sex + CMV.status,
> data = mydata)
>
>
> Is there a way to display the original variable names on the LHS?  In 
> addition, is there a better paradigm for doing these type of series of 
> regressions in an automatic fashion?
>
> Thank you very much,
> Ravi
>
> Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg) 
> Associate Professor,  Department of Oncology Division of Biostatistics 
> & Bionformatics Sidney Kimmel Comprehensive Cancer Center Johns 
> Hopkins University
> 550 N. Broadway, Suite -E
> Baltimore, MD 21205
> 410-502-2619
>
>
> [[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 

Re: [R] Extract entries from matrix

2015-10-27 Thread jim holtman
If you want to use the numbers you gave a the index into the matrix, then
you can create a matrix with the values and then index into 'm'.  I don't
see a '4' in the output example you gave using your index values:

> m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
+  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L,
+  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L,
+  0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
+  3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L,
+  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L,
+  0L, 0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
+  5L), .Dim = c(22L, 5L))
> # create index matrix
> indx <- matrix(c(4, 1,
+  5, 2,
+  6, 3,
+  7, 1,
+  8, 2,
+  9, 3,
+  10, 1,
+  11, 2,
+  12, 3), ncol = 2, byrow = TRUE)
>
>
> m
  [,1] [,2] [,3] [,4] [,5]
 [1,]00000
 [2,]00000
 [3,]00000
 [4,]12300
 [5,]12300
 [6,]12300
 [7,]12300
 [8,]12300
 [9,]12340
[10,]12340
[11,]12345
[12,]12345
[13,]12345
[14,]12345
[15,]12345
[16,]12345
[17,]12345
[18,]12345
[19,]12345
[20,]12345
[21,]12345
[22,]12345
> indx
  [,1] [,2]
 [1,]41
 [2,]52
 [3,]63
 [4,]71
 [5,]82
 [6,]93
 [7,]   101
 [8,]   112
 [9,]   123
> m[indx]
[1] 1 2 3 1 2 3 1 2 3


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Tue, Oct 27, 2015 at 2:43 PM, Jorge I Velez 
wrote:

> Dear R-help,
>
> I am working with a matrix "m" from which I would like to extract some
> elements.  An toy example is as follows:
>
> ## input matrix
> m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L,
> 0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L,
> 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L,
> 0L, 0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
> 5L), .Dim = c(22L, 5L))
>
> R> m
> # [,1]  [,2] [,3] [,4] [,5]
> #  [1,]00000
> #  [2,]00000
> #  [3,]00000
> #  [4,]12300
> #  [5,]12300
> #  [6,]12300
> #  [7,]12300
> #  [8,]12300
> #  [9,]12340
> # [10,]   12340
> # [11,]   12345
> # [12,]   12345
>
> >From "m", I would like to extract the entries
>
> 4, 1
> 5, 2
> 6, 3
> 7, 1
> 8, 2
> 9, 3
> 10, 1
> 11, 2
> 12, 3
>
> so at the end of applying a function "f" to "m" I get
>
> 1, 2, 3, 1, 2, 3, 4, 1, 2, 3
>
>
> Basically the idea is to extract the diagonal elements until a zero is
> found.
>
> In the real problem the dimensions of "m" are much bigger, but this smaller
> version of "m" illustrate what needs to be done.
>
> I would greatly appreciate any ideas on how to do this.
>
> Thanks in advance,
> Jorge Velez.-
>
> [[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.
>

[[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] Extract entries from matrix

2015-10-27 Thread Jorge I Velez
Dear Jim,

Thank you very much for your quick reply.

I am sorry for the confusion it may have caused, but I messed up the
indexes in my example.  I would like, from the following matrix "m"

## input
m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L,
4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5L, 5L), .Dim = c(12L,
5L))

to obtain

 1 2 3 1 2 3 4 5 1

Sure using m[idx] will give the desired result.  The problem is that idx is
not known and needs to be determined from "m".  I would like to use
something like

extractDiagonals(m)
## [1]  1 2 3 1 2 3 4 5 1

I look forward to your reply.  Thanks in advance.

Best regards,
Jorge Velez.-



On Tue, Oct 27, 2015 at 2:31 PM, jim holtman  wrote:

> If you want to use the numbers you gave a the index into the matrix, then
> you can create a matrix with the values and then index into 'm'.  I don't
> see a '4' in the output example you gave using your index values:
>
> > m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> +  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L,
> +  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L,
> +  0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> +  3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L,
> +  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L,
> +  0L, 0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
> +  5L), .Dim = c(22L, 5L))
> > # create index matrix
> > indx <- matrix(c(4, 1,
> +  5, 2,
> +  6, 3,
> +  7, 1,
> +  8, 2,
> +  9, 3,
> +  10, 1,
> +  11, 2,
> +  12, 3), ncol = 2, byrow = TRUE)
> >
> >
> > m
>   [,1] [,2] [,3] [,4] [,5]
>  [1,]00000
>  [2,]00000
>  [3,]00000
>  [4,]12300
>  [5,]12300
>  [6,]12300
>  [7,]12300
>  [8,]12300
>  [9,]12340
> [10,]12340
> [11,]12345
> [12,]12345
> [13,]12345
> [14,]12345
> [15,]12345
> [16,]12345
> [17,]12345
> [18,]12345
> [19,]12345
> [20,]12345
> [21,]12345
> [22,]12345
> > indx
>   [,1] [,2]
>  [1,]41
>  [2,]52
>  [3,]63
>  [4,]71
>  [5,]82
>  [6,]93
>  [7,]   101
>  [8,]   112
>  [9,]   123
> > m[indx]
> [1] 1 2 3 1 2 3 1 2 3
>
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
> On Tue, Oct 27, 2015 at 2:43 PM, Jorge I Velez 
> wrote:
>
>> Dear R-help,
>>
>> I am working with a matrix "m" from which I would like to extract some
>> elements.  An toy example is as follows:
>>
>> ## input matrix
>> m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L,
>> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L,
>> 0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
>> 3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L,
>> 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L,
>> 0L, 0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
>> 5L), .Dim = c(22L, 5L))
>>
>> R> m
>> # [,1]  [,2] [,3] [,4] [,5]
>> #  [1,]00000
>> #  [2,]00000
>> #  [3,]00000
>> #  [4,]12300
>> #  [5,]12300
>> #  [6,]12300
>> #  [7,]12300
>> #  [8,]12300
>> #  [9,]12340
>> # [10,]   12340
>> # [11,]   12345
>> # [12,]   12345
>>
>> >From "m", I would like to extract the entries
>>
>> 4, 1
>> 5, 2
>> 6, 3
>> 7, 1
>> 8, 2
>> 9, 3
>> 10, 1
>> 11, 2
>> 12, 3
>>
>> so at the end of applying a function "f" to "m" I get
>>
>> 1, 2, 3, 1, 2, 3, 4, 1, 2, 3
>>
>>
>> Basically the idea is to extract the diagonal elements until a zero is
>> found.
>>
>> In the real problem the dimensions of "m" are much bigger, but this
>> smaller
>> version of "m" illustrate what needs to be done.
>>
>> I would greatly appreciate any ideas on how to do this.
>>
>> Thanks in advance,
>> Jorge Velez.-
>>
>> [[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
>> 

Re: [R] Extract entries from matrix

2015-10-27 Thread Jorge I Velez
Thank you all for your solutions and comments.

As Dr. Carlson mentioned, we leave rows 1 to 3 out as they are all zeroes.
Then, the entries I need to select from m are


entry value

4,1  ---> 1
5,2  ---> 2
6,3  ---> 3
7,1  ---> 1
8,2  ---> 2
9,3  ---> 3
10,4  ---> 4
11,5  ---> 5
12,1  ---> 1

Note that the entry [7,4] is zero, so we start from the first column in the
7th row and then select entry [7,1] instead.  That's what I meant by  "...
the idea is to extract the diagonal elements until a zero is found."  I
should have said *entries* instead of  _diagonal elements_. I am sorry Dr.
Turner for the confusion.

Starting with m

R> m
#   [,1] [,2] [,3] [,4] [,5]
# [1,]00000
# [2,]00000
# [3,]00000
# [4,]12300
# [5,]12300
# [6,]12300
# [7,]12300
# [8,]12300
# [9,]12340
#[10,]12340
#[11,]12345
#[12,]12345

the first submatrix to work with is

# [4,]12300
# [5,]12300
# [6,]12300

from which the elements of interest are 1, 2, 3.  Note that the 7th row of
m is not included here because m[7, 5] = 0.

Further, the second submatrix is

# [7,]12300
# [8,]12300
# [9,]12340
#[10,]12340
#[11,]12345

and the corresponding elements are 1, 2, 3, 4, 5.

And the last matrix is

#[12,]12345

from which the position [12,1] is selected.

So, the resulting entries from this process are 1, 2, 3, 1, 2, 3, 4, 5, 1.

Thank you in advance for any additional insight you may provide.

Regards,
Jorge Velez.-



On Tue, Oct 27, 2015 at 4:06 PM, David L Carlson  wrote:

> I don't see how you are getting the result you provide.
>
> > m
>   [,1] [,2] [,3] [,4] [,5]
>  [1,]00000
>  [2,]00000
>  [3,]00000
>  [4,]12300
>  [5,]12300
>  [6,]12300
>  [7,]12300
>  [8,]12300
>  [9,]12340
> [10,]12340
> [11,]12345
> [12,]12345
> > t(sapply(1:8, function(x) diag(m[x:12, ])))
>  [,1] [,2] [,3] [,4] [,5]
> [1,]00000
> [2,]00300
> [3,]02300
> [4,]12300
> [5,]12300
> [6,]12340
> [7,]12345
> [8,]12345
>
> These are all of the diagonals from the 1st through 8th rows. The first 3
> begin with 0 so we leave them out, but then we have 4th: 1, 2, 3; 5th: 1,
> 2, 3; 6th: 1, 2, 3, 4, etc so you must have some additional rule in mind to
> get your answer.
>
> -
> 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 Jorge I
> Velez
> Sent: Tuesday, October 27, 2015 2:44 PM
> To: jim holtman
> Cc: R-help
> Subject: Re: [R] Extract entries from matrix
>
> Dear Jim,
>
> Thank you very much for your quick reply.
>
> I am sorry for the confusion it may have caused, but I messed up the
> indexes in my example.  I would like, from the following matrix "m"
>
> ## input
> m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
> 0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 3L, 3L,
> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L,
> 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5L, 5L), .Dim = c(12L,
> 5L))
>
> to obtain
>
>  1 2 3 1 2 3 4 5 1
>
> Sure using m[idx] will give the desired result.  The problem is that idx is
> not known and needs to be determined from "m".  I would like to use
> something like
>
> extractDiagonals(m)
> ## [1]  1 2 3 1 2 3 4 5 1
>
> I look forward to your reply.  Thanks in advance.
>
> Best regards,
> Jorge Velez.-
>
>
>
> On Tue, Oct 27, 2015 at 2:31 PM, jim holtman  wrote:
>
> > If you want to use the numbers you gave a the index into the matrix, then
> > you can create a matrix with the values and then index into 'm'.  I don't
> > see a '4' in the output example you gave using your index values:
> >
> > > m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> > +  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L,
> > +  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L,
> > +  0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> > +  3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L,
> > +  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L,
> 

Re: [R-es] Una consultilla

2015-10-27 Thread Carlos Ortega
Hola,

Creo que la función "switch()" te puede ayudar...

Saludos,
Carlos Ortega
www.qualityexcellence.es

El 27 de octubre de 2015, 21:22, heber sarmiento via R-help-es <
r-help-es@r-project.org> escribió:

> Cordial saludo
> Quiero saber si alguien me puede orientar en lo siguiente,
> he construido un scrip con algunas funciones y estoy creando un menú para
> su selección; el asunto es que quiero saber si en R se cuenta con alguna
> función para seleccionar las funciones a usar; se que en otros lenguajes
> existe "case" pero no tengo idea en R.
> De antemano gracias por la ayuda.
> Heber
> [[alternative HTML version deleted]]
>
> ___
> 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


Re: [R] Extract entries from matrix

2015-10-27 Thread David L Carlson
I don't see how you are getting the result you provide.

> m
  [,1] [,2] [,3] [,4] [,5]
 [1,]00000
 [2,]00000
 [3,]00000
 [4,]12300
 [5,]12300
 [6,]12300
 [7,]12300
 [8,]12300
 [9,]12340
[10,]12340
[11,]12345
[12,]12345
> t(sapply(1:8, function(x) diag(m[x:12, ])))
 [,1] [,2] [,3] [,4] [,5]
[1,]00000
[2,]00300
[3,]02300
[4,]12300
[5,]12300
[6,]12340
[7,]12345
[8,]12345

These are all of the diagonals from the 1st through 8th rows. The first 3 begin 
with 0 so we leave them out, but then we have 4th: 1, 2, 3; 5th: 1, 2, 3; 6th: 
1, 2, 3, 4, etc so you must have some additional rule in mind to get your 
answer.

-
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 Jorge I Velez
Sent: Tuesday, October 27, 2015 2:44 PM
To: jim holtman
Cc: R-help
Subject: Re: [R] Extract entries from matrix

Dear Jim,

Thank you very much for your quick reply.

I am sorry for the confusion it may have caused, but I messed up the
indexes in my example.  I would like, from the following matrix "m"

## input
m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L,
4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5L, 5L), .Dim = c(12L,
5L))

to obtain

 1 2 3 1 2 3 4 5 1

Sure using m[idx] will give the desired result.  The problem is that idx is
not known and needs to be determined from "m".  I would like to use
something like

extractDiagonals(m)
## [1]  1 2 3 1 2 3 4 5 1

I look forward to your reply.  Thanks in advance.

Best regards,
Jorge Velez.-



On Tue, Oct 27, 2015 at 2:31 PM, jim holtman  wrote:

> If you want to use the numbers you gave a the index into the matrix, then
> you can create a matrix with the values and then index into 'm'.  I don't
> see a '4' in the output example you gave using your index values:
>
> > m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> +  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L,
> +  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L,
> +  0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> +  3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L,
> +  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L,
> +  0L, 0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
> +  5L), .Dim = c(22L, 5L))
> > # create index matrix
> > indx <- matrix(c(4, 1,
> +  5, 2,
> +  6, 3,
> +  7, 1,
> +  8, 2,
> +  9, 3,
> +  10, 1,
> +  11, 2,
> +  12, 3), ncol = 2, byrow = TRUE)
> >
> >
> > m
>   [,1] [,2] [,3] [,4] [,5]
>  [1,]00000
>  [2,]00000
>  [3,]00000
>  [4,]12300
>  [5,]12300
>  [6,]12300
>  [7,]12300
>  [8,]12300
>  [9,]12340
> [10,]12340
> [11,]12345
> [12,]12345
> [13,]12345
> [14,]12345
> [15,]12345
> [16,]12345
> [17,]12345
> [18,]12345
> [19,]12345
> [20,]12345
> [21,]12345
> [22,]12345
> > indx
>   [,1] [,2]
>  [1,]41
>  [2,]52
>  [3,]63
>  [4,]71
>  [5,]82
>  [6,]93
>  [7,]   101
>  [8,]   112
>  [9,]   123
> > m[indx]
> [1] 1 2 3 1 2 3 1 2 3
>
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
> On Tue, Oct 27, 2015 at 2:43 PM, Jorge I Velez 
> wrote:
>
>> Dear R-help,
>>
>> I am working with a matrix "m" from which I would like to extract some
>> elements.  An toy example is as follows:
>>
>> ## input matrix
>> m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L,
>> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L,
>> 0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
>> 3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L,
>> 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L,
>> 0L, 0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 

Re: [R] [FORGED] Re: Extract entries from matrix

2015-10-27 Thread Rolf Turner



Maybe it's just me --- I'm notoriously slow --- but I haven't a clue 
what you are trying to do.  You said:


  "... the idea is to extract the diagonal elements until a
   zero is found."

I don't see anything that resembles a "diagonal element" (*entry*, 
actually; sets have elements, arrays have entries) in your desired 
output.  What do you mean by the diagonal of a non-square matrix anyway?


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

8/10/15 08:43, Jorge I Velez wrote:

Dear Jim,

Thank you very much for your quick reply.

I am sorry for the confusion it may have caused, but I messed up the
indexes in my example.  I would like, from the following matrix "m"

## input
m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L,
4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5L, 5L), .Dim = c(12L,
5L))

to obtain

  1 2 3 1 2 3 4 5 1

Sure using m[idx] will give the desired result.  The problem is that idx is
not known and needs to be determined from "m".  I would like to use
something like

extractDiagonals(m)
## [1]  1 2 3 1 2 3 4 5 1

I look forward to your reply.  Thanks in advance.

Best regards,
Jorge Velez.-



On Tue, Oct 27, 2015 at 2:31 PM, jim holtman  wrote:


If you want to use the numbers you gave a the index into the matrix, then
you can create a matrix with the values and then index into 'm'.  I don't
see a '4' in the output example you gave using your index values:


m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,

+  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L,
+  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L,
+  0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
+  3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L,
+  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L,
+  0L, 0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
+  5L), .Dim = c(22L, 5L))

# create index matrix
indx <- matrix(c(4, 1,

+  5, 2,
+  6, 3,
+  7, 1,
+  8, 2,
+  9, 3,
+  10, 1,
+  11, 2,
+  12, 3), ncol = 2, byrow = TRUE)



m

   [,1] [,2] [,3] [,4] [,5]
  [1,]00000
  [2,]00000
  [3,]00000
  [4,]12300
  [5,]12300
  [6,]12300
  [7,]12300
  [8,]12300
  [9,]12340
[10,]12340
[11,]12345
[12,]12345
[13,]12345
[14,]12345
[15,]12345
[16,]12345
[17,]12345
[18,]12345
[19,]12345
[20,]12345
[21,]12345
[22,]12345

indx

   [,1] [,2]
  [1,]41
  [2,]52
  [3,]63
  [4,]71
  [5,]82
  [6,]93
  [7,]   101
  [8,]   112
  [9,]   123

m[indx]

[1] 1 2 3 1 2 3 1 2 3


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Tue, Oct 27, 2015 at 2:43 PM, Jorge I Velez 
wrote:


Dear R-help,

I am working with a matrix "m" from which I would like to extract some
elements.  An toy example is as follows:

## input matrix
m <- structure(c(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L,
0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L), .Dim = c(22L, 5L))

R> m
# [,1]  [,2] [,3] [,4] [,5]
#  [1,]00000
#  [2,]00000
#  [3,]00000
#  [4,]12300
#  [5,]12300
#  [6,]12300
#  [7,]12300
#  [8,]12300
#  [9,]12340
# [10,]   12340
# [11,]   12345
# [12,]   12345

>From "m", I would like to extract the entries

4, 1
5, 2
6, 3
7, 1
8, 2
9, 3
10, 1
11, 2
12, 3

so at the end of applying a function "f" to "m" I get

1, 2, 3, 1, 2, 3, 4, 1, 2, 3


Basically the idea is to extract the diagonal elements until a zero is
found.

In the real problem the dimensions of "m" are much bigger, but this
smaller
version of "m" illustrate what needs to be done.

I would greatly appreciate any ideas on how to do this.

Thanks in advance.



Re: [R-es] pregunta

2015-10-27 Thread eric
tambien te sirve la funcion data.table ... si no tienes instalado el 
paquete:


install.packages("data.table")
library(data.table)
jbe <- as.data.table(read.table("tusdatos.txt"))
jbe.ave <- jbe[, .("ave"=mean(Gain)), by=.(Diet)]

> jbe.ave
   Diet ave
1:   d1 280
2:   d2 278
3:   d3 312


Saludos.

Eric.


On 10/27/2015 05:16 PM, jbetancourt wrote:


Estimados

Cuando existia epicalc,  hab�a una  manera muy f�cil de determinar la media de 
una variable (en esta caso Gain)  por grupos, en este caso (Diet). ?Como se 
puede hacer ahora?

   Diet Gain
1d1  270
2d1  300
3d1  280
4d1  280
5d1  270
6d2  290
7d2  250
8d2  280
9d2  290
10   d2  280
11   d3  290
12   d3  340
13   d3  330
14   d3  300
15   d3  300

Saludos
Jos�

[[alternative HTML version deleted]]



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



--
Forest Engineer
Master in Environmental and Natural Resource Economics
Ph.D. student in Sciences of Natural Resources at La Frontera University
Member in AguaDeTemu2030, citizen movement for Temuco with green city 
standards for living


Nota: Las tildes se han omitido para asegurar compatibilidad con algunos 
lectores de correo.


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

[R] rms package: residual df for penalised ols

2015-10-27 Thread Mark Seeto
Dear R-help,

In the rms package, when using the ols function with a penalty, the
df.residual appears to always be n-1 (with n being the sample size).
That seems strange to me, but I don't have much knowledge in this
area.

Here's an example:

library(rms)

set.seed(1)

n <- 50

d <- data.frame(x1 = rnorm(n),
x2 = rnorm(n, 0, 5),
x3 = rnorm(n))
d$y <- with(d, 1 + 0.8*x1 + 0.5*x2 - 0.5*x3) + rnorm(n)

ols1 <- ols(y ~ x1 + x2 + x3, data=d)
ols2 <- ols(y ~ x1 + x2 + x3, data=d, penalty=10)

ols1$stats["d.f."]  # 3
ols2$stats["d.f."]  # 5.2

ols1$df.residual# 46 = n - 3 - 1
ols2$df.residual# 49


I would be grateful if someone could give a brief explanation of why
df.residual is n-1. The reason I'm interested in this is that
confidence intervals for predicted values use the df.residual value.

Thanks,
Mark

__
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] Distribution hist

2015-10-27 Thread bgnumis bgnum
Hi all,

I have this data on "sim" variable

 10403.000NANANANA
 11178.000NANANANA
 11521.000NANANANA
 11385.000NANANANA
10102.000NANANANA
 10544.013 10339.925  9912.695  9928.198  9932.112
  9008.050  9437.174 10406.784 10832.123 11095.868
 10955.094 10804.075  9002.848 11276.038 10503.487
 11899.525 10085.509  9109.918  8953.339 10135.833
 11047.832 14353.462  8804.653 11942.829  7722.255
  9732.114  8413.027 10213.796 10091.471 12317.169

I want to use matplot on a left plot and a "distribution line" on a right
plot.

My idea is the same size from the ylim (max and min) on the left plot will
be the same on the right plot (but I cannot get the same size so thar the
right plot show the distribution of the matplot on the left.

I tried this but canot (some suggest me using rect() for the boundaries of
the second plot but I cannot achive what I want.

I dont care if is it a hist or line plot but something similar a
distribution shape (or like a bell)


Can anyone try to help me?

par(mar=c(10,6,6,6))
matplot(Simulation,type="l",ylim=c(0,2))


title(" Dim Mo Simulation 2 years",font=4)
fhist<-hist(Simulation,plot=FALSE)

par(mar=c(6,0,6,6))
barplot(fhist$counts,axes=FALSE, space=0,horiz=TRUE,col="lightgray")

[[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] coxme adequacy check

2015-10-27 Thread Cacique Samurai
Hello all!

I´m fitting a mixed effects cox model with coxme function of coxme package.
I want to konw what is the best way to check the model adequacy, once that
function cox.zph that does not work for coxme objects.

Thanks in advanced,

Raoni

-- 
Raoni Rosa Rodrigues
Research Associate of Fish Transposition Center CTPeixes
Universidade Federal de Minas Gerais - UFMG
Brasil
rodrigues.ra...@gmail.com

[[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] Memory problems with mice

2015-10-27 Thread Lorenz, Jennifer
Hi everyone,

I am trying to perform a multiple imputation with mice on a dataset of about 
13000 observations and 178 variables. I can start an "empty" imputation 
("imp_start <- mice(data, maxit=0)"), but after a few minutes R stops with the 
following error message:
Error: cannot allocate vector of size 2.0 Gb
In addition: Warning messages:
1: In col(value) :
  Reached total allocation of 8078Mb: see help(memory.size)
2: In col(value) :
  Reached total allocation of 8078Mb: see help(memory.size)
3: In unique.default(x) :
  Reached total allocation of 8078Mb: see help(memory.size)
4: In unique.default(x) :
  Reached total allocation of 8078Mb: see help(memory.size)
5: In unique.default(x) :
  Reached total allocation of 8078Mb: see help(memory.size)
6: In unique.default(x) :
  Reached total allocation of 8078Mb: see help(memory.size)

I am using R (with R Studio) on Windows 7, my computer has a total of 8 GB RAM.
Following advice I found on the internet, I installed the newest R-version 
(64-bit) and tried the following commands:
memory.size(max = F)
memory.limit(size=NA)

But I still get the same error. Now I am wondering, if my dataset is really to 
large for mice or R? Or is there any other setting I could use to increase 
memory size for R? I would really appreciate if anyone who is familiar with 
this problem would share their insights...

Thanks,
Jen


---
Jennifer Lorenz, M.A.
Georg-August-Universit�t G�ttingen
Sozialwissenschaftliche Fakult�t
Institut f�r Erziehungswissenschaft
Lehrstuhl Schulp�dagogik / Empirische Schulforschung

e-mail: jlor...@uni-goettingen.de
phone: 0551-39-21411
adress: Waldweg 26, 37073 G�ttingen
room: 8.106


[[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] monte carlo simulations in permanova in vegan package

2015-10-27 Thread Sean Porter
Hi Stephen and others,

 

I am trying to run a one-way permanova where I have only 2 levels in the factor 
“time”, and each level contains only 3 replicates. So because I have such few 
observations (6 in total) and levels (2) there are not enough possible 
permutations to get a reasonable test (i.e. (2*3)!/ [2!(3!)^2].   That is why 
for example if I run the analysis with only 99 permutations it completes the 
task. However, if I set the number of permutations to anything larger it 
returns the message “'nperm' > set of all permutations; Resetting 'nperm'.” as 
the number of possible permutations exceeds the number set by the argument 
“permutations=”. In PERMANOVA + for PRIMER there is a way of dealing with this 
issue – by using Monte Carlo simulations to generate the p value with a 
reasonable number of permutations. Hopefully this clarifies my situation and 
aim?

 

I was therefore hoping there was a way of coding for the Monte-Carlo 
permutation procedure into adonis?  

 

Thanks for your help!

 

From: stephen sefick [mailto:ssef...@gmail.com] 
Sent: 27 October 2015 03:11 PM
To: Sean Porter
Cc: r-help@r-project.org
Subject: Re: [R] monte carlo simulations in permanova in vegan package

 

The example code works, and reports  permutations. Can you provide more 
information? 

 

data(dune)
data(dune.env)
adonis(dune ~ Management*A1, data=dune.env, permutations=)

 

 

On Tue, Oct 27, 2015 at 3:56 AM, Sean Porter  wrote:

Dear colleagues,



I am trying to run a PERMANOVA in the vegan package with an appropriate
number of permutations (see example below), ideally . Obviously that
number of permutations does not exists so I would like to use Monte Carlo
permutation tests to derive the probability value, as is done in the
commercial package PERMANOVA+ for PRIMER. How can I adapt my code so that
adonis will do so ? Many thanks, Sean



> permanova <- adonis(species ~ time, data = time, permutations=99,
method="bray")

> permanova



Call:

adonis(formula = species ~ time, data = time, permutations = 99,  method
= "bray")



Permutation: free

Number of permutations: 99



Terms added sequentially (first to last)



  Df SumsOfSqs  MeanSqs F.Model  R2 Pr(>F)

time   1  0.070504 0.070504  123.65 0.96866   0.01 **

Residuals  4  0.002281 0.000570 0.03134

Total  5  0.072785  1.0

---

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1





> permanova <- adonis(species ~ time, data = time, permutations=999,
method="bray")

'nperm' > set of all permutations; Resetting 'nperm'.










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







-- 

Stephen Sefick
**
Auburn University 
Biological Sciences  
331 Funchess Hall   
Auburn, Alabama
36849   
**
sas0...@auburn.edu  
http://www.auburn.edu/~sas0025 
**

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

-K. Mullis

"A big computer, a complex algorithm and a long time does not equal science."

  -Robert Gentleman


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