Re: [R] Plot a Matrix as an Image with ggplot

2013-02-14 Thread Alaios


Hi,
thanks
I changed slightly the code to be reproducible from everyone . I have  tried 
ggplot
but I need a bit of help to tweak it a bit

So you can run the following in your computer

  testData<-matrix(data=round(runif(25)),nrow=5,ncol=5,dimnames=list(1:5,1:5))

  p<-ggplot(melt(testData), aes(Var2,Var1, fill=value))+xlab("MHz") + 
ylab("Threshold") +    geom_raster()


  p


What I want to improve is
a: make the colorbar so only two specific colors lets say black and white and 
only two values 0 and 1 and somewhere the string as title of the color bar 
"text" to appear.

I have tried something like
p+   scale_color_gradient(low="red",high="blue")
Fehler in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0


ggplot(melt(testData), aes(Var2,Var1, fill=value,colorbin=2))+xlab("MHz") + 
ylab("Threshold") +    geom_raster()
but this did not affect colorbar entries.


b. reduce/remove the grayish border that appears between the legend and the 
image plot

Could you please help me with these two?

Regards
Alex




From: John Kane 
To: Alaios ; R help  
Sent: Thursday, February 14, 2013 4:35 PM
Subject: RE: [R] Plot a Matrix as an Image with ggplot

The R-help list is rather picky about what attached. None of your attachments 
arrived. 

The str() info is useful but please supply some sample data 

The easiest way to supply data  is to use the dput() function.  Example with 
your file named "testfile": 
dput(testfile) 

Then copy the output and paste into your email.  For large data sets, you can 
just supply a representative sample.  Usually, 
dput(head(testfile, 100)) will be sufficient.  

How are you writing the code/or what format is the original email. Your code in 
the body of the text is badly messed up -- you probably need to post only in 
text. HTML etc is automatically dropped.




John Kane
Kingston ON Canada


> -Original Message-
> From: ala...@yahoo.com
> Sent: Thu, 14 Feb 2013 07:15:05 -0800 (PST)
> To: r-help@r-project.org
> Subject: [R] Plot a Matrix as an Image with ggplot
> 
> Dear all,
> I am trying to plot a matrix I have  as an image
> 
> str(matrixToPlot)
>  num [1:21, 1:66] 0 0 0 0 0 0 0 0 0 0 .
> 
> 
>  that contains only 0s and 1s,
> 
> 
> where the xlabel will be Labeled as
> str(xLabel)
>  num [1:66] 1e+09 1e+09 1e+09 1e+09 1e+09 ...
> 
> and the yLabels will be labeled as
> str(yLabel)
>  num [1:21] -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 ...
> 
> 
> I have found on the internet that I can do something like that with
> ggplot2.
> For example
> you can run the following
> 
> 
> 
> library(reshape2)library(ggplot2)m
> =matrix(rnorm(20),5)ggplot(melt(m),aes(Var1,Var2,fill=value))+geom_raster()
> 
> What I see missing here is to get my matrix and transform it to a data
> frame with labels for x and y axis so as ggplot can print the values
> nice. If you get the idea this matrix will be printed as a two tile
> pattern let's say with black tiles zeros and white tiles black where a
> color bar will depicting that black means zero and white one.
> 
> To help you with my code you will find attached the three items I have
> discussed here, the matrix, the x and the y labels.
> 
> Could you please help me with that?
> 
> Alex


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your 
desktop!
Check it out at http://www.inbox.com/marineaquarium

__
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] lm regression query

2013-02-14 Thread Nicole Ford
> 
> 

You could also run it and find out.  

There are many R tutorials free online.  

I presume crime is continuous, as well...?

~Nicole Ford
Graduate Instructor
Department of Government and International Affairs
University of South Florida
office: SOC 012M
e: nmhi...@mail.usf.edu
http://gia.usf.edu/student/nford/

Sent from my iPhone


[[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] lm regression query

2013-02-14 Thread Nicole Ford
You will also need to specify/ name your model:

Mod <- lm(Crime~.

~Nicole Ford
Graduate Instructor
Department of Government and International Affairs
University of South Florida
office: SOC 012M
e: nmhi...@mail.usf.edu
http://gia.usf.edu/student/nford/

Sent from my iPhone

On Feb 14, 2013, at 6:55 PM, email  wrote:

> Hello:
> 
> I have a 4-column dataset: Crime, Education, Urbanization, Age. I want to
> construct a multiple linear regression to find the effect of Education,
> Urbanization, and Age on Crime"
> 
> lm(Crime ~ Education + Urbanization + Age)
> 
> If I use + in above statement, does it mean it will build a model to find
> the relationship between Crime and Education when Urbanization and Age are
> held constant?
> 
> What would be the difference if I drop the term Urbanization + Age ?
> 
> lm(Crime ~ Education)
> 
> Regards:
> John
> 
>[[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] Using paste on results from tapply?

2013-02-14 Thread arun
HI,

You could either get the results by:
unlist(lapply(groups,function(x) paste(x,collapse=" ")),use.names=FALSE)
#[1] "6" "4 4"   "5 3 2"
#or
gsub("[c(),]","",paste(groups))
#[1] "6" "4 4"   "5 3 2"

str(gsub("[c(),]","",paste(groups)))
# chr [1:3] "6" "4 4" "5 3 2"
 str(unlist(lapply(groups,function(x) paste(x,collapse=" ")),use.names=FALSE))
# chr [1:3] "6" "4 4" "5 3 2"
A.K.




- Original Message -
From: Nikola Janevski 
To: r-help@r-project.org
Cc: 
Sent: Thursday, February 14, 2013 8:28 PM
Subject: [R] Using paste on results from tapply?

Hi,

This is what I'm trying to do:
1. I have a vector split.indexes <- c(1, 3, 3, 6, 6, 6)
2. I have another vector with something like data <- c(6, 4, 4, 5, 3, 2)
3. I use groups <- tapply(data, split.indexes, "c") to create a list of
vectors based on the levels in split.indexes. As a result groups has the
following values:
$`1`
[1] 6

$`3`
[1] 4 4

$`6`
[1] 5 3 2

This is the desired result.

4. The next thing I want to do is call paste on groups so I can get a
string representation that I can write to a file. However, when I call
paste(groups) it returns the following:
[1] "6"          "c(4, 4)"    "c(5, 3, 2)"

I do not understand why the paste function is adding the "c()" part. I
would like the result to be:
[1] "6"          "4 4"    "5 3 2"

Do you know any efficient way to get rid of the "c()"?

Note: I'm working with a very large data set 1-10 millions of points and I
would rather not use for loops since the performance are really bad.

Sincerely,
Nikola

    [[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] Format Integers

2013-02-14 Thread arun
Hi,
Try 

vec1<- c(10, 1000153846, 1000307692, 1000461538, 1000615385) 

round(vec1/1e6,2)
#[1] 1000.00 1000.15 1000.31 1000.46 1000.62
#or
as.numeric(sprintf("%.2f",vec1/1e6))
#[1] 1000.00 1000.15 1000.31 1000.46 1000.62
A.K.



- Original Message -
From: Alaios 
To: R help 
Cc: 
Sent: Friday, February 15, 2013 1:41 AM
Subject: [R] Format Integers

Dear all,
I would like to format the following numbers

xLabel
 [1] 10 1000153846 1000307692 1000461538 1000615385 1000769231
 [7] 1000923077 1001076923 1001230769 1001384615 1001538462 1001692308
[13] 1001846154 100200 1002153846 1002307692 1002461538 1002615385
[19] 1002769231 1002923077 1003076923 1003230769 1003384615 1003538462
[25] 1003692308 1003846154 100400 1004153846 1004307692 1004461538
[31] 1004615385 1004769231 1004923077 1005076923 1005230769 1005384615
[37] 1005538462 1005692308 1005846154 100600 1006153846 1006307692
[43] 1006461538 1006615385 1006769231 1006923077 1007076923 1007230769
[49] 1007384615 1007538462 1007692308 1007846154 100800 1008153846
[55] 1008307692 1008461538 1008615385 1008769231 1008923077 1009076923
[61] 1009230769 1009384615 1009538462 1009692308 1009846154 101000


that are in watts to megawatts so they appear (as an example)


from: 1009846154 to 1009.846154 and even better to truncate it a bit to look 
better as

   1009.84 

Could you please help with the formatting ?

Regards
Alex
    [[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] Format Integers

2013-02-14 Thread Alaios
Dear all,
I would like to format the following numbers

xLabel
 [1] 10 1000153846 1000307692 1000461538 1000615385 1000769231
 [7] 1000923077 1001076923 1001230769 1001384615 1001538462 1001692308
[13] 1001846154 100200 1002153846 1002307692 1002461538 1002615385
[19] 1002769231 1002923077 1003076923 1003230769 1003384615 1003538462
[25] 1003692308 1003846154 100400 1004153846 1004307692 1004461538
[31] 1004615385 1004769231 1004923077 1005076923 1005230769 1005384615
[37] 1005538462 1005692308 1005846154 100600 1006153846 1006307692
[43] 1006461538 1006615385 1006769231 1006923077 1007076923 1007230769
[49] 1007384615 1007538462 1007692308 1007846154 100800 1008153846
[55] 1008307692 1008461538 1008615385 1008769231 1008923077 1009076923
[61] 1009230769 1009384615 1009538462 1009692308 1009846154 101000


that are in watts to megawatts so they appear (as an example)


from: 1009846154 to 1009.846154 and even better to truncate it a bit to look 
better as

   1009.84 

Could you please help with the formatting ?

Regards
Alex
[[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] hyper-parameters

2013-02-14 Thread Mark Leeds
Hi: I'm not at all familiar with the r-inla package so I can't help you
there. But any arima model can
be re-cast into its state space equivalent form. ( I think Jeremy Penzer
wrote a paper for showing how this is done in general )  So, one way would
be to convert the arima (1,0,1) model for example to it's state space
equivalent and then use say the DLM package like you mentioned. ( there are
others also like sspir etc but I'm not familar with them ) .

The DLM package is essentially the full R implementation of the theory in
West and Harrison" Bayesian Forcasting and Dynamic Models" text. So, if
you're not familiar with that book, I would read it or atleast part of it
beeore getting involved with the DLM package. It's quite a nice package but
I think it's better if you read West and Harrison first. There may even be
a function in the DLM package for converting from arima to state space. I'm
not 100% sure about that but there probably is.

I hope that helps a little.









On Thu, Feb 14, 2013 at 4:27 PM, Juan Manuel Becerra wrote:

> I'm searching a method to estimate the hyper-parameters in arima models.
> I'm reading about r-inla package, but in the examples section only talk
> about the AR part of the arima, but i need help about the MA part too.
>
> I'm beginner in Bayesian methods, I'm reading the documentation about dlm
> package and kalman filters, but the computacional cost of inla i think is
> better, but  only AR models are supported for the moment. What's packages
> can help me for that?.
>
> Someone can help me about it?. I need ligth for this question. If it's
> possible with a arima(1,0,1) example, w
>
> Thanks All
>
> [[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] lm regression query

2013-02-14 Thread Pascal Oettli

Hi,

Did you read the help file? Particularly the section "Details".

?lm

Regards,
Pascal

Le 15/02/2013 08:55, email a écrit :

Hello:

I have a 4-column dataset: Crime, Education, Urbanization, Age. I want to
construct a multiple linear regression to find the effect of Education,
Urbanization, and Age on Crime"

lm(Crime ~ Education + Urbanization + Age)

If I use + in above statement, does it mean it will build a model to find
the relationship between Crime and Education when Urbanization and Age are
held constant?

What would be the difference if I drop the term Urbanization + Age ?

lm(Crime ~ Education)

Regards:
John

[[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] file copy to password protected network drive

2013-02-14 Thread Kumar Mainali
I am trying to copy files to a password protected drive which is "Ranch" at
TACC from another network drive. I am logged in to the source drive and can
run R there. The following code does not even find the destination folder.

file.copy("sourcedrive/file.tar", "
usern...@ranch.tacc.utexas.edu/uniqueID/destinationfolder/file.tar",
overwrite = FALSE)

Thanks in advance,
Kumar

On Thu, Feb 14, 2013 at 4:41 AM, e-letter  wrote:

> Readers,
>
> For this data set:
>
> testvalues<-c(10,20,30,40)
>
> How to amend the plot instruction:
>
> plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n')
>
> so that x axis ticks labels can be added to existing graph with
> arbitrary value such as 0,100,200,300)?
>
> Thanks in advance.
>
> --
> r2151
>
> __
> 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.
>



-- 
Section of Integrative Biology
University of Texas at Austin
Austin, Texas 78712, USA

[[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] Why no line? (ex. from Andy Filed book)

2013-02-14 Thread Kevin Mc Inerney
The following script is written by the author of a book on R--Andy Field:
You can also download the small datafile, hiccups.dat, from this address:

http://www.sagepub.com/dsur/study/articles.htm

The script:

hiccupsData <- read.delim("Hiccups.dat",  header = TRUE)
hiccups<-stack(hiccupsData)
names(hiccups)<-c("Hiccups","Intervention")
hiccups$Intervention_Factor<-factor(hiccups$Intervention, levels =
hiccups$Intervention)

line <- ggplot(hiccups, aes(Intervention_Factor, Hiccups))
line + stat_summary(fun.y = mean, geom = "point") + stat_summary(fun.y =
mean, geom = "line", aes(group=1),colour = "Red", linetype = "dashed")+
stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.2) +
labs(x = "Intervention", y = "Mean Number of Hiccups")
saveInImageDirectory("04 Hiccups Line.png")

Why does this script not give me a line?

It's driving e crazy :-|

[[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] Using paste on results from tapply?

2013-02-14 Thread Nikola Janevski
Hi,

This is what I'm trying to do:
1. I have a vector split.indexes <- c(1, 3, 3, 6, 6, 6)
2. I have another vector with something like data <- c(6, 4, 4, 5, 3, 2)
3. I use groups <- tapply(data, split.indexes, "c") to create a list of
vectors based on the levels in split.indexes. As a result groups has the
following values:
$`1`
[1] 6

$`3`
[1] 4 4

$`6`
[1] 5 3 2

This is the desired result.

4. The next thing I want to do is call paste on groups so I can get a
string representation that I can write to a file. However, when I call
paste(groups) it returns the following:
[1] "6"  "c(4, 4)""c(5, 3, 2)"

I do not understand why the paste function is adding the "c()" part. I
would like the result to be:
[1] "6"  "4 4""5 3 2"

Do you know any efficient way to get rid of the "c()"?

Note: I'm working with a very large data set 1-10 millions of points and I
would rather not use for loops since the performance are really bad.

Sincerely,
Nikola

[[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] Alternate tick labels in xyplot

2013-02-14 Thread Lisa Daniel


Dear David and Duncan,

Thank you for the responses.

David:

I was able to fix it with grid.text().

Duncan:
I would certainly look into ?scale.components in latticeExtra package 
(xscale.components.default)

The code for the figure is below.
library(lattice)
library(grid)

xy <-xyplot(decrease ~ treatment, OrchardSprays,
    main= "Some plot",
    groups = rowpos, type = "a",
    scales=list(x=list(at=seq(1,8,1),labels=c('A','','C','','E','','G',''))),
        page = function(n){
 grid.text(LETTERS[j],
 y = 0.95,
 x = 0.15,
 default.units = "npc",
 just = c("left"),
 gp = gpar(fontsize = 12,fontface="bold") )
   },
    par.settings = c(simpleTheme(lty=1:8, 
col="black",lwd=2),list(axis.components=list(bottom=list(tck=c(0,1))),layout.heights
 = list(main = 1.2,
   sub  = 0,
   axis.top = 0.2,
   top.padding  = 0.1,
   bottom.padding = 0,
            axis.bottom=0.8)) ),
    auto.key = list(x = 0.2, y = 0.9,
    cex = 0.75, points = FALSE, lines = TRUE)) 
j=1
print(xy, pos = c(0.0, 0.50, 0.33, 0.95), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.50, 0.66, 0.95), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.50, 0.99, 0.95), more = TRUE)
j=j+1
print(xy, pos = c(0.0, 0.0, 0.33, 0.45), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.0, 0.66, 0.45), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.0, 0.99, 0.45), more = FALSE)
grid.text("Upper row", x=0.5, y=0.97, gp=gpar(fontsize=12, col="black"))
grid.text("Lower row", x=0.5, y=0.47, gp=gpar(fontsize=12, col="black"))



Thanks,
Lisa


- Original Message -
From: David Winsemius 
To: Lisa Daniel 
Cc: "r-help@r-project.org" 
Sent: Thursday, February 14, 2013 4:31 PM
Subject: Re: [R] Alternate tick labels in xyplot


On Feb 14, 2013, at 10:52 AM, Lisa Daniel wrote:

> Dear Rhelp,
> I was able to solve the tick labels part.  If somebody can help me in 
> creating title for each row of figures above the individual headings, it will 
> be great.

I think you need to be looking at grid.text() in package grid.

> library(grid)
> library(lattice)
> xy <-xyplot(decrease ~ treatment, OrchardSprays,
>     main= "Some plot",
>         groups = rowpos, type = "a",
>     scales=list(x=list(at=seq(1,8,1),labels=c('A','','C','','E','','G',''))),
>                 page     = function(n){
>                          grid.text(LETTERS[j],
>                          y = 0.95,
>                          x = 0.15,
>                          default.units = "npc",
>                          just = c("left"),
>                          gp = gpar(fontsize = 12,fontface="bold") )
>                        },
>     par.settings = c(simpleTheme(lty=1:8, 
>col="black",lwd=2),list(axis.components=list(bottom=list(tck=c(0,1))),layout.heights
> = list(main = 1.2,
>                        sub  = 0,
>                        axis.top = 0.2,
>                        top.padding  = 0.1,
>                        bottom.padding = 0)) ),
>         auto.key = list(x = 0.2, y = 0.9,
>         cex = 0.75, points = FALSE, lines = TRUE)) 
> j=1
> print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)
> 
> Many thanks,
> Lisa
> 
> 
> 
> 
> - Original Message -
> From: Lisa Daniel 
> To: "r-help@r-project.org" 
> Cc: 
> Sent: Thursday, February 14, 2013 12:14 PM
> Subject: Alternate tick labels in xyplot
> 
> Dear Rhelp,
> 
> I would like to get alternate tick labels for the xyplot:
> library(lattice)
> library(grid)
> 
> xy <-xyplot(decrease ~ treatment, OrchardSprays,
>     main= "Some plot",
>         groups = rowpos, type = "a",
>                 page     = function(n){
>                          grid.text(LETTERS[j],
>                          y = 0.95,
>                          x = 0.15,
>                          default.units = "npc",
>                          just = c("left"),
>                          gp = gpar(fontsize = 12,fontface="bold") )
>                        },
>     par.settings = c(simpleTheme(lty=1:8, 
>col="black",lwd=2),list(layout.heights = list(main = 1.2,
>                        sub  = 0,
>                        axis.top = 0.2,
>                        top.padding  = 0.1,
>                        bottom.padding = 0)) ),
>         auto.key = list(x = 0.2, y = 0.9,
>         cex = 0.75, points = FALSE, lines = TRUE)) 
> j=1
> print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.5, 0.99, 1.0), mo

[R] lm regression query

2013-02-14 Thread email
Hello:

I have a 4-column dataset: Crime, Education, Urbanization, Age. I want to
construct a multiple linear regression to find the effect of Education,
Urbanization, and Age on Crime"

lm(Crime ~ Education + Urbanization + Age)

If I use + in above statement, does it mean it will build a model to find
the relationship between Crime and Education when Urbanization and Age are
held constant?

What would be the difference if I drop the term Urbanization + Age ?

lm(Crime ~ Education)

Regards:
John

[[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] Building a Package & using gWidgets

2013-02-14 Thread Benjamin Ward (ENV)
Hi,

For the past few months I've been building a simulation in R I hope to package. 
It consists of two usable functions, and many internal ones which one of the 
two usable functions call while looping, to perform the stages of simulation.

A simple conceptual example is:

# Abstract representation 1st Usable function, generates object containing 
settings for simulation.
settings <- function(){
  matrix(c(1:4),nrow=2,ncol=2)
}

# Abstract representation of one of many internal functions, does some action 
in simulation.
int.func <- function(x){
  out <- x*2
  return(out)
}

# Abstract representation of second usable function, takes settings & invokes 
internal functions generates results & saves as R object files.
sim.func <- function(x){
  ans <- int.func(x)
  ans2 <- ans-2
  save(ans2, file="outtest")
}

With my package so far, using it is done like so after loading and attaching 
the package with library():

INPUT <- settings()
fix(settings) # If you want to change from the defaults.
sim.func(INPUT)

Nothing needs returning from the simulation because it gets saved as an object 
to be read in afterwards.

Now I'd like it to have a simple GUI which can be used in conjunction with 
command line - think Rcmdr but much more simple, to allow my co-workes who have 
never touched R to use it.
The gui needs to be able to edit the settings - like with the fix command 
above, to save a settings object to file, and to read in setting from an object 
file. I've built this with gWidgets:

gui <- function(){
  INPUT <- matrix(c(1:4),nrow=2,ncol=2)

  mainwin <- gwindow("MainWindow")

  button1 <- gbutton("Edit Settings", cont=mainwin, handler=
   function(h,...){
 fix(INPUT)
 print("Settings Edited")
   })

  button2 <- gbutton("RUN", cont=mainwin, handler=
   function(h,...){
 sim.func(INPUT)
 print("The run is done")
   })

  savebutton <- gbutton("Write Settings to File",cont=mainwin, handler=
  function(h,...){
setfilename <- ginput("Please enter the filename")
save(INPUT, file=setfilename)
  })

  loadutton <- gbutton("Load Settings from File", cont=mainwin,
   handler=function(h,...){
 fname <- gfile(test="Choose a file",
type="open",
action="print",
handler =
  function(h,...){
do.call(h$action, list(h$file))
  }
 )
 load(fname)})
}

Note the job of the settings function from before is now done by the first line 
of this gui function.
I add this to the same R file as the three functions above, add 'gui' to the 
namespace as an export, set gWidgets stuff as imports, and rebuild, then I 
library() the package and do gui().
The interface shows up. However I have a few issues:
The gui shows up fine, but if I click button1 to edit settings through 
fix(INPUT), then change the values, close the editor and click the button again 
to see if the changes have persisted and been stored in INPUT, they have not.
Same goes for reading in an object, it does not overwrite the INPUT object 
generated by default in the first line of function gui().

I think this has something to do with environments of functions but I'm not too 
sure. In the gui-less version of my package, the user generates the object 
containing settings, which is in workspace and feeds it to the simulation 
function as an argument. However since with the gui version, everything is run 
inside the function gui() and gWidgets handlers makes use of functions(h,...) I 
can't help but feel as if environments are the issue here. It's odd that when 
clicking on button 1, it will find INPUT from the gui() environment, but won't 
make the changes back there.

Can anybody help out with this and suggest what it is I need to do?

Apologies for a long email, but I've tried to explain clearly. Code is 
reproducible, as is the issue, just by having library(gWidgets, gWidgetstcltk)
and copying and pasting code. The abstract example I've provided faithfully 
reproduces the same issues I have with my proper simulation functions so if I 
can't get it working, I won't get the real thing working.

Thanks,

Ben W.
UEA
The Sainsbury Laboratory.

[[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] hyper-parameters

2013-02-14 Thread Juan Manuel Becerra
I'm searching a method to estimate the hyper-parameters in arima models.
I'm reading about r-inla package, but in the examples section only talk
about the AR part of the arima, but i need help about the MA part too.

I'm beginner in Bayesian methods, I'm reading the documentation about dlm
package and kalman filters, but the computacional cost of inla i think is
better, but  only AR models are supported for the moment. What's packages
can help me for that?.

Someone can help me about it?. I need ligth for this question. If it's
possible with a arima(1,0,1) example, w

Thanks All

[[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] 2 setGeneric's, same name, different method signatures

2013-02-14 Thread Greg Minshall
i'm answering my own question: 

1.  setGeneric's override (wipe out, really) previous ones.  (this is
pointed out in section 5.3 of "A (Not So) Short Introduction to S4
Object Oriented Programming in R" by Christophe Genolini.)

2.  the *names* of the formals are important.

3.  one can specify a method that takes a subset of the formals declared
in the setGeneric.

so, in my example, changing "me" to "b1" in A's bB(), allows A to use
B's setGeneric().

for completeness, below is my code that works (or, seems to!).

if anyone knows, in #3 above, how A can specify that "no b2 is
allowed!", i'd be curious.

cheers, Greg Minshall

setClass("A",
 representation(
   x="numeric"));

setMethod(
  f="initialize",
  signature="A",
  definition=function(.Object) {
.Object@x <- 23;
return(.Object)
  });

setGeneric("bB", function(me) standardGeneric("bB"));
setMethod(
  "bB",
  signature("A"),
  definition=function(b1) {
return (new("B", b1@x))});

setClass("B", representation(
  bx="numeric"));

setMethod(
  "initialize",
  signature("B"),
  definition=function(.Object, x) {
.Object@bx <- x;
return(.Object);
  });

setGeneric("bB", function(b1, b2) standardGeneric("bB"));
setMethod(
  "bB",
  signature("B", "B"),
  definition=function(b1, b2) {
return(new("B", min(b1@bx, b2@bx)))});

__
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] appending data to a row

2013-02-14 Thread arun
HI,
May be this helps:
(assuming that there are only twins)

dat1<- read.table(text="
FamilyID  ParticipantID  IQ  Digit_span
1    1  95  6
1    2  93  7
2    3  102 8
2    4  101 9
3    5  106 7
3    6  108 9
",sep="",header=TRUE)
 dat1$Co_twin_IQ<-NA
 dat1$Co_twin_Digit_span<-NA
 
dat1[,5:6]<-do.call(rbind,lapply(split(dat1,dat1$FamilyID),function(x)x[2:1,3:4]))

dat1
#  FamilyID ParticipantID  IQ Digit_span Co_twin_IQ Co_twin_Digit_span
#1    1 1  95  6 93  7
#2    1 2  93  7 95  6
#3    2 3 102  8    101  9
#4    2 4 101  9    102  8
#5    3 5 106  7    108  9
#6    3 6 108  9    106  7


dat2<- read.table(text="
FamilyID  ParticipantID  IQ  Digit_span Co-twin_IQ Co-twin_Digit_span
1    1  95  6  93  7
1    2  93  7  95  6
2    3  102 8  101    9
2    4  101 9  102    8
3    5  106 7  108    9
3    6  108 9  106    7
",sep="",header=TRUE)
colnames(dat2)<- colnames(dat1)
 identical(dat1,dat2)
#[1] TRUE
A.K.




- Original Message -
From: Jamie 
To: r-help@r-project.org
Cc: 
Sent: Thursday, February 14, 2013 4:07 PM
Subject: [R] appending data to a row

For an analysis of data from twins, I'd like to do some rearranging in my
dataframe. Currently, each twin has his or her own row. I'd like to add
several columns of the co-twin's data to each row. In other words, this is
the current situation:

FamilyID  ParticipantID  IQ  Digit_span
1             1          95  6
1             2          93  7
2             3          102 8
2             4          101 9
3             5          106 7
3             6          108 9

And this is what I'd like to have, only with even more co-twin data:

FamilyID  ParticipantID  IQ  Digit_span Co-twin_IQ Co-twin_Digit_span
1             1          95  6          93          7
1             2          93  7          95          6
2             3          102 8          101         9
2             4          101 9          102         8
3             5          106 7          108         9
3             6          108 9          106         7

I'm not sure how to tell R to take the specified values from the other row
with the same family ID and append them with a new name. Thanks for any
ideas you can offer me.

Jamie in Illinois

    [[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] plot custom x axis ticks values

2013-02-14 Thread Jim Lemon

On 02/14/2013 09:41 PM, e-letter wrote:

Readers,

For this data set:

testvalues<-c(10,20,30,40)

How to amend the plot instruction:

plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n')

so that x axis ticks labels can be added to existing graph with
arbitrary value such as 0,100,200,300)?


Hi r2151,
If you want the labels to fit on the axis you will have to include this 
information in the call to "plot":


plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n',ylim=c(0,300))
axis(2,at=c(0,100,200,300))

As you may be adding more values after the first set, the same goes for 
the X axis if there are different numbers of Y values.


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] 2 setGeneric's, same name, different method signatures

2013-02-14 Thread Martin Morgan

On 2/14/2013 8:57 AM, Greg Minshall wrote:

hi.  below is a small test case (hopefully minimal, though i'm still a
bit confused about initializers).

i would have guessed (and maybe i still would have been right) that one
could re-use the name of a generic function for functions with different
numbers of arguments.  in the case below, class A's bB() queries the
status of a single A object, so bB(A) (where here "A" is an instance of
class A, just for "clarity") returns a value.  class B's bB() compares
values in two B objects, and returns the minimum, so bB(B1, B2) are its
methods.

after loading the file, i see the method for A's bB has disappeared (as
measured by showMethods("bB"), as well as trying bB(A).  if i have R
re-parse the setGeneric/setMethod  A's bB(), then B's bB() disappears.

somehow my code, or my model of how things work, is wrong.  any ideas
what am i missing?

cheers, Greg Minshall

setClass("A",
  representation(
x="numeric"));

setMethod(
   f="initialize",
   signature="A",
   definition=function(.Object) {
 .Object@x <- 23;
 return(.Object)
   });

setGeneric("bB", function(me) standardGeneric("bB"));
setMethod(
   "bB",
   signature("A"),
   definition=function(me) {
 return (new("B", me@x))});

setClass("B", representation(
   bx="numeric"));

setMethod(
   "initialize",
   signature("B"),
   definition=function(.Object, x) {
 .Object@bx <- x;
 return(.Object);
   });

setGeneric("bB", function(b1, b2) standardGeneric("bB"));


Hi Greg --

this setGeneric is over-writing the first, as would

f = function() "first"
f = function() "second"
f() # "second"

If you'd like to dispatch on a single argument, then

setGeneric("one", function(x, ...) standardGeneric("one"))
setMethod("one", "A", function(x, ...) "A-method")
setMetohd("one", "B", function(x, y, ...) "B-method")

The '...' in the generic allow you to add arguments that are 'picked off' by 
methods. The user could provide any value for y, not only an object of class "B".


If you'd like to dispatch sometimes on two arguments then

setGeneric("two", function(x, y, ...) standardGeneric("two"))
setMethod("two", c("A", "ANY"), function(x, y, ...) "A,ANY-method")
setMethod("two", c("B", "B"), function(x, y, ...) "B,B-method")

then two(new("A")), two(new("A"), new("A")) and two(new("A"), new("B")) end up 
in A,ANY,two-method while two(new("B"), new("B")) ends up in "B,B,two-method". 
Other combinations are errors. One might instead not define A,ANY but instead


setMethod("two", c("A", "missing"), function(x, y, ...) "A,missing-method")

and then two(new("A"), new("A")) would be an error.

Multiple dispatch is complicated, and perhaps best to avoid if possible.

It's possible to write a generic and methods that dispatch on '...', with the 
requirement that all classes are the same; this in the spirit of comparing two 
B's and returning the smaller; see ?dotsMethods though again this is not a 
trivial use case.


Hope that helps enough.

Martin


setMethod(
   "bB",
   signature("B", "B"),
   definition=function(b1, b2) {
 return(new("B", min(b1@bx, b2@bx)))});

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




--
Dr. Martin Morgan, PhD
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

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


Re: [R] How to stack row vector on top of each other?

2013-02-14 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of C W
> Sent: Thursday, February 14, 2013 5:08 PM
> To: r-help
> Subject: [R] How to stack row vector on top of each other?
> 
> Hi list,
> How do you actually stack a vector on top of each other?  Say, I want
> everything in a row vector.  Neither rbind(), nor cbind() will do the
> job.
>  It gives me 2 dimension.
> 
> Here's my reproducible example:
> > a <- rnorm(10)
> > b <- rnorm(10)
> > c <- cbind(a,b)
> > dim(c)
> [1] 10  2
> 
> > d <- rbind(a,b)
> > dim(d)
> [1]  2 10
> 
> Thanks,
> Mike

I guess I don't know what you mean by "actually stack a vector on top of each 
other".  Given the vectors 

a <- 1:3
b <- 4:6

What result do you want from "stacking" a and b?


Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


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


Re: [R] How to stack row vector on top of each other?

2013-02-14 Thread C W
Wow, thanks, I just wasn't thinking right.

I also figured this would do cbind(t(a), t(b)), but that's asking for more
work.

Mike

On Thu, Feb 14, 2013 at 8:17 PM, Pascal Oettli  wrote:

> Hi,
>
> Actually, ?"c"
>
>
> > a <- rnorm(10)
> > b <- rnorm(10)
> > d <- c(a,b)
> > length(d)
> [1] 20
>
> HTH,
> Pascal
>
>
> Le 15/02/2013 10:08, C W a écrit :
>
>> Hi list,
>> How do you actually stack a vector on top of each other?  Say, I want
>> everything in a row vector.  Neither rbind(), nor cbind() will do the job.
>>   It gives me 2 dimension.
>>
>> Here's my reproducible example:
>>
>>> a <- rnorm(10)
>>> b <- rnorm(10)
>>> c <- cbind(a,b)
>>> dim(c)
>>>
>> [1] 10  2
>>
>>  d <- rbind(a,b)
>>> dim(d)
>>>
>> [1]  2 10
>>
>> Thanks,
>> Mike
>>
>> [[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] How to stack row vector on top of each other?

2013-02-14 Thread Pascal Oettli

Hi,

Actually, ?"c"

> a <- rnorm(10)
> b <- rnorm(10)
> d <- c(a,b)
> length(d)
[1] 20

HTH,
Pascal


Le 15/02/2013 10:08, C W a écrit :

Hi list,
How do you actually stack a vector on top of each other?  Say, I want
everything in a row vector.  Neither rbind(), nor cbind() will do the job.
  It gives me 2 dimension.

Here's my reproducible example:

a <- rnorm(10)
b <- rnorm(10)
c <- cbind(a,b)
dim(c)

[1] 10  2


d <- rbind(a,b)
dim(d)

[1]  2 10

Thanks,
Mike

[[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] How to stack row vector on top of each other?

2013-02-14 Thread C W
Hi list,
How do you actually stack a vector on top of each other?  Say, I want
everything in a row vector.  Neither rbind(), nor cbind() will do the job.
 It gives me 2 dimension.

Here's my reproducible example:
> a <- rnorm(10)
> b <- rnorm(10)
> c <- cbind(a,b)
> dim(c)
[1] 10  2

> d <- rbind(a,b)
> dim(d)
[1]  2 10

Thanks,
Mike

[[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] sweave question

2013-02-14 Thread Duncan Mackay

Hi Mark

I need pdfs for Sweave etc, my colleagues  want wmfs or the ilk and 
for publishing eps/tiff so I just add a section for each with in the 
'print' chunk


Duncan


At 02:49 15/02/2013, you wrote:

Hi Dan, Duncan and Yihui: I apologize for my late response.

Dan: Your backslash explanation was great but yes, I think there was a
transmission problem in the link I
sent. I made the changes and everything compiled without a glitch but the
actual tex file ends
up with many begin{Schunk} and end{Schunk} statements and somehow I think
this causes the pdf to
not get put in the document. But atleast I learned I now understand the
backslash issue and why my attempt wasn't working.  So, you solved the
problem that I had but another different issue now lurks
but, given below, I'm gonna let it go.  Thanks.

Duncan: Your solution worked.  I'm not sure why I didn't think of
seperating the two processes.
That was a nice idea. I guess I got caught up in the cat method once I saw
it.  Thanks.

Yihui: I'm starting to learn Rstudio by going through the recent book out
on it. There's a section
about knitR in the book so I hope to go over that and then turn to many of
your other documents.
Thanks for recommending knitR ( I loved the kitten statement at the link,
especially since I have cats ) and it is something I plan on learning, in
addition to 20 other thousand things on my list of "to be learned".


Mark









On Wed, Feb 13, 2013 at 9:00 PM, Yihui Xie  wrote:

> Other people in this thread have explained the rule of double
> backslashes. I just want to add one more comment:
>
> That clever solution was in 2009 when knitr has not come out, and I
> have used this picture several times to show how much I dislike it:
> http://yihui.name/en/2012/06/enjoyable-reproducible-research/
>
> With knitr, you can easily write your big code chunk (with lots of
> "cats" jumping around) in a much more compact way:
>
> < out.height="5in", fig.cap="The resulting unpruned regression tree of
> the California real estate data">>=
> plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
> text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
> @
>
> Note the number "5" alone is not a legal LaTeX length; you should add
> the unit such as "5in" or "5cm", etc. This chunk in knitr will
> generate everything for you:
>
> - the figure environment
> - center the figure
> - add the figure position ht!
> - add the figure caption
> - add figure width and height
> - add the figure label fig:figthree
>
> You, as the author, only write the R code (instead of both R and
> LaTeX); other people, as the readers, only see the R code. Everything
> else should go behind the scene.
>
> Regards,
> Yihui
> --
> Yihui Xie 
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
> On Wed, Feb 13, 2013 at 4:59 PM, Mark Leeds  wrote:
> > Hi Everyone: I was having trouble getting the plot size correct when
> > putting a plot in an sweave document. So, I searched on the internet and
> I
> > found a clever solution where the person uses
> > the cat function to write latex code so he can include the cat code in
> the
> > chunk and place the plot using width and height. The solution is here:
> > https://stat.ethz.ch/pipermail/r-help/2009-April/195094.html.
> >
> > But the solution uses a backslash before the ending quotes in the cat
> > statements  that might be windows relevant possibly ? I'm not sure about
> > that part but I'm on linux and when I tried my way to mimic that solution
> > in the latex/sweave code below ( I think it's the same solution but
> without
> > the backslash on the closing quotes. I tried that also but got a
> different
> > error ) , Sweave doesn't like the start of the includegraphics command.
> The
> > error I get from Sweave is
> >
> > #===
> > Error:  chunk 9 (label = fig3)
> > Error : '\i' is an unrecognized escape in character string starting "\i"
> > Execution halted
> > :~/research/equity/projects/tree_returns/report>
> > #=
> >
> > The code is below but if anyone is interested and thinks they need the
> > whole file to look at the problem, I can send it. I just didn't want to
> > send the whole file here. Definitely the error has to do with the chunk
> > below for sure ( even though it says chunk 9 because there is no chunk 9
> > ).  Thanks a lot to anyone who can be bothered investigating because I've
> > spent pretty much the whole day on this and think it's
> > time to surrender !! or atleast give up for now and come back to
> it
> > with a fresher brain. Have a good night.
> >
> > # THE LATEX/SWEAVE CODE
> > #
> >
> > cal.tree is created in a previous chunk and that's fine.
> >
> > <>=
> > wid <- 5
> > hei <- 5
> > pdf("reg_tree-fig3.pdf", width = wid, height = hei)
> > plot(cal.tree,unifor

Re: [R] appending data to a row

2013-02-14 Thread Rui Barradas

Hello,

Maybe something like the following.


dat <- read.table(text = "
FamilyID  ParticipantID  IQ  Digit_span
1 1  95  6
1 2  93  7
2 3  102 8
2 4  101 9
3 5  106 7
3 6  108 9
", header = TRUE)
dat$timevar <- rep(1:2, nrow(dat)/2)
reshape(dat, idvar = "FamilyID", timevar = "timevar", direction = "wide")



See ?reshape.

Hope this helps,

Rui Barradas

Em 14-02-2013 21:07, Jamie escreveu:

For an analysis of data from twins, I'd like to do some rearranging in my
dataframe. Currently, each twin has his or her own row. I'd like to add
several columns of the co-twin's data to each row. In other words, this is
the current situation:

FamilyID  ParticipantID  IQ  Digit_span
1 1  95  6
1 2  93  7
2 3  102 8
2 4  101 9
3 5  106 7
3 6  108 9

And this is what I'd like to have, only with even more co-twin data:

FamilyID  ParticipantID  IQ  Digit_span Co-twin_IQ Co-twin_Digit_span
1 1  95  6  93  7
1 2  93  7  95  6
2 3  102 8  101 9
2 4  101 9  102 8
3 5  106 7  108 9
3 6  108 9  106 7

I'm not sure how to tell R to take the specified values from the other row
with the same family ID and append them with a new name. Thanks for any
ideas you can offer me.

Jamie in Illinois

[[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] appending data to a row

2013-02-14 Thread David Winsemius

On Feb 14, 2013, at 1:07 PM, Jamie wrote:

> For an analysis of data from twins, I'd like to do some rearranging in my
> dataframe. Currently, each twin has his or her own row. I'd like to add
> several columns of the co-twin's data to each row. In other words, this is
> the current situation:
> 
> FamilyID  ParticipantID  IQ  Digit_span
> 1 1  95  6
> 1 2  93  7
> 2 3  102 8
> 2 4  101 9
> 3 5  106 7
> 3 6  108 9
> 
> And this is what I'd like to have, only with even more co-twin data:
> 
> FamilyID  ParticipantID  IQ  Digit_span Co-twin_IQ Co-twin_Digit_span
> 1 1  95  6  93  7
> 1 2  93  7  95  6
> 2 3  102 8  101 9
> 2 4  101 9  102 8
> 3 5  106 7  108 9
> 3 6  108 9  106 7
> 
> I'm not sure how to tell R to take the specified values from the other row
> with the same family ID and append them with a new name. Thanks for any
> ideas you can offer me.

> dat2 <- merge(dat, dat, by.x=1, by.y=1)
> dat2 [ with( dat2, ParticipantID.x != ParticipantID.y) , ]
   FamilyID ParticipantID.x IQ.x Digit_span.x ParticipantID.y IQ.y Digit_span.y
2 1   1   956   2   937
3 1   2   937   1   956
6 2   3  1028   4  1019
7 2   4  1019   3  1028
103   5  1067   6  1089
113   6  1089   5  1067

-- 

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.


Re: [R] Rcmdr, RODBC and XLConnect conflict cause R to crash

2013-02-14 Thread John Fox
Dear Jeremy,

I'm not sure why loading all three packages creates a problem, but I can 
explain how the Rcmdr uses each of the other two. 

RODBC is more general than XLConnect, in that it allows the Rcmdr to read dBase 
and Access files in addition to Excel files. On the other hand, RODBC cannot 
read these kinds of files under 64-bit R for Windows, only under 32-bit R. 
Consequently, when the Rcmdr runs under 64-bit R for Windows, it instead uses 
the XLConnect package to read Excel files (but cannot read dBase or Access 
files).

I'm not sure why you would have all three of these packages loaded at once. I 
consider (at least from the point of view of the Rcmdr), the RODBC and 
XLConnect packages to be alternatives, and the proper package will be loaded 
when the corresponding menu item is first invoked.

I hope this helps,
 John


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

On Thu, 14 Feb 2013 21:43:21 +0100
 Jeremy MAZET  wrote:
> Dear all,
> 
> Since I upgraded R to the version 2.15.2, I have a strange problem which 
> implies XLConnect, RODBC and Rcmdr packages. 
> 
> - If the three packages are loaded in the same R session, the use of 
> RodbcConnect functions cause R to crash.
> - This crash occur only if Rcmdr is loaded. 
>  - If only one of the  RODBC or XLConnect package is loading with Rcmdr, 
> everything seems to be fine.
> 
> I reproduced the problem on several computers, always with the Windos XP 
> environement.
> 
> I hope someone could give me a piece of advice. 
> 
> Jérémy Mazet
> 
> > sessionInfo()
> R version 2.15.2 (2012-10-26)
> Platform: i386-w64-mingw32/i386 (32-bit)
> 
> locale:
> [1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252 
> [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C 
> [5] LC_TIME=French_France.1252 
> 
> attached base packages:
> [1] tcltk stats graphics  grDevices utils datasets  methods 
> [8] base 
> 
> other attached packages:
> [1] XLConnect_0.2-4 XLConnectJars_0.2-4 rJava_0.9-3 
> [4] RODBC_1.3-6 Rcmdr_1.9-2 car_2.0-15 
> [7] nnet_7.3-5  MASS_7.3-23 
> 
> 
>   [[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] Alternate tick labels in xyplot

2013-02-14 Thread David Winsemius

On Feb 14, 2013, at 10:52 AM, Lisa Daniel wrote:

> Dear Rhelp,
> I was able to solve the tick labels part.  If somebody can help me in 
> creating title for each row of figures above the individual headings, it will 
> be great.

I think you need to be looking at grid.text() in package grid.

> library(grid)
> library(lattice)
> xy <-xyplot(decrease ~ treatment, OrchardSprays,
> main= "Some plot",
> groups = rowpos, type = "a",
> scales=list(x=list(at=seq(1,8,1),labels=c('A','','C','','E','','G',''))),
> page = function(n){
>  grid.text(LETTERS[j],
>  y = 0.95,
>  x = 0.15,
>  default.units = "npc",
>  just = c("left"),
>  gp = gpar(fontsize = 12,fontface="bold") )
>},
> par.settings = c(simpleTheme(lty=1:8, 
> col="black",lwd=2),list(axis.components=list(bottom=list(tck=c(0,1))),layout.heights
>  = list(main = 1.2,
>sub  = 0,
>axis.top = 0.2,
>top.padding  = 0.1,
>bottom.padding = 0)) ),
> auto.key = list(x = 0.2, y = 0.9,
> cex = 0.75, points = FALSE, lines = TRUE)) 
> j=1
> print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)
> 
> Many thanks,
> Lisa
> 
> 
> 
> 
> - Original Message -
> From: Lisa Daniel 
> To: "r-help@r-project.org" 
> Cc: 
> Sent: Thursday, February 14, 2013 12:14 PM
> Subject: Alternate tick labels in xyplot
> 
> Dear Rhelp,
> 
> I would like to get alternate tick labels for the xyplot:
> library(lattice)
> library(grid)
> 
> xy <-xyplot(decrease ~ treatment, OrchardSprays,
> main= "Some plot",
> groups = rowpos, type = "a",
> page = function(n){
>  grid.text(LETTERS[j],
>  y = 0.95,
>  x = 0.15,
>  default.units = "npc",
>  just = c("left"),
>  gp = gpar(fontsize = 12,fontface="bold") )
>},
> par.settings = c(simpleTheme(lty=1:8, 
> col="black",lwd=2),list(layout.heights = list(main = 1.2,
>sub  = 0,
>axis.top = 0.2,
>top.padding  = 0.1,
>bottom.padding = 0)) ),
> auto.key = list(x = 0.2, y = 0.9,
> cex = 0.75, points = FALSE, lines = TRUE)) 
> j=1
> print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
> j=j+1
> print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
> j=j+1
> print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
> j=j+1
> print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)
> 
> 
> similar to the x-axis in the code below, but somehow it is not working when I 
> pasted 'list(axis.components=...) in the above code:
> xyplot(rnorm(12) ~ 1:12 , type="l",
> scales=list(x=list(at=seq(2,12,2),labels=c(1, ' ', 3 , ' ' , 5 , ' ' ))),
> par.settings=list(axis.components=list(bottom=list(tck=c(0,1) 
> 
> scales=list(x=list(at=seq(1,8,1),labels=c('A', ' ', 'C', ' ' ,'E' , ' ','G',' 
> '))),
> 
> If possible, I would like a heading for each rows (justified to center) above 
> the individual heading.
> 
> Please help.
> Many thanks,
> Lisa.
> 
> 
> __
> 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.

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.


Re: [R] stratified analysis

2013-02-14 Thread John Kane
Nothing got through.  You need to send everything in text format.

John Kane
Kingston ON Canada


> -Original Message-
> From: 98sa...@gmail.com
> Sent: Thu, 14 Feb 2013 15:04:24 -0500
> To: r-help@r-project.org
> Subject: [R] stratified analysis
> 
> I am having trouble doing a stratified analysis while obtaining the
> mean,median, and standard deviation of each group. I have copied and
> pasted
> the console below.
> 
>   [[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.


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas 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] appending data to a row

2013-02-14 Thread Jamie
For an analysis of data from twins, I'd like to do some rearranging in my
dataframe. Currently, each twin has his or her own row. I'd like to add
several columns of the co-twin's data to each row. In other words, this is
the current situation:

FamilyID  ParticipantID  IQ  Digit_span
1 1  95  6
1 2  93  7
2 3  102 8
2 4  101 9
3 5  106 7
3 6  108 9

And this is what I'd like to have, only with even more co-twin data:

FamilyID  ParticipantID  IQ  Digit_span Co-twin_IQ Co-twin_Digit_span
1 1  95  6  93  7
1 2  93  7  95  6
2 3  102 8  101 9
2 4  101 9  102 8
3 5  106 7  108 9
3 6  108 9  106 7

I'm not sure how to tell R to take the specified values from the other row
with the same family ID and append them with a new name. Thanks for any
ideas you can offer me.

Jamie in Illinois

[[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] stratified analysis

2013-02-14 Thread Samir Navare
I am having trouble doing a stratified analysis while obtaining the
mean,median, and standard deviation of each group. I have copied and pasted
the console below.

[[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] Alternate tick labels in xyplot

2013-02-14 Thread Lisa Daniel
Dear Rhelp,
I was able to solve the tick labels part.  If somebody can help me in creating 
title for each row of figures above the individual headings, it will be great.
library(grid)
library(lattice)
xy <-xyplot(decrease ~ treatment, OrchardSprays,
    main= "Some plot",
    groups = rowpos, type = "a",
    scales=list(x=list(at=seq(1,8,1),labels=c('A','','C','','E','','G',''))),
        page = function(n){
 grid.text(LETTERS[j],
 y = 0.95,
 x = 0.15,
 default.units = "npc",
 just = c("left"),
 gp = gpar(fontsize = 12,fontface="bold") )
   },
    par.settings = c(simpleTheme(lty=1:8, 
col="black",lwd=2),list(axis.components=list(bottom=list(tck=c(0,1))),layout.heights
 = list(main = 1.2,
   sub  = 0,
   axis.top = 0.2,
   top.padding  = 0.1,
   bottom.padding = 0)) ),
    auto.key = list(x = 0.2, y = 0.9,
    cex = 0.75, points = FALSE, lines = TRUE)) 
j=1
print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)

Many thanks,
Lisa




- Original Message -
From: Lisa Daniel 
To: "r-help@r-project.org" 
Cc: 
Sent: Thursday, February 14, 2013 12:14 PM
Subject: Alternate tick labels in xyplot

Dear Rhelp,

I would like to get alternate tick labels for the xyplot:
library(lattice)
library(grid)

xy <-xyplot(decrease ~ treatment, OrchardSprays,
    main= "Some plot",
    groups = rowpos, type = "a",
        page = function(n){
 grid.text(LETTERS[j],
 y = 0.95,
 x = 0.15,
 default.units = "npc",
 just = c("left"),
 gp = gpar(fontsize = 12,fontface="bold") )
   },
    par.settings = c(simpleTheme(lty=1:8, 
col="black",lwd=2),list(layout.heights = list(main = 1.2,
   sub  = 0,
   axis.top = 0.2,
   top.padding  = 0.1,
   bottom.padding = 0)) ),
    auto.key = list(x = 0.2, y = 0.9,
    cex = 0.75, points = FALSE, lines = TRUE)) 
j=1
print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)


similar to the x-axis in the code below, but somehow it is not working when I 
pasted 'list(axis.components=...) in the above code:
xyplot(rnorm(12) ~ 1:12 , type="l",
scales=list(x=list(at=seq(2,12,2),labels=c(1, ' ', 3 , ' ' , 5 , ' ' ))),
par.settings=list(axis.components=list(bottom=list(tck=c(0,1) 

scales=list(x=list(at=seq(1,8,1),labels=c('A', ' ', 'C', ' ' ,'E' , ' ','G',' 
'))),

If possible, I would like a heading for each rows (justified to center) above 
the individual heading.

Please help.
Many thanks,
Lisa.


__
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] match in dependence of 2 columns

2013-02-14 Thread arun
HI,

If the dataset is similar to this:
dat1<- read.table(text=" 
  cu.nr. name  value  
A 1 Evo 100 
B 1 Mer 80  
C 2 Ford    50  
",sep="",header=TRUE,stringsAsFactors=F) 
dat2<- read.table(text=" 
  cu.nr. name  value2 value3    
A 33 Evo   60   120 
B 1 Mer    40    90 
C 1 Pold   20    30   
",sep="",header=TRUE,stringsAsFactors=F)  
library(plyr)
join(dat1,subset(dat2,select=c("cu.nr.","name")),by=c("cu.nr.","name"),type="right")
#  cu.nr. name value
#1 33  Evo    NA
#2  1  Mer    80
#3  1 Pold    NA
#or
join(dat1,dat2[,c("cu.nr.","name")],by=c("cu.nr.","name"),type="right")


A.K.



- Original Message -
From: Mat 
To: r-help@r-project.org
Cc: 
Sent: Thursday, February 14, 2013 2:03 AM
Subject: Re: [R] match in dependence of 2 columns

thank you, this code works:

library(plyr)
join(dat1,dat2,by=c("cu.nr.","name"),type="right") 

but my dat2 frame has a lot of columns, which i don't want to match.
How can i say, that only the column "value" should be match to dat1 ?

Thank you.

Mat




--
View this message in context: 
http://r.789695.n4.nabble.com/match-in-dependence-of-2-columns-tp4658405p4658508.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.


__
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] Rcmdr, RODBC and XLConnect conflict cause R to crash

2013-02-14 Thread Jeremy MAZET
Dear all,

Since I upgraded R to the version 2.15.2, I have a strange problem which 
implies XLConnect, RODBC and Rcmdr packages. 

- If the three packages are loaded in the same R session, the use of 
RodbcConnect functions cause R to crash.
- This crash occur only if Rcmdr is loaded. 
 - If only one of the  RODBC or XLConnect package is loading with Rcmdr, 
everything seems to be fine.

I reproduced the problem on several computers, always with the Windos XP 
environement.

I hope someone could give me a piece of advice. 

Jérémy Mazet

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252 
[3] LC_MONETARY=French_France.1252 LC_NUMERIC=C 
[5] LC_TIME=French_France.1252 

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

other attached packages:
[1] XLConnect_0.2-4 XLConnectJars_0.2-4 rJava_0.9-3 
[4] RODBC_1.3-6 Rcmdr_1.9-2 car_2.0-15 
[7] nnet_7.3-5  MASS_7.3-23 


[[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] Clip a contour with shapefile while using contourplot

2013-02-14 Thread Janesh Devkota
Hi, I have done the interpolation for my data and I was able to create the
contours in multipanel with the help of Pascal. Now, I want to clip the
contour with the shapefile. I want only the portion of contour to be
displayed which falls inside the boundary of the shapefile.

The data mydata.csv can be found on
https://www.dropbox.com/s/khi7nv0160hi68p/mydata.csv

The data for shapefile can be found on
https://www.dropbox.com/sh/ztvmibsslr9ocmc/YOtiwB8p9p

THe code I have used so far is as follows:

# Load Libraries
library(latticeExtra)
library(sp)
library(rgdal)
library(lattice)
library(gridExtra)

#Read Shapefile
hello <- readOGR("shape",
 layer="Export_Output_4")
## Project the shapefile to the UTM 16 zone
proj4string(hello) <- CRS("+proj=utm +zone=16 +ellps=WGS84")

## Read Contour data
mydata <- read.csv("mydata.csv")
head(mydata )
summary(mydata)

#Create a contourplot
contourplot(Salinity ~ Eastings+Northings | Time, mydata,
cuts=30,pretty=TRUE)

Thank you so much. I would welcome any other ways to do this aside from
contourplot and lattice.

Best Regards,
Janesh

[[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] party::cforest - predict?

2013-02-14 Thread James Jong
What is the function call interface for predict in the package party for
cforest? I am looking at the documentation (the vignette) and ?cforest and
from the examples I see that one can call the function predict on a cforest
classifier. The method predict seems to be a method of the class
 RandomForest objects of which are returned by cforest.

---
> cf.model = cforest(...)
> methods(class=class(cf.model))
[1] predict.RandomForest*predictors.RandomForest* print.RandomForest*

[4] varImp.RandomForest* weights.RandomForest*

   Non-visible functions are asterisked
---

But I could not find the list of arguments that predict for cforest accepts.

The link on the function "predict" in the vignette (wherever it is
mentioned) just takes you to the front page. Is the API for predict missing
from the documentation?

Thanks,

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.


Re: [R] CARET: Any way to access other tuning parameters?

2013-02-14 Thread James Jong
Got it. Thank you Max.

James


On Wed, Feb 13, 2013 at 1:30 PM, Max Kuhn  wrote:

>
>
> @Max - Thanks a lot for your help. I have already been using that website
>> as a reference, and it's incredibly helpful. I have also been experimenting
>> with tuneGrid already. My question was specifically if tuneGrid (or caret
>> in general) supports passing method parameters to the method functions from
>> each package other than those listed in the CARET documentation (e.g. I
>> would like to specify sampsize and nodesize for randomForest, and not just
>> mtry).
>>
>>
> Yes. A custom method is how you do that.
>
>
>> Thanks,
>>
>> James
>>
>>
>>
>>
>>
>>
>> On Wed, Feb 13, 2013 at 1:07 PM, Max Kuhn  wrote:
>>
>>> James,
>>>
>>> You really need to read the documentation. Almost every question that
>>> you have has been addressed in the existing material. For this one, there
>>> is a section on custom models here:
>>>
>>>http://caret.r-forge.r-project.org/training.html
>>>
>>> Max
>>>
>>>
>>> On Wed, Feb 13, 2013 at 9:58 AM, James Jong wrote:
>>>
 The documentation for caret::train shows a list of parameters that one
 can
  tune for each method classification/regression method. For example, for
 the method randomForest one can tune mtry in the call to train. But the
  function call to train random forests in the original package has many
 other parameters, e.g. sampsize, maxnodes, etc.

 Is there **any** way to access these parameters using train in caret?
 (Is
 the function caret::createGrid limited to the list of parameters
 specified
 in the caret documentation, it's not super clear if the list of
 parameter
 is for all the caret APIs).

 Thanks,

 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.

>>>
>>>
>>>
>>> --
>>>
>>> Max
>>>
>>
>>
>
>
> --
>
> Max
>

[[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] plot custom x axis ticks values

2013-02-14 Thread MacQueen, Don
> plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n')
> par()$usr
[1]  0.88  4.12  8.80 41.20

The x axis range is from 0.88 to 4.12, so tick labels at 0, 100, 200, 300
makes no sense.

Any axis() command where the 'at' values are within the range of the x
axis will work. Even, for example,

  axis(1, at=c(2.5, 3.7) )

-Don


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 2/14/13 2:41 AM, "e-letter"  wrote:

>Readers,
>
>For this data set:
>
>testvalues<-c(10,20,30,40)
>
>How to amend the plot instruction:
>
>plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n')
>
>so that x axis ticks labels can be added to existing graph with
>arbitrary value such as 0,100,200,300)?
>
>Thanks in advance.
>
>--
>r2151
>
>__
>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] An extended Hodgkin-Huxley model that doesn't want to work.

2013-02-14 Thread Berend Hasselman

Forgot Reply to All.

On 13-02-2013, at 23:30, Jannetta Steyn  wrote:

> Hi All
> 
> I have been struggling with this model for some time now and I just can't
> get it to work correctly. The messages I get when running the code is:
> 
> DLSODA-  Warning..Internal T (=R1) and H (=R2) are
> such that in the machine, T + H = T on the next step
>(H = step size). Solver will continue anyway.
> In above message, R =
> [1] 0 0
> DINTDY-  T (=R1) illegal
> In above message, R =
> [1] 0.1
> T not in interval TCUR - HU (= R1) to TCUR (=R2)
> In above message, R =
> [1] 0 0
> DINTDY-  T (=R1) illegal
> In above message, R =
> [1] 0.2
> T not in interval TCUR - HU (= R1) to TCUR (=R2)
> In above message, R =
> [1] 0 0
> DLSODA-  Trouble in DINTDY.  ITASK = I1, TOUT = R1
> In above message, I =
> [1] 1
> In above message, R =
> [1] 0.2
> Error in lsoda(y, times, func, parms, ...) :
> illegal input detected before taking any integration steps - see written
> message
> 
> 
> 
> I'll first paste the formulae and then I'll paste my code. If anyone can
> spot something wrong with my implementation it would really make my day.
> 
> (1)
> dV/dt = (I_ext - I_int-I_coup)/C
> I_ext = injected current
> I_int = Sum of all ion currents
> I_coup = coupling current (but we're not using it here )
> 
> (2)
> I_i = g_i * m_i^pi * h_i^pi(V-E)
> i identifies the ion, thus I_K would be Potassium current.
> 
> (3)
> dm/dt = (m_inf*V - m)/tau_m
> 
> (4)
> dh/dt = (h_inf*V-h)/tau_h
> 
> (5)
> The Nernst equation is used to calculate reversal potential for Ca:
> Eca = 12.2396 * log(13000/Ca2+)
> 
> (6)
> d[Ca_2+]/dt = (F*I_Ca - [Ca2+] + C0)/Tau_Ca
> 
> 
> tau_m, tau_h, m_inf and h_inf are all calculated according to formulae
> provided in a paper. In my code these are calculated for the different
> channels into the following variables:
> 
> CaTminf, CaThinf, CaTtaum, CaTtauh, CaSminf, CaStaum, Napminf, Naphinf,
> taumna, tauhna, hminf, htaum, Kminf and Ktaum
> 
> The E (reversal potential) values for all the channels are given, except
> for CaT and CaS which uses Eca as calculated in (5).
> 
> Current for Ca is calculated by summing the CaT and CaS currents, hence
> CaI = gCaT*CaTm^3*CaTh*(v-Eca(v)) + gCaS*CaSm^3(v-ECa(v)
> 
> 
> Here is the code:
> 
> library(simecol)
> ## Hodkin-Huxley model
> HH_soma <-  function(time, init, parms) {
> with(as.list(c(init, parms)),{
> 
>   # Na only used in Axon
>   #Naminf <-1/(1+exp(-(v+24.7)/5.29));
>   #Nataum <- function(v) 1.32 - (1.26/(1+exp(-(v+120)/25)));
>   #Nahinf <-1/(1+exp((v+489)/5.18));
>   #Natauh <-(0.67/(1+exp(-(v+62.9)/10))) * (1.5+(1/(1+exp((v+34.9)/36;
> 
>   #PD
>   # mca10
>   CaTminf <- function(v) 1/(1+exp(-(v+25)/7.2));
>   # hca10
>   CaThinf <- function(v) 1/(1+exp(v+36)/7);
>   # taumca1
>   CaTtaum <- function(v) 55- (49.5/(1+exp(-v+58)/17));
>   # tauhca1
>   CaTtauh <- function(v) 350 - (300/(1+exp(-v+50)/16.9));
> 
>   #mca20
>   CaSminf <- function(v) 1/(1+exp(-(v+22)/8.5));
>   #taumca2
>   CaStaum <- function(v) 16-(13.1/(1+exp(-(v+25.1)/26.4)));
> 
> 
>   # mna0
>   Napminf <- function(v) 1/(1+exp(-(v+26.8)/8.2));
>   # hna0
>   Naphinf <- function(v) 1/(1+exp(-(v+48.5)/5.18));
> 
>   taumna <- function(v) 19.8-(10.7/(1+exp(-(v+26.5)/8.6)));
>   tauhna <- function(v) 666-(379/(1+exp(-(v+33.6)/11.7)));
> 
>   # mh0
>   hminf <- function(v)  1/(1+exp(v+70)/6);
>   # taumh
>   htaum <- function(v)  272+(1499/(1+exp(-(v+42.2)/8.73)));
> 
>   Kminf <- function(v)  1/(1+exp(-(v+14.2)/11.8));
>   Ktaum <- function(v)  7.2-(6.4/(1+exp(-(v+28.3)/19.2)));
> 
>   # Reversal potential of intracellular calcium concentration
>   # Nernst Equation using  extracellular concentration of Ca = 13mM
>   # eca
>   ECa <- function(Ca2) 12.2396*log(13000/(Ca2));
>   #ECa <- function(CaI) 12.2396*log(13000/(CaI));
> 
> 
>   #Sum of all the Ca
>   # function(v) CaTminf(v) + CaSminf(v);
>   CaI <- gCaT*CaTm^3*CaTh*(v-ECa(CaI)) + gCaS*CaSm^3*(v-ECa(CaI))
> 
>   #AB
>   #dCa2 <- (((-F*Caminf(v))-Caminf(v) + C0)/TauCa)
>   dCa2 <- (((-F*CaI) - Ca2 + C0)/TauCa)
> 
>   # mk20
>   KCaminf <- function(v, Ca2) (Ca2/(Ca2+30))*(1/(1+exp(-(v+51)/8)));
>   # taumk
>   KCataum <- function(v) 90.3 - ((75.09/(1+exp(-(v+46)/22.7;
> 
>   #AB
>   Aminf <- function(v) 1/(1+exp(-(v+27)/8.7));
>   Ahinf <- function(v) 1/(1+exp((v+56.9)/4.9));
>   Ataum <- function(v) 11.6-(10.4/(1+exp(-(v+32.9)/15.2)));
>   Atauh <- function(v) 38.6-(29.2*(1+exp(-(v+38.9)/26.5)));
> 
>   #proc
>   #mp0
>   procminf <- function(v) 1/(1+exp((v+56.9)/4));
>   #taump
>   proctaum <- function(v) 0.5;
> 
> 
>dv <- (-1*(I
>  + CaI
>  + gNap*Napm^3*Naph*(v-ENap)
>  + gh*hm*(v-Eh)
>  + gK*Km^4*(v-EK)
>  + gKCa * KCam^4*(v-EKCa)
>  + gA*Am^4*Ah*(v-EA)
>  + gL*(v-EL))
>  / C);
> 
> 
>   dCaTm <- (CaTminf(v) - CaTm)/CaTtaum(v);
>   dCaTh <- (CaThinf(v) - CaTh)/CaTtauh(v);
> 
>   dCaSm <- (CaSminf(v) - CaSm)/CaStaum(v);
> 
>

[R] Install package "ROpenOffice"

2013-02-14 Thread Earl Brown
Has anyone had trouble installing the package "ROpenOffice" from omegahat:

http://www.omegahat.org/ROpenOffice/

I downloaded the .tar.gz file to my local hard drive and tried to install it 
with the following code, but got an error message:

> install.packages("/Users/earlbrown/Desktop/ROpenOffice_0.4-0.tar.gz", repos = 
> NULL, type = "source")
Installing package(s) into ‘/Users/earlbrown/Library/R/2.15/library’
(as ‘lib’ is unspecified)
* installing *source* package ‘ROpenOffice’ ...
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error : package ‘Rcompression’ is not installed for 'arch=i386'
Error: loading failed
Execution halted
*** arch - x86_64
ERROR: loading failed for ‘i386’
* removing ‘/Users/earlbrown/Library/R/2.15/library/ROpenOffice’
Warning message:
In install.packages("/Users/earlbrown/Desktop/ROpenOffice_0.4-0.tar.gz",  :
  installation of package ‘/Users/earlbrown/Desktop/ROpenOffice_0.4-0.tar.gz’ 
had non-zero exit status

So, I tried to install the package "Rcompression" first, but got another error 
message:

> install.packages("Rcompression")
Installing package(s) into ‘/Users/earlbrown/Library/R/2.15/library’
(as ‘lib’ is unspecified)
Warning message:
package ‘Rcompression’ is not available (for R version 2.15.2)

Any ideas? 

Here's my info:

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] XML_3.95-0

loaded via a namespace (and not attached):
[1] tools_2.15.2

Thanks. Earl Brown

-
Earl K. Brown, PhD
Assistant Professor of Spanish Linguistics
Advisor, TEFL MA Program
Department of Modern Languages
Kansas State University

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


[R] Alternate tick labels in xyplot

2013-02-14 Thread Lisa Daniel
Dear Rhelp,

I would like to get alternate tick labels for the xyplot:
library(lattice)
library(grid)

xy <-xyplot(decrease ~ treatment, OrchardSprays,
    main= "Some plot",
    groups = rowpos, type = "a",
        page = function(n){
 grid.text(LETTERS[j],
 y = 0.95,
 x = 0.15,
 default.units = "npc",
 just = c("left"),
 gp = gpar(fontsize = 12,fontface="bold") )
   },
    par.settings = c(simpleTheme(lty=1:8, 
col="black",lwd=2),list(layout.heights = list(main = 1.2,
   sub  = 0,
   axis.top = 0.2,
   top.padding  = 0.1,
   bottom.padding = 0)) ),
    auto.key = list(x = 0.2, y = 0.9,
    cex = 0.75, points = FALSE, lines = TRUE)) 
j=1
print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE)
j=j+1
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE)
j=j+1
print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = FALSE)


similar to the x-axis in the code below, but somehow it is not working when I 
pasted 'list(axis.components=...) in the above code:
xyplot(rnorm(12) ~ 1:12 , type="l",
scales=list(x=list(at=seq(2,12,2),labels=c(1, ' ', 3 , ' ' , 5 , ' ' ))),
par.settings=list(axis.components=list(bottom=list(tck=c(0,1) 

scales=list(x=list(at=seq(1,8,1),labels=c('A', ' ', 'C', ' ' ,'E' , ' ','G',' 
'))),

If possible, I would like a heading for each rows (justified to center) above 
the individual heading.

Please help.
Many thanks,
Lisa.

__
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] 2 setGeneric's, same name, different method signatures

2013-02-14 Thread Greg Minshall
hi.  below is a small test case (hopefully minimal, though i'm still a
bit confused about initializers).

i would have guessed (and maybe i still would have been right) that one
could re-use the name of a generic function for functions with different
numbers of arguments.  in the case below, class A's bB() queries the
status of a single A object, so bB(A) (where here "A" is an instance of
class A, just for "clarity") returns a value.  class B's bB() compares
values in two B objects, and returns the minimum, so bB(B1, B2) are its
methods.

after loading the file, i see the method for A's bB has disappeared (as
measured by showMethods("bB"), as well as trying bB(A).  if i have R
re-parse the setGeneric/setMethod  A's bB(), then B's bB() disappears.

somehow my code, or my model of how things work, is wrong.  any ideas
what am i missing?

cheers, Greg Minshall

setClass("A",
 representation(
   x="numeric"));

setMethod(
  f="initialize",
  signature="A",
  definition=function(.Object) {
.Object@x <- 23;
return(.Object)
  });

setGeneric("bB", function(me) standardGeneric("bB"));
setMethod(
  "bB",
  signature("A"),
  definition=function(me) {
return (new("B", me@x))});

setClass("B", representation(
  bx="numeric"));

setMethod(
  "initialize",
  signature("B"),
  definition=function(.Object, x) {
.Object@bx <- x;
return(.Object);
  });

setGeneric("bB", function(b1, b2) standardGeneric("bB"));
setMethod(
  "bB",
  signature("B", "B"),
  definition=function(b1, b2) {
return(new("B", min(b1@bx, b2@bx)))});

__
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] IWSM 2013: LAST call for papers

2013-02-14 Thread Vito M.R. Muggeo

dear all,
apologizes for this OT


===
28th International Workshop on Statistical Modelling (IWSM), Palermo 
(Italy) 8-12 July 2013. http://iwsm2013.unipa.it



Dear friend,
For your information, I would like to bring to your attention that 
deadline for submission of abstracts is


FEBRUARY 18

If you are still interested to visit Palermo (and taste its specialities 
:-)) and discuss recent trends in statistical modelling with colleagues 
coming from different places in the whole world, do not hesitate to 
submit a paper for oral or poster presentation. Register at 
http://iwsm2013.unipa.it/?cmd=registration and then submit your 
abstract. Best student paper, best student oral and poster presentations 
will be awarded (see below). The deadline for Early Registration is 
April 20, 2013.



**Invited Speakers**
1)Ciprian Crainiceanu,  Johns Hopkins University, USA
2)Torsten Hothorn,  Ludwig-Maximilians-Universität Munchen, DEU
3)Stefano M. Iacus,  Università di Milano, ITA
4)Geoff McLachlan,  University of Queensland, AUS
5)Hein Putter,  Leiden University Medical Cente, NLD


**Short Course** (Sunday 7 July 2013)
J. Fox, ' An Introduction to Structural Equation Modelling with the sem 
Package for R'.



**Toyota Motor Corporation Student Awards**
(sponsored by Leonard N. Stern School of Business, New York University)
best paper: $500
best oral presentation: $500
best poster: $500



best wishes,

Vito Muggeo,
for 28IWSM Local Organizing Team


--
==
Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 23895240
fax: 091 485726
http://dssm.unipa.it/vmuggeo

28th IWSM
International Workshop on Statistical Modelling
July 8-12, 2013, Palermo
http://iwsm2013.unipa.it

__
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] 3D-plots of 2D-grids

2013-02-14 Thread David Winsemius


On Feb 14, 2013, at 8:05 AM, jas wrote:

calc_ext3.asc 



I supplied a small extent of the grid, that I am trying to  
visualize. It s a
ascii-grid with 800 cells. My goal is to display the Grid-Values as  
the
z-variable. The point that I dont understand, is what is my input as  
x and

y-Variable in the persp-function? Do I have to make 8 vectors with 100
entries and plot them individually?

Your help is greatly appreciated,

jas

pop.grid
pop.mat <- as.matrix(pop.grid) # order is not right here already

z <- pop.mat
x <- 1:nrow(z)
y <- 1:nrow(z)
persp(x,y,z, phi=30,  border=NA)
# Error n persp.default(x, y, z, phi = 30, border = NA) :
 invalid 'z' Argument


I copied the space separated data from that webpage into my clipboard  
and executed this:


grd <- matrix( scan(), ncol=40, nrow=20)
# and pasted my clipboard
is.na(grd[] ) <- grd == -  # use a proper R missing value
 str(grd)
# num [1:20, 1:40] NA NA NA NA NA ...
 persp(z=grd)
 image(grd)

Alternatively you could have used read.table from that file with skip =6

The image looks rather disjointed and I'm hoping that lack of  
continuity is an artifact of extracting only a portion of the data.


--
David.







--
View this message in context: 
http://r.789695.n4.nabble.com/3D-plots-of-2D-grids-tp4658517p4658564.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.


David Winsemius, MD
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] Center a raster on the Pacific in a plot

2013-02-14 Thread Sophie MONSARRAT
Hello all,

I am currently working with environmental data at a global scale for modeling 
marine species distribution. These environmental data are provided as ASCII 
files and I convert them into raster for the analyzes, using the raster package.

All of these raster are centered around the Greenwich meridian. However, for 
visualization purpose, I would like to be able to plot these raster centering 
them on the Pacific.

This is easily done with GIS software, by defining the central meridian at 
-180° in the coordinate system. However, I can't find a way to do the same in 
R. I tried to adjust the coordinate reference system as follows:

SST.ras <- raster(SST.asc,crs = "+proj=merc  +lat_ts=0 +lon_0=-180 +x_0=0 
+y_0=0 +ellps=WGS84 +over")

But this has no effect on the way the raster is plotted.

The answer may be straightforward, but I didn't find any solution in other 
topics. Can someone enlighten me on this?

Thank you,
Sophie

[[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] sweave question

2013-02-14 Thread Mark Leeds
Hi Dan, Duncan and Yihui: I apologize for my late response.

Dan: Your backslash explanation was great but yes, I think there was a
transmission problem in the link I
sent. I made the changes and everything compiled without a glitch but the
actual tex file ends
up with many begin{Schunk} and end{Schunk} statements and somehow I think
this causes the pdf to
not get put in the document. But atleast I learned I now understand the
backslash issue and why my attempt wasn't working.  So, you solved the
problem that I had but another different issue now lurks
but, given below, I'm gonna let it go.  Thanks.

Duncan: Your solution worked.  I'm not sure why I didn't think of
seperating the two processes.
That was a nice idea. I guess I got caught up in the cat method once I saw
it.  Thanks.

Yihui: I'm starting to learn Rstudio by going through the recent book out
on it. There's a section
about knitR in the book so I hope to go over that and then turn to many of
your other documents.
Thanks for recommending knitR ( I loved the kitten statement at the link,
especially since I have cats ) and it is something I plan on learning, in
addition to 20 other thousand things on my list of "to be learned".


Mark









On Wed, Feb 13, 2013 at 9:00 PM, Yihui Xie  wrote:

> Other people in this thread have explained the rule of double
> backslashes. I just want to add one more comment:
>
> That clever solution was in 2009 when knitr has not come out, and I
> have used this picture several times to show how much I dislike it:
> http://yihui.name/en/2012/06/enjoyable-reproducible-research/
>
> With knitr, you can easily write your big code chunk (with lots of
> "cats" jumping around) in a much more compact way:
>
> < out.height="5in", fig.cap="The resulting unpruned regression tree of
> the California real estate data">>=
> plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
> text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
> @
>
> Note the number "5" alone is not a legal LaTeX length; you should add
> the unit such as "5in" or "5cm", etc. This chunk in knitr will
> generate everything for you:
>
> - the figure environment
> - center the figure
> - add the figure position ht!
> - add the figure caption
> - add figure width and height
> - add the figure label fig:figthree
>
> You, as the author, only write the R code (instead of both R and
> LaTeX); other people, as the readers, only see the R code. Everything
> else should go behind the scene.
>
> Regards,
> Yihui
> --
> Yihui Xie 
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
> On Wed, Feb 13, 2013 at 4:59 PM, Mark Leeds  wrote:
> > Hi Everyone: I was having trouble getting the plot size correct when
> > putting a plot in an sweave document. So, I searched on the internet and
> I
> > found a clever solution where the person uses
> > the cat function to write latex code so he can include the cat code in
> the
> > chunk and place the plot using width and height. The solution is here:
> > https://stat.ethz.ch/pipermail/r-help/2009-April/195094.html.
> >
> > But the solution uses a backslash before the ending quotes in the cat
> > statements  that might be windows relevant possibly ? I'm not sure about
> > that part but I'm on linux and when I tried my way to mimic that solution
> > in the latex/sweave code below ( I think it's the same solution but
> without
> > the backslash on the closing quotes. I tried that also but got a
> different
> > error ) , Sweave doesn't like the start of the includegraphics command.
> The
> > error I get from Sweave is
> >
> > #===
> > Error:  chunk 9 (label = fig3)
> > Error : '\i' is an unrecognized escape in character string starting "\i"
> > Execution halted
> > :~/research/equity/projects/tree_returns/report>
> > #=
> >
> > The code is below but if anyone is interested and thinks they need the
> > whole file to look at the problem, I can send it. I just didn't want to
> > send the whole file here. Definitely the error has to do with the chunk
> > below for sure ( even though it says chunk 9 because there is no chunk 9
> > ).  Thanks a lot to anyone who can be bothered investigating because I've
> > spent pretty much the whole day on this and think it's
> > time to surrender !! or atleast give up for now and come back to
> it
> > with a fresher brain. Have a good night.
> >
> > # THE LATEX/SWEAVE CODE
> > #
> >
> > cal.tree is created in a previous chunk and that's fine.
> >
> > <>=
> > wid <- 5
> > hei <- 5
> > pdf("reg_tree-fig3.pdf", width = wid, height = hei)
> > plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
> > text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
> > dev.off()
> > cat("\begin{figure}[ht!]")
> > cat("\begin{center}")
> > cat("\includegraphics[width = ", wid, ", height

Re: [R] 3D-plots of 2D-grids

2013-02-14 Thread jas
calc_ext3.asc   


I supplied a small extent of the grid, that I am trying to visualize. It s a
ascii-grid with 800 cells. My goal is to display the Grid-Values as the
z-variable. The point that I dont understand, is what is my input as x and
y-Variable in the persp-function? Do I have to make 8 vectors with 100
entries and plot them individually? 

Your help is greatly appreciated,

jas

pop.grid
pop.mat <- as.matrix(pop.grid) # order is not right here already

z <- pop.mat
x <- 1:nrow(z)
y <- 1:nrow(z)
persp(x,y,z, phi=30,  border=NA)
# Error n persp.default(x, y, z, phi = 30, border = NA) : 
  invalid 'z' Argument





--
View this message in context: 
http://r.789695.n4.nabble.com/3D-plots-of-2D-grids-tp4658517p4658564.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] spearman correlation and p-value as a matrix

2013-02-14 Thread arun
Hi Ozgul,

Try this:
#Here I used the "pearson correlation" as `spearman` was not significant

resr<-do.call(rbind,lapply(split(bg_ag,1:nrow(bg_ag)),function(x) 
{res<-rcorr(cbind(bg[,x[,1]],ag[,x[,2]]),type="pearson")$r; row.names(res)<- 
rep(paste(x[1],x[2],sep="_"),2);res})) 
#p-values 
resP<-do.call(rbind,lapply(split(bg_ag,1:nrow(bg_ag)),function(x) 
{res<-rcorr(cbind(bg[,x[,1]],ag[,x[,2]]),type="pearson")$P; row.names(res)<- 
rep(paste(x[1],x[2],sep="_"),2);res}))
indx<-row(resr)%%2!=1 
 resPnew<-as.matrix(resP[indx[,1],1]) 
 resrnew<-as.matrix(resr[indx[,1],1])
resrnew1<-data.frame(read.table(text=row.names(resrnew),sep="_",stringsAsFactors=FALSE),value=resrnew)
 row.names(resrnew1)<-1:nrow(resrnew1)
library(reshape2)
resrnew2<- dcast(resrnew1,V2~V1,value.var="value") 

resPnew1<-data.frame(read.table(text=row.names(resPnew),sep="_",stringsAsFactors=FALSE),value=resPnew)
row.names(resPnew1)<-1:nrow(resPnew1)
resPnew2<-dcast(resPnew1,V2~V1,value.var="value") 

resrnew2[,-1][resPnew2[,-1]>0.10|is.na(resPnew2[,-1])]<- 0  #also I used the 
cut-off limit as 0.10 because:
#correlation value for a p-value of 0.07 was also included in the ?cor2m() 
result

resPnew2
 #  V2   Otu00022 Otu00029   Otu00039 Otu00042   Otu00101 Otu00105 Otu00125
#1 ag1 0.81044832  NaN 0.81044832  NaN 0.17157638  NaN  NaN
#2 ag2 0.19359426  NaN 0.19359426  NaN 0.07062624     NaN  NaN
#3 ag3 0.01745244  NaN 0.01745244  NaN 0.61105696  NaN  NaN
#4 ag4 0.95446965  NaN 0.95446965  NaN 0.24387489  NaN  NaN
#5 ag5 0.87628767  NaN 0.87628767  NaN 0.62117658  NaN  NaN
 # Otu00131   Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185   Otu00190
#1  NaN 0.81044832  NaN  NaN  NaN  NaN  NaN 0.81044832
#2  NaN 0.19359426  NaN  NaN  NaN  NaN  NaN 0.19359426
#3  NaN 0.01745244  NaN  NaN  NaN  NaN  NaN 0.01745244
#4  NaN 0.95446965  NaN  NaN  NaN  NaN  NaN 0.95446965
#5  NaN 0.87628767  NaN  NaN  NaN  NaN  NaN 0.87628767
 # Otu00209   Otu00218
#1  NaN 0.81044832
#2  NaN 0.19359426
#3  NaN 0.01745244
#4  NaN 0.95446965
#5  NaN 0.87628767


cor2m(bg,ag,trim=TRUE,alpha=0.05)
#  Otu00022 Otu00029   Otu00039 Otu00042  Otu00101 Otu00105 Otu00125
#ag1  0.000  NaN  0.000  NaN 0.000  NaN  NaN
#ag2  0.000  NaN  0.000  NaN 0.7743597  NaN  NaN
#ag3 -0.8901029  NaN -0.8901029  NaN 0.000  NaN  NaN
#ag4  0.000  NaN  0.000  NaN 0.000  NaN  NaN
#ag5  0.000  NaN  0.000  NaN 0.000  NaN  NaN
 #   Otu00131   Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185   Otu00190
#ag1  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
#ag2  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
#ag3  NaN -0.8901029  NaN  NaN  NaN  NaN  NaN -0.8901029
#ag4  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
#ag5  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
 #   Otu00209   Otu00218
#ag1  NaN  0.000
#ag2  NaN  0.000
#ag3  NaN -0.8901029
#ag4  NaN  0.000
#ag5  NaN  0.000


resrnew2
#   V2   Otu00022 Otu00029   Otu00039 Otu00042  Otu00101 Otu00105 Otu00125
#1 ag1  0.000    0  0.000    0 0.000    0    0
#2 ag2  0.000    0  0.000    0 0.7743597    0    0
#3 ag3 -0.8901029    0 -0.8901029    0 0.000    0    0
#4 ag4  0.000    0  0.000    0 0.000    0    0
#5 ag5  0.000    0  0.000    0 0.000    0    0
 # Otu00131   Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185   Otu00190
#1    0  0.000    0    0    0    0    0  0.000
#2    0  0.000    0    0    0    0    0  0.000
#3    0 -0.8901029    0    0    0    0    0 -0.8901029
#4    0  0.000    0    0    0    0    0  0.000
#5    0  0.000    0    0    0    0    0  0.000
#  Otu00209   Otu00218
#1    0  0.000
#2    0  0.000
#3    0 -0.8901029
#4    0  0.000
#5    0  0.000
#If you want the Na values to remain as such use:
resrnew2[,-1][resPnew2[,-1]>0.10]<- 0 

 resrnew2
#   V2   Otu00022 Otu00029   Otu00039 Otu00042  Otu00101 Otu00105 Otu00125
#1 ag1  0.000  NaN  0.000  NaN 0.000  NaN  NaN
#2 ag2  0.000  NaN  0.000  NaN 0.7743597  NaN  NaN
#3 ag3 -0.8901029  NaN -0.8901029  NaN 0.000  NaN  NaN
#4 ag4  0.000  NaN  0.000  NaN 0.000  NaN  NaN
#5 ag5  0.000  NaN  0.000  NaN 0.000  NaN  NaN
 # Otu00131   Ot

Re: [R] spearman correlation and p-value as a matrix

2013-02-14 Thread Ozgul Inceoglu
you are right! I was so happy to find out the p-value criteria, I totally 
forgot about the spearman correlation, no I dont think there is an option of 
spearman correlation. Thank you for pointing that out!

Cheers,

Ö 


>Dear Ozgul,
>
>I made a comment in the previous email, which I didn't check it.
>Thank you for the ?cor2m().
>I checked the results of the example dataset with cor2m().  Does it have an 
>option for spearman correlation?  
>
>The values below seem to be pearson
>#cor2m
> cor2m(bg,ag,trim=TRUE,alpha=0.05) ##I
>  Otu00022 Otu00029   Otu00039 Otu00042  Otu00101 Otu00105 Otu00125
>ag1  0.000  NaN  0.000  NaN 0.000  NaN  NaN
>ag2  0.000  NaN  0.000  NaN 0.7743597  NaN  NaN
>ag3 -0.8901029  NaN -0.8901029  NaN 0.000  NaN  NaN
>ag4  0.000  NaN  0.000  NaN 0.000  NaN  NaN
>ag5  0.000  NaN  0.000  NaN 0.000  NaN  NaN
>    Otu00131   Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185   Otu00190
>ag1  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
>ag2  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
>ag3  NaN -0.8901029  NaN  NaN  NaN  NaN  NaN -0.8901029
>ag4  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
>ag5  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
>    Otu00209   Otu00218
>ag1  NaN  0.000
>ag2  NaN  0.000
>ag3  NaN -0.8901029
>ag4  NaN  0.000
>ag5  NaN  0.000
>
>#Pearson correlation from my solution:
>resr<-do.call(rbind,lapply(split(bg_ag,1:nrow(bg_ag)),function(x)
> {res<-rcorr(cbind(bg[,x[,1]],ag[,x[,2]]))$r; row.names(res)<- 
>rep(paste(x[1],x[2],sep="_"),2);res})) 
> indx<-row(resr)%%2!=1
>resrnew<-as.matrix(resr[indx[,1],1]) 
>resrnew1<-data.frame(read.table(text=row.names(resrnew),sep="_",stringsAsFactors=FALSE),value=resrnew)
> row.names(resrnew1)<-1:nrow(resrnew1)
>library(reshape2)
> dcast(resrnew1,V2~V1,value.var="value")   V2    Otu00022 Otu00029    Otu00039 
>Otu00042   Otu00101 Otu00105 Otu00125
>#1 ag1 -0.12705141  NaN -0.12705141  NaN -0.6394308  NaN  NaN
>#2 ag2 -0.61522514  NaN -0.61522514  NaN  0.7743597  NaN  NaN
>#3 ag3 -0.89010286  NaN -0.89010286  NaN -0.2655363  NaN  NaN
>#4 ag4  0.03036290  NaN  0.03036290  NaN -0.5638320  NaN  NaN
>#5 ag5  0.08266317  NaN  0.08266317  NaN -0.2582930  NaN  NaN
> # Otu00131    Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185    
>Otu00190
>#1  NaN -0.12705141  NaN  NaN  NaN  NaN  NaN 
>-0.12705141
>#2  NaN -0.61522514  NaN  NaN  NaN  NaN  NaN 
>-0.61522514
>#3  NaN -0.89010286  NaN  NaN  NaN  NaN  NaN 
>-0.89010286
>#4  NaN  0.03036290  NaN  NaN  NaN  NaN  NaN  
>0.03036290
>#5  NaN  0.08266317  NaN  NaN  NaN  NaN  NaN  
>0.08266317
> # Otu00209    Otu00218
>#1  NaN -0.12705141
>#2  NaN -0.61522514
>#3  NaN -0.89010286
>#4  NaN  0.03036290
>#5  NaN  0.08266317
>
>A.K.
>
>
>
>- Original Message -
>From: Ozgul Inceoglu 
>To: R help 
>Cc: 
>Sent: Thursday, February 14, 2013 1:10 AM
>Subject: Re: [R] spearman correlation and p-value as a matrix
>
>Thank you all for the answers. I really need to learn a lot. 
>Bu I also discover cor2m(x, y, trim = TRUE, alpha = 0.05)
>in ecodist package, which gives an output file with significant correlations.
>
>Özgül
>
>Yj>HI,
>>
>>#ag data was created
>>bg<- as.matrix(read.table(text=" 
>> Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 
>>Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 
>>Otu00218 
>>Gi20Jun11  0.001217    0 0.001217    0 0.00    0    0 
>>   0 0.001217    0    0    0    0    0 0.001217    0 
>>0.001217 
>>Gi40Jun11  0.00    0 0.00    0 0.00    0    0 
>>   0 0.00    0    0    0    0    0 0.00    0 
>>0.00 
>>Gi425Jun11 0.00    0 0.00    0 0.00    0    0 
>>   0 0.00    0    0    0    0    0 0.00    0 
>>0.00 
>>Gi45Jun11  0.00    0 0.00    0 0.001513    0    0 
>>   0 0.00    0    0    0    0    0 0.00    0 
>>0.00 
>>Gi475Jun11 0.00    0 0.00    0 0.00    0    0 
>>   0 0.00    0    0    0    0    0 0.00    0 
>>0.00 
>>Gi50Jun11  0.00    0 0.00    0 0.00    0    0 
>>   0 0.00    0    0    0    0    0 0.00    0 
>>0.00 
>>",sep="",header=TRUE,stringsAsFactors=F))
>>set.seed(128)
>>ag<- matrix(rnorm(30),nrow=6)
>>co

Re: [R] spearman correlation and p-value as a matrix

2013-02-14 Thread arun
Dear Ozgul,

I made a comment in the previous email, which I didn't check it.
Thank you for the ?cor2m().
I checked the results of the example dataset with cor2m().  Does it have an 
option for spearman correlation?  

The values below seem to be pearson
#cor2m
 cor2m(bg,ag,trim=TRUE,alpha=0.05) ##I
  Otu00022 Otu00029   Otu00039 Otu00042  Otu00101 Otu00105 Otu00125
ag1  0.000  NaN  0.000  NaN 0.000  NaN  NaN
ag2  0.000  NaN  0.000  NaN 0.7743597  NaN  NaN
ag3 -0.8901029  NaN -0.8901029  NaN 0.000  NaN  NaN
ag4  0.000  NaN  0.000  NaN 0.000  NaN  NaN
ag5  0.000  NaN  0.000  NaN 0.000  NaN  NaN
    Otu00131   Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185   Otu00190
ag1  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
ag2  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
ag3  NaN -0.8901029  NaN  NaN  NaN  NaN  NaN -0.8901029
ag4  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
ag5  NaN  0.000  NaN  NaN  NaN  NaN  NaN  0.000
    Otu00209   Otu00218
ag1  NaN  0.000
ag2  NaN  0.000
ag3  NaN -0.8901029
ag4  NaN  0.000
ag5  NaN  0.000

#Pearson correlation from my solution:
resr<-do.call(rbind,lapply(split(bg_ag,1:nrow(bg_ag)),function(x)
 {res<-rcorr(cbind(bg[,x[,1]],ag[,x[,2]]))$r; row.names(res)<- 
rep(paste(x[1],x[2],sep="_"),2);res})) 
 indx<-row(resr)%%2!=1
resrnew<-as.matrix(resr[indx[,1],1]) 
resrnew1<-data.frame(read.table(text=row.names(resrnew),sep="_",stringsAsFactors=FALSE),value=resrnew)
 row.names(resrnew1)<-1:nrow(resrnew1)
library(reshape2)
 dcast(resrnew1,V2~V1,value.var="value")   V2    Otu00022 Otu00029    Otu00039 
Otu00042   Otu00101 Otu00105 Otu00125
#1 ag1 -0.12705141  NaN -0.12705141  NaN -0.6394308  NaN  NaN
#2 ag2 -0.61522514  NaN -0.61522514  NaN  0.7743597  NaN  NaN
#3 ag3 -0.89010286  NaN -0.89010286  NaN -0.2655363  NaN  NaN
#4 ag4  0.03036290  NaN  0.03036290  NaN -0.5638320  NaN  NaN
#5 ag5  0.08266317  NaN  0.08266317  NaN -0.2582930  NaN  NaN
 # Otu00131    Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185    Otu00190
#1  NaN -0.12705141  NaN  NaN  NaN  NaN  NaN -0.12705141
#2  NaN -0.61522514  NaN  NaN  NaN  NaN  NaN -0.61522514
#3  NaN -0.89010286  NaN  NaN  NaN  NaN  NaN -0.89010286
#4  NaN  0.03036290  NaN  NaN  NaN  NaN  NaN  0.03036290
#5  NaN  0.08266317  NaN  NaN  NaN  NaN  NaN  0.08266317
 # Otu00209    Otu00218
#1  NaN -0.12705141
#2  NaN -0.61522514
#3  NaN -0.89010286
#4  NaN  0.03036290
#5  NaN  0.08266317

A.K.



- Original Message -
From: Ozgul Inceoglu 
To: R help 
Cc: 
Sent: Thursday, February 14, 2013 1:10 AM
Subject: Re: [R] spearman correlation and p-value as a matrix

Thank you all for the answers. I really need to learn a lot. 
Bu I also discover cor2m(x, y, trim = TRUE, alpha = 0.05)
in ecodist package, which gives an output file with significant correlations.

Özgül

Yj>HI,
>
>#ag data was created
>bg<- as.matrix(read.table(text=" 
> Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 
>Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 
>Otu00218 
>Gi20Jun11  0.001217    0 0.001217    0 0.00    0    0  
>  0 0.001217    0    0    0    0    0 0.001217    0 
>0.001217 
>Gi40Jun11  0.00    0 0.00    0 0.00    0    0  
>  0 0.00    0    0    0    0    0 0.00    0 
>0.00 
>Gi425Jun11 0.00    0 0.00    0 0.00    0    0  
>  0 0.00    0    0    0    0    0 0.00    0 
>0.00 
>Gi45Jun11  0.00    0 0.00    0 0.001513    0    0  
>  0 0.00    0    0    0    0    0 0.00    0 
>0.00 
>Gi475Jun11 0.00    0 0.00    0 0.00    0    0  
>  0 0.00    0    0    0    0    0 0.00    0 
>0.00 
>Gi50Jun11  0.00    0 0.00    0 0.00    0    0  
>  0 0.00    0    0    0    0    0 0.00    0 
>0.00 
>",sep="",header=TRUE,stringsAsFactors=F))
>set.seed(128)
>ag<- matrix(rnorm(30),nrow=6)
>colnames(ag)<- paste("ag",1:5,sep="")
>bg_ag<-expand.grid(colnames(bg),colnames(ag),stringsAsFactors=FALSE)
> attr(bg_ag,"out.attrs")<- NULL
> library(Hmisc)
>#correlation
>resr<-do.call(rbind,lapply(split(bg_ag,1:nrow(bg_ag)),function(x) 
>{res<-rcorr(cbind(bg[,x[,1]],ag[,x[,2]]),type="spearman")$r; row.names(res)<- 
>rep(paste(x[1],x[2],

[R] R script .bat file from Python

2013-02-14 Thread Fabio Veronesi
Hello,
I would like to start running a script from Python with the Rscript command.
I tested several ways of invoking R from Python and I finally I succeeded.

The problem is that the script starts but R does not recognize the
installed packages.
I tried simplifying the matter and I created a script.bat with the classic
commands: Rscript c:\test.R

If I run it by double clicking on it it works perfectly. However, if I try
to run it from Python, with a command such as os.system("script.bat"), it
says that it cannot recognize any of the packages that it needs to load.

Has anyone had  a similar problem?

Many thanks,
Fabio

[[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] Plot a Matrix as an Image with ggplot

2013-02-14 Thread John Kane
The R-help list is rather picky about what attached. None of your attachments 
arrived. 

The str() info is useful but please supply some sample data 

 The easiest way to supply data  is to use the dput() function.  Example with 
your file named "testfile": 
dput(testfile) 

Then copy the output and paste into your email.  For large data sets, you can 
just supply a representative sample.  Usually, 
dput(head(testfile, 100)) will be sufficient.  

How are you writing the code/or what format is the original email. Your code in 
the body of the text is badly messed up -- you probably need to post only in 
text. HTML etc is automatically dropped.


 

John Kane
Kingston ON Canada


> -Original Message-
> From: ala...@yahoo.com
> Sent: Thu, 14 Feb 2013 07:15:05 -0800 (PST)
> To: r-help@r-project.org
> Subject: [R] Plot a Matrix as an Image with ggplot
> 
> Dear all,
> I am trying to plot a matrix I have  as an image
> 
> str(matrixToPlot)
>  num [1:21, 1:66] 0 0 0 0 0 0 0 0 0 0 .
> 
> 
>  that contains only 0s and 1s,
> 
> 
> where the xlabel will be Labeled as
> str(xLabel)
>  num [1:66] 1e+09 1e+09 1e+09 1e+09 1e+09 ...
> 
> and the yLabels will be labeled as
> str(yLabel)
>  num [1:21] -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 ...
> 
> 
> I have found on the internet that I can do something like that with
> ggplot2.
> For example
> you can run the following
> 
> 
> 
> library(reshape2)library(ggplot2)m
> =matrix(rnorm(20),5)ggplot(melt(m),aes(Var1,Var2,fill=value))+geom_raster()
> 
> What I see missing here is to get my matrix and transform it to a data
> frame with labels for x and y axis so as ggplot can print the values
> nice. If you get the idea this matrix will be printed as a two tile
> pattern let's say with black tiles zeros and white tiles black where a
> color bar will depicting that black means zero and white one.
> 
> To help you with my code you will find attached the three items I have
> discussed here, the matrix, the x and the y labels.
> 
> Could you please help me with that?
> 
> Alex


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas 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.


Re: [R] execute an external program in R

2013-02-14 Thread Greg Snow
?sprintf


On Thu, Feb 14, 2013 at 6:59 AM, Esam Tolba  wrote:

> Dear all
> I am using r (2.15.2) under windows 7 32bit.
> I want to use system command to execute an external program inside a
> for loop. this program needs  the input and output names.
> since the names will change in the for loop I am not able to use the
> programs on all the files
>
>
>
>
> for (k in 1:10){
> x=read.table ("data.txt")
>xx=x[1:5, ]
>xxx=paste0("data_",k,"txt")
>  write.table (xx,xxx,quote =FALSE, sep = "\t",row.names = FALSE,
> col.names = FALSE)
>  system ('dssp.exe -i xxx -o xxx.out)
>
> }
>
>
>
>
>
>
>
> Best Regards,
>
> __
> 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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@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.


Re: [R] Need Help Plotting "Line" for multiple linear regression

2013-02-14 Thread Greg Snow
The abline function works fine for simple linear regression because there
is only 1 line, but with multiple linear regression there are an infinite
number of lines and you need to decide which to plot (or find a way to plot
t he plane/hyperplane/surface/etc.).

One option is to use the Predict.Plot and TkPredict functions in the
TeachingDemos package.  These will plot the relationship between the
response and 1 of the predictors conditioned on values of the other
predictors.


On Wed, Feb 13, 2013 at 3:02 PM, Craig O'Connell
wrote:

> Hello,
>
> My name is Craig and I need help plotting a "line" for a multiple linear
> regression in R.
>
> Here is my sample data (filename:  convis.txt)
>
> Output of convis.txt is (vis and density being predictors of either
> avoidance or entrance):
>
>vis den  avoid entrance
> 1   10   1 0.   0.
> 2   10   3 0.8750   0.
> 38   3 0.8180   0.0300
> 48   3 0.6670   0.0667
> 58   1 0.2110   0.
> 66   1 0.2500   0.
> 7   10   1 0.3000   0.
> 8   10   1 0.1050   0.
> 98   1 0.7000   0.1000
> 10   3   5 0.1176   0.0588
> 11   3   5 0.3077   0.1150
> 12   3   9 0.9090   0.0900
> 13   3   7 0.7778   0.1110
> 14   3   5 0.5560   0.1110
> 15   3   1 0.5710   0.
> 16   3   4 0.5710   0.
>
> In order to do the multiple regression, I used the following coding:
>
>
> double=read.table("convis.txt",header=TRUE)
> attach(double)
> double
> stem(vis)
> stem(den)
> stem(avoid)
> stem(entrance)
> plot(entrance,vis*den)  *as means to see how the interaction between
> visibility and density may impact entrance behaviors
> model6=lm(entrance~vis*den)
> model6
> summary(model6)
> *abline(model6)  *Here is the issue as I used this for my simple linear
> regression technique, but do not know what to use for a multiple
> regression*
>
> If anybody can provide some feedback on this, it would be greatly
> appreciated.
>
> Kind Regards,
>
> Craig
>
> --
> <><  <><  <><
> Craig O'Connell
> University of Massachusetts Dartmouth
> Marine Biologist
> www.youtube.com/craigpoconnell
> craigosea.blogspot.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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


[R] Plot a Matrix as an Image with ggplot

2013-02-14 Thread Alaios
Dear all,
I am trying to plot a matrix I have  as an image

str(matrixToPlot)
 num [1:21, 1:66] 0 0 0 0 0 0 0 0 0 0 .


 that contains only 0s and 1s,


where the xlabel will be Labeled as 
str(xLabel)
 num [1:66] 1e+09 1e+09 1e+09 1e+09 1e+09 ...

and the yLabels will be labeled as
str(yLabel)
 num [1:21] -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 ...


I have found on the internet that I can do something like that with ggplot2.
For example
you can run the following



library(reshape2)library(ggplot2)m 
=matrix(rnorm(20),5)ggplot(melt(m),aes(Var1,Var2,fill=value))+geom_raster()

What I see missing here is to get my matrix and transform it to a data frame 
with labels for x and y axis so as ggplot can print the values nice. If you get 
the idea this matrix will be printed as a two tile pattern let's say with black 
tiles zeros and white tiles black where a color bar will depicting that black 
means zero and white one.

To help you with my code you will find attached the three items I have 
discussed here, the matrix, the x and the y labels.

Could you please help me with that?

Alex__
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] pearson's correlation and cross-correlation issue

2013-02-14 Thread Pierre Antoine DuBoDeNa
Hello,

I want to compute the pearson's correlation, but even for signals that are
shifted.

For example having two signals like:

1 1 2 1 1
and
1 2 1 1 1

the correlation is very low.. but if we shift them in the right we get much
better correlation.

I know that cross-correlation is used to find the best offset (where
correlation will be bigger).

Is there any metric that can do this job all together? find best
alignment.. shift and compute pearson's correlation? is that the same as
lagged correlation? or phase correlation? If it has a particular name let
me know.. and if there is any code for that.

Best,
Pierre

[[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] NA/NaN/Inf in foreign function call (arg 6) error from coxph function

2013-02-14 Thread Terry Therneau

 The NaN/Inf message is almost certainly from a singular fit.
 I would be interested in a copy of the data set to test it: data sets that cause this 
are rare, and help me to tune the convergence/signularity criteria in the program.


 Note: it is much easier to use coxph(survobj ~ therapy + ReceptorA + ReceptorB, 
data=sample.data) than to put "sample.data$" in front of every variable name; and easier 
to read as well.


Terry Therneau (author of coxph function)

On 02/14/2013 05:00 AM, r-help-requ...@r-project.org wrote:

I am trying to fit a multivariate Cox proportional hazards model,
modelling survival outcome as a function of treatment and receptor
status. The data look like below:


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

2013-02-14 Thread Adams, Jean
Pedro,

I only skimmed your question on stackoverflow, but since I had just seen a
related post on R-bloggers (http://www.r-bloggers.com), I thought you might
be interested.

"Out-of-sample one-step forecasts
"It is common to fit a model using training data, and then to eval­u­ate
its per­for­mance on a test data set. When the data are time series, it is
use­ful to com­pute one-step fore­casts on the test data. For some rea­son,
this is much more com­monly done by peo­ple trained in machine learn­ing
rather than statistics."

Continue reading ...
http://robjhyndman.com/hyndsight/out-of-sample-one-step-forecasts/

Hope this helps.

Jean



On Wed, Feb 13, 2013 at 9:28 AM, Pedro Carvalho
wrote:

>
> Hello,
>
> I have submitted a R question to stackoverflow and have not received an
> answer.
>
> Could anyone help me out?
>
>
> http://stackoverflow.com/questions/14825443/backtesting-accuracy-of-regression-model-through-rolling-window-regression-with
>
> Best regards,
> Pedro
>
> [[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] Plotting survival curves after multiple imputation

2013-02-14 Thread Robert Long
I am working with some survival data with missing values.

I am using the mice package to do multiple imputation.

I have found code in this thread which handles pooling of the MI results:
https://stat.ethz.ch/pipermail/r-help/2007-May/132180.html

Now I would like to plot a survival curve using the pooled results.

Here is a reproducible example:

require(survival)
require(mice)

set.seed(2)

dt <- colon

fit <- coxph(Surv(time,etype)~rx + sex + age, data=colon)

dummy <- data.frame(sex=c(1,1,1),rx=c("Obs","Lev","Lev+5FU"),age=c(40,40,40))
plot(survfit(fit, newdata=dummy) )

# now create some missing values in the data
dt <- colon
dt$rx[sample(1:nrow(dt),50)] <- NA
dt$sex [sample(1:nrow(dt),50)] <- NA
dt$age[sample(1:nrow(dt),50)] <- NA

imp <-mice(dt)

fit.imp <- coxph.mids(Surv(time,etype)~rx + sex + age,imp)
# Note, this function is defined below...

imputed=summary.impute(pool.impute(fit.imp))
print(imputed)

# now, how to plot a survival curve with the pooled results ?




## begin code from linked thread above

coxph.mids <- function (formula, data, ...) {

 call <- match.call()
 if (!is.mids(data)) stop("The data must have class mids")

 analyses <- as.list(1:data$m)

 for (i in 1:data$m) {
   data.i<- complete(data, i)
   analyses[[i]] <- coxph(formula, data = data.i, ...)
 }

 object <- list(call = call, call1 = data$call,
nmis = data$nmis, analyses = analyses)

 return(object)
}

pool.impute <- function (object, method = "smallsample") {

 if ((m <- length(object$analyses)) < 2)
   stop("At least two imputations are needed for pooling.\n")

 analyses <- object$analyses

 k <- length(coef(analyses[[1]]))
 names <- names(coef(analyses[[1]]))
 qhat  <- matrix(NA, nrow = m, ncol = k, dimnames = list(1:m,names))
 u <- array(NA, dim = c(m, k, k),
dimnames = list(1:m, names, names))

 for (i in 1:m) {
   fit   <- analyses[[i]]
   qhat[i, ] <- coef(fit)
   u[i, , ]  <- vcov(fit)
 }

 qbar <- apply(qhat, 2, mean)
 ubar <- apply(u, c(2, 3), mean)
 e <- qhat - matrix(qbar, nrow = m, ncol = k, byrow = TRUE)
 b <- (t(e) %*% e)/(m - 1)
 t <- ubar + (1 + 1/m) * b
 r <- (1 + 1/m) * diag(b/ubar)
 f <- (1 + 1/m) * diag(b/t)
 df <- (m - 1) * (1 + 1/r)^2

 if (method == "smallsample") {

   if( any( class(fit) == "coxph" ) ){

 ### this loop is the hack for survival analysis ###

 status   <- fit$y[ , 2]
 n.events <- sum(status == max(status))
 p<- length( coefficients( fit )  )
 dfc  <- n.events - p

   } else {

 dfc <- fit$df.residual
   }

   df <- dfc/((1 - (f/(m + 1)))/(1 - f) + dfc/df)
 }

 names(r) <- names(df) <- names(f) <- names
 fit <- list(call = call, call1 = object$call, call2 = object$call1,
 nmis = object$nmis, m = m, qhat = qhat, u = u,
 qbar = qbar, ubar = ubar, b = b, t = t, r = r, df = df,
 f = f)

 return(fit)
}

summary.impute <- function(object){

  if (!is.null(object$call1)){
cat("Call: ")
dput(object$call1)
  }

  est  <- object$qbar
  se   <- sqrt(diag(object$t))
  tval <- est/se
  df   <- object$df
  pval <- 2 * pt(abs(tval), df, lower.tail = FALSE)

  coefmat <- cbind(est, se, tval, pval)
  colnames(coefmat) <- c("Estimate", "Std. Error",
   "t value", "Pr(>|t|)")

  cat("\nCoefficients:\n")
  printCoefmat( coefmat, P.values=T, has.Pvalue=T, signif.legend=T )

  cat("\nFraction of information about the coefficients
  missing due to nonresponse:","\n")
  print(object$f)

  ans <- list( coefficients=coefmat, df=df,
   call=object$call1, fracinfo.miss=object$f )
  invisible( ans )
  }

### end code from linked thread above

__
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] Looking for an easy way to change the names of a vector

2013-02-14 Thread arun
Hi, 

names(Data)[-grep(".*\\s+.*",names(Data))]<-paste(names(Data)[-grep(".*\\s+.*",names(Data))],"-XXX",sep="")
names(Data)[grep(".*\\s+.*",names(Data))]<-gsub("[ 
]","-",names(Data)[grep(".*\\s+.*",names(Data))])
 names(Data)
#[1] "ada-XXX"    "fsdfs-XXX"  "asd-fd" "asdsa-XXX"  "dsada-XXX" 
#[6] "asasad-XXX" "adas-asdad" "aasaa-XXX" 

A.K.

- Original Message -
From: Christofer Bogaso 
To: r-help 
Cc: 
Sent: Thursday, February 14, 2013 6:43 AM
Subject: [R] Looking for an easy way to change the names of a vector

Hello again,

Let say I have following vector (this is basically a snap of very large vector):


Data <- 1:8
names(Data) <- c("ada", "fsdfs", "asd fd", "asdsa", "dsada", "asasad",
"adas asdad", "aasaa")
Data

Now I want to change the names according to following rule:

1. If there is any space then replace that space by "-"
2. Otherwise add "-XXX" at the last to each name

Therefore the names will be:

c("ada-XXX", "fsdfs-XXX", "asd-fd", "asdsa-XXX", "dsada-XXX",
"asasad-XXX", "adas-asdad", "aasaa-XXX")


Can somebody point me some direct way for that?

Thanks for your help

__
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] spearman correlation and p-value as a matrix

2013-02-14 Thread arun
Dear Ozgul,
You could use ?table() or ?count from library(plyr)
I assume that you wanted to count only from the first column.
 data2<- read.csv("cor3.csv",sep="\t",stringsAsFactors=FALSE)
 res1<-as.data.frame(table(data2[,1]))
res2<-count(data2[,1])
colnames(res1)<- colnames(res2)
 identical(res1,res2)
#[1] TRUE
A.K.





- Original Message -
From: Ozgul Inceoglu 
To: arun 
Cc: 
Sent: Thursday, February 14, 2013 6:17 AM
Subject: re:Re: [R] spearman correlation and p-value as a matrix

Dear Arun,

I bothered you this week alot, but it seems like that you know your way in R 
very well. I would appreciate if you can help me with one more thing. I have 2 
data files. One is the average value of each OTU. Second file has the 
correlation between each OTU, but I would like to plot how many times a OTU 
correlated against its relative abundance. As you see in data2 file, OTU0001 
have around 53 correlations. Is it possible to count that in R with a script? 
Because my table is too long to count by eye. I saw some script to count 
numeric values but the column one is text. And I will plot data1$average 
data2$number of occurence (e.g.53)

Thank you very much!

Ö

data1
name    average
Otu0001    0.059348357
Otu0002    0.030641714
Otu0003    0.011322821
Otu0004    0.080583357
Otu0005    0.022009357
data2
Var1    Var2    Freq    
Otu0001    Otu2    0.50308393782931    
Otu0001    Otu3    0.835976014100782    
Otu0001    Otu00021    0.913558114482734    
Otu0001    Otu00027    0.905670284922677    
Otu0001    Otu00046    0.581582392764371    
Otu0001    Otu00047    0.867801609030349    
Otu0001    Otu00057    0.678979275105813    
Otu0001    Otu00066    0.665704636891185    
Otu0001    Otu00083    0.573139564297305    
Otu0001    Otu00084    0.654793315615399    
Otu0001    Otu00114    0.545574076996571    
Otu0001    Otu00133    0.860299149983324    
Otu0001    Otu00149    0.565446769229162    
Otu0001    Otu00154    0.651905880329591    
Otu0001    Otu00165    0.58878791058    
Otu0001    Otu00199    0.636977290142002    
Otu0001    Otu00242    0.733670340504493    
Otu0001    Otu00265    0.56572800115343    
Otu0001    Otu00271    0.52274494018959    
Otu0001    Otu00290    0.565784159732485    
Otu0001    Otu00498    0.69700879002542    
Otu0001    Otu00543    0.688857846593924    
Otu0001    Otu00619    0.568561351623871    
Otu0001    Otu00646    0.710973182296609    
Otu0001    Otu00915    0.67389659584841    
Otu0001    Otu00949    0.658902464342605    
Otu0001    Otu01035    0.730329506746752    
Otu0001    Otu01327    0.680119572628299    
Otu0001    Otu01631    0.537404605465553    
Otu0001    Otu01638    0.624999817224687    
Otu0001    Otu01642    0.572231019174333    
Otu0001    Otu01649    0.551184564584919    
Otu0001    Otu01651    0.600983572760604    
Otu0001    Otu01655    0.522736661453493    
Otu0001    Otu01657    0.756955802070428    
Otu0001    Otu01669    0.540295474451908    
Otu0001    Otu01678    0.628300552686822    
Otu0001    Otu01691    0.527963252499515    
Otu0001    Otu01711    0.58532121170348    
Otu0001    Otu01722    0.521754446131501    
Otu0001    Otu01729    0.626564045909824    
Otu0001    Otu01745    0.685208099879848    
Otu0001    Otu01748    0.533461010235307    
Otu0001    Otu01776    0.708721334709103    
Otu0001    Otu01795    0.774684206920168    
Otu0001    Otu01802    0.515477574463339    
Otu0001    Otu01828    0.595278507951326    
Otu0001    Otu01836    0.521155845049491    
Otu0001    Otu01856    0.597043163472699    
Otu0001    Otu01897    0.510475231901277    
Otu0001    Otu01946    0.514243028056249    
Otu0001    Otu02289    0.547405617805684    
Otu0002    Otu3    0.694555195101993    
Otu0002    Otu00021    0.851014016127985    
Otu0002    Otu00027    0.846202663607256    
Otu0002    Otu00039    0.512465964406187    
Otu0002    Otu00047    0.730301483589089    
Otu0002    Otu00057    0.573490708638711    
Otu0002    Otu00066    0.539961837085781    
Otu0002    Otu00083    0.553157813265034    
Otu0002    Otu00084    0.530240909220586    
Otu0002    Otu00133    0.784857667907929    
Otu0002    Otu00154    0.511528128122173    
Otu0002    Otu00165    0.53831396859667    
Otu0002    Otu00242    0.669315163629151    
Otu0002    Otu00303    0.500475996445905    
Otu0002    Otu00498    0.628615400548539    
Otu0002    Otu00543    0.567818884280764    
Otu0002    Otu00619    0.75244056951144    
Otu0002    Otu00646    0.529522331732556    
Otu0002    Otu00915    0.696241613567686    
Otu0002    Otu00991    0.639059878477682    
Otu0002    Otu01035    0.563754887455874    
Otu0002    Otu01327    0.554745741443052    
Otu0002    Otu01651    0.748640849069562    
Otu0002    Otu01655    0.555344064103094    
Otu0002    Otu01657    0.747195570271361    
Otu0002    Otu01669    0.577474772318958    
Otu0002    Otu01673    0.57235592816339    
Otu0002    Otu01678    0.532054607967116    
Otu0002    Otu01692    0.510778063738462    
Otu0002    Ot

[R] Test if mysql connection is alive

2013-02-14 Thread Frans Marcelissen
Hi fellows,
I use RMySQL. I want to reconnect, if the connections is not alive anymore.

if (!connected()) con<-dbConnect(MySQL(),user=..,
password=..,host=..,db=..)

But how can I do the test connected()?
I thought the way to do this was,

connected()<-function(){return (exists("con") & isIdCurrent(con))}

But that does'n work, after some time connected() returns TRUE, but the next
dbGetQuery  signals

Error in mysqlExecStatement(conn, statement, ...) : 
  RS-DBI driver: (could not run statement: MySQL server has gone away)

How can I test if the connection is still valid?

Thanks
Frans

__
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] network connectivity is *not* symmetric -- library(parallel)

2013-02-14 Thread Greg Minshall
hi.  i've been very happy using multicore functionality, but felt the
need to get more horsepower, so have been trying to use parallel (after
realizing it is the "new snow") to access an amazon EC2 cluster, but
have had no success.

in the internet today, if machine M (the master) can open a connection
to machine S (the slave), it's somewhat of a miracle, something to be
celebrated.  having accomplished that miracle, expecting that machine S
can *then* open a connection back to machine M is expected p^2 to be
close to p.

i get failures stating that the slave can't connect to the master, that
port 10187 "cannot be opened".

it would be nice if there were a mode whereby the *slave* would set up
to listen on a socket, transmit the socket number back to the master
(over the ssh connection the master has set up to the slave), and allow
the *master* (with proven ability to connect to the slave) to do the
connecting.

would such a mode be possible?  i suspect it would make a lot of people
happy.  (network failures are pretty mysterious.)

and, while looking at the code, i note that the socket (port) number
being opened is, essentially, hard coded into parallels/snow.  and, it
looks as if socketConnection requires a specification of the port
number.  it might be nice to allow the system to choose the port number
[at the socket(2) call], and then report that back to the other side.
this would probably involve changes to socketConnection as well as maybe
the internet module, so is probably longer term.  i think, though, that
doing this would benefit people who now are confused when they can't
start up two clusters on the same (currently, master) machine, etc.

cheers, Greg Minshall

__
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] execute an external program in R

2013-02-14 Thread Esam Tolba
Dear all
I am using r (2.15.2) under windows 7 32bit.
I want to use system command to execute an external program inside a
for loop. this program needs  the input and output names.
since the names will change in the for loop I am not able to use the
programs on all the files




for (k in 1:10){
x=read.table ("data.txt")
   xx=x[1:5, ]
   xxx=paste0("data_",k,"txt")
 write.table (xx,xxx,quote =FALSE, sep = "\t",row.names = FALSE,
col.names = FALSE)
 system ('dssp.exe -i xxx -o xxx.out)

}







Best Regards,

__
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] Nomogram after Cox Random Effect (frailty) model

2013-02-14 Thread Frank Harrell
This can't be done directly, but if you can output predicted values from
coxme and fit an rms ols model that predicts these predicted values with an
R^2 of 1.0 you can use nomogram() on the ols fit to get what you want.
Frank

george boul wrote
> Dear R-users,
> I am a novice R-user with some experience in using the RMS package for
> taking nomograms after various survival models.
> This time, I am trying to plot a nomogram after a Random Effects Cox,
> implemented by the "coxme" package. My questions are:
> 1. Is it possible to take a nomogram directly after the coxme survival
> function?
> 2. If not is there a way to take the linear predictor results and plug
> them into the RMS cox model and get the nomogram I want?
> Any instructions/suggestions would be highly appreciable? 
> Thank you in advance
> George
> 
> Dr. George Bouliotis
> Research Fellow in BiostatisticsMRC-MHTMR (Midland Hub for Trials
> Methodology Research) University of BirminghamPublic Health
> BuildingBirmingham B115 2TTUnited Kingdom
> 
>   [[alternative HTML version deleted]]
> 
> __

> R-help@

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





-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Nomogram-after-Cox-Random-Effect-frailty-model-tp4658544p4658545.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.


[R] Nomogram after Cox Random Effect (frailty) model

2013-02-14 Thread george boul

Dear R-users,
I am a novice R-user with some experience in using the RMS package for taking 
nomograms after various survival models.
This time, I am trying to plot a nomogram after a Random Effects Cox, 
implemented by the "coxme" package. My questions are:
1. Is it possible to take a nomogram directly after the coxme survival function?
2. If not is there a way to take the linear predictor results and plug them 
into the RMS cox model and get the nomogram I want?
Any instructions/suggestions would be highly appreciable? 
Thank you in advance
George

Dr. George Bouliotis
Research Fellow in BiostatisticsMRC-MHTMR (Midland Hub for Trials Methodology 
Research) University of BirminghamPublic Health BuildingBirmingham B115 
2TTUnited Kingdom
  
[[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] Problems plotting and regression w.r.t. date data type on x axis

2013-02-14 Thread PIKAL Petr
Hi

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Kategoricus
> Sent: Thursday, February 14, 2013 12:25 PM
> To: r-help@r-project.org
> Subject: Re: [R] Problems plotting and regression w.r.t. date data type
> on x axis
> 
> Hello Petr!
> 
> thanks a lot for your help. The plot command plots well, but the abline
> returns without error and does nothing.
> 
> > str(tabelle)
> 'data.frame':   4 obs. of  3 variables:
>  $ date  : Factor w/ 4 levels "2009-01-1","2009-12-1",..: 1 2 3 4  $
> number: int  1673 2111 2487 4301  $ date2 : POSIXlt, format: "2009-01-
> 01" "2009-12-01" ...

As expected date is factor, number is numeric and date2 is POSIXlt format.


> > plot(tabelle$date2,tabelle$number, pch=19, xlab="date of retrieval",
> > ylab="number of animals") regression.punkte<-lm(tabelle$number ~
> > as.Date(tabelle$date)) regression.punkte

Here you are plotting number against POSIX date2.


> 
> Call:
> lm(formula = tabelle$number ~ as.Date(tabelle$date))

Here you use date probably converted by as.Date. Why you do not use 

lm(number ~ date2, data = tabelle)

which is usual form of model formula.

Try also change date2 by as.POSIXct.

Regards
Petr

> 
> Coefficients:
>   (Intercept)  as.Date(tabelle$date)
>-24046.326  1.799
> 
> > abline(regression.punkte, lwd=2)
> >
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Problems-
> plotting-and-regression-w-r-t-date-data-type-on-x-axis-
> tp4658518p4658529.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.

__
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] plot custom x axis ticks values

2013-02-14 Thread PIKAL Petr
Hi

when I tried your code the labels were positioned at correct positions. Please 
send some reproducible example.

Regards
Petr

> -Original Message-
> From: e-letter [mailto:inp...@gmail.com]
> Sent: Thursday, February 14, 2013 11:58 AM
> To: PIKAL Petr
> Cc: r-help@r-project.org
> Subject: Re: [R] plot custom x axis ticks values
> 
> On 14/02/2013, PIKAL Petr  wrote:
> > Hi
> >
> > much quicker and better for you is to inspect help pages.
> >
> > ?axis
> >
> > axis(1, at=1:4, labels=c(letters[1:4]))
> 
> Had tried, but noticed that the labels created were not positioned
> equally across the entire axis, but occupied about 50 % (the left
> half) of the axis. How to change this please?
__
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] [lattice] display a projected map on a layerplot

2013-02-14 Thread Felix Andrews
Hi

I'm a bit lost in the labyrinthine world of map projections, but
clearly something is mismatched between the two coordinate systems
being plotted:

1. the raster - the plot scale here seems to be cell numbers starting
from cell (1,1).

> summary(coordinates(o3.raster))
   xy
 Min.   :  1.00   Min.   :  1.00
 1st Qu.: 37.75   1st Qu.: 28.75
 Median : 74.50   Median : 56.50
 Mean   : 74.50   Mean   : 56.50
 3rd Qu.:111.25   3rd Qu.: 84.25
 Max.   :148.00   Max.   :112.00

2. the state boundaries - presumably projected correctly as lambert -
coordinate values less than 1

> summary(do.call("rbind", unlist(coordinates(state.map.shp), recursive = 
> FALSE)))
   V1  V2
 Min.   :-0.234093   Min.   :-0.9169
 1st Qu.:-0.000333   1st Qu.:-0.8289
 Median : 0.080378   Median :-0.7660
 Mean   : 0.058492   Mean   :-0.7711
 3rd Qu.: 0.162993   3rd Qu.:-0.7116
 Max.   : 0.221294   Max.   :-0.6343


Regards
Felix


On 14 February 2013 10:32, Tom Roche  wrote:
>
> summary: I can display a lon-lat map on a lattice::layerplot, and I
> can display a Lambert conformal conic (LCC) map on a spam::image, but
> I can't display an LCC map on a lattice::layerplot. Example follows.
> What am I doing wrong?
>
> details:
>
> I've been using `lattice` (via `rasterVis`) successfully to display
> global atmospheric data, which works well enough (though I am
> definitely intrigued by ggplot/ggmap). Particularly, I am able to
> overlay my plots with maps, which is essential for the sort of work
> I'm doing. However I'm currently unable to use lattice::layerplot for
> some regional data projected LCC: the data plots, but I cannot get a
> map to overlay. I can do this by cruder means, but would prefer to
> know how to do this in lattice/rasterVis or similar (or ggplot/ggmap).
> Two nearly-self-contained examples follow.
>
> The data, ozone_lcc.nc, comes with CRAN package=M3 ... except that M3
> supplies it as
>
> system.file("extdata/ozone_lcc.ncf", package="M3")
>
> and that extension currently causes problems for CRAN package=raster.
> You can either rename that file (and put it some current working
> directory), or you can download (270 kB)
>
> https://bitbucket.org/tlroche/mozart-global-to-aqmeii-na/downloads/ozone_lcc.nc
>
> You can then run the following code:
>
> # start example #
>
> library("M3")# http://cran.r-project.org/web/packages/M3/
> library("rasterVis") # http://cran.r-project.org/web/packages/rasterVis/
>
> ## Use an example file with projection=Lambert conformal conic.
> # lcc.file <- system.file("extdata/ozone_lcc.ncf", package="M3")
> lcc.file <- "./ozone_lcc.nc" # unfortunate problem with raster::raster
> lcc.proj4 <- get.proj.info.M3(lcc.file)
> lcc.proj4   # debugging
> # [1] "+proj=lcc +lat_1=33 +lat_2=45 +lat_0=40 +lon_0=-97 +a=637 
> +b=637"
> # Note +lat_0=40 +lat_1=33 +lat_2=45 for maps::map@projection (below)
> lcc.crs <- sp::CRS(lcc.proj4)
> lcc.pdf <- "./ozone_lcc.pdf" # for output
>
> ## Read in variable with daily ozone.
> # o3.raster <- raster::raster(x=lcc.file, varname="O3", crs=lcc.crs)
> # ozone_lcc.nc has 4 timesteps, choose 1 at random
> o3.raster <- raster::raster(x=lcc.file, varname="O3", crs=lcc.crs, level=1)
> o3.raster@crs <- lcc.crs # why does the above assignment not take?
> o3.raster # debugging
> # class   : RasterLayer
> # band: 1
> # dimensions  : 112, 148, 16576  (nrow, ncol, ncell)
> # resolution  : 1, 1  (x, y)
> # extent  : 0.5, 148.5, 0.5, 112.5  (xmin, xmax, ymin, ymax)
> # coord. ref. : +proj=lcc +lat_1=33 +lat_2=45 +lat_0=40 +lon_0=-97 +a=637 
> +b=637
> # data source : .../ozone_lcc.nc
> # names   : O3
> # z-value : 1
> # zvar: O3
> # level   : 1
>
> ## Get US state boundaries in projection units.
> state.map <- maps::map(
>   database="state", projection="lambert", par=c(33,45), plot=FALSE)
> #  parameters to lambert: 
> #  see mapproj::mapproject
> state.map.shp <-
>   maptools::map2SpatialLines(state.map, proj4string=lcc.crs)
>
> pdf(file=lcc.pdf)
> rasterVis::levelplot(o3.raster, margin=FALSE
> ) + latticeExtra::layer(
>   sp::sp.lines(state.map.shp, lwd=0.8, col='darkgray'))
>
> dev.off()
> # change this as needed to view PDFs on your system
> system(sprintf("xpdf %s", lcc.pdf))
> # data looks good, but there's no map.
>
> ## Try again, with lambert(40,33)
> state.map <- maps::map(
>   database="state", projection="lambert", par=c(40,33), plot=FALSE)
> #  parameters to lambert: 
> #  see mapproj::mapproject
> state.map.shp <-
>   maptools::map2SpatialLines(state.map, proj4string=lcc.crs)
>
> pdf(file=lcc.pdf)
> rasterVis::levelplot(o3.raster, margin=FALSE
> ) + latticeExtra::layer(
>   sp::sp.lines(state.map.shp, lwd=0.8, col='darkgray'))
> # still no map :-(
>
> dev.off()
> system(sprintf("xpdf %s", lcc.pdf))
>
> #   end example #
>
> The data looks right, in that it great

[R] How write raster files after manipulation?

2013-02-14 Thread Jonsson
I have 12 binary (raster) files   
https://echange-fichiers.inra.fr/get?k=k3M2jatJyHy65Cs99G4 .
I would like to calculate the moving average for the 12 values for each
pixel in the 12 files.

For a simple vector we can get a moving average by using this :
  
 x <- c(1,2,3,NA,NA,4,6,5,6,4,2,5)
movingmean <- rollapply(x, 3, FUN = mean, na.rm = T)
now I want to do the same but with rasters and I tried:

files   <- list.files("C:final-2010", "*.envi", full.names = TRUE)
results<- overlay(stack(files), fun=function(x) movingFun(x, fun=mean,
n=3, na.rm=TRUE))

That worked without errors but I want to write the results and check them:
I tried several ways of writing but all of them got errors:

 1)for (i in seq_along(results)) {
   fileName <- sprintf("C:\\New folder (3)\\final-2010.bin", i)
   writeBin(as.double(results[i]), fileName, size = 4)
   }
  Error in writeBin(as.double(results[i]), fileName, size = 4) : 
  (list) object cannot be coerced to type 'double'


  2) for (i in seq_along(results)) {
   fileName <- sprintf("C:\\New folder (3)\\final-2010.bin", i)
   writeBin(as.double(results[[i]]), fileName, size = 4)
  }
  Error in as.double(results[[i]]) : 
  cannot coerce type 'S4' to vector of type 'double'

   3) for(i in 1:length(results)){
   fileName <- strsplit(results[i],split='\\.')[[1]][1]
   outputFile <- paste(fileName,'_amenlast','.envi',sep='')
   rf <- writeRaster(results, filename=outputFile, overwrite=TRUE)
}
   Error in strsplit(results[i], split = "\\.") : non-character argument
   to write the results:

Any ideas?

   



--
View this message in context: 
http://r.789695.n4.nabble.com/How-write-raster-files-after-manipulation-tp4658539.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] Problems plotting and regression w.r.t. date data type on x axis

2013-02-14 Thread Kategoricus
as.POSIXct() works fine (finally!)

Thanks a lot David&Petr for your help!



--
View this message in context: 
http://r.789695.n4.nabble.com/Problems-plotting-and-regression-w-r-t-date-data-type-on-x-axis-tp4658518p4658537.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] approxfun values

2013-02-14 Thread Keith Jewell
Alternatively, with approx() use xout to specify which interpolated 
values you want returned:


approx(dat, xout=dat$V1[is.na(dat$V2)])

KJ

On 14/02/2013 11:43, Rui Barradas wrote:

Hello,

In what follows I've changed your df name to 'dat', to save some
keystrokes.
approxfun returns a function, so if you want just the interpolated
values, apply that function to the x values where y is NA.



dat <- read.table(text = "
V1 V2
1 10 2
2 20 NA
3 30 5
4 40 7
5 50 NA
6 60 NA
7 70 2
8 80 6
9 90 9
10 100 NA
", header = TRUE)

f <- approxfun(dat)
x <- dat$V1[is.na(dat$V2)]
y <- f(x)
y


Hope this helps,

Rui Barradas

Em 14-02-2013 08:43, e-letter escreveu:

Readers,

According to the help '?approxfun', the function can be used to obtain
the interpolated values. The following test was tried:


testinterpolation<-read.csv('test.csv',header=FALSE)
testinterpolation

V1 V2
1 10 2
2 20 NA
3 30 5
4 40 7
5 50 NA
6 60 NA
7 70 2
8 80 6
9 90 9
10 100 NA

testinterpolationvalues<-approxfun(testinterpolation,y=NULL)
testinterpolationvalues

function (v)
.C(C_R_approxfun, as.double(x), as.double(y), as.integer(n),
xout = as.double(v), as.integer(length(v)), as.integer(method),
as.double(yleft), as.double(yright), as.double(f), NAOK = TRUE,
PACKAGE = "stats")$xout



testinterpolationvalues<-approx(testinterpolation,y=NULL)
testinterpolationvalues

$x
[1] 10.0 11.63265 13.26531 14.89796 16.53061 18.16327 19.79592
21.42857
[9] 23.06122 24.69388 26.32653 27.95918 29.59184 31.22449 32.85714
34.48980
[17] 36.12245 37.75510 39.38776 41.02041 42.65306 44.28571 45.91837
47.55102
[25] 49.18367 50.81633 52.44898 54.08163 55.71429 57.34694 58.97959
60.61224
[33] 62.24490 63.87755 65.51020 67.14286 68.77551 70.40816 72.04082
73.67347
[41] 75.30612 76.93878 78.57143 80.20408 81.83673 83.46939 85.10204
86.73469
[49] 88.36735 90.0

$y
[1] 2.00 2.244898 2.489796 2.734694 2.979592 3.224490 3.469388
3.714286
[9] 3.959184 4.204082 4.448980 4.693878 4.938776 5.244898 5.571429
5.897959
[17] 6.224490 6.551020 6.877551 6.829932 6.557823 6.285714 6.013605
5.741497
[25] 5.469388 5.197279 4.925170 4.653061 4.380952 4.108844 3.836735
3.564626
[33] 3.292517 3.020408 2.748299 2.476190 2.204082 2.163265 2.816327
3.469388
[41] 4.122449 4.775510 5.428571 6.061224 6.551020 7.040816 7.530612
8.020408
[49] 8.510204 9.00

How to obtain a vector consisting _only_ of the interpolated values?

It was expected that 'approx' would return both original and
interpolated values (which the above shows) and that 'approxfun' would
not show the original values.

--
r2151

__
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] Looking for an easy way to change the names of a vector

2013-02-14 Thread Rui Barradas

Hello,

Use ifelse, and assign its values to names(Data)


ifelse(grepl(" ", names(Data)), gsub(" ", "-", names(Data)), 
paste0(names(Data), "-XXX"))



Hope this helps,

Rui Barradas
Em 14-02-2013 11:43, Christofer Bogaso escreveu:

Hello again,

Let say I have following vector (this is basically a snap of very large vector):


Data <- 1:8
names(Data) <- c("ada", "fsdfs", "asd fd", "asdsa", "dsada", "asasad",
"adas asdad", "aasaa")
Data

Now I want to change the names according to following rule:

1. If there is any space then replace that space by "-"
2. Otherwise add "-XXX" at the last to each name

Therefore the names will be:

c("ada-XXX", "fsdfs-XXX", "asd-fd", "asdsa-XXX", "dsada-XXX",
"asasad-XXX", "adas-asdad", "aasaa-XXX")


Can somebody point me some direct way for that?

Thanks for your help

__
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] approxfun values

2013-02-14 Thread Rui Barradas

Hello,

In what follows I've changed your df name to 'dat', to save some keystrokes.
approxfun returns a function, so if you want just the interpolated 
values, apply that function to the x values where y is NA.




dat <- read.table(text = "
 V1 V2
1   10  2
2   20 NA
3   30  5
4   40  7
5   50 NA
6   60 NA
7   70  2
8   80  6
9   90  9
10 100 NA
", header = TRUE)

f <- approxfun(dat)
x <- dat$V1[is.na(dat$V2)]
y <- f(x)
y


Hope this helps,

Rui Barradas

Em 14-02-2013 08:43, e-letter escreveu:

Readers,

According to the help '?approxfun', the function can be used to obtain
the interpolated values. The following test was tried:


testinterpolation<-read.csv('test.csv',header=FALSE)
testinterpolation

 V1 V2
1   10  2
2   20 NA
3   30  5
4   40  7
5   50 NA
6   60 NA
7   70  2
8   80  6
9   90  9
10 100 NA

testinterpolationvalues<-approxfun(testinterpolation,y=NULL)
testinterpolationvalues

function (v)
.C(C_R_approxfun, as.double(x), as.double(y), as.integer(n),
 xout = as.double(v), as.integer(length(v)), as.integer(method),
 as.double(yleft), as.double(yright), as.double(f), NAOK = TRUE,
 PACKAGE = "stats")$xout



testinterpolationvalues<-approx(testinterpolation,y=NULL)
testinterpolationvalues

$x
  [1] 10.0 11.63265 13.26531 14.89796 16.53061 18.16327 19.79592 21.42857
  [9] 23.06122 24.69388 26.32653 27.95918 29.59184 31.22449 32.85714 34.48980
[17] 36.12245 37.75510 39.38776 41.02041 42.65306 44.28571 45.91837 47.55102
[25] 49.18367 50.81633 52.44898 54.08163 55.71429 57.34694 58.97959 60.61224
[33] 62.24490 63.87755 65.51020 67.14286 68.77551 70.40816 72.04082 73.67347
[41] 75.30612 76.93878 78.57143 80.20408 81.83673 83.46939 85.10204 86.73469
[49] 88.36735 90.0

$y
  [1] 2.00 2.244898 2.489796 2.734694 2.979592 3.224490 3.469388 3.714286
  [9] 3.959184 4.204082 4.448980 4.693878 4.938776 5.244898 5.571429 5.897959
[17] 6.224490 6.551020 6.877551 6.829932 6.557823 6.285714 6.013605 5.741497
[25] 5.469388 5.197279 4.925170 4.653061 4.380952 4.108844 3.836735 3.564626
[33] 3.292517 3.020408 2.748299 2.476190 2.204082 2.163265 2.816327 3.469388
[41] 4.122449 4.775510 5.428571 6.061224 6.551020 7.040816 7.530612 8.020408
[49] 8.510204 9.00

How to obtain a vector consisting _only_ of the interpolated values?

It was expected that 'approx' would return both original and
interpolated values (which the above shows) and that 'approxfun' would
not show the original values.

--
r2151

__
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] Looking for an easy way to change the names of a vector

2013-02-14 Thread Christofer Bogaso
Hello again,

Let say I have following vector (this is basically a snap of very large vector):


Data <- 1:8
names(Data) <- c("ada", "fsdfs", "asd fd", "asdsa", "dsada", "asasad",
"adas asdad", "aasaa")
Data

Now I want to change the names according to following rule:

1. If there is any space then replace that space by "-"
2. Otherwise add "-XXX" at the last to each name

Therefore the names will be:

c("ada-XXX", "fsdfs-XXX", "asd-fd", "asdsa-XXX", "dsada-XXX",
"asasad-XXX", "adas-asdad", "aasaa-XXX")


Can somebody point me some direct way for that?

Thanks for your help

__
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] Problems plotting and regression w.r.t. date data type on x axis

2013-02-14 Thread Kategoricus
Hello Petr!

thanks a lot for your help. The plot command plots well, but the abline
returns without error and does nothing.

> str(tabelle)
'data.frame':   4 obs. of  3 variables:
 $ date  : Factor w/ 4 levels "2009-01-1","2009-12-1",..: 1 2 3 4
 $ number: int  1673 2111 2487 4301
 $ date2 : POSIXlt, format: "2009-01-01" "2009-12-01" ...
> plot(tabelle$date2,tabelle$number, pch=19, xlab="date of retrieval",
> ylab="number of animals")
> regression.punkte<-lm(tabelle$number ~ as.Date(tabelle$date))
> regression.punkte

Call:
lm(formula = tabelle$number ~ as.Date(tabelle$date))

Coefficients:
  (Intercept)  as.Date(tabelle$date)  
   -24046.326  1.799  

> abline(regression.punkte, lwd=2)
> 



--
View this message in context: 
http://r.789695.n4.nabble.com/Problems-plotting-and-regression-w-r-t-date-data-type-on-x-axis-tp4658518p4658529.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] match in dependence of 2 columns

2013-02-14 Thread Rui Barradas

Hello,

You can do something like this:


join(dat1, dat2[, c("cu.nr", "name", "value")], 
by=c("cu.nr.","name"),type="right")



Hope this helps,

Rui Barradas
Em 14-02-2013 07:03, Mat escreveu:

thank you, this code works:

library(plyr)
join(dat1,dat2,by=c("cu.nr.","name"),type="right")

but my dat2 frame has a lot of columns, which i don't want to match.
How can i say, that only the column "value" should be match to dat1 ?

Thank you.

Mat




--
View this message in context: 
http://r.789695.n4.nabble.com/match-in-dependence-of-2-columns-tp4658405p4658508.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.



__
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] Problems plotting and regression w.r.t. date data type on x axis

2013-02-14 Thread David Winsemius


On Feb 14, 2013, at 1:10 AM, Kategoricus wrote:


Hello,

probably a newbie question, but i didnt find any information on
plotting/regressing w.r.t. a date data type. My trials were  
unfruitful. Can

anyone help ? Thanks in advance!

Here is my interaction with R:



tabelle

date number date2
1 2009-01-1 1673 2009-01-01
2 2009-12-1 2111 2009-12-01
3 2010-7-1 2487 2010-07-01
4 2013-2-1 4301 2013-02-01

regression.punkte<-lm(tabelle$number ~ tabelle$date2)
Fehler in model.frame.default(formula = tabelle$number ~ tabelle 
$date2, :

ungültiger Typ (list) für die Variable 'tabelle$date2'


I'm guessing that you used as.POSIXlt to create that date2 variable.  
POSIXlt classed variables are lists and as such create all sorts of  
problems for functions that are expecting atomic vectors. If I'm  
right, you will ahve better chances of success by converting to  
POSIXct class.


> tabelle <- read.table(text="date number date2
+ 1 2009-01-1 1673 2009-01-01
+ 2 2009-12-1 2111 2009-12-01
+ 3 2010-7-1 2487 2010-07-01
+ 4 2013-2-1 4301 2013-02-01", header=TRUE, stringsAsFactors=FALSE)
> tabelle$date2 <- as.POSIXlt(tabelle$date2)
> regression.punkte<-lm(tabelle$number ~ tabelle$date2)
Error in model.frame.default(formula = tabelle$number ~ tabelle 
$date2,  :

  invalid type (list) for variable 'tabelle$date2'

> tabelle$date2 <- as.POSIXct(tabelle$date2)
> regression.punkte<-lm(tabelle$number ~ tabelle$date2)
> regression.punkte

Call:
lm(formula = tabelle$number ~ tabelle$date2)

Coefficients:
  (Intercept)  tabelle$date2
   -2.405e+04  2.082e-05



regression.punkte<-lm(tabelle$number ~ tabelle$date)
plot(tabelle$date2,tabelle$number, pch=19, xlab="date of retrieval",
ylab="number of animals") ***R DRAWS THIS***
regression.punkte


Call:
lm(formula = tabelle$number ~ tabelle$date)

Coefficients:
(Intercept) tabelle$date2009-12-1 tabelle$date2010-7-1
1673 438 814
tabelle$date2013-2-1
2628


abline(regression.punkte, lwd=2) ***R DOES NOT DRAW LINE***

Warnmeldung:
In abline(regression.punkte, lwd = 2) :
nutze nur die ersten beiden von 4 Regressionskoeffizienten

summary(regression.punkte)


Call:
lm(formula = tabelle$number ~ tabelle$date)

Residuals:
ALL 4 residuals are 0: no residual degrees of freedom!

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1673 NA NA NA
tabelle$date2009-12-1 438 NA NA NA
tabelle$date2010-7-1 814 NA NA NA
tabelle$date2013-2-1 2628 NA NA NA

Residual standard error: NaN on 0 degrees of freedom
Multiple R-squared: 1, Adjusted R-squared: NaN
F-statistic: NaN on 3 and 0 DF, p-value: NA




David Winsemius, MD
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.


Re: [R] 3D-plots of 2D-grids

2013-02-14 Thread David Winsemius


On Feb 14, 2013, at 1:10 AM, jas wrote:



Hello everybody,

I have an Ascii-grid (100x100m) with population density over  
Switzerland

(local coordinations system, CH LV03). Now I would like to have a nice
graphic to present the data. I would like to make a plot that will  
show the
density as the z-variable and raise for example a stacking pillar  
showing
how high the density is in that hectare. I attached a map that's   
similar to
what I would like, to give you an idea incase I am not making myself  
clear.



Can you tell me how I can do this? I tried persp and persp3d, but  
there the
x and y-vectors have to be increasing values, where as the  
coordinates in a
grid don't necessarily increase for both x and y, as they follow the  
line

horizontally...



I thought you said you had a 'grid'  presumably with values at the  
intersections of the grid? That is the sort of input that persp will  
take. You would supply x=seq( ..., length=100), y= seq( ... ,  
length=100) and your 'grid' (which I assume is stored as a matrix) as  
z values. In fact if you just supply a matrix as the z value to persp  
you will get an automatic display, just not with the labels you might  
have hoped for.


--

David Winsemius, MD
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.


Re: [R] list of matrices --> array

2013-02-14 Thread David Winsemius


On Feb 13, 2013, at 10:03 PM, Murat Tasan wrote:


i'm somehow embarrassed to even ask this, but is there any built-in
method for doing this:

my_list <- list()
my_list[[1]] <- matrix(1:20, ncol = 5)
my_list[[2]] <- matrix(20:1, ncol = 5)

now, knowing that these matrices are identical in dimension, i'd like
to unfold the list to a 2x4x5 (or some other permutation of the dim
sizes) array.
i know i can initialize the array, then loop through my_list to fill
the array, but somehow this seems inelegant.
i also know i can vectorize the matrices and unlist the list, then
build the array from that single vector, but this also seems inelegant
(and an easy place to introduce errors/bugs).

i can't seem to find any built-in that handles this already... but
maybe i just haven't looked hard enough :-/


I think the built-in function you seek is `simplify2array`:

# gives 4 x 5 x 2
> simplify2array(my_list)
, , 1

 [,1] [,2] [,3] [,4] [,5]
[1,]159   13   17
[2,]26   10   14   18
[3,]37   11   15   19
[4,]48   12   16   20

, , 2

 [,1] [,2] [,3] [,4] [,5]
[1,]   20   16   1284
[2,]   19   15   1173
[3,]   18   14   1062
[4,]   17   13951

> # 2 x 4 x 5
 aperm( simplify2array(my_list), c(3,1,2) )


 # 4 x 2 x 5
> aperm( simplify2array(my_list), c(1,3,2) )

--
David Winsemius, MD
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.


Re: [R] Plotting multiple xyplots in same page

2013-02-14 Thread Duncan Mackay

Hi Lisa

I did something like what you want several months ago but cannot find it.

I think I used viewport in the grid package and it was a case of 
using several viewports withing a tree akin to what you have been 
doing with print.


Paul Murrell's book R Graphics 2nd edition may be of use

Sorry cannot give you any more help

Regards

Duncan

At 17:09 14/02/2013, you wrote:
Dear Duncan and Pascal, Thank you for the response. Duncan: I was 
able to fix the space between title and figure.  I would also like 
to  have separate main titles for each row of figures in addition to 
the individual titles. xy <-xyplot(decrease ~ treatment, 
OrchardSprays, main= "Some plot", groups = rowpos, type 
= "a", page = 
function(n){  grid.text(LETTERS[j], 
y = 0.95,  x = 
0.15,  default.units = 
"npc",  just = 
c("left"),  gp = gpar(fontsize = 
12,fontface="bold") )}, par.settings = 
c(simpleTheme(lty=1:8, col="black",lwd=2),list(layout.heights = 
list(main = 1.2,sub  = 
0,axis.top = 
0.2,top.padding  = 
0.1,bottom.padding = 0)) ), auto.key 
= list(x = 0.2, y = 0.9, cex = 0.75, points = FALSE, lines = 
TRUE)) j=1 print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = TRUE) 
j=j+1 print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = TRUE) j=j+1 
print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = TRUE) j=j+1 
print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = TRUE) j=j+1 print(xy, 
pos = c(0.33, 0.0, 0.66, 0.5), more = TRUE) j=j+1 print(xy, pos = 
c(0.66, 0.0, 0.99, 0.5), more = FALSE) Pascal: I would prefer not to 
use panels as this is for publication purpose.  Many thanks, Lisa 
- Original Message - From: Duncan Mackay 
 To: Lisa Daniel ; 
r-help-r-project.org  Cc: Sent: Wednesday, 
February 13, 2013 7:53 PM Subject: Re: [R] Plotting multiple xyplots 
in same page Hi Lisa have a look at par.settings in ?xyplot 
trellis.par.get() shows the settings trellis.par.get()[[27]] $left 
$left$tck [1] 1 $left$pad1 [1] 1 $left$pad2 [1] 1 $top $top$tck [1] 
1 $top$pad1 [1] 1 $top$pad2 [1] 1 $right $right$tck [1] 1 
$right$pad1 [1] 1 $right$pad2 [1] 1 $bottom $bottom$tck [1] 1 
$bottom$pad1 [1] 1 $bottom$pad2 [1] 1 as an example: par.settings = 
list( layout.heights = list(main = 0,sub  = 
0,axis.top = 
0.2,top.padding  = 
0,bottom.padding = 0)) HTH Duncan Duncan 
Mackay Department of Agronomy and Soil Science University of New 
England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 
09:10 14/02/2013, you wrote: >Dear Rhelp, > >I was able to plot 6 
figures in one page.  I do need help in >reducing the space between 
the title and the plot and assigning >A,B,C,D,E,F to each 
figure >library(lattice) >trellis.par.set(theme = col.whitebg()) >xy 
<- xyplot(decrease ~ treatment, OrchardSprays, > main="Some 
plot", >   groups = rowpos, type = 
"a", >   auto.key = list(x = 0.2, y = 
0.9, > cex = 0.52, points = FALSE, lines = 
TRUE)) > > >print(xy, pos = c(0.0, 0.5, 0.33, 1.0), more = 
TRUE) >print(xy, pos = c(0.33, 0.5, 0.66, 1.0), more = 
TRUE) >print(xy, pos = c(0.66, 0.5, 0.99, 1.0), more = 
TRUE) >print(xy, pos = c(0.0, 0.0, 0.33, 0.5), more = 
TRUE) >print(xy, pos = c(0.33, 0.0, 0.66, 0.5), more = 
TRUE) >print(xy, pos = c(0.66, 0.0, 0.99, 0.5), more = 
FALSE) > >Thanks in advance, >Lisa > > > >- Original Message 
- >From: Lisa Daniel  >To: 
"r-help@r-project.org"  >Cc: >Sent: Wednesday, 
February 13, 2013 5:28 PM >Subject: Plotting multiple xyplots in 
same page > >Dear Rhelp, > >I would like to have 6 xyplots in the 
same page.  Similar to >(par(mfrow=c(3,3)) >Found this example on 
the R archives. >library(lattice) >trellis.par.set(theme = 
col.whitebg()) >xy <- xyplot(decrease ~ treatment, 
OrchardSprays, >   groups = rowpos, type = 
"a", >   auto.key = list(x = 0.2, y = 
0.9, > cex = 0.75, points = FALSE, lines = 
TRUE)) > >print(xy, pos = c(0.0, 0.0, 0.5, 0.5), more = 
TRUE) >print(xy, pos = c(0.0, 0.5, 0.5, 1.0), more = 
TRUE) >print(xy, pos = c(0.5, 0.0, 1.0, 0.5), more = 
TRUE) >print(xy, pos = c(0.5, 0.5, 1.0, 1.0), more = 
FALSE) > > > > >When I changed the print() to: > >  print(xy, 
pos=c(0.0,0.0,0.33,0.33),more = TRUE), >the figure was not looking 
good. > >Also, is it possible to assign A, B, C,D, etc for each 
figure. > > > >a<- rnorm(1000,0,1) >b<- rnorm(1000,0,2) >c<- 
rnorm(1000,0,3) >d<- 
rnorm(1000,0,4) >par(mfrow=c(2,2)) >hist(a,main="") >title(main="A",a 
dj=0) >hist(b,main="") >title(main="B",adj=0) >hist(c,main="") >title 
(main="C",adj=0) >hist(d,main="") >title(main="D",adj=0) > > >I 
tried this to xyplot, but it was

Re: [R] plot custom x axis ticks values

2013-02-14 Thread e-letter
On 14/02/2013, PIKAL Petr  wrote:
> Hi
>
> much quicker and better for you is to inspect help pages.
>
> ?axis
>
> axis(1, at=1:4, labels=c(letters[1:4]))

Had tried, but noticed that the labels created were not positioned
equally across the entire axis, but occupied about 50 % (the left
half) of the axis. How to change this please?

__
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] plot custom x axis ticks values

2013-02-14 Thread PIKAL Petr
Hi

much quicker and better for you is to inspect help pages.

?axis

axis(1, at=1:4, labels=c(letters[1:4]))

Regards
Petr



> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of e-letter
> Sent: Thursday, February 14, 2013 11:41 AM
> To: r-help@r-project.org
> Subject: [R] plot custom x axis ticks values
> 
> Readers,
> 
> For this data set:
> 
> testvalues<-c(10,20,30,40)
> 
> How to amend the plot instruction:
> 
> plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n')
> 
> so that x axis ticks labels can be added to existing graph with
> arbitrary value such as 0,100,200,300)?
> 
> Thanks in advance.
> 
> --
> r2151
> 
> __
> 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] plot custom x axis ticks values

2013-02-14 Thread e-letter
Readers,

For this data set:

testvalues<-c(10,20,30,40)

How to amend the plot instruction:

plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n')

so that x axis ticks labels can be added to existing graph with
arbitrary value such as 0,100,200,300)?

Thanks in advance.

--
r2151

__
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] Problems plotting and regression w.r.t. date data type on x axis

2013-02-14 Thread PIKAL Petr
Hi

most probably your dates are not what you expect. Eg. they look like a date but 
they are not treated as date. You can check yourself by

str(tabelle)

which will result probably in factor, numeric, factor.

You need to change variables date and date2 into Date class.

?strptime or ?as.Date

date and date2 seems to be same but usually you shall use the same variables 
for plotting and for model to get correct regression line. 

Regards
Petr

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Kategoricus
> Sent: Thursday, February 14, 2013 10:10 AM
> To: r-help@r-project.org
> Subject: [R] Problems plotting and regression w.r.t. date data type on
> x axis
> 
> Hello,
> 
> probably a newbie question, but i didnt find any information on
> plotting/regressing w.r.t. a date data type. My trials were unfruitful.
> Can anyone help ? Thanks in advance!
> 
> Here is my interaction with R:
> 
> 
> > tabelle
> date number date2
> 1 2009-01-1 1673 2009-01-01
> 2 2009-12-1 2111 2009-12-01
> 3 2010-7-1 2487 2010-07-01
> 4 2013-2-1 4301 2013-02-01
> > regression.punkte<-lm(tabelle$number ~ tabelle$date2)
> Fehler in model.frame.default(formula = tabelle$number ~ tabelle$date2,
> :
> ungültiger Typ (list) für die Variable 'tabelle$date2'
> > regression.punkte<-lm(tabelle$number ~ tabelle$date)
> > plot(tabelle$date2,tabelle$number, pch=19, xlab="date of retrieval",
> > ylab="number of animals") ***R DRAWS THIS*** regression.punkte
> 
> Call:
> lm(formula = tabelle$number ~ tabelle$date)
> 
> Coefficients:
> (Intercept) tabelle$date2009-12-1 tabelle$date2010-7-1
> 1673 438 814
> tabelle$date2013-2-1
> 2628
> 
> > abline(regression.punkte, lwd=2) ***R DOES NOT DRAW LINE***
> Warnmeldung:
> In abline(regression.punkte, lwd = 2) :
> nutze nur die ersten beiden von 4 Regressionskoeffizienten
> > summary(regression.punkte)
> 
> Call:
> lm(formula = tabelle$number ~ tabelle$date)
> 
> Residuals:
> ALL 4 residuals are 0: no residual degrees of freedom!
> 
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) 1673 NA NA NA
> tabelle$date2009-12-1 438 NA NA NA
> tabelle$date2010-7-1 814 NA NA NA
> tabelle$date2013-2-1 2628 NA NA NA
> 
> Residual standard error: NaN on 0 degrees of freedom Multiple R-
> squared: 1, Adjusted R-squared: NaN
> F-statistic: NaN on 3 and 0 DF, p-value: NA
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Problems-
> plotting-and-regression-w-r-t-date-data-type-on-x-axis-tp4658518.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.
__
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 plotting and regression w.r.t. date data type on x axis

2013-02-14 Thread Kategoricus
Hello,

probably a newbie question, but i didnt find any information on
plotting/regressing w.r.t. a date data type. My trials were unfruitful. Can
anyone help ? Thanks in advance!

Here is my interaction with R:


> tabelle
date number date2
1 2009-01-1 1673 2009-01-01
2 2009-12-1 2111 2009-12-01
3 2010-7-1 2487 2010-07-01
4 2013-2-1 4301 2013-02-01
> regression.punkte<-lm(tabelle$number ~ tabelle$date2)
Fehler in model.frame.default(formula = tabelle$number ~ tabelle$date2, :
ungültiger Typ (list) für die Variable 'tabelle$date2'
> regression.punkte<-lm(tabelle$number ~ tabelle$date)
> plot(tabelle$date2,tabelle$number, pch=19, xlab="date of retrieval",
> ylab="number of animals") ***R DRAWS THIS***
> regression.punkte

Call:
lm(formula = tabelle$number ~ tabelle$date)

Coefficients:
(Intercept) tabelle$date2009-12-1 tabelle$date2010-7-1
1673 438 814
tabelle$date2013-2-1
2628

> abline(regression.punkte, lwd=2) ***R DOES NOT DRAW LINE***
Warnmeldung:
In abline(regression.punkte, lwd = 2) :
nutze nur die ersten beiden von 4 Regressionskoeffizienten
> summary(regression.punkte)

Call:
lm(formula = tabelle$number ~ tabelle$date)

Residuals:
ALL 4 residuals are 0: no residual degrees of freedom!

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1673 NA NA NA
tabelle$date2009-12-1 438 NA NA NA
tabelle$date2010-7-1 814 NA NA NA
tabelle$date2013-2-1 2628 NA NA NA

Residual standard error: NaN on 0 degrees of freedom
Multiple R-squared: 1, Adjusted R-squared: NaN
F-statistic: NaN on 3 and 0 DF, p-value: NA



--
View this message in context: 
http://r.789695.n4.nabble.com/Problems-plotting-and-regression-w-r-t-date-data-type-on-x-axis-tp4658518.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.


[R] 3D-plots of 2D-grids

2013-02-14 Thread jas

Hello everybody,

I have an Ascii-grid (100x100m) with population density over Switzerland
(local coordinations system, CH LV03). Now I would like to have a nice
graphic to present the data. I would like to make a plot that will show the
density as the z-variable and raise for example a stacking pillar showing
how high the density is in that hectare. I attached a map that's  similar to
what I would like, to give you an idea incase I am not making myself clear. 

 

Can you tell me how I can do this? I tried persp and persp3d, but there the
x and y-vectors have to be increasing values, where as the coordinates in a
grid don't necessarily increase for both x and y, as they follow the line
horizontally...

Your help would be greatly appreciated :),

Thank you
jacqueline




--
View this message in context: 
http://r.789695.n4.nabble.com/3D-plots-of-2D-grids-tp4658517.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] Kernel Density estimation at specific points

2013-02-14 Thread Robert Duval
Dear Bert,

Thanks for the pointer. I had been looking for quite some time on the
r-mailing list and didn't stumble upon the right approach.
But you were right, a broader search would have led me to the right place.
My apologies for that.

Just to close this post and give an answer to future persons looking for
the same functionality:

The package that does what I was looking for in the more general setting
(in terms of kernel evaluators, and bandwidth selectors) is Jeff Racine's
np package with its function npudens using the option edat.

Many thanks,
robert



On Wed, Feb 13, 2013 at 11:16 PM, Bert Gunter wrote:

> Please learn to search!
>
> A google search on "R density estimation" brought up the akj()
> function in the quantreg package, which would seem to do what you
> requested. However, I didn't look very hard and there are probably
> still others in other packages.
>
> -- Bert
>
> On Wed, Feb 13, 2013 at 8:35 AM, Robert Duval  wrote:
> > Dear All,
> >
> > I was wondering whether someone has created a kernel density evaluator
> that
> > estimates the density at given specified points.
> >
> > The regular density() function evaluates the kernel at equidistant
> points,
> > but I am interested in doing such evaluation along a list of values
> > existing in a pre-specified vector. (Similar to the option at() in the
> > kdensity command in Stata).
> >
> > This question has appeared before in the R-list, most recently in 2011
> in :
> >
> > http://tolstoy.newcastle.edu.au/R/e14/help/11/06/5232.html
> >
> > There another list member suggested programming a home-made evaluator.
> > While the posted solution works, it is not as general, nor as fast as
> > density(). So I was wondering whether someone had recently came up with a
> > more efficient way of doing this.
> >
> > N.B. Many users have suggested using some sort of interpolation over the
> > values provided by density(). However, for the problem I have at hand
> this
> > is not what I need.
> >
> > Any help will be appreciated.
> > Robert
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
>
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>

[[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 CMD in batch mode/trycatch() keeps hold on resources

2013-02-14 Thread guillaume Le Ray
Problem fixed.

http://stackoverflow.com/questions/7103429/all-the-connections-are-in-use-execution-halted/7108799#7108799

It can happen when the error handling is not properlly done. trycatch enter
in finally and get stuck.

2013/2/13 guillaume Le Ray 

> HI all,
>
> I am using R (version 2.13.1) in batch mode on a server and I use
> trycatch() to handle the exceptions.
>
> When the code run without any exceptions, everything goes fine, however
>  as soon as trycatch handle an error, my code works fine but R keeps hold
> on the folder after quiting.
>
> Therefore when I try to delete the folder it cannot...
>
> do you have any idea of which function can be the origin of the problem?
> or how to kill the process?
>
> Regards,
>
> Guillaume Le Ray
>

[[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] list of matrices --> array

2013-02-14 Thread Rolf Turner


require(abind)
do.call(abind,c(my_list,list(along=0))) # Gives 2 x 4 x 5
do.call(abind,c(my_list,list(along=3))) # Gives 4 x 5 x 2

The latter seems more natural to me.

cheers,

Rolf Turner

On 02/14/2013 07:03 PM, Murat Tasan wrote:

i'm somehow embarrassed to even ask this, but is there any built-in
method for doing this:

my_list <- list()
my_list[[1]] <- matrix(1:20, ncol = 5)
my_list[[2]] <- matrix(20:1, ncol = 5)

now, knowing that these matrices are identical in dimension, i'd like
to unfold the list to a 2x4x5 (or some other permutation of the dim
sizes) array.
i know i can initialize the array, then loop through my_list to fill
the array, but somehow this seems inelegant.
i also know i can vectorize the matrices and unlist the list, then
build the array from that single vector, but this also seems inelegant
(and an easy place to introduce errors/bugs).

i can't seem to find any built-in that handles this already... but
maybe i just haven't looked hard enough :-/


__
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] approxfun values

2013-02-14 Thread e-letter
Readers,

According to the help '?approxfun', the function can be used to obtain
the interpolated values. The following test was tried:

> testinterpolation<-read.csv('test.csv',header=FALSE)
> testinterpolation
V1 V2
1   10  2
2   20 NA
3   30  5
4   40  7
5   50 NA
6   60 NA
7   70  2
8   80  6
9   90  9
10 100 NA
> testinterpolationvalues<-approxfun(testinterpolation,y=NULL)
> testinterpolationvalues
function (v)
.C(C_R_approxfun, as.double(x), as.double(y), as.integer(n),
xout = as.double(v), as.integer(length(v)), as.integer(method),
as.double(yleft), as.double(yright), as.double(f), NAOK = TRUE,
PACKAGE = "stats")$xout


> testinterpolationvalues<-approx(testinterpolation,y=NULL)
> testinterpolationvalues
$x
 [1] 10.0 11.63265 13.26531 14.89796 16.53061 18.16327 19.79592 21.42857
 [9] 23.06122 24.69388 26.32653 27.95918 29.59184 31.22449 32.85714 34.48980
[17] 36.12245 37.75510 39.38776 41.02041 42.65306 44.28571 45.91837 47.55102
[25] 49.18367 50.81633 52.44898 54.08163 55.71429 57.34694 58.97959 60.61224
[33] 62.24490 63.87755 65.51020 67.14286 68.77551 70.40816 72.04082 73.67347
[41] 75.30612 76.93878 78.57143 80.20408 81.83673 83.46939 85.10204 86.73469
[49] 88.36735 90.0

$y
 [1] 2.00 2.244898 2.489796 2.734694 2.979592 3.224490 3.469388 3.714286
 [9] 3.959184 4.204082 4.448980 4.693878 4.938776 5.244898 5.571429 5.897959
[17] 6.224490 6.551020 6.877551 6.829932 6.557823 6.285714 6.013605 5.741497
[25] 5.469388 5.197279 4.925170 4.653061 4.380952 4.108844 3.836735 3.564626
[33] 3.292517 3.020408 2.748299 2.476190 2.204082 2.163265 2.816327 3.469388
[41] 4.122449 4.775510 5.428571 6.061224 6.551020 7.040816 7.530612 8.020408
[49] 8.510204 9.00

How to obtain a vector consisting _only_ of the interpolated values?

It was expected that 'approx' would return both original and
interpolated values (which the above shows) and that 'approxfun' would
not show the original values.

--
r2151

__
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] Need Help Plotting "Line" for multiple linear regression

2013-02-14 Thread PIKAL Petr
Hi

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Craig O'Connell
> Sent: Wednesday, February 13, 2013 11:03 PM
> To: r-help@r-project.org
> Subject: [R] Need Help Plotting "Line" for multiple linear regression
> 
> Hello,
> 
> My name is Craig and I need help plotting a "line" for a multiple
> linear regression in R.
> 
> Here is my sample data (filename:  convis.txt)
> 
> Output of convis.txt is (vis and density being predictors of either
> avoidance or entrance):
> 
>vis den  avoid entrance
> 1   10   1 0.   0.
> 2   10   3 0.8750   0.
> 38   3 0.8180   0.0300
> 48   3 0.6670   0.0667
> 58   1 0.2110   0.
> 66   1 0.2500   0.
> 7   10   1 0.3000   0.
> 8   10   1 0.1050   0.
> 98   1 0.7000   0.1000
> 10   3   5 0.1176   0.0588
> 11   3   5 0.3077   0.1150
> 12   3   9 0.9090   0.0900
> 13   3   7 0.7778   0.1110
> 14   3   5 0.5560   0.1110
> 15   3   1 0.5710   0.
> 16   3   4 0.5710   0.
> 
> In order to do the multiple regression, I used the following coding:
> 
> 
> double=read.table("convis.txt",header=TRUE)
> attach(double)
> double
> stem(vis)
> stem(den)
> stem(avoid)
> stem(entrance)
> plot(entrance,vis*den)  *as means to see how the interaction

This is not an interaction, you just multiply vis and den and plot entrance on 
x axis and vis*den on y axis, so basically you want to model vis*den by 
entrance.

> between
> visibility and density may impact entrance behaviors
> model6=lm(entrance~vis*den)

This model is oposite of what you plotted.

> model6
> summary(model6)
> *abline(model6)  *Here is the issue as I used this for my simple
> linear
> regression technique, but do not know what to use for a multiple
> regression*

You seem to not understand how the multiple regression output and abline works.

Based on what you want you can do

plot(vis*den, entrance)
model6 <- lm(entrance~I(vis*den))
abline(model6)

however your model will have only intercept and one coefficient for variable 
x=vis*den

If you want to have separate coefficients for vis ***and*** den and their 
interaction you can use 

model6=lm(entrance~vis*den)

but in this case resulting coefficients are Intercept, vis, den and interaction 
between vis and den. In that case beside of other procedures for model 
evaluation you can do.

plot(entrance, fitted(model6))
abline(0,1)

Regards
Petr


> 
> If anybody can provide some feedback on this, it would be greatly
> appreciated.
> 
> Kind Regards,
> 
> Craig
> 
> --
> <><  <><  <><
> Craig O'Connell
> University of Massachusetts Dartmouth
> Marine Biologist
> www.youtube.com/craigpoconnell
> craigosea.blogspot.com
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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