Re: [R] Fastest way to extract rows of smaller matrix many times by index to make larger matrix? and multiply columsn of matrix by vector

2021-09-14 Thread nevil amos
OK thanks, I thought it probably was, but always worth asking. the
multiplication of the columns of M2 by V2 is as intended - not matrix
multiplication.



On Tue, 14 Sept 2021 at 17:49, Jeff Newmiller 
wrote:

> That is about as fast as it can be done. However you may be able to avoid
> doing it at all if you fold V2 into a matrix instead. Did you mean to use
> matrix multiplication in your calculation of M3?
>
> On September 13, 2021 11:48:48 PM PDT, nevil amos 
> wrote:
> >Hi is there a faster way to "extract" rows of a matrix many times to for a
> >longer matrix based in a vector or for indices than M[ V, ]
> >
> >I need to "expand" ( rather than subset)  a matrix M of 10-100,000 rows x
> >~50 columns to produce a matrix with a greater number (10^6-10^8) of rows
> >using a vector V containing the 10^6 -10^8 values that are the indices of
> >the rows of M. the output matrix M2 is then multiplied by another vector
> V2
> >With the same length as V.
> >
> >Is there a faster way to achieve these calculations (which are by far the
> >slowest portion of a function looped 1000s of times? than the standard  M2
> ><- M[ V, ] and  M3<-M2*V2, the two calculations are taking a similar time,
> >Matrix M also changes for each loop.
> >
> >
> >M<-matrix(runif(50*1,0,100),nrow=1,ncol=50)
> >x = 10^7
> >V<-sample(1:1,x,replace=T)
> >V2<-(sample(c(1,NA),x,replace=T))
> >print<-(microbenchmark(
> >M2<-M[V,],
> >M3<-M2*V2,
> >times=5,unit = "ms"))
> >
> >
> >
> >thanks for any suggestions
> >
> >Nevil Amos
> >
> >   [[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.
>
> --
> Sent from my phone. Please excuse my brevity.
>

[[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] Fastest way to extract rows of smaller matrix many times by index to make larger matrix? and multiply columsn of matrix by vector

2021-09-14 Thread nevil amos
Hi is there a faster way to "extract" rows of a matrix many times to for a
longer matrix based in a vector or for indices than M[ V, ]

I need to "expand" ( rather than subset)  a matrix M of 10-100,000 rows x
~50 columns to produce a matrix with a greater number (10^6-10^8) of rows
using a vector V containing the 10^6 -10^8 values that are the indices of
the rows of M. the output matrix M2 is then multiplied by another vector V2
With the same length as V.

Is there a faster way to achieve these calculations (which are by far the
slowest portion of a function looped 1000s of times? than the standard  M2
<- M[ V, ] and  M3<-M2*V2, the two calculations are taking a similar time,
Matrix M also changes for each loop.


M<-matrix(runif(50*1,0,100),nrow=1,ncol=50)
x = 10^7
V<-sample(1:1,x,replace=T)
V2<-(sample(c(1,NA),x,replace=T))
print<-(microbenchmark(
M2<-M[V,],
M3<-M2*V2,
times=5,unit = "ms"))



thanks for any suggestions

Nevil Amos

[[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] shinyFiles update shinySaveButton filename varaible from server

2021-06-04 Thread nevil amos
Is it possible to update the filename variable  the shinySaveButton from
the server?

I want to provide a default  filename based on a series of choices that the
user has made in the app ( here I have just made a random string to serve
the purpose.  how do I feed output$defaultname
 so that shinySaveButton( filename = outputSdefaultname )?


library(shiny)
library(shinyFiles)

data <- iris
roots <- c("UserFolder"=".")

ui <- fluidPage(
  actionButton("makeName","Make Default File Name"),
  shinySaveButton(id = "save", label = "Save file", title = "Save file as
...", filename = "defaultname",filetype=list(csv="csv"))
)


server <- shinyServer(function(input, output, session) {
  rv <- reactiveValues()
  observeEvent(input$makeName,{
output$defaultname<-paste(letters[sample(1:10,5)],collapse="")
  })

  observe({


shinyFileSave(input, "save", roots=roots, session=session)
fileinfo <- parseSavePath(roots, input$save)
xx<<-input$save
if (nrow(fileinfo) > 0) {
  write.csv(, as.character(fileinfo$datapath))

}
session$allowReconnect("force")
  })
})

runApp(list(
  ui=ui,
  server=server
))

[[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] setting wd to parent directory ("..") of rmd file for all chunks of .Rmd

2021-03-24 Thread nevil amos
The Rmarkdown cookbook states that the working directory for r chunks in an
Rmd file is usually the directory containing the file,
 however it can be reset using

knitr::opts_knit$set(root.dir =

see:
https://bookdown.org/yihui/rmarkdown-cookbook/working-directory.html#working-directory
I want to set the directory to the parent direcotry of the default directory
usually I would acheive this using  setwd("..") so  in the rmd I used the
following:

```{r setup, include=FALSE,}
print(getwd())
knitr::opts_knit$set(root.dir = '..')
print(getwd())
```
the  print(getwd()) being just to demonstrate the result.  There is no
change in the directory.
How do I change the working directory ?

thanks

nevil Amos

[[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] using aws.s3::s3 sync to dowlaod files from public s3 Bucket without credentials?

2021-03-21 Thread nevil amos
Hi I am developing a package that reives on some large datasets stored in
aws s3.
I have made the bucket and all objects in the bucket public, but still
cannot sync them to my local directory without providing my AWS key pair.
without these credentials I get a "bucket does not exist" message.

Should it be possible to "see" and use
Sys.setenv("AWS_DEFAULT_REGION" =MYDEFAULTREGION)
aws.s3::s3sync (path ="./", bucket=MYBUCKETNAME,check_region = F,direction
= "download")

to download the bucket contents without providing a keypair where both
bucket and contents are public?

thanks

Nevil Amos

[[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] Plot_ly bar plots - bars span sevral x values when there are missing values.

2021-03-18 Thread nevil amos
Hi Rasmus,

thanks for that suggestion. It does indeed fix the column widths in this
example.  the reason it does this is becuase it means that the additonal 0
values added result in values for two adjacent columns.

so if adjacent columns are present the "correct" column width is maintained

df[c(3,4),]%>%plot_ly(
  x =  ~ x,
  y =  ~ y,
  type = "bar")%>%
  layout(xaxis = list(range = c(0,20)),
 title = "adjcant x values get correct column width")
however if there are not tow adjacent columns  then the width increases

df[c(3,5),]%>%plot_ly(
  x =  ~ x,
  y =  ~ y,
  type = "bar")%>%
  layout(xaxis = list(range = c(0,20)),
 title = "gap between x values column width changes")

given this I'm still not sure why the single value example produces a
correct column width.

for now the generic work around is to pad with y=0 as you suggested.




On Wed, 10 Mar 2021 at 05:58, Rasmus Liland  wrote:

> Dear Nevil,
>
> Although I am a bit unfamiliar with
> plotly, it seems it is possible to plot
> two bars side by side at least:
>
> h <- df[3:4,]
> p <- plotly::plot_ly(
>   data = h,
>   x =  ~ x,
>   y =  ~ y,
>   type = "bar")
> p <- plotly::layout(p=p,
>   xaxis = list(range = c(0,20)),
>   title = "example 4 two bars side by side")
> plotly::orca(p=p, file="amos4.png")
>
> Thus, if you want to only plot x=3 and
> x=11 you need to set y=0 when x=4:10:
>
> h <- df[c(3, 11),]
> h <- rbind(h, cbind(x=4:10, y=0))
> p <- plotly::plot_ly(
>   data = h,
>   x =  ~ x,
>   y =  ~ y,
>   type = "bar")
> p <- plotly::layout(p=p,
>   xaxis = list(range = c(0,20)),
>   title = "example 2 corrected")
> plotly::orca(p=p, file="amos2.png")
>
> I think this has to do with the xaxis
> option in plotly::layout there, and not
> with the bar width.
>
> Best,
> Rasmus
>

[[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] Plot_ly bar plots - bars span sevral x values when there are missing values.

2021-03-08 Thread nevil amos
I need to plot a number of bar charts as part of a shiny app.

I am using ploty ly

x and y  values are both numeric x being consecutive integer values.

there are often missing values in the data I wish to plot - each plot needs
to have a fixed x range.

When there are more than a few missing values  the bars for the remaining
values are being plotted much wider spanning several x values ( see example
2)

curiously when there is a single remaining value the bar width is correct
(example 3)

how can I maintain a constant bar width regardless of number of missing
values? I cannot find a bar-width setting.


df<-data.frame(x=1:20,y=rnorm(20)^2)

#twenty bars each centred above a single x value:
df%>%plot_ly(
  x =  ~ x,
  y =  ~ y,
  type = "bar")%>%
  layout(xaxis = list(range = c(0,20)),
 title = "example 1")

# this produces wide bars first one spread x= 0-6 second x= 8-14
# expected two column same width as in example 1 centred above x=3 and x=11
df[c(3,11),]%>%plot_ly(
  x =  ~ x,
  y =  ~ y,
  type = "bar")%>%
  layout(xaxis = list(range = c(0,20)),
 title = "example 2 column width expands across multiple x values")

# when only a single bar is present it is again the correct width - in this
case centred above x=3
df[3,]%>%plot_ly(
  x =  ~ x,
  y =  ~ y,
  type = "bar")%>%
  layout(xaxis = list(range = c(0,20)),
 title = "example 3 correct columns again")

[[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] [R-sig-Geo] raster::levels() not working in packaged function.

2020-10-31 Thread nevil amos
Many thanks,

That worked, since the NAMESPACE file incudes a warning about editing it
directly I ysed the reoygen tag in the fucntion script
#' @import raster.

On Sun, 1 Nov 2020 at 00:18, Marcelino de la Cruz Rot <
marcelino.delac...@urjc.es> wrote:

> Maybe including
>
> import(raster)
>
> or
>
> importFrom("raster", "levels")
>
> in the package NAMESPACE would help.
>
> Cheers,
>
> Marcelino
>
> El 31/10/2020 a las 13:24, nevil amos escribió:
> > Apologies, I cannot see how to make a rero for this issue.
> >
> > I have a function that uses levels(r) tor return the RAT of a raster "r"
> > when the function is sourced from a script
> > source(".\R\function.r")
> > it works fine.
> > when the function is built into a package and sourced from there
> > library(mypackage) using the same script file to make the package
> > levels(r)[[1]]
> > the same line throws an error, as levels(myraster returns NULL
> >
> > If I modify the script to include the raster namespace:
> > raster::levels(r)[[1]]
> > Then I get the error
> >   Error: 'levels<-' is not an exported object from 'namespace:raster'
> >
> >
> > I have also tried just using levels(r) and putting raster as a depends
> > rather than an import in the DESCRIPTION file for the package, this does
> > not solve the error.
> >
> >
> > Any suggestions on how to overcome the problem?
> >
> > many thanks
> >
> > Nevil Amos
> >
> >   [[alternative HTML version deleted]]
> >
> > ___
> > R-sig-Geo mailing list
> > r-sig-...@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> > .
>
>
> --
> Marcelino de la Cruz Rot
> Depto. de Biología y Geología
> Física y Química Inorgánica
> Universidad Rey Juan Carlos
> Móstoles España
>
>

[[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] raster::levels() not working in packaged function.

2020-10-31 Thread nevil amos
Apologies, I cannot see how to make a rero for this issue.

I have a function that uses levels(r) tor return the RAT of a raster "r"
when the function is sourced from a script
source(".\R\function.r")
it works fine.
when the function is built into a package and sourced from there
library(mypackage) using the same script file to make the package
levels(r)[[1]]
the same line throws an error, as levels(myraster returns NULL

If I modify the script to include the raster namespace:
raster::levels(r)[[1]]
Then I get the error
 Error: 'levels<-' is not an exported object from 'namespace:raster'


I have also tried just using levels(r) and putting raster as a depends
rather than an import in the DESCRIPTION file for the package, this does
not solve the error.


Any suggestions on how to overcome the problem?

many thanks

Nevil Amos

[[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] Return filematrix column by column names instead of column index?

2020-09-08 Thread nevil amos
Is there a way to get columns out of a filematrix using the column name
directly in the same way that  you can with a regular matrix?

library(filematrix)
M<-t(matrix(1:3,3,4))
colnames(M)<-c("one","two", "three")
M
#Extract column
M[,1]
M[,"one"]
M[,c(1,3)]
M[,c("one","three")]
FM<-fm.create.from.matrix(filenamebase = "test",mat = M)
FM[,1]
colnames(FM)
#extract by column by name does not work
FM[,"one"]

#workaround using grep
#is there a more direct way of doing this  to retrieve more than one column?
FM[,grep("one",colnames(FM))]

FM[,c(grep("one",colnames(FM)),grep("three",colnames(FM)))]

many thanks for any suggestions

Nevil Amos

[[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] aws.s3::s3sync Error in curl::curl_fetch_disk(url, x$path, handle = handle) : Failed to open file

2020-07-16 Thread nevil amos
I am trying to use aws.s3::s3sync to sync the contents of a bucket to an
aws ec2 instance ( via rstudio server)

my script is as follows I cannot make a repro since that would need to be
run from the instance with my account key and details ( replaced with
xx below).

all files I am trying to sync are under the s3 prefix  FAME_FMR which is
the only top level "directory" in the bucket
Have I missed a setting?
If not any suggestions on this error?

thanks

Nevil Amos



library(aws.s3)
Sys.setenv("AWS_ACCESS_KEY_ID" = "x",
   "AWS_SECRET_ACCESS_KEY" =
"x",
   "AWS_DEFAULT_REGION" = "ap-southeast-2")
myBucket<-"ecological-risk-analysis"
myPath<-"~/ShinyApps"

> bucket_exists(myBucket)[1][1] TRUE> dir.exists(myPath)[1] TRUE

>s3sync(path = myPath ,bucket =myBucket)

 [998] 
"FAME_FMR/HDMS/75m/BinaryThresholded/Satin_Bowerbird_Spp10679_Thresholded_Binary.tif"
 [999] 
"FAME_FMR/HDMS/75m/BinaryThresholded/Satin_Flycatcher_Spp10366_Thresholded_Binary.tif"
[1000] 
"FAME_FMR/HDMS/75m/BinaryThresholded/Scaly_breasted_Lorikeet_Spp10256_Thresholded_Binary.tif"
 [ reached getOption("max.print") -- omitted 191 entries ]1191 bucket
objects not found in local directory<== Saving object 'FAME_FMR/' to
'~/ShinyApps/FAME_FMR/'Error in curl::curl_fetch_disk(url, x$path,
handle = handle) :
  Failed to open file /home/rstudio/ShinyApps/FAME_FMR/.

[[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] disk.frame change default directory that disk.frames are saved in?

2020-04-02 Thread nevil amos
I would like to change the default  directory within which all disk frames
are saved  to a directory on an SSD, which is not the drive there the r
tempdir is located. for example instead of saving all disk.frames in
tempdir the are all saved in ./media/SSDdrive/DF?


Thanks

[[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] repeat rows of matrix by number (k) in one colummatrix adding column j with values 1:k

2020-03-31 Thread nevil amos
OK sorted - hope these postings might help someone else

Any even faster options would be appreciated still

#seq() does not work but  sequence() does
print("rep and sequence")
print(system.time({
  j<-NULL
  MOut<-NULL
  MOut<-M[rep(1:nrow(M), times = M[,4]), ]
  j<-sequence(M[,4])
  MOut<-cbind(MOut,j)
  colnames(Mout)<-c("x","y","z","j")
}))

On Wed, 1 Apr 2020 at 13:42, nevil amos  wrote:

> Well,
> I found a way to do it partly using rep(), and one loop that makes it 10x
> or more faster however would still be good to do without the loop at all
> matrix made slightly beigger (1 rows):
>
> M<-matrix(c(1:3
> ), 1,3)
> M<-cbind(M,sample(1:5,size = 1,replace = T))
> #Print(M)
> #Create matrix (Mout) in this case 8 rows with x,y,z in each row of M
> #repeated k times with column j numbered from 1:k
> # ! can do with nested loops but this is very slow ( example below)
> #How do I acheive this quickly without loops?
> print("double loop")
> print(system.time({
> Mout<-NULL
>
> for(i in 1:nrow(M)){
>   a=M[i,1:3]
>   k=M[i,4]
>   for (j in 1:k){
> b=c(a,j)
> Mout<-rbind(Mout,b)
> }
> }
> colnames(Mout)<-c("x","y","z","j")
> }))
>
> print("rep and single loop")
> print(system.time({
>   j<-NULL
>   MOut<-NULL
>   MOut<-M[,1:3][rep(1:nrow(M), times = M[,4]), ]
>   for(i in M[,4])(j<-c(j,1:i))
>   MOut<-cbind(MOut,j)
>   colnames(Mout)<-c("x","y","z","j")
> }))
>
> On Wed, 1 Apr 2020 at 12:18, nevil amos  wrote:
>
>> Hi
>>
>> I can achieve this using two for loops but it is slow  I need to do this
>> on many matrices with tens of millions of rows of x,y,z and k
>>
>> What is a faster method to achieve this, I cannot use rep as j changes in
>> each row of the new matrix
>> ###
>> M<-matrix(c(1,2,3,4,1,2,3,4,1,2,3,4, 2, 1, 3, 2
>> ), 4,4, dimnames = list(NULL, c("x", "y", "z","k")))
>>
>> Print(M)
>> #Create matrix (Mout) in this case 8 rows with x,y,z in each row of M
>> #repeated k times with column j numbered from 1:k
>> # ! can do with nested loops but this is very slow ( example below)
>> #How do I acheive this quickly without loops?
>> Mout<-NULL
>>
>> for(i in 1:nrow(M)){
>>   a=M[i,c("x","y","z")]
>>   for (j in 1:M[i,"k"]){
>> b=c(a,j)
>> Mout<-rbind(Mout,b)
>> }
>> }
>> colnames(Mout)[4]<-"j"
>> print(Mout)
>>
>> #
>>
>> Thanks
>>
>> Nevil Amos
>>
>

[[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] repeat rows of matrix by number (k) in one colummatrix adding column j with values 1:k

2020-03-31 Thread nevil amos
Well,
I found a way to do it partly using rep(), and one loop that makes it 10x
or more faster however would still be good to do without the loop at all
matrix made slightly beigger (1 rows):

M<-matrix(c(1:3
), 1,3)
M<-cbind(M,sample(1:5,size = 1,replace = T))
#Print(M)
#Create matrix (Mout) in this case 8 rows with x,y,z in each row of M
#repeated k times with column j numbered from 1:k
# ! can do with nested loops but this is very slow ( example below)
#How do I acheive this quickly without loops?
print("double loop")
print(system.time({
Mout<-NULL

for(i in 1:nrow(M)){
  a=M[i,1:3]
  k=M[i,4]
  for (j in 1:k){
b=c(a,j)
Mout<-rbind(Mout,b)
}
}
colnames(Mout)<-c("x","y","z","j")
}))

print("rep and single loop")
print(system.time({
  j<-NULL
  MOut<-NULL
  MOut<-M[,1:3][rep(1:nrow(M), times = M[,4]), ]
  for(i in M[,4])(j<-c(j,1:i))
  MOut<-cbind(MOut,j)
  colnames(Mout)<-c("x","y","z","j")
}))

On Wed, 1 Apr 2020 at 12:18, nevil amos  wrote:

> Hi
>
> I can achieve this using two for loops but it is slow  I need to do this
> on many matrices with tens of millions of rows of x,y,z and k
>
> What is a faster method to achieve this, I cannot use rep as j changes in
> each row of the new matrix
> ###
> M<-matrix(c(1,2,3,4,1,2,3,4,1,2,3,4, 2, 1, 3, 2
> ), 4,4, dimnames = list(NULL, c("x", "y", "z","k")))
>
> Print(M)
> #Create matrix (Mout) in this case 8 rows with x,y,z in each row of M
> #repeated k times with column j numbered from 1:k
> # ! can do with nested loops but this is very slow ( example below)
> #How do I acheive this quickly without loops?
> Mout<-NULL
>
> for(i in 1:nrow(M)){
>   a=M[i,c("x","y","z")]
>   for (j in 1:M[i,"k"]){
> b=c(a,j)
> Mout<-rbind(Mout,b)
> }
> }
> colnames(Mout)[4]<-"j"
> print(Mout)
>
> #
>
> Thanks
>
> Nevil Amos
>

[[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] repeat rows of matrix by number (k) in one colummatrix adding column j with values 1:k

2020-03-31 Thread nevil amos
Hi

I can achieve this using two for loops but it is slow  I need to do this on
many matrices with tens of millions of rows of x,y,z and k

What is a faster method to achieve this, I cannot use rep as j changes in
each row of the new matrix
###
M<-matrix(c(1,2,3,4,1,2,3,4,1,2,3,4, 2, 1, 3, 2
), 4,4, dimnames = list(NULL, c("x", "y", "z","k")))

Print(M)
#Create matrix (Mout) in this case 8 rows with x,y,z in each row of M
#repeated k times with column j numbered from 1:k
# ! can do with nested loops but this is very slow ( example below)
#How do I acheive this quickly without loops?
Mout<-NULL

for(i in 1:nrow(M)){
  a=M[i,c("x","y","z")]
  for (j in 1:M[i,"k"]){
b=c(a,j)
Mout<-rbind(Mout,b)
}
}
colnames(Mout)[4]<-"j"
print(Mout)

#

Thanks

Nevil Amos

[[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] Cannot view custom tiles made in package tiler in r leaflet - either locally or from github pages server.

2020-02-05 Thread nevil amos
I wish to create tiled version of a large number of custom rasters for
viewing in shiny/leaflet apps ( to speed viewing of rasters)

I have produced tiles using  package tiler, these can be viewed in the
preview.html, but when uploaded to github pages  as described in the
introduction to tiler they do not show up when added as tiles in leaflet.

It is difficult to make a reproducible code here - since the tiles have to
be loaded to be served from the web.

However below I include the code used 1. to produce the tiles and 2, to
view the tiles in my github pages.

I have tried the suggestion of using {-y} in the sever path for TMS, this
makes no difference the background map is displayed but the custom tiles
are not.

Raster used from the package as an example in reality I need to serve many
1x6000 cell geotiffs.

Example code:

library(tiler)
libary(leaflet)
# make tiles in zoom levels 1:6 these tiles have then been uploaded to
github to serve from repository:
#

tile_dir<-"us48lr"
map <- system.file("maps/map_wgs84.tif", package = "tiler")
tile(map,tile_dir , "0-6")
view_tiles(tile_dir)


#no TMS related modifications
tiles <- "https://nevilamos.github.io/TileTest/us48lr/{z}/{x}/{y}.png;
leaflet(
  options = leafletOptions(minZoom = 0, maxZoom = 7), width = "100%") %>%
  addProviderTiles("Stamen.Toner") %>%
  addTiles(urlTemplate=tiles, options = tileOptions(opacity = 0.8)) %>%
setView(-100, 40, 3)

#No tiles displayed


# {-y} and tileOptions(tms=T)
tiles <- "https://nevilamos.github.io/TileTest/us48lr/{z}/{x}/{-y}.png;
leaflet(
  options = leafletOptions(minZoom = 0, maxZoom = 7), width = "100%") %>%
  addProviderTiles("Stamen.Toner") %>%
  addTiles(urlTemplate=tiles, options = tileOptions(opacity = 0.8,tms=T))
%>% setView(-100, 40, 3)

#No tiles displayed

[[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] reg expr that retains only bracketed text from strings

2019-06-11 Thread nevil amos
Hi

I am trying to extract only the text contained in brackets from a vector of
strings
not all of the strings contain closed bracketed text, they should return an
empty string or NA

this is what I have at the moment


mystrings<-c("ABC","A(B)C","AB(C)")

substring(mystrings, regexpr("\\(|\\)", mystrings))


#this returns the whole string  if there are no brackets.
[1] "ABC"  "(B)C" "(C)"


# my desired desired output:
#[1]  ""  "(B)" "(C)"

many thanks for any suggestions
Nevil Amos

[[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] profvis function parse_rprof not being loaded

2019-02-27 Thread nevil amos
I have loaded the profvis library  but the function parse_ rprof()  is
absent.
below is the session info show the absence of the function ( which is
listed  in the package help for the current version.)


Documentation for package ‘profvis’ version 0.3.5

DESCRIPTION file.
Help Pages

parse_rprof Parse Rprof output file for use with profvis
pause Pause an R process
print.profvis Print a profvis object
profvis Profile an R expression and visualize profiling data
profvisOutput Widget output function for use in Shiny
renderProfvis Widget render function for use in Shiny


Rsession info:


> library(profvis)
> parse_rprof()
Error in parse_rprof() : could not find function "parse_rprof"
> ls("package:profvis")
[1] "pause" "profvis"   "profvisOutput" "renderProfvis"
> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252
LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C   LC_TIME=English_Australia.1252

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

other attached packages:
[1] profvis_0.3.5

loaded via a namespace (and not attached):
 [1] htmlwidgets_1.3 compiler_3.5.2  magrittr_1.5htmltools_0.3.6
tools_3.5.2 yaml_2.2.0  Rcpp_1.0.0  stringi_1.2.4
 [9] stringr_1.3.1   digest_0.6.18

[[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] Mapedit::selectMap in shiny map.

2018-02-22 Thread nevil amos
I would like to select polygons from an existing spatial polygon data set
interactively in a shiny leaflet map.
The process is straightforward in leaflet/ mapedit, however I need to
include the procedure in a shiny app map interface. I cannot work out how
to incorporate the selectMap() in the shiny app. An error is returned:

Here is some toy code showing the code in using leaflet locally:

library(mapedit)
library(leaflet)
options(stringsAsFactors = F)
bounds <- c(5.956063, 10.49511, 45.81706, 47.80848 )

lf <- leaflet() %>%
addTiles()%>%
addPolygons(data =gadmCHE,
label = ~NAME_1,
layerId = ~NAME_1)

selected <-selectMap(lf)

##the above works fine and returns a dataframe giving the ids of the
selected polygons.

##however the code below - trying to implement in shiny fails with "Can’t
call runApp() from within runApp(). If your application code contains
runApp(), please remove it.

library(shiny)
library(leaflet)
library(mapedit)

ui <- fluidPage(
leafletOutput(“mymap”)
)

server <- function(input, output, session) {

lf<-leaflet() %>%
addTiles()%>%
addPolygons(data =gadmCHE,
label = ~NAME_1,
layerId = ~NAME_1)
output$mymap <- renderLeaflet({selectMap(lf)
})
}
shinyApp(ui, server)

##How do I achieve the same in a shiny map?

[[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] Identifying attributes of specific foreach task on error.

2015-11-10 Thread nevil amos
I am running foreach to reclassify a large number of rasters.

I am getting the Error in { : task 1359 failed - "cannot open the
connection"

How do I get the attributes ( in this case files being read and written)
for that specific task?


It runs fine until that point presumably there is a problem with the input
or output file name, but I cannot determine which file it refers to.

cheers

Nevil Amos

[[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] clusterR (fun=aggregate) error number of items to replace is not a multiple of replacement length

2015-04-20 Thread nevil amos
I am getting the above  error with clusterR and aggregate:

works fine without parralell:

library(raster)
r-raster(matrix(data = sample(c(1:10,NA),1,replace=T),100,100),xmn=0,
xmx=1000,ymn=0,ymx=1000)
beginCluster()
Parr_agg-clusterR(r,fun=aggregate,args=list(fact=3,fun=modal,expand=TRUE,na.rm=TRUE))
endCluster()
agg-aggregate(r,3,fun=modal,na.rm=TRUE)
plot(agg)

[[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] clusterR (fun=aggregate) error number of items to replace is not a multiple of replacement length

2015-04-20 Thread nevil amos
Apoligies.  did not read help properly it states:
Among other functions, it does _not_ work with ... (dis)aggregate

On Mon, Apr 20, 2015 at 4:54 PM, nevil amos nevil.a...@gmail.com wrote:

 I am getting the above  error with clusterR and aggregate:

 works fine without parralell:

 library(raster)
 r-raster(matrix(data = sample(c(1:10,NA),1,replace=T),100,100),xmn=0,
 xmx=1000,ymn=0,ymx=1000)
 beginCluster()

 Parr_agg-clusterR(r,fun=aggregate,args=list(fact=3,fun=modal,expand=TRUE,na.rm=TRUE))
 endCluster()
 agg-aggregate(r,3,fun=modal,na.rm=TRUE)
 plot(agg)


[[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] How to run sequential Rscript command for windows command line with a batch file.

2015-01-29 Thread nevil amos
Hi,

I need to run multiple iterations of a script to which I am supplying a
single numeric argument


I can open the command prompt window  and enter a single command:
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 18
and it runs OK and saves the outputs.
Similarly if I run the same single command from a batch file  it works fine

however If I have  multiple lines in the batch file  eg:

C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 18
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 19
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 20
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 22
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 23
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 24
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 25
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 26
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 27
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 28
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 29
C:\Program Files\R\R-3.1.0\bin\x64\Rscript.exe myScript.R.R 30
it pauses after running the first line only.

How do I get all lines in this batch file to run sequentially?

thanks

[[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] Return TRUE only for first match of values between matrix and vector.

2014-05-02 Thread nevil amos
I wish to return  True in a matrix for only the first match of a value
per row where the value equals that in a vector with the same number of
values as rosw in the matrix

eg:
A-matrix(c(2,3,2,1,1,2,NA,NA,NA,5,1,0,5,5,5),5,3)
B-c(2,1,NA,1,5)
desired result:

  [,1] [,2]  [,3]
[1,]  TRUE FALSE FALSE
[2,] FALSE   NA FALSE
[3,]NA   NANA
[4,]  TRUE   NA FALSE
[5,] FALSE TRUE  FALSE

however A==B returns:
  [,1] [,2]  [,3]
[1,]  TRUE TRUE FALSE
[2,] FALSE   NA FALSE
[3,]NA   NANA
[4,]  TRUE   NA FALSE
[5,] FALSE TRUE  TRUE
and
apply(A,1,function(x) match (B,x))
returns
 [,1] [,2] [,3] [,4] [,5]
[1,]1   NA1   NA   NA
[2,]3   NA   NA11
[3,]   NA222   NA
[4,]3   NA   NA11
[5,]   NA   NA332

thanks

[[alternative HTML version deleted]]

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


Re: [R] return the name of source.

2013-08-27 Thread nevil amos
Thanks

this does it:

script.name - basename(sys.frame(1)$ofile)



On Tue, Aug 27, 2013 at 4:07 PM, Henrik Bengtsson h...@biostat.ucsf.eduwrote:

 See findSourceTraceback() of R.utils.  /Henrik

 On Mon, Aug 26, 2013 at 10:58 PM, peter dalgaard pda...@gmail.com wrote:
 
  On Aug 27, 2013, at 07:12 , nevil amos wrote:
 
  Is there a fuction that will allow me to retrun the filename for  a
 script
  from within that script.
 
  Not a standard one, but you should be able to get at it via a bit of
 breaking and entering: sys.status() and friends (sys.calls, sys.frames)
 give you access to the evaluation frame of source() which contains a
 variable called file.
 
  -pd
 
 
  fir instance
 
  If I have a script myscript.r:
 
  FileName-unknown.fucntion()
  print(FileName)
 
 
 
  and run it
  source(myscript.r)
 
  will return
  myscript.r
 
  Thanks
 
  Nevil Amos
 
[[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
  --
  Peter Dalgaard, Professor,
  Center for Statistics, Copenhagen Business School
  Solbjerg Plads 3, 2000 Frederiksberg, Denmark
  Phone: (+45)38153501
  Email: pd@cbs.dk  Priv: pda...@gmail.com
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

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


[R] return the name of source.

2013-08-26 Thread nevil amos
Is there a fuction that will allow me to retrun the filename for  a script
 from within that script.

fir instance

If I have a script myscript.r:

FileName-unknown.fucntion()
print(FileName)



and run it
source(myscript.r)

will return
myscript.r

Thanks

Nevil Amos

[[alternative HTML version deleted]]

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


[R] return output to console for copying as input

2013-06-25 Thread nevil amos
I want to print a vector of strings to the console formatted as if it were
input

X-c(a,b,c)
 X
[1] a b c

what I would like to get is

the.function(X)
a,b,c

what is the function?

cheers

Nevil amos

[[alternative HTML version deleted]]

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


[R] Problem i9ncreasing memory to jvm for XLConnect

2013-06-11 Thread nevil amos
I am using some r scripts to reformat a large data set that needs to be
saved into xls format.

I am getting   the  “Out of Memory Error (Java)” despite having set a large
memory in the first line of the script ( on opening R and before loading
any libraries)

I am using R version 2.15.2 (2012-10-26) -- Trick or Treat
Platform: x86_64-w64-mingw32/x64 (64-bit)

On 64 Bit window 7 machine with 12G of ram.

When I run the script to increase memory for jvm it is not increasing the
memory but remaining at 244MB ( presumably the remainder of the initial
256mb once JVM is loaded...

the script and out put is as follows

 rm(list = ls())
 options(java.parameters = -Xmx4096m,stringsAsFactors=F)
 library(XLConnect)
Loading required package: XLConnectJars
Loading required package: rJava
XLConnect 0.2-3 by Mirai Solutions GmbH
http://www.mirai-solutions.com ,
http://miraisolutions.wordpress.com
 print(xlcMemoryReport())
Amount of free memory in the Java Virtual Machine (JVM):  244.0936 MB


How do I increase the memory?

thanks

[[alternative HTML version deleted]]

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


Re: [R] Problem i9ncreasing memory to jvm for XLConnect

2013-06-11 Thread nevil amos
Thanks for those suggestions.

There was no previous part of the session .  I opened r then ran the script
as seen.  In this case the

 rm(list = ls())


was superfluous - I just tend to have it at the beginning of scripts
to remove any rubbish if I have run previous stuff in the session.


It would be nice if the xlcFreeMemory()  gave the maximum available.



On Tue, Jun 11, 2013 at 11:02 PM, Anthony Damico ajdam...@gmail.com wrote:

 the

  rm(list = ls())

 at the top of your snippet makes me wonder if you had loaded any packages
 (like XLConnect) that use Java in a previous part of the session?  i
 believe you must designate the ram allocation for java prior to loading any
 java-related packages, and clearing out your objects will not act as a
 reset..


 i'm also not sure if the memory report shows what's currently allocated or
 the actual maximum..  i've had success with increasing the allocation on
 windows in the past, even though the initial memory report said only
 ~120mb.  be sure to execute the xlcFreeMemory() command after any big
 runs-- it's the java-equivalent of gc()


 also you should be able to use
 options( java.parameters = -Xmx4g )
 unless you love multiplying by 1024  :)





 On Tue, Jun 11, 2013 at 3:21 AM, nevil amos nevil.a...@gmail.com wrote:

 I am using some r scripts to reformat a large data set that needs to be
 saved into xls format.

 I am getting   the  “Out of Memory Error (Java)” despite having set a
 large
 memory in the first line of the script ( on opening R and before loading
 any libraries)

 I am using R version 2.15.2 (2012-10-26) -- Trick or Treat
 Platform: x86_64-w64-mingw32/x64 (64-bit)

 On 64 Bit window 7 machine with 12G of ram.

 When I run the script to increase memory for jvm it is not increasing the
 memory but remaining at 244MB ( presumably the remainder of the initial
 256mb once JVM is loaded...

 the script and out put is as follows

  rm(list = ls())
  options(java.parameters = -Xmx4096m,stringsAsFactors=F)
  library(XLConnect)
 Loading required package: XLConnectJars
 Loading required package: rJava
 XLConnect 0.2-3 by Mirai Solutions GmbH
 http://www.mirai-solutions.com ,
 http://miraisolutions.wordpress.com
  print(xlcMemoryReport())
 Amount of free memory in the Java Virtual Machine (JVM):  244.0936 MB


 How do I increase the memory?

 thanks

 [[alternative HTML version deleted]]


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




[[alternative HTML version deleted]]

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


[R] merge without NA last

2013-05-31 Thread nevil amos
I am trying to create a merge where the first value contains NA values.  I
wish to retain these in order.  however when I use all.x=T and sort=F they
are retained but na values are placed last:

 X-data.frame(k1=c(A,NA,C,B))
 print (X)
k1
1A
2 NA
3C
4B
 Y-data.frame(k2=c(1,2,3),k3=c(A,B,C))
 Z-merge(X,Y, by.x=1,by.y=2,all.x=T,sort=F)
 print (Z)
k1 k2
1A  1
2C  3
3B  2
4 NA NA


The result I need is
k1  k2
1A  1
2 NA NA
3C 3
4B 2

how do I prevent NA c=values being sorted to last - I need to retain values
in position.

thanks

Nevil Amos

[[alternative HTML version deleted]]

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


[R] Default for boot in mantel{ecodist} was Re: Size of subsample in ecodist mantel()

2012-07-01 Thread Nevil Amos
How do I use pboot to set the level of resampling (size of each resample) in 
mantel()?

if I enter a value for pboot then the ulim==llim

 X-dist(1:100)
 Y-dist(1:100+50*rnorm(100))
 length(X)
[1] 4950
 print(mantel(X~Y,nperm=1000,nboot=1000,pboot=10))
   mantelr  pval1  pval2  pval3  llim.2.5% ulim.97.5% 
 0.1396906  0.001  1.000  0.001  0.1396906  0.1396906 


if I do not set a value for pboot then
 as expected ulimllim


 print(mantel(X~Y,nperm=1000,nboot=1000))
   mantelr  pval1  pval2  pval3  llim.2.5% ulim.97.5% 
 0.1396906  0.001  1.000  0.001  0.1005011  0.1805416 

many thanks

Nevil Amos


[[alternative HTML version deleted]]

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


Re: [R] Size of subsample in ecodist mantel()

2012-06-29 Thread nevil amos
Thanks Sarah,

It is not clear to me exactly how I set this value. if I enter a value for
pboot then the ulim==llim

 X-dist(1:100) Y-dist(1:100+50*rnorm(100)) length(X)[1] 4950 
 print(mantel(X~Y,nperm=1000,nboot=1000,pboot=10))   mantelr  pval1  
 pval2  pval3  llim.2.5% ulim.97.5%
 0.1396906  0.001  1.000  0.001  0.1396906  0.1396906



if I do not set a value for pboot then
 as expected ulimllim

 print(mantel(X~Y,nperm=1000,nboot=1000))   mantelr  pval1  pval2  
 pval3  llim.2.5% ulim.97.5%
 0.1396906  0.001  1.000  0.001  0.1005011  0.1805416



What is the default for pboot?

this does not appear to be dealt with in  help for mantel



On Thu, Jun 28, 2012 at 8:35 PM, Sarah Goslee sarah.gos...@gmail.comwrote:

 You can set it using the pboot argument.

 Sarah


 On Thursday, June 28, 2012, nevil amos wrote:

 What is the size of the boostrapped subsample in  ecodist mantel()

 thanks

[[alternative HTML version deleted]]

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



 --
 Sarah Goslee
 http://www.stringpage.com
 http://www.sarahgoslee.com
 http://www.functionaldiversity.org


[[alternative HTML version deleted]]

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


[R] Size of subsample in ecodist mantel()

2012-06-28 Thread nevil amos
What is the size of the boostrapped subsample in  ecodist mantel()

thanks

[[alternative HTML version deleted]]

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


[R] VEGAN ordistep, stepwise model selection in CCA - familywise error correction.

2012-06-10 Thread Nevil Amos
I am using VEGAN ordistep function for stepwise model selection.  By
default the Pin and Pout values are set to .05 and .1

Is it appropriate to use a family wise correction ( such as bonferroni or
one of the alternatives) to adjust these values where there  are several
 (5-10), potentially correlated variables in the model selection process?

-- 
Nevil Amos
Molecular Ecology Research Group
Australian Centre for Biodiversity
Monash University
CLAYTON VIC 3800
Australia

[[alternative HTML version deleted]]

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


Re: [R] removing only rows/columns with na value from square ( symmetrical ) matrix.

2012-05-21 Thread Nevil Amos
Yes  the matrix is symmetric 
Gabor provided a partial solution:
Try this:

ix - na.action(na.omit(replace(M, upper.tri(M), 0)))
M[-ix, -ix]

However this removes all rows containing an NA in the lower half of the matrix 
- even if the corresponding column has also been removed

I I have revised the example to show this.

thanks all for you help

in the below case I would like to retain row and column 
[c(1:5,7,8,10:12),c(1:5,7,8,10:12)]
M-matrix(sample(144),12,12)
M[10,9]-NA
M-as.matrix(as.dist(M))
N=M
#the above rows are to create the symmetric matrix M and a copy N
M[6,]-NA
M[,6]-NA
#above two rows - make corresponding row and column NA
print (M)
ix - na.action(na.omit(replace(M, upper.tri(M), 0)))
M-M[-ix, -ix]
print (M)

print (however what I would like to retain is the maximum amout of data while 
removing rows or columns containing NA  ie:)
print(N [c(1:5,7,8,10:12),c(1:5,7,8,10:12)])

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

thanks to all
On 21/05/2012, at 1:10 AM, peter dalgaard wrote:

 
 On May 20, 2012, at 16:37 , Bert Gunter wrote:
 
 Your problem is not well-defined. In your example below, why not
 remove rows 1,2,6, and 10, all of which contain NA's? Is the matrix
 supposed to be symmetric?
YES

 Do NA's always occur symmetrically?
YES
 
 ...and even if they do, how do you decide whether to remove row/col 9 or 
 row/col 10 in the example? (Or, for that matter, between (1 and 2) and 6. In 
 that case you might chose to remove the smallest no. of row/cols but in 9 
 vs. 10, the situation is completely symmetric.) 
 
 
 You either need to rethink what you want to do or clarify your statement of 
 it.
 
 -- Bert
 
 On Sun, May 20, 2012 at 7:17 AM, Nevil Amos nevil.a...@monash.edu wrote:
 I have some square matrices with na values in corresponding rows and
 columns.
 
 M-matrix(1:2,10,10)
 M[6,1:2]-NA
 M[10,9]-NA
 M-as.matrix(as.dist(M))
 print (M)
 
   1 2 3 4 5 6 7 8 9 10
 1   0  2 1 2 1 NA 1 2  1  2
 2   2  0 1 2 1 NA 1 2  1  2
 3   1  1 0 2 1  2 1 2  1  2
 4   2  2 2 0 1  2 1 2  1  2
 5   1  1 1 1 0  2 1 2  1  2
 6  NA NA 2 2 2  0 1 2  1  2
 7   1  1 1 1 1  1 0 2  1  2
 8   2  2 2 2 2  2 2 0  1  2
 9   1  1 1 1 1  1 1 1  0 NA
 10  2  2 2 2 2  2 2 2 NA  0
 
 
 How do I remove just the row/column pair( in this trivial example row 6 and
 10 and column 6 and 10) containing the NA values?
 
 so that I end up with all rows/ columns that are not NA - e.g.
 
 1 2 3 4 5 7 8 9
 1 0 2 1 2 1 1 2 1
 2 2 0 1 2 1 1 2 1
 3 1 1 0 2 1 1 2 1
 4 2 2 2 0 1 1 2 1
 5 1 1 1 1 0 1 2 1
 7 1 1 1 1 1 0 2 1
 8 2 2 2 2 2 2 0 1
 9 1 1 1 1 1 1 1 0
 
 
 if i use na omit I lose rows 1,2,6, and 9
 which is not what I want.
 
 thanks
 --
 Nevil Amos
 Molecular Ecology Research Group
 Australian Centre for Biodiversity
 Monash University
 CLAYTON VIC 3800
 Australia
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 
 -- 
 
 Bert Gunter
 Genentech Nonclinical Biostatistics
 
 Internal Contact Info:
 Phone: 467-7374
 Website:
 http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 -- 
 Peter Dalgaard, Professor,
 Center for Statistics, Copenhagen Business School
 Solbjerg Plads 3, 2000 Frederiksberg, Denmark
 Phone: (+45)38153501
 Email: pd@cbs.dk  Priv: pda...@gmail.com
 
 
 
 
 
 
 
 


[[alternative HTML version deleted]]

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


[R] removeing only rows/columns with na value from square ( symmetrical ) matrix.

2012-05-20 Thread Nevil Amos
I have some square matrices with na values in corresponding rows and
columns.

M-matrix(1:2,10,10)
M[6,1:2]-NA
M[10,9]-NA
M-as.matrix(as.dist(M))
print (M)

1  2 3 4 5  6 7 8  9 10
1   0  2 1 2 1 NA 1 2  1  2
2   2  0 1 2 1 NA 1 2  1  2
3   1  1 0 2 1  2 1 2  1  2
4   2  2 2 0 1  2 1 2  1  2
5   1  1 1 1 0  2 1 2  1  2
6  NA NA 2 2 2  0 1 2  1  2
7   1  1 1 1 1  1 0 2  1  2
8   2  2 2 2 2  2 2 0  1  2
9   1  1 1 1 1  1 1 1  0 NA
10  2  2 2 2 2  2 2 2 NA  0


How do I remove just the row/column pair( in this trivial example row 6 and
10 and column 6 and 10) containing the NA values?

so that I end up with all rows/ columns that are not NA - e.g.

  1 2 3 4 5 7 8 9
1 0 2 1 2 1 1 2 1
2 2 0 1 2 1 1 2 1
3 1 1 0 2 1 1 2 1
4 2 2 2 0 1 1 2 1
5 1 1 1 1 0 1 2 1
7 1 1 1 1 1 0 2 1
8 2 2 2 2 2 2 0 1
9 1 1 1 1 1 1 1 0


if i use na omit I lose rows 1,2,6, and 9
which is not what I want.

thanks
-- 
Nevil Amos
Molecular Ecology Research Group
Australian Centre for Biodiversity
Monash University
CLAYTON VIC 3800
Australia

[[alternative HTML version deleted]]

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


[R] How to remove $ (Dollar sign) from string

2012-04-10 Thread Nevil Amos
How do I remove a $ character from a string sub() and gsub() with $ or
\$ as pattern do not work.
 sub($,,ABC$DEF)
[1] ABC$DEF
 sub(\$,,ABC$DEF)
Error: '\$' is an unrecognized escape in character string starting \$
 sub(\$,,ABC$DEF)
Error: unexpected input in sub(\

Thanks
-- 
Nevil Amos
Molecular Ecology Research Group
Australian Centre for Biodiversity
Monash University
CLAYTON VIC 3800
Australia

[[alternative HTML version deleted]]

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


[R] Extracting part of anova.cca()

2012-01-23 Thread Nevil Amos
I have an anova.cca() output.

If it is possible I would like to extract the table it contains as a data frame 
ie
  myAnova
 Permutation test for rda under reduced model
 Terms added sequentially (first to last)
 
 Model: rda(formula = mygenind@tab ~ mds3dCS_NULL + mds3dTRE_25_2_CS25 + 
 mydata$LAT.x + mydata$LONG.x + mydata$Hab_Config + mds3dTRE_25_100_CS25 + 
 mydata$TreeCov + mydata$Site_No + mds3dSFW_EO_100_CS25 + 
 mds3dSFW_EO_5000_CS25 + mydata$Landscape + mds3dSFW_TH_10_CS25, scale = T, 
 na.action = na.omit)
Df Var  F N.Perm Pr(F)   
 mds3dCS_NULL3   6.527 2.6380 99   0.01 **
 mds3dTRE_25_2_CS25  3   5.596 2.2616 99   0.01 **
 mydata$LAT.x1   1.892 2.2939 99   0.01 **
 mydata$LONG.x   1   1.891 2.2929 99   0.01 **
 mydata$Hab_Config   2   2.772 1.6807 99   0.01 **
 mds3dTRE_25_100_CS253   3.952 1.5970 99   0.01 **
 mydata$TreeCov  1   1.272 1.5418 99   0.01 **
 mydata$Site_No  1   1.345 1.6306 99   0.01 **
 mds3dSFW_EO_100_CS253   3.741 1.5120 99   0.01 **
 mds3dSFW_EO_5000_CS25   3   3.410 1.3783 99   0.01 **
 mydata$Landscape8   9.300 1.4094 99   0.01 **
 mds3dSFW_TH_10_CS25 3   3.658 1.4785 99   0.01 **
 Residual  139 114.644
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
  




I would like to extract as a table:
  
Df Var  F N.Perm Pr(F)   
 mds3dCS_NULL3   6.527 2.6380 99   0.01 **
 mds3dTRE_25_2_CS25  3   5.596 2.2616 99   0.01 **
 mydata$LAT.x1   1.892 2.2939 99   0.01 **
 mydata$LONG.x   1   1.891 2.2929 99   0.01 **
 mydata$Hab_Config   2   2.772 1.6807 99   0.01 **
 mds3dTRE_25_100_CS253   3.952 1.5970 99   0.01 **
 mydata$TreeCov  1   1.272 1.5418 99   0.01 **
 mydata$Site_No  1   1.345 1.6306 99   0.01 **
 mds3dSFW_EO_100_CS253   3.741 1.5120 99   0.01 **
 mds3dSFW_EO_5000_CS25   3   3.410 1.3783 99   0.01 **
 mydata$Landscape8   9.300 1.4094 99   0.01 **
 mds3dSFW_TH_10_CS25 3   3.658 1.4785 99   0.01 **
 Residual  139 114.644
  

Is this possible? what is the syntax?

I have looked at str(myAnova) but cannot see how to get the table with variable 
names included 

Many thanks
Nevil Amos
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Terms with zero variance included in ordistep best model?

2012-01-23 Thread Nevil Amos
Below I have pasted the outputs of an ordistep() on an rda()

I noticed in the final fitting of the ordistep() that two terms 
mydata$TreeCov and mydata$HabConfig were still included but had variance of 
0 and therefore P was not calculated.

Why are they still included in the final model?  

thanks

Nevil Amos


 myOrdistepBoth
Call: rda(formula = mygenind@tab ~ mds3dCS_NULL + mds3dTRE_25_2_CS25 + 
mydata$LAT.x + mydata$Hab_Config + mds3dTRE_25_100_CS25 + mydata$TreeCov +
mydata$Site_No + mds3dSFW_EO_100_CS25 + mds3dSFW_EO_5000_CS25 + 
mydata$Landscape + mds3dSFW_TH_10_CS25 + mydata$LONG.x, scale = T, na.action = 
na.omit)

   Inertia Proportion Rank
Total 160. 1. 
Constrained45.3560 0.2835   32
Unconstrained 114.6440 0.7165  139
Inertia is correlations 
Some constraints were aliased because they were collinear (redundant)

Eigenvalues for constrained axes:
  RDA1   RDA2   RDA3   RDA4   RDA5   RDA6   RDA7   RDA8   RDA9  RDA10  RDA11  
RDA12  RDA13  RDA14  RDA15  RDA16  RDA17  RDA18  RDA19  RDA20  RDA21  RDA22  
RDA23  RDA24  RDA25 
3.3489 3.2291 2.8211 2.5129 2.2606 2.1062 2.0834 1.8720 1.7727 1.6680 1.6072 
1.5512 1.5100 1.4314 1.3802 1.2427 1.1497 1.1153 1.0547 1.0287 0.9814 0.9361 
0.9168 0.8851 0.7577 
 RDA26  RDA27  RDA28  RDA29  RDA30  RDA31  RDA32 
0.7150 0.7056 0.6436 0.6098 0.5643 0.4806 0.4140 

Eigenvalues for unconstrained axes:
  PC1   PC2   PC3   PC4   PC5   PC6   PC7   PC8 
3.433 3.098 3.057 2.912 2.866 2.743 2.669 2.586 
(Showed only 8 of all 139 unconstrained eigenvalues)



 anova(myOrdistepBoth,by=term)
Permutation test for rda under reduced model
Terms added sequentially (first to last)

Model: rda(formula = mygenind@tab ~ mds3dCS_NULL + mds3dTRE_25_2_CS25 + 
mydata$LAT.x + mydata$Hab_Config + mds3dTRE_25_100_CS25 + mydata$TreeCov + 
mydata$Site_No + mds3dSFW_EO_100_CS25 + mds3dSFW_EO_5000_CS25 + 
mydata$Landscape + mds3dSFW_TH_10_CS25 + mydata$LONG.x, scale = T, na.action = 
na.omit)
   Df Var  F N.Perm Pr(F)   
mds3dCS_NULL3   6.527 2.6380 99   0.01 **
mds3dTRE_25_2_CS25  3   5.596 2.2616 99   0.01 **
mydata$LAT.x1   1.892 2.2939 99   0.01 **
mydata$Hab_Config   2   2.858 1.7325 99   0.01 **
mds3dTRE_25_100_CS253   4.314 1.7435 99   0.01 **
mydata$TreeCov  1   1.238 1.5008 99   0.01 **
mydata$Site_No  1   1.304 1.5806 99   0.01 **
mds3dSFW_EO_100_CS253   3.834 1.5497 99   0.01 **
mds3dSFW_EO_5000_CS25   3   3.344 1.3515 99   0.01 **
mydata$Landscape8   9.711 1.4717 99   0.01 **
mds3dSFW_TH_10_CS25 3   3.702 1.4961 99   0.01 **
mydata$LONG.x   1   1.037 1.2569 99   0.06 . 
Residual  139 114.644
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 



 anova(myOrdistepBoth,by=margin)
Permutation test for rda under reduced model
Marginal effects of terms

Model: rda(formula = mygenind@tab ~ mds3dCS_NULL + mds3dTRE_25_2_CS25 + 
mydata$LAT.x + mydata$Hab_Config + mds3dTRE_25_100_CS25 + mydata$TreeCov + 
mydata$Site_No + mds3dSFW_EO_100_CS25 + mds3dSFW_EO_5000_CS25 + 
mydata$Landscape + mds3dSFW_TH_10_CS25 + mydata$LONG.x, scale = T, na.action = 
na.omit)
   Df Var  F N.Perm  Pr(F)   
mds3dCS_NULL3   3.519 1.4222199 0.00500 **
mds3dTRE_25_2_CS25  3   3.663 1.4805199 0.00500 **
mydata$LAT.x1   1.185 1.4364199 0.00500 **
mydata$Hab_Config   0   0.000 0.  0   
mds3dTRE_25_100_CS253   3.569 1.4423199 0.00500 **
mydata$TreeCov  0   0.000 0.  0   
mydata$Site_No  1   1.251 1.5170199 0.00500 **
mds3dSFW_EO_100_CS253   3.303 1.3348199 0.00500 **
mds3dSFW_EO_5000_CS25   3   3.395 1.3721199 0.01000 **
mydata$Landscape8   9.573 1.4508199 0.00500 **
mds3dSFW_TH_10_CS25 3   3.658 1.4785199 0.00500 **
mydata$LONG.x   1   1.037 1.2569   1399 0.03571 * 
Residual  139 114.644 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
[[alternative HTML version deleted]]

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


[R] replacing + in string

2012-01-21 Thread Nevil Amos
I am trying to replace + in a string with another character 
I am getting odd results using sub and gsub
 X-one + two
 gsub(+,plus,X)
[1] plusoplusnpluseplus plus+plus plustpluswplusoplus
 sub(+,plus,X)
[1] plusone + two
 X-one ~ two

it seems to work fine with other characters:

 sub(~,plus,X)
[1] one plus two


How do I enable + to be recognised as a normal character?

thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] DEMEtics expected run time for calculating DEST CI

2012-01-19 Thread Nevil Amos
What would be the expected runtime for DEMEtics calculating pairwise 
Dest and CI with 1000 bootstraps for 600 individuals 9 loci in 48 
populations?


I am currently running it on a fairly  fast unix computer and the 
estimated completion time is approximately 6 weeks.  The manual 
suggested that I might expect hours to days.


Have I got a setting wrong somewhere?
D.Jost(filename=spp,object=T,format.table=T)


many thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Vegan(ordistep) error: Error in if (aod[1, 5] = Pin) { : missing value where TRUE/FALSE needed

2012-01-11 Thread Nevil Amos
Whilst the constrained proportion was 0 in the example below I am getting the 
error in cases where this is not so.  See new output pasted below


[1] ORDISTEP RDA1 BOTH WAYS
[1] 

[1] SFW ALL Adult
[1] mds3dSFW_EO_100_CS25  mds3dSFW_EO_5000_CS25 mds3dSFW_TH_10_CS25   
mds3dSFW_TH_2_CS25   
Call: rda(formula = mygenind@tab ~ mds3dTRE_25_100_CS25 + mds3dTRE_25_10_CS25 +
mds3dTRE_25_2_CS25 + mds3dTRE_25_5_CS25 + mydata$TreeCov + mydata$Hab_Config +
mydata$Site_No + mydata$Landscape + mds3dCS_NULL + mydata$LAT.x + 
mydata$LONG.x, na.action
= na.omit)

  Inertia Proportion Rank
Total  4.5099 1. 
Constrained1.2635 0.2802   29
Unconstrained  3.2464 0.7198  142
Inertia is variance 
Some constraints were aliased because they were collinear (redundant)

Eigenvalues for constrained axes:
RDA1 RDA2 RDA3 RDA4 RDA5 RDA6 RDA7 RDA8 
RDA9RDA10RDA11 
0.173325 0.126065 0.093396 0.086910 0.072219 0.063064 0.062034 0.058022 
0.050743 0.045038 0.043567 
   RDA12RDA13RDA14RDA15RDA16RDA17RDA18RDA19
RDA20RDA21RDA22 
0.039200 0.035363 0.033358 0.029372 0.028224 0.025715 0.024484 0.024007 
0.021999 0.020480 0.018853 
   RDA23RDA24RDA25RDA26RDA27RDA28RDA29 
0.017277 0.015510 0.015091 0.012845 0.011089 0.009377 0.006886 

Eigenvalues for unconstrained axes:
   PC1PC2PC3PC4PC5PC6PC7PC8 
0.2037 0.1710 0.1670 0.1450 0.1343 0.1155 0.1120 0.1015 
(Showed only 8 of all 142 unconstrained eigenvalues)

Error in if (aod[1, 5] = Pin) { : missing value where TRUE/FALSE needed
In addition: There were 50 or more warnings (use warnings() to see the first 50)
 
 
 
 traceback()
6: ordistep(myrda0, scope = formula(myrda1), direction = both, 
   Pin = 0.05, Pout = 0.1) at #55
5: eval(expr, envir, enclos) at #55
4: eval(expr, pf) at #55
3: withVisible(eval(expr, pf)) at #55
2: evalVis(expr) at #55
1: capture.output(ordistep(myrda0, scope = formula(myrda1), direction = both, 
   Pin = 0.05, Pout = 0.1)) at #55
Cheers

Nevil Amos

 
 Nevil Amos nevil.amos at monash.edu writes:
 
 
 I am getting the following erro rmessage in ordistep.  I have a number of
 similarly structured datasets using ordistep in a loop, and the message
 only occurs for some of the datasets.
 
 I cannot include a reproducible sample  - the specific datasets where this
 is occur ing are fairly large and there are several pcnm's in the rhs of
 the formula.
 
 Error in if (aod[1, 5] = Pin) { : missing value where TRUE/FALSE needed
 
 Nevil,
 
 It seems to me that the source of the problem appears in this table:
 
 Inertia Proportion Rank
 Total  1.8110 1.
 Conditional0.8681 0.4793   32
 Constrained0. 0.0
 Unconstrained  0.9429 0.5207   29
 Inertia is variance
 Some constraints were aliased because they were collinear (redundant)
 
 
 The key point is that Constrained component is completely alaised (Inertia 
 0,
 Rank 0) and therefore it cannot be analysed in permutation tests. You get the
 same error message with this model:
 
 mod - rda(dune ~  Moisture + Condition(Moisture), dune.env)
 
 and for the same reason. In your case, PCNM's seem to explain everything and
 there is nothing left for other variables, and therefore you cannot analyse 
 them.
 
 Cheers, Jari Oksanen
 
 I can see how to fix this in vegan. All I can do is to handle these cases
 smoothly and with comprehensible error messages, though. They cannot be 
 handled
 with permutation tests since there is nothing to do if Constrained component
 is zeroed.
 
 Cheers, Jari Oksanen

[[alternative HTML version deleted]]

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


[R] Error message in vegan ordistep

2012-01-10 Thread Nevil Amos
I am getting the following erro rmessage in ordistep.  I have a number of 
similarly structured datasets using ordistep in a loop, and the message only 
occurs for some of the datasets.  

I cannot include a reproducible sample  - the specific datasets where this is 
occur ing are fairly large and there are several pcnm's in the rhs of the 
formula.

thanks for any pointers that may allow me to track down the cause of the error.

Nevil Amos

Error in if (aod[1, 5] = Pin) { : missing value where TRUE/FALSE needed
In addition: There were 50 or more warnings (use warnings() to see the first 50)
 traceback()
9: ordistep(myrda0, scope = formula(myrda1), direction = both, 
   Pin = 0.05, Pout = 0.1) at RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
8: eval(expr, envir, enclos) at RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
7: eval(expr, pf) at RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
6: withVisible(eval(expr, pf)) at RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
5: evalVis(expr) at RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
4: capture.output(ordistep(myrda0, scope = formula(myrda1), direction = both, 
   Pin = 0.05, Pout = 0.1)) at RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
3: eval.with.vis(expr, envir, enclos)
2: eval.with.vis(ei, envir)
1: 
source(~/Documents/Dropbox/thesis/CH3/Analysis/RDAPARTIALSexandAgeConnectandGEOGraphy2.R)



 
 print(myrda1)
Call: rda(formula = mygenind@tab ~ pcnmTRE_25_100_CS25 + pcnmTRE_25_10_CS25 + 
pcnmTRE_25_2_CS25 +
pcnmTRE_25_5_CS25 + mydata$TreeCov + mydata$Hab_Config + pcnmEYR_EO_100_CS25 +
pcnmEYR_EO_5000_CS25 + pcnmEYR_TH_10_CS25 + pcnmEYR_TH_2_CS25 + mydata$Site_No 
+ mydata$Landscape
+ Condition(pcnmCS_NULL + mydata$LAT.x + mydata$LONG.x), na.action = na.omit)

  Inertia Proportion Rank
Total  1.8110 1. 
Conditional0.8681 0.4793   32
Constrained0. 0.0
Unconstrained  0.9429 0.5207   29
Inertia is variance 
Some constraints were aliased because they were collinear (redundant)

Eigenvalues for unconstrained axes:
PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 
0.16008 0.14733 0.12183 0.09054 0.07380 0.06971 0.05578 0.04215 
(Showed only 8 of all 29 unconstrained eigenvalues) 
 
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Vegan(ordistep) error: Error in if (aod[1, 5] = Pin) { : missing value where TRUE/FALSE needed

2012-01-10 Thread Nevil Amos
I am getting the following erro rmessage in ordistep.  I have a number of
similarly structured datasets using ordistep in a loop, and the message
only occurs for some of the datasets.

I cannot include a reproducible sample  - the specific datasets where this
is occur ing are fairly large and there are several pcnm's in the rhs of
the formula.

thanks for any pointers that may allow me to track down the cause of the
error.


Error in if (aod[1, 5] = Pin) { : missing value where TRUE/FALSE needed
In addition: There were 50 or more warnings (use warnings() to see the
first 50)
traceback()
9: ordistep(myrda0, scope = formula(myrda1), direction = both,
  Pin = 0.05, Pout = 0.1) at
RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
8: eval(expr, envir, enclos) at RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
7: eval(expr, pf) at RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
6: withVisible(eval(expr, pf)) at
RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
5: evalVis(expr) at RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
4: capture.output(ordistep(myrda0, scope = formula(myrda1), direction =
both,
  Pin = 0.05, Pout = 0.1)) at
RDAPARTIALSexandAgeConnectandGEOGraphy2.R#86
3: eval.with.vis(expr, envir, enclos)
2: eval.with.vis(ei, envir)
1:
source(~/Documents/Dropbox/thesis/CH3/Analysis/RDAPARTIALSexandAgeConnectandGEOGraphy2.R)




print(myrda1)
Call: rda(formula = mygenind@tab ~ pcnmTRE_25_100_CS25 + pcnmTRE_25_10_CS25
+ pcnmTRE_25_2_CS25 +
pcnmTRE_25_5_CS25 + mydata$TreeCov + mydata$Hab_Config +
pcnmEYR_EO_100_CS25 +
pcnmEYR_EO_5000_CS25 + pcnmEYR_TH_10_CS25 + pcnmEYR_TH_2_CS25 +
mydata$Site_No + mydata$Landscape
+ Condition(pcnmCS_NULL + mydata$LAT.x + mydata$LONG.x), na.action =
na.omit)

 Inertia Proportion Rank
Total  1.8110 1.
Conditional0.8681 0.4793   32
Constrained0. 0.0
Unconstrained  0.9429 0.5207   29
Inertia is variance
Some constraints were aliased because they were collinear (redundant)

Eigenvalues for unconstrained axes:
   PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8
0.16008 0.14733 0.12183 0.09054 0.07380 0.06971 0.05578 0.04215
(Showed only 8 of all 29 unconstrained eigenvalues)


-- 
Nevil Amos
Molecular Ecology Research Group
Australian Centre for Biodiversity
Monash University
CLAYTON VIC 3800
Australia

[[alternative HTML version deleted]]

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


[R] partial mantel tests in ecodist with intential NA values.

2011-12-03 Thread Nevil Amos
I would like to perform partial mantel tests  on only within group values, with 
between group values assigned to NA.
This is possible in package ncf partial.mantel.test, however this sues a 
different permutation to that used in ecodist.ecodist will not accept data with 
NA values, returning a matrix is not square error.

is it possible to perform this test in ecodist?

many thanks

Nevil Amos

 library(ecodist)
 library(ncf)
 x-sample(1:1000,20)
 y-sample(1:1000,20)
 z-sample(1:1000,20)
 M1-as.matrix( distance(x))
 M2 -as.matrix( distance(y ))
 M3-as.matrix( distance(z ))
 D1-(lower(M1))
 D2-(lower(M2))
 D3-(lower(M3))
 mantel(D1 ~ D2+D3, nperm=1000)
   mantelr  pval1  pval2  pval3  llim.2.5% ulim.97.5% 
0.09014696 0.1030 0.8980 0.1840 0.01857311 0.18468621 
 partial.mantel.test(M1,M2,M3,quiet=T)
$MantelR
r12 r13 r23   r12.3   r13.2 
 0.08977575  0.02170997 -0.01561346  0.09014696  0.02320821 

$p
[1] 0.09590410 0.30769231 0.47552448 0.09490509 0.30169830

$call
[1] partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)

attr(,class)
[1] partial.Mantel
 M1[1:10,11:20]-NA
 M1[11:20,1:10]-NA
 D1-(lower(M1))
 mantel(D1 ~ D2+D3, nperm=1000)
Error in mantel(D1 ~ D2 + D3, nperm = 1000) : Matrix not square.
 partial.mantel.test(M1,M2,M3,quiet=T)
$MantelR
 r12  r13  r23r12.3r13.2 
 0.054906562  0.003446670 -0.015613460  0.054967403  0.004310979 

$p
[1] 0.2837163 0.4275724 0.4555445 0.2857143 0.4235764

$call
[1] partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)

attr(,class)
[1] partial.Mantel
Warning message:
In partial.mantel.test(M1, M2, M3, quiet = T) :
  Missing values exist; Pairwise deletion will be used
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 plot CI's (llim ulim) on ecodist mgram

2011-10-16 Thread Nevil Amos

I would like to put confidence intervals on a mantel corellogram
they are already calculated in the pmgram object but I am unsure how I 
get the x value in order to plot them?


package(ecodist)
X-1:100
Y-rnorm(1:100)
Z-rnorm(1:100)
XY-dist(data.frame(X,Y))
YX-dist(data.frame(Y,X))
my.mgram-mgram(XY,XZ)
plot(my.mgram)
print(my.mgram)
 print(my.mgram)
$mgram
lag ngroup  mantelr  pvalllim ulim
 [1,]  3.770055672  0.500012737 0.001  0.49689923  0.504301550
 [2,] 11.310165691  0.383960457 0.001  0.38000201  0.387324434
 [3,] 18.850274584  0.232086251 0.001  0.22670074  0.237501735
 [4,] 26.390384587  0.114097397 0.001  0.10243901  0.122973735
 [5,] 33.930494463 -0.003113351 0.835 -0.01928101  0.008839295
 [6,] 41.470603468 -0.106354446 0.001 -0.12682280 -0.089539628
 [7,] 49.010713357 -0.181250278 0.001 -0.20154017 -0.164863572
 [8,] 56.550823348 -0.266397615 0.001 -0.28498271 -0.251134864
 [9,] 64.090933252 -0.298705798 0.001 -0.31421396 -0.284154643
[10,] 71.631042228 -0.353134525 0.001 -0.36468910 -0.341422330
[11,] 79.171152147 -0.337181781 0.001 -0.34854961 -0.322161075
[12,] 86.711262108 -0.334465576 0.001 -0.35500933 -0.309763543
[13,] 94.251371 43 -0.238965642 0.001 -0.26437371 -0.196038662

$resids
[1] NA

attr(,class)
[1] mgram


Thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 format Rsuperscript 2 followed by = value

2011-10-03 Thread Nevil Amos

I am trying to put  an
R2 value with R2 formatted with a superscript 2 followed by = and the 
value :
the first mtext prints the R2 correctly formatted but follows it with 
=round(summary(mylm)$r.squared,3))) as text
the second prints R^2 = followed by the value of 
round(summary(mylm)$r.squared,3))).


how do I correctly write the expression to get formatted r2 followed by 
the value?





x=runif(10)
y=runif(10)
summary(mylm-lm(y~x))
plot(x,y)
abline(mylm)
mtext(expression(paste(R^2,=,round(summary(mylm)$r.squared,3))),1)
mtext(paste(expression(R^2),=,round(summary(mylm)$r.squared,3)),3)



thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 format R superscript 2 followed by = value

2011-10-02 Thread Nevil Amos

I am trying to put  an
R2 value with R2 formatted with a superscript 2 followed by = and the 
value :
the first mtext prints the R2 correctly formatted but follows it with 
=round(summary(mylm)$r.squared,3))) as text
the second prints R^2 = followed by the value of 
round(summary(mylm)$r.squared,3))).


how do I correctly write the expression to get formatted r2 followed by 
the value?





x=runif(10)
y=runif(10)
summary(mylm-lm(y~x))
plot(x,y)
abline(mylm)
mtext(expression(paste(R^2,=,round(summary(mylm)$r.squared,3))),1)
mtext(paste(expression(R^2),=,round(summary(mylm)$r.squared,3)),3)



thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 get xlab and ylab in bold?

2011-09-12 Thread Nevil Amos

A very basic query

This code plots OK the axis values are in bold but the axis labels are 
not.  how do I get them in bold too?


thanks

Nevil Amos

plot(c(1,1),xlim=c(0,450),ylim=c(0.7,1.4),xlab=Distance (cells) from 
edge of grid,ylab=Resistance distance, 
type=l,col=white,lwd=2,font=2,family='sans')


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

2011-06-30 Thread Nevil Amos
I am getting the following error:

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
   0 (non-NA) cases

when running the command

scatterplotMatrix(~THL+WL+BD+TL+Mass|SEX_,by.group=TRUE,plot.points=T,smooth=F,main=spp,)

it works fine without the by group option

I assume there are some cases with too few values, how can I get the loop 
containing this line to skip errors and move on to the next case?



[[alternative HTML version deleted]]

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


[R] How to add label to lines()

2011-06-22 Thread Nevil Amos
I am plotting a number of lines on a standard plot.  I would like to add 
labels at the end (rhs) of each line.  is there a way to do this other 
than defining the individual xy coordinates and placing each label using 
text()


Thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 assemble data frame of unknown number of columns in loop

2011-04-23 Thread Nevil Amos
How do I assemble  ad data fame, consisting of columns form other data 
frames identified in a loop?  cbind is not working as the initial data 
fame has 0 columns and rows.


 ModList-dir(./MODEL_DISTS/)
 ModList-ModList[grep(pattern=3COLUMNS,ModList)]
 ALL_MODELS-data.frame()
 for (i in ModList){
+ X-read.table(file=paste(./MODEL_DISTS/,i,sep=))
+ BASE=sub(3COLUMNS, , i, fixed = TRUE)
+ names(X)-c(FromSiteID,ToSiteID,CS_RESISTANCE)
+ ALL_MODELS-cbind(ALL_MODELS,X[3])
+ }
Error in data.frame(..., check.names = FALSE) :
  arguments imply differing number of rows: 0, 2080


thanks

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


[R] how to keep keep matching column in output of merge

2011-01-04 Thread Nevil Amos

How do I keep the linking column[s] in a merge()?
 I need to use the values again in a further merge.

thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 keep keep matching column in output of merge

2011-01-04 Thread Nevil Amos

Apologies,  it is there!

On 5/01/2011 1:26 AM, Sarah Goslee wrote:

Hi Nevil,

We really need an example here of what you're doing, since
merge() does keep the id column by default.



x- data.frame(id = c(a, b, c, NA), x=c(1,2,3,4))
y- data.frame(id1 = c(NA, a, d, c), y=c(101, 102, 103, 104))
merge(x, y)

   id x   y
1  a 1 102
2  b 2 101
3  c 3 104
4  d 4 103

Sarah

On Tue, Jan 4, 2011 at 8:31 AM, Nevil Amosnevil.a...@gmail.com  wrote:

How do I keep the linking column[s] in a merge()?
  I need to use the values again in a further merge.

thanks

Nevil Amos



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


[R] Change legend position in s.value {ade4}

2010-12-17 Thread Nevil Amos
How do I change the postion of the legend in s.value {ade4} from the 
defaul , bootom left?


thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 change number of characters per line for print() to sink()?

2010-11-22 Thread Nevil Amos
I am using r to read and reformat data that is then saved to a text file 
using sink(), the file has a number of initial lines of comments and 
summary data followed by print of a data.frame with no row names.

for example

a-c(100:120)
b-c(rnorm(100:120))
c-c(rnorm(200:220))
mydata-data.frame(rbind(a,b,c))
sink(datafile.txt)

cat(comments about my data \n)
cat(other calculations returned as separate text comments on a line \n)
print(mydata,row.names=F)
sink()


I need the content of the text file to keep each row of the data frame 
on a single line thus (with intervening columns present of course)


datafile.txt

comments about my data
other calculations returned as separate text comments on a line
  X1 X2  X3  X4  X5  
X6   
. 
X19 X20 X21



 100.000 101.00 102.000 103.000 104.000 
105.000  ..118.000 119.000 120.000
  -0.3380570  -1.400905   1.0396499  -0.5802181  -0.2340614   
0.6044928   ...-0.4854702  -0.3677461  
-1.2033173
  -0.9002824   1.544242  -0.8668653   0.3066256   0.2490254  -1.6429223 
.   0.0861146   0.4276929  -0.3408604


How doI change setting for print() or use another function to keep each 
row of the data frame as a single line ( of greater length up to approx 
300 characters) instead of wrapping the data frame into multiple lines 
of text?


The problem : I end up with the data frame split into several sections 
one under another thus


datafile.txt

comments about my data
other calculations returned as separate text comments on a line
  X1 X2  X3  X4  X5  X6
 100.000 101.00 102.000 103.000 104.000 105.000
  -0.3380570  -1.400905   1.0396499  -0.5802181  -0.2340614   0.6044928
  -0.9002824   1.544242  -0.8668653   0.3066256   0.2490254  -1.6429223
  X7   X8  X9 X10 X11 X12
 106.000 107. 108.000 109.000 110.000 111.000
   0.3152427   0.15093494  -0.3316172  -0.3603724  -2.0516402  -0.4556241
  -0.6502265  -0.08842649  -0.3775335  -0.4942572  -0.0976565  -0.7716651
 X13 X14 X15 X16  X17X18
 112.000 113.000 114.000 115.000 116. 117.00
   0.8829135   0.8851043  -0.7687383  -0.9573476  -0.03041968   1.425754
   0.2666777   0.6405255   0.2342905  -0.7705545  -1.18028004   1.303601
 X19 X20 X21
 118.000 119.000 120.000
  -0.4854702  -0.3677461  -1.2033173
   0.0861146   0.4276929  -0.3408604

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] filling large matrix( or dist object) with values from small matrix.

2010-11-18 Thread Nevil Amos
The script below provides a trivial example of filling a large matrix 
with values from a small one with corresponding row and column details.


this is fine for a small example but too slow for many large examples ( 
my small matrices are 65x65 and my large matrices up to 900x900, and I 
have many permutations to fill.


is there a more efficient way to achieve this

M-as.matrix(as.dist(matrix(x,nrow=4,ncol=4,dimnames=list(c(A,B,C,D),c(A,B,C,D)
N-matrix(NA,nrow=8,ncol=8,dimnames=list(c(A,B,C,D,A,B,C,D),c(A,B,C,D,A,B,C,D)))
for (r in 1:nrow(N)){
for (c in 1:(ncol(N))){
N[r,c]=M[rownames(N)[r],colnames(N)[c]]
}
}

thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 find names referring to parts of an R object. particlualry w.r.t capscale

2010-11-14 Thread Nevil Amos
This is both a very general, and a specific question. either answer will 
help me a lot.


I know the object$part syntax is used to retrieve parts of an object for 
instance myMantel$signif will return the  the p value of mantel() and 
myMantel$statistic the mantel r.


Is there any way of listing such components of all objects.  at the 
moment I would like to be able to extract the variance, p value etc for 
a capscle to tabulate the automatically but would also like to know if 
the re is a simple way to establish the way to refer to all individual 
sub parts of a object?



thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] NA handling problem in capscale (vegan)

2010-11-10 Thread Nevil Amos

I am having a problem with NA handling in capscale function.

as I understand it from the help capscale should permit NA values when 
na.action=na.mit or na.exclude,


however I am getting  the error

Error in X[nas, , drop = FALSE] : incorrect number of dimensions

trivial example is pasted below.

library(vegan)
mydist- matrix(1:25, 5, 5)
mydata-matrix(rnorm(1:25),5,5)
mydata[3,1]-NA
mydata-data.frame(mydata)

capscale(mydist~X1+X2+Condition(X3),data=mydata,na.action = na.omit)


Thanks

Nevil Amos

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

2010-10-12 Thread Nevil Amos
  I have a spectrophotometric dataset with repeated measures of a value 
at 200 wavelengths for each of  150 individuals.

I would like to use the repeated samples to at each wavelength to look 
at measurement/observer error, compared to difference between 
individuals error

I have looked at doing this with icc{irr} or using an anova approach, 
but I am unclear how to acheive this given that there is a nested 
structure- the value varies between wavelengths within individuals.

Many thanks

Nevil Amos

data is structured thus:

   ANWC_NO Wavelength Repeatvalue
 1   00239300   r1 0.079501
 2   00239302   r1 0.084113
 3   00239304   r1 0.087697
 202 11157300   r1 0.008449
 203 11157302   r1 0.009489
 204 11157304   r1 0.010142
 403 11158300   r1 0.026999
 404 11158302   r1 0.029612
 405 11158304   r1 0.030271
 604 11159300   r1 0.032784
 66934   38711300   r3 0.062081
 66935   38711302   r3 0.065137
 66936   38711304   r3 0.067092
 67135   38712300   r3 0.029389
 67136   38712302   r3 0.030192
 67137   38712304   r3 0.030860
 67336   38993300   r3 0.045720
 67337   38993302   r3 0.048060
 67338   38993304   r3 0.051898
 67537   38994300   r3 0.051815
 67538   38994302   r3 0.055162


[[alternative HTML version deleted]]

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


[R] conditioning variables in dbRDA

2010-10-11 Thread Nevil Amos
 I am using cascaple() in vegan, is it permissible to have more than 
one conditioning variable thus
capscale(DIST~varaible1+variable2+Conditon(varaible3+variable4), 
data=mydata)


many thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] partial dbRDA or CCA with two distance objects in Vegan.

2010-09-21 Thread Nevil Amos
 I am trying to use the cca/rda/capscale functions in vegan to analyse 
genetic distance data ( provided as a dist object calculated using 
dist.genpop in package adegenet) with geographic distance partialled out 
( provided as a distance object using dist function in veganthis method 
is attempting to follow the method used by Geffen et al 2004  as 
suggested by Legendre and . FORTIN (2010).


I cannot see how to introduce the Conditioning ( partialled) second dist 
matrix.  as you can see from the code snippet below, the two dist 
objects are of the same dimensions. - I get an error using capscale:

Error in qr.fitted(Q, Xbar) :
  'qr' and 'y' must have the same number of rows
or cca
Error in weighted.mean.default(newX[, i], ...) :
   'x' and 'w' must have the same length
when using a conditioning distance object instead of a variable (Clade) 
of the same length as  the constraints ( Latitude and Longitude)


I would be grateful, for any pointers on this, ie which test is the 
appropriate one to use ( I believe capscale since it is similar to 
distance-based redundancy analysis (Legendre  Anderson 1999)) and 
whether this test is indeed equivalent to the approach suggested by 
Legendre Fortin, (Geffen et al used DISTLM).


many thanks

Nevil Amos
ACB
Monash University


references
(Geffen, E., M. J. Anderson, et al. (2004). Climate and habitat 
barriers to dispersal in the highly mobile grey wolf. Molecular Ecology 
13(8): 2481-2490.)
LEGENDRE, P. and M.-J. FORTIN (2010). Comparison of the Mantel test and 
alternative approaches for detecting complex multivariate relationships 
in the spatial analysis of genetic data. Molecular ecology resources 
early copy online



Snippet from analysis script:
 Gen_Dist-dist.genpop(mygenpop,method=2,diag=F,upper=F)
 str(Gen_Dist)
Class 'dist'  atomic [1:666] 0.866 0.757 0.813 0.872 0.887 ...
  ..- attr(*, Labels)= Named chr [1:37] 4879 4883 4884 4885 ...
  .. ..- attr(*, names)= chr [1:37] 01 02 03 04 ...
  ..- attr(*, Size)= int 37
  ..- attr(*, call)= language dist.genpop(x = mygenpop, method = 2, 
diag = F, upper = F)

  ..- attr(*, Diag)= logi FALSE
  ..- attr(*, Upper)= logi FALSE
  ..- attr(*, method)= chr Edwards
 str(geog)
Class 'dist'  atomic [1:666] 6.61 4.19 14.6 16.71 16.68 ...
  ..- attr(*, Size)= int 37
  ..- attr(*, Labels)= chr [1:37] 2 5 6 7 ...
  ..- attr(*, Diag)= logi FALSE
  ..- attr(*, Upper)= logi FALSE
  ..- attr(*, method)= chr euclidean
  ..- attr(*, call)= language dist(x = XY)
 myDbRDA-cca(Gen_Dist ~ Latitude+Longitude+Condition(Clade),data = 
mydata)

 myDbRDA-cca(Gen_Dist ~ Latitude+Longitude+Condition(geog),data = mydata)
Error in weighted.mean.default(newX[, i], ...) :
  'x' and 'w' must have the same length

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] partial dbRDA or CCA with two distance objects in Vegan.

2010-09-21 Thread Nevil Amos

 Thanks for that, just to confirm I therefore need to use:
#if
#geogdist  is a geographic distance matrix
#gen_dist is a genetic distance matrix
#env_var are environmental variables

mypcnm-pcnm(geogdist)


mydbRDA-capscale(gen_dist~env_var+Condition(mypcnm$vectors))

cheers


Nevil





On 22/09/2010 1:34 AM, Jari Oksanen wrote:

On 21/09/10 17:40 PM, Nevil Amosnevil.a...@gmail.com  wrote:


   I am trying to use the cca/rda/capscale functions in vegan to analyse
genetic distance data ( provided as a dist object calculated using
dist.genpop in package adegenet) with geographic distance partialled out
( provided as a distance object using dist function in veganthis method
is attempting to follow the method used by Geffen et al 2004  as
suggested by Legendre and . FORTIN (2010).

I cannot see how to introduce the Conditioning ( partialled) second dist
matrix.  as you can see from the code snippet below, the two dist
objects are of the same dimensions. - I get an error using capscale:
  Error in qr.fitted(Q, Xbar) :
'qr' and 'y' must have the same number of rows
or cca
  Error in weighted.mean.default(newX[, i], ...) :
 'x' and 'w' must have the same length
when using a conditioning distance object instead of a variable (Clade)
of the same length as  the constraints ( Latitude and Longitude)

I would be grateful, for any pointers on this, ie which test is the
appropriate one to use ( I believe capscale since it is similar to
distance-based redundancy analysis (Legendre  Anderson 1999)) and
whether this test is indeed equivalent to the approach suggested by
LegendreFortin, (Geffen et al used DISTLM).


Nevil,

You cannot use cca() for dissimilarity data. If you have dissimilarity data,
you must use capscale() which runs db-RDA. Even there, your constraints
(variables on the right hand side of the formula) must be rectangular data
and not dissimilarities. AFAIK, people have changed their dissimilarities
into a PCNM structure when they want to partial out the distance effect.
That is one of the few original possibilities since data must be rectangular
(rows and columns).

Cheers, jari oksanen



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 un-crosstabulate data without changing numeric values to text?

2010-08-28 Thread Nevil Amos
I have a large amount of data read in from over 140 excel files in the 
format of x.  r1 to r5 are repeat measures for a given Wavelength and 
ANWC_NO.


I need to rearrange x into 3 columns, ANWC_NO,Wavelegth, value ie

ANWC_NOWavelength r1
ANWC_NOWavelength,r2
ANWC_NOWavelength r3


etc...

I can rearrange the data using the code below, however all the columns 
end up as strings, not numeric values.  I cannot then summaries the 
data, ( whcih I need to do in bins of wavelanght for each ANWC_NO)



 x
 Wavelength   r1   r2   r3   r4   r5 ANWC_NO
1300 0.003126 0.005382 0.001094 0.012529 0.005632   39239
2302 0.004924 0.006280 0.002366 0.015234 0.006204   39239
3304 0.004769 0.005960 0.002759 0.015856 0.006804   39239
4306 0.005181 0.006717 0.004033 0.017380 0.007675   39239
5308 0.005872 0.008083 0.004429 0.018334 0.008504   39239
6310 0.007164 0.010775 0.005949 0.019952 0.009594   39239
 y =NULL
 rows-nrow(x)
 for(r in 1:rows){
+ for(c in 2:6){
+ row-c(c(x[r,7]),as.numeric(c(x[r,1])),as.numeric(c(x[r,c])))
+ y-rbind(y,row)
+ }}
 colnames(y)-c(ANWC_NO,WAVELENGTH,VALUE)
 head (y)
   ANWC_NO WAVELENGTH VALUE
row 39239 300  0.003126
row 39239 300  0.005382
row 39239 300  0.001094
row 39239 300  0.012529
row 39239 300  0.005632
row 39239 302  0.004924

 mean(y$VALUE)
Error in y$VALUE : $ operator is invalid for atomic vectors

how do I get the data arranged in three columns but maintaining 
WavelENGTH and the values as numeric in a data.frame?

Many thanks

Nevil Amos
Monash University

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

2010-06-20 Thread Nevil Amos
I have the following script to convert Longitude and Latitude into 
lambert projection ( adapted from Geneland manual).  How do I get the 
proejction with units in metres rather than whatever they are 
currently?  alos is it possible to add a fualse XY so that all values 
are positive ( all my lattidudes are south ie negative)


Many thanks

Nevil Amos

Monash University

LONGLAT is a headerless two column file of longitude and latitude
such as

141 -32
142 -35
136 -20

## load packages
require(mapproj)
require(maps)
## read raw data
coord.lonlat - LONGLAT
## convert (Lon,Lat) coordinates into Lambert
mapproj.res - mapproject(x=coord.lonlat[,1],
y=coord.lonlat[,2],
projection=lambert,
param=c(min(coord.lonlat[,2]),max(coord.lonlat[,2])))
## save planar coordinates as a two-column matrix
coord.lamb - cbind(mapproj.res$x,mapproj.res$y)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 output text to sink without initial line number [1], and data frame line by line without column names

2010-06-13 Thread Nevil Amos
I want to output a text file assembeld from various soruces within r ( 
actually as a genepop file)


the output should be formatted line 1 text comment
   line 2:n  selected 
column names from data frame
line n+1on lines of 
selected columns  from data frame one row at a time



I have the following code, but cannot see how to remove the line numbers 
and omit column names form the line by line data frame output


col1-c(2,45,67)
col2-c(a,B,C)
col3-c(234,44,566)
mydf-as.data.frame(cbind(col1,col2,col3))
n-ncol(mydf)
nr-nrow(mydf)
sink(test.txt)

print(I will be including text of various sorts in this file so cannot 
use print table or similar command)

for (i in 1:n){
print(colnames(mydf[i]),quote=F) }
for (j in 1:nr){
print(mydf[j,c(2:n)],quote=F,row.names=F)}
sink()

The test.txt contains:

[1] I will be including text of various sorts in this file so cannot 
use print table or similar command

[1] col1
[1] col2
[1] col3
 col2 col3
a  234
 col2 col3
B   44
 col2 col3
C  566

what I would like in test.txt  is:

I will be including text of various sorts in this file so cannot use 
print table or similar command

col1
col2
col3
 a  234
 B   44
 C  566

Many thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 output text to sink from data frame line by line without column names

2010-06-13 Thread Nevil Amos
OK I see how to remove the line numbers[1] etc by using cat instead of 
print, but cannot work out how to remove the column names from the data 
frame output


On 13/06/2010 4:21 PM, Nevil Amos wrote:
I want to output a text file assembeld from various soruces within r ( 
actually as a genepop file)


the output should be formatted line 1 text comment
   line 2:n  selected 
column names from data frame
line n+1on lines 
of selected columns  from data frame one row at a time



I have the following code, but cannot see how to remove the line 
numbers and omit column names form the line by line data frame output


col1-c(2,45,67)
col2-c(a,B,C)
col3-c(234,44,566)
mydf-as.data.frame(cbind(col1,col2,col3))
n-ncol(mydf)
nr-nrow(mydf)
sink(test.txt)

print(I will be including text of various sorts in this file so 
cannot use print table or similar command)

for (i in 1:n){
print(colnames(mydf[i]),quote=F) }
for (j in 1:nr){
print(mydf[j,c(2:n)],quote=F,row.names=F)}
sink()

The test.txt contains:

[1] I will be including text of various sorts in this file so cannot 
use print table or similar command

[1] col1
[1] col2
[1] col3
 col2 col3
a  234
 col2 col3
B   44
 col2 col3
C  566

what I would like in test.txt  is:

I will be including text of various sorts in this file so cannot use 
print table or similar command

col1
col2
col3
 a  234
 B   44
 C  566

Many thanks

Nevil Amos


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 get a list of subdirectories in the wd?

2010-06-01 Thread Nevil Amos

How do I get a list of subdirectories only, not files, in a directory


dir.create(test)
setwd(test)
dir.create(adir)
dir.create(bdir)
file.create(afile)
dir()

returns [1] adir  afile bdir

in need to return [1] adir  bdir

cheers

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Printing page nmbers in multi-page pdf

2010-05-31 Thread Nevil Amos

Is it possible to print page numbers in pdf() with multiple pages?

thanks

Nevil Amos

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


[R] warning In fun(...) : no DISPLAY variable so Tk is not available

2010-05-29 Thread Nevil Amos
I am getting the above warning following loading of Geneland 3.1.5 on 
unix , while a simple plot sends output to the pdf file ( see attached 
code) no output results from Geneland functions, resulting in empty pdf 
files



 library (Geneland)
Loading required package: RandomFields
Loading required package: fields
Loading required package: spam
Package 'spam' is loaded. Spam version 0.21-0 (2010-03-13).
Type demo( spam) for some demos, help( Spam) for an overview
of this package.
Help for individual functions is optained by adding the
suffix '.spam' to the function name, e.g. 'help(chol.spam)'.

Attaching package: 'spam'

The following object(s) are masked from 'package:base':

backsolve, forwardsolve, norm

 Try help(fields) for an overview of this library
fields web: http://www.image.ucar.edu/Software/Fields
Loading required package: mapproj
Loading required package: maps
Loading required package: snow
Loading required package: tcltk
Loading Tcl/Tk interface ... done
ooo
oGeneland is loaded   o
o o
o* Please *   o
o o
oRegister on  o
ohttp://folk.uio.no/gillesg/Geneland/register.php o
o o
oSee manual ono
ohttp://folk.uio.no/gillesg/Geneland/Geneland.htmlo
o o
oThis is Geneland-3.1.5   o
o o
ooo
Warning message:
In fun(...) : no DISPLAY variable so Tk is not available
 pdf(test.pdf)
 plot(1:10,1:10)
 dev.off()
null device

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 install an archived version of a package in windows

2010-05-27 Thread Nevil Amos
How do I install an archived version of a package - in this case 
Geneland 3.1.5 in windows?


The archived versions are available on CRAN and tar.gz.  I can downland 
this, but then the only option to install a local copy is

 utils:::menuInstallLocal()
or install from local zip file in the console packages menu, this does 
not work wither with the downlaoded tar.gz, or if I unzip it and save 
all its contents as Genland_3.1.5.zip in the R/bin direcotry.


What do I need to do?

thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Geneland error on unix: Error in MCMC(........ :, unused argument(s) (ploidy = 2, genotypes = geno)

2010-05-20 Thread Nevil Amos


I am receiving the above error ( full r session output below)  the 
script runs OK in windows.  and genotypes and ploidy are both 
correct arguments


any suggestions would be most welcome

Nevil Amos
MERG/ACB
Monash University School of Biological Sciences







 library(Geneland)
Loading required package: RandomFields
Loading required package: fields
Loading required package: spam
Package 'spam' is loaded. Spam version 0.21-0 (2010-03-13).
Type demo( spam) for some demos, help( Spam) for an overview
of this package.
Help for individual functions is optained by adding the
suffix '.spam' to the function name, e.g. 'help(chol.spam)'.

Attaching package: 'spam'

The following object(s) are masked from 'package:base':

backsolve, forwardsolve, norm

 Try help(fields) for an overview of this library
fields web: http://www.image.ucar.edu/Software/Fields
Loading required package: mapproj
Loading required package: maps
Loading required package: snow
Loading required package: tcltk
Loading Tcl/Tk interface ... done
ooo
oGeneland is loaded   o
o o
o* Please *   o
o o
oRegister on  o
ohttp://www2.imm.dtu.dk/~gigu/Geneland/register.php   o
o o
oSee manual ono
ohttp://www2.imm.dtu.dk/~gigu/Geneland/#Manualo
o o
oType citation(Geneland) for a quick citation guide o
o o
oSee http://www2.imm.dtu.dk/~gigu/Geneland/#  o
ofor additional referenceso
o o
oThis is Geneland-3.2.1   o
o o
ooo
Warning message:
In fun(...) : no DISPLAY variable so Tk is not available
 DIRLIST-c(Adult_ALL 
NO_ANW/)#,Adult_Or_ANW/,Adult_Females/,Adult_Males/)

 for(d in DIRLIST){
+ theWd- paste(/nfs/monash/home/namos/Rwork/,d,sep=)
+ setwd(theWd)
+ SPP.CODES -EYR#c(BT,EYR,FH,SPP,STP)
+ for (sp in  SPP.CODES){
+ path.sp- paste(theWd,sp,/,sep=)
+ dir.create(path.sp)
+ GENO.TABLE-paste(theWd,sp,geno,sep=)
+ XY.TABLE-paste(theWd,sp,xy,sep=)
+ MINPOP=1
+ MAXPOP=25
+ INITPOP=1
+ NITS=50
+ THIN=NITS/1000
+ nrun - 10
+ burnin - 200
+ geno-noquote(read.table(GENO.TABLE))
+ coord-read.table(XY.TABLE)
+
+ ## Loop for multiple runs
+
+ for(irun in 1:nrun)
+ {
+ ## define path to MCMC directory
+
+ path.mcmc - paste(path.sp,irun,/,sep=)
+ dir.create(path.mcmc)
+ MCMC(coordinates=coord, ploidy=2, genotypes=geno, varnpop=T, 
npopmax=MAXPOP, npopinit=MINPOP, spatial=T, freq.model=Correlated, 
nit=NITS, thinning=500, rate.max=nrow(geno), delta.coord=100, 
path.mcmc=path.mcmc)

+ ## MCMC postprocessing
+ PostProcessChain(coordinates=coord,path.mcmc=path.mcmc,genotypes=geno, 
nxdom=50,nydom=50,burnin=burnin)

+ }
+ ## Computing average posterior probability
+
+ lpd - rep(NA,nrun)
+ for(irun in 1:nrun)
+ {
+ path.lpd - paste(path.mcmc,log.posterior.density.txt,sep=)
+ lpd[irun] - mean(scan(path.lpd)[-(1:burnin)])
+ }
+ ## Runs sorted by decreasing average posterior probability:
+ order(lpd,decreasing=TRUE)
+
+ #pdf(Number of pops.pdf,((210-10)/25.4),((297-10)/25.4))
+ #theWd-getwd()
+ ##setwd(theWd)
+ #par(mfrow = c(5, 2),cex=0.25)
+ #for(irun in 1:nrun)
+ #
+ #{
+ #
+ ###Below is code form the Geneland Plotnpop function
+ #fileparam - paste(path.mcmc, parameters.txt, sep = )
+ #param - as.matrix(read.table(fileparam))
+ #thinning - as.numeric(param[param[, 1] == thinning, 3])
+ #filenpop - paste(path.mcmc, populations.numbers.txt, sep = )
+ #npop - scan(filenpop)
+ # sub - -(1:burnin)
+ #
+ #plot((1:length(npop)) * thinning, npop, type = l,ylab = Number of 
classes, xlab = Index of MCMC iteration Whole 
chain,main=paste(path.mcmc,\n,Run:, irun, sep =  ), ylim = c(1, 
max(npop)+ 0.5))
+ #hist(npop[sub], plot = TRUE, prob = TRUE, breaks = seq(0.5,max(npop) 
+ 0.5, 1), xlab = paste(Nb. of pop. along the chain (after a burnin of 
, burnin, x, thinning, i t.), sep = ), main = Number of 
populations long the chain after burnin)

+ #
+ #
+ #}
+ #dev.off()
+ }
+ }
Error in MCMC(coordinates = coord, ploidy = 2, genotypes = geno, varnpop 
= T,  :

  unused argument(s) (ploidy = 2, genotypes = geno)
Execution halted

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

[R] writing string values from a matrix to a file without enclosing quotes

2010-05-07 Thread Nevil Amos

I am trying to format data for the Geneland package
I need to write a series of paired numbers and paired 000
to a plain ascii file without surrounding the numerals with quotes,
the original data is in a matrix formatted paired  strings,
and written to file using
write.table(x,output filename,col.names=F,row.names=F)
thus
77 79 132 132 000 000
179 181 132 132 150 150
179 179 132 132 000 000
179 179 132 134 150 152

however I need the output file without the quotes but retaining 000 not 
reducing it to 0


thus
77 79 132 132 000 000
179 181 132 132 150 150
179 179 132 132 000 000
179 179 132 134 150 152

How might I achieve this?

Thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 replace all NA values in a data.frame with another ( not 0) value

2010-05-04 Thread Nevil Amos
I need to replace NA occurrences in multiple columns  in a data.frame 
with 000/000


how do I achieve this?

Thanks

Nevil Amos

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 replace all NA values in a data.frame with another ( not 0) value

2010-05-04 Thread Nevil Amos

Thanks, this works, replacing the NA values with the 000/000' string.

On 4/05/2010 11:20 PM, Muhammad Rahiz wrote:

Hi Nevil,

You can try a method like this

x - c(rnorm(5),rep(NA,3),rnorm(5)) # sample data
dat - data.frame(x,x)   # make sample dataframe
dat2 - as.matrix(dat) # conver to matrix
y - which(is.na(dat)==TRUE) # get index of NA values
dat2[y] - 000/000 # replace all na values 
with 000/000


Muhammad






Nevil Amos wrote:
I need to replace NA occurrences in multiple columns  in a 
data.frame with 000/000


how do I achieve this?

Thanks

Nevil Amos

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

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


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


[R] using get and paste in a loop to return objects for object names listed a strings

2010-04-29 Thread Nevil Amos
I am trying to create a heap of boxplots, by looping though a series of 
factors and variables in a large data.frame suing paste to constrcut the 
facto and response names from the colnames

I thought I could do this using get()
however it is not working what am I doing wrong?

thanks

Nevil Amos


sp.codes=levels(data.all$CODE_LETTERS)

for(spp in sp.codes) {


data.sp=subset(data.all,CODE_LETTERS==spp)

responses = colnames(data.all)[c(20,28,29,19)]
 #if (spp==BT) responses = colnames(data.all)[c(19,20,26:29)]
groups=colnames   (data.all)[c(9,10,13,16,30)]

data.sp=subset(data.all,CODE_LETTERS==spp)
for (response in responses){
for (group in groups){
r-get(paste(data.sp$,response,sep=))
g-get(paste(data.sp$,group, sep=))
print (r)
print(g)

boxplot(r ~g)
}}}

Error in get(paste(data.sp$, response, sep = )) :
  object 'data.sp$Hb' not found

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] using get and paste in a loop to return objects for object names listed a strings

2010-04-29 Thread Nevil Amos
Thanks for that, the package looks very useful.  It gave me the answer 
in a roundabout way - reminded me I needed to sue attach() so that the 
get () was only dealing with the objects in data.frame, rather than 
using the data.frame$factorname


I therefore managed to sort a work around, but will be looking at ggplot 
2 for other things


the work around and the head of the data file is shown below

 head(data.all)
   Line Capture_ID Landscape_Name Band_text Bird_IDDate 
CODE_LETTERS Site_Name Age_Class SEX_ Capture_Number Mass Season 
SEASON_CLASS   EVC Moult Sine_Julian Cosine_Julian  HCT   Hb 
Site_Cond Logs_Length
10   10 10  Axe Creek   42605012275  7/11/2007 
0:00  YTH   Ax1 AF  1 21.5 
Spring   SS Heathy Dry Forest N   -0.80  0.59 
0.48   NA43   5
13   13 13  Axe Creek   37136021170  8/11/2007 
0:00  YTH   Ax1 AF  1 21.5 
Spring   SS Heathy Dry Forest N   -0.79  0.61 
0.53 20.443   5
19   19 21  Axe Creek   37136031171  9/11/2007 
0:00  YTH   Ax1 AF  1 19.5 
Spring   SS Heathy Dry Forest N   -0.78  0.62 
0.53   NA43   5
30   30 34  Axe Creek   37136041172 10/11/2007 
0:00  YTH   Ax1 UM  1 24.5 
Spring   SS Heathy Dry Forest Y   -0.76  0.63   
NA   NA43   5
31   31 35  Axe Creek   37136051173 10/11/2007 
0:00  YTH   Ax1 UU  1   NA 
Spring   SS Heathy Dry Forest U   -0.76  0.63   
NA   NA43   5
32   32 36  Axe Creek   37136061174 10/11/2007 
0:00  YTH   Ax1 UM  1 23.5 
Spring   SS Heathy Dry Forest U   -0.76  0.63 
0.50   NA43   5
   Litter_Cov Understorey TreeCov H.L WBC  BCI   CCIPca1 YEAR 
Hab_Config

10   22.5  650.35  NA  NA   NANA 2007  D
13   22.5  650.35  NA  NA -3.11592 0.6215803 2007  D
19   22.5  650.35  NA  NA   NANA 2007  D
30   22.5  650.35  NA  NA   NANA 2007  D
31   22.5  650.35  NA  NA   NANA 2007  D
32   22.5  650.35  NA  NA   NANA 2007  D


sp.codes=levels(data.all$CODE_LETTERS)

for(spp in sp.codes) {


data.sp=subset(data.all,CODE_LETTERS==spp)

responses = colnames(data.all)[c(20,28,29,19)]
 #if (spp==BT) responses = colnames(data.all)[c(19]#,20,26:29)]
groups=colnames   (data.all)[c(9,10)]# ,13,16,30

attach(data.sp)
for (response in responses){
for (group in groups){
g=get(group)
r=get(response)
boxplot(r ~g, main=spp,xlab=group,ylab=response)

}
}
detach(data.sp)
}




On 29/04/2010 7:05 PM, Paul Hiemstra wrote:

Nevil Amos wrote:
I am trying to create a heap of boxplots, by looping though a series 
of factors and variables in a large data.frame suing paste to 
constrcut the facto and response names from the colnames

I thought I could do this using get()
however it is not working what am I doing wrong?
You don't give a reproducible example, this makes it hard to answer 
your question.


But not really in response to your question, take a look at histogram 
from the lattice package or geom_boxplot from the ggplot2 package. 
These functions can do all the work for you of drawing boxplots for a 
series of factors and variables in a large data.frame. This saves you 
a lot of time.


cheers,
Paul







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


[R] reduce size of pdf

2010-04-29 Thread Nevil Amos

is there a way to reduce the size of pdf files  in R: ?
compression?

lower dpi ?

or some other option?

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

2010-04-29 Thread Nevil Amos
The file is a large number of scatterplot matrices (120pp of 4x4 
matrix)  the individual plots may have up to several hudred points.


I am already using the useDingbats  but the files are still very large 
- I can reduce them about 50% in cute.pdf by changing the dpi setting 
but it would be good to handle directly in R


They need to be screen/ draft print quality only not for publication.

They are being used to ciruclate to a number of people for discussion




On 30/04/2010 2:20 AM, Greg Snow wrote:

It would help if we knew how big your pdf is and why it is big.  Can you show 
an example or at least describe the process used to generate the file and what 
you goals are in creating/displaying the file?




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