Re: [R] Fwd: problem with kmeans

2014-04-28 Thread Peter Langfelder
You are using the wrong algorithm. You want Partitioning around
Medoids (PAM, function pam), not k-means. PAM is also known as
k-medoids, which is where the confusion may come from.

use

library(cluster)

cl = pam(dis, 4)

and see if you get what you want.

HTH,

Peter



On Mon, Apr 28, 2014 at 9:15 PM, cassie jones  wrote:
> Dear R-users,
>
> I am trying to run kmeans on a set comprising of 100 observations. But R
> somehow can not figure out the true underlying groups, although other
> software such as Jmp, MINITAB are producing the desired result.
>
> Following is a brief example of what I am doing.
>
> library(stringdist)
> test=c('hematolgy','hemtology','oncology','onclogy',
> 'oncolgy','dermatolgy','dermatoloy','dematology',
> 'neurolog','nerology','neurolgy','nerology')
>
> dis=stringdistmatrix(test,test, method = "lv")
>
> set.seed(123)
> cl=kmeans(dis,4)
>
>
> grp_cl=vector('list',4)
>
> for(i in 1:4)
> {
> grp_cl[[i]]=test[which(cl$cluster==i)]
> }
> grp_cl
>
> [[1]]
> [1] "oncology" "onclogy"
>
> [[2]]
> [1] "neurolog" "nerology" "neurolgy" "nerology"
>
> [[3]]
> [1] "oncolgy"
>
> [[4]]
> [1] "hematolgy"  "hemtology"  "dermatolgy" "dermatoloy" "dematology"
>
> In the above example, the 'test' variable consists of a set of
> terminologies with various typos and I am trying to group the similar types
> of words based on their string distance. Unfortunately kmeans is not able
> to replicate the following result that the other software are able to
> produce.
> [[1]]
> [1] "oncology" "onclogy"  "oncolgy"
>
> [[2]]
> [1] "neurolog" "nerology" "neurolgy" "nerology"
>
> [[3]]
> [1] "dermatolgy" "dermatoloy" "dematology"
>
> [[4]]
> [1] "hematolgy"  "hemtology"
>
>
> Does anyone know if there is a way out, I have heard from a lot of people
> that multivariate analysis in R does not produce the desired result most of
> the time. Any help is really appreciated.
>
>
> Thanks in advance.
>
>
> Cassie
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] R Cairo Installation - Cannot find cairo.h!

2014-04-28 Thread Peter Langfelder
I **think** the linker is missing a directive to actually link in the
cairo library. Try adding -lcairo to the LIB flags, something like

export CAIRO_LIBS='-L${HOME}/usr/local/lib -lcairo'

or simply

export CAIRO_LIBS=-l${HOME}/usr/local/lib/libcairo.so

I am not 100% sure of the syntax, but this may work.

Note that my pkg-config gives me this for cairo:

$ pkg-config --cflags --libs cairo
-I/usr/include/cairo -I/usr/include/glib-2.0
-I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1
-I/usr/include/freetype2 -I/usr/include/libpng15 -I/usr/include/libdrm
 -lcairo

There are many more -I directives than what you had, but I'm not sure
if all of it is really necessary. if your configure or compilation
fail, it is something to keep in mind.

HTH,

Peter

On Mon, Apr 28, 2014 at 8:16 PM, Fong Chun Chan  wrote:
> Thanks Peter. From the config.log file, the issue appears to occur here at
> the "/home/fong/Cairo/conftest.c:28: undefined reference to `cairo_create'"
>
>
> -
>
> configure:3631: gcc -std=gnu99 -o conftest -g -O2
> -I/home/fong/usr/local/include/cairo   conftest.c -lz
> -L/home/fong/usr/local/lib >&5
> configure:3631: $? = 0
> configure:3648: result: -lz
> configure:3657: checking whether Cairo programs can be compiled
> configure:3671: gcc -std=gnu99 -o conftest -g -O2
> -I/home/fong/usr/local/include/cairo   conftest.c -lz
> -L/home/fong/usr/local/lib >&5
> /tmp/ccIr2WlB.o: In function `main':
> /home/fong/Cairo/conftest.c:28: undefined reference to `cairo_create'
> collect2: ld returned 1 exit status
> configure:3671: $? = 1
> configure: failed program was:
> | /* confdefs.h */
> | #define PACKAGE_NAME "Cairo"
> | #define PACKAGE_TARNAME "cairo"
> | #define PACKAGE_VERSION "1.3"
> | #define PACKAGE_STRING "Cairo 1.3"
> | #define PACKAGE_BUGREPORT "simon.urba...@r-project.org"
> | #define PACKAGE_URL ""
> | #define STDC_HEADERS 1
> | #define HAVE_SYS_WAIT_H 1
> | #define HAVE_SYS_TYPES_H 1
> | #define HAVE_SYS_STAT_H 1
> | #define HAVE_STDLIB_H 1
> | #define HAVE_STRING_H 1
> | #define HAVE_MEMORY_H 1
> | #define HAVE_STRINGS_H 1
> | #define HAVE_INTTYPES_H 1
> | #define HAVE_STDINT_H 1
> | #define HAVE_UNISTD_H 1
> | #define HAVE_STRING_H 1
> | #define HAVE_SYS_TIME_H 1
> | #define HAVE_UNISTD_H 1
> | /* end confdefs.h.  */
>
>
> On Mon, Apr 28, 2014 at 7:50 PM, Peter Langfelder
>  wrote:
>>
>> On Mon, Apr 28, 2014 at 7:14 PM, Fong Chun Chan 
>> wrote:
>> > Hi Peter,
>> >
>> > Thanks for the reply. I don't have access to the package manager
>> > unfortunately as I am working on a cluster where I don't have admin. So
>> > everything has to installed into my ~/export
>> > CAIRO_LIBS=-L${HOME}/usr/local/lib
>> > export CAIRO_CFLAGS=-I${HOME}/usr/local/include
>> > /local. I tried looking into homebrew/linuxbrew, but the gcc compiler
>> > (4.1.2) is not suitable for linuxbrew and installing a new gcc compiler
>> > isn't a simply endeavor from source.
>>
>> I see - in that case I think you are on the right track.
>>
>> >
>> > I installed cairo from source specifically the
>> > http://cairographics.org/releases/cairo-1.12.16.tar.xz download. What is
>> > this cairo-devel you are referring to? It seems to be something related
>> > to
>> > using the package manager?
>>
>> If you install from source, you (usually) also get the development
>> files (the content of cairo-devel) by default.
>>
>> >
>> > In any case, your second point about the "-L for library directories,
>> > and -I
>> > for
>> > include directories" was actually useful. Rather than remove those lines
>> > (as
>> > that didn't help), I modified my ~/.bashrc a bit (I am also limited in
>> > my
>> > understanding paths)
>> >
>> > export CAIRO_LIBS=-L${HOME}/usr/local/lib
>> > export CAIRO_CFLAGS=-I${HOME}/usr/local/include
>> >
>> > This actually got around that issue! But now I've run into another
>> > issue:
>> >
>> > checking for pkg-config... /home/fong/usr/local/bin/pkg-config
>> > configure: CAIRO_CFLAGS=-I/home/fong/usr/local/include/cairo
>> > checking if R was compiled with the RConn patch... no
>> > checking cairo.h usability... yes
>> > checking cairo.h presence... yes
>> > checking for cairo.h... yes
>> > checking for PNG support in Cairo... yes
>> > checking for ATS font support in Cairo... no
>> > configure: CAIRO_LIBS=-L/home/fong/usr/local/lib
>> > checking for library containing deflate... -lz
>> > checking whether Cairo programs can be compiled... configure: error:
>> > Cannot
>> > compile a simple Cairo program. See config.log for details.
>> > ERROR: configuration failed for package ‘Cairo’
>>
>> If you look at the config.log file and post the releavant part (don't
>> post the whole thing, it's huge), I (or R compiling experts) can try
>> to help you more.
>>
>> Peter
>
>

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

Re: [R] Fwd: problem with kmeans

2014-04-28 Thread Ranjan Maitra
Cassie,

I am sorry but do you even know what k-means does? That it is a locally
optimal algorithm. That different software implement the same algorithm
differently.

FYI, R uses the Hartigan-Wong (1979) algorithm by default, which is
probably the most efficient out there. 

I suggest you first go to a multivariate statistics class before
passing such sweeping statements. (Btw, did these same "some people"
tell you that most other software do not provide the kinds of broad
abilities which R provides, and therefore are not even comparable.)

And then, please read the help function for how to "improve" your run
of k-means using R.  

HTH,
Ranjan


On Tue, 29 Apr 2014 09:45:18 +0530 cassie jones
 wrote:

> Dear R-users,
> 
> I am trying to run kmeans on a set comprising of 100 observations. But R
> somehow can not figure out the true underlying groups, although other
> software such as Jmp, MINITAB are producing the desired result.
> 
> Following is a brief example of what I am doing.
> 
> library(stringdist)
> test=c('hematolgy','hemtology','oncology','onclogy',
> 'oncolgy','dermatolgy','dermatoloy','dematology',
> 'neurolog','nerology','neurolgy','nerology')
> 
> dis=stringdistmatrix(test,test, method = "lv")
> 
> set.seed(123)
> cl=kmeans(dis,4)
> 
> 
> grp_cl=vector('list',4)
> 
> for(i in 1:4)
> {
> grp_cl[[i]]=test[which(cl$cluster==i)]
> }
> grp_cl
> 
> [[1]]
> [1] "oncology" "onclogy"
> 
> [[2]]
> [1] "neurolog" "nerology" "neurolgy" "nerology"
> 
> [[3]]
> [1] "oncolgy"
> 
> [[4]]
> [1] "hematolgy"  "hemtology"  "dermatolgy" "dermatoloy" "dematology"
> 
> In the above example, the 'test' variable consists of a set of
> terminologies with various typos and I am trying to group the similar types
> of words based on their string distance. Unfortunately kmeans is not able
> to replicate the following result that the other software are able to
> produce.
> [[1]]
> [1] "oncology" "onclogy"  "oncolgy"
> 
> [[2]]
> [1] "neurolog" "nerology" "neurolgy" "nerology"
> 
> [[3]]
> [1] "dermatolgy" "dermatoloy" "dematology"
> 
> [[4]]
> [1] "hematolgy"  "hemtology"
> 
> 
> Does anyone know if there is a way out, I have heard from a lot of people
> that multivariate analysis in R does not produce the desired result most of
> the time. Any help is really appreciated.
> 
> 
> Thanks in advance.
> 
> 
> Cassie
> 
>   [[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.
> 


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


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

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


[R] Fwd: problem with kmeans

2014-04-28 Thread cassie jones
Dear R-users,

I am trying to run kmeans on a set comprising of 100 observations. But R
somehow can not figure out the true underlying groups, although other
software such as Jmp, MINITAB are producing the desired result.

Following is a brief example of what I am doing.

library(stringdist)
test=c('hematolgy','hemtology','oncology','onclogy',
'oncolgy','dermatolgy','dermatoloy','dematology',
'neurolog','nerology','neurolgy','nerology')

dis=stringdistmatrix(test,test, method = "lv")

set.seed(123)
cl=kmeans(dis,4)


grp_cl=vector('list',4)

for(i in 1:4)
{
grp_cl[[i]]=test[which(cl$cluster==i)]
}
grp_cl

[[1]]
[1] "oncology" "onclogy"

[[2]]
[1] "neurolog" "nerology" "neurolgy" "nerology"

[[3]]
[1] "oncolgy"

[[4]]
[1] "hematolgy"  "hemtology"  "dermatolgy" "dermatoloy" "dematology"

In the above example, the 'test' variable consists of a set of
terminologies with various typos and I am trying to group the similar types
of words based on their string distance. Unfortunately kmeans is not able
to replicate the following result that the other software are able to
produce.
[[1]]
[1] "oncology" "onclogy"  "oncolgy"

[[2]]
[1] "neurolog" "nerology" "neurolgy" "nerology"

[[3]]
[1] "dermatolgy" "dermatoloy" "dematology"

[[4]]
[1] "hematolgy"  "hemtology"


Does anyone know if there is a way out, I have heard from a lot of people
that multivariate analysis in R does not produce the desired result most of
the time. Any help is really appreciated.


Thanks in advance.


Cassie

[[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] R Cairo Installation - Cannot find cairo.h!

2014-04-28 Thread Fong Chun Chan
Thanks Peter. From the config.log file, the issue appears to occur here at
the "*/home/fong/Cairo/conftest.c:28: undefined reference to
`cairo_create'"*


 -

configure:3631: gcc -std=gnu99 -o conftest -g -O2
 -I/home/fong/usr/local/include/cairo   conftest.c -lz
-L/home/fong/usr/local/lib >&5
configure:3631: $? = 0
configure:3648: result: -lz
configure:3657: checking whether Cairo programs can be compiled
configure:3671: gcc -std=gnu99 -o conftest -g -O2
 -I/home/fong/usr/local/include/cairo   conftest.c -lz
 -L/home/fong/usr/local/lib >&5
/tmp/ccIr2WlB.o: In function `main':
*/home/fong/Cairo/conftest.c:28: undefined reference to `cairo_create'*
collect2: ld returned 1 exit status
configure:3671: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "Cairo"
| #define PACKAGE_TARNAME "cairo"
| #define PACKAGE_VERSION "1.3"
| #define PACKAGE_STRING "Cairo 1.3"
| #define PACKAGE_BUGREPORT "simon.urba...@r-project.org"
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_WAIT_H 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_STRING_H 1
| #define HAVE_SYS_TIME_H 1
| #define HAVE_UNISTD_H 1
| /* end confdefs.h.  */


On Mon, Apr 28, 2014 at 7:50 PM, Peter Langfelder <
peter.langfel...@gmail.com> wrote:

> On Mon, Apr 28, 2014 at 7:14 PM, Fong Chun Chan 
> wrote:
> > Hi Peter,
> >
> > Thanks for the reply. I don't have access to the package manager
> > unfortunately as I am working on a cluster where I don't have admin. So
> > everything has to installed into my ~/export
> > CAIRO_LIBS=-L${HOME}/usr/local/lib
> > export CAIRO_CFLAGS=-I${HOME}/usr/local/include
> > /local. I tried looking into homebrew/linuxbrew, but the gcc compiler
> > (4.1.2) is not suitable for linuxbrew and installing a new gcc compiler
> > isn't a simply endeavor from source.
>
> I see - in that case I think you are on the right track.
>
> >
> > I installed cairo from source specifically the
> > http://cairographics.org/releases/cairo-1.12.16.tar.xz download. What is
> > this cairo-devel you are referring to? It seems to be something related
> to
> > using the package manager?
>
> If you install from source, you (usually) also get the development
> files (the content of cairo-devel) by default.
>
> >
> > In any case, your second point about the "-L for library directories,
> and -I
> > for
> > include directories" was actually useful. Rather than remove those lines
> (as
> > that didn't help), I modified my ~/.bashrc a bit (I am also limited in my
> > understanding paths)
> >
> > export CAIRO_LIBS=-L${HOME}/usr/local/lib
> > export CAIRO_CFLAGS=-I${HOME}/usr/local/include
> >
> > This actually got around that issue! But now I've run into another issue:
> >
> > checking for pkg-config... /home/fong/usr/local/bin/pkg-config
> > configure: CAIRO_CFLAGS=-I/home/fong/usr/local/include/cairo
> > checking if R was compiled with the RConn patch... no
> > checking cairo.h usability... yes
> > checking cairo.h presence... yes
> > checking for cairo.h... yes
> > checking for PNG support in Cairo... yes
> > checking for ATS font support in Cairo... no
> > configure: CAIRO_LIBS=-L/home/fong/usr/local/lib
> > checking for library containing deflate... -lz
> > checking whether Cairo programs can be compiled... configure: error:
> Cannot
> > compile a simple Cairo program. See config.log for details.
> > ERROR: configuration failed for package 'Cairo'
>
> If you look at the config.log file and post the releavant part (don't
> post the whole thing, it's huge), I (or R compiling experts) can try
> to help you more.
>
> Peter
>

[[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] problems with cloropleth map of Japan

2014-04-28 Thread Guadalupe Bastos
Hi:
I have recently started working with creating maps in R. I have been able
to create cloropleth maps for Europe without a problem.
However, when I try doing the same for Japan, which shapefile is downloaded
from the website http://gadm.org/country , R stops working. The message
that pops up is "Error: R for windows GUI front-end has stopped working". I
can see the map was created at the back of the screen, but I'm not able to
save it.
I don't know if this is a bug or if there's something I'm doing wrong. The
idea of this code is that Japan only has a value for all the country of my
variable (the value is 2.15). And what I want is for Japan to be shaded in
the corresponding color. So it will be only one color for the whole country.
Here is the code. You'll need to download the shapefile from
http://gadm.org/country and un-zip in the directory you are working.

I hope you can help me. Thanks in advance!

rm(list=ls(all=TRUE))
#--
#USER INSTRUCTIONS:
#First time user: install packages
#install.packages(c("sp", "maptools", "rgdal"), dependencies=TRUE)  #It's
very important that this package is installed this way
  #Install this package if it's the first time you run this
#install.packages("ggplot2")
#install.packages("ggmap")
#install.packages("rgeos")
#install.packages("foreign")

#
# Libraries we use:
library(maptools)
library(ggplot2)
library(ggmap)
library(rgeos)
library(foreign)


#---
# JAPAN
#---
#Download shapefile from
#http://gadm.org/country

# read administrative boundaries (change folder appropriately)
japMap <- readShapePoly(fn="JPN_adm/JPN_adm0.shp")

summary(japMap)
# data
japEdu <- data.frame(1,2); names(japEdu) <- c('GEO','Value')
japEdu$GEO <- 114
japEdu$Value <- 2.15

japMapDf=fortify(japMap, region='ID_0')

# merge map and data
japEduMapDf <- merge(japMapDf, japEdu, by.x="id", by.y="GEO")
japEduMapDf <- japEduMapDf[order(japEduMapDf$order),]

# ggplot mapping
# data layer
m0 <- ggplot(data=japEduMapDf)

# empty map (only borders)
m1 <- m0 + geom_path(aes(x=long, y=lat, group=group), color='gray') +
coord_equal()

# fill with education expenditure data
m2 <- m1 + geom_polygon(aes(x=long, y=lat, group=group, fill=Value))
m2
__
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] Color points in princomp() plot

2014-04-28 Thread Boris Steipe
At first I thought this is easy: use the same strategy you use for all of these 
types of questions. Plot with type="n" to suppress output of points, then use 
points() or text() to get the colors and shapes and whatnot you need ...

Turns out biplot() does not use a type argument ...

... and you can't simply fake it by setting cex to a really small value, 
because biplot() actually creates two plots: one for the scores, then one for 
the axes. And once you have plotted the axes, the axis limits for the plot have 
changed, and you can't easily apply points() anymore.

... and you can't easily rescale, because ... well, have a look at the code.

The code, incidentally can be found with getAnywhere().

So what's the solution ...

Since I've wanted this capability for some time, I modified the original 
biplot() to accept a type parameter type={"t" (Default) | "p" | "n"}. For "t", 
the function behaves almost exactly as before. For "p" it plots points, and 
should accept all the usual arguments for that. For "n" it plots nothing except 
the axes. You can then add the points as desired.

I also added two parameters col.arrows = "red", and col.text = "black" to have 
extra control.

Here is an example. (Note, you have to load the function, below, first.





library(MASS)
data(crabs)
PRC <- prcomp(crabs[, 4:8])

myBiplot(PRC)
myBiplot(PRC, choices=2:3, cex = 0.7, col.text="#445599") # much as before


# use filled points, color by the value found in column 4 of the data
r <- range(crabs[,4]) 
n <- 15
cv <- cm.colors(n)  
c <- cv[cut(crabs[,4],n)]  
myBiplot(PRC, choices=2:3, type = "p", pch=20, col=c, col.arrows = "#FF6600")


# finally: plot nothing then use points() for detailed control 
myBiplot(PRC, choices=2:3, type = "n")  # no points

# blue/orange crab males/females - as given by rows in the data
points(PRC$x[  1: 50, 2:3], pch=21, bg="#0066FF")
points(PRC$x[ 51:100, 2:3], pch=24, bg="#0066FF")
points(PRC$x[101:150, 2:3], pch=21, bg="#FF6600")
points(PRC$x[151:200, 2:3], pch=24, bg="#FF6600")




Enjoy,
Boris

==
myBiplot <- function (x, choices = 1L:2L, scale = 1,
  pc.biplot = FALSE, var.axes = TRUE,
  type = "t",
  col,
  col.arrows = "#FF",
  col.text = "#00",
  cex = rep(par("cex"), 2),
  expand = 1, 
  xlabs = NULL, ylabs = NULL,
  xlim = NULL, ylim = NULL, 
  main = NULL, sub = NULL,
  xlab = NULL, ylab = NULL, 
  arrow.len = 0.1,
  ...
  )

{
if (length(choices) != 2L) 
stop("length of choices must be 2")
if (!length(scores <- x$x)) 
stop(gettextf("object '%s' has no scores", deparse(substitute(x))), 
domain = NA)
if (is.complex(scores)) 
stop("biplots are not defined for complex PCA")

lam <- x$sdev[choices]
n <- NROW(scores)
lam <- lam * sqrt(n)

if (scale < 0 || scale > 1) 
warning("'scale' is outside [0, 1]")
if (scale != 0) 
lam <- lam^scale
else lam <- 1
if (pc.biplot) 
lam <- lam/sqrt(n)

y <- t(t(x$rotation[, choices]) * lam)
x <- t(t(scores[, choices])/lam)  # note that from here on
  # x is no longer the PC object
  # originally pased into the function
n <- nrow(x)
p <- nrow(y)

if (missing(xlabs)) {
xlabs <- dimnames(x)[[1L]]
if (is.null(xlabs)) 
xlabs <- 1L:n
}
xlabs <- as.character(xlabs)
dimnames(x) <- list(xlabs, dimnames(x)[[2L]])

if (missing(ylabs)) {
ylabs <- dimnames(y)[[1L]]
if (is.null(ylabs)) 
ylabs <- paste("Var", 1L:p)
}
ylabs <- as.character(ylabs)
dimnames(y) <- list(ylabs, dimnames(y)[[2L]])

if (length(cex) == 1L) 
cex <- c(cex, cex)

unsigned.range <- function(x) c(-abs(min(x, na.rm = TRUE)), 
abs(max(x, na.rm = TRUE)))
rangx1 <- unsigned.range(x[, 1L])
rangx2 <- unsigned.range(x[, 2L])
rangy1 <- unsigned.range(y[, 1L])
rangy2 <- unsigned.range(y[, 2L])

if (missing(xlim) && missing(ylim)) 
xlim <- ylim <- rangx1 <- rangx2 <- range(rangx1, rangx2)
else if (missing(xlim)) 
xlim <- rangx1
else if (missing(ylim)) 
ylim <- rangx2

ratio <- max(rangy1/rangx1, rangy2/rangx2)/expand
on.exit(par(op))
op <- par(pty = "s")
if (!is.null(main)) 
op <- c(op, par(mar = par("mar") + c(0, 0, 1, 0)))

# first, plot scores - either normally, or as row labels
if (type == "p") {
plot(x, type = type, xlim = xlim, ylim = ylim, col = col, 
xlab = xlab, ylab = ylab, sub = sub, main = main, ...)
}
else if (type =

Re: [R] R Cairo Installation - Cannot find cairo.h!

2014-04-28 Thread Fong Chun Chan
Hi Peter,

Thanks for the reply. I don't have access to the package manager
unfortunately as I am working on a cluster where I don't have admin. So
everything has to installed into my ~/export CAIRO_LIBS=-L${HOME}/usr/local/
lib
export CAIRO_CFLAGS=-I${HOME}/usr/local/include
/local. I tried looking into homebrew/linuxbrew, but the gcc compiler
(4.1.2) is not suitable for linuxbrew and installing a new gcc compiler
isn't a simply endeavor from source.

I installed cairo from source specifically the
http://cairographics.org/releases/cairo-1.12.16.tar.xz download. What is
this cairo-devel you are referring to? It seems to be something related to
using the package manager?

In any case, your second point about the "-L for library directories, and
-I for
include directories" was actually useful. Rather than remove those lines
(as that didn't help), I modified my ~/.bashrc a bit (I am also limited in
my understanding paths)

export CAIRO_LIBS=-L${HOME}/usr/local/lib
export CAIRO_CFLAGS=-I${HOME}/usr/local/include

This actually got around that issue! But now I've run into another issue:

checking for pkg-config... /home/fong/usr/local/bin/pkg-config
configure: CAIRO_CFLAGS=-I/home/fong/usr/local/include/cairo
checking if R was compiled with the RConn patch... no
checking cairo.h usability... yes
checking cairo.h presence... yes
checking for cairo.h... yes
checking for PNG support in Cairo... yes
checking for ATS font support in Cairo... no
configure: CAIRO_LIBS=-L/home/fong/usr/local/lib
checking for library containing deflate... -lz
checking whether Cairo programs can be compiled... configure: error: Cannot
compile a simple Cairo program. See config.log for details.
ERROR: configuration failed for package 'Cairo'


On Mon, Apr 28, 2014 at 6:36 PM, Peter Langfelder <
peter.langfel...@gmail.com> wrote:

> Make sure you have cairo-devel installed, and remove the lines
>
> export CAIRO_LIBS=${HOME}/usr/local/lib
> export CAIRO_CFLAGS=${HOME}/usr/local/include
>
> from your .bashrc file. If you have cairo-devel installed normally,
> the headers should be found with default settings of all search paths.
> The settings you have are, to the best of my somewhat limited
> knowledge, wrong - you need to prefix each directory with an
> appropriate compiler flags (-L for library directories, and -I for
> include directories). Anyway, as I said, 1. install cairo-devel using
> your package manager, and 2. remove the two lines from .bashrc.
>
> Peter
>
>
> On Mon, Apr 28, 2014 at 12:26 PM, Fong Chun Chan 
> wrote:
> > Hi,
> >
> > I am trying to get the R package Cairo installed. I've been successfully
> in
> > building the latest version of Cairo library (1.12.16,
> > http://cairographics.org/) from source and installed into ~/usr/local
> using
> >
> > ./configure --prefix=/home/fong/usr/local
> >
> > I set the my CAIRO_LIBS and CAIRO_CLAGS environment variables in my
> > ~/.bashrc:
> >
> > export CAIRO_LIBS=${HOME}/usr/local/lib
> > export CAIRO_CFLAGS=${HOME}/usr/local/include
> >
> > When I try to install Cairo in R using:
> >
> > install.packages('Cairo')
> >
> > I get the following error:
> >
> > checking for pkg-config... /home/fong/usr/local/bin/pkg-config
> > configure: CAIRO_CFLAGS=/home/fong/usr/local/include/cairo
> > checking if R was compiled with the RConn patch... no
> > checking cairo.h usability... no
> > checking cairo.h presence... no
> > checking for cairo.h... no
> > configure: error: Cannot find cairo.h! Please install cairo (
> > http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS
> correspondingly.
> > ERROR: configuration failed for package 'Cairo'
> >
> > But I can see the cairo.h header in /home/fong/usr/local/include/cairo. I
> > been trying to scouring the internet for answers, but I can't seem to
> find
> > any work for me. If anyone has any suggestions that would be helpful.
> >
> > Thanks
> >
> >> sessionInfo()
> > R version 3.1.0 (2014-04-10)
> > Platform: x86_64-unknown-linux-gnu (64-bit)
> >
> > locale:
> >  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
> > LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
> > LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
> >  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C  LC_ADDRESS=C
> >   LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8
> > LC_IDENTIFICATION=C
> >
> > attached base packages:
> > [1] stats graphics  grDevices utils datasets  methods   base
> >
> > other attached packages:
> > [1] vimcom.plus_0.9-93 setwidth_1.0-3 colorout_1.0-2
> >
> > loaded via a namespace (and not attached):
> > [1] tcltk_3.1.0 tools_3.1.0
> >
> > [[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 dele

Re: [R] R Cairo Installation - Cannot find cairo.h!

2014-04-28 Thread Peter Langfelder
Make sure you have cairo-devel installed, and remove the lines

export CAIRO_LIBS=${HOME}/usr/local/lib
export CAIRO_CFLAGS=${HOME}/usr/local/include

from your .bashrc file. If you have cairo-devel installed normally,
the headers should be found with default settings of all search paths.
The settings you have are, to the best of my somewhat limited
knowledge, wrong - you need to prefix each directory with an
appropriate compiler flags (-L for library directories, and -I for
include directories). Anyway, as I said, 1. install cairo-devel using
your package manager, and 2. remove the two lines from .bashrc.

Peter


On Mon, Apr 28, 2014 at 12:26 PM, Fong Chun Chan  wrote:
> Hi,
>
> I am trying to get the R package Cairo installed. I've been successfully in
> building the latest version of Cairo library (1.12.16,
> http://cairographics.org/) from source and installed into ~/usr/local using
>
> ./configure --prefix=/home/fong/usr/local
>
> I set the my CAIRO_LIBS and CAIRO_CLAGS environment variables in my
> ~/.bashrc:
>
> export CAIRO_LIBS=${HOME}/usr/local/lib
> export CAIRO_CFLAGS=${HOME}/usr/local/include
>
> When I try to install Cairo in R using:
>
> install.packages('Cairo')
>
> I get the following error:
>
> checking for pkg-config... /home/fong/usr/local/bin/pkg-config
> configure: CAIRO_CFLAGS=/home/fong/usr/local/include/cairo
> checking if R was compiled with the RConn patch... no
> checking cairo.h usability... no
> checking cairo.h presence... no
> checking for cairo.h... no
> configure: error: Cannot find cairo.h! Please install cairo (
> http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS correspondingly.
> ERROR: configuration failed for package 'Cairo'
>
> But I can see the cairo.h header in /home/fong/usr/local/include/cairo. I
> been trying to scouring the internet for answers, but I can't seem to find
> any work for me. If anyone has any suggestions that would be helpful.
>
> Thanks
>
>> sessionInfo()
> R version 3.1.0 (2014-04-10)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
> LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
> LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C  LC_ADDRESS=C
>   LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8
> LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
> [1] vimcom.plus_0.9-93 setwidth_1.0-3 colorout_1.0-2
>
> loaded via a namespace (and not attached):
> [1] tcltk_3.1.0 tools_3.1.0
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] delay evaluation of expression

2014-04-28 Thread William Dunlap
> I have tried, but it doesn't help because when you use the load_all()
> function of devtools,
> the datasets are not lazyLoaded but fully evaluated..

Does LazyLoad:yes in yourPackage/DESCRIPTION work for you when you use
the command line 'R CMD INSTALL yourPackage?

I don't use devtools, but perhaps you should ask its author about how
to do what you want.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Apr 28, 2014 at 3:21 PM, Luca Cerone  wrote:
> Hi William,
> I have tried, but it doesn't help because when you use the load_all()
> function of devtools,
> the datasets are not lazyLoaded but fully evaluated..
>
> I have solved for the moment saving them as rds files (saveRDS()) and
> using the function delayedAssign()
>
> I was wondering if there is some better way to manage this, though.
>
> Thanks for your help,
> Luca
>
> 2014-04-29 0:06 GMT+02:00 William Dunlap :
>> Have you tried putting the line
>>   LazyData; true
>> (or yes) into your package's DESCRIPTION file?
>>
>> See 'Writing R Extensions', section 1.1.6 'Data in packages.'
>>
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>>
>> On Mon, Apr 28, 2014 at 12:45 AM, Luca Cerone  wrote:
>>> Dear all,
>>> in one of my packages I need to load some data from .Rdata files that
>>> are to be used from
>>> some functions (but not all off them). I would like to delay the
>>> loading of this datasets
>>> only when needed. In other cases I successfully used lazyLoad and
>>> delayedAssign(),
>>> but when I try to load a .Rdata file I get this message: Error: cannot
>>> add bindings to a locked environment
>>>
>>> What would be the best way to load such a db only the first time that is 
>>> needed?
>>> Thanks a lot for you help,
>>>
>>> Cheers,
>>> Luca
>>>
>>> __
>>> 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.
>
>
>
> --
> Luca Cerone
>
> Tel: +34 692 06 71 28
> Skype: luca.cerone

__
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] R Cairo Installation - Cannot find cairo.h!

2014-04-28 Thread Rolf Turner


Probably not much help to you, but for what it's worth:

* on my system cairo.h is in /usr/include/cairo

Perhaps the CAIRO flags that you set are not adequately guiding the search.

* you need to have the *development* version of cairo installed; on my 
system (Fedora 17) I do:


sudo yum install cairo-devel.x86_64

to effect this.

* I believe that to get cairo to fly properly you also need to have 
(the development version of) *pango* installed.  On my system I do


sudo yum install pango-devel.x86_64

to effect this.

* I don't know how (or even if it is possible) to get yum to install 
packages to a "custom" location --- as you would apparently need to do, 
since you have created a custom ".../usr/local" under your home directory.


* I was under the impression that to get cairo to fly one needs to do

./configure --with-cairo

All of the foregoing may be a red herring, off the point and have 
nothing to do with the problem that you are having.  I don't really know 
what I'm doing.  I just follow recipes. :-)  Good luck.


cheers,

Rolf Turner

On 29/04/14 07:26, Fong Chun Chan wrote:

Hi,

I am trying to get the R package Cairo installed. I've been successfully in
building the latest version of Cairo library (1.12.16,
http://cairographics.org/) from source and installed into ~/usr/local using

./configure --prefix=/home/fong/usr/local

I set the my CAIRO_LIBS and CAIRO_CLAGS environment variables in my
~/.bashrc:

export CAIRO_LIBS=${HOME}/usr/local/lib
export CAIRO_CFLAGS=${HOME}/usr/local/include

When I try to install Cairo in R using:

install.packages('Cairo')

I get the following error:

checking for pkg-config... /home/fong/usr/local/bin/pkg-config
configure: CAIRO_CFLAGS=/home/fong/usr/local/include/cairo
checking if R was compiled with the RConn patch... no
checking cairo.h usability... no
checking cairo.h presence... no
checking for cairo.h... no
configure: error: Cannot find cairo.h! Please install cairo (
http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS correspondingly.
ERROR: configuration failed for package 'Cairo'

But I can see the cairo.h header in /home/fong/usr/local/include/cairo. I
been trying to scouring the internet for answers, but I can't seem to find
any work for me. If anyone has any suggestions that would be helpful.

Thanks


sessionInfo()

R version 3.1.0 (2014-04-10)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C  LC_ADDRESS=C
   LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=C

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

other attached packages:
[1] vimcom.plus_0.9-93 setwidth_1.0-3 colorout_1.0-2

loaded via a namespace (and not attached):
[1] tcltk_3.1.0 tools_3.1.0


__
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] LogLikelihood of a Distribution Given Fixed Parameters

2014-04-28 Thread Rolf Turner



Indeed it should be lower=FALSE.  Du!  Sorry 'bout that!

cheers,

Rolf

On 29/04/14 02:51, Jacob Warren (RIT Student) wrote:

Thanks Rolf. That took care of it. It should be lower=FALSE through
right? I want the upper tail because my values are right censored?
Regards,
Jake


On Fri, Apr 25, 2014 at 12:50 AM, Rolf Turner mailto:r.tur...@auckland.ac.nz>> wrote:


As usual I am too lazy to fight my way through the rather convoluted
code presented, but it seems to me that you just want to calculate a
log likelihood.  And that is bog-simple:

The log likelihood for i.i.d. data is just the sum of log f(y_i)
where the y_i are your observed values and f() is the density
function of the distribution that you have in mind.

Where there is (right) censoring you take the sum of log f(y_i) over all
the non-censored values and then add k*(1-F(cens.time)) where k is
the number of censored values and F() is the cumulative distribution
function corresponding to f().

In your case it would appear that f(y) = dlnorm(y,1.66,0.25) and
F(y) = plnorm(y,1.66,0.25).  Note that instead of using
1-F(cens.time) you can use plnorm(cens.time,1.66,0.25,__lower=TRUE)
and that instead of taking logs explicitly you can set log=TRUE in
the calls to dlnorm() and plnorm().

cheers,

Rolf Turner


On 25/04/14 07:27, Jacob Warren (RIT Student) wrote:

I'm trying to figure out if there is a way in R to get the
loglikelihood of
a distribution fit to a set of data where the parameter values
are fixed.
For example, I want to simulate data from a given alternate
lognormal
distribution and then I will fit it to a lognormal distribution
with null
parameter values to see what the likelihood of the null
distribution is
given random data from the alternate distribution.

I have been using fitdistrplus for other purposes but I cannot
use it to
fix both parameter values.

Here is an example of what I've been working with...

nullmu<-1.66 #set null mu
altmu<-1.58 #set alt mu
sd.log<-0.25 #set common sigma
cens.time<-6 #if simulated times are greater than this turn them
into right
censored times

#simulating lognormal data (time) from altnative dist
(sim<-rlnorm(n=samplesize, meanlog=altmu, sdlog=sd.log))
#if the time was > cens.time replace time with cens.time
(sim[which(sim>cens.time)]<-__cens.time)
sim

#create a variable indicating censoring
(cens<-sim)
cens[which(sim==cens.time)]<-__NA
cens

#create the data frame to be passed to fitdistcens and fitdist
(x<-data.frame(left=sim,right=__cens))


#if there is censored data use fitdistcens else use fitdist
ifelse(length(which(is.na (__cens)))>0,
simfit<-fitdistcens(censdata=__x, distr="lnorm"),
simfit<-fitdist(data=x[,1], distr="lnorm")
)

#Now I can get the loglikelihood of the MLE fitted distribution
simfit$loglik

#I want to get the loglikelihood of the distribution with the null
parameterization
#This is what I can't get to work
#I can't seem to find any function that allows me to set both
parameter
values
#so I can get to loglikelihood of the of the parameterization
given the data
nulldist<-fitdistcens(__censdata=x, distr="lnorm",
start=list(meanlog=nullmu,
sdlog=sd.log)

#Then I want to do a likelihood ratio test between the two
distributions
pchisq((-2*simfit$loglik--2*__nulldist$loglik), df=2,
lower.tail=FALSE)





__
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] Label customization in R plots

2014-04-28 Thread Jim Lemon

On 04/29/2014 03:47 AM, Ayan Mitra wrote:

Hi all,
  I am a new comer in R . i am trying to figure out how to put in the
label of a plot the basic statistics values like mean=
no of data =
media =
chi-square =


in a box.

I tried a lot to search over the net but couldn't find one as yet.
Thanks in advance for suggestions.


Hi Ayan,
Have a look at the addtable2plot function in the plotrix package.

Jim

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


Re: [R] Color points in princomp() plot

2014-04-28 Thread David Winsemius

On Apr 28, 2014, at 2:41 PM, Noah Silverman wrote:

> Hi,
> 
> The princomp() function has a nice method to generate a pretty biplot of
> the data.  I have some data where the points are divided into a few
> groups.  My intention is to generate a biplot, using princomp, but color
> the points based on group membership.  The hope is that points will show
> some kind of clustering by group in the biplot.
> 
> However, I can't figure out how to indicate individual point color in a
> biplot.  The only setting I found was to indicate a single color for
> *all* the points.
> 
> Any ideas?

Offer some code?

The help page says you can provide a vector for coloring sets of points.

>   [[alternative HTML version deleted]]

And when you do offer code it should be with plain text format.

-- 
David Winsemius
Alameda, CA, USA

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


[R] About Tree Package

2014-04-28 Thread Si Qi L.
Hi,

I will be very grateful if you can give a help on my problem. I am
really stuck on it now. The problem is that I need to construct a
classification tree model and prune tree in order to test the learning
dataset for getting its sensitivity and specificity. But my codes
seems wrong somewhere, will you guys please help me out? Many
thanks!:D

These are codes:

library(tree)
attach(learning.set1)
Status.f<- factor(Status)

tree1<-tree(Status.f  ~ Gender.compl+ X2.4.times.per.month+
Once.a.month+Council.tenant+Living.with.friends.family+Living.with.parents+Owner.occupier+X1.year.to.2.years+X2.to.4.years+X3.months.to.a.year+Less.than.3.months+Empl.compl+Reqloanamount+EmpNetMonthlyPay+Customer_Age+RTI+acc.compl+iic.compl+irb.compl+jbc.compl+jic.compl+jq.compl+kic.compl+lbc.compl+mbc.compl+njc.compl+or.compl+pq.compl+pr.compl+qic.compl+teb.compl+tpb.compl+vbc.compl+yzb.compl+zr.compl,
method="class", data=learning.set1, split="gini")

summary(tree1)
print(tree1)
plot(tree1)
text(tree1)
pfit<-prune.tree(tree1,
k=tree1$cptable[which.min(tree1$cptable[,"xerror"]),"CP"])
plot(pfit, uniform=TRUE)
text(pfit)
pred<-predict(tree1,learning.set1,type="vector")
table1<-table(learning.set1$Status,predict(tree1,type="vector"))
> table1

   01

  0 1429  108

  1  273  164

sum<-sum(learning.set1$Status==pred)/length(pred)
sens<- function(table1) { table1[2,2] / sum(table1[,2]) }
spec<- function(table1) { table1[1,1] / sum(table1[,1]) }
myt<-matrix(c(1429,273,108,164), ncol=2)
sens
spec

__
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] SVEC with exogen vector

2014-04-28 Thread Denise Manfredini
Hi,

I using the package vars to implement a SVEC model, however I have to
include a exogen vector that's not a dummy. I try to use the tsDyn package
but I don't see a solution for my problem.

So I need to know if any package allow me to do that.




thanks,
Denise

[[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] Color points in princomp() plot

2014-04-28 Thread Noah Silverman
Hi,

The princomp() function has a nice method to generate a pretty biplot of
the data.  I have some data where the points are divided into a few
groups.  My intention is to generate a biplot, using princomp, but color
the points based on group membership.  The hope is that points will show
some kind of clustering by group in the biplot.

However, I can't figure out how to indicate individual point color in a
biplot.  The only setting I found was to indicate a single color for
*all* the points.

Any ideas?


-- 
*Noah Silverman, PhD* | UCLA Department of Statistics
8117 Math Sciences Building, Los Angeles, CA 90095

[[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] Label customization in R plots

2014-04-28 Thread Bert Gunter
See also ?panel.text for lattice. This presumes that you know how to
use panel functions, however.

-- Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch




On Mon, Apr 28, 2014 at 12:36 PM, David Winsemius
 wrote:
>
> On Apr 28, 2014, at 10:47 AM, Ayan Mitra wrote:
>
>> Hi all,
>> I am a new comer in R . i am trying to figure out how to put in the
>> label of a plot the basic statistics values like mean=
>>   no of data =
>>   media =
>>   chi-square =
>
> In base graphics you could do this with functions 'rect' and 'text'.
>
> For lattice (and probably ggplot2), there is a gridExtra package that has 
> 'tableGrob'
>
> --
>
> David Winsemius
> Alameda, CA, USA
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
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] Label customization in R plots

2014-04-28 Thread David Carlson
You can also use the legend() function which will draw the box
and arrange the text in a single column (or three columns if you
want a single row). It also has shortcuts for positioning the
box such as "topleft" or "bottomright."

?legend

for more details.

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

-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of David
Winsemius
Sent: Monday, April 28, 2014 2:37 PM
To: Ayan Mitra
Cc: r-help@r-project.org
Subject: Re: [R] Label customization in R plots


On Apr 28, 2014, at 10:47 AM, Ayan Mitra wrote:

> Hi all,
> I am a new comer in R . i am trying to figure out how
to put in the
> label of a plot the basic statistics values like mean=
>   no of data = 
>   media = 
>   chi-square =

In base graphics you could do this with functions 'rect' and
'text'.

For lattice (and probably ggplot2), there is a gridExtra package
that has 'tableGrob'

-- 

David Winsemius
Alameda, CA, USA

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

__
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] Label customization in R plots

2014-04-28 Thread David Winsemius

On Apr 28, 2014, at 10:47 AM, Ayan Mitra wrote:

> Hi all,
> I am a new comer in R . i am trying to figure out how to put in the
> label of a plot the basic statistics values like mean=
>   no of data = 
>   media = 
>   chi-square =

In base graphics you could do this with functions 'rect' and 'text'.

For lattice (and probably ggplot2), there is a gridExtra package that has 
'tableGrob'

-- 

David Winsemius
Alameda, CA, USA

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


[R] R Cairo Installation - Cannot find cairo.h!

2014-04-28 Thread Fong Chun Chan
Hi,

I am trying to get the R package Cairo installed. I've been successfully in
building the latest version of Cairo library (1.12.16,
http://cairographics.org/) from source and installed into ~/usr/local using

./configure --prefix=/home/fong/usr/local

I set the my CAIRO_LIBS and CAIRO_CLAGS environment variables in my
~/.bashrc:

export CAIRO_LIBS=${HOME}/usr/local/lib
export CAIRO_CFLAGS=${HOME}/usr/local/include

When I try to install Cairo in R using:

install.packages('Cairo')

I get the following error:

checking for pkg-config... /home/fong/usr/local/bin/pkg-config
configure: CAIRO_CFLAGS=/home/fong/usr/local/include/cairo
checking if R was compiled with the RConn patch... no
checking cairo.h usability... no
checking cairo.h presence... no
checking for cairo.h... no
configure: error: Cannot find cairo.h! Please install cairo (
http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS correspondingly.
ERROR: configuration failed for package 'Cairo'

But I can see the cairo.h header in /home/fong/usr/local/include/cairo. I
been trying to scouring the internet for answers, but I can't seem to find
any work for me. If anyone has any suggestions that would be helpful.

Thanks

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C  LC_ADDRESS=C
  LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=C

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

other attached packages:
[1] vimcom.plus_0.9-93 setwidth_1.0-3 colorout_1.0-2

loaded via a namespace (and not attached):
[1] tcltk_3.1.0 tools_3.1.0

[[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] About lm(y~1)

2014-04-28 Thread Rui Barradas

Hello,

That will compute a "fit" with coefficient equal to mean(y) and std 
error equal to sd(y)/sqrt(length(y))


Hope this helps,

Rui Barradas

Em 28-04-2014 19:35, Alejo C.S. escreveu:

Dear list,
Reading a function I found this:

lm ( y ~ 1 )

I know that Y ~ -1 + A  is a straight-line with no y-intercept; that is, a
fit forced through (0,0). But I never saw the first example. Any tip?

Thanks in advance!

C.

[[alternative HTML version deleted]]

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



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


[R] Color points in princomp() plot

2014-04-28 Thread Noah Silverman
Hi,

The princomp() function has a nice method to generate a pretty biplot of
the data.  I have some data where the points are divided into a few
groups.  My intention is to generate a biplot, using princomp, but color
the points based on group membership.  The hope is that points will show
some kind of clustering by group in the biplot.

However, I can't figure out how to indicate individual point color in a
biplot.  The only setting I found was to indicate a single color for
*all* the points.

Any ideas?


-- 
*Noah Silverman, PhD* | UCLA Department of Statistics
8117 Math Sciences Building, Los Angeles, CA 90095

[[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] About lm(y~1)

2014-04-28 Thread Alejo C.S.
Dear list,
Reading a function I found this:

lm ( y ~ 1 )

I know that Y ~ -1 + A  is a straight-line with no y-intercept; that is, a
fit forced through (0,0). But I never saw the first example. Any tip?

Thanks in advance!

C.

[[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] about rect.hclust

2014-04-28 Thread chris Jhon
Thank you all for your kind help.



On Sat, Apr 26, 2014 at 7:03 PM, Tal Galili  wrote:

> Thank you for mentioning the
> dendextendpackage
> Gregory.
>
> As I mention in the package, the dendextend package implements a similar
> function as in the dendroextra. The big difference between the two is that
> the dendextend package has an implementation of the "cutree" function for
> dendrograms (making it possible to not have to go through the hclust object
> in order to perform it). This is helpful when using non-standard
> dendrograms that can not be turned into an hclust object (via
> as.hclust.dendrogram).
> Also, the dendextend package includes many other functions for dendrogram
> manipulation which might be helpful.
>
> Here is a quick example that can give you a sense of the possibilities:
>
>
> install.packages("dendextend")
> require(dendextend)
>
> # pdf("dendextend_example.pdf")
> dend <- as.dendrogram(hclust(dist(USArrests), "ave"))
> d1=color_branches(dend, k=5, col = c(3,1,1,4,1))
> plot(d1) # selective coloring of branches :)
> d2=color_branches(d1,k=5)
> plot(d2) # getting rainbow_hcl colors for each cluster (the default)
> d3=color_branches(d1,5,groupLabels=TRUE) # adding numbers to the branches
> plot(d3)
> d4=color_labels(d3, k=5, col = c(3,1,1,4,1)) # color labels by cluster
> plot(d4)
> d5=color_labels(d4, col = c("red", "orange")) # color labels from left to
> right
> plot(d5)
> # dev.off()
>
> Here is the output:
> https://www.dropbox.com/s/vii83jd9xnbmuv7/dendextend_example.pdf
>
> Also, there is a (rough draft) of a vignettes for the package here:
>
> https://github.com/talgalili/dendextend/blob/master/vignettes/dendextend-tutorial.pdf?raw=true
>
> Feedback is welcome.
>
> Best,
> Tal
>
>
>
>
>
>
>
>
>
> Contact
> Details:---
> Contact me: tal.gal...@gmail.com |
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
>
> --
>
>
>
> On Sat, Apr 26, 2014 at 10:36 AM, Gregory Jefferis  >wrote:
>
> >
> > On 26 Apr 2014, at 06:41, Gregory Jefferis  wrote:
> >
> > > # plot dendrogram coloured by cluster:
> > > ##
> > > library(dendroextras)
> > > cluc=colour_clusters(clu, k=3, groupLabels =TRUE)
> > > plot(cluc)
> >
> > There was a typo in an argument name for colour_clusters in my earlier
> > response (thanks to Dennis Murphy for pointing this out). Correction in
> > above.
> >
> > Fancier versions are also possible:
> >
> > plot(colour_clusters(clu, k=3, groupLabels = as.roman))
> >
> > Best,
> >
> > Greg.
> > [[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.
>

[[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] lme4 Error Help: “maxstephalfit…pwrssUpdate”

2014-04-28 Thread Craig O'Connell
Thanks.  I used the most current version of lme4 that is why I was a bit 
concerned.  My data seems appropriate and with lme4 working last week on a very 
similar data set, I was left a bit confused.  Since I only starting 
implementing this technique, does anybody have some pointers on what I should 
look for that may potentially cause some issues?  

> 
> -Oorspronkelijk bericht-
> Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
> Namens Craig O'Connell
> Verzonden: maandag 28 april 2014 3:20
> Aan: r-help@r-project.org
> Onderwerp: [R] lme4 Error Help: “maxstephalfit…pwrssUpdate”
> 
> I am using a mixed model to assess the effects of various variables (i.e. 
> treatment, density, visibility) on bee behavior (e.g., avoidance frequency - 
> total avoidances per total visits; feeding frequency, and mating frequency).  
> Bee individuals is my random factor (n=63 different bees), whereas treatment 
> type, animal density, and air visibility are my fixed factors.
> However, when I run my models, I immediately get an error that I cannot fix.  
> Here is a sample of my data:
> Bee   TreatmentVisitsAvoid   FeedingMatingDensity   Visibility
> 
> 1   C   5   0   5   0  54
> 2   C   4   0   3   0  54
> 3   C   3   0   3   0  54
> ...
> 63
> 
> 1   PC  2   0   1   1  54
> 2   PC  3   0   0   3  54
> 3   PC  1   0   0   0  54
> ...
> 63
> 
> 1   M   5   0   1   3  54
> 2   M   3   2   0   0  54
> 3   M   2   0   0   2  54
> ...
> 63One I create my .txt file, I being my coding in R by first loading lme4.  
> After that, my coding starts off as follows:
> barrierdat = read.table("GLMMROW.txt", header=TRUE) barrierdat 
> barrierdat$Visibility = as.factor(barrierdat$Visibility);
> barrierdat$Density= as.factor(barrierdat$Density);
> 
> p01.glmer = glmer(Avoidance~offset(log(Visits))+(1|Bee),
> family=poisson,
>   data=egghead);  # null model; p02.glmer = 
> glmer(Avoidance~offset(log(Visits))+(1|Bee)+Treatment,  family=poisson,
>   data=egghead);
> p03.glmer = glmer(Avoidance~offset(log(Visits))+(1|Bee)+Visibility, 
> family=poisson,
>   data=egghead);
> p04.glmer = glmer(Avoidance~offset(log(Visits))+(1|Bee)+Density,
> family=poisson,
>   data=egghead);However, upon immediately running my models 
> (e.g. p01.glmer), I receive the error:
> Error: (maxstephalfit) PIRLS step-halvings failed to reduce deviance in 
> pwrssUpdate
> 
> Does anybody know what the issue is?  I ran similar data several weeks ago 
> and had no issues.  Any Suggestions on how to proceed?
> 
> [[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.
> * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
> Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
> en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd 
> is door een geldig ondertekend document.
> The views expressed in this message and any annex are purely those of the 
> writer and may not be regarded as stating an official position of INBO, as 
> long as the message is not confirmed by a duly signed document.

  
[[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] Label customization in R plots

2014-04-28 Thread Ayan Mitra
Hi all,
 I am a new comer in R . i am trying to figure out how to put in the
label of a plot the basic statistics values like mean=
   no of data = 
   media = 
   chi-square =


in a box.

I tried a lot to search over the net but couldn't find one as yet. 
Thanks in advance for suggestions.

Ayan.



--
View this message in context: 
http://r.789695.n4.nabble.com/Label-customization-in-R-plots-tp4689616.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] LogLikelihood of a Distribution Given Fixed Parameters

2014-04-28 Thread Jacob Warren (RIT Student)
Thanks Rolf. That took care of it. It should be lower=FALSE through right?
I want the upper tail because my values are right censored?
Regards,
Jake


On Fri, Apr 25, 2014 at 12:50 AM, Rolf Turner wrote:

>
> As usual I am too lazy to fight my way through the rather convoluted code
> presented, but it seems to me that you just want to calculate a log
> likelihood.  And that is bog-simple:
>
> The log likelihood for i.i.d. data is just the sum of log f(y_i) where the
> y_i are your observed values and f() is the density function of the
> distribution that you have in mind.
>
> Where there is (right) censoring you take the sum of log f(y_i) over all
> the non-censored values and then add k*(1-F(cens.time)) where k is the
> number of censored values and F() is the cumulative distribution function
> corresponding to f().
>
> In your case it would appear that f(y) = dlnorm(y,1.66,0.25) and
> F(y) = plnorm(y,1.66,0.25).  Note that instead of using 1-F(cens.time) you
> can use plnorm(cens.time,1.66,0.25,lower=TRUE) and that instead of taking
> logs explicitly you can set log=TRUE in the calls to dlnorm() and plnorm().
>
> cheers,
>
> Rolf Turner
>
>
> On 25/04/14 07:27, Jacob Warren (RIT Student) wrote:
>
>> I'm trying to figure out if there is a way in R to get the loglikelihood
>> of
>> a distribution fit to a set of data where the parameter values are fixed.
>> For example, I want to simulate data from a given alternate lognormal
>> distribution and then I will fit it to a lognormal distribution with null
>> parameter values to see what the likelihood of the null distribution is
>> given random data from the alternate distribution.
>>
>> I have been using fitdistrplus for other purposes but I cannot use it to
>> fix both parameter values.
>>
>> Here is an example of what I've been working with...
>>
>> nullmu<-1.66 #set null mu
>> altmu<-1.58 #set alt mu
>> sd.log<-0.25 #set common sigma
>> cens.time<-6 #if simulated times are greater than this turn them into
>> right
>> censored times
>>
>> #simulating lognormal data (time) from altnative dist
>> (sim<-rlnorm(n=samplesize, meanlog=altmu, sdlog=sd.log))
>> #if the time was > cens.time replace time with cens.time
>> (sim[which(sim>cens.time)]<-cens.time)
>> sim
>>
>> #create a variable indicating censoring
>> (cens<-sim)
>> cens[which(sim==cens.time)]<-NA
>> cens
>>
>> #create the data frame to be passed to fitdistcens and fitdist
>> (x<-data.frame(left=sim,right=cens))
>>
>>
>> #if there is censored data use fitdistcens else use fitdist
>> ifelse(length(which(is.na(cens)))>0,
>> simfit<-fitdistcens(censdata=x, distr="lnorm"),
>> simfit<-fitdist(data=x[,1], distr="lnorm")
>> )
>>
>> #Now I can get the loglikelihood of the MLE fitted distribution
>> simfit$loglik
>>
>> #I want to get the loglikelihood of the distribution with the null
>> parameterization
>> #This is what I can't get to work
>> #I can't seem to find any function that allows me to set both parameter
>> values
>> #so I can get to loglikelihood of the of the parameterization given the
>> data
>> nulldist<-fitdistcens(censdata=x, distr="lnorm",
>> start=list(meanlog=nullmu,
>> sdlog=sd.log)
>>
>> #Then I want to do a likelihood ratio test between the two distributions
>> pchisq((-2*simfit$loglik--2*nulldist$loglik), df=2, lower.tail=FALSE)
>>
>
>

[[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] Forecast Package in R version 3.1.0

2014-04-28 Thread Duncan Murdoch

On 28/04/2014 11:31 AM, Paul Bernal wrote:

Dear Duncan,

This is what is happening when I try downloading the Rcpp package in R 
version 3.1.0


Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = 
vI[[i]]) :

  there is no package called ‘Rcpp’
Error: package or namespace load failed for ‘forecast’


Others have told you how to solve this problem, so I will assume that's 
done, and just offer some advice for future problems:  Don't be vague 
about what you did to trigger the error message, cut and paste the exact 
code or describe the exact circumstances that led to it.  I can say with 
some certainty that you wouldn't get the message above from "downloading 
the Rcpp package", but if you had posted the code that you used, I could 
probably have told you what you were doing wrong.


Duncan Murdoch






2014-04-28 10:27 GMT-05:00 Duncan Murdoch >:


On 28/04/2014 11:22 AM, Paul Bernal wrote:

Dear R community, hello,

Hope everybody is doing great. I just downloaded R version
3.1.0, and,
whenever I try to load the forecast package, the following
error message
appears:

Error in loadNamespace(i, c(lib.loc, .libPaths()),
versionCheck = vI[[i]])
:
   there is no package called ‘Rcpp’
Error: package or namespace load failed for ‘forecast’

Does anybody knows or have an idea of what could be happeing
with this new
version of R?


Just what it says: the forecast package depends on the Rcpp
package, but you don't have Rcpp installed. Install it and this
error should go away.

Duncan Murdoch




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


[R] Job openings for 2 statisticians at Roche in Basel, Switzerland

2014-04-28 Thread Bert Gunter
Roche Pharmaceuticals has openings for two nonclinical statisticians
at its Basel, Switzerland R&D site.  The positions' initial focus will
be working with process and  formulation chemists. A solid background
in linear models, Design of Experiments, and English fluency are
minimal requirements.

For further information, please go to:

 
http://careers.roche.com/en/jobs/switzerland/development/2958368052/nonclinical-biostatistician.html#sthash.G0mkwDCS.dpuf

Bert Gunter
Genentech Nonclinical Biostatistics

__
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] Forecast Package in R version 3.1.0

2014-04-28 Thread Rui Barradas

Hello,

Or maybe better,

install.packages("forecast", dependencies = TRUE)


since package forecast depends on several other packages

Hope this helps,

Rui Barradas

Em 28-04-2014 17:04, Rich Shepard escreveu:

On Mon, 28 Apr 2014, Dirk Eddelbuettel wrote:


That is conflicting with the fact that the package page for Rcpp shows
you binaries for

 three R versions (devel, release, old-release) on Windows
 three R versions (devel, release, old-release) on OS X 'snow leopard'
 one R version (release) on OS X 'mavericks'

whereas you have not even told us what OS you use.


   FWIW, I run Slackware-14.1 and just installed Rcpp (as root) with
install.packages("Rcpp")

   No issues at all.

Rich

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


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


Re: [R] Forecast Package in R version 3.1.0

2014-04-28 Thread Rich Shepard

On Mon, 28 Apr 2014, Dirk Eddelbuettel wrote:


That is conflicting with the fact that the package page for Rcpp shows
you binaries for

 three R versions (devel, release, old-release) on Windows
 three R versions (devel, release, old-release) on OS X 'snow leopard'
 one R version (release) on OS X 'mavericks'

whereas you have not even told us what OS you use.


  FWIW, I run Slackware-14.1 and just installed Rcpp (as root) with
install.packages("Rcpp")

  No issues at all.

Rich

__
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] Forecast Package in R version 3.1.0

2014-04-28 Thread Dirk Eddelbuettel
Paul Bernal  gmail.com> writes:
> This is what is happening when I try downloading the Rcpp package in R
> version 3.1.0
> 
> Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
> :
>   there is no package called ‘Rcpp’
> Error: package or namespace load failed for ‘forecast’

That is conflicting with the fact that the package page for Rcpp shows
you binaries for

  three R versions (devel, release, old-release) on Windows
  three R versions (devel, release, old-release) on OS X 'snow leopard'
  one R version (release) on OS X 'mavericks'

whereas you have not even told us what OS you use.

Dirk

__
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] Forecast Package in R version 3.1.0

2014-04-28 Thread Duncan Murdoch

On 28/04/2014 11:22 AM, Paul Bernal wrote:

Dear R community, hello,

Hope everybody is doing great. I just downloaded R version 3.1.0, and,
whenever I try to load the forecast package, the following error message
appears:

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
:
   there is no package called ‘Rcpp’
Error: package or namespace load failed for ‘forecast’

Does anybody knows or have an idea of what could be happeing with this new
version of R?


Just what it says: the forecast package depends on the Rcpp package, but 
you don't have Rcpp installed. Install it and this error should go away.


Duncan Murdoch

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


Re: [R] Forecast Package in R version 3.1.0

2014-04-28 Thread Paul Bernal
Dear Duncan,

This is what is happening when I try downloading the Rcpp package in R
version 3.1.0

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
:
  there is no package called ‘Rcpp’
Error: package or namespace load failed for ‘forecast’




2014-04-28 10:27 GMT-05:00 Duncan Murdoch :

> On 28/04/2014 11:22 AM, Paul Bernal wrote:
>
>> Dear R community, hello,
>>
>> Hope everybody is doing great. I just downloaded R version 3.1.0, and,
>> whenever I try to load the forecast package, the following error message
>> appears:
>>
>> Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
>> :
>>there is no package called ‘Rcpp’
>> Error: package or namespace load failed for ‘forecast’
>>
>> Does anybody knows or have an idea of what could be happeing with this new
>> version of R?
>>
>
> Just what it says: the forecast package depends on the Rcpp package, but
> you don't have Rcpp installed. Install it and this error should go away.
>
> Duncan Murdoch
>

[[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] Forecast Package in R version 3.1.0

2014-04-28 Thread Paul Bernal
Dear R community, hello,

Hope everybody is doing great. I just downloaded R version 3.1.0, and,
whenever I try to load the forecast package, the following error message
appears:

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
:
  there is no package called ‘Rcpp’
Error: package or namespace load failed for ‘forecast’

Does anybody knows or have an idea of what could be happeing with this new
version of R?

Best regards,

Paul

[[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] subset of obersevation depending on multiple conditions

2014-04-28 Thread Frede Aakmann Tøgersen
So Christoph now have 3 methods giving him three different results. Of course 
it is not really clear what Christoph really wants ;-)

Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of arun
> Sent: 28. april 2014 13:58
> To: R. Help
> Subject: Re: [R] subset of obersevation depending on multiple conditions
> 
> Hi,
> 
> The conditions are not very clear.  Based on the rows you wanted to pick,
> may be this helps,
> 
> #It is better to dput() the example.
> 
>     dat <- structure(list(Date = structure(c(14610, 14611, 14612, 14613,
> 14614, 14615, 14616, 14617, 14618, 14619, 14620, 14621, 14622,
> 14623, 14624, 14625, 14626, 14627, 14628, 14629, 14630, 14631,
> 14632, 14633, 14634, 14635, 14636, 14637, 14638, 14639), class = "Date"),
>     N = c(0, 1.9, 0, 0, 1.6, 0, 0.3, 0, 1.1, 1.7, 2.6, 0, 0,
>     0, 0, 0, 0, 0.2, 0, 0, 0, 0, 0, 0, 0, 0, 1.9, 6.2, 0, 0)), .Names = 
> c("Date",
> "N"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
> "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
> "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"), class = 
> "data.frame")
> 
> 
> indx <- with(dat, N <=0.3)
> 
> rowInd <- unlist(lapply(split(seq_along(indx), cumsum(c(TRUE, diff(indx) ==
> 1))), function(x) {
>     x1 <- indx[x]
>     x2 <- with(dat, N[x])
>     x3 <- if (length(x2[x1]) > 1)
>     !cumsum(c(0, diff(x2[x1])) < 0)
>     x[c(x3, rep(FALSE, length(x2) - length(x3)))]
> }), use.names = FALSE)
> rowInd
> # [1]  3  4  6  7 12 13 14 15 16 17 18 29 30
> dat[rowInd,]
> 
> 
> 
> A.K.
> 
> 
> Hello,
> 
> I want to subset a data.frame containing the variables "Date" in (%Y %m %d
> ) and "N".
> 
> I want to print "Date" and "N" if  N is less than or equal to 0.3 and if
> "N" is also less than or equal to 0.3 on the day before the day where "N"
> is less than or equal to 0.3.
> 
> This would be the case in line 3 and 4 , 6 and 7, 12 to 18, and so on.
> 
> "Date"    "N"
> "1"    2010-01-01    0
> "2"    2010-01-02    1.9
> "3"    2010-01-03    0
> "4"    2010-01-04    0
> "5"    2010-01-05    1.6
> "6"    2010-01-06    0
> "7"    2010-01-07    0.3
> "8"    2010-01-08    0
> "9"    2010-01-09    1.1
> "10"    2010-01-10    1.7
> "11"    2010-01-11    2.6
> "12"    2010-01-12    0
> "13"    2010-01-13    0
> "14"    2010-01-14    0
> "15"    2010-01-15    0
> "16"    2010-01-16    0
> "17"    2010-01-17    0
> "18"    2010-01-18    0.2
> "19"    2010-01-19    0
> "20"    2010-01-20    0
> "21"    2010-01-21    0
> "22"    2010-01-22    0
> "23"    2010-01-23    0
> "24"    2010-01-24    0
> "25"    2010-01-25    0
> "26"    2010-01-26    0
> "27"    2010-01-27    1.9
> "28"    2010-01-28    6.2
> "29"    2010-01-29    0
> "30"    2010-01-30    0
> 
> I tried some methods with subset but I couldn't work it out. Maybe I have
> to use something like " for (i in x) {} but as a beginner I really don't
> know how to do it.
> 
> Can somebody please help me with this.
> 
> Thanks in advance,
> 
> Christoph
> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] subset of obersevation depending on multiple conditions

2014-04-28 Thread Frede Aakmann Tøgersen
Hi

Here is a very simple way.


mydat <- read.table(text="
DateN
2010-01-010
2010-01-021.9
2010-01-030
2010-01-040
2010-01-051.6
2010-01-060
2010-01-070.3
2010-01-080
2010-01-091.1
2010-01-101.7
2010-01-112.6
2010-01-120
2010-01-130
2010-01-140
2010-01-150
2010-01-160
2010-01-170
2010-01-180.2
2010-01-190
2010-01-200
2010-01-210
2010-01-220
2010-01-230
2010-01-240
2010-01-250
2010-01-260
2010-01-271.9
2010-01-286.2
2010-01-290
2010-01-300", sep = "", h = TRUE)

mydat$NdayBefore <- c(NA, mydat[-nrow(mydat), "N"])

head(mydat)

subset(mydat, N <= 0.3)

subset(mydat, N <= 0.3 & NdayBefore <= 0.3)

Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Christoph Schlächter
> Sent: 28. april 2014 10:38
> To: r-help@r-project.org
> Subject: [R] subset of obersevation depending on multiple conditions
> 
> Hello,
> 
> I want to subset a data.frame containing the variables "Date" in (%Y %m %d
> ) and "N".
> 
> I want to print "Date" and "N" if  N is less than or equal to 0.3 and if
> "N" is also less than or equal to 0.3 on the day before the day where "N"
> is less than or equal to 0.3.
> 
> This would be the case in line 3 and 4 , 6 and 7, 12 to 18, and so on.
> 
> "Date""N"
> "1"2010-01-010
> "2"2010-01-021.9
> "3"2010-01-030
> "4"2010-01-040
> "5"2010-01-051.6
> "6"2010-01-060
> "7"2010-01-070.3
> "8"2010-01-080
> "9"2010-01-091.1
> "10"2010-01-101.7
> "11"2010-01-112.6
> "12"2010-01-120
> "13"2010-01-130
> "14"2010-01-140
> "15"2010-01-150
> "16"2010-01-160
> "17"2010-01-170
> "18"2010-01-180.2
> "19"2010-01-190
> "20"2010-01-200
> "21"2010-01-210
> "22"2010-01-220
> "23"2010-01-230
> "24"2010-01-240
> "25"2010-01-250
> "26"2010-01-260
> "27"2010-01-271.9
> "28"2010-01-286.2
> "29"2010-01-290
> "30"2010-01-300
> 
> I tried some methods with subset but I couldn't work it out. Maybe I have
> to use something like " for (i in x) {} but as a beginner I really don't
> know how to do it.
> 
> Can somebody please help me with this.
> 
> Thanks in advance,
> 
> Christoph
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] subset of obersevation depending on multiple conditions

2014-04-28 Thread arun
Hi,

The conditions are not very clear.  Based on the rows you wanted to pick, may 
be this helps,

#It is better to dput() the example.

    dat <- structure(list(Date = structure(c(14610, 14611, 14612, 14613, 
14614, 14615, 14616, 14617, 14618, 14619, 14620, 14621, 14622, 
14623, 14624, 14625, 14626, 14627, 14628, 14629, 14630, 14631, 
14632, 14633, 14634, 14635, 14636, 14637, 14638, 14639), class = "Date"), 
    N = c(0, 1.9, 0, 0, 1.6, 0, 0.3, 0, 1.1, 1.7, 2.6, 0, 0, 
    0, 0, 0, 0, 0.2, 0, 0, 0, 0, 0, 0, 0, 0, 1.9, 6.2, 0, 0)), .Names = 
c("Date", 
"N"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", 
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", 
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30"), class = 
"data.frame")


indx <- with(dat, N <=0.3)

rowInd <- unlist(lapply(split(seq_along(indx), cumsum(c(TRUE, diff(indx) == 
1))), function(x) {
    x1 <- indx[x]
    x2 <- with(dat, N[x])
    x3 <- if (length(x2[x1]) > 1) 
    !cumsum(c(0, diff(x2[x1])) < 0)
    x[c(x3, rep(FALSE, length(x2) - length(x3)))]
}), use.names = FALSE)
rowInd
# [1]  3  4  6  7 12 13 14 15 16 17 18 29 30
dat[rowInd,]



A.K.


Hello,

I want to subset a data.frame containing the variables "Date" in (%Y %m %d
) and "N".

I want to print "Date" and "N" if  N is less than or equal to 0.3 and if
"N" is also less than or equal to 0.3 on the day before the day where "N"
is less than or equal to 0.3.

This would be the case in line 3 and 4 , 6 and 7, 12 to 18, and so on.

"Date"    "N"
"1"    2010-01-01    0
"2"    2010-01-02    1.9
"3"    2010-01-03    0
"4"    2010-01-04    0
"5"    2010-01-05    1.6
"6"    2010-01-06    0
"7"    2010-01-07    0.3
"8"    2010-01-08    0
"9"    2010-01-09    1.1
"10"    2010-01-10    1.7
"11"    2010-01-11    2.6
"12"    2010-01-12    0
"13"    2010-01-13    0
"14"    2010-01-14    0
"15"    2010-01-15    0
"16"    2010-01-16    0
"17"    2010-01-17    0
"18"    2010-01-18    0.2
"19"    2010-01-19    0
"20"    2010-01-20    0
"21"    2010-01-21    0
"22"    2010-01-22    0
"23"    2010-01-23    0
"24"    2010-01-24    0
"25"    2010-01-25    0
"26"    2010-01-26    0
"27"    2010-01-27    1.9
"28"    2010-01-28    6.2
"29"    2010-01-29    0
"30"    2010-01-30    0

I tried some methods with subset but I couldn't work it out. Maybe I have
to use something like " for (i in x) {} but as a beginner I really don't
know how to do it.

Can somebody please help me with this.

Thanks in advance,

Christoph 


__
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] linear mixed model for non-normal negative and continous data

2014-04-28 Thread ONKELINX, Thierry
Dear Caroline,

Check the homogeneity of the variances. If they are inhomogeneous, you can add 
a variance function to deal with it. However, you will need to switch to the 
lme() from the nlme package.

Best regards,

Thierry

PS R-Sig-mixed-models is a better list for this kind of questions.

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
Caroline Lustenberger
Verzonden: maandag 28 april 2014 12:04
Aan: r-help@r-project.org
Onderwerp: [R] linear mixed model for non-normal negative and continous data

Dear all



I try to fit a linear mixed model to my data. In short, my dependent variable 
reflects changes of the bone level (Knmn, in mm), thus this variable is 
continous and provides negative values. I have two different groups (factor 
Group) that were measured 3 times each (thus repeated measures, factor 
Timepoint). I used the following model:



mod_Knmn<-lmer(Knmn~Group*Timepoint+(1|VPnr),data=data)



When performing a qq-plot my residuals are clearly deviant from the norm 
(long-tailed). Due to negative values I cannot perform classical transformation 
methods (e.g. log transformation). How could I proccede with this data. Is 
there a possibility to use a generalized linear model?



Thanks and all the best

Caroline

[[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.
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document.

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


Re: [R] Problem with new(er) R version's matrix package

2014-04-28 Thread Martin Maechler
> Werner W 
> on Sun, 27 Apr 2014 17:48:23 +0100 writes:

> Dear Martin, Arne, David,

> Thanks for considering my problem. However, I have a bit of a problem in 
making a small reproducible example. So far, I tried to drill down into the 
code and to quick fix this by setting the particular tolerance to zero which 
switches off the check in ".solve.sparse.dgC". The obstacle I got stuck with 
doing that is, seemingly, the "solvetol" parameter from systemfit.control is 
not handed through all the way. 
> ".calcGLS" from systemfit still hands it over but it does not reach 
".solve.sparse.dgC"


> This is the stack at that point before the error is thrown:
> Browse[2]> where
> where 1: .solve.sparse.dgC(as(a, "dgCMatrix"), b = b, tol = tol)
> where 2: solve.dsC.dC(a, b)
> where 3: solve(a, as(b, "CsparseMatrix"))
> where 4: solve(a, as(b, "CsparseMatrix"))
> where 5: eval(expr, envir, enclos)
> where 6: eval(call, sys.frame(sys.parent()))
> where 7: callGeneric(a, as(b, "CsparseMatrix"))
> where 8: solve(forceCspSymmetric(a, isTri = FALSE), b = Diagonal(nrow(a)))
> where 9: solve(forceCspSymmetric(a, isTri = FALSE), b = Diagonal(nrow(a)))
> where 10: .local(a, b, ...)
> where 11: solve(W, tol = solvetol)
> where 12: solve(W, tol = solvetol)
> where 13: as.matrix(solve(W, tol = solvetol)[1:ncol(xMat), 1:ncol(xMat)])
> where 14: .calcGLS(xMat = xMatAll, R.restr = R.restr, q.restr = q.restr,
> sigma = rcov, validObsEq = validObsEq, useMatrix = control$useMatrix,
> solvetol = control$solvetol)
> where 15 at ILLS.R#465: systemfit(eqsys, method = "SUR", data = dat, 
restrict.matrix = restrmat,
> control = sysfit.contr)

> I will now further try to create a small, reproducible example.

Thank you, Werner,  the above is already very useful!

Currently, I'd concluded that there must be a buglet in either
systemfit or Matrix  as you assert that the 'tol' argument is
not passed all the way down the Matrix package sparse solver.
[after 10 more minutes ..]
My current guess is that the buglet is in 'Matrix'...
I see the phenomenon also, using   example(systemfit)
so we have a reproducible example for 
   "tol is not passed all the way to the Matrix solve(..)",
and I will investigate that later.  
There are a few more urgent things currently, and other
duties...

> I also have to better understand what the procedure is doing to be able 
to decide whether the previous results were wrong or this newly occurring error 
is wrong.

Indeed, the above is the real question you should address and
you have to do yourself alone.

> Many thanks,
> Werner

> Martin Maechler  schrieb am 22:00 Samstag, 
26.April 2014:
 
> Arne Henningsen 
>> 
>>>      on Sat, 26 Apr 2014 08:15:37 +0200 writes:
>> 
>>     > On 25 April 2014 20:15, David Winsemius
>>     >  wrote:
>>     >> 
>>     >> On Apr 25, 2014, at 9:17 AM, Werner W. wrote:
>>     >> 
>>     >>> Dear Rs,
>>     >>> 
>>     >>> I am re-executing some older code. It does work in the
>>     >>> ancient R 2.12.0 which I still have on my PC but with
>>     >>> the new version R 3.1.0 it does not work any more (but
>>     >>> some other new stuff, which won't work with 2.12).
>>     >>> 
>>     >>> The problem arises in context with the systemfit package
>>     >>> using the matrix package. In R 3.1.0 the following error
>>     >>> is thrown: Error in as.matrix(solve(W, tol =
>>     >>> solvetol)[1:ncol(xMat), 1:ncol(xMat)]) : error in
>>     >>> evaluating the argument 'x' in selecting a method for
>>     >>> function 'as.matrix': Error in .solve.sparse.dgC(as(a,
>>     >>> "dgCMatrix"), b = b, tol = tol) : LU computationally
>>     >>> singular: ratio of extreme entries in |diag(U)| =
>>     >>> 7.012e-39
>>     >>> 
>>     >>> However, I have no clue what I can do about this. Was
>>     >>> there some change in the defaults of the matrix package?
>>     >>> I couldn't find anything apparent in the changelog. As
>>     >>> the same code works in R 2.12.0, I suppose that the
>>     >>> problem is not my data.
>>     >> 
>>     >> You have not told us what version of the Matrix package
>>     >> you were using.  As such I would suggest that you review
>>     >> the Changelog which is a link for the CRAN page for
>>     >> pkg:Matrix and go back 4 years or so since R major
>>     >> versions change about once a year.
>>     >> 
>>     >> http://cran.r-project.org/web/packages/Matrix/ChangeLog
>> 
>>     > In addition, please provide a minimal, self-contained,
>>     > reproducible example.
>> 
>> Yes, please do.   As maintainer of the Matrix package, I'm
>> willing to look into the situation of course.
>> 
>> As was mentioned, many things have changed in 4 years.
>> The error m

[R] Trouble with subset.ffdf

2014-04-28 Thread christian.kamenik
Dear all



I am having trouble with subsetting an ffdf object, hopefully somebody can 
help...



I have an index, which is a ff object of vmode "logical":

> index.SAS

ff (open) logical length=4977231 (4977231)

  [1]   [2]   [3]   [4]   [5]   [6]   [7]   [8] 
  [4977224] [4977225] [4977226] [4977227] [4977228] [4977229]

 TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE 
:  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE

[4977230] [4977231]

 TRUE  TRUE



I would like to use this index to subset the ffdf object "data.SAS". The number 
of rows in data.SAS equals the length of index.SAS. However, the command

> Missing.data <- subset(data.SAS, !index.SAS)



gives me the following error:

Error in ffdf(x = x) : ffdf components must be atomic ff objects



A similar command also results in an error:

> Missing.data <- data.SAS[!index.SAS,]

Error: vmode(index) == "integer" is not TRUE



I do not want to use "index.SAS[]" (which works in many cases, but sometimes 
crashes), because - as far as I understand - this will cause trouble with 
really large index vectors (I would prefer using ff objects).



So I came up with the following syntax, which seems to work:

> Missing.data <- data.SAS[ffwhich(index.SAS,index.SAS==FALSE),]



...I am just not sure if this is the right approach.



I am running



platform   i386-w64-mingw32

arch   i386

os mingw32

system i386, mingw32

status

major  3

minor  0.3

year   2014

month  03

day06

svn rev65126

language   R

version.string R version 3.0.3 (2014-03-06)

nickname   Warm Puppy



with ffbase_0.11.3 and ff_2.2-12



Many thanks in advance

Christian


[[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] average and median values for each of the class

2014-04-28 Thread arun


Hi,
I noticed that if ?mean" or ?median in fun1 is changed to other functions, for 
e.g. ?sum, it will show error message.
##Using shortened version that runs
library(plyr)
fun1 <- function(data, .group) {
    f1 <- function(x) c(x, mean(x, na.rm = TRUE), sum(x, na.rm = TRUE))
    res <- ddply(data, .group, sapply, FUN = f1)
    res
}
fun1(dat,"class")##check the value of class column. This creates error in the 
full version.

To be a bit more general, you can try this:
fun2 <- function(data, .group, funcVec) {
    data <- data[order(data[, .group]), ]
    f1 <- function(x) c(x, eval(parse(text = paste0("c(", paste(paste0(funcVec, 
"(", 
    "x,", "na.rm=TRUE", ")"), collapse = ","), ")"
    res <- ddply(data, .group, sapply, FUN = f1)[, -1]
    indx <- table(factor(data[, .group], levels = unique(data[, .group]))) + 
length(funcVec)
    res <- cbind(class = as.numeric(rep(names(indx), indx)), res)
    indxN <- as.numeric(sort(rep(cumsum(indx), length(funcVec)) - 
rep((seq(funcVec) - 
    1), each = length(indx
    UniqGroup <- unique(data[, .group])
    rownames(res)[indxN] <- paste0(rep(gsub("[.]", "", 
toupper(abbreviate(funcVec, 
    min = 4))), length(UniqGroup)), rep(UniqGroup, each = length(funcVec)))
    rownames(res)[-indxN] <- rownames(data)
    res
}

vec1 <- c("mean", "median", "sd", "sum")
vec2 <- "mean"
vec3 <- c("mean", "median", "min", "max", "sd")
vec4 <- c("mean", "median", "min", "max", "sd", "sum", "var")
library(plotrix)  ## for ?std.error
vec5 <- c("mean", "median", "min", "max", "var", "sd", "std.error", "prod")
library(psych)  ### for ?skew,?kurtosi
vec6 <- c("mean", "median", "min", "max", "var", "sd", "std.error", "prod", 
"skew", 
    "kurtosi")
fun2(dat, "class", vec1)
fun2(dat, "class", vec2)
fun2(dat, "class", vec3)
fun2(dat, "class", vec4)
fun2(dat, "class", vec5)
fun2(dat, "class", vec6)

#or running all the above in a loop
 lapply(paste0("vec",1:6),function(x) fun2(dat,"class",get(x)))
A.K.


On Sunday, April 27, 2014 7:11 AM, arun  wrote:

Hi,
You could also try:
library(plyr)


fun1 <- function(data, .group) {
    f1 <- function(x) c(x, mean(x, na.rm = TRUE), median(x, na.rm = TRUE))
    res <- ddply(data, .group, sapply, FUN = f1)
    vec1 <- as.vector(table(res[, .group]))
    indx <- sort(c(cumsum(vec1) - 1, cumsum(vec1)))
    UniqGroup <- unique(data[, .group])
    rownames(res)[indx] <- paste0(rep(c("Avg", "Med"), length(UniqGroup)), 
rep(UniqGroup, 
    each = 2))
    rownames(res)[-indx] <- rownames(data)
    res
}
fun1(dat,"class")
all.equal(res2,fun1(dat,"class"))
#[1] TRUE



A.K.





On Saturday, April 26, 2014 9:14 PM, arun  wrote:


Hi,
Your dput() suggests dat as data.frame.
##Using the results you got,

res2 <- do.call(rbind,lapply(unique(dat$class),function(i) {x1 
<-rbind(dat[dat$class==i,], avg[avg$class==i,], med[med$class==i,]); 
rownames(x1)[!grepl("ara",rownames(x1))] <- paste0(c("Avg", "Med"), i); x1}))


A.K.




On Saturday, April 26, 2014 8:39 PM, Nico Met  wrote:
Dear all,



I have a matrix (dimension, 16 x 12) where  2nd column represents class
(1,1,1,1,1,2,2,2, etc) information. I want to estimate average  and median
values for each of the class and add this information as a row at end of
the each classes.


for example:

dput(dat)

structure(list(class = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,

3L, 3L, 3L, 4L, 4L, 4L, 5L), name1 = c(2.554923977, 2.371586762,

2.497293431, 2.464827875, 2.981934845, 2.228995664, 2.099640729,

1.900314302, 2.630005966, 2.632590262, 2.581887814, 2.408797563,

2.098761103, 3.070460716, 1.436980716, 1.645121806), name2 = c(1.297412278,

1.104804244, 1.30621114, 1.126009533, 1.466740841, 1.012041118,

0.923466541, 0.840575023, 1.285530176, 1.041909333, 1.194917856,

1.085015826, 1.047492703, 1.587558217, 0.593340012, 0.723630088

), name3 = c(0.587160798, 0.596127884, 0.623760721, 0.549016135,

0.686642084, 0.487523394, 0.458620467, 0.397974913, 0.615928976,

0.546005649, 0.657383069, 0.546613129, 0.476503461, 0.749062102,

0.304160587, 0.29037358), name4 = c(2.833441759, 2.713374426,

2.532626548, 2.409093102, 3.014912721, 2.113507947, 2.017291324,

1.667744912, 2.602560666, 2.31649643, 2.761204809, 2.433963493,

2.229911767, 3.191646399, 1.269919241, 1.387479858), name5 = c(2.172365295,

1.955695471, 2.141072829, 1.975743278, 2.377018372, 1.791300389,

1.669079382, 1.500209628, 2.164401874, 1.830038378, 2.106750025,

1.92888294, 1.707217549, 2.585082653, 1.114841754, 1.315712452

), name6 = c(0.715129844, 0.688186262, 0.70133748, 0.709362008,

0.712145174, 0.563593885, 0.532109761, 0.472197304, 0.690165016,

0.65635473, 0.615835066, 0.64310098, 0.562974891, 0.900622255,

0.408546784, 0.416284408), name7 = c(1.995505133, 1.860095899,

1.843151597, 1.709861774, 2.155993511, 1.506409746, 1.315405587,

1.234544153, 1.96629927, 1.74879757, 1.93994009, 1.660173854,

1.556735295, 2.355723318, 0.866634243, 1.013367677), name8 = c(0.275484997,

0.233856392, 0.294021245, 0.315504347, 0.251906585, 0

Re: [R] subset of obersevation depending on multiple conditions

2014-04-28 Thread Ivan Calandra

Hi Christoph,

I'm not sure I understand your conditions. It is an "AND" or an "OR", 
i.e. must both conditions be met to subset or any one of them?
From your explanation, I would think you really mean AND, but then I 
don't understand why you would select both lines 3 and 4.


I would just say:
df[df$N <= 0.3, ]
but I might be missing something.

You should also be careful with floating point numbers, I guess.

HTH,
Ivan

--
Ivan Calandra
University of Franche-Comté
Laboratoire Chrono-Environnement
Bureau ATER -107L
16, Route de Gray
25030 Besançon Cedex, France
ivan.calan...@univ-fcomte.fr
+33 (0) 381 66 20 60
http://chrono-environnement.univ-fcomte.fr/spip.php?article1830

Le 28/04/14 10:37, Christoph Schlächter a écrit :

Hello,

I want to subset a data.frame containing the variables "Date" in (%Y %m %d
) and "N".

I want to print "Date" and "N" if  N is less than or equal to 0.3 and if
"N" is also less than or equal to 0.3 on the day before the day where "N"
is less than or equal to 0.3.

This would be the case in line 3 and 4 , 6 and 7, 12 to 18, and so on.

"Date""N"
"1"2010-01-010
"2"2010-01-021.9
"3"2010-01-030
"4"2010-01-040
"5"2010-01-051.6
"6"2010-01-060
"7"2010-01-070.3
"8"2010-01-080
"9"2010-01-091.1
"10"2010-01-101.7
"11"2010-01-112.6
"12"2010-01-120
"13"2010-01-130
"14"2010-01-140
"15"2010-01-150
"16"2010-01-160
"17"2010-01-170
"18"2010-01-180.2
"19"2010-01-190
"20"2010-01-200
"21"2010-01-210
"22"2010-01-220
"23"2010-01-230
"24"2010-01-240
"25"2010-01-250
"26"2010-01-260
"27"2010-01-271.9
"28"2010-01-286.2
"29"2010-01-290
"30"2010-01-300

I tried some methods with subset but I couldn't work it out. Maybe I have
to use something like " for (i in x) {} but as a beginner I really don't
know how to do it.

Can somebody please help me with this.

Thanks in advance,

Christoph

[[alternative HTML version deleted]]

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



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


Re: [R] Faster way to transform vector [3 8 4 6 1 5] to [2 6 3 5 1 4]

2014-04-28 Thread xmliu1...@gmail.com

Thanks for your kind replies 

Jorge's answer helps.

warm wishes
Xueming




xmliu1...@gmail.com

From: Jorge I Velez
Date: 2014-04-26 23:41
To: xmliu1...@gmail.com
CC: r-help
Subject: Re: [R] Faster way to transform vector [3 8 4 6 1 5] to [2 6 3 5 1 4]
Hi Xueming,


Try


(1:length(bo))[rank(bo)]



In a function the above would be


f <- function(x){
  N <- length(x)
  (1:N)[rank(x)]
}
f(bo)
# [1] 2 6 3 5 1 4



HTH,
Jorge.-







On Sat, Apr 26, 2014 at 7:54 PM, xmliu1...@gmail.com  
wrote:

Hi,

could anybody help me to find a fast way to fix the following question?

Given a verctor of length N, for example bo = [3  8  4  6  1  5],
I want to drive a vector whose elements are 1, 2, ..., N and the order of 
elements is the same as that in verctor bo.
In this example, the result is supposed to be bt = [2  6  3  5  1 4].

I used the following code to solove this:

bo <- c(3,  8,  4,  6,  1,  5)
N <- length(bo)
bt <- rep(0, N)
M <- max(bo)
temp <- bo
  for(i in 1 : N)
{
min <- M
i_min <- 0

for(j in 1 : N)
{
if(min >= temp[j])
{
  min <- temp[j]
  i_min <-j
 }
}
bt[i_min] <- i
temp[i_min] <- M+ 1
 }
> bt
[1] 2 6 3 5 1 4

However, the time complexity is O(N2).
When N is larger than 100, it takes too much time.
Is there any faster way to fix it?

best
Xueming



xmliu1...@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.
[[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] Ridge regression for beta and gamma models

2014-04-28 Thread john james
Dear All,

Please, is there any package in R that has implemented ridge regression for 
beta and gamma models?

If not, kindly help me to adjust my model below for the beta regression so as 
to accommodate ridge
penalty. Thanks.



lbeta <- function(par,y,X){
n <-length(y)
k <- ncol(X)
beta <- par[1:k]
phi <- par[k+1]
if(phi < 0)return(NA)
mu <- X%*%beta
val <- vector()
mu <- X%*%beta
mul <- exp(mu)/(1+exp(mu))
p <- phi*mul; q <- phi*(1-mul)
for(i in 1:n) val[i] <- dbeta(y[i],p[i,],q[i,],log=TRUE)
return(-sum(val))
}

James
[[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] subset of obersevation depending on multiple conditions

2014-04-28 Thread Christoph Schlächter
Hello,

I want to subset a data.frame containing the variables "Date" in (%Y %m %d
) and "N".

I want to print "Date" and "N" if  N is less than or equal to 0.3 and if
"N" is also less than or equal to 0.3 on the day before the day where "N"
is less than or equal to 0.3.

This would be the case in line 3 and 4 , 6 and 7, 12 to 18, and so on.

"Date""N"
"1"2010-01-010
"2"2010-01-021.9
"3"2010-01-030
"4"2010-01-040
"5"2010-01-051.6
"6"2010-01-060
"7"2010-01-070.3
"8"2010-01-080
"9"2010-01-091.1
"10"2010-01-101.7
"11"2010-01-112.6
"12"2010-01-120
"13"2010-01-130
"14"2010-01-140
"15"2010-01-150
"16"2010-01-160
"17"2010-01-170
"18"2010-01-180.2
"19"2010-01-190
"20"2010-01-200
"21"2010-01-210
"22"2010-01-220
"23"2010-01-230
"24"2010-01-240
"25"2010-01-250
"26"2010-01-260
"27"2010-01-271.9
"28"2010-01-286.2
"29"2010-01-290
"30"2010-01-300

I tried some methods with subset but I couldn't work it out. Maybe I have
to use something like " for (i in x) {} but as a beginner I really don't
know how to do it.

Can somebody please help me with this.

Thanks in advance,

Christoph

[[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] linear mixed model for non-normal negative and continous data

2014-04-28 Thread Caroline Lustenberger
Dear all

 

I try to fit a linear mixed model to my data. In short, my dependent variable 
reflects changes of the bone level (Knmn, in mm), thus this variable is 
continous and provides negative values. I have two different groups (factor 
Group) that were measured 3 times each (thus repeated measures, factor 
Timepoint). I used the following model:

 

mod_Knmn<-lmer(Knmn~Group*Timepoint+(1|VPnr),data=data)

 

When performing a qq-plot my residuals are clearly deviant from the norm 
(long-tailed). Due to negative values I cannot perform classical transformation 
methods (e.g. log transformation). How could I proccede with this data. Is 
there a possibility to use a generalized linear model?

 

Thanks and all the best

Caroline
  
[[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] delay evaluation of expression

2014-04-28 Thread Luca Cerone
Dear all,
in one of my packages I need to load some data from .Rdata files that
are to be used from
some functions (but not all off them). I would like to delay the
loading of this datasets
only when needed. In other cases I successfully used lazyLoad and
delayedAssign(),
but when I try to load a .Rdata file I get this message: Error: cannot
add bindings to a locked environment

What would be the best way to load such a db only the first time that is needed?
Thanks a lot for you help,

Cheers,
Luca

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