[R] xyplot squeezed together

2011-12-04 Thread syrvn
Hi,


I created the following example of a xyplot. The plot actually looks ok
apart from that the

x-axis is pretty squeezed/clinched. I tried aspect=fill already but I want
to have all 3 sub plots

next to each other. I tried loads of different scaling varieties but with no
significant result...



library(lattice)

N - 6

d - data.frame(factor(rep(c(A1,A2,A3),each=N),
levels=c(A1,A2,A3)),

   factor(rep(c(B1, B2, B3, B4, B5, B6, B7, 
B8, B9),
each=N/3),

  levels=c(B1, B2, B3, B4, B5, B6, 
B7,
B8, B9)),

rep(c(0,1), each=N/3/2))

colnames(d) - c(ID, class, group)

value - matrix(c(400,300, 320,380, 410,500, 800,670, 810,900, 560,750,
1100,1200, 1200,1300, 1300,1200))

d - cbind(d, value)

xyplot(value ~ group | ID, d, groups = class, type = c(g, b),

  auto.key = list(lines = TRUE, columns = 3), xlab = blocked=0,
released=1,

  ylab = value, aspect = 'xy', scales=list(x=list(at=-1:2,
labels=c(,0,1,



Anyone any ideas how to enlarge the x-axis?

Cheers


--
View this message in context: 
http://r.789695.n4.nabble.com/xyplot-squeezed-together-tp4156661p4156661.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] Data Analysis for Gas Prices

2011-12-04 Thread John
On Sat, 3 Dec 2011 14:11:39 -0800 (PST)
inferno846 robe...@uoregon.edu wrote:

...
 
 Also, could anyone help me figure out how to import a data table to
 R? When I try to create a .txt file from a word document and read it
 in R, the format of the first column always messes up. Any/all help
 is appreciated.
 
For reading in data, avoid using Word, a program that is overkill for
almost all purposes.  Either use Notepad, or grab a simple text editor
off the internet - preferably capable of block selection.  

Since you do not say just how the first column messes up, it is
rather problematic trying suggest a solution the problem.  The first
line of the table and a couple data lines, the form of command you use
to read in the data and the field separator in your table are all useful
pieces of information. There are however a great many books about R out
there and nearly all of them address at least briefly how to import
data. Portland has one of the best bookstores on the planet.  As a last
resort you might try the command ??read.table from the R prompt.

JD

__
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] frequency table?

2011-12-04 Thread set
Hello R-users,

I've got a file with individuals as colums and the clusters where they occur
in as rows. And I wanted a table which tells me how many times each
individual occurs with another. I don't really know how such a table is
called...it is not a frequency tableMy eventual goal is to make
Venn-diagrams from the occurence of my individuals.

So I've this:

cluster   ind1 ind2 ind3 etc.
10  1 2
23   01
31   1 1

And I want to go to this:
ind1  ind2  ind3
ind1  0  42
ind2  4  04
ind3  2   4   1

is there a way to do this?
Thank you for your help


--
View this message in context: 
http://r.789695.n4.nabble.com/frequency-table-tp4156422p4156422.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] pivot table help

2011-12-04 Thread set
Thank you very much! works perfectly! 

--
View this message in context: 
http://r.789695.n4.nabble.com/pivot-table-help-tp4155144p4156393.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] density function always evaluating to zero

2011-12-04 Thread napps22
Sorry that was my poor copying and pasting. Here's the correct R code. The
problem does seem to be with the function I define as f.

# Model selection example in a bayesian framework
# two competiting non-nested models
# M0: y_t = alpha * x1^2 + e_t
# M1: y_t = beta * x1^4 + e_t
# where e_t ~ iidN(0,1)

#generate data

x1 - runif(100, min = -10, max = 10)
y - 2 * x1^2 + rnorm(100)
n - length(y)
k - 1
v - n - k

# want the posterior probabilities of the two models
# postprob_mj = p(y|model j true) * priorprob_mj / p(y)
# need to calculate the integral of p(y|alpha,h)p(alpha,h)
# and the integral of p(y|beta,h)p(beta,h)
# recall we chose p(alpha,h) = p(beta,h) = 1/h
# need to sample from the posterior to get an approximation of the integral

# # # # # # # # Model 0 # # # # # # # 

z - x1^2
M - sum(z^2)
MI - 1/M
zy - crossprod(z,y)
alpha.ols - MI * zy
resid_m0 - y - z * alpha.ols
s2_m0 - sum(resid_m0^2)/v

# set up gibbs sampler

nrDraws - 1
h_sample_m0 - rgamma(nrDraws, v/2, v*s2_m0/2) 
alpha_sample - matrix(0, nrow = nrDraws, ncol = 1)

for(i in 1:nrDraws) {

alpha_sample[i] - rnorm(1,alpha.ols,(1/h_sample_m0[i]) * MI)

}

# define posterior density for m0

f - function(alpha,h) {

e - y - alpha * x1^2
const - (2*pi)^(-n/2) / ( gamma(v/2) * (v*s2_m0/2)^(-v/2) )  
kernel - h^((v-1)/2) * exp((-(h/2) * sum(e^2)) - (v*s2_m0)*h)
x - const * kernel
return(x)
}

# calculate approximation of p(y|m_0)

m0 -f(alpha_sample,h_sample_m0)
post_m0 - sum(m0) / nrDraws



--
View this message in context: 
http://r.789695.n4.nabble.com/density-function-always-evaluating-to-zero-tp4155181p4156746.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 using the thin plate spline method

2011-12-04 Thread Mintewab Bezabih
Dear R users and Jeff, 

Sorry for not being quite explicit in my earlier message. My main problem is 
while my data seem to be read into R well (I manage to graph them and all), I 
cannot get the following line to work. 

tpsfit - Tps(cbind(x1, x2), y, scale.type=unscaled)

and I get the following error message

Error in as.matrix(x) : 
  error in evaluating the argument 'x' in selecting a method for function 
'as.matrix': Error: object 'x1' not found

thanks for help
minti

Från: Jeff Newmiller [jdnew...@dcn.davis.ca.us]
Skickat: den 3 december 2011 17:45
Till: Mintewab Bezabih; r-help@r-project.org
Ämne: Re: [R] problems using the thin plate spline method

I can tell that you are puzzled and confused. Unfortunately, I am not psychic, 
so I cannot tell what you did, and therefore cannot tell where you went astray.

The solution is for you to read the posting guide mentioned at the bottom of 
every R-help message. Spend a little time to create a small bit of data like 
yours if your actual data is large (subset and dput are useful for this). 
Remember to include the output of sessionInfo, and so on. Many times you are 
likely to find the answer yourself by going through these steps, but they are 
essential for communication.

Good luck.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

Mintewab Bezabih mintewab.beza...@economics.gu.se wrote:

Dear R users,

I am a beginner in R trying to apply the thin plate spline method to my
climate data. I used the example in R to do so, and the lines seem to
run fine ( I am not getting errors) but I am not getting any output in
the form of graph or anything. I got a warning message saying that
'surface extends beyond box'.

Any help is much appreciated.
thanks
minti
__
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 using the thin plate spline method

2011-12-04 Thread Sarah Goslee
Hello,

On Sun, Dec 4, 2011 at 8:08 AM, Mintewab Bezabih
mintewab.beza...@economics.gu.se wrote:
 Dear R users and Jeff,

 Sorry for not being quite explicit in my earlier message.

And you are still not explicit. We have no idea what you've done.

 My main problem is while my data seem to be read into R well (I manage to 
 graph them and all), I cannot get the following line to work.

 tpsfit - Tps(cbind(x1, x2), y, scale.type=unscaled)

 and I get the following error message

 Error in as.matrix(x) :
  error in evaluating the argument 'x' in selecting a method for function 
 'as.matrix': Error: object 'x1' not found

I'd have to guess that there's no object x1. What does ls() tell you? str(x1)?

What do your data look like? You were already given instructions on how to
include sample data to construct a reproducible example. You said that
graphing your data worked; how did you do so?

The posting guide and the advice you were already given were both
offered for a reason. The querent needs to do the work of formulating
an understandable and answerable question.

Sarah

 thanks for help
 minti
 
 Från: Jeff Newmiller [jdnew...@dcn.davis.ca.us]
 Skickat: den 3 december 2011 17:45
 Till: Mintewab Bezabih; r-help@r-project.org
 Ämne: Re: [R] problems using the thin plate spline method

 I can tell that you are puzzled and confused. Unfortunately, I am not 
 psychic, so I cannot tell what you did, and therefore cannot tell where you 
 went astray.

 The solution is for you to read the posting guide mentioned at the bottom of 
 every R-help message. Spend a little time to create a small bit of data like 
 yours if your actual data is large (subset and dput are useful for this). 
 Remember to include the output of sessionInfo, and so on. Many times you are 
 likely to find the answer yourself by going through these steps, but they are 
 essential for communication.

 Good luck.
 Sent from my phone. Please excuse my brevity.

 Mintewab Bezabih mintewab.beza...@economics.gu.se wrote:

Dear R users,

I am a beginner in R trying to apply the thin plate spline method to my
climate data. I used the example in R to do so, and the lines seem to
run fine ( I am not getting errors) but I am not getting any output in
the form of graph or anything. I got a warning message saying that
'surface extends beyond box'.

Any help is much appreciated.
thanks
minti


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] density function always evaluating to zero

2011-12-04 Thread Sarah Goslee
I didn't try out your extensive code, but here's one potentially serious
problem:

You only pass two arguments to f(), alpha and h, but within f you nonetheless
use x1 and y and several other things. This is bad practice, and dangerous:
you should pass all the necessary arguments to f(), not rely on the environment
to contain them.

After you fix that, working through your function step by step at the command
line and looking at the results of each line of code can be very educational.

Sarah

On Sun, Dec 4, 2011 at 7:47 AM, napps22 n.j.app...@gmail.com wrote:
 Sorry that was my poor copying and pasting. Here's the correct R code. The
 problem does seem to be with the function I define as f.

 # Model selection example in a bayesian framework
 # two competiting non-nested models
 # M0: y_t = alpha * x1^2 + e_t
 # M1: y_t = beta * x1^4 + e_t
 # where e_t ~ iidN(0,1)

 #generate data

 x1 - runif(100, min = -10, max = 10)
 y - 2 * x1^2 + rnorm(100)
 n - length(y)
 k - 1
 v - n - k

 # want the posterior probabilities of the two models
 # postprob_mj = p(y|model j true) * priorprob_mj / p(y)
 # need to calculate the integral of p(y|alpha,h)p(alpha,h)
 # and the integral of p(y|beta,h)p(beta,h)
 # recall we chose p(alpha,h) = p(beta,h) = 1/h
 # need to sample from the posterior to get an approximation of the integral

 # # # # # # # # Model 0 # # # # # # #

 z - x1^2
 M - sum(z^2)
 MI - 1/M
 zy - crossprod(z,y)
 alpha.ols - MI * zy
 resid_m0 - y - z * alpha.ols
 s2_m0 - sum(resid_m0^2)/v

 # set up gibbs sampler

 nrDraws - 1
 h_sample_m0 - rgamma(nrDraws, v/2, v*s2_m0/2)
 alpha_sample - matrix(0, nrow = nrDraws, ncol = 1)

 for(i in 1:nrDraws) {

        alpha_sample[i] - rnorm(1,alpha.ols,(1/h_sample_m0[i]) * MI)

        }

 # define posterior density for m0

 f - function(alpha,h) {

        e - y - alpha * x1^2
        const - (2*pi)^(-n/2) / ( gamma(v/2) * (v*s2_m0/2)^(-v/2) )
        kernel - h^((v-1)/2) * exp((-(h/2) * sum(e^2)) - (v*s2_m0)*h)
        x - const * kernel
        return(x)
        }

 # calculate approximation of p(y|m_0)

 m0 -f(alpha_sample,h_sample_m0)
 post_m0 - sum(m0) / nrDraws




-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] xyplot squeezed together

2011-12-04 Thread Sarah Goslee
You specified the aspect ratio, so your plots must have that ratio
of width to height.

It looks like you are trying to control layout by specifying aspect
ratio? That, as you've discovered, is an ineffective way to do it.

Instead, you should specify layout directly, using for your example
layout=c(3,1,1)
and deleting the aspect='xy' argument.

Rereading the help for xyplot()  more carefully would also be a good
idea.

Sarah

On Sun, Dec 4, 2011 at 6:49 AM, syrvn ment...@gmx.net wrote:
 Hi,


 I created the following example of a xyplot. The plot actually looks ok
 apart from that the

 x-axis is pretty squeezed/clinched. I tried aspect=fill already but I want
 to have all 3 sub plots

 next to each other. I tried loads of different scaling varieties but with no
 significant result...



 library(lattice)

 N - 6

 d - data.frame(factor(rep(c(A1,A2,A3),each=N),
 levels=c(A1,A2,A3)),

                       factor(rep(c(B1, B2, B3, B4, B5, B6, B7, 
 B8, B9),
 each=N/3),

                                  levels=c(B1, B2, B3, B4, B5, B6, 
 B7,
 B8, B9)),

                                    rep(c(0,1), each=N/3/2))

 colnames(d) - c(ID, class, group)

 value - matrix(c(400,300, 320,380, 410,500, 800,670, 810,900, 560,750,
 1100,1200, 1200,1300, 1300,1200))

 d - cbind(d, value)

 xyplot(value ~ group | ID, d, groups = class, type = c(g, b),

          auto.key = list(lines = TRUE, columns = 3), xlab = blocked=0,
 released=1,

          ylab = value, aspect = 'xy', scales=list(x=list(at=-1:2,
 labels=c(,0,1,



 Anyone any ideas how to enlarge the x-axis?

 Cheers




-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] RODBC connect to Excel (64-bit Windows 7)

2011-12-04 Thread andrija djurovic
Hi to all.
 I have a problem to connect to an Excel database using RODBC.
Namely, I am using 64-bit R 2.14.0, under Windows 7 and I tried following:
library(RODBC)
 channel - odbcConnectExcel(results.xlsx)
Error in odbcConnectExcel(results.xlsx) :
  odbcConnectExcel is only usable with 32-bit Windows   # ok this is
clear why it doesn't work
 channel - odbcConnectExcel2007(results.xlsx) # this was
one of proposals from old R help posts, but it doesn't work for me
Warning messages:
1: In odbcDriverConnect(con, tabQuote = c([, ]), ...) :
  [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect(con, tabQuote = c([, ]), ...) :
  ODBC connection failed

After that as it suggested in R data import/export manual I
installed AccessDatabaseEngine.exe. Also I used ODBC in
c:\Windows\SysWOW64\odbcad32 to create data source called result. I check
if it is created:
 odbcDataSources()
 dBASE Files
   Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)
  MS Access Database
  Microsoft Access Driver (*.mdb, *.accdb)
  Excel file
Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)
* results*
Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)

and tried again but it doesn't work:

 channel - odbcDriverConnect()
Warning messages:
1: In odbcDriverConnect() :
  [RODBC] ERROR: state IM014, code 0, message [Microsoft][ODBC Driver
Manager] The specified DSN contains an architecture mismatch between the
Driver and Application
2: In odbcDriverConnect() : ODBC connection failed


Could someone guide me what should I try next to fix a problem? Is this
some problem with Drivers or not?

Thanks in advance

Andrija

[[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] LaTeX output for summary.lm object - while displaying the information outside the table

2011-12-04 Thread Tal Galili
This seemed to me to be basic, but I can't seem to find a solution online,
so I wondered what I might be missing.

I wish to include the output of an lm summary object inside an Sweave
(.Rnw) document. I can either output the summary.lm as is, or use the
xtable/Hmisc packages (through xtable or latex commands).

Is there something like xtable that also gives the summary information
which is available from outside the table? (

R2, F statistics etc...?)
Thanks.


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[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] Programming Statistical Functions

2011-12-04 Thread B77S
As Stephen pointed out, this is easy to do.  The word file the OP posted has
all the necessary formulae.  Now you just need to learn how to convert those
formulae into R functions
Stephen gave you an example of how to create a function for CV.  Now run
with it.

perhaps something like this is what you need:

http://cran.r-project.org/doc/contrib/Short-refcard.pdf

It is time for you to do some reading on your own.

Good luck.



gvjones wrote
 
 Hello,
 
 Did you find anything helpful for calculating the statistical functions in
 your list. I would like to also calculate these and have been looking for
 some code to do so.
 
 Thanks
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Programming-Statistical-Functions-tp2307880p4157101.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] Vectorization instead of loops problem

2011-12-04 Thread Costas Vorlow
Hello,

I am having problems vectorizing the following (i/o using a for/next/while
loop):

I have 2 sequences such as:

x, y
1, 30
2, -40
0, 50
0, 25
1, -5
2, -10
1, 5
0, 40

etc etc

The first sequence (x) takes integer numbers only: 0, 1, 2
The sequence y can be anything...

I want to be able to retrieve (in a list if possible) the 3 last values of
the y sequence before a value of 1 is encountered on the x sequence, i.e:

On line 5 in the above dataset, x is 1 so I need to capture values: 25, 50
and -40 of the y sequence.

So the outcome (if a list) should look something like:

[1],[25,50,-40]
[2],[-10,-5,25] # as member #7 of x sequence is 1...

etc. etc.

Can I do the above avoiding for/next or while loops?
I am not sure I can explain it better. Any help/pointer extremely welcome.

Best regards,
Costas


-- 

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

[[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] Polishing my geom_bar for publication

2011-12-04 Thread Aurelie Cosandey Godin
Dear list,

I am new with ggplot2 and I have spend quiet some time putting together the 
following code to create the attached plot. However there's still a few things 
that I'm having trouble with!
I would be grateful if someone can tell me how to fix (1) the colour of my bars 
into grey scales (2) removing the y-axis (species name) on the right figure to 
avoid duplication, and (3) fix the width, such that both figures have the same 
apparence regardless of the legend.

Thank you very much in advance!


The code is as follow:


(a-ggplot(Final2, aes(x=spp, y=CPUE, fill=season)) + 
geom_bar(position=position_dodge()) + 
geom_errorbar(aes(ymin=CPUE-cpue.se, ymax=CPUE+cpue.se),
  size=.3,  
  width=.2,
  position=position_dodge(.9)) +
xlab(Species) +  
scale_x_discrete(breaks=c(100,102,107,88,90,91,92,93,94,96,98,99),
 labels=c(WINTER,SPINYTAIL,BIGELOW'S,SKATES 
(NS),THORNY,SMOOTH,ABYSSAL,LITTLE,DEEPWATER,JENSEN'S,WHITE,SOFT))
 + 
ylab(Abundance (fish/tow))  + coord_flip() +
theme_bw() + opts(axis.title.x = theme_text(size = 10)) + 
opts(panel.grid.minor = theme_blank()) + opts(legend.position='none') )

(b-ggplot(Final2, aes(x=spp, y=WPUE, fill=season)) + 
geom_bar(position=position_dodge()) +  
geom_errorbar(aes(ymin=WPUE-wpue.se, ymax=WPUE+wpue.se),
  size=.3,  
  width=.2,
  position=position_dodge(.9)) + xlab(NULL)+  
scale_x_discrete(breaks=c(100,102,107,88,90,91,92,93,94,96,98,99),
 labels=c(WINTER,SPINYTAIL,BIGELOW'S,SKATES 
(NS),THORNY,SMOOTH,ABYSSAL,LITTLE,DEEPWATER,JENSEN'S,WHITE,SOFT))+
ylab(Biomass (Weight (kg)/tow)) + scale_fill_hue(name=Survey season, # 
Legend label, use darker colors
   breaks=c(summer, winter),
   labels=c(Spring, Fall)) + coord_flip() +
theme_bw() + opts(axis.title.x = theme_text(size = 10)) + 
opts(panel.grid.minor = theme_blank()))

pdf(polishing-layout2.pdf, width = 10, height = 6)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))
vplayout - function(x, y)
  viewport(layout.pos.row = x, layout.pos.col = y)
print(a, vp = vplayout(1, 1))
print(b, vp = vplayout(1, 2))
dev.off()


Aurelie Cosandey-Godin
Ph.D. student, Department of Biology
Industrial Graduate Fellow, WWF-Canada

Dalhousie University | Biology Dept. | 1459 Oxford Street |Halifax, NS | Canada 
B3H 4R2  
Phone: 1-902-494-2478 | cell: 1-902-412-3404 |Fax: 1-902-494-3736 
Email: god...@dal.ca | Skype: aureliegodinco | Web: wormlab.biology.dal.ca

Want to learn more about sharks in Atlantic Canada? Visit ShARCC! 
www.atlanticsharks.org












__
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] Vectorization instead of loops problem

2011-12-04 Thread Uwe Ligges



On 04.12.2011 16:18, Costas Vorlow wrote:

Hello,

I am having problems vectorizing the following (i/o using a for/next/while
loop):

I have 2 sequences such as:

x, y
1, 30
2, -40
0, 50
0, 25
1, -5
2, -10
1, 5
0, 40

etc etc

The first sequence (x) takes integer numbers only: 0, 1, 2
The sequence y can be anything...

I want to be able to retrieve (in a list if possible) the 3 last values of
the y sequence before a value of 1 is encountered on the x sequence, i.e:

On line 5 in the above dataset, x is 1 so I need to capture values: 25, 50
and -40 of the y sequence.

So the outcome (if a list) should look something like:

[1],[25,50,-40]
[2],[-10,-5,25] # as member #7 of x sequence is 1...

etc. etc.

Can I do the above avoiding for/next or while loops?
I am not sure I can explain it better. Any help/pointer extremely welcome.

Best regards,
Costas




One way is (assuming your data is in a data.frame called dat):

 wx - which(dat$x==1)
 result - lapply(wx[wx  3], function(x) dat$y[x - (1:3)])

(where lapply is a loop, implicitly).


Uwe Ligges

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


[R] Linear quadratic Gaussian control with Kalman filter

2011-12-04 Thread nserdar
I need to generate Linear quadratic Gaussian control with Kalman filter in R
programming. I only get matlab code. I think that R portfolio optimisation
code ( quad..)  is not adequate for this topic. 

Linear quadratic Gaussian control  with Kalman filter 


http://en.wikipedia.org/wiki/Linear_quadratic_Gaussian_control  


Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/Linear-quadratic-Gaussian-control-with-Kalman-filter-tp4156813p4156813.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] Extract last 3 characters from numeric vector

2011-12-04 Thread Kang Min
Hi all,

I have a numeric vector with 1 decimal place, and I'd like to extract
the last 3 characters, including the decimal point. The vector ranges
from 0 to 20.

x - round(runif(100)*20, digits=1)

Some of numbers have 3 characters, and some have 4. I've read up on
the substr() function but that extracts characters based on exact
positions. How can I extract just the last 3 characters no matter the
length of the number? e.g. from 16.7 I want 6.7, from 3.5 I want 3.5
as it is.

Thanks,
Kang Min

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


[R] problem merging data with different shapes

2011-12-04 Thread Miriam
I have been trying to merge datasets, one of which has a long format (Adata) 
and one has a (different) long format (Bdata):

Adata  Bdata
subject order bpm  subject order trial agegroup gender
1 1   70.21  1 3   2   1
1 1   69.51  2 1   2   1
1 1   68.81  3 2   2   1
1 2   69.12  1 2   1   2
1 270 2  2 3   1   2
1 2   70.52  3 1   1   2
1 3   70.2...
1 3
1 3
2 1 
2 1 
...   ...

In the end I would like to have a dataset that contains A unchanged with the 
additional information from B added.

subject order bpm trial agegroup gender
1 1   70.2  3   2   1
1 1   69.5  3   2   1
1 1   68.8  3   2   1
...  
I have tried:
newdataframe - merge(Adata,Bdata, by= c(subject, order), sort = FALSE)

For some reason, the trial column is not matched to the subject and order 
information, despite them being identified as key-variables for the merge. (The 
same is true for other variables, the actual dataset has more variables and 
trials, but this is essentially the problem.)
So it results in something like:
subject order bpm trial agegroup gender
1 1   70.2  3   2   1
1 1   69.5  2   2   1
1 1   68.8  1   2   1 

What could be my mistake?

Thank you VERY much.
Miriam


-- 




--

__
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] Programming Statistical Functions

2011-12-04 Thread gvjones
Hello,

Did you find anything helpful for calculating the statistical functions in
your list. I would like to also calculate these and have been looking for
some code to do so.

Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/Programming-Statistical-Functions-tp2307880p4157012.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] Extract last 3 characters from numeric vector

2011-12-04 Thread Sarah Goslee
You can use nchar() to get the length of the string, and use that in
substring:

mynum - as.character(15.6)

 substring(mynum, nchar(mynum)-2, nchar(mynum))
[1] 5.6

On Sun, Dec 4, 2011 at 8:38 AM, Kang Min ngokang...@gmail.com wrote:
 Hi all,

 I have a numeric vector with 1 decimal place, and I'd like to extract
 the last 3 characters, including the decimal point. The vector ranges
 from 0 to 20.

 x - round(runif(100)*20, digits=1)

 Some of numbers have 3 characters, and some have 4. I've read up on
 the substr() function but that extracts characters based on exact
 positions. How can I extract just the last 3 characters no matter the
 length of the number? e.g. from 16.7 I want 6.7, from 3.5 I want 3.5
 as it is.

 Thanks,
 Kang Min

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] upper bound in the integrate function depends on a parameter

2011-12-04 Thread e eeyore
This is not homework, I calculate some expectations and to finish that I
must solve integral like this one..
Upper bound have some unknown parameter, but I dont know how to write it in
R.

Do I must define m like symbol, or something else, just need help with that.
I know how this work in MatLab, but in R I have problem.
Is there any solution how to solve integral like this one?

Can you help me please little more or direct me to right way, I will
appreciate your effort.

Thanks


On Sun, Dec 4, 2011 at 6:06 AM, David Winsemius dwinsem...@comcast.netwrote:


 On Dec 3, 2011, at 10:23 PM, grttt nbbfg wrote:

  Sorry for my English, is not my first language..

 I have some trouble in terms of using integrate function in R.
 fx is a function of m and x where m is supposed to be a unknown parameter.


 R is not an algebraic solver (and R-help is not a homework list.).



  fx=function(m,x){

 + x*2/(3*m)*(1-x/(3*m))
 + }

 The problem is in upper bound, it depends on parameter m.

  integrate(fx,lower=0,upper=3***m)$value


 Is it possible to use the integrate function when bounds depend on a
 parameter?


 If it is known, yes. You could also do some investigation:

 curve(x*2/(3*5)*(1-x/(3*5)), 0, 15)



 How to define m to solve this integral? The result should be m.


 As I said, no homework answers here.


[[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] Vectorization instead of loops problem

2011-12-04 Thread Costas Vorlow
Thanks Uwe.

What happens if these are zoo (or time series) sequences/dataframes?
\
I think your solution would apply as well, no?

Thanks again  best wishes,
Costas

2011/12/4 Uwe Ligges lig...@statistik.tu-dortmund.de



 On 04.12.2011 16:18, Costas Vorlow wrote:

 Hello,

 I am having problems vectorizing the following (i/o using a for/next/while
 loop):

 I have 2 sequences such as:

 x, y
 1, 30
 2, -40
 0, 50
 0, 25
 1, -5
 2, -10
 1, 5
 0, 40

 etc etc

 The first sequence (x) takes integer numbers only: 0, 1, 2
 The sequence y can be anything...

 I want to be able to retrieve (in a list if possible) the 3 last values of
 the y sequence before a value of 1 is encountered on the x sequence, i.e:

 On line 5 in the above dataset, x is 1 so I need to capture values: 25, 50
 and -40 of the y sequence.

 So the outcome (if a list) should look something like:

 [1],[25,50,-40]
 [2],[-10,-5,25] # as member #7 of x sequence is 1...

 etc. etc.

 Can I do the above avoiding for/next or while loops?
 I am not sure I can explain it better. Any help/pointer extremely welcome.

 Best regards,
 Costas



 One way is (assuming your data is in a data.frame called dat):

  wx - which(dat$x==1)
  result - lapply(wx[wx  3], function(x) dat$y[x - (1:3)])

 (where lapply is a loop, implicitly).


 Uwe Ligges




-- 

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

[[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] Complex multiple t tests in a data frame with several id factors

2011-12-04 Thread Kaiyin Zhong
I have assayed the concentrations of various metal elements in
different anatomic regions of two strains of mice. Now, for each
element, in each region, I want to do a t test to find whether there
is any difference between the two strains.

Here is what I did (using simulated data as an example):

# create the data frame
 elemconc = data.frame(expand.grid(id=1:3, geno=c('exp', 'wt'), 
 region=c('brain', 'spine'), elem=c('fe', 'cu', 'zn')), conc=rnorm(36, 10))
 elemconc
   id geno region elem  conc
1   1  exp  brain   fe  8.497498
2   2  exp  brain   fe  9.280944
3   3  exp  brain   fe  9.726271
4   1   wt  brain   fe 11.556397
5   2   wt  brain   fe 10.992550
6   3   wt  brain   fe  9.711200
7   1  exp  spine   fe 11.168603
8   2  exp  spine   fe  9.331127
9   3  exp  spine   fe 11.048226
10  1   wt  spine   fe  8.480867
11  2   wt  spine   fe  8.887062
12  3   wt  spine   fe  8.329797
13  1  exp  brain   cu 10.242652
14  2  exp  brain   cu  9.865984
15  3  exp  brain   cu  9.163728
16  1   wt  brain   cu 11.099385
17  2   wt  brain   cu  9.364261
18  3   wt  brain   cu  9.718322
19  1  exp  spine   cu 10.720157
20  2  exp  spine   cu 11.505430
21  3  exp  spine   cu  9.499359
22  1   wt  spine   cu  9.855950
23  2   wt  spine   cu 10.120489
24  3   wt  spine   cu  9.526252
25  1  exp  brain   zn  9.736196
26  2  exp  brain   zn 11.938710
27  3  exp  brain   zn  9.668625
28  1   wt  brain   zn  9.961574
29  2   wt  brain   zn 10.461621
30  3   wt  brain   zn  9.873667
31  1  exp  spine   zn  9.708067
32  2  exp  spine   zn 10.109309
33  3  exp  spine   zn 10.973387
34  1   wt  spine   zn  8.406536
35  2   wt  spine   zn  7.797746
36  3   wt  spine   zn 11.127984

# use tapply to aggregate
 tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) x)
region
elem brain spine
  fe Numeric,6 Numeric,6
  cu Numeric,6 Numeric,6
  zn Numeric,6 Numeric,6

# check whether the order of data has been preserved after aggregation
 x['fe', 'brain']
[[1]]
[1]  8.497498  9.280944  9.726271 11.556397 10.992550  9.711200

# create an external factor for strain grouping
 tmpgeno = rep(c('exp', 'wt'), each=3)
 tmpgeno
[1] exp exp exp wt  wt  wt

# do the t test using the grouping factor
 x = tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) 
 t.test(x~tmpgeno) )
 x
region
elem brain  spine
  fe List,9 List,9
  cu List,9 List,9
  zn List,9 List,9

I believe I have made no mistakes so far, but I wonder is there a
better way of doing this?


-- 
Kaiyin Zhong
--
Neuroscience Research Institute, Peking University, Beijing, P.R.China 100038

__
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] Vectorization instead of loops problem

2011-12-04 Thread Gabor Grothendieck
On Sun, Dec 4, 2011 at 10:18 AM, Costas Vorlow costas.vor...@gmail.com wrote:
 Hello,

 I am having problems vectorizing the following (i/o using a for/next/while
 loop):

 I have 2 sequences such as:

 x, y
 1, 30
 2, -40
 0, 50
 0, 25
 1, -5
 2, -10
 1, 5
 0, 40

 etc etc

 The first sequence (x) takes integer numbers only: 0, 1, 2
 The sequence y can be anything...

 I want to be able to retrieve (in a list if possible) the 3 last values of
 the y sequence before a value of 1 is encountered on the x sequence, i.e:

 On line 5 in the above dataset, x is 1 so I need to capture values: 25, 50
 and -40 of the y sequence.

 So the outcome (if a list) should look something like:

 [1],[25,50,-40]
 [2],[-10,-5,25] # as member #7 of x sequence is 1...

 etc. etc.

 Can I do the above avoiding for/next or while loops?
 I am not sure I can explain it better. Any help/pointer extremely welcome.

Try this. embed(z, 4) places values 1,2,3,4 of vector z in the first
row, values 2,3,4,5 in the second row and so on so we want the rows of
embed(y, 4) for which embed(x, 4) is 1, i.e we want rows of embed(y,
4) for which embed(x, 4)[,1]==1, except the first column can be
suppressed (-1).

 embed(y, 4)[embed(x, 4)[, 1] == 1, -1]
 [,1] [,2] [,3]
[1,]   25   50  -40
[2,]  -10   -5   25

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

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


Re: [R] Extract last 3 characters from numeric vector

2011-12-04 Thread Uwe Ligges



On 04.12.2011 14:38, Kang Min wrote:

Hi all,

I have a numeric vector with 1 decimal place, and I'd like to extract
the last 3 characters, including the decimal point. The vector ranges
from 0 to 20.

x- round(runif(100)*20, digits=1)



formatC(round(x%%10, 1), format=f, digits=1)

Uwe Ligges



Some of numbers have 3 characters, and some have 4. I've read up on
the substr() function but that extracts characters based on exact
positions. How can I extract just the last 3 characters no matter the
length of the number? e.g. from 16.7 I want 6.7, from 3.5 I want 3.5
as it is.

Thanks,
Kang Min

__
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] Vectorization instead of loops problem

2011-12-04 Thread Bert Gunter
Costas: (and thanks for giving us your name)

which(x == 1)

gives you the indices where x is 1 (up to floating point equality --
you did not specify whether your x values are integers or calculated
as floating point, and that certainly makes a difference). You can
then use simple indexing to get the y values. No loops needed.

However, let's explore why your question may have been too poorly
formed to get the answer you seek:

1. What if the index of the first 1 is 3 or less? -- Do you want to
ignore the (less than 3) preceding values or just choose as many as
you can?

2. What if, as in your example, several 1's occur in x. Do you want
the 3 preceding values for all of them or just the first?

3. If the answer to 2 is all of them, what if several 1's are less
than 3 indices apart -- do you want to include the overlapping sets of
3 y's -- or what?

My point is that etc. etc. is simply inadequate as a coherent or
useful problem description in your post. You _must_ be explicit,
complete, and concise. This can be hard. Indeed, it may require
considerable thought and effort. I have found -- and others have often
noted here -- that going through such an exercise itself often reveals
a solution. But be that as it may, the Posting Guide is actually an
excellent, comprehensive discussion of how to ask good questions in
forums like this. Read it. Follow it.

... and to be fair, your post below is, imho, probably above average
as posts go, allowing me to focus on specific points that I thought
required clarification. Quite a few posts here of late have been so
muddled and incoherent that I had no clue what the OP wanted. And it's
not English as a second language. I am a language ignoramus and speak
only English, so I am happy to tolerate poor grammar and vocabulary
from someone for whom English is only one of several languages in
which they can communicate. The problem is poor thinking, not poor
English.

Best,
Bert

On Sun, Dec 4, 2011 at 7:18 AM, Costas Vorlow costas.vor...@gmail.com wrote:
 Hello,

 I am having problems vectorizing the following (i/o using a for/next/while
 loop):

 I have 2 sequences such as:

 x, y
 1, 30
 2, -40
 0, 50
 0, 25
 1, -5
 2, -10
 1, 5
 0, 40

 etc etc

 The first sequence (x) takes integer numbers only: 0, 1, 2
 The sequence y can be anything...

 I want to be able to retrieve (in a list if possible) the 3 last values of
 the y sequence before a value of 1 is encountered on the x sequence, i.e:

 On line 5 in the above dataset, x is 1 so I need to capture values: 25, 50
 and -40 of the y sequence.

 So the outcome (if a list) should look something like:

 [1],[25,50,-40]
 [2],[-10,-5,25] # as member #7 of x sequence is 1...

 etc. etc.

 Can I do the above avoiding for/next or while loops?
 I am not sure I can explain it better. Any help/pointer extremely welcome.

 Best regards,
 Costas


 --

 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

        [[alternative HTML version deleted]]

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


Re: [R] upper bound in the integrate function depends on a parameter

2011-12-04 Thread David Winsemius

On Dec 4, 2011, at 9:52 AM, e eeyore wrote:

 This is not homework, I calculate some expectations and to finish  
 that I must solve integral like this one..
 Upper bound have some unknown parameter, but I dont know how to  
 write it in R.

You almost did write it in R. You just left the m unspecified. If  
you replace m by 5 the code works.

 Do I must define m like symbol, or something else, just need help  
 with that.
 I know how this work in MatLab, but in R I have problem.
 Is there any solution how to solve integral like this one?

 Can you help me please little more or direct me to right way, I will  
 appreciate your effort.

 Thanks


 On Sun, Dec 4, 2011 at 6:06 AM, David Winsemius dwinsem...@comcast.net 
  wrote:

 On Dec 3, 2011, at 10:23 PM, grttt nbbfg wrote:

 Sorry for my English, is not my first language..

 I have some trouble in terms of using integrate function in R.
 fx is a function of m and x where m is supposed to be a unknown  
 parameter.

 R is not an algebraic solver (and R-help is not a homework list.).



 fx=function(m,x){
 + x*2/(3*m)*(1-x/(3*m))
 + }

 The problem is in upper bound, it depends on parameter m.

 integrate(fx,lower=0,upper=3*m)$value

 Is it possible to use the integrate function when bounds depend on a
 parameter?

 If it is known, yes. You could also do some investigation:

 curve(x*2/(3*5)*(1-x/(3*5)), 0, 15)



 How to define m to solve this integral? The result should be m.

 As I said, no homework answers here.


David Winsemius, MD
West Hartford, CT


[[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] Logistic Regression with genetic component

2011-12-04 Thread Ben Bolker
Danielle Duncan dlduncan2 at alaska.edu writes:

 Greetings, I have a question that I'd like to get input on. I have a
 classic toxicology study where I artificially fertilized and exposed
 embryos to a chemical and counted defects. In addition, I kept track of
 male-female pairs that I used to artificially fertilize and generate
 embryos with. I need to use logistic regression to model the response, but
 also check that the genetics of the pairings did or did not have an effect
 on the response. My data looks a bit like this:
 
 response matrix chemical concentration  Genetic Matrix
 Present AbsentMale Female
 2 152   0.13 a 1
 6 121  1 a 2
 21 92  2 b 3
 24 89  5 b 4
 0141 10 c 5
 5 95 15 c  6
 
 R code:
 
 DA-cbind(Present, Absent)
 glm-(DA ~ chemical concentration)
 
 If I do glm-(DA ~ chemical concentration + Male + Female, I get every
 possible combination, but I only want specific pairs. So, I am thinking
 about doing:
 
 MF-cbind(Male, Female)
 glm-(DA ~ chemical concentration + MF)


You're on the right track.  paste() is probably what
you want, although you can also use interaction() to
get the interactions and then droplevels() to get
rid of the unobserved crosses.

d - read.table(textConnection(
Present Absent   conc   Male Female
2 152   0.13 a 1
6 121  1 a 2
21 92  2 b 3
24 89  5 b 4
0141 10 c 5
5 95 15 c  6),
header=TRUE)

Either of these should give you what you want:
  
d - droplevels(transform(d,cross=interaction(Male,Female)))
levels(d$cross)

d - transform(d,cross=paste(Male,Female,sep=.))
levels(d$cross)

You should be a little careful -- if each cross is exposed
only to a single concentration, and if you treat cross as
a fixed effect, you will overparameterize your model.  If
you treat it as a random effect, e.g. using glmer in the
lme4 package:

glmer(cbind(Present,Absent)~conc+(1|cross),data=d)

you will effectively be fitting a model for overdispersion
(see the example in ?cbpp).

__
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] Complex multiple t tests in a data frame with several id factors

2011-12-04 Thread Bert Gunter
The concentrations of the different metals within an animal are
correlated, so that doing as you suggest will almost certainly result
in nonsense P values. So I suggest you seek local statistical help or,
failing that, post on a statistical forum like stats.stackexchange.com
 .

There are  various multivariate packages -- check e.g. the ChemPhys
and Multivariate task views -- that may be pertinent, but your post
suggests that you probably need some help to use them. Ergo my
suggestion above.

Cheers,
Bert

On Sun, Dec 4, 2011 at 7:36 AM, Kaiyin Zhong kindlych...@gmail.com wrote:
 I have assayed the concentrations of various metal elements in
 different anatomic regions of two strains of mice. Now, for each
 element, in each region, I want to do a t test to find whether there
 is any difference between the two strains.

 Here is what I did (using simulated data as an example):

 # create the data frame
 elemconc = data.frame(expand.grid(id=1:3, geno=c('exp', 'wt'), 
 region=c('brain', 'spine'), elem=c('fe', 'cu', 'zn')), conc=rnorm(36, 10))
 elemconc
   id geno region elem      conc
 1   1  exp  brain   fe  8.497498
 2   2  exp  brain   fe  9.280944
 3   3  exp  brain   fe  9.726271
 4   1   wt  brain   fe 11.556397
 5   2   wt  brain   fe 10.992550
 6   3   wt  brain   fe  9.711200
 7   1  exp  spine   fe 11.168603
 8   2  exp  spine   fe  9.331127
 9   3  exp  spine   fe 11.048226
 10  1   wt  spine   fe  8.480867
 11  2   wt  spine   fe  8.887062
 12  3   wt  spine   fe  8.329797
 13  1  exp  brain   cu 10.242652
 14  2  exp  brain   cu  9.865984
 15  3  exp  brain   cu  9.163728
 16  1   wt  brain   cu 11.099385
 17  2   wt  brain   cu  9.364261
 18  3   wt  brain   cu  9.718322
 19  1  exp  spine   cu 10.720157
 20  2  exp  spine   cu 11.505430
 21  3  exp  spine   cu  9.499359
 22  1   wt  spine   cu  9.855950
 23  2   wt  spine   cu 10.120489
 24  3   wt  spine   cu  9.526252
 25  1  exp  brain   zn  9.736196
 26  2  exp  brain   zn 11.938710
 27  3  exp  brain   zn  9.668625
 28  1   wt  brain   zn  9.961574
 29  2   wt  brain   zn 10.461621
 30  3   wt  brain   zn  9.873667
 31  1  exp  spine   zn  9.708067
 32  2  exp  spine   zn 10.109309
 33  3  exp  spine   zn 10.973387
 34  1   wt  spine   zn  8.406536
 35  2   wt  spine   zn  7.797746
 36  3   wt  spine   zn 11.127984

 # use tapply to aggregate
 tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) x)
    region
 elem brain     spine
  fe Numeric,6 Numeric,6
  cu Numeric,6 Numeric,6
  zn Numeric,6 Numeric,6

 # check whether the order of data has been preserved after aggregation
 x['fe', 'brain']
 [[1]]
 [1]  8.497498  9.280944  9.726271 11.556397 10.992550  9.711200

 # create an external factor for strain grouping
 tmpgeno = rep(c('exp', 'wt'), each=3)
 tmpgeno
 [1] exp exp exp wt  wt  wt

 # do the t test using the grouping factor
 x = tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) 
 t.test(x~tmpgeno) )
 x
    region
 elem brain  spine
  fe List,9 List,9
  cu List,9 List,9
  zn List,9 List,9

 I believe I have made no mistakes so far, but I wonder is there a
 better way of doing this?


 --
 Kaiyin Zhong
 --
 Neuroscience Research Institute, Peking University, Beijing, P.R.China 100038

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


Re: [R] upper bound in the integrate function depends on a parameter

2011-12-04 Thread e eeyore
On Sun, Dec 4, 2011 at 4:47 PM, David Winsemius dwinsem...@comcast.netwrote:


 You almost did write it in R. You just left the m unspecified. If you
 replace m by 5 the code works.


Check how wolfram work with same integral, I dont need to replace anything..
http://www.wolframalpha.com/input/?i=integrate+x*2%2F%283*m%29*%281-x%2F%283*m%29%29+dx+from+x%3D0+to+3*m

I need only answer is possible in R do the same work and get the same
result and if is how.

You dont need to try be funny..

[[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] Complex multiple t tests in a data frame with several id factors

2011-12-04 Thread Kaiyin Zhong
Okay, thank you.

On Mon, Dec 5, 2011 at 12:01 AM, Bert Gunter gunter.ber...@gene.com wrote:
 The concentrations of the different metals within an animal are
 correlated, so that doing as you suggest will almost certainly result
 in nonsense P values. So I suggest you seek local statistical help or,
 failing that, post on a statistical forum like stats.stackexchange.com
  .

 There are  various multivariate packages -- check e.g. the ChemPhys
 and Multivariate task views -- that may be pertinent, but your post
 suggests that you probably need some help to use them. Ergo my
 suggestion above.

 Cheers,
 Bert

 On Sun, Dec 4, 2011 at 7:36 AM, Kaiyin Zhong kindlych...@gmail.com wrote:
 I have assayed the concentrations of various metal elements in
 different anatomic regions of two strains of mice. Now, for each
 element, in each region, I want to do a t test to find whether there
 is any difference between the two strains.

 Here is what I did (using simulated data as an example):

 # create the data frame
 elemconc = data.frame(expand.grid(id=1:3, geno=c('exp', 'wt'), 
 region=c('brain', 'spine'), elem=c('fe', 'cu', 'zn')), conc=rnorm(36, 10))
 elemconc
   id geno region elem      conc
 1   1  exp  brain   fe  8.497498
 2   2  exp  brain   fe  9.280944
 3   3  exp  brain   fe  9.726271
 4   1   wt  brain   fe 11.556397
 5   2   wt  brain   fe 10.992550
 6   3   wt  brain   fe  9.711200
 7   1  exp  spine   fe 11.168603
 8   2  exp  spine   fe  9.331127
 9   3  exp  spine   fe 11.048226
 10  1   wt  spine   fe  8.480867
 11  2   wt  spine   fe  8.887062
 12  3   wt  spine   fe  8.329797
 13  1  exp  brain   cu 10.242652
 14  2  exp  brain   cu  9.865984
 15  3  exp  brain   cu  9.163728
 16  1   wt  brain   cu 11.099385
 17  2   wt  brain   cu  9.364261
 18  3   wt  brain   cu  9.718322
 19  1  exp  spine   cu 10.720157
 20  2  exp  spine   cu 11.505430
 21  3  exp  spine   cu  9.499359
 22  1   wt  spine   cu  9.855950
 23  2   wt  spine   cu 10.120489
 24  3   wt  spine   cu  9.526252
 25  1  exp  brain   zn  9.736196
 26  2  exp  brain   zn 11.938710
 27  3  exp  brain   zn  9.668625
 28  1   wt  brain   zn  9.961574
 29  2   wt  brain   zn 10.461621
 30  3   wt  brain   zn  9.873667
 31  1  exp  spine   zn  9.708067
 32  2  exp  spine   zn 10.109309
 33  3  exp  spine   zn 10.973387
 34  1   wt  spine   zn  8.406536
 35  2   wt  spine   zn  7.797746
 36  3   wt  spine   zn 11.127984

 # use tapply to aggregate
 tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) x)
    region
 elem brain     spine
  fe Numeric,6 Numeric,6
  cu Numeric,6 Numeric,6
  zn Numeric,6 Numeric,6

 # check whether the order of data has been preserved after aggregation
 x['fe', 'brain']
 [[1]]
 [1]  8.497498  9.280944  9.726271 11.556397 10.992550  9.711200

 # create an external factor for strain grouping
 tmpgeno = rep(c('exp', 'wt'), each=3)
 tmpgeno
 [1] exp exp exp wt  wt  wt

 # do the t test using the grouping factor
 x = tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) 
 t.test(x~tmpgeno) )
 x
    region
 elem brain  spine
  fe List,9 List,9
  cu List,9 List,9
  zn List,9 List,9

 I believe I have made no mistakes so far, but I wonder is there a
 better way of doing this?


 --
 Kaiyin Zhong
 --
 Neuroscience Research Institute, Peking University, Beijing, P.R.China 100038

 __
 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



-- 
Kaiyin Zhong
--
Neuroscience Research Institute, Peking University, Beijing, P.R.China 100038

__
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] Programming Statistical Functions

2011-12-04 Thread David Winsemius


On Dec 4, 2011, at 9:27 AM, gvjones wrote:


Hello,

Did you find anything helpful for calculating the statistical  
functions in
your list. I would like to also calculate these and have been  
looking for

some code to do so.



A search at the site linked by the R function RSiteSearch() produces  
two (or more) candidate packages. Rather than naming them, I think it  
good exercise to do the looking and judging by yourself:


http://search.r-project.org/cgi-bin/namazu.cgi?query=meteorologymax=100result=normalsort=scoreidxname=functionsidxname=Rhelp08idxname=Rhelp10idxname=Rhelp02

--

David Winsemius, MD
West Hartford, CT

__
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] upper bound in the integrate function depends on a parameter

2011-12-04 Thread David Winsemius

On Dec 4, 2011, at 11:04 AM, e eeyore wrote:



 On Sun, Dec 4, 2011 at 4:47 PM, David Winsemius dwinsem...@comcast.net 
  wrote:

 You almost did write it in R. You just left the m unspecified. If  
 you replace m by 5 the code works.

 Check how wolfram work with same integral, I dont need to replace  
 anything..
 http://www.wolframalpha.com/input/?i=integrate+x*2%2F%283*m%29*%281-x%2F%283*m%29%29+dx+from+x%3D0+to+3*m

 I need only answer is possible in R do the same work and get the  
 same result and if is how.

 You dont need to try be funny..


Sometimes my sarcasm is under-interpreted, but in this case no sarcasm  
was intended. I told you in an earlier post that R does not do  
symbolic algebra. Your counter-example points to a program that does.  
Bottom line: R is not Mathematica. Complaining about that fact is not  
going to get you anywhere. There is a package which provides an  
interface to the open-source Yacas system if you want to pursue an R- 
centric approach.

-- 

David Winsemius, MD
West Hartford, CT


[[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] prediction in conmode class of Nonparametric binary models

2011-12-04 Thread shyam basnet
Dear R users,

Is it possible to apply 'predict' to an object of class conmode? 

Could you please suggest me any applicable method for 'predict' for the 
conmode class?

Thanking you,

Sincerely Yours,

Shyam Kumar Basnet
SLU, Uppsala
Sweden
[[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] upper bound in the integrate function depends on a parameter

2011-12-04 Thread e eeyore
I know that is not Mhatematica, my question is only is it possible, it
seams its not..

Sorry if I did not get it, I can interprete different your answer, not
intentionally..

Thanks for your answer and patience.


On Sun, Dec 4, 2011 at 5:15 PM, David Winsemius dwinsem...@comcast.netwrote:


 On Dec 4, 2011, at 11:04 AM, e eeyore wrote:



 On Sun, Dec 4, 2011 at 4:47 PM, David Winsemius dwinsem...@comcast.netwrote:


 You almost did write it in R. You just left the m unspecified. If you
 replace m by 5 the code works.


 Check how wolfram work with same integral, I dont need to replace
 anything..

 http://www.wolframalpha.com/input/?i=integrate+x*2%2F%283*m%29*%281-x%2F%283*m%29%29+dx+from+x%3D0+to+3*m

 I need only answer is possible in R do the same work and get the same
 result and if is how.

 You dont need to try be funny..


 Sometimes my sarcasm is under-interpreted, but in this case no sarcasm was
 intended. I told you in an earlier post that R does not do symbolic
 algebra. Your counter-example points to a program that does. Bottom line: R
 is not Mathematica. Complaining about that fact is not going to get you
 anywhere. There is a package which provides an interface to the open-source
 Yacas system if you want to pursue an R-centric approach.

 --


 David Winsemius, MD
 West Hartford, CT



[[alternative HTML version deleted]]

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


[R] How to write (complex) coercion methods or what's the reason to limit 'setAs()' the way it is limited?

2011-12-04 Thread Janko Thyson

Dear list,

I'd like to write coercion methods for some of my Reference Classes. 
However, using 'setAs()' is not a real option as its argument 'def' only 
allows for functions depending on one single argument. In some cases, 
that is simply too much of a limitation for me. And I don't really see 
why it needs to be this way, so I guess this question is also some sort 
of a feature request to make 'setAs' a bit more flexible (in case anyone 
from the Core Team is listening ;-))


A reproducible example can be found here: 
http://stackoverflow.com/questions/8346654/how-to-write-coercion-methods


Thanks a lot for any replies!
Janko

__
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] upper bound in the integrate function depends on a parameter

2011-12-04 Thread Jorge I Velez
Hi e eeyore,

Here is one way:

fx - function(x, m) x*2/(3*m)*(1-x/(3*m))
foo - function(m) integrate(fx, m = m, lower = 0, upper = 3*m)$value
foo(3)
# 3
foo(2)
# 2

And remember:

#install.packages('fortunes')
require(fortunes)
fortune('Yoda')

Evelyn Hall: I would like to know how (if) I can extract some of the
information
from the summary of my nlme.
Simon Blomberg: This is R. There is no if. Only how.
   -- Evelyn Hall and Simon 'Yoda' Blomberg
  R-help (April 2005)

HTH,
Jorge.-


On Sun, Dec 4, 2011 at 11:23 AM, e eeyore  wrote:

 I know that is not Mhatematica, my question is only is it possible, it
 seams its not..

 Sorry if I did not get it, I can interprete different your answer, not
 intentionally..

 Thanks for your answer and patience.


 On Sun, Dec 4, 2011 at 5:15 PM, David Winsemius wrote:

 
  On Dec 4, 2011, at 11:04 AM, e eeyore wrote:
 
 
 
  On Sun, Dec 4, 2011 at 4:47 PM, David Winsemius wrote:
 
 
  You almost did write it in R. You just left the m unspecified. If you
  replace m by 5 the code works.
 
 
  Check how wolfram work with same integral, I dont need to replace
  anything..
 
 
 http://www.wolframalpha.com/input/?i=integrate+x*2%2F%283*m%29*%281-x%2F%283*m%29%29+dx+from+x%3D0+to+3*m
 
  I need only answer is possible in R do the same work and get the same
  result and if is how.
 
  You dont need to try be funny..
 
 
  Sometimes my sarcasm is under-interpreted, but in this case no sarcasm
 was
  intended. I told you in an earlier post that R does not do symbolic
  algebra. Your counter-example points to a program that does. Bottom
 line: R
  is not Mathematica. Complaining about that fact is not going to get you
  anywhere. There is a package which provides an interface to the
 open-source
  Yacas system if you want to pursue an R-centric approach.
 
  --
 
 
  David Winsemius, MD
  West Hartford, CT
 
 

[[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] problem merging data with different shapes

2011-12-04 Thread B77S
Please use dput() to post your example data sets.

dput(Adata)
dput(Bdata)

**then copy and paste the results of each so that we can play around with
it easily.




Miriam -2 wrote
 
 I have been trying to merge datasets, one of which has a long format
 (Adata) and one has a (different) long format (Bdata):
 
 Adata  Bdata
 subject order bpm  subject order trial agegroup gender
 1 1   70.21  1 3   2   1
 1 1   69.51  2 1   2   1
 1 1   68.81  3 2   2   1
 1 2   69.12  1 2   1   2
 1 270 2  2 3   1   2
 1 2   70.52  3 1   1   2
 1 3   70.2...
 1 3
 1 3
 2 1 
 2 1 
 ...   ...
 
 In the end I would like to have a dataset that contains A unchanged with
 the additional information from B added.
 
 subject order bpm trial agegroup gender
 1 1   70.2  3   2   1
 1 1   69.5  3   2   1
 1 1   68.8  3   2   1
 ...  
 I have tried:
 newdataframe - merge(Adata,Bdata, by= c(subject, order), sort =
 FALSE)
 
 For some reason, the trial column is not matched to the subject and order
 information, despite them being identified as key-variables for the merge.
 (The same is true for other variables, the actual dataset has more
 variables and trials, but this is essentially the problem.)
 So it results in something like:
 subject order bpm trial agegroup gender
 1 1   70.2  3   2   1
 1 1   69.5  2   2   1
 1 1   68.8  1   2   1 
 
 What could be my mistake?
 
 Thank you VERY much.
 Miriam
 
 
 -- 
 
 
 
 
 --
 
 __
 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.
 


--
View this message in context: 
http://r.789695.n4.nabble.com/problem-merging-data-with-different-shapes-tp4157137p4157442.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] Polishing my geom_bar for publication

2011-12-04 Thread Aurelie Cosandey Godin
Sorry Dennis,
Didn't realized I went off the list!
I found a solution for one of my problem: removing x-axis label!

with this code: ggplot(Final2, aes(x=spp, y=WPUE, fill=season)) + 
geom_bar(position=position_dodge()) + geom_errorbar(aes(ymin=WPUE-wpue.se, 
ymax=WPUE+wpue.se),  size=.3,width=.2,position=position_dodge(.9)) + 
scale_x_discrete(, breaks=c(102,90,91,94,96), labels= rep(, 5)) + 
ylab(Biomass (Weight (kg)/tow)) + scale_fill_grey(name=Survey season, 
breaks=c(summer, winter), labels=c(Spring, Fall))+ coord_flip() + 
theme_bw() + opts(axis.title.x = theme_text(size = 10), panel.grid.minor = 
theme_blank())

However, I am still trying to figure out how to fix the width of my two plots 
on my final pdf. I would appreciate any help on this! Thank you.



On 2011-12-04, at 12:59 PM, Aurelie Cosandey Godin wrote:

 Thank you Denis,
 
 I changed my code as you suggested, however the xlab didn't work  I tried 
 something else (see below my new code), but I still get my labels for my 
 x-axis (coord_flip) in my b figure (spp 96, 94, 91, etc...). See figure 
 below.
 To answer your question, I would like that both of my figure a  b have the 
 same width on the final pdf. Right now they aren't because of the legend.
 
 and (3) fix the width, such that both figures
 have the same appearance regardless of the legend.
 
 I'm afraid I don't understand clearly what you mean my 'same
 appearance'. Could you provide a reproducible example, which includes
 (possibly fake) data as well as code?
 
 
 
 Here's my new code:
 
 (a- ggplot(Final2, aes(x=spp, y=CPUE, fill=season)) +
 geom_bar(position=position_dodge()) +
 geom_errorbar(aes(ymin=CPUE-cpue.se, ymax=CPUE+cpue.se),
  size=.3,width=.2,
 position=position_dodge(.9)) +scale_x_discrete(Species,
 breaks=c(102,90,91,94,96),
 labels=c(SPINYTAIL,THORNY,SMOOTH,DEEPWATER,JENSEN'S)) + 
 ylab(Abundance (fish/tow))  + coord_flip() +
  scale_fill_grey() + theme_bw() + opts(axis.title.x =
 theme_text(size = 10), panel.grid.minor = theme_blank(),
 legend.position='none') )
 
 ##I added scale_x_discrete(NULL, breaks=c(102,90,91,94,96), labels= 
 rep(NULL, 5)) thinking that this would be able to remove my x-axis label 
 (coord_flip) but it didn't... any other ideas of how I can achieve this?
 
 (b- ggplot(Final2, aes(x=spp, y=WPUE, fill=season)) + 
 geom_bar(position=position_dodge()) + geom_errorbar(aes(ymin=WPUE-wpue.se, 
 ymax=WPUE+wpue.se),  size=.3,width=.2,position=position_dodge(.9)) + 
 scale_x_discrete(NULL, breaks=c(102,90,91,94,96), labels= rep(NULL, 
 5)) + ylab(Biomass (Weight (kg)/tow)) + scale_fill_grey(name=Survey 
 season, breaks=c(summer, winter), labels=c(Spring, Fall))+ 
 coord_flip() + theme_bw() + opts(axis.title.x = theme_text(size = 10), 
 panel.grid.minor = theme_blank()) )
 
 pdf(polishing-layout3.pdf, width = 10, height = 6)
 grid.newpage()
 pushViewport(viewport(layout = grid.layout(1, 2)))
 vplayout - function(x, y)
  viewport(layout.pos.row = x, layout.pos.col = y)
 print(a, vp = vplayout(1, 1))
 print(b, vp = vplayout(1, 2))
 dev.off()
 
 PastedGraphic-2.pdf
 
 Thank you very much!
 Aurelie
 
 On 2011-12-04, at 11:33 AM, Dennis Murphy wrote:
 
 Hi:
 
 On Sun, Dec 4, 2011 at 5:21 AM, Aurelie Cosandey Godin god...@dal.ca wrote:
 Dear list,
 
 I am new with ggplot2 and I have spend quiet some time putting together the
 following code to create the attached plot. However there's still a few
 things that I'm having trouble with!
 I would be grateful if someone can tell me how to fix (1) the colour of my
 bars into grey scales
 
 One way is to provide greyscale values to scale_fill_discrete; e.g.,
values = c(grey50,grey20)
 
 (2) removing the y-axis (species name) on the right
 figure to avoid duplication,
 
 In the second figure, insert either
   ylab()
 or if you have a labs() statement that defines several titles at once,
   labs(..., y = , ...)
 
 and (3) fix the width, such that both figures
 have the same appearance regardless of the legend.
 
 I'm afraid I don't understand clearly what you mean my 'same
 appearance'. Could you provide a reproducible example, which includes
 (possibly fake) data as well as code?
 
 Dennis
 
 Thank you very much in advance!
 
 --
 You received this message because you are subscribed to the ggplot2 mailing
 list.
 Please provide a reproducible example: http://gist.github.com/270442
 
 To post: email ggpl...@googlegroups.com
 To unsubscribe: email ggplot2+unsubscr...@googlegroups.com
 More options: http://groups.google.com/group/ggplot2
 
 
 The code is as follow:
 
 
 (a-ggplot(Final2, aes(x=spp, y=CPUE, fill=season)) +
geom_bar(position=position_dodge()) +
geom_errorbar(aes(ymin=CPUE-cpue.se, ymax=CPUE+cpue.se),
  size=.3,
  width=.2,
  position=position_dodge(.9)) +
xlab(Species) +
 scale_x_discrete(breaks=c(100,102,107,88,90,91,92,93,94,96,98,99),
 labels=c(WINTER,SPINYTAIL,BIGELOW'S,SKATES
 

Re: [R] Export cols to single csv files

2011-12-04 Thread B77S
just use indexing.
without doing it all for you...

df - structure(list(AA = c(0.3, 0.1, 0.6), BB = c(0.9, 0.4, 0.2), 
CC = c(1, 0.8, 0.6), DD = c(0.7, 0.5, 0.5)), .Names = c(AA, 
BB, CC, DD), class = data.frame, row.names = c(NA, -3L
))

write.csv(df[,1], paste(colnames(df[1]), csv, sep=.))




Chega wrote
 
 Hi
 
 I am trying to batch export the columns of a numeric matrix to separate
 csv files by naming them according to the column names.
 
 So my matrix in R looks like this:
  AA   BB   CC   DD   etc.
 1:  0.3  0.9  1.0   0.7  ...
 2:  0.1  0.4  0.8   0.5  ...
 3:  0.6  0.2  0.6   0.5  ...
 etc. 
 
 Now I am looking for a way to get these files (file names in quotes):
 
 AA.csv  BB.csv CC.csvetc.
 1:  0.31: 0.91: 1.0
 2:  0.12: 0.42: 0.8 
 3:  0.63: 0.23: 0.6
 etc.   etc.   etc.
 
 As I understand this may be done using write.csv and a loop with the
 column names, but I have no idea how to export single columns.
 
 Thanks i.a. for help!
 Chega
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Export-cols-to-single-csv-files-tp4157484p4157537.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] Vectorization instead of loops problem

2011-12-04 Thread Costas Vorlow
Dear Bert,

You are right (obviously).

Apologies for any inconvenience caused.  I thought my problem was
simplistic with a very obvious answer which eluded me.

As per your justified questions :

2: Answer is all,

hence:

3. would be include overlapping set (I guess) but this does not matter for
the time being. I didn't give it too much thought admittedly... If I got 1
 2 right I could have modified the code for point 3 (if answer in 2 !=
all'), so I did not consider it when I was formulating my query. However,
I can see now why this is confusing.

Anyways, thanks again for the pointers.

BTW, is there a good  quick read/guide on vectorization in R that one
could recommend? That would minimize my queries at least in the list. :-)

Apologies again and best regards,
Costas

On 4 December 2011 17:45, Bert Gunter gunter.ber...@gene.com wrote:

 Costas: (and thanks for giving us your name)

 which(x == 1)

 gives you the indices where x is 1 (up to floating point equality --
 you did not specify whether your x values are integers or calculated
 as floating point, and that certainly makes a difference). You can
 then use simple indexing to get the y values. No loops needed.

 However, let's explore why your question may have been too poorly
 formed to get the answer you seek:

 1. What if the index of the first 1 is 3 or less? -- Do you want to
 ignore the (less than 3) preceding values or just choose as many as
 you can?

 2. What if, as in your example, several 1's occur in x. Do you want
 the 3 preceding values for all of them or just the first?

 3. If the answer to 2 is all of them, what if several 1's are less
 than 3 indices apart -- do you want to include the overlapping sets of
 3 y's -- or what?

 My point is that etc. etc. is simply inadequate as a coherent or
 useful problem description in your post. You _must_ be explicit,
 complete, and concise. This can be hard. Indeed, it may require
 considerable thought and effort. I have found -- and others have often
 noted here -- that going through such an exercise itself often reveals
 a solution. But be that as it may, the Posting Guide is actually an
 excellent, comprehensive discussion of how to ask good questions in
 forums like this. Read it. Follow it.

 ... and to be fair, your post below is, imho, probably above average
 as posts go, allowing me to focus on specific points that I thought
 required clarification. Quite a few posts here of late have been so
 muddled and incoherent that I had no clue what the OP wanted. And it's
 not English as a second language. I am a language ignoramus and speak
 only English, so I am happy to tolerate poor grammar and vocabulary
 from someone for whom English is only one of several languages in
 which they can communicate. The problem is poor thinking, not poor
 English.

 Best,
 Bert

 On Sun, Dec 4, 2011 at 7:18 AM, Costas Vorlow costas.vor...@gmail.com
 wrote:
  Hello,
 
  I am having problems vectorizing the following (i/o using a
 for/next/while
  loop):
 
  I have 2 sequences such as:
 
  x, y
  1, 30
  2, -40
  0, 50
  0, 25
  1, -5
  2, -10
  1, 5
  0, 40
 
  etc etc
 
  The first sequence (x) takes integer numbers only: 0, 1, 2
  The sequence y can be anything...
 
  I want to be able to retrieve (in a list if possible) the 3 last values
 of
  the y sequence before a value of 1 is encountered on the x sequence, i.e:
 
  On line 5 in the above dataset, x is 1 so I need to capture values: 25,
 50
  and -40 of the y sequence.
 
  So the outcome (if a list) should look something like:
 
  [1],[25,50,-40]
  [2],[-10,-5,25] # as member #7 of x sequence is 1...
 
  etc. etc.
 
  Can I do the above avoiding for/next or while loops?
  I am not sure I can explain it better. Any help/pointer extremely
 welcome.
 
  Best regards,
  Costas
 
 
  --
 
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
 [[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




-- 

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

[[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] equating approximate values

2011-12-04 Thread vamshi999
Hello List, 

I am having trouble finding the command for my problem. 

I have two arrays x and y. now i would like to compare the values of x and y
and then get the index of x which is exactly or approximately equal(+/- some
value ) to the values in y.
 x - runif(100,min=0,max=5)
 y - runif(10,min=0,max=5)


the threshold value(+/-) value can vary. for this example lets take it to be
.5

I know the regular method of doing this by writing different if and for
loops. But i have very big dataframe the computation time is very high for
this method. can anyone please tell me if there any functions to do this. 

thank you for your help. 

--
View this message in context: 
http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4157551.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] similarity matrix

2011-12-04 Thread set
Hello R-users,

I've got a file with individuals as colums and the clusters where they occur
in as rows. And I wanted a similarity matrix which tells me how many times
each individual occurs with another. My eventual goal is to make
Venn-diagrams from the occurence of my individuals.

So I've this:

cluster   ind1 ind2 ind3 etc.
10  1 2
23   01
31   1 1

And I want to go to this:
ind1  ind2  ind3
ind1  0  42
ind2  4  04
ind3  2   4   1

is there a way to do this?
Thank you for your help 

--
View this message in context: 
http://r.789695.n4.nabble.com/similarity-matrix-tp4157576p4157576.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] RODBC connect to Excel (64-bit Windows 7)

2011-12-04 Thread R. Michael Weylandt michael.weyla...@gmail.com
Do you need to use RODBC specifically? I've been using XLConnect quite a lot 
recently and have been quite pleased with it. 

Michael

On Dec 4, 2011, at 9:40 AM, andrija djurovic djandr...@gmail.com wrote:

 Hi to all.
 I have a problem to connect to an Excel database using RODBC.
 Namely, I am using 64-bit R 2.14.0, under Windows 7 and I tried following:
 library(RODBC)
 channel - odbcConnectExcel(results.xlsx)
 Error in odbcConnectExcel(results.xlsx) :
  odbcConnectExcel is only usable with 32-bit Windows   # ok this is
 clear why it doesn't work
 channel - odbcConnectExcel2007(results.xlsx) # this was
 one of proposals from old R help posts, but it doesn't work for me
 Warning messages:
 1: In odbcDriverConnect(con, tabQuote = c([, ]), ...) :
  [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
 Manager] Data source name not found and no default driver specified
 2: In odbcDriverConnect(con, tabQuote = c([, ]), ...) :
  ODBC connection failed
 
 After that as it suggested in R data import/export manual I
 installed AccessDatabaseEngine.exe. Also I used ODBC in
 c:\Windows\SysWOW64\odbcad32 to create data source called result. I check
 if it is created:
 odbcDataSources()
 dBASE Files
   Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)
  MS Access Database
  Microsoft Access Driver (*.mdb, *.accdb)
  Excel file
 Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)
* results*
 Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)
 
 and tried again but it doesn't work:
 
 channel - odbcDriverConnect()
 Warning messages:
 1: In odbcDriverConnect() :
  [RODBC] ERROR: state IM014, code 0, message [Microsoft][ODBC Driver
 Manager] The specified DSN contains an architecture mismatch between the
 Driver and Application
 2: In odbcDriverConnect() : ODBC connection failed
 
 
 Could someone guide me what should I try next to fix a problem? Is this
 some problem with Drivers or not?
 
 Thanks in advance
 
 Andrija
 
[[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] RODBC connect to Excel (64-bit Windows 7)

2011-12-04 Thread andrija djurovic
Hi. Not specifically, but I used it before with 32-bit R under Windows XP
and it worked just fine so i though to keep using it.Anyway I will lookt at
XLConnect.
Thank you for suggestion.
Andrija

On Sun, Dec 4, 2011 at 7:41 PM, R. Michael Weylandt 
michael.weyla...@gmail.com michael.weyla...@gmail.com wrote:

 Do you need to use RODBC specifically? I've been using XLConnect quite a
 lot recently and have been quite pleased with it.

 Michael

 On Dec 4, 2011, at 9:40 AM, andrija djurovic djandr...@gmail.com wrote:

  Hi to all.
  I have a problem to connect to an Excel database using RODBC.
  Namely, I am using 64-bit R 2.14.0, under Windows 7 and I tried
 following:
  library(RODBC)
  channel - odbcConnectExcel(results.xlsx)
  Error in odbcConnectExcel(results.xlsx) :
   odbcConnectExcel is only usable with 32-bit Windows   # ok this is
  clear why it doesn't work
  channel - odbcConnectExcel2007(results.xlsx) # this was
  one of proposals from old R help posts, but it doesn't work for me
  Warning messages:
  1: In odbcDriverConnect(con, tabQuote = c([, ]), ...) :
   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
  Manager] Data source name not found and no default driver specified
  2: In odbcDriverConnect(con, tabQuote = c([, ]), ...) :
   ODBC connection failed
 
  After that as it suggested in R data import/export manual I
  installed AccessDatabaseEngine.exe. Also I used ODBC in
  c:\Windows\SysWOW64\odbcad32 to create data source called result. I check
  if it is created:
  odbcDataSources()
  dBASE Files
Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)
   MS Access Database
   Microsoft Access Driver (*.mdb, *.accdb)
   Excel file
  Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)
 * results*
  Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)
 
  and tried again but it doesn't work:
 
  channel - odbcDriverConnect()
  Warning messages:
  1: In odbcDriverConnect() :
   [RODBC] ERROR: state IM014, code 0, message [Microsoft][ODBC Driver
  Manager] The specified DSN contains an architecture mismatch between the
  Driver and Application
  2: In odbcDriverConnect() : ODBC connection failed
 
 
  Could someone guide me what should I try next to fix a problem? Is this
  some problem with Drivers or not?
 
  Thanks in advance
 
  Andrija
 
 [[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] equating approximate values

2011-12-04 Thread andrija djurovic
Hi. Maybe this can help you (you can try additionally to incorporate
threshold):

 set.seed(1)
 x-rnorm(10,10,1)
 values - sample(1:10,10)  #values that we are looking for
 mat - matrix(c(x,values),ncol=2)

 closest-function(x,values)#function is an example from The R book
(Crawley)
+ {
+ x[which(abs(x-values)==min(abs(x-values)))]
+ }

 apply(mat[,2,drop=FALSE],1,function(y) closest(mat[,1],y))
 [1] 10.183643  9.164371  9.164371  9.164371  9.164371  9.164371  9.164371
 9.164371
 [9]  9.164371  9.164371


On Sun, Dec 4, 2011 at 7:00 PM, vamshi999 vamshi...@gmail.com wrote:

 Hello List,

 I am having trouble finding the command for my problem.

 I have two arrays x and y. now i would like to compare the values of x and
 y
 and then get the index of x which is exactly or approximately equal(+/-
 some
 value ) to the values in y.
  x - runif(100,min=0,max=5)
  y - runif(10,min=0,max=5)


 the threshold value(+/-) value can vary. for this example lets take it to
 be
 .5

 I know the regular method of doing this by writing different if and for
 loops. But i have very big dataframe the computation time is very high for
 this method. can anyone please tell me if there any functions to do this.

 thank you for your help.

 --
 View this message in context:
 http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4157551.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.


[[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] similarity matrix

2011-12-04 Thread B77S
I apologize to the list and you if I am mis-understanding something, but...

As an example:
ind2 occurs with ind1 only in cluster#3, so why does it get a value of 4 in
your similarity matrix?

Also, if this isn't a recognized similarity algorithm, perhaps you should at
the very least put quotes around similarity.  

Again, sorry if I am confused here.
 


set wrote
 
 Hello R-users,
 
 I've got a file with individuals as colums and the clusters where they
 occur in as rows. And I wanted a similarity matrix which tells me how many
 times each individual occurs with another. My eventual goal is to make
 Venn-diagrams from the occurence of my individuals.
 
 So I've this:
 
 cluster   ind1 ind2 ind3 etc.
 10  1 2
 23   01
 31   1 1
 
 And I want to go to this:
 ind1  ind2  ind3
 ind1  0  42
 ind2  4  04
 ind3  2   4   1
 
 is there a way to do this?
 Thank you for your help
 


--
View this message in context: 
http://r.789695.n4.nabble.com/similarity-matrix-tp4157576p4157840.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] Vectorization instead of loops problem

2011-12-04 Thread Bert Gunter
Inline below

On Sun, Dec 4, 2011 at 10:29 AM, Costas Vorlow costas.vor...@gmail.com wrote:
 Dear Bert,

 You are right (obviously).

 Apologies for any inconvenience caused.  I thought my problem was simplistic
 with a very obvious answer which eluded me.

 As per your justified questions :

 2: Answer is all,

 hence:

 3. would be include overlapping set (I guess) but this does not matter for
 the time being. I didn't give it too much thought admittedly... If I got 1 
 2 right I could have modified the code for point 3 (if answer in 2 !=
 all'), so I did not consider it when I was formulating my query. However, I
 can see now why this is confusing.

 Anyways, thanks again for the pointers.

 BTW, is there a good  quick read/guide on vectorization in R that one could
 recommend? That would minimize my queries at least in the list. :-)

Vectorization is a central paradigm in R, so practically all books on
the S language discuss this. The R language definition manual that
ships with R is pretty comprehensive, but VR's MASS or S Programming
Books, Patrick Burns's website tutorials (he has several well suited
for beginners), John Chambers's  Programming with R  , etc. are just
a few among many. It is impossible for me to be more specific than
that.

-- Bert

 Apologies again and best regards,
 Costas

 On 4 December 2011 17:45, Bert Gunter gunter.ber...@gene.com wrote:

 Costas: (and thanks for giving us your name)

 which(x == 1)

 gives you the indices where x is 1 (up to floating point equality --
 you did not specify whether your x values are integers or calculated
 as floating point, and that certainly makes a difference). You can
 then use simple indexing to get the y values. No loops needed.

 However, let's explore why your question may have been too poorly
 formed to get the answer you seek:

 1. What if the index of the first 1 is 3 or less? -- Do you want to
 ignore the (less than 3) preceding values or just choose as many as
 you can?

 2. What if, as in your example, several 1's occur in x. Do you want
 the 3 preceding values for all of them or just the first?

 3. If the answer to 2 is all of them, what if several 1's are less
 than 3 indices apart -- do you want to include the overlapping sets of
 3 y's -- or what?

 My point is that etc. etc. is simply inadequate as a coherent or
 useful problem description in your post. You _must_ be explicit,
 complete, and concise. This can be hard. Indeed, it may require
 considerable thought and effort. I have found -- and others have often
 noted here -- that going through such an exercise itself often reveals
 a solution. But be that as it may, the Posting Guide is actually an
 excellent, comprehensive discussion of how to ask good questions in
 forums like this. Read it. Follow it.

 ... and to be fair, your post below is, imho, probably above average
 as posts go, allowing me to focus on specific points that I thought
 required clarification. Quite a few posts here of late have been so
 muddled and incoherent that I had no clue what the OP wanted. And it's
 not English as a second language. I am a language ignoramus and speak
 only English, so I am happy to tolerate poor grammar and vocabulary
 from someone for whom English is only one of several languages in
 which they can communicate. The problem is poor thinking, not poor
 English.

 Best,
 Bert

 On Sun, Dec 4, 2011 at 7:18 AM, Costas Vorlow costas.vor...@gmail.com
 wrote:
  Hello,
 
  I am having problems vectorizing the following (i/o using a
  for/next/while
  loop):
 
  I have 2 sequences such as:
 
  x, y
  1, 30
  2, -40
  0, 50
  0, 25
  1, -5
  2, -10
  1, 5
  0, 40
 
  etc etc
 
  The first sequence (x) takes integer numbers only: 0, 1, 2
  The sequence y can be anything...
 
  I want to be able to retrieve (in a list if possible) the 3 last values
  of
  the y sequence before a value of 1 is encountered on the x sequence,
  i.e:
 
  On line 5 in the above dataset, x is 1 so I need to capture values: 25,
  50
  and -40 of the y sequence.
 
  So the outcome (if a list) should look something like:
 
  [1],[25,50,-40]
  [2],[-10,-5,25] # as member #7 of x sequence is 1...
 
  etc. etc.
 
  Can I do the above avoiding for/next or while loops?
  I am not sure I can explain it better. Any help/pointer extremely
  welcome.
 
  Best regards,
  Costas
 
 
  --
 
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
         [[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:

 

[R] Group several variables and apply a function to the group

2011-12-04 Thread Aurélien PHILIPPOT
Dear R-experts,
I am struggling with the following problem, and I am looking for advice
from more experienced R-users: I have a data frame with 2 identifying
variables (comn and mi), and an output variable (x). comn is a variable for
a company and mi is a variable for a month.

comn-c(abc, abc, abc, abc, abc, abc, xyz, xyz,xyz, xyz)
mi- c(1, 1,1, 2, 2, 2, 1, 1, 3, 3)
x- c(-0.0031, 0.0009, -0.007, 0.1929,0.0087, 0.099,-0.089,
0.005, -0.0078, 0.67 )
df- data.frame(comn=comn, mi=mi, x=x)


For each company, within a particular month, I would like to compute the
standard deviation of x: for example, for abc, I would like to compute the
sd of x for month1 (when mi=1) and for month2 (when mi=2).

In other languages (Stata for instance), I would create a grouping variable
(group comnn and mi) and then, apply the sd function for each group.

However, I don't find an elegant way to do the same in R:

I was thinking about the following: I could subset my data frame by mi and
create one file per month, and then make a loop and in each file, use a
by operator for each comn. I am sure it would work, but I feel that it
would be like killing an ant with a tank.

I was wondering if anyone knew a more straightforward way to implement that
kind of operation?

Thanks a lot,

Best,
Aurelien

[[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] Group several variables and apply a function to the group

2011-12-04 Thread Felipe Carrillo
 Like this?
library(plyr)
ddply(df,.(comn,mi),summarise,stDEV=sd(x))

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx


From: Aurélien PHILIPPOT aurelien.philip...@gmail.com
To: R-help@r-project.org 
Sent: Sunday, December 4, 2011 12:32 PM
Subject: [R] Group several variables and apply a function to the group

Dear R-experts,
I am struggling with the following problem, and I am looking for advice
from more experienced R-users: I have a data frame with 2 identifying
variables (comn and mi), and an output variable (x). comn is a variable for
a company and mi is a variable for a month.

comn-c(abc, abc, abc, abc, abc, abc, xyz, xyz,xyz, xyz)
mi- c(1, 1,1, 2, 2, 2, 1, 1, 3, 3)
x- c(-0.0031, 0.0009, -0.007, 0.1929,0.0087, 0.099,-0.089,
0.005, -0.0078, 0.67 )
df- data.frame(comn=comn, mi=mi, x=x)


For each company, within a particular month, I would like to compute the
standard deviation of x: for example, for abc, I would like to compute the
sd of x for month1 (when mi=1) and for month2 (when mi=2).

In other languages (Stata for instance), I would create a grouping variable
(group comnn and mi) and then, apply the sd function for each group.

However, I don't find an elegant way to do the same in R:

I was thinking about the following: I could subset my data frame by mi and
create one file per month, and then make a loop and in each file, use a
by operator for each comn. I am sure it would work, but I feel that it
would be like killing an ant with a tank.

I was wondering if anyone knew a more straightforward way to implement that
kind of operation?

Thanks a lot,

Best,
Aurelien

    [[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] Group several variables and apply a function to the group

2011-12-04 Thread Aurélien PHILIPPOT
exactly like that!
thanks a lot.

Aurelien

2011/12/4 Felipe Carrillo mazatlanmex...@yahoo.com

  Like this?
 library(plyr)
 ddply(df,.(comn,mi),summarise,stDEV=sd(x))

 Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx

   *From:* Aurélien PHILIPPOT aurelien.philip...@gmail.com
 *To:* R-help@r-project.org
 *Sent:* Sunday, December 4, 2011 12:32 PM
 *Subject:* [R] Group several variables and apply a function to the group

 Dear R-experts,
 I am struggling with the following problem, and I am looking for advice
 from more experienced R-users: I have a data frame with 2 identifying
 variables (comn and mi), and an output variable (x). comn is a variable for
 a company and mi is a variable for a month.

 comn-c(abc, abc, abc, abc, abc, abc, xyz, xyz,xyz,
 xyz)
 mi- c(1, 1,1, 2, 2, 2, 1, 1, 3, 3)
 x- c(-0.0031, 0.0009, -0.007, 0.1929,0.0087, 0.099,-0.089,
 0.005, -0.0078, 0.67 )
 df- data.frame(comn=comn, mi=mi, x=x)


 For each company, within a particular month, I would like to compute the
 standard deviation of x: for example, for abc, I would like to compute the
 sd of x for month1 (when mi=1) and for month2 (when mi=2).

 In other languages (Stata for instance), I would create a grouping variable
 (group comnn and mi) and then, apply the sd function for each group.

 However, I don't find an elegant way to do the same in R:

 I was thinking about the following: I could subset my data frame by mi and
 create one file per month, and then make a loop and in each file, use a
 by operator for each comn. I am sure it would work, but I feel that it
 would be like killing an ant with a tank.

 I was wondering if anyone knew a more straightforward way to implement that
 kind of operation?

 Thanks a lot,

 Best,
 Aurelien

 [[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] Group several variables and apply a function to the group

2011-12-04 Thread Pete Brecknock

Aurélien PHILIPPOT wrote
 
 Dear R-experts,
 I am struggling with the following problem, and I am looking for advice
 from more experienced R-users: I have a data frame with 2 identifying
 variables (comn and mi), and an output variable (x). comn is a variable
 for
 a company and mi is a variable for a month.
 
 comn-c(abc, abc, abc, abc, abc, abc, xyz, xyz,xyz,
 xyz)
 mi- c(1, 1,1, 2, 2, 2, 1, 1, 3, 3)
 x- c(-0.0031, 0.0009, -0.007, 0.1929,0.0087, 0.099,-0.089,
 0.005, -0.0078, 0.67 )
 df- data.frame(comn=comn, mi=mi, x=x)
 
 
 For each company, within a particular month, I would like to compute the
 standard deviation of x: for example, for abc, I would like to compute the
 sd of x for month1 (when mi=1) and for month2 (when mi=2).
 
 In other languages (Stata for instance), I would create a grouping
 variable
 (group comnn and mi) and then, apply the sd function for each group.
 
 However, I don't find an elegant way to do the same in R:
 
 I was thinking about the following: I could subset my data frame by mi and
 create one file per month, and then make a loop and in each file, use a
 by operator for each comn. I am sure it would work, but I feel that it
 would be like killing an ant with a tank.
 
 I was wondering if anyone knew a more straightforward way to implement
 that
 kind of operation?
 
 Thanks a lot,
 
 Best,
 Aurelien
 
   [[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.
 

One way would be to use the aggregate function. 

# Your Data ... 
# Note:  I have removed the quotes off the output variable x
comn-c(abc, abc, abc, abc, abc, abc, xyz, xyz,xyz, xyz)
mi- c(1, 1,1, 2, 2, 2, 1, 1, 3, 3)
x- c(-0.0031, 0.0009, -0.007, 0.1929,0.0087, 0.099,-0.089, 0.005, -0.0078,
0.67)
df- data.frame(comn=comn, mi=mi, x=x)

# Aggregate Function
aggregate(df$x, by=list(df$comn,df$mi),FUN=sd)

HTH

Pete

--
View this message in context: 
http://r.789695.n4.nabble.com/Group-several-variables-and-apply-a-function-to-the-group-tp4158017p4158090.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] Group several variables and apply a function to the group

2011-12-04 Thread John Kane
?aggregate should do it

aggregate(df$x,list(df$comn, df$mi), sd)

There are other ways of course

Using the reshape2 package 

library(reshape2)
x1 - melt(df, id=c(comn, mi))
dcast(x1, comn + mi ~ variable, sd)




--- On Sun, 12/4/11, Aurélien PHILIPPOT aurelien.philip...@gmail.com wrote:

 From: Aurélien PHILIPPOT aurelien.philip...@gmail.com
 Subject: [R] Group several variables and apply a function to the group
 To: R-help@r-project.org
 Received: Sunday, December 4, 2011, 3:32 PM
 Dear R-experts,
 I am struggling with the following problem, and I am
 looking for advice
 from more experienced R-users: I have a data frame with 2
 identifying
 variables (comn and mi), and an output variable (x). comn
 is a variable for
 a company and mi is a variable for a month.
 
 comn-c(abc, abc, abc, abc, abc, abc, xyz,
 xyz,xyz, xyz)
 mi- c(1, 1,1, 2, 2, 2, 1, 1, 3, 3)
 x- c(-0.0031, 0.0009, -0.007, 0.1929,0.0087,
 0.099,-0.089,
 0.005, -0.0078, 0.67 )
 df- data.frame(comn=comn, mi=mi, x=x)
 
 
 For each company, within a particular month, I would like
 to compute the
 standard deviation of x: for example, for abc, I would like
 to compute the
 sd of x for month1 (when mi=1) and for month2 (when mi=2).
 
 In other languages (Stata for instance), I would create a
 grouping variable
 (group comnn and mi) and then, apply the sd function for
 each group.
 
 However, I don't find an elegant way to do the same in R:
 
 I was thinking about the following: I could subset my data
 frame by mi and
 create one file per month, and then make a loop and in each
 file, use a
 by operator for each comn. I am sure it would work, but I
 feel that it
 would be like killing an ant with a tank.
 
 I was wondering if anyone knew a more straightforward way
 to implement that
 kind of operation?
 
 Thanks a lot,
 
 Best,
 Aurelien
 
     [[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] trouble with installXLSXsupport()

2011-12-04 Thread Erin Hodgess
Dear R People:

I'm using gdata and read.xls for a couple of projects.

When I load gdata, it says to run installXLSXsupport()

When I do that, I get a not responding error.

I tried it with verbose=TRUE, but nothing appears.

Has anyone else run into this, please?

This is on Windows 7, 64 bit, compiled from source.

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

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


[R] a weird question about gdata:::

2011-12-04 Thread Erin Hodgess
Dear R People:

If I put in:

 findPerl
Error: object 'findPerl' not found


But if I use:

 gdata:::findPerl
function (perl, verbose = FALSE)
{
errorMsg - perl executable not found. Use perl= argument to
specify the correct path.
if (missing(perl)) {
perl = perl
}
perl = Sys.which(perl)
if (perl ==  || perl == perl)
stop(errorMsg)
if (.Platform$OS == windows) {
if (length(grep(rtools, tolower(perl)))  0) {
perl.ftype - shell(ftype perl, intern = TRUE)
if (length(grep(^perl=, perl.ftype))  0) {
perl - sub(^perl=\([^\]*)\.*, \\1, perl.ftype)
}
}
}
if (verbose)
cat(Using perl at, perl, \n)
perl
}
environment: namespace:gdata


Why does one work but not the other, please?

Thanks,
Erin

-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

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


Re: [R] Estimation of AR(1) Model with Markov Switching

2011-12-04 Thread Ingmar Visser
I did not quite get what the problem was from your description ...
However, I did search on CRAN and found at least two packages that can fit
markov switching ar models so that may be an easier way to go.
Hth, Ingmar

On Thu, Dec 1, 2011 at 5:58 PM, napps22 n.j.app...@gmail.com wrote:

 Dear R users,

 I have been trying to obtain the MLE of the following model

 state 0: y_t = 2 + 0.5 * y_{t-1} + e_t
 state 1: y_t = 0.5 + 0.9 * y_{t-1} + e_t

 where e_t ~ iidN(0,1)

 transition probability between states is 0.2

 I've generated some fake data and tried to estimate the parameters using
 the
 constrOptim() function but I can't get sensible answers using it. I've
 tried
 using nlminb and maxLik but they haven't helped. Any tips on how I could
 possibly rewrite my likelihood in a better way to improve my results would
 be welcome.

 Given below is my R code

 # markov switching regime model
 # generate data for a AR(1) markov switching model with the following pars
 # state 0: y_t = 2 + 0.5 * y_{t-1} + e_t
 # state 1: y_t = 0.5 + 0.9 * y_{t-1} + e_t
 # where e_t ~ N(0,1)
 # transition probabilities p_s0_s1 = p_s1_s0 = 0.20

 # generate realisations of the state

 gamma_s0 - qnorm(0.8)
 gamma_s1 - qnorm(0.2)
 gamma - rep(0,100)
 state - rep(0,100)

 # choose initial state at t=0 to be state 0

 gamma[1] - gamma_s0
 state[1] - 0

 for(i in 2:100) {

if(rnorm(1)  gamma[i-1]) {
gamma[i] - gamma_s0
state[i] - 0
}
else {
gamma[i] - gamma_s1
state[i] - 1
}
}

 # generate observations
 # choose y_0 = 0
 # recall state at t=1 was set to 0

 y1 - 2 + 0.5 * 0 + rnorm(1)
 y - rep(0,100)
 y[1] - y1

 for(i in 2:100) {

if(state[i]==0) {
y[i] - 2 + 0.5 * y[i-1] + rnorm(1)
}
else {
y[i] - 0.5 + 0.9 * y[i-1] + rnorm(1)
}
}

 # convert into time series object

 y - ts(y, start = 1, freq = 1)

 # construct negative conditional likelihood function

 neg.logl - function(theta, data) {

 # construct parameters
beta_s0 - theta[1:2]
beta_s1 - theta[3:4]
sigma2 - exp(theta[5])
gamma0 - theta[6]
gamma1 - theta[7]

 # construct probabilities

 #probit specification

 p_s0_s0 - pnorm(gamma_s0)
 p_s0_s1 - pnorm(gamma_s1)
 p_s1_s0 - 1-pnorm(gamma_s0)
 p_s1_s1 - 1-pnorm(gamma_s1)

 # create data matrix

 X - cbind(1,y)

 # assume erogodicity of the markov chain
 # use unconditional probabilities

 p0_s0 - (1 - p_s1_s1) / (2 -p_s0_s0 -p_s1_s1)
 p0_s1 - 1-p0_s0

 # create variables

 p_s0_t_1 - rep(0, nrow(X))
 p_s1_t_1 - rep(0, nrow(X))
 p_s0_t - rep(0, nrow(X))
 p_s1_t - rep(0, nrow(X))
 f_s0 - rep(0,nrow(X)-1)
 f_s1 - rep(0,nrow(X)-1)
 f - rep(0,nrow(X)-1)
 logf - rep(0, nrow(X)-1)

 p_s0_t[1] - p0_s0
 p_s1_t[1] - p0_s1

 # initiate hamilton filter

 for(i in 2:nrow(X)) {

 # calculate prior probabilities using the TPT
 # TPT for this example gives us
 # p_si_t_1 = p_si_t_1_si * p_si_t + p_si_t_1_sj * p_si_t
 # where p_si_t_1 is the prob state_t = i given information @ time t-1
 # p_si_t_1_sj is the prob state_t = i given state_t_1 = j, and all info @
 time t-1
 # p_si_t is the prob state_t = i given information @ time t

 # in this simple example p_si_t_1_sj = p_si_sj

 p_s0_t_1[i] - (p_s0_s0 * p_s0_t[i-1]) + (p_s0_s1 * p_s1_t[i-1])
 p_s1_t_1[i] - (p_s1_s0 * p_s0_t[i-1]) + (p_s1_s1 * p_s1_t[i-1])

 # calculate density function for observation i
 # f_si is density conditional on state = i
 # f is the density

 f_s0[i] - dnorm(y[i]-X[i-1,]%*%beta_s0, sd = sqrt(sigma2))
 f_s1[i] - dnorm(y[i]-X[i-1,]%*%beta_s1, sd = sqrt(sigma2))
 f[i] - (f_s0[i] * p_s0_t_1[i]) + (f_s1[i] * p_s1_t_1[i])

 # calculate filtered/posterior probabilities using bayes rule
 # p_si_t is the prob that state = i given information @ time t

 p_s0_t[i] - (f_s0[i] * p_s0_t_1[i]) / f[i]
 p_s1_t[i] - (f_s1[i] * p_s1_t_1[i]) / f[i]

 logf[i] - log(f[i])

 }

 logl -sum(logf)
 return(-logl)

 }


 # restrict intercept in state model 0 to be greater than intercept in state
 model 1
 # thus matrix of restrictions R is [1 0 -1 0 0 0 0]

 R - matrix(c(1,0,-1,0,0,0,0), nrow = 1)

 # pick start values for the 7 unknown parameters

 start_val - matrix(runif(7), nrow = 7)

 # ensures starting values are in the feasible set

 start_val[1,] - start_val[3,] + 0.1

 # estimate pars

 results -constrOptim(start_val,neg.logl,grad = NULL, ui = R, ci = 0)

 Regards,

 N

 --
 View this message in context:
 http://r.789695.n4.nabble.com/Estimation-of-AR-1-Model-with-Markov-Switching-tp4129417p4129417.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.


[[alternative HTML version deleted]]


Re: [R] a weird question about gdata:::

2011-12-04 Thread Bert Gunter
??namespace
?getAnywhere
?::

See also:  http://www.stat.uiowa.edu/~luke/R/namespaces/morenames.pdf

Bottom line: namespaces provide a mechanism to hide  certain
variables within a package. Special measures as documented above are
required to view them

-- Bert

On Sun, Dec 4, 2011 at 1:19 PM, Erin Hodgess erinm.hodg...@gmail.com wrote:
 Dear R People:

 If I put in:

 findPerl
 Error: object 'findPerl' not found


 But if I use:

 gdata:::findPerl
 function (perl, verbose = FALSE)
 {
    errorMsg - perl executable not found. Use perl= argument to
 specify the correct path.
    if (missing(perl)) {
        perl = perl
    }
    perl = Sys.which(perl)
    if (perl ==  || perl == perl)
        stop(errorMsg)
    if (.Platform$OS == windows) {
        if (length(grep(rtools, tolower(perl)))  0) {
            perl.ftype - shell(ftype perl, intern = TRUE)
            if (length(grep(^perl=, perl.ftype))  0) {
                perl - sub(^perl=\([^\]*)\.*, \\1, perl.ftype)
            }
        }
    }
    if (verbose)
        cat(Using perl at, perl, \n)
    perl
 }
 environment: namespace:gdata


 Why does one work but not the other, please?

 Thanks,
 Erin

 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: erinm.hodg...@gmail.com

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


Re: [R] Group several variables and apply a function to the group

2011-12-04 Thread Bert Gunter
... with() is useful here: e.g. in base R, simply  tapply() or ave() with with()

with(df,ave(x, comn,mi, FUN = sd))

-- Bert



On Sun, Dec 4, 2011 at 1:07 PM, John Kane jrkrid...@yahoo.ca wrote:
 ?aggregate should do it

 aggregate(df$x,list(df$comn, df$mi), sd)

 There are other ways of course

 Using the reshape2 package

 library(reshape2)
 x1 - melt(df, id=c(comn, mi))
 dcast(x1, comn + mi ~ variable, sd)




 --- On Sun, 12/4/11, Aurélien PHILIPPOT aurelien.philip...@gmail.com wrote:

 From: Aurélien PHILIPPOT aurelien.philip...@gmail.com
 Subject: [R] Group several variables and apply a function to the group
 To: R-help@r-project.org
 Received: Sunday, December 4, 2011, 3:32 PM
 Dear R-experts,
 I am struggling with the following problem, and I am
 looking for advice
 from more experienced R-users: I have a data frame with 2
 identifying
 variables (comn and mi), and an output variable (x). comn
 is a variable for
 a company and mi is a variable for a month.

 comn-c(abc, abc, abc, abc, abc, abc, xyz,
 xyz,xyz, xyz)
 mi- c(1, 1,1, 2, 2, 2, 1, 1, 3, 3)
 x- c(-0.0031, 0.0009, -0.007, 0.1929,0.0087,
 0.099,-0.089,
 0.005, -0.0078, 0.67 )
 df- data.frame(comn=comn, mi=mi, x=x)


 For each company, within a particular month, I would like
 to compute the
 standard deviation of x: for example, for abc, I would like
 to compute the
 sd of x for month1 (when mi=1) and for month2 (when mi=2).

 In other languages (Stata for instance), I would create a
 grouping variable
 (group comnn and mi) and then, apply the sd function for
 each group.

 However, I don't find an elegant way to do the same in R:

 I was thinking about the following: I could subset my data
 frame by mi and
 create one file per month, and then make a loop and in each
 file, use a
 by operator for each comn. I am sure it would work, but I
 feel that it
 would be like killing an ant with a tank.

 I was wondering if anyone knew a more straightforward way
 to implement that
 kind of operation?

 Thanks a lot,

 Best,
 Aurelien

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


[R] RODBC sqlSave / append problem (windows XP, R 2.13.2)

2011-12-04 Thread mattjo
Dear All, 

Using RODBC I have read in a (429 x 11) dataframe from Access, and would
like to append two columns of transformed data (429 x 2) to the original
table (thereby making it a 429 x 13 table). I would ideally like this to
be the same name etc as the original table in Access. 

I have used the following command: 

R
sqlSave(con,as.data.frame(SA_data),tablename=Const_mats_8301_t1,rownam
es=T,fast=T, append=T)

And get the error: 

Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test, :
missing columns in 'data'

Thanks in advance,

mj

Visit our website at http://www.ubs.com

This message contains confidential information and is in...{{dropped:26}}

__
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] equating approximate values

2011-12-04 Thread R. Michael Weylandt
Not sure what to make of the fact that your x, y are of different
lengths: if you mean to check all possible pairings, this is probably
what you need:

which(outer(x, y, -)  threshold, arr.ind = TRUE)

Michael

On Sun, Dec 4, 2011 at 2:24 PM, andrija djurovic djandr...@gmail.com wrote:
 Hi. Maybe this can help you (you can try additionally to incorporate
 threshold):

 set.seed(1)
 x-rnorm(10,10,1)
 values - sample(1:10,10)  #values that we are looking for
 mat - matrix(c(x,values),ncol=2)

 closest-function(x,values)    #function is an example from The R book
 (Crawley)
 + {
 + x[which(abs(x-values)==min(abs(x-values)))]
 + }

 apply(mat[,2,drop=FALSE],1,function(y) closest(mat[,1],y))
  [1] 10.183643  9.164371  9.164371  9.164371  9.164371  9.164371  9.164371
  9.164371
  [9]  9.164371  9.164371


 On Sun, Dec 4, 2011 at 7:00 PM, vamshi999 vamshi...@gmail.com wrote:

 Hello List,

 I am having trouble finding the command for my problem.

 I have two arrays x and y. now i would like to compare the values of x and
 y
 and then get the index of x which is exactly or approximately equal(+/-
 some
 value ) to the values in y.
  x - runif(100,min=0,max=5)
  y - runif(10,min=0,max=5)


 the threshold value(+/-) value can vary. for this example lets take it to
 be
 .5

 I know the regular method of doing this by writing different if and for
 loops. But i have very big dataframe the computation time is very high for
 this method. can anyone please tell me if there any functions to do this.

 thank you for your help.

 --
 View this message in context:
 http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4157551.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.


        [[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] equating approximate values

2011-12-04 Thread R. Michael Weylandt
My apologies: you need an abs() call as well:

which(abs(outer(x, y, -))  threshold, arr.ind = TRUE)

Michael

On Sun, Dec 4, 2011 at 6:25 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 Not sure what to make of the fact that your x, y are of different
 lengths: if you mean to check all possible pairings, this is probably
 what you need:

 which(outer(x, y, -)  threshold, arr.ind = TRUE)

 Michael

 On Sun, Dec 4, 2011 at 2:24 PM, andrija djurovic djandr...@gmail.com wrote:
 Hi. Maybe this can help you (you can try additionally to incorporate
 threshold):

 set.seed(1)
 x-rnorm(10,10,1)
 values - sample(1:10,10)  #values that we are looking for
 mat - matrix(c(x,values),ncol=2)

 closest-function(x,values)    #function is an example from The R book
 (Crawley)
 + {
 + x[which(abs(x-values)==min(abs(x-values)))]
 + }

 apply(mat[,2,drop=FALSE],1,function(y) closest(mat[,1],y))
  [1] 10.183643  9.164371  9.164371  9.164371  9.164371  9.164371  9.164371
  9.164371
  [9]  9.164371  9.164371


 On Sun, Dec 4, 2011 at 7:00 PM, vamshi999 vamshi...@gmail.com wrote:

 Hello List,

 I am having trouble finding the command for my problem.

 I have two arrays x and y. now i would like to compare the values of x and
 y
 and then get the index of x which is exactly or approximately equal(+/-
 some
 value ) to the values in y.
  x - runif(100,min=0,max=5)
  y - runif(10,min=0,max=5)


 the threshold value(+/-) value can vary. for this example lets take it to
 be
 .5

 I know the regular method of doing this by writing different if and for
 loops. But i have very big dataframe the computation time is very high for
 this method. can anyone please tell me if there any functions to do this.

 thank you for your help.

 --
 View this message in context:
 http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4157551.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.


        [[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] a weird question about gdata:::

2011-12-04 Thread Rolf Turner


See end of message.

On 05/12/11 10:19, Erin Hodgess wrote:

Dear R People:

If I put in:


findPerl

Error: object 'findPerl' not found


But if I use:


gdata:::findPerl

function (perl, verbose = FALSE)
{
 errorMsg- perl executable not found. Use perl= argument to
specify the correct path.
 if (missing(perl)) {
 perl = perl
 }
 perl = Sys.which(perl)
 if (perl ==  || perl == perl)
 stop(errorMsg)
 if (.Platform$OS == windows) {
 if (length(grep(rtools, tolower(perl)))  0) {
 perl.ftype- shell(ftype perl, intern = TRUE)
 if (length(grep(^perl=, perl.ftype))  0) {
 perl- sub(^perl=\([^\]*)\.*, \\1, perl.ftype)
 }
 }
 }
 if (verbose)
 cat(Using perl at, perl, \n)
 perl
}
environment: namespace:gdata
Why does one work but not the other, please?


Because findPerl is ``not exported'' from the gdata namespace.

Uhhh, what does that mean?  I have a vague idea, but I'm not sufficiently
confident/competent to elaborate.  You'll just have to read up on 
namespaces.

I'm *sure* namespaces are really a Good Thing, but they sure do add to the
mysteries of R usage.

Has Pat Burns written anything by way of explaining namespace to bunnies
like me?

cheers,

Rolf

__
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] a weird question about gdata:::

2011-12-04 Thread Gabor Grothendieck
On Sun, Dec 4, 2011 at 6:57 PM, Rolf Turner rolf.tur...@xtra.co.nz wrote:

 See end of message.


 On 05/12/11 10:19, Erin Hodgess wrote:

 Dear R People:

 If I put in:

 findPerl

 Error: object 'findPerl' not found


 But if I use:

 gdata:::findPerl

 function (perl, verbose = FALSE)
 {
     errorMsg- perl executable not found. Use perl= argument to
 specify the correct path.
     if (missing(perl)) {
         perl = perl
     }
     perl = Sys.which(perl)
     if (perl ==  || perl == perl)
         stop(errorMsg)
     if (.Platform$OS == windows) {
         if (length(grep(rtools, tolower(perl)))  0) {
             perl.ftype- shell(ftype perl, intern = TRUE)
             if (length(grep(^perl=, perl.ftype))  0) {
                 perl- sub(^perl=\([^\]*)\.*, \\1, perl.ftype)
             }
         }
     }
     if (verbose)
         cat(Using perl at, perl, \n)
     perl
 }
 environment: namespace:gdata
 Why does one work but not the other, please?


 Because findPerl is ``not exported'' from the gdata namespace.

 Uhhh, what does that mean?  I have a vague idea, but I'm not sufficiently
 confident/competent to elaborate.  You'll just have to read up on
 namespaces.
 I'm *sure* namespaces are really a Good Thing, but they sure do add to the
 mysteries of R usage.


The idea is to divide objects into those that are there for the user
to access (exported objects) and those that are internal objects that
only the package itself uses (everything else).   findPerl is there
only so that read.xls and other routines that depend on perl scripts
can use it internally to find perl.  It was not intended that users
access it so its better hidden from view.

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

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


Re: [R] a weird question about gdata:::

2011-12-04 Thread Jeff Newmiller
I prefer to think of namespaces as preventing clashes with similarly-named 
functions in the main workspace or in other packages that might serve a 
different need.

Given that purpose, I don't think I would have confined that particular 
function behind the namespace, because any other use of that name is likely to 
duplicate the functionality of that particular function, and any improvements 
to it probably ought to be incorporated into that particular function just as 
much as any other implementation would deserve improvement.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Gabor Grothendieck ggrothendi...@gmail.com wrote:

On Sun, Dec 4, 2011 at 6:57 PM, Rolf Turner rolf.tur...@xtra.co.nz
wrote:

 See end of message.


 On 05/12/11 10:19, Erin Hodgess wrote:

 Dear R People:

 If I put in:

 findPerl

 Error: object 'findPerl' not found


 But if I use:

 gdata:::findPerl

 function (perl, verbose = FALSE)
 {
     errorMsg- perl executable not found. Use perl= argument to
 specify the correct path.
     if (missing(perl)) {
         perl = perl
     }
     perl = Sys.which(perl)
     if (perl ==  || perl == perl)
         stop(errorMsg)
     if (.Platform$OS == windows) {
         if (length(grep(rtools, tolower(perl)))  0) {
             perl.ftype- shell(ftype perl, intern = TRUE)
             if (length(grep(^perl=, perl.ftype))  0) {
                 perl- sub(^perl=\([^\]*)\.*, \\1,
perl.ftype)
             }
         }
     }
     if (verbose)
         cat(Using perl at, perl, \n)
     perl
 }
 environment: namespace:gdata
 Why does one work but not the other, please?


 Because findPerl is ``not exported'' from the gdata namespace.

 Uhhh, what does that mean?  I have a vague idea, but I'm not
sufficiently
 confident/competent to elaborate.  You'll just have to read up on
 namespaces.
 I'm *sure* namespaces are really a Good Thing, but they sure do add
to the
 mysteries of R usage.


The idea is to divide objects into those that are there for the user
to access (exported objects) and those that are internal objects that
only the package itself uses (everything else).   findPerl is there
only so that read.xls and other routines that depend on perl scripts
can use it internally to find perl.  It was not intended that users
access it so its better hidden from view.

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

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

__
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] convert table to a string in matrix

2011-12-04 Thread Philipp Chapkovski
Hello everybody! I need help in collecting the information about Russian
elections.

There is a table at the web-site
http://www.moscow_city.vybory.izbirkom.ru/region/region/moscow_city?action=showroot=774003008tvd=477400389537vrn=100100028713299region=77global=truesub_region=77prver=0pronetvd=nullvibid=477400389537type=242
the problem is how to convert this table to a string in order to add it to
the table with 25 columns. ReadHTMLTable doesn't work because I need only
bold digits and it takes both normal and bold digits and stick them
together.
What can be done?
Thanks!
Philipp

[[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] upper bound in the integrate function depends on a parameter

2011-12-04 Thread Ben Bolker
Jorge I Velez jorgeivanvelez at gmail.com writes:

 And remember:
 
 #install.packages('fortunes')
 require(fortunes)
 fortune('Yoda')
 
 Evelyn Hall: I would like to know how (if) I can extract some of the
 information
 from the summary of my nlme.
 Simon Blomberg: This is R. There is no if. Only how.
-- Evelyn Hall and Simon 'Yoda' Blomberg
   R-help (April 2005)


  Yes, although if you really wanted to compute (symbolic) indefinite integrals,
it would be awfully hard. R is Turing-complete so of course you could do
it ... but ...

  Ben Bolker

__
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] Save debugging session info and resume from the middle?

2011-12-04 Thread Michael
Hi all,

In debugging, I've met the following problem:

myfunction = function (x, y)
{

for (i in 1:length(x)}
{
 Part_A;

 #save the debugging session here?

 Part_B;
}
}

All these parts are of very heavy computations and often can take hours to
finish.

How do I debug them efficiently?

I am thinking of to save a snapshot of the debugging session (everything
including the stack trace, etc.) in between Part_A and Part_B,

and then when I want to focus on Part_B only, I can replace the code
Part_A by LoadDebugSession...so that I don't have recompute Part_A
again and again...

Is ths possible to do?

Can stack traces be saved and then recovered?

Thanks

Thanks a lot!

[[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] equating approximate values

2011-12-04 Thread vamshi999
this is exactly what i wanted. 

How to i select only the minimum value from this?. 

thank you 




My apologies: you need an abs() call as well:

which(abs(outer(x, y, -))  threshold, arr.ind = TRUE)

Michael




--
View this message in context: 
http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4158691.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] Rggobi pdf output

2011-12-04 Thread =)
Good day everyone. I have a question concerning *ggobi* and
*rggobi*package. I am using R version 2.13.2 and Ubuntu 11.04. I am
new to ggobi
and I'm reading the book *Interactive and Dynamic Graphics for Data Analysis
*. The book was published 2007.

My question is: how can I export a graph for *rggobi* to pdf to include it
in latex. For example: I have lots of variables in ggobi and I need to
export the ggplot like scatterplot of any two variables or parallel
cordinates graph to a pdf. So far I've read that the authors suggests to
solve it like this:

library(DescribeDisplay)
d - dd_load(fig.R)
plot(d)

or

p - ggplot(d)
print(p)

which produces nice graphics which you can use with pdf() function. But
neither the *DescribeDisplay* package, nor *ggplot* are available in
2.13.2.

I browsed the web for solution, but I found only that
ggobi_display_save_picture() could be useful for image graphs but not for
pdf. I also tried save display description (tools-save display
description) and then plotting it with qplot() or plot(). But all I get is
a blank screen while ggobi_display_save_picture() gives a good picture.
There is probably a much easier solution since R is changing and becoming
more convenient to use.

I i'm also including the code of the example i'm doing


f.std.data-function(x) {
  return((x-mean(x,na.rm=T))/sd(x,na.rm=T))
}

# Read data, and standardize before running SOM

d.music-read.csv(music-sub.csv,row.names=1)
d.music.std-cbind(d.music[,c(1,2)],apply(d.music[,-c(1,2)],2,f.std.data))



# Load libraries
library(rggobi)
library(som)

# Run SOM

music.som-som(d.music.std[,-c(1:2)],6,6,neigh=bubble,rlen=100)
music.som-som(d.music.std[,-c(1:2)],6,6,neigh=bubble,rlen=1000)

# Set up data for ggobi - data needs to have any labels in the first few columns

f.ggobi.som-function(x,x.som) {
  xmx-jitter(x.som$visual$x,factor=2)
  xmy-jitter(x.som$visual$y,factor=2)
  ncols-ncol(x)
  x.ggobi-cbind(x,xmx,xmy)
  dimnames(x.ggobi)[[2]][ncols+1]-Map 1

  dimnames(x.ggobi)[[2]][ncols+2]-Map 2
  x.grid-cbind(x.som$code,x.som$code.sum[,1:2])
  dimnames(x.grid)[[2]]-dimnames(x.ggobi)[[2]]
  x.clust-rbind(x.ggobi,x.grid)
}
f.ggobi.som.net-function(x.som) {

  x.net-NULL
  for (i in 1:x.som$xdim) {
for (j in 1:x.som$ydim) {
if (jx.som$ydim)
x.net-rbind(x.net,c((i-1)*x.som$xdim+j,(i-1)*x.som$xdim+j+1))

if (ix.som$xdim) x.net-rbind(x.net,c((i-1)*x.som$xdim+j,i*x.som$xdim+j))
}
  }
  return(x.net)
}

d.music.som-f.ggobi.som(d.music.std[,-c(1,2)],music.som)

d.music.som-list(Songs=factor(c(as.character(row.names(d.music)),rep(0,36))),
  Artist=factor(c(as.character(d.music[,1]),rep(0,36))),
  Type=factor(c(as.character(d.music[,2]),rep(0,36))),

  LVar=d.music.som[,1],LAve=d.music.som[,2],LMax=d.music.som[,3],
  LFEner=d.music.som[,4],LFreq=d.music.som[,5],Map.1=d.music.som[,6],
  Map.2=d.music.som[,7])
gg-ggobi(d.music.som)
g-gg[1]

#load edges
d.music.som.net-f.ggobi.som.net(music.som)
edges(g) - d.music.som.net + 62

# Color points according to type of music, and som net

gcolor- rep(8,98)
gcolor[d.music.som$Type==Rock]-6
gcolor[d.music.som$Type==Classical]-4
gcolor[d.music.som$Type==New wave]-1
glyph_color(g)-gcolor

[[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] [rggobi] ggplot like pdf output

2011-12-04 Thread =)
Good day everyone. I have a question concerning *ggobi* and
*rggobi*package. I am using R version 2.13.2 and Ubuntu 11.04. I am
new to ggobi
and I'm reading the book *Interactive and Dynamic Graphics for Data Analysis
*. The book was published 2007.

My question is: how can I export a graph for *rggobi* to pdf to include it
in latex. For example: I have lots of variables in ggobi and I need to
export the ggplot like scatterplot of any two variables or parallel
cordinates graph to a pdf. So far I've read that the authors suggests to
solve it like this:

library(DescribeDisplay)
d - dd_load(fig.R)
plot(d)

or

p - ggplot(d)
print(p)

which produces nice graphics which you can use with pdf() function. But
neither the *DescribeDisplay* package, nor *ggplot* are available in
2.13.2.

I browsed the web for solution, but I found only that
ggobi_display_save_picture() could be useful for image graphs but not for
pdf. I also tried save display description (tools-save display
description) and then plotting it with qplot() or plot(). But all I get is
a blank screen while ggobi_display_save_picture() gives a good picture.
There is probably a much easier solution since R is changing and becoming
more convenient to use.

I i'm also including the code of the example i'm doing


f.std.data-function(x) {
  return((x-mean(x,na.rm=T))/sd(x,na.rm=T))
}

# Read data, and standardize before running SOM

d.music-read.csv(music-sub.csv,row.names=1)
d.music.std-cbind(d.music[,c(1,2)],apply(d.music[,-c(1,2)],2,f.std.data))



# Load libraries
library(rggobi)
library(som)

# Run SOM

music.som-som(d.music.std[,-c(1:2)],6,6,neigh=bubble,rlen=100)
music.som-som(d.music.std[,-c(1:2)],6,6,neigh=bubble,rlen=1000)

# Set up data for ggobi - data needs to have any labels in the first few columns

f.ggobi.som-function(x,x.som) {
  xmx-jitter(x.som$visual$x,factor=2)
  xmy-jitter(x.som$visual$y,factor=2)
  ncols-ncol(x)
  x.ggobi-cbind(x,xmx,xmy)
  dimnames(x.ggobi)[[2]][ncols+1]-Map 1

  dimnames(x.ggobi)[[2]][ncols+2]-Map 2
  x.grid-cbind(x.som$code,x.som$code.sum[,1:2])
  dimnames(x.grid)[[2]]-dimnames(x.ggobi)[[2]]
  x.clust-rbind(x.ggobi,x.grid)
}
f.ggobi.som.net-function(x.som) {

  x.net-NULL
  for (i in 1:x.som$xdim) {
for (j in 1:x.som$ydim) {
if (jx.som$ydim)
x.net-rbind(x.net,c((i-1)*x.som$xdim+j,(i-1)*x.som$xdim+j+1))

if (ix.som$xdim) x.net-rbind(x.net,c((i-1)*x.som$xdim+j,i*x.som$xdim+j))
}
  }
  return(x.net)
}

d.music.som-f.ggobi.som(d.music.std[,-c(1,2)],music.som)

d.music.som-list(Songs=factor(c(as.character(row.names(d.music)),rep(0,36))),
  Artist=factor(c(as.character(d.music[,1]),rep(0,36))),
  Type=factor(c(as.character(d.music[,2]),rep(0,36))),

  LVar=d.music.som[,1],LAve=d.music.som[,2],LMax=d.music.som[,3],
  LFEner=d.music.som[,4],LFreq=d.music.som[,5],Map.1=d.music.som[,6],
  Map.2=d.music.som[,7])
gg-ggobi(d.music.som)
g-gg[1]

#load edges
d.music.som.net-f.ggobi.som.net(music.som)
edges(g) - d.music.som.net + 62

# Color points according to type of music, and som net

gcolor- rep(8,98)
gcolor[d.music.som$Type==Rock]-6
gcolor[d.music.som$Type==Classical]-4
gcolor[d.music.som$Type==New wave]-1
glyph_color(g)-gcolor

[[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] Prediction from censReg?

2011-12-04 Thread z2.0
Just posting again here...

--
View this message in context: 
http://r.789695.n4.nabble.com/Prediction-from-censReg-tp4155855p4158844.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] Persp3d freezes when run from within Python

2011-12-04 Thread wchips
G'day everyone,

I've been trying to get an interactive OpenGL plot to work from within
Python 2.6 using Rpy2 and the persp3d function. The problem is that the plot
seems to freeze upon activation. All interactivity is lost even though it
works fine when run from within the R console (version 2.11.1). Is this a
known issue? Any ideas as to what might be causing this, or possibly how to
fix it?

cheers,
wchips

--
View this message in context: 
http://r.789695.n4.nabble.com/Persp3d-freezes-when-run-from-within-Python-tp4158940p4158940.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] a weird question about gdata:::

2011-12-04 Thread Gabor Grothendieck
On Sun, Dec 4, 2011 at 8:07 PM, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote:
 I prefer to think of namespaces as preventing clashes with similarly-named 
 functions in the main workspace or in other packages that might serve a 
 different need.

 Given that purpose, I don't think I would have confined that particular 
 function behind the namespace, because any other use of that name is likely 
 to duplicate the functionality of that particular function, and any 
 improvements to it probably ought to be incorporated into that particular 
 function just as much as any other implementation would deserve improvement.

The idea of hiding the the internals is that they can then be changed
with reasonable likelihood that it won't affect users.  Only those who
attempted to circumvent the barriers put in place would be affected.
For example, suppose that read.xls and the related Excel routines were
to be changed so that internally they use C instead of perl.  In that
case findPerl would not serve any purpose in the package and the
current design would allow it to be dropped.  On the other hand, if
the purpose of the package were specifically to interface to perl then
it would make sense to export it.

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

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


Re: [R] Extract last 3 characters from numeric vector

2011-12-04 Thread Kang Min
Thanks Sarah, but I discovered that numbers like 3.0 only have 1
character, so I had a range of character lengths from 1 to 4 (e.g.
17.0 has 2 characters, 3.4 has 3 and 12.4 has 4).

Uwe's method worked well. Thanks again.

Kang Min

On Dec 4, 11:42 pm, Uwe Ligges lig...@statistik.tu-dortmund.de
wrote:
 On 04.12.2011 14:38, Kang Min wrote:

  Hi all,

  I have a numeric vector with 1 decimal place, and I'd like to extract
  the last 3 characters, including the decimal point. The vector ranges
  from 0 to 20.

  x- round(runif(100)*20, digits=1)

 formatC(round(x%%10, 1), format=f, digits=1)

 Uwe Ligges

  Some of numbers have 3 characters, and some have 4. I've read up on
  the substr() function but that extracts characters based on exact
  positions. How can I extract just the last 3 characters no matter the
  length of the number? e.g. from 16.7 I want 6.7, from 3.5 I want 3.5
  as it is.

  Thanks,
  Kang Min

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

 __
 r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guidehttp://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] similarity matrix

2011-12-04 Thread set
I'm sorry, I made a mistake in my example. you're right. I don't really know
how a similarity alogrithm worksbut I'm willing to try that...are there
any good examples available?
Thank you

--
View this message in context: 
http://r.789695.n4.nabble.com/similarity-matrix-tp4157576p4159547.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] Toggle cASE

2011-12-04 Thread Tonio
Hello R-help list,
 
I am looking for way to toggle the case of the characters like a flip-flop; 
that is from ''Hello'' to hELLO or vice versa.
 
I know that there are a number of functions like casefold, tolower, toupper, 
etc. but these functions change the case in an uniform way.
 
Thanks in advance,
 
Antonio Rivero Ostoic
 
 
 
 
Antonio Rivero Ostoic
PhD Student, Department of Leadership and Strategy
From 1 Jul until 31 Dec 2011
Tel.    +61 3 8344 4300
Fax +61 3 9347 6618
Email   j...@sdu.dk
Addr.   The University of Melbourne, Victoria 3010  Australia
-
UNIVERSITY OF SOUTHERN DENMARK
Sdr. Stationsvej 28 · DK-4200   Slagelse · Denmark · Tel. +45 6550 1000 ·
www.sdu.dk

[[alternative HTML version deleted]]

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


[R] about interpretation of anova results...

2011-12-04 Thread narendarreddy kalam
quantreg package is used.
*fit1 results are*
Call:
rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + 
inp8 + inp9, tau = 0.15, data = wbc)

Coefficients:
 (Intercept) inp1 inp2 inp3 inp4
inp5 
-0.191528450  0.005276347  0.021414032  0.016034803  0.007510343 
0.005276347 
inp6 inp7 inp8 inp9 
 0.058708544  0.005224906  0.006804871 -0.003931540 

Degrees of freedom: 673 total; 663 residual
*fit2 results are*
Call:
rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + 
inp8 + inp9, tau = 0.3, data = wbc)

Coefficients:
  (Intercept)  inp1  inp2  inp3  inp4 
-1.11e-01  5.776765e-19  4.635734e-18  1.874715e-18  2.099872e-18 
 inp5  inp6  inp7  inp8  inp9 
-4.942052e-19  1.11e-01  2.205289e-18  4.138435e-18  9.300642e-19 

Degrees of freedom: 673 total; 663 residual

anova(fit1,fit2);
Quantile Regression Analysis of Deviance Table

Model: op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + inp8 + inp9
Joint Test of Equality of Slopes: tau in {  0.15 0.3  }

  Df Resid Df F value Pr(F)
1  9 1337  0.5256 0.8568
Warning messages:
1: In summary.rq(x, se = nid, covariance = TRUE) : 93 non-positive fis
2: In summary.rq(x, se = nid, covariance = TRUE) : 138 non-positive fis
how to interpret the above results??

what is the use of anova function??
will it give the best among fit1  fit2..


--
View this message in context: 
http://r.789695.n4.nabble.com/about-interpretation-of-anova-results-tp4159510p4159510.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] about error while using anova function

2011-12-04 Thread narendarreddy kalam
fit1-rq(formula=op~inp1+inp2+inp3+inp4+inp5+inp6+inp7+inp8+inp9,tau=0.15,data=wbc)
fit2-rq(formula=op~inp1+inp2+inp3+inp4+inp5+inp6+inp7+inp8+inp9,tau=0.5,data=wbc)
fit3-rq(formula=op~inp1+inp2+inp3+inp4+inp5+inp6+inp7+inp8+inp9,tau=0.15,data=wbc)
fit4-rq(formula=op~inp1+inp2+inp3+inp4+inp5+inp6+inp7+inp8+inp9,tau=0.15,data=wbc)
fit5-rq(formula=op~inp1+inp2+inp3+inp4+inp5+inp6+inp7+inp8+inp9,tau=0.15,data=wbc)
*output of tau=0.15*fit1
Call:
rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + 
inp8 + inp9, tau = 0.15, data = wbc)

Coefficients:
 (Intercept) inp1 inp2 inp3 inp4
inp5 
-0.191528450  0.005276347  0.021414032  0.016034803  0.007510343 
0.005276347 
inp6 inp7 inp8 inp9 
 0.058708544  0.005224906  0.006804871 -0.003931540 

Degrees of freedom: 673 total; 663 residual


*output of tau=0.3*fit2
Call:
rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + 
inp8 + inp9, tau = 0.3, data = wbc)

Coefficients:
  (Intercept)  inp1  inp2  inp3  inp4 
-1.11e-01  5.776765e-19  4.635734e-18  1.874715e-18  2.099872e-18 
 inp5  inp6  inp7  inp8  inp9 
-4.942052e-19  1.11e-01  2.205289e-18  4.138435e-18  9.300642e-19 

Degrees of freedom: 673 total; 663 residual

*output of tau=0.5*fit3
Call:
rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + 
inp8 + inp9, tau = 0.5, data = wbc)

Coefficients:
  (Intercept)  inp1  inp2  inp3  inp4 
-1.40e-01  5.810236e-17  4.00e-02  1.087160e-16  4.297771e-18 
 inp5  inp6  inp7  inp8  inp9 
 8.045868e-17  8.00e-02  6.841101e-17  2.00e-02  7.560947e-17 

Degrees of freedom: 673 total; 663 residual
*output of tau=0.65*
Call:
rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + 
inp8 + inp9, tau = 0.65, data = wbc)

Coefficients:
 (Intercept) inp1 inp2 inp3 inp4
inp5 
-0.193593706  0.005012804  0.044208182  0.008994346  0.006214294 
0.007622629 
inp6 inp7 inp8 inp9 
 0.064595895  0.006214294  0.028904532  0.001775512 

Degrees of freedom: 673 total; 663 residual
*output of tau=0.9:*
fit5
Call:
rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + 
inp8 + inp9, tau = 0.9, data = wbc)

Coefficients:
 (Intercept) inp1 inp2 inp3 inp4
inp5 
-0.249006688  0.040430238  0.010854846  0.031021326  0.013558943 
0.024867111 
inp6 inp7 inp8 inp9 
 0.050441784  0.024867111  0.027018345  0.001079872 

Degrees of freedom: 673 total; 663 residual

b so fit1 fit2,fit3,fit4,fit5 are the 5 quantiles of the wbc dataset.but
why i am encoutering the following error while using anova*

*anova(fit1,fit2,fit3,fit4,fit5);
Error in solve.default(D %*% W %*% t(D), D %*% coef) : 
  system is computationally singular: reciprocal condition number =
5.58091e-19
In addition: Warning messages:
1: In summary.rq(x, se = nid, covariance = TRUE) : 93 non-positive fis
2: In summary.rq(x, se = nid, covariance = TRUE) : 138 non-positive fis
3: In summary.rq(x, se = nid, covariance = TRUE) : 206 non-positive fis
4: In summary.rq(x, se = nid, covariance = TRUE) : 53 non-positive fis
5: In summary.rq(x, se = nid, covariance = TRUE) : 30 non-positive fis*


--
View this message in context: 
http://r.789695.n4.nabble.com/about-error-while-using-anova-function-tp4159463p4159463.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] local minima/ maxima

2011-12-04 Thread Tonja Krueger

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