Re: [R] xts/zoo index problem?

2016-01-18 Thread Huzefa Khalil
Try

a["2016-01-18 15:31:54.079"]

The question though is why R displays the milliseconds as "078", when
it is clearly "079"...

-h



On Mon, Jan 18, 2016 at 8:55 PM, ce  wrote:
> Dear all,
>
> I have this code :
>
> library(xts)
> a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
> "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index 
> = structure(c(1453137885.23,
> 1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
> 1L), .Dimnames = list(NULL, "value"))
>
> a
>
> a["2016-01-18 12:24:45.230"]
> #value
> #2016-01-18 12:24:45 1
>
> a["2016-01-18 15:31:54.078"]
> #   value
>
> Why second line doesn't show the value? Something to do with miliseconds ?
> Thanks
> CE
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] xts/zoo index problem?

2016-01-18 Thread Huzefa Khalil
Well it works when you don't put the milliseconds because it is
matching that part of the date which is provided. Hence, the following
all work:

a["2016-01-18 15:31:54.0"]
a["2016-01-18 15:31:54"]
a["2016-01-18 15:31"]
a["2016-01-18 15"]

However, what I don't get is why it is showing 1453149114.079 as
"2016-01-18 15:31:54.078". It should be showing it as "2016-01-18
15:31:54.079".

Anybody?

On Mon, Jan 18, 2016 at 9:31 PM, ce  wrote:
>
> yes it shows , more interesting :
>
>>  a["2016-01-18 15:31:54.0"]
> value
> 2016-01-18 15:31:54 2
>
>> a["2016-01-18 15:31:54.07"]
>  value
>
>> a["2016-01-18 15:31:54.079"]
> value
> 2016-01-18 15:31:54 2
>
>
> why it doesn't work with .07 milisecond  but work with .079  and .0 ??
>
>
> -Original Message-
> From: "Huzefa Khalil" [huzefa.kha...@umich.edu]
> Date: 01/18/2016 09:26 PM
> To: "ce" 
> CC: r-help@r-project.org
> Subject: Re: [R] xts/zoo index problem?
>
> Try
>
> a["2016-01-18 15:31:54.079"]
>
> The question though is why R displays the milliseconds as "078", when
> it is clearly "079"...
>
> -h
>
>
>
> On Mon, Jan 18, 2016 at 8:55 PM, ce  wrote:
>> Dear all,
>>
>> I have this code :
>>
>> library(xts)
>> a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
>> "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index 
>> = structure(c(1453137885.23,
>> 1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
>> 1L), .Dimnames = list(NULL, "value"))
>>
>> a
>>
>> a["2016-01-18 12:24:45.230"]
>> #value
>> #2016-01-18 12:24:45 1
>>
>> a["2016-01-18 15:31:54.078"]
>> #   value
>>
>> Why second line doesn't show the value? Something to do with miliseconds ?
>> Thanks
>> CE
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>

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


Re: [R] xts/zoo index problem?

2016-01-18 Thread Joshua Ulrich
On Mon, Jan 18, 2016 at 8:31 PM, ce  wrote:
>
> yes it shows , more interesting :
>
>>  a["2016-01-18 15:31:54.0"]
> value
> 2016-01-18 15:31:54 2
>
>> a["2016-01-18 15:31:54.07"]
>  value
>
>> a["2016-01-18 15:31:54.079"]
> value
> 2016-01-18 15:31:54 2
>
>
> why it doesn't work with .07 milisecond  but work with .079  and .0 ??
>
It's not surprising why it doesn't work with 0.070.  It doesn't work
because that's not what the milliseconds component is.  It's also not
surprising why it works with 0.079, because that's what the
milliseconds component is (how something prints is not what it is
equal to).  It is a bit surprising that a value is returned when the
milliseconds component is zero.

>
> -Original Message-
> From: "Huzefa Khalil" [huzefa.kha...@umich.edu]
> Date: 01/18/2016 09:26 PM
> To: "ce" 
> CC: r-help@r-project.org
> Subject: Re: [R] xts/zoo index problem?
>
> Try
>
> a["2016-01-18 15:31:54.079"]
>
> The question though is why R displays the milliseconds as "078", when
> it is clearly "079"...
>
See this StackOverflow question for discussion around why R prints
fractional seconds the way it does:
http://stackoverflow.com/q/7726034/271616

> -h
>
>
>
> On Mon, Jan 18, 2016 at 8:55 PM, ce  wrote:
>> Dear all,
>>
>> I have this code :
>>
>> library(xts)
>> a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
>> "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index 
>> = structure(c(1453137885.23,
>> 1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
>> 1L), .Dimnames = list(NULL, "value"))
>>
Use a specific timezone.  Everyone does not share your local timezone,
and you don't say what it is.

library(xts)
# don't warn about object TZ vs local TZ differences
options(xts_check_TZ=FALSE, digits.secs=6)
a <- structure(1:2,
  class = c("xts", "zoo"), .indexCLASS=c("POSIXct", "POSIXt"),
  .indexTZ = "UTC", tclass = c("POSIXct", "POSIXt"), tzone = "UTC",
  index = structure(c(1453137885.23, 1453149114.079), tzone = "UTC",
  tclass = c("POSIXct", "POSIXt")), .Dim = c(2L, 1L),
  .Dimnames = list(NULL, "value"))

>> a
>>
>> a["2016-01-18 12:24:45.230"]
>> #value
>> #2016-01-18 12:24:45 1
>>
>> a["2016-01-18 15:31:54.078"]
>> #   value
>>
>> Why second line doesn't show the value? Something to do with miliseconds ?
>> Thanks
>> CE
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



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

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


Re: [R] xts/zoo index problem?

2016-01-18 Thread ce

yes it shows , more interesting :

>  a["2016-01-18 15:31:54.0"]
value
2016-01-18 15:31:54 2

> a["2016-01-18 15:31:54.07"]
 value

> a["2016-01-18 15:31:54.079"]
value
2016-01-18 15:31:54 2


why it doesn't work with .07 milisecond  but work with .079  and .0 ??


-Original Message-
From: "Huzefa Khalil" [huzefa.kha...@umich.edu]
Date: 01/18/2016 09:26 PM
To: "ce" 
CC: r-help@r-project.org
Subject: Re: [R] xts/zoo index problem?

Try

a["2016-01-18 15:31:54.079"]

The question though is why R displays the milliseconds as "078", when
it is clearly "079"...

-h



On Mon, Jan 18, 2016 at 8:55 PM, ce  wrote:
> Dear all,
>
> I have this code :
>
> library(xts)
> a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
> "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index 
> = structure(c(1453137885.23,
> 1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
> 1L), .Dimnames = list(NULL, "value"))
>
> a
>
> a["2016-01-18 12:24:45.230"]
> #value
> #2016-01-18 12:24:45 1
>
> a["2016-01-18 15:31:54.078"]
> #   value
>
> Why second line doesn't show the value? Something to do with miliseconds ?
> Thanks
> CE
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] xts/zoo index problem?

2016-01-18 Thread ce
Dear all,

I have this code :

library(xts)
a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct", 
"POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index = 
structure(c(1453137885.23, 
1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L, 
1L), .Dimnames = list(NULL, "value"))

a

a["2016-01-18 12:24:45.230"]
#value
#2016-01-18 12:24:45 1

a["2016-01-18 15:31:54.078"]
#   value

Why second line doesn't show the value? Something to do with miliseconds ?
Thanks 
CE

__
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] LSD value

2016-01-18 Thread Jianling Fan
Thanks David,

That's exactly what I need! Thanks very much for your example.

Best regards,

Julian






On 18 January 2016 at 13:00, David L Carlson  wrote:
> Providing us with a reproducible example, makes it much easier to answer your 
> question. The object returned by LSD.test() is completely different from the 
> object described in the "Value" section of its manual page which makes things 
> confusing. If you look at the first example on the manual page:
>
>> library(agricolae)
>> data(sweetpotato)
>> model<-aov(yield~virus, data=sweetpotato)
>> out <- LSD.test(model,"virus", p.adj="bonferroni")
>> out
> $statistics
> Mean  CV  MSerror LSD
>   27.625 17.1666 22.48917 13.4704
>
> $parameters
>   Df ntr bonferroni alpha   test name.t
>8   4   3.478879  0.05 bonferroni  virus
>
> $means
>   yield  std r   LCL  UCL  Min  Max
> cc 24.4 3.609709 3 18.086268 30.71373 21.7 28.5
> fc 12.86667 2.159475 3  6.552935 19.18040 10.6 14.9
> ff 36.3 7.333030 3 30.019601 42.64707 28.0 41.8
> oo 36.9 4.30 3 30.586268 43.21373 32.1 40.4
>
> $comparison
> NULL
>
> $groups
>   trtmeans  M
> 1  oo 36.9  a
> 2  ff 36.3  a
> 3  cc 24.4 ab
> 4  fc 12.86667  b
>
> So you can get the LSD statistic with
>
>> out$statistics$LSD
> [1] 13.4704
>> out$statistics[4]
>   LSD
>   13.4704
>> out[[1]][4]
>   LSD
>   13.4704
>
> -
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jianling Fan
> Sent: Monday, January 18, 2016 10:47 AM
> To: r-help
> Subject: [R] LSD value
>
> Hello, everyone,
>
> I am using LSD.test() from package "agricolae" to do my anova
> analysis. I know I can calculate LSD value by its equation
> t*sqrt(MSE*2/n), but I am wondering if there is a code or something
> that can give the LSD value more directly in R?
>
> Thanks!
>
> Julian
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Installation of R Rmpi and snow on cluster running Platform MPI and PBS Pro

2016-01-18 Thread Segovia, Andrea
Hello,

I am new to R support. I am trying to install R on a compute cluster running 
Platform MPI and PBS Pro.

I have installed R, Rmpi and snow - at first glance successfully.

When I try to run a simple Rmpi program, however, I get a Segmentation fault on 
mpi send. 

The error messages reads as follows:

segoviaa@c01 Rmpi_examples]$ mpirun -e PATH=/export/opt/R-3.2.2/bin:$PATH 
-hostfile myhostfile -np 8 R --no-save -q  <
mpi_test2.r

*** caught segfault ***
ddress 0x78, cause 'memory not mapped'

raceback:
1: .Call("mpi_send", .force.type(x, type), as.integer(type), as.integer(dest),  
   as.integer(tag), as.integer(comm), P
CKAGE = "Rmpi")
2: mpi.send(x = scmd.arg, type = 4, dest = i, tag = 5 + i, comm = comm)
3: mpi.bcast.cmd(.mpi.worker.exec, tag = tag, ret = ret, simplify = simplify,   
  comm = comm)
4: mpi.remote.exec(mpi.get.processor.name(), comm = comm)
5: unlist(mpi.remote.exec(mpi.get.processor.name(), comm = comm))
6: slave.hostinfo(1)
borting ...
PI Application rank 0 killed before MPI_Finalize() with signal 11

The program I am running is:

[segoviaa@c01 Rmpi_examples]$ more Rmpi_test2.r
# The corresponding cluster of processes is already pre-constructed with mpirun.

# This where the main work happens
mpi.remote.exec(paste("Rank",mpi.comm.rank(),"on",Sys.info()[c("nodename")]))

# Shut down the cluster and clean up any remaining connections between machines.
mpi.close.Rslaves()
mpi.quit()

The Rprofile is located in the running directory, it is being run, and looks 
like this:

# This R profile can be used when a cluster does not allow spawning or a job
# scheduler is required to launch any parallel jobs. Saving this file as
# .Rprofile in the working directory or root directory. For unix platform, run
# mpirun -n [cpu numbers] R --no-save -q

# Another way is to modify R_home_dir/bin/R by adding the following line after
# R_HOME_DIR
# R_PROFILE=${R_HOME_DIR}/library/Rmpi/Rprofile; export R_PROFILE

# For windows platform with mpich2, use mpiexec wrapper and specify a working
# directory where .Rprofile is inside.

# Cannot be used as Rprofile.site because it will not work

# If no CPU consumptions of slaves while waiting are desirable, change
# nonblocak=FALSE to nonblock=TRUE and change sleep time accordingly

# Following system libraries are not loaded automatically. So manual loads are
# needed.
#
library(utils)
library(stats)
library(datasets)
library(grDevices)
library(graphics)
library(methods)

#Change to TRUE if you don't want any slave host info
quiet=FALSE

if (!invisible(library(Rmpi,logical.return = TRUE))){
    warning("Rmpi cannot be loaded")
    q(save = "no")
}

options(error=quote(assign(".mpi.err", FALSE, envir = .GlobalEnv)))

if (mpi.comm.size(0) > 1)
    invisible(mpi.comm.dup(0,1))

if (mpi.comm.rank(0) >0){
    #sys.load.image(".RData",TRUE)
    options(echo=FALSE)
    .comm <- 1
    mpi.barrier(0)
    repeat
                try(eval(mpi.bcast.cmd(rank=0,comm=.comm, nonblock=FALSE, 
sleep=0.1)),TRUE)
        if (is.loaded("mpi_comm_disconnect"))
        mpi.comm.disconnect(.comm)
    else mpi.comm.free(.comm)
    mpi.quit()
}

if (mpi.comm.rank(0)==0) {
    #options(echo=TRUE)
    mpi.barrier(0)
    if(mpi.comm.size(0) > 1 && !quiet)
        slave.hostinfo(1)
}

.Last <- function(){
    if (is.loaded("mpi_initialize")){
        if (mpi.comm.size(1) > 1){
            print("Please use mpi.close.Rslaves() to close slaves")
            mpi.close.Rslaves(comm=1)
        }
    }
    print("Please use mpi.quit() to quit R")
    mpi.quit()
}

I am not certain that the R installation was successful, either. I installed R 
as follows:

./configure --prefix=/export/opt/R-3.2.2
make
make check
make install
make install-pdf
make install-tests


I installed Rmpi as follows:

[root@c01 R-3.2.2]# R CMD INSTALL Rmpi_0.6-5.tar.gz 
"--configure-args=--with-Rmpi-include=/export/opt/platform_mpi/include/ 
--with-Rmpi-libpath=/export/opt/platform_mpi/lib/linux_amd64/ 
--with-Rmpi-type=OPENMPI"

I installed snow as follows:

[root@c01 R-3.2.2]# R CMD INSTALL snow -l /export/opt/R-3.2.2
* installing *source* package 'snow' ...
** package 'snow' successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (snow)

Any suggestions would be greatly appreciated.

Thank you,
Andrea

Andrea Segovia - Team Lead, HPC Services 
Science Portfolio/Portfolio de la Science 
Shared Services Canada/Services partagés Canada 

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


Re: [R] LSD value

2016-01-18 Thread David L Carlson
Providing us with a reproducible example, makes it much easier to answer your 
question. The object returned by LSD.test() is completely different from the 
object described in the "Value" section of its manual page which makes things 
confusing. If you look at the first example on the manual page:

> library(agricolae)
> data(sweetpotato)
> model<-aov(yield~virus, data=sweetpotato)
> out <- LSD.test(model,"virus", p.adj="bonferroni")
> out
$statistics
Mean  CV  MSerror LSD
  27.625 17.1666 22.48917 13.4704

$parameters
  Df ntr bonferroni alpha   test name.t
   8   4   3.478879  0.05 bonferroni  virus

$means
  yield  std r   LCL  UCL  Min  Max
cc 24.4 3.609709 3 18.086268 30.71373 21.7 28.5
fc 12.86667 2.159475 3  6.552935 19.18040 10.6 14.9
ff 36.3 7.333030 3 30.019601 42.64707 28.0 41.8
oo 36.9 4.30 3 30.586268 43.21373 32.1 40.4

$comparison
NULL

$groups
  trtmeans  M
1  oo 36.9  a
2  ff 36.3  a
3  cc 24.4 ab
4  fc 12.86667  b

So you can get the LSD statistic with

> out$statistics$LSD
[1] 13.4704
> out$statistics[4]
  LSD
  13.4704
> out[[1]][4]
  LSD
  13.4704

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


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jianling Fan
Sent: Monday, January 18, 2016 10:47 AM
To: r-help
Subject: [R] LSD value

Hello, everyone,

I am using LSD.test() from package "agricolae" to do my anova
analysis. I know I can calculate LSD value by its equation
t*sqrt(MSE*2/n), but I am wondering if there is a code or something
that can give the LSD value more directly in R?

Thanks!

Julian

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

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


Re: [R] tikzDevice and Sweave

2016-01-18 Thread Yihui Xie
Yeah, the philosophy of knitr from the very beginning is that if you
want to draw a plot, simply draw it, and knitr will take care of the
rest of work (http://i.imgur.com/jrwbX.jpg). You rarely need to think
about graphical devices or LaTeX or a specific output format. With
knitr, the example can be reduced to the absolutely minimal:

\documentclass{article}
\begin{document}
<>=
plot(sin, -pi, 2*pi, main = "A stand alone TikZ plot", xlab = "x",
ylab = "sin(x)")
@
\end{document}


Regards,
Yihui
--
Yihui Xie 
Web: http://yihui.name


On Mon, Jan 18, 2016 at 6:30 AM, Duncan Murdoch
 wrote:
> On 18/01/2016 6:12 AM, Naresh Gurbuxani wrote:
>>
>> Duncan,
>>
>> Many thanks for looking at my code and for your suggestion.
>>
>> Your solution works.  But my problem is different.  This code gives me a
>> tex file with a lot of tikz code.  If there are several graphs in the
>> document, then tex file become very large.  I would like the code to result
>> in a pdf file for each graph.  When this pdf file is included in the tex
>> file, the tex file is more readable.
>
>
> You probably don't want to do that -- tikz outputs LaTeX code, so you'd need
> to run pdflatex once in every figure in your document.  And you probably
> shouldn't care:  when using Sweave, the .tex file is not really of interest.
> Concentrate on the .Rnw file as the source file.
> However, sometimes you need to deal with other people...
>
> You can easily redirect tikz output to a file, and \input{} that file. Just
> change the figure chunk to
>
> <>=
> library(tikzDevice)
> # added height and width
> tikz(file = "tikzFig.tex", width = 4, height = 3)
> plot(sin, -pi, 2*pi, main = "A stand alone TikZ plot", xlab = "x", ylab =
> "sin(x)")
> dummy <- dev.off()
> cat("\\input{tikzFig.tex}")
> @
>
> As mentioned, this is a bit simpler in knitr.
>
> Duncan Murdoch
>
>
>> Naresh
>>
>> 
>>>
>>> From: dulca...@bigpond.com
>>> To: r-help@r-project.org
>>> Date: Mon, 18 Jan 2016 14:17:42 +1000
>>> Subject: Re: [R] tikzDevice and Sweave
>>>
>>> Hi
>>>
>>> I use Sweave and some tikz in latex but not in Sweave
>>>
>>> Your problem is that you left out Sweave in the preamble
>>> It must be in the preamble of any Sweave document
>>>
>>> I added sizing so that it is not off the page.
>>> I do not know if Sweave options will cover this or you have to set it.
>>> eg
>>> \setkeys{Gin}{width=1.0\textwidth}
>>>
>>> \documentclass{article}
>>> \usepackage{tikz}
>>> \usepackage{Sweave}
>>>
>>> \begin{document}
>>>
>>> Figure~\ref{tikzExampleFig} is an example of \texttt{tikzDevice} package.
>>>
>>> \begin{figure}
>>> \begin{center}
>>>
>>> <>=
>>> # % <>=
>>>
>>> # %<>=
>>> # setwd("/Users/nareshgurbuxani/Documents/tex/tikz")
>>> library(tikzDevice)
>>>
>>> # added height and width
>>> tikz(console = TRUE, width = 4, height = 3)
>>> plot(sin, -pi, 2*pi, main = "A stand alone TikZ plot", xlab = "x", ylab =
>>> "sin(x)")
>>> dummy <- dev.off()
>>> @
>>>
>>> \caption{Example of tikz graph}
>>> \label{tikzExampleFig}
>>> \end{center}
>>> \end{figure}
>>>
>>> \end{document}
>>>
>>> If this is an example for a larger document then have a look at the latex
>>> hyperref package
>>>
>>> Regards
>>>
>>> Duncan
>>>
>>> Duncan Mackay
>>> Department of Agronomy and Soil Science
>>> University of New England
>>> Armidale NSW 2351
>>> Email: home: mac...@northnet.com.au
>>>
>>> -Original Message-
>>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Naresh
>>> Gurbuxani
>>> Sent: Monday, 18 January 2016 06:54
>>> To: R-help@r-project.org
>>> Subject: Re: [R] tikzDevice and Sweave
>>>
>>> Resending as a useable example
>>>
>>> \documentclass{article}
>>> \usepackage{tikz}
>>>
>>> \begin{document}
>>>
>>> Figure~\ref{tikzExampleFig} is an example of \texttt{tikzDevice} package.
>>>
>>> \begin{figure}
>>> \begin{center}
>>>
>>> <>=
>>> # % <>=
>>>
>>> # %<>=
>>> # setwd("/Users/nareshgurbuxani/Documents/tex/tikz")
>>> library(tikzDevice)
>>>
>>> tikz(console = TRUE)
>>> plot(sin, -pi, 2*pi, main = "A stand alone TikZ plot", xlab = "x", ylab =
>>> "sin(x)")
>>> dummy <- dev.off()
>>> @
>>>
>>> \caption{Example of tikz graph}
>>> \label{tikzExampleFig}
>>> \end{center}
>>> \end{figure}
>>>
>>> \end{document}
>>>
>>> 

 Subject: Re: [R] tikzDevice and Sweave
 To: naresh_gurbux...@hotmail.com; r-help@r-project.org
 From: murdoch.dun...@gmail.com
 Date: Sun, 17 Jan 2016 15:40:24 -0500

 On 17/01/2016 3:25 PM, Naresh Gurbuxani wrote:
>
> I want to use tikz() function in tikzDevice package so that it
> generates
>>>
>>> a pdf file to be included in the bigger tex file. Below code works, but
>>> directly inserts tikz commands in the output tex file.
>
> This works:
> <>=
> This does not work:
> <>=
> Full code is given below:
> \documentclass{article}\usepackage{tikz}
> Figure~\ref{tikzExampleFig} is and an example of \texttt{

[R] LSD value

2016-01-18 Thread Jianling Fan
Hello, everyone,

I am using LSD.test() from package "agricolae" to do my anova
analysis. I know I can calculate LSD value by its equation
t*sqrt(MSE*2/n), but I am wondering if there is a code or something
that can give the LSD value more directly in R?

Thanks!

Julian

__
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] Order of formula terms in model.matrix

2016-01-18 Thread Guelman, Leo
Thanks Peter. That make sense. Nevertheless, what comes at a surprise to me 
(and maybe to others) is that one can potentially get different fits by simply 
swapping the terms in the model formula. 

Best,
Leo. 

-Original Message-
From: peter dalgaard [mailto:pda...@gmail.com] 
Sent: 2016, January, 18 11:16 AM
To: Guelman, Leo
Cc: r-help@r-project.org; Charles C. Berry
Subject: Re: [R] Order of formula terms in model.matrix


On 18 Jan 2016, at 16:49 , Guelman, Leo  wrote:

> Is it really the same model?


No, and I didn't say that they would be. I did say that they would be in the 
all-factor case, which does seem to be right:

> df$trt <- factor(df$trt)
> fit1 <- glm(y ~ x1:trt + f1:trt, data = df, family = binomial)
> fit2 <- glm(y ~ f1:trt + x1:trt, data = df, family = binomial) 
> plot(fitted(fit1), fitted(fit2)) # still differs
> df$x1 <- factor(sample(c(-1,1), 100, replace = TRUE))
> fit1 <- glm(y ~ x1:trt + f1:trt, data = df, family = binomial)
> fit2 <- glm(y ~ f1:trt + x1:trt, data = df, family = binomial) 
> plot(fitted(fit1), fitted(fit2)) # looks like it's on diagonal 
> identical(fitted(fit1), fitted(fit2)) # wrong check
[1] FALSE
> all.equal(fitted(fit1), fitted(fit2)) # better
[1] TRUE


-pd


>  
> Following the example provided by Lars:
>  
> set.seed(1)
> x1 <- rnorm(100)
> f1 <- factor(sample(letters[1:3], 100, replace = TRUE)) trt <- 
> sample(c(-1,1), 100, replace = TRUE) y <- factor(sample(c(0,1), 100, 
> T)) df <- data.frame(y=y, x1=x1, f1=f1, trt=trt)
>  
> fit1 <- glm(y ~ x1:trt + f1:trt, data = df, family = binomial)
> coef(fit1)
>  
> fit2 <- glm(y ~ f1:trt + x1:trt, data = df, family = binomial)
> coef(fit2)
>  
> identical(fitted(fit1), fitted(fit2))
> [1] FALSE
>  
>  
>  
> __
> _
> 
> If you received this email in error, please advise the sender (by return 
> email or otherwise) immediately. You have consented to receive the attached 
> electronically at the above-noted email address; please retain a copy of this 
> confirmation for future reference.
> 
> Si vous recevez ce courriel par erreur, veuillez en aviser l'expéditeur 
> immédiatement, par retour de courriel ou par un autre moyen. Vous avez 
> accepté de recevoir le(s) document(s) ci-joint(s) par voie électronique à 
> l'adresse courriel indiquée ci-dessus; veuillez conserver une copie de cette 
> confirmation pour les fins de reference future.
> 

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 
Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

___
If you received this email in error, please advise the sender (by return email 
or otherwise) immediately. You have consented to receive the attached 
electronically at the above-noted email address; please retain a copy of this 
confirmation for future reference.  

Si vous recevez ce courriel par erreur, veuillez en aviser l'expéditeur 
immédiatement, par retour de courriel ou par un autre moyen. Vous avez accepté 
de recevoir le(s) document(s) ci-joint(s) par voie électronique à l'adresse 
courriel indiquée ci-dessus; veuillez conserver une copie de cette confirmation 
pour les fins de reference future.

__
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] Order of formula terms in model.matrix

2016-01-18 Thread peter dalgaard

On 18 Jan 2016, at 16:49 , Guelman, Leo  wrote:

> Is it really the same model?


No, and I didn't say that they would be. I did say that they would be in the 
all-factor case, which does seem to be right:

> df$trt <- factor(df$trt)
> fit1 <- glm(y ~ x1:trt + f1:trt, data = df, family = binomial)
> fit2 <- glm(y ~ f1:trt + x1:trt, data = df, family = binomial)
> plot(fitted(fit1), fitted(fit2)) # still differs
> df$x1 <- factor(sample(c(-1,1), 100, replace = TRUE))
> fit1 <- glm(y ~ x1:trt + f1:trt, data = df, family = binomial)
> fit2 <- glm(y ~ f1:trt + x1:trt, data = df, family = binomial)
> plot(fitted(fit1), fitted(fit2)) # looks like it's on diagonal
> identical(fitted(fit1), fitted(fit2)) # wrong check
[1] FALSE
> all.equal(fitted(fit1), fitted(fit2)) # better
[1] TRUE


-pd


>  
> Following the example provided by Lars:
>  
> set.seed(1)
> x1 <- rnorm(100)
> f1 <- factor(sample(letters[1:3], 100, replace = TRUE))
> trt <- sample(c(-1,1), 100, replace = TRUE)
> y <- factor(sample(c(0,1), 100, T))
> df <- data.frame(y=y, x1=x1, f1=f1, trt=trt)
>  
> fit1 <- glm(y ~ x1:trt + f1:trt, data = df, family = binomial)
> coef(fit1)
>  
> fit2 <- glm(y ~ f1:trt + x1:trt, data = df, family = binomial)
> coef(fit2)
>  
> identical(fitted(fit1), fitted(fit2))
> [1] FALSE
>  
>  
>  
> ___
> 
> If you received this email in error, please advise the sender (by return 
> email or otherwise) immediately. You have consented to receive the attached 
> electronically at the above-noted email address; please retain a copy of this 
> confirmation for future reference.
> 
> Si vous recevez ce courriel par erreur, veuillez en aviser l'expéditeur 
> immédiatement, par retour de courriel ou par un autre moyen. Vous avez 
> accepté de recevoir le(s) document(s) ci-joint(s) par voie électronique à 
> l'adresse courriel indiquée ci-dessus; veuillez conserver une copie de cette 
> confirmation pour les fins de reference future.
> 

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] Order of formula terms in model.matrix

2016-01-18 Thread Guelman, Leo
Is it really the same model?

Following the example provided by Lars:

set.seed(1)
x1 <- rnorm(100)
f1 <- factor(sample(letters[1:3], 100, replace = TRUE))
trt <- sample(c(-1,1), 100, replace = TRUE)
y <- factor(sample(c(0,1), 100, T))
df <- data.frame(y=y, x1=x1, f1=f1, trt=trt)

fit1 <- glm(y ~ x1:trt + f1:trt, data = df, family = binomial)
coef(fit1)

fit2 <- glm(y ~ f1:trt + x1:trt, data = df, family = binomial)
coef(fit2)

identical(fitted(fit1), fitted(fit2))
[1] FALSE



___
If you received this email in error, please advise the sender (by return email 
or otherwise) immediately. You have consented to receive the attached 
electronically at the above-noted email address; please retain a copy of this 
confirmation for future reference.  

Si vous recevez ce courriel par erreur, veuillez en aviser l'expéditeur 
immédiatement, par retour de courriel ou par un autre moyen. Vous avez accepté 
de recevoir le(s) document(s) ci-joint(s) par voie électronique à l'adresse 
courriel indiquée ci-dessus; veuillez conserver une copie de cette confirmation 
pour les fins de reference future.

[[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] Strange behavior with S3 class

2016-01-18 Thread S Ellison
> This is "bugged":
>   > str(test1)List of 1$ justaname: chr "justaname"- attr(*, "class")= chr 
> "eem"
> This is ok:> str(test2)List of 1$ sample: chr "justaname"- attr(*, 
> "class")= chr
> "eem2"
> It seems that override of the "<-" is causing problem since in str(test1) the
> variable name is not preserved.
> Any idea?

Compare 
str(test1)
# List of 1
#  $ justaname: chr "justaname"
#  - attr(*, "class")= chr "eem"

str(unclass(test1))
# List of 1
#  $ sample: chr "justaname"

That says the internal variable name is preserved but while it still has the 
'eem' class the name is reported differently.
That is presumably because you defined a 'names' function for objects of class 
'eem' which returns the contents of $sample as the name, not "sample". Looks 
like str is using your names.eem method to extract the name of each component 
of your object, which is kind of what redefining 'names' asks for. And just to 
demonstrate that str does indeed use the current class's names method: 

names.eem <- function(x, ...){  "AnotherName"}
str(test1)
# List of 1
#  $ AnotherName: chr "justaname"
#  - attr(*, "class")= chr "eem"

So it isn't your '<-', it's because you overrode 'names'


S Ellison



***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
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] read in csv.-data file with blanks and missing values

2016-01-18 Thread David McPearson
swizz-john wrote:

> Hi people,
> 
> my task is to analyse data that is formatted like this.
> 
>
date,bid,name,w1,w2,w3,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,debt2mkt,cds,equity
> 28jul2009,1,"ABN Amro",56.5,
> 29jul2009,1,"ABN Amro",56.5,
> 30jul2009,1,"ABN Amro",55,
> 31jul2009,1,"ABN Amro",55,
> 03aug2009,1,"ABN
Amro",.35,.4,.45,,.71,.96,1.05,1.14,1.22,1.26,1.3,1.35,1.38,1.41,1.44,,55,
> 06aug2009,1,"ABN
Amro",.35,.4,.45,,.72,.92,1,1.1,1.18,1.2,1.23,1.28,1.32,1.35,1.38,,53.75,

##
## Er - no, it'snot.
##

> 
> It has 21 columns but not every column has a value, some only have commas
instead.
> 
> My file is named: test_data.csv and it is attached here:
> test_data.csv

If I open your attachment with Excel I see what you have above. If I open it
with LibreOffice Calc I see the same as you are getting in R.

When I open test_dta.csv with a plain text editor (I used Tinn-R, Notepad
should also work) I see why you are not getting wjat you expect. Take a
careful look at the data: All the commas are contained withing matching pairs
of quotation marks. Hence they are all treated as plain text by sensible
software.

Hope this helps,
Dave.

PS - If this comes through as html can someone flame me, please. I'm using a
web based service and don't yet know what format it sends...
Thanks.


South Africas premier free email service - www.webmail.co.za

__
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] tikzDevice and Sweave

2016-01-18 Thread Duncan Murdoch

On 18/01/2016 6:12 AM, Naresh Gurbuxani wrote:

Duncan,

Many thanks for looking at my code and for your suggestion.

Your solution works.  But my problem is different.  This code gives me a tex 
file with a lot of tikz code.  If there are several graphs in the document, 
then tex file become very large.  I would like the code to result in a pdf file 
for each graph.  When this pdf file is included in the tex file, the tex file 
is more readable.


You probably don't want to do that -- tikz outputs LaTeX code, so you'd 
need to run pdflatex once in every figure in your document.  And you 
probably shouldn't care:  when using Sweave, the .tex file is not really 
of interest.  Concentrate on the .Rnw file as the source file.

However, sometimes you need to deal with other people...

You can easily redirect tikz output to a file, and \input{} that file. 
Just change the figure chunk to


<>=
library(tikzDevice)
# added height and width
tikz(file = "tikzFig.tex", width = 4, height = 3)
plot(sin, -pi, 2*pi, main = "A stand alone TikZ plot", xlab = "x", ylab 
= "sin(x)")

dummy <- dev.off()
cat("\\input{tikzFig.tex}")
@

As mentioned, this is a bit simpler in knitr.

Duncan Murdoch


Naresh



From: dulca...@bigpond.com
To: r-help@r-project.org
Date: Mon, 18 Jan 2016 14:17:42 +1000
Subject: Re: [R] tikzDevice and Sweave

Hi

I use Sweave and some tikz in latex but not in Sweave

Your problem is that you left out Sweave in the preamble
It must be in the preamble of any Sweave document

I added sizing so that it is not off the page.
I do not know if Sweave options will cover this or you have to set it.
eg
\setkeys{Gin}{width=1.0\textwidth}

\documentclass{article}
\usepackage{tikz}
\usepackage{Sweave}

\begin{document}

Figure~\ref{tikzExampleFig} is an example of \texttt{tikzDevice} package.

\begin{figure}
\begin{center}

<>=
# % <>=

# %<>=
# setwd("/Users/nareshgurbuxani/Documents/tex/tikz")
library(tikzDevice)

# added height and width
tikz(console = TRUE, width = 4, height = 3)
plot(sin, -pi, 2*pi, main = "A stand alone TikZ plot", xlab = "x", ylab =
"sin(x)")
dummy <- dev.off()
@

\caption{Example of tikz graph}
\label{tikzExampleFig}
\end{center}
\end{figure}

\end{document}

If this is an example for a larger document then have a look at the latex
hyperref package

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Naresh
Gurbuxani
Sent: Monday, 18 January 2016 06:54
To: R-help@r-project.org
Subject: Re: [R] tikzDevice and Sweave

Resending as a useable example

\documentclass{article}
\usepackage{tikz}

\begin{document}

Figure~\ref{tikzExampleFig} is an example of \texttt{tikzDevice} package.

\begin{figure}
\begin{center}

<>=
# % <>=

# %<>=
# setwd("/Users/nareshgurbuxani/Documents/tex/tikz")
library(tikzDevice)

tikz(console = TRUE)
plot(sin, -pi, 2*pi, main = "A stand alone TikZ plot", xlab = "x", ylab =
"sin(x)")
dummy <- dev.off()
@

\caption{Example of tikz graph}
\label{tikzExampleFig}
\end{center}
\end{figure}

\end{document}



Subject: Re: [R] tikzDevice and Sweave
To: naresh_gurbux...@hotmail.com; r-help@r-project.org
From: murdoch.dun...@gmail.com
Date: Sun, 17 Jan 2016 15:40:24 -0500

On 17/01/2016 3:25 PM, Naresh Gurbuxani wrote:

I want to use tikz() function in tikzDevice package so that it generates

a pdf file to be included in the bigger tex file. Below code works, but
directly inserts tikz commands in the output tex file.

This works:
<>=
This does not work:
<>=
Full code is given below:
\documentclass{article}\usepackage{tikz}
Figure~\ref{tikzExampleFig} is and an example of \texttt{tikzDevice}

package.

\begin{figure}\begin{center}
<>=
library(tikzDevice)tikz(console = TRUE)plot(sin, -pi, pi, main = "A stand

alone TikZ plot", xlab = "x", ylab = "sin(x)")dummy <- dev.off()@

\caption{Example of tikz

graph}\label{tikzExampleFig}\end{center}\end{figure}

\end{document}


Your example isn't usable -- please post in plain text, not HTML.

I can't tell whether you are trying to use Sweave or knitr. If you're
using knitr, see the discussion of dev = "tikz" in
. If you're using Sweave, you probably need
pgfSweave.

Duncan Murdoch



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

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

Re: [R] Problems with data structure when using plsr() from package pls

2016-01-18 Thread CG Pettersson
Again: thanks a lot for all your suggestions, the problem is now solved.

This combination of calls finally did the trick:

> n96 <- as.matrix(n96)
> frame2 <- data.frame(gushVM, n96=I(n96))
> str(frame2)
'data.frame':   15 obs. of  2 variables:
 $ gushVM: num  2 23.2 14.3 40.9 32.8 29.1 0 79 0 0 ...
 $ n96   : AsIs [1:15, 1:96] 34.24092067 31.79041592 52.00961175 36.10294958 
47.02360183 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr  "1" "2" "3" "4" ...
  .. ..$ : chr  "n96 1" "n96 2" "n96 3" "n96 4" ...

Which is exactly the same structure as the supplied datasets in package pls, 
and works well with plsr()

Thanks a lot for the help!
/CG


-Ursprungligt meddelande-
Från: CG Pettersson 
Skickat: den 17 januari 2016 13:30
Till: 'S Ellison'; Sarah Goslee
Kopia: r-help@r-project.org
Ämne: SV: [R] Problems with data structure when using plsr() from package pls

Thanks a lot to both of you for the effort and nice suggestions.

I have tested all suggested coding variants and I do succeed in changing the 
data structure, for example like this (with a test using str())

> names(n96) <- paste("n96", 1:96)
> frame1 <- cbind(gushVM, n96)
>  
> str(frame1)
'data.frame':   15 obs. of  97 variables:
 $ gushVM: num  2 23.2 14.3 40.9 32.8 29.1 0 79 0 0 ...
 $ n96 1 : num  34.2 31.8 52 36.1 47 ...
 $ n96 2 : num  23.3 21.1 33.6 24.3 31.5 ...
 $ n96 3 : num  97.5 80.6 89.5 97.3 122.4 ...
 $ n96 4 : num  79.2 64.4 79.9 79.4 99.7 ...
 $ n96 5 : num  24.1 25.8 45.3 25.8 45.2 ...
 $ n96 6 : num  83.1 81.7 119 82.6 140.2 ...
 $ n96 7 : num  10 10.8 16.2 10.9 15.9 ...
 $ n96 8 : num  129 124 180 135 202 ...
 $ n96 9 : num  58.8 52.9 84 61.7 76.7 ...   and so on until row variable 96 
inside n96

But using this dataframe with plsr() results in the same error message, like:

> pls1 <- plsr(gushVM ~ n96, data = frame1)
Error in model.frame.default(formula = gushVM ~ n96, data = frame1) : 
  invalid type (list) for variable 'n96'

Which is the same message as ever. The same happens with the other two 
suggestions, even if the detail structure of "n96" inside "frame" differ a 
little whe I test it with str().
Still stuck, but thanks all the same!

/CG

-Ursprungligt meddelande-
Från: S Ellison [mailto:s.elli...@lgcgroup.com] 
Skickat: den 15 januari 2016 14:39
Till: Sarah Goslee; CG Pettersson
Kopia: r-help@r-project.org
Ämne: RE: [R] Problems with data structure when using plsr() from package pls


> > I am trying to make pls-regression using plsr() from package pls, 
> > with Mevik & Wehrens (2007) as tutorial and the datasets from the package.
> > Everything works real nice as long as I use the supplied datasets, 
> > but I don´t understand how to prepare my own data.
> > This is what I have done:
> >
> > > frame1 <- data.frame(gushVM, I(n96))

Reading ?plsr examples and inspecting the data they use, you need to arrange 
frame1 so that it has the data from n96 included as columns with names of the 
from "n96.xxx" whre xxx can be numbers, names etc.

If n96 is a data frame, try something like
names(n96) <- paste("n96", 1:96)
frame1 <- cbind(gushVM, n96)

pls1 <- plsr(gushVM ~ n96, data = frame1)


If n96 is a matrix, 

frame1 <- data.frame(gushVM, n96=n96)

should also give you a data frame with names of the right format.

I() wrapped round a matrix or data frame does nothing like what is needed if 
you include it in a data frame construction, so either things have changed 
since the tutorial was written, or the authors were not handling a matrix or 
data frame with I().

S Ellison






***
This email and any attachments are confidential. Any use, copying or disclosure 
other than by the intended recipient is unauthorised. If you have received this 
message in error, please notify the sender immediately via +44(0)20 8943 7000 
or notify postmas...@lgcgroup.com and delete this message and any copies from 
your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
__
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] Problems with data structure when using plsr() from package pls

2016-01-18 Thread Bjørn-Helge Mevik
S Ellison  writes:

> Reading ?plsr examples and inspecting the data they use, you need to arrange
> frame1 so that it has the data from n96 included as columns with names of the
> from "n96.xxx" whre xxx can be numbers, names etc.

No, you do not. :)  plsr() is happy with a data frame where n96 is a
single variable consisting of a matrix.  And this is the recommended way
for matrices with a lot of coloumns.  Which is what you get with

frame1 <- data.frame(gushVM, n96 = I(n96))

if n96 is a matrix, or

frame1 <- data.frame(gushVM, n96 = I(as.matrix(n96)))

if it is a data.frame.

> If n96 is a data frame, try something like
> names(n96) <- paste("n96", 1:96) 
> frame1 <- cbind(gushVM, n96)
>
> pls1 <- plsr(gushVM ~ n96, data = frame1)

Have you actually tried this?  It doesn't work:  For instance:

> gushVM <- 1:5
> n96 <- data.frame(a=1:5, b=2:6)
> names(n96) <- paste("n96", 1:2)
> n96
  n96 1 n96 2
1 1 2
2 2 3
3 3 4
4 4 5
5 5 6
> frame1 <- cbind(gushVM, n96)
> frame1
  gushVM n96 1 n96 2
1  1 1 2
2  2 2 3
3  3 3 4
4  4 4 5
5  5 5 6
> dim(frame1)
[1] 5 3
> pls1 <- plsr(gushVM ~ n96, data = frame1)
Error in model.frame.default(formula = gushVM ~ n96, data = frame1) : 
  invalid type (list) for variable 'n96'

The reason is that frame1 does _not_ contain a variable called 'n96', so
plsr() (or actually model.frame.default()) searches in the global work
space, where it finds a _data.frame_ n96.  A data.frame is a list.
Hence the error message.

> If n96 is a matrix, 
>
> frame1 <- data.frame(gushVM, n96=n96)
>
> should also give you a data frame with names of the right format.

It does not:

> n96 <- as.matrix(n96)
> frame1 <- data.frame(gushVM, n96=n96)
> frame1
  gushVM n96.n96.1 n96.n96.2
1  1 1 2
2  2 2 3
3  3 3 4
4  4 4 5
5  5 5 6
> dim(frame1)
[1] 5 3
> names(frame1)
[1] "gushVM""n96.n96.1" "n96.n96.2"

So the data frame still does not have any variable named 'n96'.  The
only reason

> pls1 <- plsr(gushVM ~ n96, data = frame1)

seems to work, is that the 'n96' variable it now finds in the global
environment, happens to be a matrix

> class(n96)
[1] "matrix"

If that wasn't there, you would get an error:

> rm(n96)
> pls1 <- plsr(gushVM ~ n96, data = frame1)
Error in eval(expr, envir, enclos) : object 'n96' not found

> I() wrapped round a matrix or data frame does nothing like what is needed if
> you include it in a data frame construction, so either things have changed
> since the tutorial was written, or the authors were not handling a matrix or
> data frame with I().

Yes it does. :)  Nothing (substantial) has changed, and we did/do handle
matrices with I():

> n96 <- matrix(1:10, ncol=2)
> n96
 [,1] [,2]
[1,]16
[2,]27
[3,]38
[4,]49
[5,]5   10
> frame1 <- data.frame(gushVM, I(n96))
> frame1
  gushVM n96.1 n96.2
1  1 1 6
2  2 2 7
3  3 3 8
4  4 4 9
5  5 510
> dim(frame1)
[1] 5 2
> names(frame1)
[1] "gushVM" "n96"   
> rm(n96)
> pls1 <- plsr(gushVM ~ n96, data = frame1)
> pls1
Partial least squares regression , fitted with the kernel algorithm.
Call:
plsr(formula = gushVM ~ n96, data = frame1)

-- 
Regards,
Bjørn-Helge Mevik

__
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] Split Strings

2016-01-18 Thread Miluji Sb
Thank you everyone for the codes and the link. They work well!

Mr. Lemon, thank you for the detailed code and the explanations. I
appreciate it. One thing though, in the last line

sapply(split_strings,fill_strings,list(max_length,element_sets))

should it be unlist instead of list - I get this error "Error in
FUN(X[[i]], ...) : (list) object cannot be coerced to type 'integer'".
Thanks again!



On Mon, Jan 18, 2016 at 9:19 AM, Jim Lemon  wrote:

> Hi Miluji,
> While the other answers are correct in general, I noticed that your
> request was for the elements of an incomplete string to be placed in the
> same positions as in the complete strings. Perhaps this will help:
>
> strings<-list("pc_m2_45_ssp3_wheat","pc_m2_45_ssp3_wheat",
>  "ssp3_maize","m2_wheat","pc_m2_45_ssp3_maize")
> split_strings<-strsplit(unlist(strings),"_")
> max_length <- max(sapply(split_strings,length))
> complete_sets<-split_strings[sapply(split_strings,length)==max_length]
> element_sets<-list()
>
> # build a list with the unique elements of each complete string
> for(i in 1:max_length)
>  element_sets[[i]]<-unique(sapply(complete_sets,"[",i))
>
> # function to guess the position of the elements in a partial string
> # and return them in the hopefully correct positions
> fill_strings<-function(split_string,max_length,element_sets) {
>  if(length(split_string) < max_length) {
>   new_split_string<-rep(NA,max_length)
>   for(i in 1:length(split_string)) {
>for(j in 1:length(complete_sets)) {
> if(grep(split_string[i],element_sets[j]))
>  new_split_string[j]<-split_string[i]
>}
>   }
>   return(new_split_string)
>  }
>  return(split_string)
> }
>
> # however, if you know that the incomplete strings will always
> # be composed of the last elements in the complete strings
> fill_strings<-function(split_string,max_length) {
>  lenstring<-length(split_string)
>  if(lenstring < max_length)
>   split_string<-c(rep(NA,max_length-lenstring),split_string)
>  return(split_string)
> }
>
> sapply(split_strings,fill_strings,list(max_length,element_sets))
>
> Jim
>
> On Mon, Jan 18, 2016 at 7:56 AM, Miluji Sb  wrote:
>
>> I have a list of strings of different lengths and would like to split each
>> string by underscore "_"
>>
>> pc_m2_45_ssp3_wheat
>> pc_m2_45_ssp3_wheat
>> ssp3_maize
>> m2_wheat
>>
>> I would like to separate each part of the string into different columns
>> such as
>>
>> pc m2 45 ssp3 wheat
>>
>> But because of the different lengths - I would like NA in the columns for
>> the variables have fewer parts such as
>>
>> NA NA NA m2 wheat
>>
>> I have tried unlist(strsplit(x, "_")) to split, it works for one variable
>> but not for the list - gives me "non-character argument" error. I would
>> highly appreciate any help. Thank you!
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

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


Re: [R] Split Strings

2016-01-18 Thread Jim Lemon
Hi Miluji,
While the other answers are correct in general, I noticed that your request
was for the elements of an incomplete string to be placed in the same
positions as in the complete strings. Perhaps this will help:

strings<-list("pc_m2_45_ssp3_wheat","pc_m2_45_ssp3_wheat",
 "ssp3_maize","m2_wheat","pc_m2_45_ssp3_maize")
split_strings<-strsplit(unlist(strings),"_")
max_length <- max(sapply(split_strings,length))
complete_sets<-split_strings[sapply(split_strings,length)==max_length]
element_sets<-list()

# build a list with the unique elements of each complete string
for(i in 1:max_length)
 element_sets[[i]]<-unique(sapply(complete_sets,"[",i))

# function to guess the position of the elements in a partial string
# and return them in the hopefully correct positions
fill_strings<-function(split_string,max_length,element_sets) {
 if(length(split_string) < max_length) {
  new_split_string<-rep(NA,max_length)
  for(i in 1:length(split_string)) {
   for(j in 1:length(complete_sets)) {
if(grep(split_string[i],element_sets[j]))
 new_split_string[j]<-split_string[i]
   }
  }
  return(new_split_string)
 }
 return(split_string)
}

# however, if you know that the incomplete strings will always
# be composed of the last elements in the complete strings
fill_strings<-function(split_string,max_length) {
 lenstring<-length(split_string)
 if(lenstring < max_length)
  split_string<-c(rep(NA,max_length-lenstring),split_string)
 return(split_string)
}

sapply(split_strings,fill_strings,list(max_length,element_sets))

Jim

On Mon, Jan 18, 2016 at 7:56 AM, Miluji Sb  wrote:

> I have a list of strings of different lengths and would like to split each
> string by underscore "_"
>
> pc_m2_45_ssp3_wheat
> pc_m2_45_ssp3_wheat
> ssp3_maize
> m2_wheat
>
> I would like to separate each part of the string into different columns
> such as
>
> pc m2 45 ssp3 wheat
>
> But because of the different lengths - I would like NA in the columns for
> the variables have fewer parts such as
>
> NA NA NA m2 wheat
>
> I have tried unlist(strsplit(x, "_")) to split, it works for one variable
> but not for the list - gives me "non-character argument" error. I would
> highly appreciate any help. Thank you!
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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