Henrik Bengtsson | 1 Feb 02:00
Picon

Re: how to unzip files in R

I may be wrong, but I don't think unz() handles bz2 files - only zip files.

See bunzip2() of the R.utils package (which utilizes bzfile connections).

/Henrik

On Tue, Jan 31, 2012 at 2:34 PM, ql16717 <ql16717 <at> gmail.com> wrote:
> Hi,
>
> I have downloaded a bunch of bz2 files. I wonder if R will be able to
> unzip them in a batch mode or even one at a time?
>
> I was looking at the unz function. But it didn't work well. Say I have
> a bz2 file in H:/Temp/65502805_532.pair.bz2. Anyone has any
> suggestion?
>
> thanks
> John
>
>> setwd("H:\\Temp\\")
>> getwd()
> [1] "H:/Temp"
>> fn<-list.files(pattern="bz2", full.names=TRUE)
>> fn
> [1] "./65502805_532.pair.bz2"
>> unz(description=fn, filename="65502805_532.pair", open="r")
> Error in unz(description = fn, filename = "65502805_532.pair", open = "r") :
>  cannot open the connection
> In addition: Warning message:
> In unz(description = fn, filename = "65502805_532.pair", open = "r") :
(Continue reading)

Luke Miller | 1 Feb 02:04
Picon

Re: how to unzip files in R

Try the bzfile() function instead of unz(). You'll find that you're
taken to the same help page for both of those functions.

?bzfile

On Tue, Jan 31, 2012 at 2:34 PM, ql16717 <ql16717 <at> gmail.com> wrote:
>
> Hi,
>
> I have downloaded a bunch of bz2 files. I wonder if R will be able to
> unzip them in a batch mode or even one at a time?
>
> I was looking at the unz function. But it didn't work well. Say I have
> a bz2 file in H:/Temp/65502805_532.pair.bz2. Anyone has any
> suggestion?
>
> thanks
> John
>
> > setwd("H:\\Temp\\")
> > getwd()
> [1] "H:/Temp"
> > fn<-list.files(pattern="bz2", full.names=TRUE)
> > fn
> [1] "./65502805_532.pair.bz2"
> > unz(description=fn, filename="65502805_532.pair", open="r")
> Error in unz(description = fn, filename = "65502805_532.pair", open = "r") :
>  cannot open the connection
> In addition: Warning message:
> In unz(description = fn, filename = "65502805_532.pair", open = "r") :
(Continue reading)

Favicon

Re: question on simple graph

Without knowing more about what you are trying to accomplish, and what 
you have tried so far (code) it's difficult to say. But I'll venture 
this: are you sure you need a graph? Seems like a table might suffice.

BT <- sample(1:5, 50, replace=TRUE)
RA <- sample(1:5, 50, replace=TRUE)
table(BT)
table(RA)
dd <- data.frame(better <- BT, race=RA)
str(dd)
dd.table <- xtabs(~better+race, data=dd)

# doesn't this table convey what you want?
prop.table(dd.table,2)

# if for some reason a graph is essential, this creates one:
mosaicplot(dd.table)

Is this sort of what you had in mind?

--Chris Ryan
SUNY Upstate Medical University
Clinical Campus at Binghamton

Rebecca Lisi wrote:
> I am having trouble generating a graph.
>
> I want to know the % of respondents who answered that they "strongly
> agree" or "agree" the "America owes R's ethnic group a better chance"
> (BTTRCHNC) and I want to organize it by racial group (RACESHRT).
(Continue reading)

Matyas Sustik | 1 Feb 03:37
Picon

Makefile to compile .so in src (was: Re: automated libR location)

Prof Brian Ripley wrote:
> 'library' in R has a different meaning: I've altered the subject to be
> more accurate 'libR'.
>
> This is what R CMD SHLIB is for: it does all this for you in a portable way.
>
> But if you want to DIY, you can use R CMD config to find out the
> appropriate linker incantation.

Thank you for the clarification.  I do not insist on doing it myself
and would welcome
R doing it automatically.  I guess I did not fully understand the
instructions in the
document "R Extensions".  (English is my second language.)

A small example compiling a single .so would help greatly I think.  My
current Makefile
that I put in src of  a package skeleton looks like this to create the
.so on Linux:

all :  QUIC.so

OBJECTS = QUIC.o QUIC.so

PKG_LIBS = @LAPACK_LIBS@ @BLAS_LIBS@

QUIC.o : QUIC.cpp
       g++ -O3 -DNDEBUG -Wall -fpic -pthread -shared
-fno-omit-frame-pointer -ansi -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -c
QUIC.cpp -o QUIC.o
(Continue reading)

sjlabrie | 1 Feb 05:53
Picon
Favicon

Plotting bar graph over a geographical map

Hi, 

I am looking for a way to plot bar on a map instead of the standard points. 
I have been using ggplot2 and maps libraries. 
The points are added with the function geom_point. I know that there is a
function 
geom_bar but I can't figure out how to use it. 

Thank you for your help, 

Simon 

### R-code
library(ggplot2)
library(maps)

measurements <- read.csv("all_podo.count.csv", header=T)
allworld <- map_data("world")

pdf("map.pdf")
ggplot(measurements, aes(long, lat)) + 
 geom_polygon(data = allworld, aes(x = long, y = lat, group = group),
 colour = "grey70", fill = "grey70") +
 geom_point(aes(size = ref)) +
 opts(axis.title.x = theme_blank(), 
 axis.title.y = theme_blank()) +
 geom_bar(aes(y = normcount))  
dev.off()
###

(Continue reading)

Partha Sinha | 1 Feb 07:31
Picon

Optimisation

Can optimisation (simplex etc) be done through R?

Sally Luo | 1 Feb 07:49
Picon

Probit regression with limited parameter space

Dear R helpers,

I need to estimate a probit model with box constraints placed on several of
the model parameters.  I have the following two questions:

1) How are the standard errors calclulated in glm
(family=binomial(link="probit")?  I ran a typical probit model using the
glm probit link and the nlminb function with my own coding of the
loglikehood, separately. As nlminb does not produce the hessian matrix, I
used hessian (numDeriv) to calculate it.  However, the standard errors
calculated using hessian function are quite different from the ones
generated by the glm function, although the parameter estimates are very
close.  I was wondering what makes this difference in the estmation of
standard errors and how this computation is carried out in glm.

2) Does any one know how to estimate a constrained probit model in R (to be
specific, I need to restrain the range of three parameters to [-1,1])?
Among the optimation functions, so far nlminb and spg work for my problem,
but neither produces a hessian matrix.  As I mentioned above, if I use
hessian funciton and calculate standard errors manually, the standard
errors seem not right.

Many thanks in advance for your kind help.

Maomao

	[[alternative HTML version deleted]]

Jim Lemon | 1 Feb 08:20
Picon
Gravatar

Re: question on simple graph

On 02/01/2012 08:13 AM, Rebecca Lisi wrote:
> I am having trouble generating a graph.
>
> I want to know the % of respondents who answered that they "strongly
> agree" or "agree" the "America owes R's ethnic group a better chance"
> (BTTRCHNC) and I want to organize it by racial group (RACESHRT).
>
> "BTTRCHNC" is organized ordinally from 1 through 5 with 1=Strongly
> Agree, 5=Strongly Disagree
> "RACESHRT" is ordinally organized from 1 through 5 where each number
> represents a racial group category, i.e. white, black, Asian, etc.
>
> Any hints for how to proceed?
>
Hi Rebecca,
Let's say you have 100 respondents who are members of five racial groups:

r_ethnic<-data.frame(BTTRCHNC=sample(1:5,100,TRUE),
  RACESHRT=sample(LETTERS[1:5],100,TRUE))
library(prettyR)
r_ethnic.xtab<-xtab(BTTRCHNC~RACESHRT,r_ethnic)
Crosstabulation of BTTRCHNC by RACESHRT
         RACESHRT
...     A       B       C       D       E
1       4       3       4       6       5       22
         18.18   13.64   18.18   27.27   22.73    -
         22.22   13.04   21.05   28.57   26.32   22

2       3       3       3       1       3       13
         23.08   23.08   23.08   7.69    23.08    -
(Continue reading)

Picon

Problem with xtable- rescaling a table

Dear R users,
I am new to Latex and I am using the R package xtable to generate tables.
I want to produce a table that is very long.  in the landscape format, but
I would need to rescale the table so that it fits in the page. xtable
enables me to have the landscape format, but I cannot rescale it, and there
seems to be a problem, if I use scalebox in Latex on my output produced
with stable and the option sidewaystable. Do you know any way to achieve
this result with xtable or another R package?

Let's look at the following example:
In R, I use the following code

##############
outfile<- matrix(nrow=3, ncol=3)
outfile[2,1]<- 6.912
outfile[3,1]<- 400
outfile[2,2]<- 8.9722
outfile[2,2]<- 500
outfile[2,3]<- 4.00
outfile[3,3]<- 400

library(xtable)
outfile<- data.frame(outfile)
colnames(outfile)<- c(" ","V1", "V2")

outfile<- xtable(outfile, caption= "Title", include.rownames=F,
align=rep("c", 4), digit=2)
print(outfile, include.rownames=F, floating.environment='sidewaystable')
################

(Continue reading)

Jim Lemon | 1 Feb 09:12
Picon
Gravatar

Re: testing for temperature differences between years and sites?

On 01/31/2012 11:34 PM, swertie wrote:
> Hello!
>
> I have a dataset with monthly temperatures for 4 different years and I would
> like to test if they are significantly different between the years. As I
> collected the data for different sites I wondered if there were some
> possibility to perform the calculation at once or if I have to repeat it for
> each site.
>
> I tried like this:
>
> Model_Temp<- lmer(Temp ~Year + (1|Site)+(1|Month),na.action=na.omit, data=
> MeanTemp)
>
> But I am not sure at all if it is correct to put the sites as random factors
> or if I have to do the calculation for each site separately. I am not
> interested in correlation between sites, but only between years for each
> different site.
>
> Alternatively, can you indicate me some way to plot this?
>
Hi swertie,
Let's say you have monthly temperature readings for four sites:

mon_temp<-data.frame(site=rep(LETTERS[1:4],48),
  year=rep(2008:2011,each=48),month=rep(month.abb,each=4),
  temp=20+rnorm(192)+
  10*sin(rep(rep(seq(1.5*pi,3.5*pi,length.out=12),each=4,4))))

Having gotten some data, you can then display a line plot of the 
(Continue reading)


Gmane